ViewPort Usage

BlitzMax Forums/BlitzMax Beginners Area/ViewPort Usage

GrimGary(Posted 2016) [#1]
Hello folks!

Been thinking of using SetViewPort / GetViewport for some GUI work. Never thought about using these commands before now. Never had to think about it really.

A couple of questions about them.

1) Once SetViewPort is set to a specific rectangle area, when or how is it reset so the normal surface drawing area is usable again. If I set the ViewPort, do I have to manually set it back or does it clear some other way?

2) Do the settings of the ViewPort fit to a virtual resolution or the application resolution?

3) Does anyone have a short and sweet example of using GetViewport? I've tried to experiment with it, but sometimes my brain has trouble wrapping itself around Var scopes and general usage!

Thank you!


GrimGary(Posted 2016) [#2]
Actually with a little more experimentation, I think I managed to answer all three of my own questions. [face palm]


Floyd(Posted 2016) [#3]
Good, I was about to suggest an experimental approach. Use GetViewPort to read x,y,w,h at the start. Then "reset" by using SetViewPort on these values.

Finding information in the BiltzMax docs can be a challenge. Here's one way to look for missing information.

Type an interesting keyword such a SetViewPort into the editor. F1 will show minimal help at the bottom of the window. A second F1 will show a manual page. If you are lucky there will be details and an example. SetViewPort is part of a module and the help page is really help for that entire module.

If you scroll up to the top of the page you will see that this particular module is BRL.Max2D. There is an overview of the module, plus links to data structures, functions and the full source code. For example you will find

Rem
bbdoc: Set drawing viewport
about:
The current ViewPort defines an area within the back buffer that all drawing is clipped to. Any
regions of a DrawCommand that fall outside the current ViewPort are not drawn.
End Rem
Function SetViewport( x,y,width,height )
	gc.viewport_x=x
	gc.viewport_y=y
	gc.viewport_w=width
	gc.viewport_h=height
	Local x0=Floor( x / gc.vres_mousexscale )
	Local y0=Floor( y / gc.vres_mouseyscale )
	Local x1=Floor( (x+width) / gc.vres_mousexscale )
	Local y1=Floor( (y+height) / gc.vres_mouseyscale )
	_max2dDriver.SetViewport x0,y0,(x1-x0),(y1-y0)
End Function

Rem
bbdoc: Get dimensions of current Viewport.
returns: The horizontal, vertical, width and height values of the current Viewport in the variables supplied.
End Rem
Function GetViewport( x Var,y Var,width Var,height Var )
	x=gc.viewport_x
	y=gc.viewport_y
	width=gc.viewport_w
	height=gc.viewport_h
End Function