Skip to content

Latest commit

 

History

History
243 lines (191 loc) · 6.94 KB

SDL_bwindow.cc

File metadata and controls

243 lines (191 loc) · 6.94 KB
 
1
2
/*
Simple DirectMedia Layer
Jan 5, 2019
Jan 5, 2019
3
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_HAIKU
#include "../SDL_sysvideo.h"
#include "SDL_BWin.h"
#include <new>
Nov 11, 2019
Nov 11, 2019
29
30
#include "SDL_syswm.h"
31
32
33
34
35
36
/* Define a path to window's BWIN data */
#ifdef __cplusplus
extern "C" {
#endif
static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) {
Sep 24, 2018
Sep 24, 2018
37
return ((SDL_BWin*)(window->driverdata));
38
39
40
}
static SDL_INLINE SDL_BApp *_GetBeApp() {
Sep 24, 2018
Sep 24, 2018
41
return ((SDL_BApp*)be_app);
42
43
44
}
static int _InitWindow(_THIS, SDL_Window *window) {
Sep 24, 2018
Sep 24, 2018
45
46
uint32 flags = 0;
window_look look = B_TITLED_WINDOW_LOOK;
Sep 24, 2018
Sep 24, 2018
48
BRect bounds(
49
50
window->x,
window->y,
Sep 24, 2018
Sep 24, 2018
51
window->x + window->w - 1, //BeWindows have an off-by-one px w/h thing
52
53
54
55
window->y + window->h - 1
);
if(window->flags & SDL_WINDOW_FULLSCREEN) {
Sep 24, 2018
Sep 24, 2018
56
57
/* TODO: Add support for this flag */
printf(__FILE__": %d!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",__LINE__);
58
59
}
if(window->flags & SDL_WINDOW_OPENGL) {
Sep 24, 2018
Sep 24, 2018
60
/* TODO: Add support for this flag */
61
62
}
if(!(window->flags & SDL_WINDOW_RESIZABLE)) {
Sep 24, 2018
Sep 24, 2018
63
flags |= B_NOT_RESIZABLE | B_NOT_ZOOMABLE;
64
65
}
if(window->flags & SDL_WINDOW_BORDERLESS) {
Sep 24, 2018
Sep 24, 2018
66
look = B_NO_BORDER_WINDOW_LOOK;
67
68
69
70
}
SDL_BWin *bwin = new(std::nothrow) SDL_BWin(bounds, look, flags);
if(bwin == NULL)
Jul 2, 2017
Jul 2, 2017
71
return -1;
72
73
74
75
76
77
78
79
window->driverdata = bwin;
int32 winID = _GetBeApp()->GetID(window);
bwin->SetID(winID);
return 0;
}
Aug 7, 2018
Aug 7, 2018
80
int HAIKU_CreateWindow(_THIS, SDL_Window *window) {
Jul 2, 2017
Jul 2, 2017
81
82
83
if (_InitWindow(_this, window) < 0) {
return -1;
}
Sep 24, 2018
Sep 24, 2018
84
85
/* Start window loop */
86
87
88
89
_ToBeWin(window)->Show();
return 0;
}
Aug 7, 2018
Aug 7, 2018
90
int HAIKU_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) {
Sep 24, 2018
Sep 24, 2018
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
SDL_BWin *otherBWin = (SDL_BWin*)data;
if(!otherBWin->LockLooper())
return -1;
/* Create the new window and initialize its members */
window->x = (int)otherBWin->Frame().left;
window->y = (int)otherBWin->Frame().top;
window->w = (int)otherBWin->Frame().Width();
window->h = (int)otherBWin->Frame().Height();
/* Set SDL flags */
if(!(otherBWin->Flags() & B_NOT_RESIZABLE)) {
window->flags |= SDL_WINDOW_RESIZABLE;
}
/* If we are out of memory, return the error code */
Jul 2, 2017
Jul 2, 2017
108
109
110
if (_InitWindow(_this, window) < 0) {
return -1;
}
Sep 24, 2018
Sep 24, 2018
111
112
/* TODO: Add any other SDL-supported window attributes here */
113
114
115
116
117
118
119
120
121
_ToBeWin(window)->SetTitle(otherBWin->Title());
/* Start window loop and unlock the other window */
_ToBeWin(window)->Show();
otherBWin->UnlockLooper();
return 0;
}
Aug 7, 2018
Aug 7, 2018
122
void HAIKU_SetWindowTitle(_THIS, SDL_Window * window) {
Sep 24, 2018
Sep 24, 2018
123
124
125
BMessage msg(BWIN_SET_TITLE);
msg.AddString("window-title", window->title);
_ToBeWin(window)->PostMessage(&msg);
Aug 7, 2018
Aug 7, 2018
128
void HAIKU_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon) {
Sep 24, 2018
Sep 24, 2018
129
/* FIXME: Icons not supported by Haiku */
Aug 7, 2018
Aug 7, 2018
132
void HAIKU_SetWindowPosition(_THIS, SDL_Window * window) {
Sep 24, 2018
Sep 24, 2018
133
134
135
136
BMessage msg(BWIN_MOVE_WINDOW);
msg.AddInt32("window-x", window->x);
msg.AddInt32("window-y", window->y);
_ToBeWin(window)->PostMessage(&msg);
Aug 7, 2018
Aug 7, 2018
139
void HAIKU_SetWindowSize(_THIS, SDL_Window * window) {
Sep 24, 2018
Sep 24, 2018
140
141
142
143
BMessage msg(BWIN_RESIZE_WINDOW);
msg.AddInt32("window-w", window->w - 1);
msg.AddInt32("window-h", window->h - 1);
_ToBeWin(window)->PostMessage(&msg);
Aug 7, 2018
Aug 7, 2018
146
void HAIKU_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered) {
Sep 24, 2018
Sep 24, 2018
147
148
149
BMessage msg(BWIN_SET_BORDERED);
msg.AddBool("window-border", bordered != SDL_FALSE);
_ToBeWin(window)->PostMessage(&msg);
Aug 7, 2018
Aug 7, 2018
152
void HAIKU_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable) {
Sep 24, 2018
Sep 24, 2018
153
154
155
BMessage msg(BWIN_SET_RESIZABLE);
msg.AddBool("window-resizable", resizable != SDL_FALSE);
_ToBeWin(window)->PostMessage(&msg);
Sep 30, 2016
Sep 30, 2016
156
157
}
Aug 7, 2018
Aug 7, 2018
158
void HAIKU_ShowWindow(_THIS, SDL_Window * window) {
Sep 24, 2018
Sep 24, 2018
159
160
BMessage msg(BWIN_SHOW_WINDOW);
_ToBeWin(window)->PostMessage(&msg);
Aug 7, 2018
Aug 7, 2018
163
void HAIKU_HideWindow(_THIS, SDL_Window * window) {
Sep 24, 2018
Sep 24, 2018
164
165
BMessage msg(BWIN_HIDE_WINDOW);
_ToBeWin(window)->PostMessage(&msg);
Aug 7, 2018
Aug 7, 2018
168
void HAIKU_RaiseWindow(_THIS, SDL_Window * window) {
Sep 24, 2018
Sep 24, 2018
169
170
BMessage msg(BWIN_SHOW_WINDOW); /* Activate this window and move to front */
_ToBeWin(window)->PostMessage(&msg);
Aug 7, 2018
Aug 7, 2018
173
void HAIKU_MaximizeWindow(_THIS, SDL_Window * window) {
Sep 24, 2018
Sep 24, 2018
174
175
BMessage msg(BWIN_MAXIMIZE_WINDOW);
_ToBeWin(window)->PostMessage(&msg);
Aug 7, 2018
Aug 7, 2018
178
void HAIKU_MinimizeWindow(_THIS, SDL_Window * window) {
Sep 24, 2018
Sep 24, 2018
179
180
BMessage msg(BWIN_MINIMIZE_WINDOW);
_ToBeWin(window)->PostMessage(&msg);
Aug 7, 2018
Aug 7, 2018
183
void HAIKU_RestoreWindow(_THIS, SDL_Window * window) {
Sep 24, 2018
Sep 24, 2018
184
185
BMessage msg(BWIN_RESTORE_WINDOW);
_ToBeWin(window)->PostMessage(&msg);
Aug 7, 2018
Aug 7, 2018
188
void HAIKU_SetWindowFullscreen(_THIS, SDL_Window * window,
Sep 24, 2018
Sep 24, 2018
189
190
191
192
193
194
SDL_VideoDisplay * display, SDL_bool fullscreen) {
/* Haiku tracks all video display information */
BMessage msg(BWIN_FULLSCREEN);
msg.AddBool("fullscreen", fullscreen);
_ToBeWin(window)->PostMessage(&msg);
Aug 7, 2018
Aug 7, 2018
197
int HAIKU_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp) {
Sep 24, 2018
Sep 24, 2018
198
199
/* FIXME: Not Haiku supported */
return -1;
Aug 7, 2018
Aug 7, 2018
202
int HAIKU_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp) {
Sep 24, 2018
Sep 24, 2018
203
204
/* FIXME: Not Haiku supported */
return -1;
Aug 7, 2018
Aug 7, 2018
208
void HAIKU_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed) {
Sep 24, 2018
Sep 24, 2018
209
/* TODO: Implement this! */
Aug 7, 2018
Aug 7, 2018
212
void HAIKU_DestroyWindow(_THIS, SDL_Window * window) {
Sep 24, 2018
Sep 24, 2018
213
214
215
216
_ToBeWin(window)->LockLooper(); /* This MUST be locked */
_GetBeApp()->ClearID(_ToBeWin(window));
_ToBeWin(window)->Quit();
window->driverdata = NULL;
Aug 7, 2018
Aug 7, 2018
219
SDL_bool HAIKU_GetWindowWMInfo(_THIS, SDL_Window * window,
220
struct SDL_SysWMinfo *info) {
Sep 24, 2018
Sep 24, 2018
221
/* FIXME: What is the point of this? What information should be included? */
Nov 11, 2019
Nov 11, 2019
222
223
224
225
226
227
228
229
230
if (info->version.major == SDL_MAJOR_VERSION &&
info->version.minor == SDL_MINOR_VERSION) {
info->subsystem = SDL_SYSWM_HAIKU;
return SDL_TRUE;
} else {
SDL_SetError("Application not compiled with SDL %d.%d",
SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
return SDL_FALSE;
}
231
232
233
234
235
236
237
238
239
240
241
}
#ifdef __cplusplus
}
#endif
#endif /* SDL_VIDEO_DRIVER_HAIKU */
Dec 9, 2016
Dec 9, 2016
242
243
/* vi: set ts=4 sw=4 expandtab: */