Creating a mouse-over pop-out window

1 view
Skip to first unread message

EagleEye

unread,
Aug 24, 2008, 8:53:31 PM8/24/08
to EEGUI
In my online bridge game, I wanted to create a news area that would
pop up when you hovered over the title bar for it, stay as long as the
mouse is over it (or to be specific, over it or any child in it), then
after the mouse was no longer over it (or any of its children) for
more than 1 second (1000 ms), the window would slide back to where it
started.

Below you will find my code for accomplishing this.

Private SW As Stopwatch
Private SWThread As Threading.Thread

I create a stopwatch, and a thread to handle the stopwatch logic.

Private Sub TitleMouseOver(ByVal ctrl As guiControlBase, ByVal md
As MouseStates) Handles TitleBar.MouseOver
Height = Parent.Height / 2
Me.EffectSlide(New Point(Parent.Right - Width, Parent.Height -
Height), 1000)
SWThread = New Threading.Thread(AddressOf SWHandler)
SWThread.Start()
End Sub

This is my MouseOver handler that starts the slide effect to show the
window. (It's at the bottom right of the window to start, 250 wide,
and about 30 high (or the height of the title bar), so all that is
showing of the window is a 250x30 titlebar, with the rest of the
window "hanging off" the render area, and not being shown.

We immediately start checking to see if the mouse is still over any
child of the entire window... Children could consist of:

Title Bar (label)
Message Container (listbox)
Message container children (wrapping text boxes)


Here we have the thread sub...

Private Sub SWHandler()
SW = Stopwatch.StartNew
While SW.ElapsedMilliseconds < 1000
Threading.Thread.Sleep(10)
If ChildIsMouseOver(Me) Then SW = Stopwatch.StartNew
End While
EffectSlide(New Point(Parent.Right - Width, Parent.Height -
TitleBar.Height), 1000)
End Sub

So, we start a new stopwatch, and we start looping, pausing for 10 ms
each iteration so it's not spiking the processor. Then all of the
children are checked in a recursive boolean function, like so:

Private Function ChildIsMouseOver(ByVal P As guiControlBase) As
Boolean
For Each Child As guiControlBase In P.Children
If Child.isMouseOver Then Return True
If Child.Children.Count > 0 Then Return
ChildIsMouseOver(Child)
Next
End Function

(Note "P" is short for parent in this sub).

Back to the thread sub... if any child, grandchild, great grandchild,
great great gandchild, etc... has "isMouseOver = true", the function
will return true.

By default, boolean functions return false, so it's not necessary to
specify that.

If it returns true, however, the stopwatch is reset, keeping the loop
going (because SW.ElapsedMilliseconds is set back to 0).

This is a nice trick to use for auto-pop-ups as well... new message
comes in, pop up a little window that stays up for 2 seconds, but will
stay up longer should the player want to hover the mouse over it to
"hold" it there so they can read the whole thing.
Reply all
Reply to author
Forward
0 new messages