Atlas - SDL_bwindow.cc
Home / ext / SDL / src / video / haiku Lines: 1 | Size: 6532 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2025 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#include "SDL_internal.h" 22 23#ifdef SDL_VIDEO_DRIVER_HAIKU 24#include "../SDL_sysvideo.h" 25 26#include "SDL_BWin.h" 27#include <new> 28 29// Define a path to window's BWIN data 30#ifdef __cplusplus 31extern "C" { 32#endif 33 34static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) 35{ 36 return (SDL_BWin *)(window->internal); 37} 38 39static SDL_INLINE SDL_BLooper *_GetBeLooper() 40{ 41 return SDL_Looper; 42} 43 44static bool _InitWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) 45{ 46 uint32 flags = 0; 47 window_look look = B_TITLED_WINDOW_LOOK; 48 49 BRect bounds( 50 window->x, 51 window->y, 52 window->x + window->w - 1, //BeWindows have an off-by-one px w/h thing 53 window->y + window->h - 1 54 ); 55 56 if (window->flags & SDL_WINDOW_FULLSCREEN) { 57 // TODO: Add support for this flag 58 } 59 if (window->flags & SDL_WINDOW_OPENGL) { 60 // TODO: Add support for this flag 61 } 62 if (!(window->flags & SDL_WINDOW_RESIZABLE)) { 63 flags |= B_NOT_RESIZABLE | B_NOT_ZOOMABLE; 64 } 65 if (window->flags & SDL_WINDOW_BORDERLESS) { 66 look = B_NO_BORDER_WINDOW_LOOK; 67 } 68 69 SDL_BWin *bwin = new(std::nothrow) SDL_BWin(bounds, look, flags); 70 if (!bwin) { 71 return false; 72 } 73 74 window->internal = (SDL_WindowData *)bwin; 75 int32 winID = _GetBeLooper()->GetID(window); 76 bwin->SetID(winID); 77 78 return true; 79} 80 81bool HAIKU_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) 82{ 83 if (!_InitWindow(_this, window, create_props)) { 84 return false; 85 } 86 87 // Start window loop 88 _ToBeWin(window)->Show(); 89 return true; 90} 91 92void HAIKU_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window * window) 93{ 94 BMessage msg(BWIN_SET_TITLE); 95 msg.AddString("window-title", window->title); 96 _ToBeWin(window)->PostMessage(&msg); 97} 98 99bool HAIKU_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window * window) 100{ 101 BMessage msg(BWIN_MOVE_WINDOW); 102 msg.AddInt32("window-x", window->pending.x); 103 msg.AddInt32("window-y", window->pending.y); 104 _ToBeWin(window)->PostMessage(&msg); 105 return true; 106} 107 108void HAIKU_SetWindowSize(SDL_VideoDevice *_this, SDL_Window * window) 109{ 110 BMessage msg(BWIN_RESIZE_WINDOW); 111 msg.AddInt32("window-w", window->pending.w - 1); 112 msg.AddInt32("window-h", window->pending.h - 1); 113 _ToBeWin(window)->PostMessage(&msg); 114} 115 116void HAIKU_SetWindowBordered(SDL_VideoDevice *_this, SDL_Window * window, bool bordered) 117{ 118 BMessage msg(BWIN_SET_BORDERED); 119 msg.AddBool("window-border", bordered != false); 120 _ToBeWin(window)->PostMessage(&msg); 121} 122 123void HAIKU_SetWindowResizable(SDL_VideoDevice *_this, SDL_Window * window, bool resizable) 124{ 125 BMessage msg(BWIN_SET_RESIZABLE); 126 msg.AddBool("window-resizable", resizable != false); 127 _ToBeWin(window)->PostMessage(&msg); 128} 129 130void HAIKU_ShowWindow(SDL_VideoDevice *_this, SDL_Window * window) 131{ 132 BMessage msg(BWIN_SHOW_WINDOW); 133 _ToBeWin(window)->PostMessage(&msg); 134} 135 136void HAIKU_HideWindow(SDL_VideoDevice *_this, SDL_Window * window) 137{ 138 BMessage msg(BWIN_HIDE_WINDOW); 139 _ToBeWin(window)->PostMessage(&msg); 140} 141 142void HAIKU_RaiseWindow(SDL_VideoDevice *_this, SDL_Window * window) 143{ 144 BMessage msg(BWIN_SHOW_WINDOW); // Activate this window and move to front 145 _ToBeWin(window)->PostMessage(&msg); 146} 147 148void HAIKU_MaximizeWindow(SDL_VideoDevice *_this, SDL_Window * window) 149{ 150 BMessage msg(BWIN_MAXIMIZE_WINDOW); 151 _ToBeWin(window)->PostMessage(&msg); 152} 153 154void HAIKU_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window * window) 155{ 156 BMessage msg(BWIN_MINIMIZE_WINDOW); 157 _ToBeWin(window)->PostMessage(&msg); 158} 159 160void HAIKU_RestoreWindow(SDL_VideoDevice *_this, SDL_Window * window) 161{ 162 BMessage msg(BWIN_RESTORE_WINDOW); 163 _ToBeWin(window)->PostMessage(&msg); 164} 165 166SDL_FullscreenResult HAIKU_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay * display, SDL_FullscreenOp fullscreen) 167{ 168 // Haiku tracks all video display information 169 BMessage msg(BWIN_FULLSCREEN); 170 msg.AddBool("fullscreen", !!fullscreen); 171 _ToBeWin(window)->PostMessage(&msg); 172 return SDL_FULLSCREEN_SUCCEEDED; 173} 174 175 176void HAIKU_SetWindowMinimumSize(SDL_VideoDevice *_this, SDL_Window * window) 177{ 178 BMessage msg(BWIN_MINIMUM_SIZE_WINDOW); 179 msg.AddInt32("window-w", window->w -1); 180 msg.AddInt32("window-h", window->h -1); 181 _ToBeWin(window)->PostMessage(&msg); 182} 183 184bool HAIKU_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window * window, bool grabbed) 185{ 186 // TODO: Implement this! 187 return SDL_Unsupported(); 188} 189 190bool HAIKU_SetWindowParent(SDL_VideoDevice *_this, SDL_Window * window, SDL_Window *parent) 191{ 192 return true; 193} 194 195bool HAIKU_SetWindowModal(SDL_VideoDevice *_this, SDL_Window *window, bool modal) 196{ 197 if (modal) { 198 _ToBeWin(window)->SetLook(B_MODAL_WINDOW_LOOK); 199 _ToBeWin(window)->SetFeel(B_MODAL_SUBSET_WINDOW_FEEL); 200 _ToBeWin(window)->AddToSubset(_ToBeWin(window->parent)); 201 } else { 202 window_look look = (window->flags & SDL_WINDOW_BORDERLESS) ? B_NO_BORDER_WINDOW_LOOK : B_TITLED_WINDOW_LOOK; 203 _ToBeWin(window)->RemoveFromSubset(_ToBeWin(window->parent)); 204 _ToBeWin(window)->SetLook(look); 205 _ToBeWin(window)->SetFeel(B_NORMAL_WINDOW_FEEL); 206 } 207 208 return true; 209} 210 211void HAIKU_DestroyWindow(SDL_VideoDevice *_this, SDL_Window * window) 212{ 213 _ToBeWin(window)->LockLooper(); // This MUST be locked 214 _GetBeLooper()->ClearID(_ToBeWin(window)); 215 _ToBeWin(window)->Quit(); 216 window->internal = NULL; 217} 218 219#ifdef __cplusplus 220} 221#endif 222 223#endif // SDL_VIDEO_DRIVER_HAIKU 224[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.