Events Notification - MrShoor/AvalancheProject GitHub Wiki
The event notification system is based on FPC/Delphi run-time Dispatch() mechanism. Any object inheriting from TavObject within the objects hierarchy could get a notification from the main engine about a particular event. In order to handle it, the object must declare a message handler
procedure EMWindowDestroy(var msg: TavMessage); message EM_WINDOWDESTROY;
using message keyword to identify the event that the mechanism need to process.
Event Message
Each event message is record, starting with msg identifier ( 32-bit unsigned integer ). msg identifier would specify what the actual message is and the remaining fields must be interpreted of that.
TavSomeMessage = packed record
msg : Cardinal;
... other field
end;
The most common message structure used is TAvMessage.
TavMessage = packed record
msg : Cardinal;
result : boolean;
param : Integer;
sender : TObject;
end;
- msg - contains the code of the event (the engine events are described below)
- param - is the additional data about event. It's event dependent
- sender - the source of the event
- result - the indicate if the message was processed on not
Broadcasting
todo: describe methods
Events
Here's the list of basic events
EM_NONE
EM_NONE = $0000;
EM_UPS (Process Timer Event)
EM_UPS = $0010;
The message is triggered by ProcessTimerEvents method, it's using TAvMessage to propagate the information. param indicates the number of time intervals passed since the last call of the event. The "logical" time passed could be calculated as UpdateStatesInterval * param.
Mouse Input Events
EM_MOUSEDOWN = $0020;
EM_MOUSEUP = $0021;
EM_MOUSEDBLCLICK = $0022;
EM_MOUSEMOVE = $0023;
EM_MOUSEWHEEL = $0024;
Each event is using Mouse event structure (not TavMessage)
TavMouseBtnMessage = packed record
msg : Cardinal;
button : integer;
xPos : integer;
yPos : integer;
wheelShift: integer;
shifts : TShifts;
result : boolean;
end;
The event is typically triggered by an underlying operating system to indicate an input action.
For actual values of the fields see Input Events
(...in the rendering engine... yes. But it's for your own convenience!)
EM_KEYDOWN, EM_KEYUP, EM_CHAR (Keyboard Input)
EM_KEYDOWN = $0030;
EM_KEYUP = $0031;
EM_CHAR = $0032;
EM_WINDOWDESTROY
EM_WINDOWDESTROY = $0100;
The notification is sent whenever the system window is being destroyed. The notification message used TavMessage
- sender - set to null
- param - (reserved)
EM_3D_AFTER_INIT
EM_3D_AFTER_INIT = $0101;
The event is fired right after 3d context has been initialized. The event is called during Init 3D call.
EM_3D_BEFORE_FREE
EM_3D_BEFORE_FREE = $0102;
EM_3D_AFTER_FREE
EM_3D_AFTER_FREE = $0103;
EM_EVENTS_START_CONTROLS
EM_EVENTS_START_CONTROLS = $0200;
EM_EVENTS_END_CONTROLS
EM_EVENTS_END_CONTROLS = $02FF;