Browse Source

Initial support for defining window position.

woollybah 6 năm trước cách đây
mục cha
commit
062f8e2578

+ 4 - 4
d3d9max2d.mod/d3d9max2d.bmx

@@ -27,7 +27,7 @@ Const LOG_ERRS=True'False
 
 Private
 
-Global _gw,_gh,_gd,_gr,_gf
+Global _gw,_gh,_gd,_gr,_gf,_gx,_gy
 Global _color
 Global _clscolor
 Global _ix#,_iy#,_jx#,_jy#
@@ -268,8 +268,8 @@ Type TD3D9Max2DDriver Extends TMax2dDriver
 		If g Return TMax2DGraphics.Create( g,Self )
 	End Method
 	
-	Method CreateGraphics:TGraphics( width,height,depth,hertz,flags ) Override
-		Local g:TD3D9Graphics=D3D9GraphicsDriver().CreateGraphics( width,height,depth,hertz,flags )
+	Method CreateGraphics:TGraphics( width,height,depth,hertz,flags,x,y ) Override
+		Local g:TD3D9Graphics=D3D9GraphicsDriver().CreateGraphics( width,height,depth,hertz,flags,x,y )
 		If Not g Return Null
 		Return TMax2DGraphics.Create( g,Self )
 	End Method
@@ -321,7 +321,7 @@ Type TD3D9Max2DDriver Extends TMax2dDriver
 	
 	Method ResetDevice()
 		_d3d9graphics.ValidateSize
-		_d3d9graphics.GetSettings _gw,_gh,_gd,_gr,_gf
+		_d3d9graphics.GetSettings _gw,_gh,_gd,_gr,_gf,_gx,_gy
 	
 		Local viewport:D3DVIEWPORT9
 		viewport.X = 0

+ 24 - 6
dxgraphics.mod/d3d9graphics.bmx

@@ -11,6 +11,7 @@ Import brl.systemdefault
 Private
 Extern
 	Function bbAppIcon:Byte Ptr(inst:Byte Ptr)="HICON bbAppIcon(HINSTANCE)!"
+	Function GetSystemMetrics:Int(index:Int)
 End Extern
 
 Global _wndClass$="BBDX9Device Window Class"
@@ -178,7 +179,11 @@ Type TD3D9Graphics Extends TGraphics
 		Return Self
 	End Method
 	
-	Method Create:TD3D9Graphics( width:Int,height:Int,depth:Int,hertz:Int,flags:Int)
+	Method Create:TD3D9Graphics( width:Int,height:Int,depth:Int,hertz:Int,flags:Int,x:Int,y:Int)
+		Const SM_CYCAPTION:Int = 4
+		Const SM_CXBORDER:Int = 5
+		Const SM_CYFIXEDFRAME:Int = 8
+		
 		Local wstyle:Int
 
 		If depth
@@ -193,8 +198,18 @@ Type TD3D9Graphics Extends TGraphics
 			Local desktopRect:Int[4]
 			GetWindowRect GetDesktopWindow(),desktopRect
 				
-			rect[0]=desktopRect[2]/2-width/2;		
-			rect[1]=desktopRect[3]/2-height/2;		
+			If x = -1 Then
+				x = desktopRect[2]/2-width/2
+			Else
+				x = x + GetSystemMetrics(SM_CXBORDER)
+			End If
+			If y = -1 Then
+				y = desktopRect[3]/2-height/2
+			Else
+				y = y + GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYFIXEDFRAME)
+			End If
+			rect[0]=x;
+			rect[1]=y;
 			rect[2]=rect[0]+width;
 			rect[3]=rect[1]+height;
 				
@@ -285,7 +300,7 @@ Type TD3D9Graphics Extends TGraphics
 		Return _driver
 	End Method
 	
-	Method GetSettings:Int( width:Int Var,height:Int Var,depth:Int Var,hertz:Int Var,flags:Int Var ) Override
+	Method GetSettings:Int( width:Int Var,height:Int Var,depth:Int Var,hertz:Int Var,flags:Int Var, x:Int Var, y:Int Var ) Override
 		'
 		ValidateSize
 		'
@@ -321,6 +336,9 @@ Type TD3D9Graphics Extends TGraphics
 
 	Method Resize(width:Int, height:Int) Override
  	End Method
+
+	Method Position(x:Int, y:Int) Override
+	End Method
 	
 	Field _hwnd:Byte Ptr
 	Field _width:Int
@@ -394,8 +412,8 @@ Type TD3D9GraphicsDriver Extends TGraphicsDriver
 		Return New TD3D9Graphics.Attach( widget:Byte Ptr,flags:Int )
 	End Method
 	
-	Method CreateGraphics:TD3D9Graphics( width:Int,height:Int,depth:Int,hertz:Int,flags:Int) Override
-		Return New TD3D9Graphics.Create( width,height,depth,hertz,flags )
+	Method CreateGraphics:TD3D9Graphics( width:Int,height:Int,depth:Int,hertz:Int,flags:Int,x:Int,y:Int) Override
+		Return New TD3D9Graphics.Create( width,height,depth,hertz,flags,x,y )
 	End Method
 
 	Method Graphics:TD3D9Graphics()

+ 7 - 4
glgraphics.mod/glgraphics.linux.c

@@ -59,7 +59,7 @@ struct BBGLContext{
 
 int bbGLGraphicsGraphicsModes( int *imodes,int maxcount );
 BBGLContext *bbGLGraphicsAttachGraphics( void * window,int flags );
-BBGLContext *bbGLGraphicsCreateGraphics( int width,int height,int depth,int hz,int flags );
+BBGLContext *bbGLGraphicsCreateGraphics( int width,int height,int depth,int hz,int flags, int x, int y );
 void bbGLGraphicsGetSettings( BBGLContext *context,int *width,int *height,int *depth,int *hz,int *flags );
 void bbGLGraphicsClose( BBGLContext *context );
 void bbGLGraphicsSetGraphics( BBGLContext *context );
@@ -210,7 +210,7 @@ void bbGLGraphicsShareContexts(){
 	_sharedContext=bbGLGraphicsCreateGraphics(0,0,0,0,0);
 }
 
-BBGLContext *bbGLGraphicsCreateGraphics( int width,int height,int depth,int hz,int flags ){
+BBGLContext *bbGLGraphicsCreateGraphics( int width,int height,int depth,int hz,int flags, int x, int y ){
 	XSetWindowAttributes swa;
 	XVisualInfo *vizinfo;
 	XEvent event;
@@ -300,6 +300,9 @@ BBGLContext *bbGLGraphicsCreateGraphics( int width,int height,int depth,int hz,i
 		Atom atom;
 		XSizeHints *hints;
 		
+		if (x < 0) x = 0 ;
+		if (y < 0) y = 0 ;	
+		
 		swa.border_pixel=0;
 		swa.event_mask=StructureNotifyMask;
 		swa.colormap=XCreateColormap( xdisplay,RootWindow(xdisplay,0),vizinfo->visual,AllocNone );
@@ -307,8 +310,8 @@ BBGLContext *bbGLGraphicsCreateGraphics( int width,int height,int depth,int hz,i
 		window=XCreateWindow(
 			xdisplay,
 			RootWindow(xdisplay,xscreen),
-			0,
-			0,  
+			x,
+			y,  
 			width,height,
 			0,
 			vizinfo->depth,

+ 4 - 2
glgraphics.mod/glgraphics.macos.m

@@ -220,7 +220,7 @@ BBGLContext *bbGLGraphicsAttachGraphics( NSView *view,int flags ){
 	return context;
 }
 
-BBGLContext *bbGLGraphicsCreateGraphics( int width,int height,int depth,int hertz,int flags ){
+BBGLContext *bbGLGraphicsCreateGraphics( int width,int height,int depth,int hertz,int flags, int x, int y ){
 	int mode;
 	BBGLWindow *window=0;
 	BBGLContext *context;
@@ -262,9 +262,11 @@ BBGLContext *bbGLGraphicsCreateGraphics( int width,int height,int depth,int hert
 		mode=MODE_DISPLAY;
 		
 	}else{
+		if (x < 0) x = 0;
+		if (y < 0) y = 0;
 		
 		window=[[BBGLWindow alloc]
-			initWithContentRect:NSMakeRect( 0,0,width,height )
+			initWithContentRect:NSMakeRect( x, y,width,height )
 			styleMask:NSTitledWindowMask|NSClosableWindowMask
 			backing:NSBackingStoreBuffered
 			defer:YES];

+ 3 - 3
glgraphics.mod/glgraphics.win32.c

@@ -411,7 +411,7 @@ BBGLContext *bbGLGraphicsAttachGraphics( HWND hwnd,int flags ){
 	return context;
 }
 
-BBGLContext *bbGLGraphicsCreateGraphics( int width,int height,int depth,int hertz,int flags ){
+BBGLContext *bbGLGraphicsCreateGraphics( int width,int height,int depth,int hertz,int flags, int x, int y ){
 	BBGLContext *context;
 	
 	int mode;
@@ -434,8 +434,8 @@ BBGLContext *bbGLGraphicsCreateGraphics( int width,int height,int depth,int hert
 		RECT desktopRect;
 		GetWindowRect(desktop, &desktopRect);
 
-		rect.left=desktopRect.right/2-width/2;		
-		rect.top=desktopRect.bottom/2-height/2;		
+		rect.left=(x == -1) ? desktopRect.right/2-width/2 : x + GetSystemMetrics(SM_CXBORDER);
+		rect.top=(y == -1) ? desktopRect.bottom/2-height/2: y + GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYFIXEDFRAME);
 		rect.right=rect.left+width;
 		rect.bottom=rect.top+height;
 		

+ 10 - 5
glgraphics.mod/source.bmx

@@ -14,7 +14,7 @@ Extern
 	Function bbGLGraphicsShareContexts()
 	Function bbGLGraphicsGraphicsModes( buf:Byte Ptr,size )
 	Function bbGLGraphicsAttachGraphics:Byte Ptr( widget:Byte Ptr,flags )
-	Function bbGLGraphicsCreateGraphics:Byte Ptr( width,height,depth,hertz,flags )
+	Function bbGLGraphicsCreateGraphics:Byte Ptr( width,height,depth,hertz,flags,x,y )
 	Function bbGLGraphicsGetSettings( context:Byte Ptr,width Var,height Var,depth Var,hertz Var,flags Var )
 	Function bbGLGraphicsClose( context:Byte Ptr )	
 	Function bbGLGraphicsSetGraphics( context:Byte Ptr )
@@ -30,15 +30,17 @@ Type TGLGraphics Extends TGraphics
 		Return GLGraphicsDriver()
 	End Method
 	
-	Method GetSettings( width Var,height Var,depth Var,hertz Var,flags Var ) Override
+	Method GetSettings( width Var,height Var,depth Var,hertz Var,flags Var, x Var, y Var ) Override
 		Assert _context
-		Local w,h,d,r,f
+		Local w,h,d,r,f,xp,yp
 		bbGLGraphicsGetSettings _context,w,h,d,r,f
 		width=w
 		height=h
 		depth=d
 		hertz=r
 		flags=f
+		x=-1
+		y=-1
 	End Method
 	
 	Method Close() Override
@@ -50,6 +52,9 @@ Type TGLGraphics Extends TGraphics
 	Method Resize(width:Int, height:Int) Override
 	End Method
 	
+	Method Position(x:Int, y:Int) Override
+	End Method
+
 	Field _context:Byte Ptr
 	
 End Type
@@ -78,9 +83,9 @@ Type TGLGraphicsDriver Extends TGraphicsDriver
 		Return t
 	End Method
 	
-	Method CreateGraphics:TGLGraphics( width,height,depth,hertz,flags ) Override
+	Method CreateGraphics:TGLGraphics( width,height,depth,hertz,flags,x,y ) Override
 		Local t:TGLGraphics=New TGLGraphics
-		t._context=bbGLGraphicsCreateGraphics( width,height,depth,hertz,flags )
+		t._context=bbGLGraphicsCreateGraphics( width,height,depth,hertz,flags,x,y )
 		Return t
 	End Method
 	

+ 4 - 4
glmax2d.mod/glmax2d.bmx

@@ -353,8 +353,8 @@ Type TGLMax2DDriver Extends TMax2DDriver
 		If g Return TMax2DGraphics.Create( g,Self )
 	End Method
 	
-	Method CreateGraphics:TMax2DGraphics( width,height,depth,hertz,flags ) Override
-		Local g:TGLGraphics=GLGraphicsDriver().CreateGraphics( width,height,depth,hertz,flags )
+	Method CreateGraphics:TMax2DGraphics( width,height,depth,hertz,flags,x,y ) Override
+		Local g:TGLGraphics=GLGraphicsDriver().CreateGraphics( width,height,depth,hertz,flags,x,y )
 		If g Return TMax2DGraphics.Create( g,Self )
 	End Method
 	
@@ -376,8 +376,8 @@ Type TGLMax2DDriver Extends TMax2DDriver
 	End Method
 	
 	Method ResetGLContext( g:TGraphics )
-		Local gw,gh,gd,gr,gf
-		g.GetSettings gw,gh,gd,gr,gf
+		Local gw,gh,gd,gr,gf,gx,gy
+		g.GetSettings gw,gh,gd,gr,gf,gx,gy
 		
 		state_blend=0
 		state_boundtex=0

+ 34 - 9
graphics.mod/graphics.bmx

@@ -59,11 +59,13 @@ Type TGraphics
 
 	Method Driver:TGraphicsDriver() Abstract
 
-	Method GetSettings( width Var,height Var,depth Var,hertz Var,flags Var ) Abstract
+	Method GetSettings( width Var,height Var,depth Var,hertz Var,flags Var, x Var, y Var ) Abstract
 
 	Method Close() Abstract
 	
 	Method Resize(width:Int, height:Int) Abstract
+	
+	Method Position(x:Int, y:Int) Abstract
 
 End Type
 
@@ -83,7 +85,7 @@ Type TGraphicsDriver
 	
 	Method AttachGraphics:TGraphics( widget:Byte Ptr,flags ) Abstract
 	
-	Method CreateGraphics:TGraphics( width,height,depth,hertz,flags ) Abstract
+	Method CreateGraphics:TGraphics( width,height,depth,hertz,flags,x,y ) Abstract
 	
 	Method SetGraphics( g:TGraphics ) Abstract
 	
@@ -100,7 +102,7 @@ Private
 Global _defaultFlags
 Global _driver:TGraphicsDriver
 Global _graphicsModes:TGraphicsMode[]
-Global _graphics:TGraphics,_gWidth,_gHeight,_gDepth,_gHertz,_gFlags
+Global _graphics:TGraphics,_gWidth,_gHeight,_gDepth,_gHertz,_gFlags,_gx,_gy
 
 Global _exGraphics:TGraphics
 
@@ -142,6 +144,8 @@ Function SetGraphicsDriver( driver:TGraphicsDriver,defaultFlags=GRAPHICS_BACKBUF
 	_gDepth=0
 	_gHertz=0
 	_gFlags=0
+	_gx=0
+	_gy=0
 End Function
 
 Rem
@@ -223,11 +227,11 @@ first have to select it using #SetGraphics.
 The kind of graphics object returned depends upon the current graphics driver as set by
 #SetGraphicsDriver.
 End Rem
-Function CreateGraphics:TGraphics( width,height,depth,hertz,flags )
+Function CreateGraphics:TGraphics( width,height,depth,hertz,flags,x,y )
 	flags:|_defaultFlags
 	Local g:TGraphics
 	Try
-		g=_driver.CreateGraphics( width,height,depth,hertz,flags )
+		g=_driver.CreateGraphics( width,height,depth,hertz,flags,x,y )
 	Catch ex:Object
 ?Debug
 		WriteStdout "CreateGraphics failed:"+ex.ToString()
@@ -275,6 +279,8 @@ Function SetGraphics( g:TGraphics )
 		_gDepth=0
 		_gHertz=0
 		_gFlags=0
+		_gx=0
+		_gy=0
 		Return
 	EndIf
 	Local d:TGraphicsDriver=g.Driver()
@@ -283,7 +289,7 @@ Function SetGraphics( g:TGraphics )
 		_graphicsModes=Null
 		_driver=d
 	EndIf
-	g.GetSettings _gWidth,_gHeight,_gDepth,_gHertz,_gFlags
+	g.GetSettings _gWidth,_gHeight,_gDepth,_gHertz,_gFlags,_gx,_gy
 	d.SetGraphics g
 	_graphics=g
 End Function
@@ -299,6 +305,17 @@ Function GraphicsResize( width:Int, height:Int )
 	End If
 End Function
 
+Rem
+bbdoc: Sets the position of the graphics window to @x, @y.
+End Rem
+Function GraphicsPosition( x:Int, y:Int )
+	If _driver And _graphics Then
+		_gx = x
+		_gy = y
+		_graphics.Position(x, y)
+	End If
+End Function
+
 Rem
 bbdoc: Get width of current graphics object
 returns: The width, in pixels, of the current graphics object
@@ -349,6 +366,14 @@ Function GraphicsFlags()
 	Return _gFlags
 End Function
 
+Function GraphicsX:Int()
+	Return _gx
+End Function
+
+Function GraphicsY:Int()
+	Return _gy
+End Function
+
 Rem
 bbdoc: Flip current graphics object
 about:
@@ -441,15 +466,15 @@ Once #Graphics has executed, you can begin rendering immediately without any nee
 #Graphics also enables #{polled input} mode, providing a simple way to monitor the keyboard
 and mouse.
 End Rem
-Function Graphics:TGraphics( width,height,depth=0,hertz=60,flags=0 )
+Function Graphics:TGraphics( width,height,depth=0,hertz=60,flags=0,x=-1,y=-1 )
 	EndGraphics
 	flags:|_defaultFlags
 	
-	Local g:TGraphics=CreateGraphics( width,height,depth,hertz,flags )
+	Local g:TGraphics=CreateGraphics( width,height,depth,hertz,flags,x,y )
 	If Not g Return
 	
 	BumpGraphicsSeq
-	
+
 	SetGraphics g
 
 	If depth

+ 12 - 7
max2d.mod/max2d.bmx

@@ -110,14 +110,16 @@ Type TMax2DGraphics Extends TGraphics
 		Return _driver
 	End Method
 	
-	Method GetSettings( width Var,height Var,depth Var,hertz Var,flags Var ) Override
-		Local w,h,d,r,f
-		_graphics.GetSettings w,h,d,r,f
+	Method GetSettings( width Var,height Var,depth Var,hertz Var,flags Var, x Var, y Var ) Override
+		Local w,h,d,r,f,xp,yp
+		_graphics.GetSettings w,h,d,r,f,xp,yp
 		width=w
 		height=h
 		depth=d
 		hertz=r
 		flags=f
+		x=-1
+		y=-1
 	End Method
 	
 	Method Close() Override
@@ -128,8 +130,8 @@ Type TMax2DGraphics Extends TGraphics
 	End Method
 	
 	Method Validate()
-		Local w,h,d,r,f
-		_graphics.GetSettings w,h,d,r,f
+		Local w,h,d,r,f,xp,yp
+		_graphics.GetSettings w,h,d,r,f,xp,yp
 		If w<>g_width Or h<>g_height
 			g_width=w
 			g_height=h
@@ -175,8 +177,8 @@ Type TMax2DGraphics Extends TGraphics
 	End Function
 	
 	Function Create:TMax2DGraphics( g:TGraphics,d:TMax2DDriver )
-		Local gw,gh,gd,gr,gf
-		g.GetSettings gw,gh,gd,gr,gf
+		Local gw,gh,gd,gr,gf,gx,gy
+		g.GetSettings gw,gh,gd,gr,gf,gx,gy
 		
 		If Not default_font default_font=TImageFont.CreateDefault()
 
@@ -225,6 +227,9 @@ Type TMax2DGraphics Extends TGraphics
 		_graphics.Resize(width, height)
 	End Method
 	
+	Method Position(x:Int, y:Int)
+		_graphics.Position(x, y)
+	End Method
 End Type
 
 Rem