Here is my main loop :
Repeat
OldEvent = ActualEvent : ActualEvent = 0 : Counter = 0
Repeat
GetEvent : NewEvent = EventType() : Inc Counter, 1
If NewEvent = LEFTBUTTON_UP Or NewEvent = RIGHTBUTTON_UP Then ActualEvent = NewEvent
If ( NewEvent = MOUSE_CLICK Or NewEvent = RIGHTMOUSE_CLICK ) And ActualEvent = 0 Then ActualEvent = NewEvent
If NewEvent = MOUSE_MOVE And ActualEvent = 0 Then ActualEvent = NewEvent
If ActualEvent = MOUSE_CLICK
NewGadget = EventSource()
If NewGadget = TMolderGAD.Brush01 : X4ETM_SetBrush( 1, 1, 100, -1 ) : ActualEvent = 0 : Endif
If NewGadget = TMolderGAD.Brush02 : X4ETM_SetBrush( 2, 7, 100, -1 ) : ActualEvent = 0 : Endif
If NewGadget = TMolderGAD.Brush03 : X4ETM_SetBrush( 2, 13, 100, -1 ) : ActualEvent = 0 : Endif
If NewGadget = TMolderGAD.Brush04 : X4ETM_SetBrush( 2, 19, 100, -1 ) : ActualEvent = 0 : Endif
If NewGadget = TMolderGAD.Brush05 : X4ETM_SetBrush( 2, 25, 100, -1 ) : ActualEvent = 0 : Endif
If NewGadget = TMolderGAD.Brush11 : X4ETM_SetBrush( -1, -1, 0, 5 ) : ActualEvent = 0 : Endif
If NewGadget = TMolderGAD.Brush12 : X4ETM_SetBrush( -1, -1, 0, 25 ) : ActualEvent = 0 : Endif
If NewGadget = TMolderGAD.Brush13 : X4ETM_SetBrush( -1, -1, 0, 45 ) : ActualEvent = 0 : Endif
If NewGadget = TMolderGAD.Brush14 : X4ETM_SetBrush( -1, -1, 0, 65 ) : ActualEvent = 0 : Endif
If NewGadget = TMolderGAD.Brush15 : X4ETM_SetBrush( -1, -1, 0, 85 ) : ActualEvent = 0 : Endif
If NewGadget = TMolderGAD.Import
X4E_IntTerrainImport() : ActualEvent = 0
Endif
If NewGadget = TMolderGAD.Export
X4E_IntTerrainExport() : ActualEvent = 0
Endif
If NewGadget = TMolderGAD.Clear
X4E_IntTerrainClear() : ActualEvent = 0
Endif
Endif
Until NewEvent = 0 Or ActualEvent > 0 Or Counter > 10
RETOUR = X4ETM_Plot( ActualEvent )
Sync
Until SpaceKey() = 1
I try to read all events availables on each loop.
I generally get counter = 4 at max.
All we have to decide is what to do with the time that is given to us.