SDL  2.0
SDL_bwindow.cc
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2020 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 #if SDL_VIDEO_DRIVER_HAIKU
24 #include "../SDL_sysvideo.h"
25 
26 #include "SDL_BWin.h"
27 #include <new>
28 
29 #include "SDL_syswm.h"
30 
31 /* Define a path to window's BWIN data */
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) {
37  return ((SDL_BWin*)(window->driverdata));
38 }
39 
40 static SDL_INLINE SDL_BApp *_GetBeApp() {
41  return ((SDL_BApp*)be_app);
42 }
43 
44 static int _InitWindow(_THIS, SDL_Window *window) {
45  uint32 flags = 0;
46  window_look look = B_TITLED_WINDOW_LOOK;
47 
48  BRect bounds(
49  window->x,
50  window->y,
51  window->x + window->w - 1, //BeWindows have an off-by-one px w/h thing
52  window->y + window->h - 1
53  );
54 
55  if(window->flags & SDL_WINDOW_FULLSCREEN) {
56  /* TODO: Add support for this flag */
57  printf(__FILE__": %d!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",__LINE__);
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 == NULL)
71  return -1;
72 
73  window->driverdata = bwin;
74  int32 winID = _GetBeApp()->GetID(window);
75  bwin->SetID(winID);
76 
77  return 0;
78 }
79 
81  if (_InitWindow(_this, window) < 0) {
82  return -1;
83  }
84 
85  /* Start window loop */
86  _ToBeWin(window)->Show();
87  return 0;
88 }
89 
90 int HAIKU_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) {
91 
92  SDL_BWin *otherBWin = (SDL_BWin*)data;
93  if(!otherBWin->LockLooper())
94  return -1;
95 
96  /* Create the new window and initialize its members */
97  window->x = (int)otherBWin->Frame().left;
98  window->y = (int)otherBWin->Frame().top;
99  window->w = (int)otherBWin->Frame().Width();
100  window->h = (int)otherBWin->Frame().Height();
101 
102  /* Set SDL flags */
103  if(!(otherBWin->Flags() & B_NOT_RESIZABLE)) {
104  window->flags |= SDL_WINDOW_RESIZABLE;
105  }
106 
107  /* If we are out of memory, return the error code */
108  if (_InitWindow(_this, window) < 0) {
109  return -1;
110  }
111 
112  /* TODO: Add any other SDL-supported window attributes here */
113  _ToBeWin(window)->SetTitle(otherBWin->Title());
114 
115  /* Start window loop and unlock the other window */
116  _ToBeWin(window)->Show();
117 
118  otherBWin->UnlockLooper();
119  return 0;
120 }
121 
123  BMessage msg(BWIN_SET_TITLE);
124  msg.AddString("window-title", window->title);
125  _ToBeWin(window)->PostMessage(&msg);
126 }
127 
129  /* FIXME: Icons not supported by Haiku */
130 }
131 
133  BMessage msg(BWIN_MOVE_WINDOW);
134  msg.AddInt32("window-x", window->x);
135  msg.AddInt32("window-y", window->y);
136  _ToBeWin(window)->PostMessage(&msg);
137 }
138 
140  BMessage msg(BWIN_RESIZE_WINDOW);
141  msg.AddInt32("window-w", window->w - 1);
142  msg.AddInt32("window-h", window->h - 1);
143  _ToBeWin(window)->PostMessage(&msg);
144 }
145 
147  BMessage msg(BWIN_SET_BORDERED);
148  msg.AddBool("window-border", bordered != SDL_FALSE);
149  _ToBeWin(window)->PostMessage(&msg);
150 }
151 
153  BMessage msg(BWIN_SET_RESIZABLE);
154  msg.AddBool("window-resizable", resizable != SDL_FALSE);
155  _ToBeWin(window)->PostMessage(&msg);
156 }
157 
159  BMessage msg(BWIN_SHOW_WINDOW);
160  _ToBeWin(window)->PostMessage(&msg);
161 }
162 
164  BMessage msg(BWIN_HIDE_WINDOW);
165  _ToBeWin(window)->PostMessage(&msg);
166 }
167 
169  BMessage msg(BWIN_SHOW_WINDOW); /* Activate this window and move to front */
170  _ToBeWin(window)->PostMessage(&msg);
171 }
172 
174  BMessage msg(BWIN_MAXIMIZE_WINDOW);
175  _ToBeWin(window)->PostMessage(&msg);
176 }
177 
179  BMessage msg(BWIN_MINIMIZE_WINDOW);
180  _ToBeWin(window)->PostMessage(&msg);
181 }
182 
184  BMessage msg(BWIN_RESTORE_WINDOW);
185  _ToBeWin(window)->PostMessage(&msg);
186 }
187 
189  SDL_VideoDisplay * display, SDL_bool fullscreen) {
190  /* Haiku tracks all video display information */
191  BMessage msg(BWIN_FULLSCREEN);
192  msg.AddBool("fullscreen", fullscreen);
193  _ToBeWin(window)->PostMessage(&msg);
194 
195 }
196 
197 int HAIKU_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp) {
198  /* FIXME: Not Haiku supported */
199  return -1;
200 }
201 
203  /* FIXME: Not Haiku supported */
204  return -1;
205 }
206 
207 
209  /* TODO: Implement this! */
210 }
211 
213  _ToBeWin(window)->LockLooper(); /* This MUST be locked */
214  _GetBeApp()->ClearID(_ToBeWin(window));
215  _ToBeWin(window)->Quit();
216  window->driverdata = NULL;
217 }
218 
220  struct SDL_SysWMinfo *info) {
221  /* FIXME: What is the point of this? What information should be included? */
222  if (info->version.major == SDL_MAJOR_VERSION &&
223  info->version.minor == SDL_MINOR_VERSION) {
224  info->subsystem = SDL_SYSWM_HAIKU;
225  return SDL_TRUE;
226  } else {
227  SDL_SetError("Application not compiled with SDL %d.%d",
229  return SDL_FALSE;
230  }
231 }
232 
233 
234 
235 
236 
237 #ifdef __cplusplus
238 }
239 #endif
240 
241 #endif /* SDL_VIDEO_DRIVER_HAIKU */
242 
243 /* vi: set ts=4 sw=4 expandtab: */
HAIKU_SetWindowTitle
void HAIKU_SetWindowTitle(_THIS, SDL_Window *window)
HAIKU_CreateWindow
int HAIKU_CreateWindow(_THIS, SDL_Window *window)
SDL_SYSWM_HAIKU
@ SDL_SYSWM_HAIKU
Definition: SDL_syswm.h:136
Uint16
uint16_t Uint16
Definition: SDL_stdinc.h:191
SDL_Surface
A collection of pixels used in software blitting.
Definition: SDL_surface.h:71
BWIN_RESIZE_WINDOW
@ BWIN_RESIZE_WINDOW
Definition: SDL_BWin.h:51
HAIKU_RaiseWindow
void HAIKU_RaiseWindow(_THIS, SDL_Window *window)
HAIKU_MinimizeWindow
void HAIKU_MinimizeWindow(_THIS, SDL_Window *window)
HAIKU_SetWindowGammaRamp
int HAIKU_SetWindowGammaRamp(_THIS, SDL_Window *window, const Uint16 *ramp)
NULL
#define NULL
Definition: begin_code.h:167
HAIKU_CreateWindowFrom
int HAIKU_CreateWindowFrom(_THIS, SDL_Window *window, const void *data)
SDL_SysWMinfo
Definition: SDL_syswm.h:202
SDL_BWin
Definition: SDL_BWin.h:65
SDL_version::minor
Uint8 minor
Definition: SDL_version.h:54
BWIN_HIDE_WINDOW
@ BWIN_HIDE_WINDOW
Definition: SDL_BWin.h:53
SDL_WINDOW_FULLSCREEN
@ SDL_WINDOW_FULLSCREEN
Definition: SDL_video.h:99
SDL_WINDOW_OPENGL
@ SDL_WINDOW_OPENGL
Definition: SDL_video.h:100
HAIKU_RestoreWindow
void HAIKU_RestoreWindow(_THIS, SDL_Window *window)
BWIN_MINIMIZE_WINDOW
@ BWIN_MINIMIZE_WINDOW
Definition: SDL_BWin.h:55
SDL_BWin::SetID
void SetID(int32 id)
Definition: SDL_BWin.h:455
HAIKU_SetWindowGrab
void HAIKU_SetWindowGrab(_THIS, SDL_Window *window, SDL_bool grabbed)
BWIN_SET_RESIZABLE
@ BWIN_SET_RESIZABLE
Definition: SDL_BWin.h:59
SDL_WINDOW_RESIZABLE
@ SDL_WINDOW_RESIZABLE
Definition: SDL_video.h:104
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
HAIKU_SetWindowResizable
void HAIKU_SetWindowResizable(_THIS, SDL_Window *window, SDL_bool resizable)
SDL_Window
The type used to identify a window.
Definition: SDL_sysvideo.h:75
BWIN_SET_BORDERED
@ BWIN_SET_BORDERED
Definition: SDL_BWin.h:58
SDL_BWin::GetID
int32 GetID()
Definition: SDL_BWin.h:435
HAIKU_MaximizeWindow
void HAIKU_MaximizeWindow(_THIS, SDL_Window *window)
BWIN_SET_TITLE
@ BWIN_SET_TITLE
Definition: SDL_BWin.h:57
_this
static SDL_VideoDevice * _this
Definition: SDL_video.c:121
HAIKU_ShowWindow
void HAIKU_ShowWindow(_THIS, SDL_Window *window)
SDL_MINOR_VERSION
#define SDL_MINOR_VERSION
Definition: SDL_version.h:61
HAIKU_GetWindowWMInfo
SDL_bool HAIKU_GetWindowWMInfo(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info)
SDL_SysWMinfo::subsystem
SDL_SYSWM_TYPE subsystem
Definition: SDL_syswm.h:204
BWIN_SHOW_WINDOW
@ BWIN_SHOW_WINDOW
Definition: SDL_BWin.h:52
window
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
SDL_INLINE
#define SDL_INLINE
Definition: begin_code.h:134
HAIKU_SetWindowIcon
void HAIKU_SetWindowIcon(_THIS, SDL_Window *window, SDL_Surface *icon)
HAIKU_DestroyWindow
void HAIKU_DestroyWindow(_THIS, SDL_Window *window)
BWIN_MOVE_WINDOW
@ BWIN_MOVE_WINDOW
Definition: SDL_BWin.h:50
HAIKU_GetWindowGammaRamp
int HAIKU_GetWindowGammaRamp(_THIS, SDL_Window *window, Uint16 *ramp)
_THIS
#define _THIS
Definition: SDL_alsa_audio.h:31
HAIKU_SetWindowSize
void HAIKU_SetWindowSize(_THIS, SDL_Window *window)
SDL_TRUE
@ SDL_TRUE
Definition: SDL_stdinc.h:164
HAIKU_SetWindowBordered
void HAIKU_SetWindowBordered(_THIS, SDL_Window *window, SDL_bool bordered)
HAIKU_SetWindowPosition
void HAIKU_SetWindowPosition(_THIS, SDL_Window *window)
SDL_BWin.h
SDL_SysWMinfo::version
SDL_version version
Definition: SDL_syswm.h:203
BWIN_FULLSCREEN
@ BWIN_FULLSCREEN
Definition: SDL_BWin.h:60
SDL_VideoDisplay
Definition: SDL_sysvideo.h:127
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:30
BWIN_RESTORE_WINDOW
@ BWIN_RESTORE_WINDOW
Definition: SDL_BWin.h:56
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:162
HAIKU_HideWindow
void HAIKU_HideWindow(_THIS, SDL_Window *window)
SDL_FALSE
@ SDL_FALSE
Definition: SDL_stdinc.h:163
HAIKU_SetWindowFullscreen
void HAIKU_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen)
SDL_BApp
Definition: SDL_BApp.h:81
SDL_version::major
Uint8 major
Definition: SDL_version.h:53
flags
GLbitfield flags
Definition: SDL_opengl_glext.h:1483
BWIN_MAXIMIZE_WINDOW
@ BWIN_MAXIMIZE_WINDOW
Definition: SDL_BWin.h:54
SDL_MAJOR_VERSION
#define SDL_MAJOR_VERSION
Definition: SDL_version.h:60
SDL_syswm.h
SDL_WINDOW_BORDERLESS
@ SDL_WINDOW_BORDERLESS
Definition: SDL_video.h:103