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::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:389

§ ~SDL_BApp()

virtual SDL_BApp::~SDL_BApp ( )
inlinevirtual

Definition at line 88 of file SDL_BApp.h.

88  {
89  }

Member Function Documentation

§ _GetNumWindowSlots()

int32 SDL_BApp::_GetNumWindowSlots ( )
inlineprivate

Definition at line 371 of file SDL_BApp.h.

References _window_map.

Referenced by GetID().

371  {
372  return _window_map.size();
373  }
std::vector< SDL_Window * > _window_map
Definition: SDL_BApp.h:386

§ _GetWinID()

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

Definition at line 359 of file SDL_BApp.h.

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

359  {
360  return msg->FindInt32("window-id", winID) == B_OK;
361  }

§ _HandleBasicWindowEvent()

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

Definition at line 201 of file SDL_BApp.h.

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

Referenced by MessageReceived().

201  {
202  SDL_Window *win;
203  int32 winID;
204  if(
205  !_GetWinID(msg, &winID)
206  ) {
207  return;
208  }
209  win = GetSDLWindow(winID);
210  SDL_SendWindowEvent(win, sdlEventType, 0, 0);
211  }
bool _GetWinID(BMessage *msg, int32 *winID)
Definition: SDL_BApp.h:359
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

§ _HandleKey()

void SDL_BApp::_HandleKey ( BMessage *  msg)
inlineprivate

Definition at line 261 of file SDL_BApp.h.

References BE_GetKeyState(), BE_GetScancodeFromBeKey(), BE_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().

261  {
262  int32 scancode, state; /* scancode, pressed/released */
263  if(
264  msg->FindInt32("key-state", &state) != B_OK ||
265  msg->FindInt32("key-scancode", &scancode) != B_OK
266  ) {
267  return;
268  }
269 
270  /* Make sure this isn't a repeated event (key pressed and held) */
271  if(state == SDL_PRESSED && BE_GetKeyState(scancode) == SDL_PRESSED) {
272  return;
273  }
274  BE_SetKeyState(scancode, state);
276 
278  const int8 *keyUtf8;
279  ssize_t count;
280  if (msg->FindData("key-utf8", B_INT8_TYPE, (const void**)&keyUtf8, &count) == B_OK) {
282  SDL_zero(text);
283  SDL_memcpy(text, keyUtf8, count);
284  SDL_SendKeyboardText(text);
285  }
286  }
287  }
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1564
struct xkb_state * state
void BE_SetKeyState(int32 bkey, int8 state)
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
Definition: SDL_keyboard.c:661
#define SDL_memcpy
int SDL_SendKeyboardText(const char *text)
Definition: SDL_keyboard.c:774
#define SDL_zero(x)
Definition: SDL_stdinc.h:359
SDL_Scancode BE_GetScancodeFromBeKey(int32 bkey)
int8 BE_GetKeyState(int32 bkey)
static char text[MAX_TEXT_LENGTH]
Definition: testime.c:47
#define SDL_EventState
#define SDL_TEXTINPUTEVENT_TEXT_SIZE
Definition: SDL_events.h:217
#define SDL_PRESSED
Definition: SDL_events.h:50
#define SDL_QUERY
Definition: SDL_events.h:719

§ _HandleKeyboardFocus()

void SDL_BApp::_HandleKeyboardFocus ( BMessage *  msg)
inlineprivate

Definition at line 308 of file SDL_BApp.h.

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

Referenced by MessageReceived().

308  {
309  SDL_Window *win;
310  int32 winID;
311  bool bSetFocus; /* If false, lose focus */
312  if(
313  !_GetWinID(msg, &winID) ||
314  msg->FindBool("focusGained", &bSetFocus) != B_OK
315  ) {
316  return;
317  }
318  win = GetSDLWindow(winID);
319  if(bSetFocus) {
321  } else if(SDL_GetKeyboardFocus() == win) {
322  /* Only lose all focus if this window was the current focus */
324  }
325  }
bool _GetWinID(BMessage *msg, int32 *winID)
Definition: SDL_BApp.h:359
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

§ _HandleMouseButton()

void SDL_BApp::_HandleMouseButton ( BMessage *  msg)
inlineprivate

Definition at line 231 of file SDL_BApp.h.

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

Referenced by MessageReceived().

231  {
232  SDL_Window *win;
233  int32 winID;
234  int32 button, state; /* left/middle/right, pressed/released */
235  if(
236  !_GetWinID(msg, &winID) ||
237  msg->FindInt32("button-id", &button) != B_OK ||
238  msg->FindInt32("button-state", &state) != B_OK
239  ) {
240  return;
241  }
242  win = GetSDLWindow(winID);
243  SDL_SendMouseButton(win, 0, state, button);
244  }
bool _GetWinID(BMessage *msg, int32 *winID)
Definition: SDL_BApp.h:359
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:414

§ _HandleMouseFocus()

void SDL_BApp::_HandleMouseFocus ( BMessage *  msg)
inlineprivate

Definition at line 289 of file SDL_BApp.h.

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

Referenced by MessageReceived().

289  {
290  SDL_Window *win;
291  int32 winID;
292  bool bSetFocus; /* If false, lose focus */
293  if(
294  !_GetWinID(msg, &winID) ||
295  msg->FindBool("focusGained", &bSetFocus) != B_OK
296  ) {
297  return;
298  }
299  win = GetSDLWindow(winID);
300  if(bSetFocus) {
301  SDL_SetMouseFocus(win);
302  } else if(SDL_GetMouseFocus() == win) {
303  /* Only lose all focus if this window was the current focus */
305  }
306  }
bool _GetWinID(BMessage *msg, int32 *winID)
Definition: SDL_BApp.h:359
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

§ _HandleMouseMove()

void SDL_BApp::_HandleMouseMove ( BMessage *  msg)
inlineprivate

Definition at line 213 of file SDL_BApp.h.

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

Referenced by MessageReceived().

213  {
214  SDL_Window *win;
215  int32 winID;
216  int32 x = 0, y = 0;
217  if(
218  !_GetWinID(msg, &winID) ||
219  msg->FindInt32("x", &x) != B_OK || /* x movement */
220  msg->FindInt32("y", &y) != B_OK /* y movement */
221  ) {
222  return;
223  }
224  win = GetSDLWindow(winID);
225  SDL_SendMouseMotion(win, 0, 0, x, y);
226 
227  /* Tell the application that the mouse passed over, redraw needed */
229  }
bool _GetWinID(BMessage *msg, int32 *winID)
Definition: SDL_BApp.h:359
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1567
GLint GLint GLint GLint GLint GLint y
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
The type used to identify a window.
Definition: SDL_sysvideo.h:71

§ _HandleMouseWheel()

void SDL_BApp::_HandleMouseWheel ( BMessage *  msg)
inlineprivate

Definition at line 246 of file SDL_BApp.h.

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

Referenced by MessageReceived().

246  {
247  SDL_Window *win;
248  int32 winID;
249  int32 xTicks, yTicks;
250  if(
251  !_GetWinID(msg, &winID) ||
252  msg->FindInt32("xticks", &xTicks) != B_OK ||
253  msg->FindInt32("yticks", &yTicks) != B_OK
254  ) {
255  return;
256  }
257  win = GetSDLWindow(winID);
258  SDL_SendMouseWheel(win, 0, xTicks, yTicks, SDL_MOUSEWHEEL_NORMAL);
259  }
bool _GetWinID(BMessage *msg, int32 *winID)
Definition: SDL_BApp.h:359
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:420

§ _HandleWindowMoved()

void SDL_BApp::_HandleWindowMoved ( BMessage *  msg)
inlineprivate

Definition at line 327 of file SDL_BApp.h.

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

Referenced by MessageReceived().

327  {
328  SDL_Window *win;
329  int32 winID;
330  int32 xPos, yPos;
331  /* Get the window id and new x/y position of the window */
332  if(
333  !_GetWinID(msg, &winID) ||
334  msg->FindInt32("window-x", &xPos) != B_OK ||
335  msg->FindInt32("window-y", &yPos) != B_OK
336  ) {
337  return;
338  }
339  win = GetSDLWindow(winID);
340  SDL_SendWindowEvent(win, SDL_WINDOWEVENT_MOVED, xPos, yPos);
341  }
bool _GetWinID(BMessage *msg, int32 *winID)
Definition: SDL_BApp.h:359
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

§ _HandleWindowResized()

void SDL_BApp::_HandleWindowResized ( BMessage *  msg)
inlineprivate

Definition at line 343 of file SDL_BApp.h.

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

Referenced by MessageReceived().

343  {
344  SDL_Window *win;
345  int32 winID;
346  int32 w, h;
347  /* Get the window id ]and new x/y position of the window */
348  if(
349  !_GetWinID(msg, &winID) ||
350  msg->FindInt32("window-w", &w) != B_OK ||
351  msg->FindInt32("window-h", &h) != B_OK
352  ) {
353  return;
354  }
355  win = GetSDLWindow(winID);
357  }
bool _GetWinID(BMessage *msg, int32 *winID)
Definition: SDL_BApp.h:359
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

§ _PopBackWindow()

void SDL_BApp::_PopBackWindow ( )
inlineprivate

Definition at line 376 of file SDL_BApp.h.

References _window_map.

376  {
377  _window_map.pop_back();
378  }
std::vector< SDL_Window * > _window_map
Definition: SDL_BApp.h:386

§ _PushBackWindow()

void SDL_BApp::_PushBackWindow ( SDL_Window win)
inlineprivate

Definition at line 380 of file SDL_BApp.h.

References _window_map.

Referenced by GetID().

380  {
381  _window_map.push_back(win);
382  }
std::vector< SDL_Window * > _window_map
Definition: SDL_BApp.h:386

§ _SetSDLWindow()

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

Definition at line 367 of file SDL_BApp.h.

References _window_map.

Referenced by GetID().

367  {
368  _window_map[winID] = win;
369  }
std::vector< SDL_Window * > _window_map
Definition: SDL_BApp.h:386

§ ClearID()

void SDL_BApp::ClearID ( SDL_BWin bwin)

Referenced by GetID().

§ 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:371
void _SetSDLWindow(SDL_Window *win, int32 winID)
Definition: SDL_BApp.h:367
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
SDL_Window * GetSDLWindow(int32 winID)
Definition: SDL_BApp.h:188
#define NULL
Definition: begin_code.h:143
void _PushBackWindow(SDL_Window *win)
Definition: SDL_BApp.h:380

§ GetSDLWindow()

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:386

§ MessageReceived()

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:231
GLuint GLsizei const GLchar * message
void _HandleWindowMoved(BMessage *msg)
Definition: SDL_BApp.h:327
void _HandleKeyboardFocus(BMessage *msg)
Definition: SDL_BApp.h:308
void _HandleMouseFocus(BMessage *msg)
Definition: SDL_BApp.h:289
void _HandleMouseMove(BMessage *msg)
Definition: SDL_BApp.h:213
void _HandleKey(BMessage *msg)
Definition: SDL_BApp.h:261
void _HandleBasicWindowEvent(BMessage *msg, int32 sdlEventType)
Definition: SDL_BApp.h:201
void _HandleWindowResized(BMessage *msg)
Definition: SDL_BApp.h:343
void _HandleMouseWheel(BMessage *msg)
Definition: SDL_BApp.h:246

§ SetCurrentContext()

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  if (_current_context)
197  _current_context->LockGL();
198  }
BGLView * _current_context
Definition: SDL_BApp.h:389

Field Documentation

§ _current_context

BGLView* SDL_BApp::_current_context
private

Definition at line 389 of file SDL_BApp.h.

Referenced by SDL_BApp(), and SetCurrentContext().

§ _saved_mode

display_mode* SDL_BApp::_saved_mode
private

Definition at line 388 of file SDL_BApp.h.

§ _window_map

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

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