Author |
Topic: New EVENTLIB library (Read 1625 times) |
|
admin
Administrator
member is offline


Posts: 1145
|
 |
New EVENTLIB library
« Thread started on: Mar 10th, 2012, 10:17am » |
|
I have written a new BB4W library EVENTLIB:
http://tech.groups.yahoo.com/group/bb4w/files/Libraries/EVENTLIB.BBC
This library is intended to address the issues discussed in these recent threads:
http://tech.groups.yahoo.com/group/bb4w/message/16863 http://tech.groups.yahoo.com/group/bb4w/message/17189 http://tech.groups.yahoo.com/group/bb4w/message/17397 http://tech.groups.yahoo.com/group/bb4w/message/17573
The EVENTLIB library is extremely simple; it consists of only three procedures as follows:PROC_eventinit: This initialises the library and sets up a 32-event FIFO queue. Importantly, it can be called multiple times so in a modular program each section of code needing to receive event notifications can call it independently. All the ON... events except ON CLOSE are trapped (ON MOUSE, ON MOVE, ON SYS and ON TIME).
PROC_eventregister(WM_xxxx, PROChandler()): This registers a procedure to be called when the specified event occurs; the event is identified by its @msg% value. PROC_eventregister can be called multiple times with the same event identifier, in which case all the specified handlers will be called sequentially. The handler needs to be defined to receive three parameters as follows:
Code: DEF PROChandler(msg%, wparam%, lparam%) PROC_eventpoll: This simply polls the queue to see if any events are pending, and if so calls their registered handlers (if any) in the sequence in which the events occurred. If multiple handlers are registered for an event, they are all called (the last one registered is called first). Typically a program will wait in a polling loop such as:
Code: REPEAT
PROC_eventpoll
WAIT 0
UNTIL FALSE If you need to be informed that the event queue overflowed, you can register a handler for that by specifying an event ID of zero:
Code: PROC_eventregister(0, PROCoverflow()) Despite the library's simplicity it is quite powerful, and goes a long way to solving the problem of distributing events to multiple handlers (potentially in multiple libraries). It is designed to use only a small amount of memory.
Here's a simple test program illustrating its use:
Code: WM_MOVE = 3
WM_SIZE = 5
WM_TIMER = 275
WM_LBUTTONDOWN = 513
WM_RBUTTONDOWN = 516
INSTALL @lib$+"EVENTLIB"
PROC_eventinit
PROC_eventregister(WM_TIMER, PROCtimer())
PROC_eventregister(WM_TIMER, PROCanothertimer())
PROC_eventregister(WM_MOVE, PROCmove())
PROC_eventregister(WM_SIZE, PROCsize())
PROC_eventinit
PROC_eventregister(WM_LBUTTONDOWN, PROCmouse())
PROC_eventregister(WM_RBUTTONDOWN, PROCmouse())
PROC_eventregister(0, PROCoverflow())
REPEAT
PROC_eventpoll
WAIT 0
UNTIL FALSE
END
DEF PROCtimer(M%, W%, L%)
PRINT "Timer fired: "~ M% W% L%
ENDPROC
DEF PROCanothertimer(M%, W%, L%)
PRINT "Timer fired (2) ";
ENDPROC
DEF PROCmove(M%, W%, L%)
PRINT "Window moved: "~ M% W% L%
ENDPROC
DEF PROCsize(M%, W%, L%)
PRINT "Window resized: "~ M% W% L%
ENDPROC
DEF PROCmouse(M%, W%, L%)
PRINT "Mouse clicked: "~ M% W% L%
ENDPROC
DEF PROCoverflow(M%, W%, L%)
PRINT "Event queue overflowed!!"
ENDPROC Richard.
|
|
Logged
|
|
|
|
dsquare
New Member
member is offline


Posts: 2
|
 |
Re: New EVENTLIB library
« Reply #1 on: Dec 10th, 2015, 7:10pm » |
|
I am new to BB4W and am using an old favourite of mine (LIFE) to learn programming in Windows. My original experience with this stuff was a LONG time ago. The EVENTLIB example works just fine and would do what I need for selecting an area of my grid, IF, the LBUTTONUP worked as well as the LBUTTONDOWN. I have set WM_LBUTTONUP = 514 as I believe this is the right msg but I get no events when letting the left mouse button up. I assume there is more to this, but maybe this will not work for some other reason. I am running the example code to do this test.
|
|
Logged
|
BB4W NEWBIE
|
|
|
Zaphod
Guest
|
 |
Re: New EVENTLIB library
« Reply #2 on: Dec 11th, 2015, 12:21pm » |
|
The message code 514 is not passed onto the user so you cannot get this event notification that way. However, the mouse up up may result in a WM_COMMAND event depending what you are over when you click.
If you need to know when the mouse key is released then you would use the mouse down event to start a polling loop of the mouse button via INKEY(-10) and see what the state of the button is. Or you could start polling MOUSE. The 513 interrupt lets you know the mouse position or you can get that from the MOUSE command. Don't forget to put a WAIT in the polling loop or you will use 100% of CPU time for one processor core.
|
|
Logged
|
|
|
|
dsquare
New Member
member is offline


Posts: 2
|
 |
Re: New EVENTLIB library
« Reply #3 on: Dec 11th, 2015, 4:09pm » |
|
Thanks for the update. I suspected that. I saw some code that was doing what you suggested but wasn't sure I had to do it that way. Dave
|
|
Logged
|
BB4W NEWBIE
|
|
|
RNBW
New Member
member is offline


Gender: 
Posts: 19
|
 |
Re: New EVENTLIB library
« Reply #4 on: Dec 12th, 2015, 11:37am » |
|
Quote:
All I get from the link is "Oops Invalid Path"
When I go into /bb4w/files/Libraries I can't find EVENTLIB.BBC
|
|
Logged
|
|
|
|
Zaphod
Guest
|
 |
Re: New EVENTLIB library
« Reply #5 on: Dec 12th, 2015, 5:48pm » |
|
I believe that Eventlib was part of the distribution in Version 6. If you haven't upgraded then you may not have it otherwise it should already be in your Lib folder. Richard usually takes it down when it gets included in a distribution. However, some of the links in the wiki seem to be missing as well. There are also some Event libraries by others in the Temp folder if you are just experimenting. The Event queue and event handling are similar to techniques Richard has used elsewhere.
|
|
Logged
|
|
|
|
RNBW
New Member
member is offline


Gender: 
Posts: 19
|
 |
Re: New EVENTLIB library
« Reply #6 on: Dec 12th, 2015, 8:05pm » |
|
My mistake. I should have looked at the date of Richard's post. I thought it was an update to BB4W V6 EVENTLIB.BBC. But I see now that dsquare's post was in response to a much earlier posting. All resolved!
|
|
Logged
|
|
|
|
|