Centered Graphics Window (Win32)

BlitzMax Forums/BlitzMax Module Tweaks/Centered Graphics Window (Win32)

kfprimm(Posted 2006) [#1]
Alright, this tweak allows you to center a window using by adding a flag to the SetGraphicsDriver command.

in graphics.bmx of BRL.Graphics add this to bottom of the the graphics types.
Const GRAPHICS_CENTERED=        $40


in glgraphics.win32.bmx of BRL.DXGraphics replace bbGLGraphicsCreateGraphics with this,


Now, the DX part gets a little tricky. In d3d7graphics.bmx of BRL.DXGraphics, replace CreateHWND with this,


now, replace TD3D7Device.OpenWindowed() (yes, the method), with this,
Method OpenWindowed(w,h,center)
		Local 	res
		width=w
		height=h
		depth=0
		freq=0
		hwnd=CreateHWND(width,height,False,center)
		res=ddraw.SetCooperativeLevel(hwnd,DDSCL_NORMAL|DDSCL_FPUPRESERVE)	
		If res Throw "SetCooperativeLevel Failed result="+res
		state=DX7WINDOWED
		Reset()
		device.BeginScene()
	End Method


and finally, replace TD3D7GraphicsDriver.CreateGraphics with this,
Method CreateGraphics:TD3D7Graphics( width,height,depth,hertz,flags )
		Local	g:TD3D7Graphics				
		Try
			If isgui PrimaryDevice._Release
			If depth
				PrimaryDevice.OpenFullScreen width,height,depth,hertz
			Else
				Local center
				If flags&GRAPHICS_CENTERED center=True
				PrimaryDevice.OpenWindowed width,height,center
			EndIf		
			isgui=False
		Catch err$
			Return 
		End Try

		g=New TD3D7Graphics
		g.depth=depth
		g.hertz=hertz
		g.flags=flags
		Return g		
	End Method


rebuild,
BRL.Graphics
BRL.DXGraphics
BRL.GLGraphics

to use,
SetGraphicsDriver D3D7GraphicsDriver(),GRAPHICS_BACKBUFFER|GRAPHICS_CENTERED
Graphics 800,600,0

or
SetGraphicsDriver GLGraphicsDriver(),GRAPHICS_BACKBUFFER|GRAPHICS_CENTERED
Graphics 800,600,0



Grisu(Posted 2006) [#2]
Ahm, could you apply the changes to the newest 1.24 version and host the complete file somewhere?

That would be nice...


kfprimm(Posted 2007) [#3]
Give me a minute and I will post them on this thread. I don't think I can legally upload the source/compiled files. If BRL says its alright I will.


GfK(Posted 2007) [#4]
Send the modified files to BRL and get them to put it on the mod server.

Nobody in their right mind is NOT going to want this option.

I need to have my game window centered but I despise having to change BRL mods myself when changes you rely on can be so easily lost.


H&K(Posted 2007) [#5]
I despise having to change BRL mods myself when changes you rely on can be so easily lost
Agreed


Grisu(Posted 2007) [#6]
Got the issue solved already, see other topic.
http://www.blitzbasic.com/Community/posts.php?topic=66129

I'd really love having an option flag in the gfx command to center the window by default or not.

I simply hate editing the files by hand over and over.

Thanks anyway.


degac(Posted 2007) [#7]
Ok - I will assume all the possible consequencies of my comment...

but

there is just ONE reason that explains why this simple modification is not added in the last update?


JoshK(Posted 2007) [#8]
Nice. One comaplaint I got when I centered the graphics window was from people with multiple monitors. I had no idea there were so many of them.

I suggest using $800 for your constant, since I already used these others in my antialias modification:
	GRAPHICS_MULTISAMPLE2X=	$40
	GRAPHICS_MULTISAMPLE4X=	$80
	GRAPHICS_MULTISAMPLE8X=	$100
	GRAPHICS_MULTISAMPLE16X=$200
	GRAPHICS_HIDDEN=	$400