Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PictureButton Rollover effect
#1
Hi friends
here a simple demo to get a picturebutton with rollover effect

Code: (Select All)

Rem demo of a pictureButton with rollover effect
Rem here we use one image to load and we create the rollover image on fly

DefLng L

Lscreen = _NewImage(800, 600, 32)
Screen Lscreen
_Title "Rollover PictureButton example"
Cls , _RGBA(127, 28, 211, 255)
If _FileExists("QB64bee.jpeg") Then LBee1 = _LoadImage("QB64bee.jpeg") Else _PrintString (10, 200), "Not found QB64bee"
' here we create the second image used for rollover effect
Lbee2 = _NewImage(50, 50, 32)
_Dest Lbee2
Line (0, 0)-(50, 50), _RGBA(227, 72, 17, 255), BF
_PutImage (3, 3)-(45, 45), LBee1, Lbee2
_Dest 0
_PrintString (10, 140), " move mouse over and out of button, press leftclick on the button, press rightclick to quit"
_PutImage (30, 50)-(80, 100), LBee1, Lscreen ' show picturebutton

Do
    If _MouseInput Then
        If InTheMiddle(30, 80, _MouseX) Then
            If InTheMiddle(50, 100, _MouseY) Then
                lbee = Lbee2
            Else
                lbee = LBee1
            End If
        Else
            lbee = LBee1
        End If
        _PutImage (30, 50)-(80, 100), lbee, Lscreen
    End If
    If _MouseButton(1) And lbee = Lbee2 Then Msg$ = " You have clicked on the button" Else Msg$ = Space$(40)

    _PrintString (10, 200), Msg$
Loop Until _MouseButton(2) = -1
End

Function InTheMiddle (min As Integer, max As Integer, value As Integer)
    If min > max Then Swap min, max
    If min < value And value < max Then
        InTheMiddle = -1
    Else
        InTheMiddle = 0
    End If
End Function

please download the attached image or use another of your choice. In this second case, please change the name and path of the image to load with _LOADIMAGE.
then
copy and paste this code into QB64IDE and save it in the same folder of the image downloaded or choosen by you.
At the end press F5 and see the result.

[Image: QB64bee.jpg]
Reply
#2
+1 for using TheBOB's QB64 logo design!

Pete Smile
Shoot first and shoot people who ask questions, later.
Reply
#3
Heart Smile
(10-19-2024, 04:22 AM)Pete Wrote: +1 for using TheBOB's QB64 logo design!

Pete Smile
Reply
#4
For screens with a lot of controls/buttons with click/hover/rollover effect I've used the alpha channel a lot to detect if the mouse was over a certain area.
You can make your controls alpha-color &HFE and downwards and then check with _Alpha32(Point(_mouseX,_mouseY)) for the alpha value...
45y and 2M lines of MBASIC>BASICA>QBASIC>QBX>QB64 experience
Reply
#5
(10-22-2024, 10:55 AM)mdijkens Wrote: For screens with a lot of controls/buttons with click/hover/rollover effect I've used the alpha channel a lot to detect if the mouse was over a certain area.
You can make your controls alpha-color &HFE and downwards and then check with _Alpha32(Point(_mouseX,_mouseY)) for the alpha value...

this is a good trick! Using the information brought by memory screen for evaluating  the position of an object on the screen from its graphic rappresentation. (Using the screen as a map!)
it implies that alpha channel is exclusive for specific graphic areas.
Reply




Users browsing this thread: 1 Guest(s)