Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Another way to think about hardware accelerated images in Screen 0
#1
Hi
@Pete
using Hardware images in Screen 0 for buttons and menus..
Q1: how many menus do you have ? Build an image for each menu and make it an hardware accelerated image!
Q2: how many buttons do you have? Build an image for each button and make it an hardware accelerated image!
And for the Hover selection effect? Well you need of another hardware accelerated image with a grade of transparency to cover the area of selection pointed by mouse!

here screenshots:

window in screen 0 and button with hardware graphic
[Image: 1-Hardware-study3.jpg]

window in screen 0 software graphic, popupmenu over button and hover popup menu in hardware graphic

[Image: 2-hardware-study3.jpg]



here the code:
Code: (Select All)

Screen 0
_DisplayOrder _Software , _Hardware ' this says only what must be shown
Dim As Long Img1, Img2, Img3
Dim As Integer X, Y, Mb, Xm, Ym

' here it creates a square to overlap menu to make the shadow of selection
Img1 = _NewImage(112, 16, 32)
_Dest Img1
Cls , _RGBA32(127, 205, 255, 125)
Img1 = _CopyImage(Img1, 33)

' here it creates the Button image
Img2 = _NewImage(100, 50, 32)
_Dest Img2
Cls , _RGBA32(127, 0, 255, 180)
Color _RGBA32(0, 10, 140, 180), _RGBA32(0, 0, 0, 100)
_PrintString (10, 17), "Click Here"
Img2 = _CopyImage(Img2, 33)

' it creates image of popup from screen 0
Img3 = _NewImage(112, 64, 32)
_Dest Img3
Color _RGBA32(211, 166, 6, 255), _RGBA32(44, 44, 255, 255)
'Locate 1, 1
_PrintString (1, 1), "New.....Ctrl+N"
'Locate , 1
_PrintString (1, 16), "Open....Ctrl+O"
'Locate , 1
_PrintString (1, 32), "Close...Ctrl+X"
'Locate , 1
_PrintString (1, 48), "Quit....Ctrl+Q"
Img3 = _CopyImage(Img3, 33)
Screen 0

' inizialization and main loop
_Dest 0
Color 11, 3
Cls , 2
X = 0
Y = 0
Xm = 0
Ym = 0
Mb = 0
Do
    Cls , 2
    Locate 1, 1: Print "Left click to show popup menu"; ' it shows help on first line of text
    _PutImage (300, 300), Img2, 0 ' button
    If _MouseInput Then
        X = _MouseX
        Y = _MouseY
        If _MouseButton(1) Then Mb = 1
        If _MouseButton(2) Then Mb = 2
    End If
    If Mb = 1 Then
        If X < 1 Or X + 13 > 80 Or Y < 1 Or Y + 3 > 24 Then
            Beep ' mouse's popup menu goes out of window's area
        Else
            Xm = X: Ym = Y ' X and Y  for popup and hovering menu
            ' popup menu
        End If
        Mb = 0
    End If
    If Xm And Ym Then
        _PutImage (1 + ((Xm - 1) * 8), 1 + ((Ym - 1) * 16)), Img3, 0
        If (X >= Xm And X <= Xm + 13) And (Y >= Ym And Y <= Ym + 3) Then
            _PutImage ((Xm - 1) * 8, (Y - 1) * 16), Img1, 0 ' hover / selection item of popup menu
        End If
    End If
    _Display
Loop Until Mb = 2
_FreeImage Img1
_FreeImage Img2
_FreeImage Img3
End
Reply
#2
This is actually an option I have been leaning towards. I didn't even have to visit Pisa, to come up with it, either!

I know if I did a hardware popup, I'd have to draw the menu in the background on a graphics screen, copy the image to memory, and then it would be usable. That would allow for the different colors of text in the menu, too.

I would have to switch to the same idea for menu highlighting shadow effect that you posted. I created the shadow on my menu that makes it 3-D like that, already.

I wouldn't need to convert the software buttons, because this method would allow the hardware to go over the software buttons and the translucent shadow would allow see-through where applicable.

The one thing holding me back is that I have some menus that prompt for text input. That stuff is better left to a software menu than a hardware one.

Now the other method I've been exploring is to just make the screen a hardware image. Steve showed us that was possible by using _SAVEIMAGE. What is really cool is it looks like Sam is interested in making this easier by creating a _COPYIMAGE for SCREEN 0, _COPYIMAGE(0, 33)

oh, and about _FREEIMAGE

I see you use the same variable for both your image screen and image. I would think you would want to use different variables, so you could free the screen variable right after you copy it, and only free the image variables after they are no longer to be displayed.

Example converted from your other program.
Code: (Select All)
Img1Screen = _NewImage(112, 16, 32)
_Dest Img1Screen
Cls , _RGBA32(127, 205, 255, 125)
Img1 = _CopyImage(Img1Screen, 33)
_FreeImage Img1Screen

What is your take on this? I see that your not freeing what could be made a disposable drawing screens, and by overwriting the screen handle with the image handle, you wouldn't be able to free the memory of those screens.

Pete
Reply
#3
@Pete
yes I dunno why but in my mind has taken place the idea that overwriting the handle the relative image in memory comes into garbage memory ready to be re-used! (an automatic malloc!)
So I have used the same handle for software image and hardware accellerated image!
Wrong.. so here the corrected code with the right economic management of the RAM.

Code: (Select All)

Screen 0
_DisplayOrder _Software , _Hardware ' this says only what must be shown
Dim As Long Img1, Img2, Img3, Img1H, Img2H, Img3H
Dim As Integer X, Y, Mb, Xm, Ym

' here it creates a square to overlap menu to make the shadow of selection
Img1 = _NewImage(112, 16, 32)
_Dest Img1
Cls , _RGBA32(127, 205, 255, 125)
Img1H = _CopyImage(Img1, 33)
_FreeImage Img1
' here it creates the Button image
Img2 = _NewImage(100, 50, 32)
_Dest Img2
Cls , _RGBA32(127, 0, 255, 180)
Color _RGBA32(183, 10, 140, 180), _RGBA32(0, 0, 0, 100)
_PrintString (10, 17), "Click Here"
Img2H = _CopyImage(Img2, 33)
_FreeImage Img2
' it creates image of popup from screen 0
Img3 = _NewImage(112, 64, 32)
_Dest Img3
Color _RGBA32(211, 166, 6, 255), _RGBA32(44, 44, 255, 255)
_PrintString (1, 1), "New.....Ctrl+N"
_PrintString (1, 16), "Open....Ctrl+O"
_PrintString (1, 32), "Close...Ctrl+X"
_PrintString (1, 48), "Quit....Ctrl+Q"
Img3H = _CopyImage(Img3, 33)
_FreeImage Img3

Screen 0
' inizialization and main loop
_Dest 0
Color 11, 3
Cls , 2
X = 0
Y = 0
Xm = 0
Ym = 0
Mb = 0
Do
    Cls , 2
    Locate 1, 1: Print "Left click to show popup menu"; ' it shows help on first line of text
    _PutImage (300, 300), Img2H, 0 ' button
    If _MouseInput Then
        X = _MouseX
        Y = _MouseY
        If _MouseButton(1) Then Mb = 1
        If _MouseButton(2) Then Mb = 2
    End If
    If Mb = 1 Then
        If X < 1 Or X + 13 > 80 Or Y < 1 Or Y + 3 > 24 Then
            Beep ' mouse's popup menu goes out of window's area
        Else
            Xm = X: Ym = Y ' X and Y  for popup and hovering menu
            ' popup menu
        End If
        Mb = 0
    End If
    If Xm And Ym Then
        _PutImage (1 + ((Xm - 1) * 8), 1 + ((Ym - 1) * 16)), Img3H, 0
        If (X >= Xm And X <= Xm + 13) And (Y >= Ym And Y <= Ym + 3) Then
            _PutImage ((Xm - 1) * 8, (Y - 1) * 16), Img1H, 0 ' hover / selection item of popup menu
        End If
    End If
    _Display
Loop Until Mb = 2
_FreeImage Img1H
_FreeImage Img2H
_FreeImage Img3H
End

the behaviour is the same, but we don't waste ram blocking pieces of this. 
In a large or intensive program that makes software images and convert them into hardware accellerated images, the management of unused software images makes the difference in performance of the application!

I must think that the same rule stands for re-using the same handle for more different software images. We must free ram from previous image before using again the same handle for another _NEWIMAGE!

explicative code:
Code: (Select All)

Dim As Long Img, Scr
Dim As Integer Counter
Scr = _NewImage(800, 600, 32)
Screen Scr
_Title "Freeimage for software images"
Img = _NewImage(100, 100, 32)
_Dest Img
For Counter = 1 To 10 Step 2
    Circle (50, 50), Counter * 2, _RGBA32(Counter + (Rnd * 200), Counter + (Rnd * 200), Counter + (Rnd * 200), 255)
Next Counter
_PutImage (100, 150), Img, 0,
_FreeImage Img

Img = _NewImage(200, 200, 32)
_Dest Img
For Counter = 10 To 100 Step 10
    Line (20 + Counter, 20 + Counter)-Step(80, 80), _RGBA32(Counter + (Rnd * 200), Counter + (Rnd * 200), Counter + (Rnd * 200), 255), B
Next Counter
_PutImage (100, 300), Img, 0,
_FreeImage Img

Img = _NewImage(300, 200, 32)
_Dest Img
For Counter = 1 To 50 Step 5
    Line (20 + Counter, 20 + Counter)-Step(100, 30), _RGBA32(Counter + (Rnd * 200), Counter + (Rnd * 200), Counter + (Rnd * 200), 255)
Next Counter
_PutImage (300, 350), Img, 0,
_FreeImage Img

End
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  about Hardware Images and _DisplayOrder,Help! qbfans 11 541 02-11-2026, 07:10 AM
Last Post: SMcNeill
  Nth problem with hardware images Ikerkaz 9 471 01-23-2026, 02:58 PM
Last Post: bplus
  Hardware images questions Dav 5 460 12-04-2025, 04:18 PM
Last Post: Pete
  Hardware images...Talk to me! Unseen Machine 5 722 09-22-2025, 11:12 PM
Last Post: TempodiBasic
  Transparency with Hardware Images NakedApe 8 1,018 07-10-2025, 09:47 AM
Last Post: Pete

Forum Jump:


Users browsing this thread: 1 Guest(s)