SDL 2.0
SDL_BApp Class Reference

#include <SDL_BApp.h>

+ Inheritance diagram for SDL_BApp:
+ Collaboration diagram for SDL_BApp:

Public Member Functions

 SDL_BApp (const char *signature)
 
virtual ~SDL_BApp ()
 
virtual void MessageReceived (BMessage *message)
 
int32 GetID (SDL_Window *win)
 
void ClearID (SDL_BWin *bwin)
 
SDL_WindowGetSDLWindow (int32 winID)
 

Private Member Functions

void _HandleBasicWindowEvent (BMessage *msg, int32 sdlEventType)
 
void _HandleMouseMove (BMessage *msg)
 
void _HandleMouseButton (BMessage *msg)
 
void _HandleMouseWheel (BMessage *msg)
 
void _HandleKey (BMessage *msg)
 
void _HandleMouseFocus (BMessage *msg)
 
void _HandleKeyboardFocus (BMessage *msg)
 
void _HandleWindowMoved (BMessage *msg)
 
void _HandleWindowResized (BMessage *msg)
 
bool _GetWinID (BMessage *msg, int32 *winID)
 
void _SetSDLWindow (SDL_Window *win, int32 winID)
 
int32 _GetNumWindowSlots ()
 
void _PopBackWindow ()
 
void _PushBackWindow (SDL_Window *win)
 

Private Attributes

std::vector< SDL_Window * > _window_map
 

Detailed Description

Definition at line 81 of file SDL_BApp.h.

Constructor & Destructor Documentation

◆ SDL_BApp()

SDL_BApp::SDL_BApp ( const char *  signature)
inline

Definition at line 83 of file SDL_BApp.h.

83 :
84 BApplication(signature) {
85#if SDL_VIDEO_OPENGL
86 _current_context = NULL;
87#endif
88 }
#define NULL
Definition: begin_code.h:167

References NULL.

◆ ~SDL_BApp()

virtual SDL_BApp::~SDL_BApp ( )
inlinevirtual

Definition at line 91 of file SDL_BApp.h.

91 {
92 }

Member Function Documentation

◆ _GetNumWindowSlots()

int32 SDL_BApp::_GetNumWindowSlots ( )
inlineprivate

Definition at line 377 of file SDL_BApp.h.

377 {
378 return _window_map.size();
379 }
std::vector< SDL_Window * > _window_map
Definition: SDL_BApp.h:392

References _window_map.

Referenced by GetID().

◆ _GetWinID()

bool SDL_BApp::_GetWinID ( BMessage *  msg,
int32 *  winID 
)
inlineprivate

Definition at line 365 of file SDL_BApp.h.

365 {
366 return msg->FindInt32("window-id", winID) == B_OK;
367 }

Referenced by _HandleBasicWindowEvent(), _HandleKeyboardFocus(), _HandleMouseButton(), _HandleMouseFocus(), _HandleMouseMove(), _HandleMouseWheel(), _HandleWindowMoved(), and _HandleWindowResized().

◆ _HandleBasicWindowEvent()

void SDL_BApp::_HandleBasicWindowEvent ( BMessage *  msg,
int32  sdlEventType 
)
inlineprivate

Definition at line 207 of file SDL_BApp.h.

207 {
208 SDL_Window *win;
209 int32 winID;
210 if(
211 !_GetWinID(msg, &winID)
212 ) {
213 return;
214 }
215 win = GetSDLWindow(winID);
216 SDL_SendWindowEvent(win, sdlEventType, 0, 0);
217 }
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
SDL_Window * GetSDLWindow(int32 winID)
Definition: SDL_BApp.h:191
bool _GetWinID(BMessage *msg, int32 *winID)
Definition: SDL_BApp.h:365
The type used to identify a window.
Definition: SDL_sysvideo.h:74

References _GetWinID(), GetSDLWindow(), and SDL_SendWindowEvent().

Referenced by MessageReceived().

◆ _HandleKey()

void SDL_BApp::_HandleKey ( BMessage *  msg)
inlineprivate

Definition at line 267 of file SDL_BApp.h.

267 {
268 int32 scancode, state; /* scancode, pressed/released */
269 if(
270 msg->FindInt32("key-state", &state) != B_OK ||
271 msg->FindInt32("key-scancode", &scancode) != B_OK
272 ) {
273 return;
274 }
275
276 /* Make sure this isn't a repeated event (key pressed and held) */
277 if(state == SDL_PRESSED && HAIKU_GetKeyState(scancode) == SDL_PRESSED) {
278 return;
279 }
280 HAIKU_SetKeyState(scancode, state);
282
284 const int8 *keyUtf8;
285 ssize_t count;
286 if (msg->FindData("key-utf8", B_INT8_TYPE, (const void**)&keyUtf8, &count) == B_OK) {
288 SDL_zero(text);
289 SDL_memcpy(text, keyUtf8, count);
291 }
292 }
293 }
int8 HAIKU_GetKeyState(int32 bkey)
void HAIKU_SetKeyState(int32 bkey, int8 state)
SDL_Scancode HAIKU_GetScancodeFromBeKey(int32 bkey)
#define SDL_EventState
#define SDL_memcpy
@ SDL_TEXTINPUT
Definition: SDL_events.h:99
#define SDL_TEXTINPUTEVENT_TEXT_SIZE
Definition: SDL_events.h:238
#define SDL_QUERY
Definition: SDL_events.h:756
#define SDL_PRESSED
Definition: SDL_events.h:50
int SDL_SendKeyboardText(const char *text)
Definition: SDL_keyboard.c:789
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
Definition: SDL_keyboard.c:679
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
#define SDL_zero(x)
Definition: SDL_stdinc.h:416
struct xkb_state * state
static char text[MAX_TEXT_LENGTH]
Definition: testime.c:47

References HAIKU_GetKeyState(), HAIKU_GetScancodeFromBeKey(), HAIKU_SetKeyState(), SDL_EventState, SDL_memcpy, SDL_PRESSED, SDL_QUERY, SDL_SendKeyboardKey(), SDL_SendKeyboardText(), SDL_TEXTINPUT, SDL_TEXTINPUTEVENT_TEXT_SIZE, SDL_zero, state, and text.

Referenced by MessageReceived().

◆ _HandleKeyboardFocus()

void SDL_BApp::_HandleKeyboardFocus ( BMessage *  msg)
inlineprivate

Definition at line 314 of file SDL_BApp.h.

314 {
315 SDL_Window *win;
316 int32 winID;
317 bool bSetFocus; /* If false, lose focus */
318 if(
319 !_GetWinID(msg, &winID) ||
320 msg->FindBool("focusGained", &bSetFocus) != B_OK
321 ) {
322 return;
323 }
324 win = GetSDLWindow(winID);
325 if(bSetFocus) {
327 } else if(SDL_GetKeyboardFocus() == win) {
328 /* Only lose all focus if this window was the current focus */
330 }
331 }
#define SDL_GetKeyboardFocus
void SDL_SetKeyboardFocus(SDL_Window *window)
Definition: SDL_keyboard.c:630

References _GetWinID(), GetSDLWindow(), NULL, SDL_GetKeyboardFocus, and SDL_SetKeyboardFocus().

Referenced by MessageReceived().

◆ _HandleMouseButton()

void SDL_BApp::_HandleMouseButton ( BMessage *  msg)
inlineprivate

Definition at line 237 of file SDL_BApp.h.

237 {
238 SDL_Window *win;
239 int32 winID;
240 int32 button, state; /* left/middle/right, pressed/released */
241 if(
242 !_GetWinID(msg, &winID) ||
243 msg->FindInt32("button-id", &button) != B_OK ||
244 msg->FindInt32("button-state", &state) != B_OK
245 ) {
246 return;
247 }
248 win = GetSDLWindow(winID);
250 }
int SDL_SendMouseButton(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button)
Definition: SDL_mouse.c:605
SDL_Texture * button

References _GetWinID(), button, GetSDLWindow(), SDL_SendMouseButton(), and state.

Referenced by MessageReceived().

◆ _HandleMouseFocus()

void SDL_BApp::_HandleMouseFocus ( BMessage *  msg)
inlineprivate

Definition at line 295 of file SDL_BApp.h.

295 {
296 SDL_Window *win;
297 int32 winID;
298 bool bSetFocus; /* If false, lose focus */
299 if(
300 !_GetWinID(msg, &winID) ||
301 msg->FindBool("focusGained", &bSetFocus) != B_OK
302 ) {
303 return;
304 }
305 win = GetSDLWindow(winID);
306 if(bSetFocus) {
308 } else if(SDL_GetMouseFocus() == win) {
309 /* Only lose all focus if this window was the current focus */
311 }
312 }
#define SDL_GetMouseFocus
void SDL_SetMouseFocus(SDL_Window *window)
Definition: SDL_mouse.c:211

References _GetWinID(), GetSDLWindow(), NULL, SDL_GetMouseFocus, and SDL_SetMouseFocus().

Referenced by MessageReceived().

◆ _HandleMouseMove()

void SDL_BApp::_HandleMouseMove ( BMessage *  msg)
inlineprivate

Definition at line 219 of file SDL_BApp.h.

219 {
220 SDL_Window *win;
221 int32 winID;
222 int32 x = 0, y = 0;
223 if(
224 !_GetWinID(msg, &winID) ||
225 msg->FindInt32("x", &x) != B_OK || /* x movement */
226 msg->FindInt32("y", &y) != B_OK /* y movement */
227 ) {
228 return;
229 }
230 win = GetSDLWindow(winID);
231 SDL_SendMouseMotion(win, 0, 0, x, y);
232
233 /* Tell the application that the mouse passed over, redraw needed */
235 }
int HAIKU_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect *rects, int numrects)
int SDL_SendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
Definition: SDL_mouse.c:301
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574

References _GetWinID(), GetSDLWindow(), HAIKU_UpdateWindowFramebuffer(), NULL, and SDL_SendMouseMotion().

Referenced by MessageReceived().

◆ _HandleMouseWheel()

void SDL_BApp::_HandleMouseWheel ( BMessage *  msg)
inlineprivate

Definition at line 252 of file SDL_BApp.h.

252 {
253 SDL_Window *win;
254 int32 winID;
255 int32 xTicks, yTicks;
256 if(
257 !_GetWinID(msg, &winID) ||
258 msg->FindInt32("xticks", &xTicks) != B_OK ||
259 msg->FindInt32("yticks", &yTicks) != B_OK
260 ) {
261 return;
262 }
263 win = GetSDLWindow(winID);
264 SDL_SendMouseWheel(win, 0, xTicks, yTicks, SDL_MOUSEWHEEL_NORMAL);
265 }
int SDL_SendMouseWheel(SDL_Window *window, SDL_MouseID mouseID, float x, float y, SDL_MouseWheelDirection direction)
Definition: SDL_mouse.c:611
@ SDL_MOUSEWHEEL_NORMAL
Definition: SDL_mouse.h:68

References _GetWinID(), GetSDLWindow(), SDL_MOUSEWHEEL_NORMAL, and SDL_SendMouseWheel().

Referenced by MessageReceived().

◆ _HandleWindowMoved()

void SDL_BApp::_HandleWindowMoved ( BMessage *  msg)
inlineprivate

Definition at line 333 of file SDL_BApp.h.

333 {
334 SDL_Window *win;
335 int32 winID;
336 int32 xPos, yPos;
337 /* Get the window id and new x/y position of the window */
338 if(
339 !_GetWinID(msg, &winID) ||
340 msg->FindInt32("window-x", &xPos) != B_OK ||
341 msg->FindInt32("window-y", &yPos) != B_OK
342 ) {
343 return;
344 }
345 win = GetSDLWindow(winID);
347 }
@ SDL_WINDOWEVENT_MOVED
Definition: SDL_video.h:153

References _GetWinID(), GetSDLWindow(), SDL_SendWindowEvent(), and SDL_WINDOWEVENT_MOVED.

Referenced by MessageReceived().

◆ _HandleWindowResized()

void SDL_BApp::_HandleWindowResized ( BMessage *  msg)
inlineprivate

Definition at line 349 of file SDL_BApp.h.

349 {
350 SDL_Window *win;
351 int32 winID;
352 int32 w, h;
353 /* Get the window id ]and new x/y position of the window */
354 if(
355 !_GetWinID(msg, &winID) ||
356 msg->FindInt32("window-w", &w) != B_OK ||
357 msg->FindInt32("window-h", &h) != B_OK
358 ) {
359 return;
360 }
361 win = GetSDLWindow(winID);
363 }
GLfloat GLfloat GLfloat GLfloat h
GLubyte GLubyte GLubyte GLubyte w
@ SDL_WINDOWEVENT_RESIZED
Definition: SDL_video.h:155

References _GetWinID(), GetSDLWindow(), SDL_SendWindowEvent(), and SDL_WINDOWEVENT_RESIZED.

Referenced by MessageReceived().

◆ _PopBackWindow()

void SDL_BApp::_PopBackWindow ( )
inlineprivate

Definition at line 382 of file SDL_BApp.h.

382 {
383 _window_map.pop_back();
384 }

References _window_map.

◆ _PushBackWindow()

void SDL_BApp::_PushBackWindow ( SDL_Window win)
inlineprivate

Definition at line 386 of file SDL_BApp.h.

386 {
387 _window_map.push_back(win);
388 }

References _window_map.

Referenced by GetID().

◆ _SetSDLWindow()

void SDL_BApp::_SetSDLWindow ( SDL_Window win,
int32  winID 
)
inlineprivate

Definition at line 373 of file SDL_BApp.h.

373 {
374 _window_map[winID] = win;
375 }

References _window_map.

Referenced by GetID().

◆ ClearID()

void SDL_BApp::ClearID ( SDL_BWin bwin)

◆ GetID()

int32 SDL_BApp::GetID ( SDL_Window win)
inline

Definition at line 167 of file SDL_BApp.h.

167 {
168 int32 i;
169 for(i = 0; i < _GetNumWindowSlots(); ++i) {
170 if( GetSDLWindow(i) == NULL ) {
171 _SetSDLWindow(win, i);
172 return i;
173 }
174 }
175
176 /* Expand the vector if all slots are full */
177 if( i == _GetNumWindowSlots() ) {
178 _PushBackWindow(win);
179 return i;
180 }
181
182 /* TODO: error handling */
183 return 0;
184 }
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
int32 _GetNumWindowSlots()
Definition: SDL_BApp.h:377
void _SetSDLWindow(SDL_Window *win, int32 winID)
Definition: SDL_BApp.h:373
void _PushBackWindow(SDL_Window *win)
Definition: SDL_BApp.h:386

References _GetNumWindowSlots(), _PushBackWindow(), _SetSDLWindow(), GetSDLWindow(), i, and NULL.

◆ GetSDLWindow()

SDL_Window * SDL_BApp::GetSDLWindow ( int32  winID)
inline

◆ MessageReceived()

virtual void SDL_BApp::MessageReceived ( BMessage *  message)
inlinevirtual

Definition at line 97 of file SDL_BApp.h.

97 {
98 /* Sort out SDL-related messages */
99 switch ( message->what ) {
100 case BAPP_MOUSE_MOVED:
102 break;
103
106 break;
107
108 case BAPP_MOUSE_WHEEL:
110 break;
111
112 case BAPP_KEY:
114 break;
115
116 case BAPP_REPAINT:
118 break;
119
120 case BAPP_MAXIMIZE:
122 break;
123
124 case BAPP_MINIMIZE:
126 break;
127
128 case BAPP_SHOW:
130 break;
131
132 case BAPP_HIDE:
134 break;
135
136 case BAPP_MOUSE_FOCUS:
138 break;
139
142 break;
143
146 break;
147
150 break;
151
154 break;
155
157 /* TODO: Handle screen resize or workspace change */
158 break;
159
160 default:
161 BApplication::MessageReceived(message);
162 break;
163 }
164 }
@ BAPP_MAXIMIZE
Definition: SDL_BApp.h:65
@ BAPP_SCREEN_CHANGED
Definition: SDL_BApp.h:75
@ BAPP_MOUSE_FOCUS
Definition: SDL_BApp.h:70
@ BAPP_WINDOW_MOVED
Definition: SDL_BApp.h:73
@ BAPP_WINDOW_CLOSE_REQUESTED
Definition: SDL_BApp.h:72
@ BAPP_KEY
Definition: SDL_BApp.h:62
@ BAPP_MOUSE_BUTTON
Definition: SDL_BApp.h:60
@ BAPP_REPAINT
Definition: SDL_BApp.h:63
@ BAPP_HIDE
Definition: SDL_BApp.h:69
@ BAPP_KEYBOARD_FOCUS
Definition: SDL_BApp.h:71
@ BAPP_MOUSE_MOVED
Definition: SDL_BApp.h:59
@ BAPP_SHOW
Definition: SDL_BApp.h:68
@ BAPP_MINIMIZE
Definition: SDL_BApp.h:66
@ BAPP_WINDOW_RESIZED
Definition: SDL_BApp.h:74
@ BAPP_MOUSE_WHEEL
Definition: SDL_BApp.h:61
GLuint GLsizei const GLchar * message
@ SDL_WINDOWEVENT_HIDDEN
Definition: SDL_video.h:150
@ SDL_WINDOWEVENT_CLOSE
Definition: SDL_video.h:167
@ SDL_WINDOWEVENT_SHOWN
Definition: SDL_video.h:149
@ SDL_WINDOWEVENT_MINIMIZED
Definition: SDL_video.h:159
@ SDL_WINDOWEVENT_MAXIMIZED
Definition: SDL_video.h:160
@ SDL_WINDOWEVENT_EXPOSED
Definition: SDL_video.h:151
void _HandleWindowResized(BMessage *msg)
Definition: SDL_BApp.h:349
void _HandleBasicWindowEvent(BMessage *msg, int32 sdlEventType)
Definition: SDL_BApp.h:207
void _HandleMouseFocus(BMessage *msg)
Definition: SDL_BApp.h:295
void _HandleKeyboardFocus(BMessage *msg)
Definition: SDL_BApp.h:314
void _HandleWindowMoved(BMessage *msg)
Definition: SDL_BApp.h:333
void _HandleMouseWheel(BMessage *msg)
Definition: SDL_BApp.h:252
void _HandleMouseMove(BMessage *msg)
Definition: SDL_BApp.h:219
void _HandleKey(BMessage *msg)
Definition: SDL_BApp.h:267
void _HandleMouseButton(BMessage *msg)
Definition: SDL_BApp.h:237

References _HandleBasicWindowEvent(), _HandleKey(), _HandleKeyboardFocus(), _HandleMouseButton(), _HandleMouseFocus(), _HandleMouseMove(), _HandleMouseWheel(), _HandleWindowMoved(), _HandleWindowResized(), BAPP_HIDE, BAPP_KEY, BAPP_KEYBOARD_FOCUS, BAPP_MAXIMIZE, BAPP_MINIMIZE, BAPP_MOUSE_BUTTON, BAPP_MOUSE_FOCUS, BAPP_MOUSE_MOVED, BAPP_MOUSE_WHEEL, BAPP_REPAINT, BAPP_SCREEN_CHANGED, BAPP_SHOW, BAPP_WINDOW_CLOSE_REQUESTED, BAPP_WINDOW_MOVED, BAPP_WINDOW_RESIZED, SDL_WINDOWEVENT_CLOSE, SDL_WINDOWEVENT_EXPOSED, SDL_WINDOWEVENT_HIDDEN, SDL_WINDOWEVENT_MAXIMIZED, SDL_WINDOWEVENT_MINIMIZED, and SDL_WINDOWEVENT_SHOWN.

Field Documentation

◆ _window_map

std::vector<SDL_Window*> SDL_BApp::_window_map
private

The documentation for this class was generated from the following file: