Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/intern
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-07-13 04:31:08 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-07-13 04:31:08 +0400
commit41f37cff93eeb2e617f6504aaa5f72ea0787fd27 (patch)
treefce6118a37d1f39aa1dffec4686bbe5a789b30f6 /intern
parenta557773f46fb11ae7c99e96b292182275b27de4b (diff)
changes to ghost/sdl
- mouse coords made absolute - window position set - building with SDL 1.2 gives an error.
Diffstat (limited to 'intern')
-rw-r--r--intern/ghost/intern/GHOST_DisplayManagerSDL.h4
-rw-r--r--intern/ghost/intern/GHOST_SystemSDL.cpp67
-rw-r--r--intern/ghost/intern/GHOST_SystemSDL.h5
-rw-r--r--intern/ghost/intern/GHOST_WindowSDL.cpp24
-rw-r--r--intern/ghost/intern/GHOST_WindowSDL.h97
5 files changed, 160 insertions, 37 deletions
diff --git a/intern/ghost/intern/GHOST_DisplayManagerSDL.h b/intern/ghost/intern/GHOST_DisplayManagerSDL.h
index 5019d1b1351..0afa964b3c0 100644
--- a/intern/ghost/intern/GHOST_DisplayManagerSDL.h
+++ b/intern/ghost/intern/GHOST_DisplayManagerSDL.h
@@ -35,6 +35,10 @@ extern "C" {
#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
diff --git a/intern/ghost/intern/GHOST_SystemSDL.cpp b/intern/ghost/intern/GHOST_SystemSDL.cpp
index 33dcbc01307..59900e67940 100644
--- a/intern/ghost/intern/GHOST_SystemSDL.cpp
+++ b/intern/ghost/intern/GHOST_SystemSDL.cpp
@@ -279,10 +279,57 @@ GHOST_SystemSDL::processEvent(SDL_Event *sdl_event)
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_TSuccess
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_TSuccess
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;
}
diff --git a/intern/ghost/intern/GHOST_SystemSDL.h b/intern/ghost/intern/GHOST_SystemSDL.h
index 7aea1b6694a..63141ad807b 100644
--- a/intern/ghost/intern/GHOST_SystemSDL.h
+++ b/intern/ghost/intern/GHOST_SystemSDL.h
@@ -40,6 +40,11 @@ extern "C" {
#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;
diff --git a/intern/ghost/intern/GHOST_WindowSDL.cpp b/intern/ghost/intern/GHOST_WindowSDL.cpp
index 9d4263f6311..a97f2877f10 100644
--- a/intern/ghost/intern/GHOST_WindowSDL.cpp
+++ b/intern/ghost/intern/GHOST_WindowSDL.cpp
@@ -50,8 +50,8 @@ GHOST_WindowSDL::GHOST_WindowSDL(GHOST_SystemSDL *system,
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,6 +285,26 @@ GHOST_WindowSDL::setClientSize(GHOST_TUns32 width,
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,};
diff --git a/intern/ghost/intern/GHOST_WindowSDL.h b/intern/ghost/intern/GHOST_WindowSDL.h
index 12ff0266e8c..1b2bd35e057 100644
--- a/intern/ghost/intern/GHOST_WindowSDL.h
+++ b/intern/ghost/intern/GHOST_WindowSDL.h
@@ -37,6 +37,10 @@ extern "C" {
#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 @@ public:
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 @@ public:
/* SDL spesific */
SDL_Window *
- getSDLWindow(
- ){
+ getSDLWindow()
+ {
return m_sdl_win;
}
@@ -88,37 +90,74 @@ public:
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);
-
- 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);
-
- /* 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 swapBuffers();
- GHOST_TSuccess activateDrawingContext();
- GHOST_TSuccess setState(GHOST_TWindowState state);
- GHOST_TWindowState getState() const;
+ 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);
+
+ 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);
+
+ GHOST_TWindowState
+ getState() const;
GHOST_TSuccess setOrder(GHOST_TWindowOrder order) { return GHOST_kSuccess; } // TODO