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)
 
void SetCurrentContext (BGLView *newContext)
 

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
 
display_mode * _saved_mode
 
BGLView * _current_context
 

Detailed Description

Definition at line 80 of file SDL_BApp.h.

Constructor & Destructor Documentation

SDL_BApp::SDL_BApp ( const char *  signature)
inline

Definition at line 82 of file SDL_BApp.h.

References _current_context, and NULL.

82  :
83  BApplication(signature) {
85  }
#define NULL
Definition: begin_code.h:143
BGLView * _current_context
Definition: SDL_BApp.h:377
virtual SDL_BApp::~SDL_BApp ( )
inlinevirtual

Definition at line 88 of file SDL_BApp.h.

88  {
89  }

Member Function Documentation

int32 SDL_BApp::_GetNumWindowSlots ( )
inlineprivate

Definition at line 359 of file SDL_BApp.h.

References _window_map.

Referenced by GetID().

359  {
360  return _window_map.size();
361  }
std::vector< SDL_Window * > _window_map
Definition: SDL_BApp.h:374
bool SDL_BApp::_GetWinID ( BMessage *  msg,
int32 *  winID 
)
inlineprivate

Definition at line 347 of file SDL_BApp.h.

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

347  {
348  return msg->FindInt32("window-id", winID) == B_OK;
349  }
void SDL_BApp::_HandleBasicWindowEvent ( BMessage *  msg,
int32  sdlEventType 
)
inlineprivate

Definition at line 200 of file SDL_BApp.h.

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

Referenced by MessageReceived().

200  {
201  SDL_Window *win;
202  int32 winID;
203  if(
204  !_GetWinID(msg, &winID)
205  ) {
206  return;
207  }
208  win = GetSDLWindow(winID);
209  SDL_SendWindowEvent(win, sdlEventType, 0, 0);
210  }
bool _GetWinID(BMessage *msg, int32 *winID)
Definition: SDL_BApp.h:347
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
SDL_Window * GetSDLWindow(int32 winID)
Definition: SDL_BApp.h:188
The type used to identify a window.
Definition: SDL_sysvideo.h:71
void SDL_BApp::_HandleKey ( BMessage *  msg)
inlineprivate

Definition at line 260 of file SDL_BApp.h.

References BE_GetKeyState(), BE_GetScancodeFromBeKey(), BE_SetKeyState(), SDL_PRESSED, SDL_SendKeyboardKey(), and state.

Referenced by MessageReceived().

260  {
261  int32 scancode, state; /* scancode, pressed/released */
262  if(
263  msg->FindInt32("key-state", &state) != B_OK ||
264  msg->FindInt32("key-scancode", &scancode) != B_OK
265  ) {
266  return;
267  }
268 
269  /* Make sure this isn't a repeated event (key pressed and held) */
270  if(state == SDL_PRESSED && BE_GetKeyState(scancode) == SDL_PRESSED) {
271  return;
272  }
273  BE_SetKeyState(scancode, state);
275  }
struct xkb_state * state
void BE_SetKeyState(int32 bkey, int8 state)
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
Definition: SDL_keyboard.c:661
SDL_Scancode BE_GetScancodeFromBeKey(int32 bkey)
int8 BE_GetKeyState(int32 bkey)
#define SDL_PRESSED
Definition: SDL_events.h:50
void SDL_BApp::_HandleKeyboardFocus ( BMessage *  msg)
inlineprivate

Definition at line 296 of file SDL_BApp.h.

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

Referenced by MessageReceived().

296  {
297  SDL_Window *win;
298  int32 winID;
299  bool bSetFocus; /* If false, lose focus */
300  if(
301  !_GetWinID(msg, &winID) ||
302  msg->FindBool("focusGained", &bSetFocus) != B_OK
303  ) {
304  return;
305  }
306  win = GetSDLWindow(winID);
307  if(bSetFocus) {
309  } else if(SDL_GetKeyboardFocus() == win) {
310  /* Only lose all focus if this window was the current focus */
312  }
313  }
bool _GetWinID(BMessage *msg, int32 *winID)
Definition: SDL_BApp.h:347
void SDL_SetKeyboardFocus(SDL_Window *window)
Definition: SDL_keyboard.c:612
#define SDL_GetKeyboardFocus
SDL_Window * GetSDLWindow(int32 winID)
Definition: SDL_BApp.h:188
#define NULL
Definition: begin_code.h:143
The type used to identify a window.
Definition: SDL_sysvideo.h:71
void SDL_BApp::_HandleMouseButton ( BMessage *  msg)
inlineprivate

Definition at line 230 of file SDL_BApp.h.

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

Referenced by MessageReceived().

230  {
231  SDL_Window *win;
232  int32 winID;
233  int32 button, state; /* left/middle/right, pressed/released */
234  if(
235  !_GetWinID(msg, &winID) ||
236  msg->FindInt32("button-id", &button) != B_OK ||
237  msg->FindInt32("button-state", &state) != B_OK
238  ) {
239  return;
240  }
241  win = GetSDLWindow(winID);
242  SDL_SendMouseButton(win, 0, state, button);
243  }
bool _GetWinID(BMessage *msg, int32 *winID)
Definition: SDL_BApp.h:347
SDL_Texture * button
struct xkb_state * state
SDL_Window * GetSDLWindow(int32 winID)
Definition: SDL_BApp.h:188
The type used to identify a window.
Definition: SDL_sysvideo.h:71
int SDL_SendMouseButton(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button)
Definition: SDL_mouse.c:326
void SDL_BApp::_HandleMouseFocus ( BMessage *  msg)
inlineprivate

Definition at line 277 of file SDL_BApp.h.

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

Referenced by MessageReceived().

277  {
278  SDL_Window *win;
279  int32 winID;
280  bool bSetFocus; /* If false, lose focus */
281  if(
282  !_GetWinID(msg, &winID) ||
283  msg->FindBool("focusGained", &bSetFocus) != B_OK
284  ) {
285  return;
286  }
287  win = GetSDLWindow(winID);
288  if(bSetFocus) {
289  SDL_SetMouseFocus(win);
290  } else if(SDL_GetMouseFocus() == win) {
291  /* Only lose all focus if this window was the current focus */
293  }
294  }
bool _GetWinID(BMessage *msg, int32 *winID)
Definition: SDL_BApp.h:347
void SDL_SetMouseFocus(SDL_Window *window)
Definition: SDL_mouse.c:103
SDL_Window * GetSDLWindow(int32 winID)
Definition: SDL_BApp.h:188
#define NULL
Definition: begin_code.h:143
#define SDL_GetMouseFocus
The type used to identify a window.
Definition: SDL_sysvideo.h:71
void SDL_BApp::_HandleMouseMove ( BMessage *  msg)
inlineprivate

Definition at line 212 of file SDL_BApp.h.

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

Referenced by MessageReceived().

212  {
213  SDL_Window *win;
214  int32 winID;
215  int32 x = 0, y = 0;
216  if(
217  !_GetWinID(msg, &winID) ||
218  msg->FindInt32("x", &x) != B_OK || /* x movement */
219  msg->FindInt32("y", &y) != B_OK /* y movement */
220  ) {
221  return;
222  }
223  win = GetSDLWindow(winID);
224  SDL_SendMouseMotion(win, 0, 0, x, y);
225 
226  /* Tell the application that the mouse passed over, redraw needed */
228  }
bool _GetWinID(BMessage *msg, int32 *winID)
Definition: SDL_BApp.h:347
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1567
int SDL_SendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
Definition: SDL_mouse.c:188
int BE_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect *rects, int numrects)
SDL_Window * GetSDLWindow(int32 winID)
Definition: SDL_BApp.h:188
#define NULL
Definition: begin_code.h:143
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1567
The type used to identify a window.
Definition: SDL_sysvideo.h:71
void SDL_BApp::_HandleMouseWheel ( BMessage *  msg)
inlineprivate

Definition at line 245 of file SDL_BApp.h.

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

Referenced by MessageReceived().

245  {
246  SDL_Window *win;
247  int32 winID;
248  int32 xTicks, yTicks;
249  if(
250  !_GetWinID(msg, &winID) ||
251  msg->FindInt32("xticks", &xTicks) != B_OK ||
252  msg->FindInt32("yticks", &yTicks) != B_OK
253  ) {
254  return;
255  }
256  win = GetSDLWindow(winID);
257  SDL_SendMouseWheel(win, 0, xTicks, yTicks, SDL_MOUSEWHEEL_NORMAL);
258  }
bool _GetWinID(BMessage *msg, int32 *winID)
Definition: SDL_BApp.h:347
SDL_Window * GetSDLWindow(int32 winID)
Definition: SDL_BApp.h:188
The type used to identify a window.
Definition: SDL_sysvideo.h:71
int SDL_SendMouseWheel(SDL_Window *window, SDL_MouseID mouseID, int x, int y, SDL_MouseWheelDirection direction)
Definition: SDL_mouse.c:406
void SDL_BApp::_HandleWindowMoved ( BMessage *  msg)
inlineprivate

Definition at line 315 of file SDL_BApp.h.

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

Referenced by MessageReceived().

315  {
316  SDL_Window *win;
317  int32 winID;
318  int32 xPos, yPos;
319  /* Get the window id and new x/y position of the window */
320  if(
321  !_GetWinID(msg, &winID) ||
322  msg->FindInt32("window-x", &xPos) != B_OK ||
323  msg->FindInt32("window-y", &yPos) != B_OK
324  ) {
325  return;
326  }
327  win = GetSDLWindow(winID);
328  SDL_SendWindowEvent(win, SDL_WINDOWEVENT_MOVED, xPos, yPos);
329  }
bool _GetWinID(BMessage *msg, int32 *winID)
Definition: SDL_BApp.h:347
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
SDL_Window * GetSDLWindow(int32 winID)
Definition: SDL_BApp.h:188
The type used to identify a window.
Definition: SDL_sysvideo.h:71
void SDL_BApp::_HandleWindowResized ( BMessage *  msg)
inlineprivate

Definition at line 331 of file SDL_BApp.h.

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

Referenced by MessageReceived().

331  {
332  SDL_Window *win;
333  int32 winID;
334  int32 w, h;
335  /* Get the window id ]and new x/y position of the window */
336  if(
337  !_GetWinID(msg, &winID) ||
338  msg->FindInt32("window-w", &w) != B_OK ||
339  msg->FindInt32("window-h", &h) != B_OK
340  ) {
341  return;
342  }
343  win = GetSDLWindow(winID);
345  }
bool _GetWinID(BMessage *msg, int32 *winID)
Definition: SDL_BApp.h:347
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
SDL_Window * GetSDLWindow(int32 winID)
Definition: SDL_BApp.h:188
The type used to identify a window.
Definition: SDL_sysvideo.h:71
GLubyte GLubyte GLubyte GLubyte w
GLfloat GLfloat GLfloat GLfloat h
void SDL_BApp::_PopBackWindow ( )
inlineprivate

Definition at line 364 of file SDL_BApp.h.

References _window_map.

364  {
365  _window_map.pop_back();
366  }
std::vector< SDL_Window * > _window_map
Definition: SDL_BApp.h:374
void SDL_BApp::_PushBackWindow ( SDL_Window win)
inlineprivate

Definition at line 368 of file SDL_BApp.h.

References _window_map.

Referenced by GetID().

368  {
369  _window_map.push_back(win);
370  }
std::vector< SDL_Window * > _window_map
Definition: SDL_BApp.h:374
void SDL_BApp::_SetSDLWindow ( SDL_Window win,
int32  winID 
)
inlineprivate

Definition at line 355 of file SDL_BApp.h.

References _window_map.

Referenced by GetID().

355  {
356  _window_map[winID] = win;
357  }
std::vector< SDL_Window * > _window_map
Definition: SDL_BApp.h:374
void SDL_BApp::ClearID ( SDL_BWin bwin)

Referenced by GetID().

int32 SDL_BApp::GetID ( SDL_Window win)
inline

Definition at line 164 of file SDL_BApp.h.

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

164  {
165  int32 i;
166  for(i = 0; i < _GetNumWindowSlots(); ++i) {
167  if( GetSDLWindow(i) == NULL ) {
168  _SetSDLWindow(win, i);
169  return i;
170  }
171  }
172 
173  /* Expand the vector if all slots are full */
174  if( i == _GetNumWindowSlots() ) {
175  _PushBackWindow(win);
176  return i;
177  }
178 
179  /* TODO: error handling */
180  return 0;
181  }
int32 _GetNumWindowSlots()
Definition: SDL_BApp.h:359
void _SetSDLWindow(SDL_Window *win, int32 winID)
Definition: SDL_BApp.h:355
SDL_Window * GetSDLWindow(int32 winID)
Definition: SDL_BApp.h:188
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:42
#define NULL
Definition: begin_code.h:143
void _PushBackWindow(SDL_Window *win)
Definition: SDL_BApp.h:368
SDL_Window* SDL_BApp::GetSDLWindow ( int32  winID)
inline

Definition at line 188 of file SDL_BApp.h.

References _window_map.

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

188  {
189  return _window_map[winID];
190  }
std::vector< SDL_Window * > _window_map
Definition: SDL_BApp.h:374
virtual void SDL_BApp::MessageReceived ( BMessage *  message)
inlinevirtual

Definition at line 94 of file SDL_BApp.h.

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.

94  {
95  /* Sort out SDL-related messages */
96  switch ( message->what ) {
97  case BAPP_MOUSE_MOVED:
99  break;
100 
101  case BAPP_MOUSE_BUTTON:
103  break;
104 
105  case BAPP_MOUSE_WHEEL:
107  break;
108 
109  case BAPP_KEY:
111  break;
112 
113  case BAPP_REPAINT:
115  break;
116 
117  case BAPP_MAXIMIZE:
119  break;
120 
121  case BAPP_MINIMIZE:
123  break;
124 
125  case BAPP_SHOW:
127  break;
128 
129  case BAPP_HIDE:
131  break;
132 
133  case BAPP_MOUSE_FOCUS:
135  break;
136 
137  case BAPP_KEYBOARD_FOCUS:
139  break;
140 
143  break;
144 
145  case BAPP_WINDOW_MOVED:
147  break;
148 
149  case BAPP_WINDOW_RESIZED:
151  break;
152 
153  case BAPP_SCREEN_CHANGED:
154  /* TODO: Handle screen resize or workspace change */
155  break;
156 
157  default:
158  BApplication::MessageReceived(message);
159  break;
160  }
161  }
void _HandleMouseButton(BMessage *msg)
Definition: SDL_BApp.h:230
GLuint GLsizei const GLchar * message
void _HandleWindowMoved(BMessage *msg)
Definition: SDL_BApp.h:315
void _HandleKeyboardFocus(BMessage *msg)
Definition: SDL_BApp.h:296
void _HandleMouseFocus(BMessage *msg)
Definition: SDL_BApp.h:277
void _HandleMouseMove(BMessage *msg)
Definition: SDL_BApp.h:212
void _HandleKey(BMessage *msg)
Definition: SDL_BApp.h:260
void _HandleBasicWindowEvent(BMessage *msg, int32 sdlEventType)
Definition: SDL_BApp.h:200
void _HandleWindowResized(BMessage *msg)
Definition: SDL_BApp.h:331
void _HandleMouseWheel(BMessage *msg)
Definition: SDL_BApp.h:245
void SDL_BApp::SetCurrentContext ( BGLView *  newContext)
inline

Definition at line 192 of file SDL_BApp.h.

References _current_context.

192  {
193  if(_current_context)
194  _current_context->UnlockGL();
195  _current_context = newContext;
196  _current_context->LockGL();
197  }
BGLView * _current_context
Definition: SDL_BApp.h:377

Field Documentation

BGLView* SDL_BApp::_current_context
private

Definition at line 377 of file SDL_BApp.h.

Referenced by SDL_BApp(), and SetCurrentContext().

display_mode* SDL_BApp::_saved_mode
private

Definition at line 376 of file SDL_BApp.h.

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

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