/project/jni/sdl-1.3/src/video/bwindow/SDL_bwindow.cc

https://github.com/aichunyu/FFPlayer · C++ · 215 lines · 135 code · 44 blank · 36 comment · 12 complexity · d450d99f57fe0da88eb48d02c9774081 MD5 · raw file

  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2012 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_config.h"
  19. #if SDL_VIDEO_DRIVER_BWINDOW
  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 inline SDL_BWin *_ToBeWin(SDL_Window *window) {
  28. return ((SDL_BWin*)(window->driverdata));
  29. }
  30. static inline SDL_BApp *_GetBeApp() {
  31. return ((SDL_BApp*)be_app);
  32. }
  33. static int _InitWindow(_THIS, SDL_Window *window) {
  34. uint32 flags = 0;
  35. BRect bounds(
  36. window->x,
  37. window->y,
  38. window->x + window->w - 1, //BeWindows have an off-by-one px w/h thing
  39. window->y + window->h - 1
  40. );
  41. if(window->flags & SDL_WINDOW_FULLSCREEN) {
  42. /* TODO: Add support for this flag */
  43. printf(__FILE__": %d!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",__LINE__);
  44. }
  45. if(window->flags & SDL_WINDOW_OPENGL) {
  46. /* TODO: Add support for this flag */
  47. }
  48. if(!(window->flags & SDL_WINDOW_RESIZABLE)) {
  49. flags |= B_NOT_RESIZABLE | B_NOT_ZOOMABLE;
  50. }
  51. if(window->flags & SDL_WINDOW_BORDERLESS) {
  52. /* TODO: Add support for this flag */
  53. }
  54. SDL_BWin *bwin = new(std::nothrow) SDL_BWin(bounds, flags);
  55. if(bwin == NULL)
  56. return ENOMEM;
  57. window->driverdata = bwin;
  58. int32 winID = _GetBeApp()->GetID(window);
  59. bwin->SetID(winID);
  60. return 0;
  61. }
  62. int BE_CreateWindow(_THIS, SDL_Window *window) {
  63. if(_InitWindow(_this, window) == ENOMEM)
  64. return ENOMEM;
  65. /* Start window loop */
  66. _ToBeWin(window)->Show();
  67. return 0;
  68. }
  69. int BE_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) {
  70. SDL_BWin *otherBWin = (SDL_BWin*)data;
  71. if(!otherBWin->LockLooper())
  72. return -1;
  73. /* Create the new window and initialize its members */
  74. window->x = (int)otherBWin->Frame().left;
  75. window->y = (int)otherBWin->Frame().top;
  76. window->w = (int)otherBWin->Frame().Width();
  77. window->h = (int)otherBWin->Frame().Height();
  78. /* Set SDL flags */
  79. if(!(otherBWin->Flags() & B_NOT_RESIZABLE)) {
  80. window->flags |= SDL_WINDOW_RESIZABLE;
  81. }
  82. /* If we are out of memory, return the error code */
  83. if(_InitWindow(_this, window) == ENOMEM)
  84. return ENOMEM;
  85. /* TODO: Add any other SDL-supported window attributes here */
  86. _ToBeWin(window)->SetTitle(otherBWin->Title());
  87. /* Start window loop and unlock the other window */
  88. _ToBeWin(window)->Show();
  89. otherBWin->UnlockLooper();
  90. return 0;
  91. }
  92. void BE_SetWindowTitle(_THIS, SDL_Window * window) {
  93. BMessage msg(BWIN_SET_TITLE);
  94. msg.AddString("window-title", window->title);
  95. _ToBeWin(window)->PostMessage(&msg);
  96. }
  97. void BE_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon) {
  98. /* FIXME: Icons not supported by BeOs/Haiku */
  99. }
  100. void BE_SetWindowPosition(_THIS, SDL_Window * window) {
  101. BMessage msg(BWIN_MOVE_WINDOW);
  102. msg.AddInt32("window-x", window->x);
  103. msg.AddInt32("window-y", window->y);
  104. _ToBeWin(window)->PostMessage(&msg);
  105. }
  106. void BE_SetWindowSize(_THIS, SDL_Window * window) {
  107. BMessage msg(BWIN_RESIZE_WINDOW);
  108. msg.AddInt32("window-w", window->w - 1);
  109. msg.AddInt32("window-h", window->h - 1);
  110. _ToBeWin(window)->PostMessage(&msg);
  111. }
  112. void BE_ShowWindow(_THIS, SDL_Window * window) {
  113. BMessage msg(BWIN_SHOW_WINDOW);
  114. _ToBeWin(window)->PostMessage(&msg);
  115. }
  116. void BE_HideWindow(_THIS, SDL_Window * window) {
  117. BMessage msg(BWIN_HIDE_WINDOW);
  118. _ToBeWin(window)->PostMessage(&msg);
  119. }
  120. void BE_RaiseWindow(_THIS, SDL_Window * window) {
  121. BMessage msg(BWIN_SHOW_WINDOW); /* Activate this window and move to front */
  122. _ToBeWin(window)->PostMessage(&msg);
  123. }
  124. void BE_MaximizeWindow(_THIS, SDL_Window * window) {
  125. BMessage msg(BWIN_MAXIMIZE_WINDOW);
  126. _ToBeWin(window)->PostMessage(&msg);
  127. }
  128. void BE_MinimizeWindow(_THIS, SDL_Window * window) {
  129. BMessage msg(BWIN_MINIMIZE_WINDOW);
  130. _ToBeWin(window)->PostMessage(&msg);
  131. }
  132. void BE_RestoreWindow(_THIS, SDL_Window * window) {
  133. BMessage msg(BWIN_RESTORE_WINDOW);
  134. _ToBeWin(window)->PostMessage(&msg);
  135. }
  136. void BE_SetWindowFullscreen(_THIS, SDL_Window * window,
  137. SDL_VideoDisplay * display, SDL_bool fullscreen) {
  138. /* Haiku tracks all video display information */
  139. BMessage msg(BWIN_FULLSCREEN);
  140. msg.AddBool("fullscreen", fullscreen);
  141. _ToBeWin(window)->PostMessage(&msg);
  142. }
  143. int BE_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp) {
  144. /* FIXME: Not BeOs/Haiku supported */
  145. return -1;
  146. }
  147. int BE_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp) {
  148. /* FIXME: Not BeOs/Haiku supported */
  149. return -1;
  150. }
  151. void BE_SetWindowGrab(_THIS, SDL_Window * window) {
  152. /* TODO: Implement this! */
  153. }
  154. void BE_DestroyWindow(_THIS, SDL_Window * window) {
  155. _ToBeWin(window)->LockLooper(); /* This MUST be locked */
  156. _GetBeApp()->ClearID(_ToBeWin(window));
  157. _ToBeWin(window)->Quit();
  158. window->driverdata = NULL;
  159. }
  160. SDL_bool BE_GetWindowWMInfo(_THIS, SDL_Window * window,
  161. struct SDL_SysWMinfo *info) {
  162. /* FIXME: What is the point of this? What information should be included? */
  163. return SDL_FALSE;
  164. }
  165. #ifdef __cplusplus
  166. }
  167. #endif
  168. #endif /* SDL_VIDEO_DRIVER_BWINDOW */