Atlas - SDL_bvideo.cc

Home / ext / SDL / src / video / haiku Lines: 1 | Size: 9683 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2026 Sam Lantinga <[email protected]> 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20*/ 21 22#include "SDL_internal.h" 23#include "../../core/haiku/SDL_BApp.h" 24 25#ifdef SDL_VIDEO_DRIVER_HAIKU 26 27#include "SDL_BWin.h" 28#include <Url.h> 29 30#ifdef __cplusplus 31extern "C" { 32#endif 33 34#include "SDL_bkeyboard.h" 35#include "SDL_bwindow.h" 36#include "SDL_bclipboard.h" 37#include "SDL_bvideo.h" 38#include "SDL_bopengl.h" 39#include "SDL_bmodes.h" 40#include "SDL_bframebuffer.h" 41#include "SDL_bevents.h" 42#include "SDL_bmessagebox.h" 43#include "../../events/SDL_keyboard_c.h" 44#include "../../events/SDL_mouse_c.h" 45 46static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) { 47 return (SDL_BWin *)(window->internal); 48} 49 50static SDL_VideoDevice * HAIKU_CreateDevice(void) 51{ 52 SDL_VideoDevice *device; 53 54 // Initialize all variables that we clean on shutdown 55 device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); 56 57 device->internal = NULL; /* FIXME: Is this the cause of some of the 58 SDL_Quit() errors? */ 59 60// TODO: Figure out if any initialization needs to go here 61 62 // Set the function pointers 63 device->VideoInit = HAIKU_VideoInit; 64 device->VideoQuit = HAIKU_VideoQuit; 65 device->GetDisplayBounds = HAIKU_GetDisplayBounds; 66 device->GetDisplayModes = HAIKU_GetDisplayModes; 67 device->SetDisplayMode = HAIKU_SetDisplayMode; 68 device->PumpEvents = HAIKU_PumpEvents; 69 70 device->CreateSDLWindow = HAIKU_CreateWindow; 71 device->SetWindowTitle = HAIKU_SetWindowTitle; 72 device->SetWindowPosition = HAIKU_SetWindowPosition; 73 device->SetWindowSize = HAIKU_SetWindowSize; 74 device->ShowWindow = HAIKU_ShowWindow; 75 device->HideWindow = HAIKU_HideWindow; 76 device->RaiseWindow = HAIKU_RaiseWindow; 77 device->MaximizeWindow = HAIKU_MaximizeWindow; 78 device->MinimizeWindow = HAIKU_MinimizeWindow; 79 device->RestoreWindow = HAIKU_RestoreWindow; 80 device->SetWindowBordered = HAIKU_SetWindowBordered; 81 device->SetWindowResizable = HAIKU_SetWindowResizable; 82 device->SetWindowFullscreen = HAIKU_SetWindowFullscreen; 83 device->SetWindowMouseGrab = HAIKU_SetWindowMouseGrab; 84 device->SetWindowMinimumSize = HAIKU_SetWindowMinimumSize; 85 device->SetWindowParent = HAIKU_SetWindowParent; 86 device->SetWindowModal = HAIKU_SetWindowModal; 87 device->DestroyWindow = HAIKU_DestroyWindow; 88 device->CreateWindowFramebuffer = HAIKU_CreateWindowFramebuffer; 89 device->UpdateWindowFramebuffer = HAIKU_UpdateWindowFramebuffer; 90 device->DestroyWindowFramebuffer = HAIKU_DestroyWindowFramebuffer; 91 92#ifdef SDL_VIDEO_OPENGL 93 device->GL_LoadLibrary = HAIKU_GL_LoadLibrary; 94 device->GL_GetProcAddress = HAIKU_GL_GetProcAddress; 95 device->GL_UnloadLibrary = HAIKU_GL_UnloadLibrary; 96 device->GL_CreateContext = HAIKU_GL_CreateContext; 97 device->GL_MakeCurrent = HAIKU_GL_MakeCurrent; 98 device->GL_SetSwapInterval = HAIKU_GL_SetSwapInterval; 99 device->GL_GetSwapInterval = HAIKU_GL_GetSwapInterval; 100 device->GL_SwapWindow = HAIKU_GL_SwapWindow; 101 device->GL_DestroyContext = HAIKU_GL_DestroyContext; 102#endif 103 104 device->SetClipboardText = HAIKU_SetClipboardText; 105 device->GetClipboardText = HAIKU_GetClipboardText; 106 device->HasClipboardText = HAIKU_HasClipboardText; 107 108 device->free = HAIKU_DeleteDevice; 109 110 // TODO: Is this needed? 111 device->device_caps = VIDEO_DEVICE_CAPS_SLOW_FRAMEBUFFER; 112 113 return device; 114} 115 116VideoBootStrap HAIKU_bootstrap = { 117 "haiku", "Haiku graphics", 118 HAIKU_CreateDevice, 119 HAIKU_ShowMessageBox, 120 false 121}; 122 123void HAIKU_DeleteDevice(SDL_VideoDevice * device) 124{ 125 SDL_free(device->internal); 126 SDL_free(device); 127} 128 129struct SDL_CursorData 130{ 131 BCursor *cursor; 132}; 133 134static SDL_Cursor *HAIKU_CreateCursorAndData(BCursor *bcursor) 135{ 136 SDL_Cursor *cursor = (SDL_Cursor *)SDL_calloc(1, sizeof(*cursor)); 137 if (cursor) { 138 SDL_CursorData *data = (SDL_CursorData *)SDL_calloc(1, sizeof(*data)); 139 if (!data) { 140 SDL_free(cursor); 141 return NULL; 142 } 143 data->cursor = bcursor; 144 cursor->internal = data; 145 } 146 return cursor; 147} 148 149static SDL_Cursor * HAIKU_CreateSystemCursor(SDL_SystemCursor id) 150{ 151 BCursorID cursorId = B_CURSOR_ID_SYSTEM_DEFAULT; 152 153 switch(id) 154 { 155 #define CURSORCASE(sdlname, bname) case SDL_SYSTEM_CURSOR_##sdlname: cursorId = B_CURSOR_ID_##bname; break 156 CURSORCASE(DEFAULT, SYSTEM_DEFAULT); 157 CURSORCASE(TEXT, I_BEAM); 158 CURSORCASE(WAIT, PROGRESS); 159 CURSORCASE(CROSSHAIR, CROSS_HAIR); 160 CURSORCASE(PROGRESS, PROGRESS); 161 CURSORCASE(NWSE_RESIZE, RESIZE_NORTH_WEST_SOUTH_EAST); 162 CURSORCASE(NESW_RESIZE, RESIZE_NORTH_EAST_SOUTH_WEST); 163 CURSORCASE(EW_RESIZE, RESIZE_EAST_WEST); 164 CURSORCASE(NS_RESIZE, RESIZE_NORTH_SOUTH); 165 CURSORCASE(MOVE, MOVE); 166 CURSORCASE(NOT_ALLOWED, NOT_ALLOWED); 167 CURSORCASE(POINTER, FOLLOW_LINK); 168 CURSORCASE(NW_RESIZE, RESIZE_NORTH_WEST_SOUTH_EAST); 169 CURSORCASE(N_RESIZE, RESIZE_NORTH_SOUTH); 170 CURSORCASE(NE_RESIZE, RESIZE_NORTH_EAST_SOUTH_WEST); 171 CURSORCASE(E_RESIZE, RESIZE_EAST_WEST); 172 CURSORCASE(SE_RESIZE, RESIZE_NORTH_WEST_SOUTH_EAST); 173 CURSORCASE(S_RESIZE, RESIZE_NORTH_SOUTH); 174 CURSORCASE(SW_RESIZE, RESIZE_NORTH_EAST_SOUTH_WEST); 175 CURSORCASE(W_RESIZE, RESIZE_EAST_WEST); 176 #undef CURSORCASE 177 default: 178 SDL_assert(0); 179 return NULL; 180 } 181 182 return HAIKU_CreateCursorAndData(new BCursor(cursorId)); 183} 184 185static SDL_Cursor * HAIKU_CreateDefaultCursor() 186{ 187 SDL_SystemCursor id = SDL_GetDefaultSystemCursor(); 188 return HAIKU_CreateSystemCursor(id); 189} 190 191static void HAIKU_FreeCursor(SDL_Cursor * cursor) 192{ 193 SDL_CursorData *data = cursor->internal; 194 195 if (data) { 196 delete data->cursor; 197 } 198 SDL_free(data); 199 SDL_free(cursor); 200} 201 202static SDL_Cursor * HAIKU_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y) 203{ 204 SDL_Surface *converted; 205 206 converted = SDL_ConvertSurface(surface, SDL_PIXELFORMAT_ARGB8888); 207 if (!converted) { 208 return NULL; 209 } 210 211 BBitmap *cursorBitmap = new BBitmap(BRect(0, 0, surface->w - 1, surface->h - 1), B_RGBA32); 212 cursorBitmap->SetBits(converted->pixels, converted->h * converted->pitch, 0, B_RGBA32); 213 SDL_DestroySurface(converted); 214 215 return HAIKU_CreateCursorAndData(new BCursor(cursorBitmap, BPoint(hot_x, hot_y))); 216} 217 218static bool HAIKU_ShowCursor(SDL_Cursor *cursor) 219{ 220 SDL_Mouse *mouse = SDL_GetMouse(); 221 222 if (!mouse) { 223 return true; 224 } 225 226 if (cursor) { 227 BCursor *hCursor = cursor->internal->cursor; 228 be_app->SetCursor(hCursor); 229 } else { 230 BCursor *hCursor = new BCursor(B_CURSOR_ID_NO_CURSOR); 231 be_app->SetCursor(hCursor); 232 delete hCursor; 233 } 234 235 return true; 236} 237 238static bool HAIKU_SetRelativeMouseMode(bool enabled) 239{ 240 SDL_Window *window = SDL_GetMouseFocus(); 241 if (!window) { 242 return true; 243 } 244 245 SDL_BWin *bewin = _ToBeWin(window); 246 BView *_SDL_View = bewin->GetGLView(); 247 if (!_SDL_View) { 248 _SDL_View = bewin->GetView(); 249 if (!_SDL_View) 250 return false; 251 } 252 253 bewin->Lock(); 254 if (enabled) 255 _SDL_View->SetEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY); 256 else 257 _SDL_View->SetEventMask(0, 0); 258 bewin->Unlock(); 259 260 return true; 261} 262 263static void HAIKU_MouseInit(SDL_VideoDevice *_this) 264{ 265 SDL_Mouse *mouse = SDL_GetMouse(); 266 if (!mouse) { 267 return; 268 } 269 mouse->CreateCursor = HAIKU_CreateCursor; 270 mouse->CreateSystemCursor = HAIKU_CreateSystemCursor; 271 mouse->ShowCursor = HAIKU_ShowCursor; 272 mouse->FreeCursor = HAIKU_FreeCursor; 273 mouse->SetRelativeMouseMode = HAIKU_SetRelativeMouseMode; 274 275 SDL_SetDefaultCursor(HAIKU_CreateDefaultCursor()); 276} 277 278bool HAIKU_VideoInit(SDL_VideoDevice *_this) 279{ 280 // Initialize the Be Application for appserver interaction 281 if (!SDL_InitBeApp()) { 282 return false; 283 } 284 285 // Initialize video modes 286 HAIKU_InitModes(_this); 287 288 // Init the keymap 289 HAIKU_InitOSKeymap(); 290 291 HAIKU_MouseInit(_this); 292 293 // Assume we have a mouse and keyboard 294 SDL_AddKeyboard(SDL_DEFAULT_KEYBOARD_ID, NULL); 295 SDL_AddMouse(SDL_DEFAULT_MOUSE_ID, NULL); 296 297#ifdef SDL_VIDEO_OPENGL 298 // testgl application doesn't load library, just tries to load symbols 299 // is it correct? if so we have to load library here 300 HAIKU_GL_LoadLibrary(_this, NULL); 301#endif 302 303 // We're done! 304 return true; 305} 306 307void HAIKU_VideoQuit(SDL_VideoDevice *_this) 308{ 309 310 HAIKU_QuitModes(_this); 311 312 SDL_QuitBeApp(); 313} 314 315// just sticking this function in here so it's in a C++ source file. 316extern "C" 317bool HAIKU_OpenURL(const char *url) 318{ 319 BUrl burl(url); 320 const status_t rc = burl.OpenWithPreferredApplication(false); 321 if (rc != B_NO_ERROR) { 322 return SDL_SetError("URL open failed (err=%d)", (int)rc); 323 } 324 return true; 325} 326 327#ifdef __cplusplus 328} 329#endif 330 331#endif // SDL_VIDEO_DRIVER_HAIKU 332
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.