Просмотр исходного кода

Initial support for defining window position.

woollybah 6 лет назад
Родитель
Сommit
32e069689e

+ 10 - 6
d3d9sdlgraphics.mod/d3d9sdlgraphics.bmx

@@ -161,10 +161,10 @@ Type TD3D9SDLGraphics Extends TGraphics
 		Return Self
 	End Method
 	
-	Method Create:TD3D9SDLGraphics( width:Int,height:Int,depth:Int,hertz:Int,flags:Int)
+	Method Create:TD3D9SDLGraphics( width:Int,height:Int,depth:Int,hertz:Int,flags:Int,x:Int,y:Int)
 	
 		
-		_g = SDLGraphicsDriver().CreateGraphics( width, height, depth, hertz, flags | GRAPHICS_WIN32_DX )
+		_g = SDLGraphicsDriver().CreateGraphics( width, height, depth, hertz, flags | GRAPHICS_WIN32_DX, x, y )
 		
 		_hwnd = _g.GetHandle()
 		
@@ -250,11 +250,11 @@ Type TD3D9SDLGraphics Extends TGraphics
 		Return _driver
 	End Method
 	
-	Method GetSettings:Int( width:Int Var,height:Int Var,depth:Int Var,hertz:Int Var,flags:Int Var )
+	Method GetSettings:Int( width:Int Var,height:Int Var,depth:Int Var,hertz:Int Var,flags:Int Var,x:Int Var,y:Int Var )
 		'
 		ValidateSize
 		'
-		_g.GetSettings(width, height, depth, hertz, flags)
+		_g.GetSettings(width, height, depth, hertz, flags, x, y)
 	End Method
 
 	Method Close:Int()
@@ -285,6 +285,10 @@ Type TD3D9SDLGraphics Extends TGraphics
 	Method Resize(width:Int, height:Int)
 		_g.Resize(width, height)
 	End Method
+
+	Method Position(x:Int, y:Int)
+		_g.Position(x, y)
+	End Method
 	
 	Field _hwnd:Byte Ptr
 	
@@ -359,8 +363,8 @@ Type TD3D9SDLGraphicsDriver Extends TGraphicsDriver
 		Return New TD3D9SDLGraphics.Attach( widget:Byte Ptr,flags:Int )
 	End Method
 	
-	Method CreateGraphics:TD3D9SDLGraphics( width:Int,height:Int,depth:Int,hertz:Int,flags:Int)
-		Return New TD3D9SDLGraphics.Create( width,height,depth,hertz,flags )
+	Method CreateGraphics:TD3D9SDLGraphics( width:Int,height:Int,depth:Int,hertz:Int,flags:Int,x:Int,y:Int)
+		Return New TD3D9SDLGraphics.Create( width,height,depth,hertz,flags,x,y )
 	End Method
 
 	Method Graphics:TD3D9SDLGraphics()

+ 4 - 4
d3d9sdlmax2d.mod/d3d9sdlmax2d.bmx

@@ -24,7 +24,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#
@@ -265,8 +265,8 @@ Type TD3D9SDLMax2DDriver Extends TMax2dDriver
 		If g Return TMax2DGraphics.Create( g,Self )
 	End Method
 	
-	Method CreateGraphics:TGraphics( width,height,depth,hertz,flags )
-		Local g:TD3D9SDLGraphics=D3D9SDLGraphicsDriver().CreateGraphics( width,height,depth,hertz,flags )
+	Method CreateGraphics:TGraphics( width,height,depth,hertz,flags,x,y )
+		Local g:TD3D9SDLGraphics=D3D9SDLGraphicsDriver().CreateGraphics( width,height,depth,hertz,flags,x,y )
 		If Not g Return Null
 		Return TMax2DGraphics.Create( g,Self )
 	End Method
@@ -318,7 +318,7 @@ Type TD3D9SDLMax2DDriver 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

+ 4 - 4
gl2sdlmax2d.mod/main.bmx

@@ -733,9 +733,9 @@ Type TGL2Max2DDriver Extends TMax2DDriver
 
 	End Method
 	
-	Method CreateGraphics:TMax2DGraphics( width, height, depth, hertz, flags )
+	Method CreateGraphics:TMax2DGraphics( width, height, depth, hertz, flags, x, y )
 
-		Local g:TSDLGraphics = SDLGraphicsDriver().CreateGraphics( width, height, depth, hertz, flags | SDL_GRAPHICS_GL )
+		Local g:TSDLGraphics = SDLGraphicsDriver().CreateGraphics( width, height, depth, hertz, flags | SDL_GRAPHICS_GL, x, y )
 		
 		If g Then Return TMax2DGraphics.Create( g, Self )
 
@@ -767,8 +767,8 @@ Type TGL2Max2DDriver Extends TMax2DDriver
 	
 	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 )
 
 		If Not inited Then
 			Init()

+ 4 - 4
glsdlmax2d.mod/glsdlmax2d.bmx

@@ -303,8 +303,8 @@ Type TGLMax2DDriver Extends TMax2DDriver
 		If g Return TMax2DGraphics.Create( g,Self )
 	End Method
 	
-	Method CreateGraphics:TMax2DGraphics( width,height,depth,hertz,flags )
-		Local g:TSDLGraphics=SDLGraphicsDriver().CreateGraphics( width,height,depth,hertz,flags | SDL_GRAPHICS_GL )
+	Method CreateGraphics:TMax2DGraphics( width,height,depth,hertz,flags,x,y )
+		Local g:TSDLGraphics=SDLGraphicsDriver().CreateGraphics( width,height,depth,hertz,flags | SDL_GRAPHICS_GL,x,y )
 		If g Return TMax2DGraphics.Create( g,Self )
 	End Method
 	
@@ -326,8 +326,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

+ 27 - 5
sdlgraphics.mod/sdlgraphics.bmx

@@ -52,6 +52,8 @@ Type TGraphicsContext
 	Field hertz:Int
 	Field flags:Int
 	Field sync:Int
+	Field x:Int
+	Field y:Int
 
 	Field window:TSDLWindow
 	Field context:TSDLGLContext
@@ -66,7 +68,7 @@ Type TSDLGraphics Extends TGraphics
 		Return SDLGraphicsDriver()
 	End Method
 
-	Method GetSettings( width:Int Var,height:Int Var,depth:Int Var,hertz:Int Var,flags:Int Var )
+	Method GetSettings( width:Int Var,height:Int Var,depth:Int Var,hertz:Int Var,flags:Int Var,x:Int Var,y:Int Var )
 		Assert _context
 		'Local w:Int,h:Int,d:Int,r:Int,f:Int
 		'bbSDLGraphicsGetSettings _context,w,h,d,r,f
@@ -75,6 +77,8 @@ Type TSDLGraphics Extends TGraphics
 		depth=_context.depth
 		hertz=_context.hertz
 		flags=_context.flags
+		x=_context.x
+		y=_context.y
 	End Method
 
 	Method Close()
@@ -100,6 +104,9 @@ Type TSDLGraphics Extends TGraphics
 
 	Method Resize(width:Int, height:Int) Override
 	End Method
+	
+	Method Position(x:Int, y:Int) Override
+	End Method
 
 	Field _context:TGraphicsContext
 
@@ -151,13 +158,13 @@ Type TSDLGraphicsDriver Extends TGraphicsDriver
 		Return t
 	End Method
 
-	Method CreateGraphics:TSDLGraphics( width:Int,height:Int,depth:Int,hertz:Int,flags:Int )
+	Method CreateGraphics:TSDLGraphics( width:Int,height:Int,depth:Int,hertz:Int,flags:Int,x:Int,y:Int )
 		Local t:TSDLGraphics=New TSDLGraphics
-		t._context=SDLGraphicsCreateGraphics( width,height,depth,hertz,flags )
+		t._context=SDLGraphicsCreateGraphics( width,height,depth,hertz,flags,x,y )
 		Return t
 	End Method
 
-	Method SDLGraphicsCreateGraphics:TGraphicsContext(width:Int,height:Int,depth:Int,hertz:Int,flags:Int)
+	Method SDLGraphicsCreateGraphics:TGraphicsContext(width:Int,height:Int,depth:Int,hertz:Int,flags:Int,x:Int,y:Int)
 		Local context:TGraphicsContext = New TGraphicsContext
 
 		Local windowFlags:UInt = SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_OPENGL
@@ -207,8 +214,14 @@ Type TSDLGraphicsDriver Extends TGraphicsDriver
 
 
 		'End If
+		If x < 0 Then
+			x = SDL_WINDOWPOS_CENTERED
+		End If
+		If y < 0 Then
+			y = SDL_WINDOWPOS_CENTERED
+		End If
 
-		context.window = TSDLWindow.Create(AppTitle, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, windowFlags)
+		context.window = TSDLWindow.Create(AppTitle, x, y, width, height, windowFlags)
 		If glFlags Then
 			context.context = context.window.GLCreateContext()
 			SDL_GL_SetSwapInterval(-1)
@@ -274,6 +287,15 @@ Type TSDLGraphicsDriver Extends TGraphicsDriver
 						GraphicsResize(ev.x, ev.y)
 					End If
 				End If
+			Case EVENT_WINDOWMOVE
+				Local ctxt:TGraphicsContext = TGraphicsContext(context)
+				If ctxt Then
+					If ctxt.window.GetID() = ev.data Then
+						ctxt.x = ev.x
+						ctxt.y = ev.y
+						GraphicsPosition(ev.x, ev.y)
+					End If
+				End If
 		End Select
 
 		Return data

+ 3 - 0
sdlsystem.mod/glue.c

@@ -181,6 +181,9 @@ void bmx_SDL_EmitSDLEvent( SDL_Event *event, BBObject *source ) {
 				case SDL_WINDOWEVENT_RESIZED:
 					bbSDLSystemEmitEvent(BBEVENT_WINDOWSIZE, source, event->window.windowID, 0, event->window.data1, event->window.data2, &bbNullObject);
 					return;
+				case SDL_WINDOWEVENT_MOVED:
+					bbSDLSystemEmitEvent(BBEVENT_WINDOWMOVE, source, event->window.windowID, 0, event->window.data1, event->window.data2, &bbNullObject);
+					return;
 			}
 	}