About Monkey 2 › Forums › Monkey 2 Programming Help › [solved] letterbox border color
This topic contains 8 replies, has 3 voices, and was last updated by jihem 1 year ago.
-
AuthorPosts
-
February 5, 2017 at 8:08 pm #6961
Hi,
How do you change the border color of the letterbox (in fullkscreen mode) ?
How can I activate fullscreen at startup ? (uncommenting Self.BeginFullscreen() in the new method doesn’t work)
Kind regards,
jihemMonkey
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253#Import "<std>"#Import "<mojo>"#Import "assets/splash.png"Using std..Using mojo..Class Splash Extends WindowField image:ImageMethod New()Super.New("Splash",800,600,Null)image=Image.Load( "asset::splash.png" )image.Handle=New Vec2f( .5,.5 )Self.Layout="letterbox"Self.Style.BackgroundColor=New Color(52, 48, 39)Self.MinSize=New Vec2i(800,600)Self.MaxSize=New Vec2i(800,600)Self.ClearColor=Color.Black ' New Color(52, 48, 39,0)Mouse.PointerVisible=False'Self.BeginFullscreen()EndMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender()canvas.Clear(Color.Black) 'New Color(52, 48, 39,0)canvas.DrawImage(image,400,300)EndMethod OnKeyEvent( event:KeyEvent ) OverrideIf event.Type=EventType.KeyDown ThenIf event.Key=Key.Enter And event.Modifiers & Modifier.AltIf Not Self.Fullscreen ThenSelf.BeginFullscreen()ElseSelf.EndFullscreen()EndEndIf event.Key=Key.EscapeApp.Terminate()EndEndEndEndFunction Main()New AppInstanceNew SplashApp.Run()EndFebruary 5, 2017 at 11:03 pm #6964You need to use “WindowFlags.Fullscreen” when you create the window for fullscreen:
Monkey
123456789101112Method New()Super.New("Splash",800,600,WindowFlags.Fullscreen)image=Image.Load( "asset::splash.png" )image.Handle=New Vec2f( .5,.5 )Self.Layout="letterbox"Self.Style.BackgroundColor=New Color(52, 48, 39)Self.MinSize=New Vec2i(800,600)Self.MaxSize=New Vec2i(800,600)Self.ClearColor=Color.Black ' New Color(52, 48, 39,0)Mouse.PointerVisible=False'Self.BeginFullscreen()EndI’m not sure about the border, it will be somewhere along these lines i think:
Monkey
12Self.Style.BorderColor = New Color(1,1,1,1)Self.Style.Border = New Recti(5, 5, 5, 5)Also, note that color ranges from 0-1 for example red would be: New Color(1, 0 , 0, 1)
February 6, 2017 at 8:37 am #6968Thanks
The border color is set with ClearColor. I was using wrong args: 52, 48, 39 => 52/255, 48/255, 39/255.
Monkey
1234567891011Method New()Super.New("Splash",800,600,Null) ' Flags.Fullscreenimage=Image.Load( "asset::splash.png" )image.Handle=New Vec2f( .5,.5 )Self.Layout="letterbox"Self.ClearColor=New Color(0.2039,0.1882,0.1529,1) ' 52 48 39Self.Style.BackgroundColor=Color.BlackSelf.MinSize=New Vec2i(800,600)Self.MaxSize=New Vec2i(800,600)Mouse.PointerVisible=FalseEndWindowFlags.Fullscreen and Self.BeginFullscreen aren’t working in the New method. The Window is fullscreen but display nothing except the ClearColor everywhere… ?!
February 7, 2017 at 12:26 am #6975If you use the ‘letterbox’ layout, you should also implement ‘OnMeasure’.
This returns the ‘virtual’ size of the letterbox, while the size passed to the window constructor is the actual physical size of the window (or fullscreen).
Have a look at the viewlayout.monkey2 banana. Also, I tweaked your code above:
Monkey
12345678910111213141516171819202122232425262728293031323334353637383940414243444546Namespace myapp#Import "<std>"#Import "<mojo>"Using std..Using mojo..Class MyWindow Extends WindowMethod New()Super.New( "Splash",800,600,WindowFlags.Fullscreen )Self.Layout="letterbox"Self.ClearColor=New Color( 0.2039,0.1882,0.1529,1 ) ' 52 48 39Mouse.PointerVisible=FalseEndMethod OnMeasure:Vec2i() OverrideReturn New Vec2i( 512,283 )EndMethod OnRender( canvas:Canvas ) OverrideRequestRender()canvas.DrawText( "Hello World!",Width/2,Height/2,.5,.5 )EndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndFebruary 7, 2017 at 2:00 pm #6979Thanks
OnMeasure helps. Now the app starts in fullscreen mode and shows the picture but… the border color of the letterbox is not set (always black). If you use [Alt]-[Enter] to switch in windowed mode, then again to switch back in fullscreen mode the border color is set properly (?!).Monkey
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253#Import "<std>"#Import "<mojo>"#Import "assets/splash.png"Using std..Using mojo..Class Splash Extends WindowField image:ImageMethod New()Super.New("Splash",800,600,WindowFlags.Fullscreen)image=Image.Load( "asset::splash.png" )image.Handle=New Vec2f( .5,.5 )Self.Layout="letterbox"Self.ClearColor=New Color(0.2039,0.1882,0.1529,1) ' 52 48 39Self.Style.BackgroundColor=Color.BlackMouse.PointerVisible=FalseEndMethod OnMeasure:Vec2i() OverrideReturn New Vec2i( 800,600 )EndMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender()canvas.DrawImage(image,Self.Width/2,Self.Height/2)EndMethod OnKeyEvent( event:KeyEvent ) OverrideIf event.Type=EventType.KeyDown ThenIf event.Key=Key.Enter And event.Modifiers & Modifier.AltIf Not Self.Fullscreen ThenSelf.BeginFullscreen()ElseSelf.EndFullscreen()EndEndIf event.Key=Key.EscapeApp.Terminate()EndEndEndEndFunction Main()New AppInstanceNew SplashApp.Run()EndFebruary 7, 2017 at 8:42 pm #7003Well, there is no border as both the window and virtual res are 800,600, so the virtual display fits’ perfectly’. There will in fact be no border for any virtual res with the same aspect ratio as the window res.
Your window’s Style.BackgroundColor is also overwriting the window clear color. Style.BackgroundColor defaults to Color.None (ie: fully transparent) so normally you only ever see Window.ClearColor. This implies Style.BackgroundColor is drawn *after* ClearColor – in fact, ClearColor is drawn *before* everything else, as it’s a window property.
My advice would be to skip Style.BackgroundColor altogether for now and stick with canvas.Clear(), eg:
Monkey
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455#Import "<std>"#Import "<mojo>"Using std..Using mojo..Class Splash Extends WindowMethod New()Super.New("Splash",800,600,WindowFlags.Fullscreen)Self.Layout="letterbox"Self.ClearColor=Color.Green' Self.Style.BackgroundColor=Color.Red 'One way to clear virtual area, but let's use canvas.Clear in OnRender().Mouse.PointerVisible=FalseEndMethod OnMeasure:Vec2i() OverrideReturn New Vec2i( 800,400 ) 'Note: Different aspect ratio to window size or no border!EndMethod OnRender( canvas:Canvas ) OverrideRequestRender()canvas.Clear( Color.Red ) 'Another way to clear virtual area.EndMethod OnKeyEvent( event:KeyEvent ) OverrideIf event.Type=EventType.KeyDown ThenIf event.Key=Key.Enter And event.Modifiers & Modifier.AltIf Not Self.Fullscreen ThenSelf.BeginFullscreen()ElseSelf.EndFullscreen()EndEndIf event.Key=Key.EscapeApp.Terminate()EndEndEndEndFunction Main()New AppInstanceNew SplashApp.Run()EndFebruary 8, 2017 at 12:10 pm #7017Thanks for spending time with me
With your sample, there is a black border (left and right) at startup. If you press [alt][enter] to switch in windowed mode and another time to return in fullscreen it disappears (and the red rectangle is bigger).
Attachments:
February 8, 2017 at 9:19 pm #7023Thanks for spending time with me
No problem at all – I want people to hammer this stuff and ask questions so I can make sure it works (and makes some sort of sense!) and so far it seems to be, so thank you!
With your sample, there is a black border (left and right) at startup.
Not doing quite the same thing here, but I think this is the difference between ‘real’ fullscreen and ‘fake’ fullscreen.
When you use WindowFlags.Fullscreen to create the window, it actually causes the display resolution to change. However, BeginFullScreen() with no parameters (as in the Alt-Tab handler) instead takes you into fake fullscreen, where the window is really just resized to the size of the desktop.
Try using BeginFullScreen( 800,600,60 ) instead in the Alt-Tab handler – this should also cause a display mode change.
This highlights a bit of a limitation with using WindowFlags.Fullscreen to go into fullscreen mode – you can’t select refresh rate this way.
February 9, 2017 at 5:07 pm #7064Thanks
I understand the difference between the real/fake fullscreen modes. Now, with BeginFullScreen( 800,600,60 ) I can use the same fullscreen mode. -
AuthorPosts
You must be logged in to reply to this topic.