diff options
Diffstat (limited to 'contrib/SDL-3.2.8/src/video/haiku/SDL_bwindow.cc')
| -rw-r--r-- | contrib/SDL-3.2.8/src/video/haiku/SDL_bwindow.cc | 224 |
1 files changed, 224 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/src/video/haiku/SDL_bwindow.cc b/contrib/SDL-3.2.8/src/video/haiku/SDL_bwindow.cc new file mode 100644 index 0000000..47a28d3 --- /dev/null +++ b/contrib/SDL-3.2.8/src/video/haiku/SDL_bwindow.cc | |||
| @@ -0,0 +1,224 @@ | |||
| 1 | /* | ||
| 2 | Simple DirectMedia Layer | ||
| 3 | Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> | ||
| 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 | ||
| 31 | extern "C" { | ||
| 32 | #endif | ||
| 33 | |||
| 34 | static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) | ||
| 35 | { | ||
| 36 | return (SDL_BWin *)(window->internal); | ||
| 37 | } | ||
| 38 | |||
| 39 | static SDL_INLINE SDL_BLooper *_GetBeLooper() | ||
| 40 | { | ||
| 41 | return SDL_Looper; | ||
| 42 | } | ||
| 43 | |||
| 44 | static 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 | printf(__FILE__": %d!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",__LINE__); | ||
| 59 | } | ||
| 60 | if (window->flags & SDL_WINDOW_OPENGL) { | ||
| 61 | // TODO: Add support for this flag | ||
| 62 | } | ||
| 63 | if (!(window->flags & SDL_WINDOW_RESIZABLE)) { | ||
| 64 | flags |= B_NOT_RESIZABLE | B_NOT_ZOOMABLE; | ||
| 65 | } | ||
| 66 | if (window->flags & SDL_WINDOW_BORDERLESS) { | ||
| 67 | look = B_NO_BORDER_WINDOW_LOOK; | ||
| 68 | } | ||
| 69 | |||
| 70 | SDL_BWin *bwin = new(std::nothrow) SDL_BWin(bounds, look, flags); | ||
| 71 | if (!bwin) { | ||
| 72 | return false; | ||
| 73 | } | ||
| 74 | |||
| 75 | window->internal = (SDL_WindowData *)bwin; | ||
| 76 | int32 winID = _GetBeLooper()->GetID(window); | ||
| 77 | bwin->SetID(winID); | ||
| 78 | |||
| 79 | return true; | ||
| 80 | } | ||
| 81 | |||
| 82 | bool HAIKU_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) | ||
| 83 | { | ||
| 84 | if (!_InitWindow(_this, window, create_props)) { | ||
| 85 | return false; | ||
| 86 | } | ||
| 87 | |||
| 88 | // Start window loop | ||
| 89 | _ToBeWin(window)->Show(); | ||
| 90 | return true; | ||
| 91 | } | ||
| 92 | |||
| 93 | void HAIKU_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window * window) | ||
| 94 | { | ||
| 95 | BMessage msg(BWIN_SET_TITLE); | ||
| 96 | msg.AddString("window-title", window->title); | ||
| 97 | _ToBeWin(window)->PostMessage(&msg); | ||
| 98 | } | ||
| 99 | |||
| 100 | bool HAIKU_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window * window) | ||
| 101 | { | ||
| 102 | BMessage msg(BWIN_MOVE_WINDOW); | ||
| 103 | msg.AddInt32("window-x", window->pending.x); | ||
| 104 | msg.AddInt32("window-y", window->pending.y); | ||
| 105 | _ToBeWin(window)->PostMessage(&msg); | ||
| 106 | return true; | ||
| 107 | } | ||
| 108 | |||
| 109 | void HAIKU_SetWindowSize(SDL_VideoDevice *_this, SDL_Window * window) | ||
| 110 | { | ||
| 111 | BMessage msg(BWIN_RESIZE_WINDOW); | ||
| 112 | msg.AddInt32("window-w", window->pending.w - 1); | ||
| 113 | msg.AddInt32("window-h", window->pending.h - 1); | ||
| 114 | _ToBeWin(window)->PostMessage(&msg); | ||
| 115 | } | ||
| 116 | |||
| 117 | void HAIKU_SetWindowBordered(SDL_VideoDevice *_this, SDL_Window * window, bool bordered) | ||
| 118 | { | ||
| 119 | BMessage msg(BWIN_SET_BORDERED); | ||
| 120 | msg.AddBool("window-border", bordered != false); | ||
| 121 | _ToBeWin(window)->PostMessage(&msg); | ||
| 122 | } | ||
| 123 | |||
| 124 | void HAIKU_SetWindowResizable(SDL_VideoDevice *_this, SDL_Window * window, bool resizable) | ||
| 125 | { | ||
| 126 | BMessage msg(BWIN_SET_RESIZABLE); | ||
| 127 | msg.AddBool("window-resizable", resizable != false); | ||
| 128 | _ToBeWin(window)->PostMessage(&msg); | ||
| 129 | } | ||
| 130 | |||
| 131 | void HAIKU_ShowWindow(SDL_VideoDevice *_this, SDL_Window * window) | ||
| 132 | { | ||
| 133 | BMessage msg(BWIN_SHOW_WINDOW); | ||
| 134 | _ToBeWin(window)->PostMessage(&msg); | ||
| 135 | } | ||
| 136 | |||
| 137 | void HAIKU_HideWindow(SDL_VideoDevice *_this, SDL_Window * window) | ||
| 138 | { | ||
| 139 | BMessage msg(BWIN_HIDE_WINDOW); | ||
| 140 | _ToBeWin(window)->PostMessage(&msg); | ||
| 141 | } | ||
| 142 | |||
| 143 | void HAIKU_RaiseWindow(SDL_VideoDevice *_this, SDL_Window * window) | ||
| 144 | { | ||
| 145 | BMessage msg(BWIN_SHOW_WINDOW); // Activate this window and move to front | ||
| 146 | _ToBeWin(window)->PostMessage(&msg); | ||
| 147 | } | ||
| 148 | |||
| 149 | void HAIKU_MaximizeWindow(SDL_VideoDevice *_this, SDL_Window * window) | ||
| 150 | { | ||
| 151 | BMessage msg(BWIN_MAXIMIZE_WINDOW); | ||
| 152 | _ToBeWin(window)->PostMessage(&msg); | ||
| 153 | } | ||
| 154 | |||
| 155 | void HAIKU_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window * window) | ||
| 156 | { | ||
| 157 | BMessage msg(BWIN_MINIMIZE_WINDOW); | ||
| 158 | _ToBeWin(window)->PostMessage(&msg); | ||
| 159 | } | ||
| 160 | |||
| 161 | void HAIKU_RestoreWindow(SDL_VideoDevice *_this, SDL_Window * window) | ||
| 162 | { | ||
| 163 | BMessage msg(BWIN_RESTORE_WINDOW); | ||
| 164 | _ToBeWin(window)->PostMessage(&msg); | ||
| 165 | } | ||
| 166 | |||
| 167 | SDL_FullscreenResult HAIKU_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay * display, SDL_FullscreenOp fullscreen) | ||
| 168 | { | ||
| 169 | // Haiku tracks all video display information | ||
| 170 | BMessage msg(BWIN_FULLSCREEN); | ||
| 171 | msg.AddBool("fullscreen", !!fullscreen); | ||
| 172 | _ToBeWin(window)->PostMessage(&msg); | ||
| 173 | return SDL_FULLSCREEN_SUCCEEDED; | ||
| 174 | } | ||
| 175 | |||
| 176 | |||
| 177 | void HAIKU_SetWindowMinimumSize(SDL_VideoDevice *_this, SDL_Window * window) | ||
| 178 | { | ||
| 179 | BMessage msg(BWIN_MINIMUM_SIZE_WINDOW); | ||
| 180 | msg.AddInt32("window-w", window->w -1); | ||
| 181 | msg.AddInt32("window-h", window->h -1); | ||
| 182 | _ToBeWin(window)->PostMessage(&msg); | ||
| 183 | } | ||
| 184 | |||
| 185 | bool HAIKU_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window * window, bool grabbed) | ||
| 186 | { | ||
| 187 | // TODO: Implement this! | ||
| 188 | return SDL_Unsupported(); | ||
| 189 | } | ||
| 190 | |||
| 191 | bool HAIKU_SetWindowParent(SDL_VideoDevice *_this, SDL_Window * window, SDL_Window *parent) | ||
| 192 | { | ||
| 193 | return true; | ||
| 194 | } | ||
| 195 | |||
| 196 | bool HAIKU_SetWindowModal(SDL_VideoDevice *_this, SDL_Window *window, bool modal) | ||
| 197 | { | ||
| 198 | if (modal) { | ||
| 199 | _ToBeWin(window)->SetLook(B_MODAL_WINDOW_LOOK); | ||
| 200 | _ToBeWin(window)->SetFeel(B_MODAL_SUBSET_WINDOW_FEEL); | ||
| 201 | _ToBeWin(window)->AddToSubset(_ToBeWin(window->parent)); | ||
| 202 | } else { | ||
| 203 | window_look look = (window->flags & SDL_WINDOW_BORDERLESS) ? B_NO_BORDER_WINDOW_LOOK : B_TITLED_WINDOW_LOOK; | ||
| 204 | _ToBeWin(window)->RemoveFromSubset(_ToBeWin(window->parent)); | ||
| 205 | _ToBeWin(window)->SetLook(look); | ||
| 206 | _ToBeWin(window)->SetFeel(B_NORMAL_WINDOW_FEEL); | ||
| 207 | } | ||
| 208 | |||
| 209 | return true; | ||
| 210 | } | ||
| 211 | |||
| 212 | void HAIKU_DestroyWindow(SDL_VideoDevice *_this, SDL_Window * window) | ||
| 213 | { | ||
| 214 | _ToBeWin(window)->LockLooper(); // This MUST be locked | ||
| 215 | _GetBeLooper()->ClearID(_ToBeWin(window)); | ||
| 216 | _ToBeWin(window)->Quit(); | ||
| 217 | window->internal = NULL; | ||
| 218 | } | ||
| 219 | |||
| 220 | #ifdef __cplusplus | ||
| 221 | } | ||
| 222 | #endif | ||
| 223 | |||
| 224 | #endif // SDL_VIDEO_DRIVER_HAIKU | ||
