SDL: Updated patches for HAIKU
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
diff --git a/src/video/haiku/SDL_BWin.h b/src/video/haiku/SDL_BWin.h
index 4a00507..bfd2014 100644
--- a/src/video/haiku/SDL_BWin.h
+++ b/src/video/haiku/SDL_BWin.h
@@ -37,6 +37,7 @@ extern "C" {
#include <stdio.h>
#include <AppKit.h>
+#include <Cursor.h>
#include <InterfaceKit.h>
#include <game/DirectWindow.h>
#if SDL_VIDEO_OPENGL
@@ -140,8 +141,7 @@ class SDL_BWin:public BDirectWindow
_gl_type = gl_flags;
}
AddChild(_SDL_GLView);
- _SDL_GLView->SetEventMask(B_POINTER_EVENTS | B_KEYBOARD_EVENTS, B_NO_POINTER_HISTORY);
- _SDL_GLView->EnableDirectMode(true);
+ _SDL_GLView->EnableDirectMode(false); /* Disable direct mode */
_SDL_GLView->LockGL(); /* "New" GLViews are created */
Unlock();
return (_SDL_GLView);
diff --git a/src/video/haiku/SDL_bvideo.cc b/src/video/haiku/SDL_bvideo.cc
index eed7191..0b5c874 100644
--- a/src/video/haiku/SDL_bvideo.cc
+++ b/src/video/haiku/SDL_bvideo.cc
@@ -18,11 +18,14 @@
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
+
#include "../../SDL_internal.h"
#include "../../main/haiku/SDL_BApp.h"
#if SDL_VIDEO_DRIVER_HAIKU
+#include "SDL_BWin.h"
+#include <Url.h>
#ifdef __cplusplus
extern "C" {
@@ -37,7 +40,9 @@ extern "C" {
#include "SDL_bframebuffer.h"
#include "SDL_bevents.h"
-#include <Url.h>
+static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) {
+ return ((SDL_BWin*)(window->driverdata));
+}
/* FIXME: Undefined functions */
// #define HAIKU_PumpEvents NULL
@@ -135,31 +140,107 @@ void HAIKU_DeleteDevice(SDL_VideoDevice * device)
SDL_free(device);
}
-static int HAIKU_ShowCursor(SDL_Cursor *cur)
+static SDL_Cursor *
+HAIKU_CreateSystemCursor(SDL_SystemCursor id)
+{
+ SDL_Cursor *cursor;
+ BCursorID cursorId = B_CURSOR_ID_SYSTEM_DEFAULT;
+
+ switch(id)
+ {
+ default:
+ SDL_assert(0);
+ return NULL;
+ case SDL_SYSTEM_CURSOR_ARROW: cursorId = B_CURSOR_ID_SYSTEM_DEFAULT; break;
+ case SDL_SYSTEM_CURSOR_IBEAM: cursorId = B_CURSOR_ID_I_BEAM; break;
+ case SDL_SYSTEM_CURSOR_WAIT: cursorId = B_CURSOR_ID_PROGRESS; break;
+ case SDL_SYSTEM_CURSOR_CROSSHAIR: cursorId = B_CURSOR_ID_CROSS_HAIR; break;
+ case SDL_SYSTEM_CURSOR_WAITARROW: cursorId = B_CURSOR_ID_PROGRESS; break;
+ case SDL_SYSTEM_CURSOR_SIZENWSE: cursorId = B_CURSOR_ID_RESIZE_NORTH_WEST_SOUTH_EAST; break;
+ case SDL_SYSTEM_CURSOR_SIZENESW: cursorId = B_CURSOR_ID_RESIZE_NORTH_EAST_SOUTH_WEST; break;
+ case SDL_SYSTEM_CURSOR_SIZEWE: cursorId = B_CURSOR_ID_RESIZE_EAST_WEST; break;
+ case SDL_SYSTEM_CURSOR_SIZENS: cursorId = B_CURSOR_ID_RESIZE_NORTH_SOUTH; break;
+ case SDL_SYSTEM_CURSOR_SIZEALL: cursorId = B_CURSOR_ID_MOVE; break;
+ case SDL_SYSTEM_CURSOR_NO: cursorId = B_CURSOR_ID_NOT_ALLOWED; break;
+ case SDL_SYSTEM_CURSOR_HAND: cursorId = B_CURSOR_ID_FOLLOW_LINK; break;
+ }
+
+ cursor = (SDL_Cursor *) SDL_calloc(1, sizeof(*cursor));
+ if (cursor) {
+ cursor->driverdata = (void *)new BCursor(cursorId);
+ } else {
+ SDL_OutOfMemory();
+ }
+
+ return cursor;
+}
+
+static SDL_Cursor *
+HAIKU_CreateDefaultCursor()
+{
+ return HAIKU_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
+}
+
+static void
+HAIKU_FreeCursor(SDL_Cursor * cursor)
+{
+ if (cursor->driverdata) {
+ delete (BCursor*) cursor->driverdata;
+ }
+ SDL_free(cursor);
+}
+
+static int HAIKU_ShowCursor(SDL_Cursor *cursor)
{
SDL_Mouse *mouse = SDL_GetMouse();
- int show;
+
if (!mouse)
return 0;
- show = (cur || !mouse->focus);
- if (show) {
- if (be_app->IsCursorHidden())
- be_app->ShowCursor();
+
+ if (cursor) {
+ BCursor *hCursor = (BCursor*)cursor->driverdata;
+ be_app->SetCursor(hCursor);
} else {
- if (!be_app->IsCursorHidden())
- be_app->HideCursor();
+ BCursor *hCursor = new BCursor(B_CURSOR_ID_NO_CURSOR);
+ be_app->SetCursor(hCursor);
+ delete hCursor;
}
+
return 0;
}
+static int
+HAIKU_SetRelativeMouseMode(SDL_bool enabled)
+{
+ SDL_Window *window = SDL_GetMouseFocus();
+ if (!window) {
+ return 0;
+ }
+
+ SDL_BWin *bewin = _ToBeWin(window);
+ BGLView *_SDL_GLView = bewin->GetGLView();
+
+ bewin->Lock();
+ if (enabled)
+ _SDL_GLView->SetEventMask(B_POINTER_EVENTS | B_KEYBOARD_EVENTS, B_NO_POINTER_HISTORY);
+ else
+ _SDL_GLView->SetEventMask(0, 0);
+ bewin->Unlock();
+
+ return 0;
+}
+
static void HAIKU_MouseInit(_THIS)
{
SDL_Mouse *mouse = SDL_GetMouse();
if (!mouse)
return;
+ mouse->CreateSystemCursor = HAIKU_CreateSystemCursor;
mouse->ShowCursor = HAIKU_ShowCursor;
- mouse->cur_cursor = (SDL_Cursor*)0x1;
- mouse->def_cursor = (SDL_Cursor*)0x2;
+ mouse->FreeCursor = HAIKU_FreeCursor;
+ mouse->SetRelativeMouseMode = HAIKU_SetRelativeMouseMode;
+
+ SDL_SetDefaultCursor(HAIKU_CreateDefaultCursor());
}
int HAIKU_VideoInit(_THIS)