SetVirtualResolution on a MaxGUI canvas?

BlitzMax Forums/BlitzMax Programming/SetVirtualResolution on a MaxGUI canvas?

JaviCervera(Posted 2011) [#1]
Hi guys. I haven't used BlitzMax in a while, but now that I am starting a game in Monkey, I want to use BlitzMax to write the tools I need for my game (basically a scene editor).

The game should run on a virtual resolution of 640x480, with the real screen resolution varying from one to other device. On my scene editor, I have a canvas which shows the scene contents. Despite the size of the canvas (which can change by resizing the window), the contents of the 640x480 scene should always be visible on the whole canvas.

The problem is that I cannot seem to make it work. I have written an example which shows the problem I have:

Import MaxGUI.MaxGUI
Import MaxGUI.Drivers

Local win:TGadget = CreateWindow("Virtual Resolution Test", 0, 0, 640, 480, Null, WINDOW_TITLEBAR | WINDOW_RESIZABLE | WINDOW_CLIENTCOORDS | WINDOW_CENTER)
Local canvas:TGadget = CreateCanvas(0, 0, 640, 480, win)
SetGadgetLayout canvas, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_ALIGNED
CreateTimer(20)

SetGraphics CanvasGraphics(canvas)
SetVirtualResolution 640, 480

Repeat
	Select WaitEvent()
		Case EVENT_APPTERMINATE
			End
		Case EVENT_WINDOWCLOSE
			PostEvent CreateEvent(EVENT_APPTERMINATE)
		Case EVENT_TIMERTICK
			RedrawGadget canvas
		Case EVENT_GADGETPAINT
			SetGraphics CanvasGraphics(canvas)
			Cls
			SetColor Rand(0, 255), Rand(0, 255), Rand(0, 255)
			DrawRect 16, 16, 608, 448
			Flip
	End Select
Forever

This creates a resizable window with a canvas inside it. The virtual resolution is set to 640x480, which is the initial size of the canvas. A rect covering the whole screen except for a 16 pixels margin on every edge is drawn.

Before resizing the window, the rect is drawn correctly. After resizing it, the canvas is much bigger, but I assume that having the virtual resolution fixed to 640x480, the same contents as before should now be scaled to fit the whole canvas.

Am I doing something wrong?

And sorry if this has been posted before, I made a search and none of the virtual resolution posts I found seemed to relate this problem with canvases.

Last edited 2011


Oddball(Posted 2011) [#2]
You have to SetVirtualResolution each time you SetGraphics. This is mentioned somewhere in the manual but I don't remember where. Anyway the virtual resolution is reset each time you SetGraphics.


JaviCervera(Posted 2011) [#3]
Thank you, that works!

I checked the documentation, but I couldn't find much info on how the virtual resolution system works, and the SetVirtualResolution method does not indicate that I should call it after every SetGraphics call.