Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Rollover Buttons.


sir zach
 Share

Recommended Posts

This is a horribly dated technique. Adding in extra form components is never the best solution.

If you did actually write this, and from looking through the code I doubt this, then you should have no problem writing up a class file which would allow this all to be handled through either BitBlt or DirectDraw.

Here's a much better way of doing things, in DirectDraw7:

```
Private button() as new clsButton
Private buttonCount as byte

Private sub initButtons()
    redim button(0 to buttonCount)

    ' Format for storing button information, use in class.
    button(0).x = [value]
    button(0).y = [value]
    button(0).width = [value]
    button(0).height = [value]
    button(0).state = BUTTON_STATE_NORMAL

    'etc. etc. Either use this to hardcode all button placements, or
    'you could load from a .ini or .xml file.
end sub

```
Then, when you have either a DirectInput mousemove event or a mouse is moved over your form, call a loop which checks each button and sets their state accordingly.

```
Public Sub CheckButtons(ByVal x As Single, ByVal y As Single, ByVal button As Integer)
Dim i As Long

    For i = 0 To MaxButtons
        With button(i)
            If x > .x And x < .x + .Width Then
                If y > .y And y < .y + .Height Then
                    If button = BUTTON_LEFTMOUSE Then ' no idea on the const in vb6.
                        .state = BUTTON_STATE_CLICKED
                        Exit Sub
                    End If
                    .state = BUTTON_STATE_HOVER
                    Exit Sub
                End If
            End If
        End With
    Next
End Sub
```
Then, in your main rendering loop, simply set it to use the class' .x, .y, .height and .width for the destrect. You could even store a srcrect in the class, rather than creating it each loop.

Not only is this much more modular than your program, it allows for on-screen buttons.

Yours,
_Robin_
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...