You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
am just experimenting a bit with the resizeable windows (sdlrendermax2d offers them conveniently). For now the graphics context gets already automatically updated by SDL .. so it scales (keeping aspect ratio) and all this.
But stuff like GraphicsWidth() and others simply return the values of some variables which are not updated when the windows resizes.
Yes, one method would be to have custom callbacks (onWindowResize ...) added or similar stuff. But I am still experimenting what and how to approach all this (eg you can have multiple contexts/canvases in a window etc).
So I wanted to add a hook to listen to EVENT_WINDOWSIZE (which is BBEVENT_WINDOWSIZE which itself listens to the SDL-equivalent). You cannot simply attach a callback to a given eventID (eg EVENT_WINDOWSIZE). You have to add a "hook" (up to 256 hooks at all are allowed as brl.hooks has an artificial limit of 256). So when using brl.event' (and also brl.hooks`) you can only add a hook which itself is a function then receiving ALL events (unfiltered).
So a way to have a callback for this event would be to act similar to brl.eventqueue which itself adds to the EmitEventHook-Event and then has to cast the object into an TEvent, then check the ID of the event if it is of interest.
SuperStrict
Framework Brl.StandardIO
Import SDL.SDLRenderMax2D
'react to window resizes
AddHook(EmitEventHook, WindowResizedHook, Null, -10000)
Graphics 800,600,0,0, SDL_WINDOW_RESIZABLE
Repeat
SetClsColor 100,100,0
Cls
DrawText "Window: " + GraphicsWidth()+"x"+GraphicsHeight(),5,1 * 12
DrawText "Mouse: Virtual=" + TrimFloat(VirtualMouseX(),2)+", "+TrimFloat(VirtualMouseY(),3),5,2 * 12
DrawText " Normal =" + TrimFloat(MouseX(),2)+", "+TrimFloat(MouseY(),3),5,3 * 12
Flip
Until AppTerminate() or KeyHit(KEY_ESCAPE)
'This function will be called as soon as the window resizes
Function WindowResizedHook:Object( id:Int, data:Object,context:Object )
Local ev:TEvent=TEvent( data )
If Not ev Return Null
If ev.id <> EVENT_WINDOWSIZE Then Return Null
print "resize"
End Function
Function TrimFloat:String(value:Float, precision:Int = 2)
Local c:Int = string( int(value) ).length + 1 + precision
Return string(value)[.. c]
End Function
As you see this means if somehow the application triggers 1000 events per second then eg the eventqueue will check all 1000, my custom WindowResizedHook will also check all 1000...
So it is a bit like a "broadcast" system - but unfiltered. If each hook could define what it is interested in, then hooks could be run "by emitted event x" instead of "for all emitted events".
As said - this aside a "callback" in this very situation might be the better approach.
The text was updated successfully, but these errors were encountered:
Heya,
am just experimenting a bit with the resizeable windows (sdlrendermax2d offers them conveniently). For now the graphics context gets already automatically updated by SDL .. so it scales (keeping aspect ratio) and all this.
But stuff like
GraphicsWidth()
and others simply return the values of some variables which are not updated when the windows resizes.Yes, one method would be to have custom callbacks (onWindowResize ...) added or similar stuff. But I am still experimenting what and how to approach all this (eg you can have multiple contexts/canvases in a window etc).
So I wanted to add a hook to listen to
EVENT_WINDOWSIZE
(which is BBEVENT_WINDOWSIZE which itself listens to the SDL-equivalent). You cannot simply attach a callback to a given eventID (egEVENT_WINDOWSIZE
). You have to add a "hook" (up to 256 hooks at all are allowed asbrl.hooks
has an artificial limit of 256). So when usingbrl.event' (and also
brl.hooks`) you can only add a hook which itself is a function then receiving ALL events (unfiltered).So a way to have a callback for this event would be to act similar to
brl.eventqueue
which itself adds to theEmitEventHook
-Event and then has to cast the object into anTEvent
, then check the ID of the event if it is of interest.As you see this means if somehow the application triggers 1000 events per second then eg the eventqueue will check all 1000, my custom
WindowResizedHook
will also check all 1000...So it is a bit like a "broadcast" system - but unfiltered. If each hook could define what it is interested in, then hooks could be run "by emitted event x" instead of "for all emitted events".
As said - this aside a "callback" in this very situation might be the better approach.
The text was updated successfully, but these errors were encountered: