About Monkey 2 › Forums › Monkey 2 Programming Help › Window.ClearColor vs canvas.Clear(color)
This topic contains 3 replies, has 3 voices, and was last updated by
therevills 1 year, 4 months ago.
-
AuthorPosts
-
November 21, 2017 at 8:05 am #11878
I’m using a virtual resolution in letterbox mode and I want to change the background colour from black to a light bluish colour.
When using ClearColor and when I “fade to black” using DrawRect(0, 0, width, height) the “border” color is still the bluish colour:
Monkey123bgColor = New Color(109.0/255.0, 194.0/255.0, 202/255.0)Window.ClearColor = bgColorIf I keep the ClearColor as black and use canvas.Clear to have my background as the bluish colour the borders keep black, which is what I want but there is a performance hit:
Monkey123canvas.Clear(bgColor)Is there any other solutions I am missing?
Monkey1234567891011121314151617181920212223242526272829303132333435363738394041424344454647Namespace myapp#Import "<std>"#Import "<mojo>"Using std..Using mojo..Const Size:=New Vec2i( 320,200 )Class MyWindow Extends WindowField _ratio:Float = 1Method New()Super.New( "My Window",800,600,WindowFlags.Resizable )Layout="letterbox"ClearColor = New Color(109.0/255.0, 194.0/255.0, 202/255.0)EndMethod OnRender( canvas:Canvas ) Override_ratio -= 0.005If _ratio < 0 Then _ratio = 1App.RequestRender()canvas.Color = Color.Whitecanvas.DrawText( "Hello World",Width/2,Height/2,.5,.5 )canvas.Color = Color.Blackcanvas.Alpha = 1 - _ratiocanvas.DrawRect(0,0,Width,Height)canvas.Color = Color.Whitecanvas.Alpha = 1EndMethod OnMeasure:Vec2i() OverrideReturn SizeEndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndAttachments:
November 21, 2017 at 10:22 am #11884use clearcolor for the entire window color
with your ‘own’ window you will need to clear the color to black first
canvas.Color = Color.Black
canvas.DrawRect( 0, 0, Width, Height )then the alpha stuff will fade to black as you wanted
November 21, 2017 at 9:17 pm #11891Here’s a little demo of manually drawing letterbox borders yourself.
This allows you to turn of windows clearing so there is 0 overdraw, I’m not sure it’ll be significantly faster, or even any faster at all as window clearing should be pretty fast. But it’s still nice to be able to customize letterbox borders…
If it is significantly faster, it’s probably worth adding an option similar to Window.ClearEnabled to automate it.
It uses the currently undocumented View.RenderBounds property, but it should be pretty obvious what this does, ie: it’s the view ‘bounds’ in windows coordinates. View bounds is view rect + padding + border + margin.
Monkey12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576Namespace myapp#Import "<std>"#Import "<mojo>"Using std..Using mojo..Class GameView Extends ViewMethod New()Layout="letterbox"EndMethod OnRender( canvas:Canvas ) OverrideRequestRender()canvas.Clear( Color.Blue )canvas.DrawText( "Hello World!",Width/2,Height/2,.5,.5 )EndMethod OnMeasure:Vec2i() OverrideReturn New Vec2i( 320,200 )EndEndClass MyWindow Extends WindowMethod New()Super.New( "VRES test",640,480,WindowFlags.Resizable )Local gameView:=New GameViewContentView=gameViewClearEnabled=FalseEndMethod OnRender( canvas:Canvas ) OverrideLocal rect:=ContentView.RenderBoundscanvas.Color=Color.Red'left border?If rect.Left canvas.DrawRect( 0,0,rect.Left,Height )'right border?If rect.Right<Width canvas.DrawRect( rect.Right,0,Width-rect.Right,Height )'top border?If rect.Top canvas.DrawRect( 0,0,Width,rect.Top )'bottom border?If rect.Bottom<Height canvas.DrawRect( 0,rect.Bottom,Width,Height-rect.Bottom )EndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndNovember 22, 2017 at 8:09 am #11912Thanks Mark, I’ll have a look
-
AuthorPosts
You must be logged in to reply to this topic.
