[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [MiNT] SV: SV: some gem question
On Sun, 2005-10-02 at 15:55 +0200, Jo Even Skarstein wrote:
> You then call x_graf_slidebox() whenever the mousebutton is clicked
> (but not released ofcourse) on a slider-object.
>
> I haven't implemented a slider this way, but I did this to implement a
> multitasking-friendly version of graf_watchbox(), and it works very
> well.
>
> Jo Even
You could also use a callback approach, which I think is much cleaner,
but likely not as common on the Atari (except for Windom based apps).
Generally, your main event loop checks some internal state information
before calling evnt_multi. Function to add and remove events would
exist, so when the slider is created it would call a function that says
"call function y when the mouse is down over me". The evnt_multi
information will suggest that a mouse button was pressed and is being
held down over some object. It finds the object and which function
should be called, and does it. Finding the function to be called can be
a linked list, hash, array of structures, etc.
The called function looks at the location of the mouse and saves it. It
then asks the event loop to be notified if the mouse moves and when the
button goes back up. When the mouse moves it calculates the offset
from the saved position to the stored position and adjusts the slider,
possibly causing a redraw. When the mouse goes up, it tells the event
loop it no longer needs mouse movement or mouse up calls.
The difference is that instead of multiple event_multi() calls and a
central dispatcher to call for non-mouse-move events, you have a central
event_multi() that can actually call multiple functions every time the
mouse moves.
I believe WinDom handles most if not all of the above for you. Add the
ability to handle socket and pipe IO from inside the main WinDom event
loop using some of the tricks we've talked about and you'd get a nice
general-purpose event-based system.