SDL_bwindow.cc 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #include "SDL_internal.h"
  19. #ifdef SDL_VIDEO_DRIVER_HAIKU
  20. #include "../SDL_sysvideo.h"
  21. #include "SDL_BWin.h"
  22. #include <new>
  23. // Define a path to window's BWIN data
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window)
  28. {
  29. return (SDL_BWin *)(window->internal);
  30. }
  31. static SDL_INLINE SDL_BLooper *_GetBeLooper()
  32. {
  33. return SDL_Looper;
  34. }
  35. static bool _InitWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props)
  36. {
  37. uint32 flags = 0;
  38. window_look look = B_TITLED_WINDOW_LOOK;
  39. BRect bounds(
  40. window->x,
  41. window->y,
  42. window->x + window->w - 1, //BeWindows have an off-by-one px w/h thing
  43. window->y + window->h - 1
  44. );
  45. if (window->flags & SDL_WINDOW_FULLSCREEN) {
  46. // TODO: Add support for this flag
  47. printf(__FILE__": %d!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",__LINE__);
  48. }
  49. if (window->flags & SDL_WINDOW_OPENGL) {
  50. // TODO: Add support for this flag
  51. }
  52. if (!(window->flags & SDL_WINDOW_RESIZABLE)) {
  53. flags |= B_NOT_RESIZABLE | B_NOT_ZOOMABLE;
  54. }
  55. if (window->flags & SDL_WINDOW_BORDERLESS) {
  56. look = B_NO_BORDER_WINDOW_LOOK;
  57. }
  58. SDL_BWin *bwin = new(std::nothrow) SDL_BWin(bounds, look, flags);
  59. if (!bwin) {
  60. return false;
  61. }
  62. window->internal = (SDL_WindowData *)bwin;
  63. int32 winID = _GetBeLooper()->GetID(window);
  64. bwin->SetID(winID);
  65. return true;
  66. }
  67. bool HAIKU_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props)
  68. {
  69. if (!_InitWindow(_this, window, create_props)) {
  70. return false;
  71. }
  72. // Start window loop
  73. _ToBeWin(window)->Show();
  74. return true;
  75. }
  76. void HAIKU_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window * window)
  77. {
  78. BMessage msg(BWIN_SET_TITLE);
  79. msg.AddString("window-title", window->title);
  80. _ToBeWin(window)->PostMessage(&msg);
  81. }
  82. bool HAIKU_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window * window)
  83. {
  84. BMessage msg(BWIN_MOVE_WINDOW);
  85. msg.AddInt32("window-x", window->pending.x);
  86. msg.AddInt32("window-y", window->pending.y);
  87. _ToBeWin(window)->PostMessage(&msg);
  88. return true;
  89. }
  90. void HAIKU_SetWindowSize(SDL_VideoDevice *_this, SDL_Window * window)
  91. {
  92. BMessage msg(BWIN_RESIZE_WINDOW);
  93. msg.AddInt32("window-w", window->pending.w - 1);
  94. msg.AddInt32("window-h", window->pending.h - 1);
  95. _ToBeWin(window)->PostMessage(&msg);
  96. }
  97. void HAIKU_SetWindowBordered(SDL_VideoDevice *_this, SDL_Window * window, bool bordered)
  98. {
  99. BMessage msg(BWIN_SET_BORDERED);
  100. msg.AddBool("window-border", bordered != false);
  101. _ToBeWin(window)->PostMessage(&msg);
  102. }
  103. void HAIKU_SetWindowResizable(SDL_VideoDevice *_this, SDL_Window * window, bool resizable)
  104. {
  105. BMessage msg(BWIN_SET_RESIZABLE);
  106. msg.AddBool("window-resizable", resizable != false);
  107. _ToBeWin(window)->PostMessage(&msg);
  108. }
  109. void HAIKU_ShowWindow(SDL_VideoDevice *_this, SDL_Window * window)
  110. {
  111. BMessage msg(BWIN_SHOW_WINDOW);
  112. _ToBeWin(window)->PostMessage(&msg);
  113. }
  114. void HAIKU_HideWindow(SDL_VideoDevice *_this, SDL_Window * window)
  115. {
  116. BMessage msg(BWIN_HIDE_WINDOW);
  117. _ToBeWin(window)->PostMessage(&msg);
  118. }
  119. void HAIKU_RaiseWindow(SDL_VideoDevice *_this, SDL_Window * window)
  120. {
  121. BMessage msg(BWIN_SHOW_WINDOW); // Activate this window and move to front
  122. _ToBeWin(window)->PostMessage(&msg);
  123. }
  124. void HAIKU_MaximizeWindow(SDL_VideoDevice *_this, SDL_Window * window)
  125. {
  126. BMessage msg(BWIN_MAXIMIZE_WINDOW);
  127. _ToBeWin(window)->PostMessage(&msg);
  128. }
  129. void HAIKU_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window * window)
  130. {
  131. BMessage msg(BWIN_MINIMIZE_WINDOW);
  132. _ToBeWin(window)->PostMessage(&msg);
  133. }
  134. void HAIKU_RestoreWindow(SDL_VideoDevice *_this, SDL_Window * window)
  135. {
  136. BMessage msg(BWIN_RESTORE_WINDOW);
  137. _ToBeWin(window)->PostMessage(&msg);
  138. }
  139. SDL_FullscreenResult HAIKU_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay * display, SDL_FullscreenOp fullscreen)
  140. {
  141. // Haiku tracks all video display information
  142. BMessage msg(BWIN_FULLSCREEN);
  143. msg.AddBool("fullscreen", !!fullscreen);
  144. _ToBeWin(window)->PostMessage(&msg);
  145. return SDL_FULLSCREEN_SUCCEEDED;
  146. }
  147. void HAIKU_SetWindowMinimumSize(SDL_VideoDevice *_this, SDL_Window * window)
  148. {
  149. BMessage msg(BWIN_MINIMUM_SIZE_WINDOW);
  150. msg.AddInt32("window-w", window->w -1);
  151. msg.AddInt32("window-h", window->h -1);
  152. _ToBeWin(window)->PostMessage(&msg);
  153. }
  154. bool HAIKU_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window * window, bool grabbed)
  155. {
  156. // TODO: Implement this!
  157. return SDL_Unsupported();
  158. }
  159. bool HAIKU_SetWindowParent(SDL_VideoDevice *_this, SDL_Window * window, SDL_Window *parent)
  160. {
  161. return true;
  162. }
  163. bool HAIKU_SetWindowModal(SDL_VideoDevice *_this, SDL_Window *window, bool modal)
  164. {
  165. if (modal) {
  166. _ToBeWin(window)->SetLook(B_MODAL_WINDOW_LOOK);
  167. _ToBeWin(window)->SetFeel(B_MODAL_SUBSET_WINDOW_FEEL);
  168. _ToBeWin(window)->AddToSubset(_ToBeWin(window->parent));
  169. } else {
  170. window_look look = (window->flags & SDL_WINDOW_BORDERLESS) ? B_NO_BORDER_WINDOW_LOOK : B_TITLED_WINDOW_LOOK;
  171. _ToBeWin(window)->RemoveFromSubset(_ToBeWin(window->parent));
  172. _ToBeWin(window)->SetLook(look);
  173. _ToBeWin(window)->SetFeel(B_NORMAL_WINDOW_FEEL);
  174. }
  175. return true;
  176. }
  177. void HAIKU_DestroyWindow(SDL_VideoDevice *_this, SDL_Window * window)
  178. {
  179. _ToBeWin(window)->LockLooper(); // This MUST be locked
  180. _GetBeLooper()->ClearID(_ToBeWin(window));
  181. _ToBeWin(window)->Quit();
  182. window->internal = NULL;
  183. }
  184. #ifdef __cplusplus
  185. }
  186. #endif
  187. #endif // SDL_VIDEO_DRIVER_HAIKU