About Monkey 2 › Forums › Monkey 2 Code Library › Realtime resizing of MojoX apps on macOS
This topic contains 1 reply, has 1 voice, and was last updated by Danilo 3 days, 5 hours ago.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
January 15, 2019 at 8:30 pm #15912
Here is a code to prevent the stretching of the window content while resizing the window on macOS.
I added the code to my Monkey2-Codes on github.
Monkey
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139#Import "<std>" ' Realtime resize test for Monkey2 MojoX apps#Import "<mojo>" '#Import "<mojox>" ' We are installing the SdlEventFilter here' and update the main Monkey2 SDL window in the handler' to prevent stretching of the window content' while the user resizes the window.'' Danilo Krahn, 2019/01/15' - Monkey2 2018-09, Mx2cc version 1.1.15' - tested on macOS MojaveFunction InstallWindowResizeFilter( _win:mojo.app.Window, _updateInterval:UInt = 1 )Global window_ResizeFilter:mojo.app.WindowGlobal counter_ResizeFilter:UIntGlobal interval_ResizeFilter:UIntwindow_ResizeFilter = _wininterval_ResizeFilter = _updateInterval = 0 ? 1 Else _updateIntervalmojo.app.App.SdlEventFilter =Lambda( eventPtr:sdl2.SDL_Event Ptr )If eventPtr->type = sdl2.SDL_WINDOWEVENTSelect eventPtr->window.eventCase sdl2.SDL_WINDOWEVENT_RESIZED'' This is a handler for realtime window resizing''======================================================' SDL stuff:Local sdlWindowID := eventPtr->window.windowIDLocal sdlWindow := sdl2.SDL_GetWindowFromID(sdlWindowID)'SDL_SetWindowInputFocus(sdlWindow)sdl2.SDL_CaptureMouse(sdl2.SDL_TRUE)' Monkey2 stuffcounter_ResizeFilter += 1' we do this only as long as the left mouse button is pressedIf window_ResizeFilter And( sdl2.SDL_GetGlobalMouseState(Null,Null) & sdl2.SDL_BUTTON_LMASK )Local frame:std.geom.Recti = window_ResizeFilter.Frameframe.Size = New std.geom.Vec2i(eventPtr->window.data1,eventPtr->window.data2)window_ResizeFilter.Frame = framewindow_ResizeFilter.ContentView.MakeKeyView()'window_ResizeFilter.UpdateWindow(False)' update window content only every '_updateInterval' timeIf counter_ResizeFilter <> 0 And( counter_ResizeFilter Mod interval_ResizeFilter ) = 0window_ResizeFilter.RequestRender()mojo.app.App.MainLoop()EndifEndif'======================================================End SelectEndIfEnd LambdaEndClass Program Extends mojo.app.WindowMethod New()Super.New( "Monkey2 Realtime Window Resize Test",800,600,mojo.app.WindowFlags.HighDPI |mojo.app.WindowFlags.Resizable )EndPrivateMethod OnCreateWindow() OverrideInstallWindowResizeFilter(Self) ' update window on every resize step'InstallWindowResizeFilter(Self,2) ' update window on every 2nd resize stepdockingView = New mojox.DockingViewnamespacesView = New mojox.TreeViewhtmlView = New mojox.HtmlViewmessageView = New mojox.TextView( "Monkey2 Realtime Window Resize Test started.~n" )messageView.ReadOnly = TrueLocal style:mojo.app.Stylestyle = messageView.Stylestyle.BackgroundColor = std.graphics.Color.DarkGreystyle = htmlView.Stylestyle.BackgroundColor = std.graphics.Color.DarkGreystyle.TextColor = std.graphics.Color.WhiteLocal txt:String = "<!DOCTYPE html><html><head>"+"<meta charset=~qutf-8~q />"+" <style>"+" h1 { color: red; } "+" body { color: #808080; } "+" strong { color: #000000; } "+" </style>"+"</head>"+"<body> <h1>Hello</h1> <strong>strong</strong> text<p>"+"</body></html>"For Local i := 0 To 1000txt += "a b c d e f g 0 1 2 3 4 5 6 7 8 9 "NexthtmlView.HtmlSource = txtdockingView.AddView( namespacesView, "left", "250", True )dockingView.AddView( messageView, "bottom", "80", True )dockingView.ContentView = htmlViewSelf.ContentView = dockingViewdockingView.ContentView.MakeKeyView()EndField dockingView : mojox.DockingViewField namespacesView : mojox.TreeViewField htmlView : mojox.HtmlViewField messageView : mojox.TextViewEndFunction Main()New mojo.app.AppInstanceNew Programmojo.app.App.Run()EndJanuary 16, 2019 at 12:39 pm #15922Updated the code:
- added _updateInterval
If redrawing the resized window in realtime becomes too slow, we can now use ‘_updateInterval’ to change how often the window content is completely refreshed.
Monkey
12_updateInterval = 1 ' window is updated at every resize step_updateInterval = 5 ' window content is only resized every 5th step, the other 4 steps the content is stretched -
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic.