[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [38348] trunk/blender/intern/ghost/intern: changes to ghost/sdl

Campbell Barton ideasman42 at gmail.com
Wed Jul 13 02:31:10 CEST 2011


Revision: 38348
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38348
Author:   campbellbarton
Date:     2011-07-13 00:31:08 +0000 (Wed, 13 Jul 2011)
Log Message:
-----------
changes to ghost/sdl
- mouse coords made absolute
- window position set
- building with SDL 1.2 gives an error.

Modified Paths:
--------------
    trunk/blender/intern/ghost/intern/GHOST_DisplayManagerSDL.h
    trunk/blender/intern/ghost/intern/GHOST_SystemSDL.cpp
    trunk/blender/intern/ghost/intern/GHOST_SystemSDL.h
    trunk/blender/intern/ghost/intern/GHOST_WindowSDL.cpp
    trunk/blender/intern/ghost/intern/GHOST_WindowSDL.h

Modified: trunk/blender/intern/ghost/intern/GHOST_DisplayManagerSDL.h
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_DisplayManagerSDL.h	2011-07-12 19:21:38 UTC (rev 38347)
+++ trunk/blender/intern/ghost/intern/GHOST_DisplayManagerSDL.h	2011-07-13 00:31:08 UTC (rev 38348)
@@ -35,6 +35,10 @@
 	#include "SDL.h"
 }
 
+#if !SDL_VERSION_ATLEAST(1, 3, 0)
+#  error "SDL 1.3 or newer is needed to build with Ghost"
+#endif
+
 class GHOST_SystemSDL;
 
 class GHOST_DisplayManagerSDL : public GHOST_DisplayManager

Modified: trunk/blender/intern/ghost/intern/GHOST_SystemSDL.cpp
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_SystemSDL.cpp	2011-07-12 19:21:38 UTC (rev 38347)
+++ trunk/blender/intern/ghost/intern/GHOST_SystemSDL.cpp	2011-07-13 00:31:08 UTC (rev 38348)
@@ -279,10 +279,57 @@
 	case SDL_MOUSEMOTION:
 		{
 			SDL_MouseMotionEvent &sdl_sub_evt= sdl_event->motion;
-			GHOST_WindowSDL *window= findGhostWindow(SDL_GetWindowFromID(sdl_sub_evt.windowID));
+			SDL_Window *sdl_win= SDL_GetWindowFromID(sdl_sub_evt.windowID);
+			GHOST_WindowSDL *window= findGhostWindow(sdl_win);
 			assert(window != NULL);
 
-			g_event= new GHOST_EventCursor(getMilliSeconds(), GHOST_kEventCursorMove, window, sdl_sub_evt.x, sdl_sub_evt.y);
+			int x_win, y_win;
+			SDL_GetWindowPosition(sdl_win, &x_win, &y_win);
+
+			GHOST_TInt32 x_root= sdl_sub_evt.x + x_win;
+			GHOST_TInt32 y_root= sdl_sub_evt.y + y_win;
+
+#if 0
+			if(window->getCursorGrabMode() != GHOST_kGrabDisable && window->getCursorGrabMode() != GHOST_kGrabNormal)
+			{
+				GHOST_TInt32 x_new= x_root;
+				GHOST_TInt32 y_new= y_root;
+				GHOST_TInt32 x_accum, y_accum;
+				GHOST_Rect bounds;
+
+				/* fallback to window bounds */
+				if(window->getCursorGrabBounds(bounds)==GHOST_kFailure)
+					window->getClientBounds(bounds);
+
+				/* could also clamp to screen bounds
+				 * wrap with a window outside the view will fail atm  */
+				bounds.wrapPoint(x_new, y_new, 8); /* offset of one incase blender is at screen bounds */
+				window->getCursorGrabAccum(x_accum, y_accum);
+
+				// cant use setCursorPosition because the mouse may have no focus!
+				if(x_new != x_root || y_new != y_root) {
+					if (1 ) { //xme.time > m_last_warp) {
+						/* when wrapping we don't need to add an event because the
+						 * setCursorPosition call will cause a new event after */
+						SDL_WarpMouseInWindow(sdl_win, x_new - x_win, y_new - y_win); /* wrap */
+						window->setCursorGrabAccum(x_accum + (x_root - x_new), y_accum + (y_root - y_new));
+						// m_last_warp= lastEventTime(xme.time);
+					} else {
+						// setCursorPosition(x_new, y_new); /* wrap but don't accumulate */
+						SDL_WarpMouseInWindow(sdl_win, x_new - x_win, y_new - y_win);
+					}
+
+					g_event = new GHOST_EventCursor(getMilliSeconds(), GHOST_kEventCursorMove, window, x_new, y_new);
+				}
+				else {
+					g_event = new GHOST_EventCursor(getMilliSeconds(), GHOST_kEventCursorMove, window, x_root + x_accum, y_root + y_accum);
+				}
+			}
+			else
+#endif
+			{
+				g_event= new GHOST_EventCursor(getMilliSeconds(), GHOST_kEventCursorMove, window, x_root, y_root);
+			}
 			break;
 		}
 	case SDL_MOUSEBUTTONUP:
@@ -346,10 +393,15 @@
 GHOST_SystemSDL::getCursorPosition(GHOST_TInt32& x,
                                    GHOST_TInt32& y) const
 {
+	int x_win, y_win;
+	SDL_Window *win= SDL_GetMouseFocus();
+	SDL_GetWindowPosition(win, &x_win, &y_win);
+
 	int xi, yi;
 	SDL_GetMouseState(&xi, &yi);
-	x= xi;
-	y= yi;
+	x= xi + x_win;
+	y= yi + x_win;
+
 	return GHOST_kSuccess;
 }
 
@@ -357,8 +409,11 @@
 GHOST_SystemSDL::setCursorPosition(GHOST_TInt32 x,
                                    GHOST_TInt32 y)
 {
-	// SDL_SendMouseMotion(SDL, SDL_FALSE, x, y); // NOT EXPOSED
-	SDL_WarpMouseInWindow(NULL, x, y);
+	int x_win, y_win;
+	SDL_Window *win= SDL_GetMouseFocus();
+	SDL_GetWindowPosition(win, &x_win, &y_win);
+
+	SDL_WarpMouseInWindow(win, x - x_win, y - y_win);
 	return GHOST_kSuccess;
 }
 

Modified: trunk/blender/intern/ghost/intern/GHOST_SystemSDL.h
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_SystemSDL.h	2011-07-12 19:21:38 UTC (rev 38347)
+++ trunk/blender/intern/ghost/intern/GHOST_SystemSDL.h	2011-07-13 00:31:08 UTC (rev 38348)
@@ -40,6 +40,11 @@
 	#include "SDL.h"
 }
 
+#if !SDL_VERSION_ATLEAST(1, 3, 0)
+#  error "SDL 1.3 or newer is needed to build with Ghost"
+#endif
+
+
 class GHOST_WindowSDL;
 
 

Modified: trunk/blender/intern/ghost/intern/GHOST_WindowSDL.cpp
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_WindowSDL.cpp	2011-07-12 19:21:38 UTC (rev 38347)
+++ trunk/blender/intern/ghost/intern/GHOST_WindowSDL.cpp	2011-07-13 00:31:08 UTC (rev 38348)
@@ -50,8 +50,8 @@
       m_sdl_custom_cursor(NULL)
 {
 	m_sdl_win= SDL_CreateWindow(title,
-	                            10,
-	                            10,
+	                            left,
+	                            top,
 	                            width,
 	                            height,
 	                            SDL_WINDOW_RESIZABLE|SDL_WINDOW_OPENGL|SDL_WINDOW_SHOWN);
@@ -285,7 +285,27 @@
 	return GHOST_kSuccess;
 }
 
+void
+GHOST_WindowSDL::screenToClient( GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY ) const
+{
+	/* XXXSDL_WEAK_ABS_COORDS */
+	int x_win, y_win;
+	SDL_GetWindowPosition(m_sdl_win, &x_win, &y_win);
 
+	outX = inX - x_win;
+	outY = inY - y_win;
+}
+void
+GHOST_WindowSDL::clientToScreen( GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY ) const
+{
+	/* XXXSDL_WEAK_ABS_COORDS */
+	int x_win, y_win;
+	SDL_GetWindowPosition(m_sdl_win, &x_win, &y_win);
+
+	outX = inX + x_win;
+	outY = inY + y_win;
+}
+
 /* mouse cursor */
 static unsigned char sdl_std_cursor_mask_xterm[]= {0xef,0x01,0xff,0x01,0xff,0x01,0x7c,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x7c,0x00,0xff,0x01,0xff,0x01,0xef,0x01,};
 static unsigned char sdl_std_cursor_xterm[]= {0x00,0x77,0x00,0x1c,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x1c,0x00,0x77,0x00,0x00,0x00,0x00,};

Modified: trunk/blender/intern/ghost/intern/GHOST_WindowSDL.h
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_WindowSDL.h	2011-07-12 19:21:38 UTC (rev 38347)
+++ trunk/blender/intern/ghost/intern/GHOST_WindowSDL.h	2011-07-13 00:31:08 UTC (rev 38348)
@@ -37,6 +37,10 @@
 	#include "SDL.h"
 }
 
+#if !SDL_VERSION_ATLEAST(1, 3, 0)
+#  error "SDL 1.3 or newer is needed to build with Ghost"
+#endif
+
 class STR_String;
 
 class GHOST_WindowSDL : public GHOST_Window
@@ -55,10 +59,8 @@
 
 	GHOST_WindowSDL(GHOST_SystemSDL *system,
 	                const STR_String& title,
-	                GHOST_TInt32 left,
-	                GHOST_TInt32 top,
-	                GHOST_TUns32 width,
-	                GHOST_TUns32 height,
+	                GHOST_TInt32 left, GHOST_TInt32 top,
+	                GHOST_TUns32 width, GHOST_TUns32 height,
 	                GHOST_TWindowState state,
 	                const GHOST_TEmbedderWindowID parentWindow,
 	                GHOST_TDrawingContextType type,
@@ -70,8 +72,8 @@
 
 	/* SDL spesific */
 	SDL_Window *
-	getSDLWindow(
-	){
+	getSDLWindow()
+	{
 		return m_sdl_win;
 	}
 
@@ -88,38 +90,75 @@
 		m_invalid_window = false;
 	}
 
-	bool getValid( ) const
+	bool getValid() const
 	{
 		return (m_sdl_win != NULL);
 	}
 
+	void getWindowBounds(GHOST_Rect& bounds) const;
+	void getClientBounds(GHOST_Rect& bounds) const;
+
 protected:
 	GHOST_TSuccess installDrawingContext(GHOST_TDrawingContextType type);
 	GHOST_TSuccess removeDrawingContext();
 
-	GHOST_TSuccess setWindowCursorGrab(GHOST_TGrabCursorMode mode);
-	GHOST_TSuccess setWindowCursorShape(GHOST_TStandardCursor shape);
-	GHOST_TSuccess setWindowCustomCursorShape(GHOST_TUns8 bitmap[16][2], GHOST_TUns8 mask[16][2], int hotX, int hotY);
-	GHOST_TSuccess setWindowCustomCursorShape(GHOST_TUns8 *bitmap, GHOST_TUns8 *mask, int sizex, int sizey, int hotX, int hotY, int fg_color, int bg_color);
-	GHOST_TSuccess setWindowCursorVisibility(bool visible);
+	GHOST_TSuccess
+	setWindowCursorGrab(GHOST_TGrabCursorMode mode);
 
-	void setTitle(const STR_String& title);
-	void getTitle(STR_String& title) const;
-	void getWindowBounds( GHOST_Rect& bounds ) const;
-	void getClientBounds( GHOST_Rect& bounds ) const;
-	GHOST_TSuccess setClientWidth(GHOST_TUns32 width);
-	GHOST_TSuccess setClientHeight(GHOST_TUns32 height);
-	GHOST_TSuccess setClientSize(GHOST_TUns32 width, GHOST_TUns32 height);
+	GHOST_TSuccess
+	setWindowCursorShape(GHOST_TStandardCursor shape);
 
-	/* TODO */
-	void screenToClient( GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY ) const { outX = inX; outY = inY; }
-	void clientToScreen( GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY ) const { outX = inX; outY = inY; }
+	GHOST_TSuccess
+	setWindowCustomCursorShape(GHOST_TUns8 bitmap[16][2],
+	                           GHOST_TUns8 mask[16][2],
+	                           int hotX, int hotY);
 
-	GHOST_TSuccess swapBuffers();
-	GHOST_TSuccess activateDrawingContext();
-	GHOST_TSuccess setState(GHOST_TWindowState state);
-	GHOST_TWindowState getState() const;
+	GHOST_TSuccess
+	setWindowCustomCursorShape(GHOST_TUns8 *bitmap,
+	                           GHOST_TUns8 *mask,
+	                           int sizex, int sizey,
+	                           int hotX, int hotY,
+	                           int fg_color, int bg_color);
 
+	GHOST_TSuccess
+	setWindowCursorVisibility(bool visible);
+
+	void
+	setTitle(const STR_String& title);
+
+	void
+	getTitle(STR_String& title) const;
+
+	GHOST_TSuccess
+	setClientWidth(GHOST_TUns32 width);
+
+	GHOST_TSuccess
+	setClientHeight(GHOST_TUns32 height);
+
+	GHOST_TSuccess
+	setClientSize(GHOST_TUns32 width,
+	              GHOST_TUns32 height);
+
+	void
+	screenToClient(GHOST_TInt32 inX, GHOST_TInt32 inY,
+	               GHOST_TInt32& outX, GHOST_TInt32& outY) const;
+
+	void
+	clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY,
+	               GHOST_TInt32& outX, GHOST_TInt32& outY) const;
+
+	GHOST_TSuccess
+	swapBuffers();
+
+	GHOST_TSuccess
+	activateDrawingContext();
+
+	GHOST_TSuccess
+	setState(GHOST_TWindowState state);
+

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list