Events in BlitzMax
BlitzMax Forums/BlitzMax Programming/Events in BlitzMax
| ||
I am trying to migrate my BlitzPlus app to BlitzMax. I don't see any of the routines to handle system events in BlitzMax. In particular I have the following that works well in BlitzPlus, but cannot see how to do it in Max: <codebox> Repeat event = WaitEvent() Select event Case EVENT_KeyDown gKeyPressed = EventData() Select gKeyPressed Case KEY_Escape GameShutDown() Case KEY_F If gFullScreen=MODE_FullScreen Then gFullScreen = MODE_Windowed Else gFullScreen = MODE_FullScreen EndIf SetupDisplay() End Select Case EVENT_MouseDown Select EventData() Case 1 gLeftMouseDown = True Case 2 gRightMouseDown = True End Select Case EVENT_MouseUp Select EventData() Case 1 gLeftMouseDown = False Case 2 gRightMouseDown = False End Select Case EVENT_Close GameShutDown() End Select Until event = EVENT_Timer </codebox> I guess I can do this by programming directly in Windows, but that won't help me when I try and get this running on the Mac. Thanks, - Ken |
| ||
Hmmm, I guess I got the formatting tags wrong for the code box. Is there a post somewhere that lists all of the Forum formatting options? |
| ||
Use [], not <>. |
| ||
BlitzMax is not event based. You have to use IF keyhit(key_left) endif If mousehit(1) endif or keydown/mousedown |
| ||
BlitzMax is not event based. I think you mean that the input handling system (The BRL.System module) is not yet event based. When MaxGUI is released, there will no doubt be an event-based way of handling user input. |
| ||
I vote for structures like thiiiis:Type MyButton Extends Control Field Click:Int( sender:Control, e:EventArgs ) End Type Anyone recognize what it's based on? |
| ||
It's as easy as to have a function pointer in each object that has to throw an event. example: Type MyBaseObject Field OnClick() Method Update() abstract End Method Type Button extends MyBaseObject field x,y,text Method New() ObjectManager.ObjectCollection.AddLast(self) end Method Method Update() If (whatver mouse control for example) and OnClick <> Null then OnClick() End if End Method End Type Type ObjectManager Global ObjectCollection Function DoEvents() For o:BaseObject = eachin ObjectCollection o.Update() Next end Function End Type With this, you can do a code as: ObjectManager.ObjectCollection = New TList Local MyBut:Button MyBut.OnClick = Button_Click_Event while not keyhit(key_escape) ObjectManager.Doevents() Wend Function Button_Click_Event() Notify("Pressed!!!") End Function |
| ||
It's as easy as to have a function pointer in each object that has to throw an event. Absolutely. As someone who's completely new to function pointers, this is the only use for them that I can really see the use of. I've already found a lot of code which can benefit from it in this regard. |
| ||
I suspect that the SendMessage() method in all objects is there to allow for some sort of event-based system. Probably. |
| ||
@Noel - Anyone recognize what it's based on? both .Net and VCL (Delphi) support this methodology (as I'm sure do many others). Cheers, Stu |