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

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.

References _current_context, and NULL.

83  :
84  BApplication(signature) {
85 #if SDL_VIDEO_OPENGL
87 #endif
88  }
#define NULL
Definition: begin_code.h:164
BGLView * _current_context
Definition: SDL_BApp.h:395

◆ ~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.

References _window_map.

Referenced by GetID().

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

◆ _GetWinID()

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

Definition at line 365 of file SDL_BApp.h.

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

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

◆ _HandleBasicWindowEvent()

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

Definition at line 207 of file SDL_BApp.h.

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

Referenced by MessageReceived().

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  }
bool _GetWinID(BMessage *msg, int32 *winID)
Definition: SDL_BApp.h:365
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
SDL_Window * GetSDLWindow(int32 winID)
Definition: SDL_BApp.h:191
The type used to identify a window.
Definition: SDL_sysvideo.h:73

◆ _HandleKey()

void SDL_BApp::_HandleKey ( BMessage *  msg)
inlineprivate

Definition at line 267 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().

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 && BE_GetKeyState(scancode) == SDL_PRESSED) {
278  return;
279  }
280  BE_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);
290  SDL_SendKeyboardText(text);
291  }
292  }
293  }
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
struct xkb_state * state
void BE_SetKeyState(int32 bkey, int8 state)
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
Definition: SDL_keyboard.c:679
#define SDL_memcpy
int SDL_SendKeyboardText(const char *text)
Definition: SDL_keyboard.c:789
#define SDL_zero(x)
Definition: SDL_stdinc.h:416
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 314 of file SDL_BApp.h.

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

Referenced by MessageReceived().

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  }
bool _GetWinID(BMessage *msg, int32 *winID)
Definition: SDL_BApp.h:365
void SDL_SetKeyboardFocus(SDL_Window *window)
Definition: SDL_keyboard.c:630
#define SDL_GetKeyboardFocus
SDL_Window * GetSDLWindow(int32 winID)
Definition: SDL_BApp.h:191
#define NULL
Definition: begin_code.h:164
The type used to identify a window.
Definition: SDL_sysvideo.h:73

◆ _HandleMouseButton()

void SDL_BApp::_HandleMouseButton ( BMessage *  msg)
inlineprivate

Definition at line 237 of file SDL_BApp.h.

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

Referenced by MessageReceived().

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);
249  SDL_SendMouseButton(win, 0, state, button);
250  }
bool _GetWinID(BMessage *msg, int32 *winID)
Definition: SDL_BApp.h:365
SDL_Texture * button
struct xkb_state * state
SDL_Window * GetSDLWindow(int32 winID)
Definition: SDL_BApp.h:191
The type used to identify a window.
Definition: SDL_sysvideo.h:73
int SDL_SendMouseButton(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button)
Definition: SDL_mouse.c:506

◆ _HandleMouseFocus()

void SDL_BApp::_HandleMouseFocus ( BMessage *  msg)
inlineprivate

Definition at line 295 of file SDL_BApp.h.

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

Referenced by MessageReceived().

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) {
307  SDL_SetMouseFocus(win);
308  } else if(SDL_GetMouseFocus() == win) {
309  /* Only lose all focus if this window was the current focus */
311  }
312  }
bool _GetWinID(BMessage *msg, int32 *winID)
Definition: SDL_BApp.h:365
void SDL_SetMouseFocus(SDL_Window *window)
Definition: SDL_mouse.c:151
SDL_Window * GetSDLWindow(int32 winID)
Definition: SDL_BApp.h:191
#define NULL
Definition: begin_code.h:164
#define SDL_GetMouseFocus
The type used to identify a window.
Definition: SDL_sysvideo.h:73

◆ _HandleMouseMove()

void SDL_BApp::_HandleMouseMove ( BMessage *  msg)
inlineprivate

Definition at line 219 of file SDL_BApp.h.

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

Referenced by MessageReceived().

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  }
bool _GetWinID(BMessage *msg, int32 *winID)
Definition: SDL_BApp.h:365
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
int SDL_SendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
Definition: SDL_mouse.c:237
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
int BE_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect *rects, int numrects)
SDL_Window * GetSDLWindow(int32 winID)
Definition: SDL_BApp.h:191
#define NULL
Definition: begin_code.h:164
The type used to identify a window.
Definition: SDL_sysvideo.h:73

◆ _HandleMouseWheel()

void SDL_BApp::_HandleMouseWheel ( BMessage *  msg)
inlineprivate

Definition at line 252 of file SDL_BApp.h.

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

Referenced by MessageReceived().

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  }
bool _GetWinID(BMessage *msg, int32 *winID)
Definition: SDL_BApp.h:365
SDL_Window * GetSDLWindow(int32 winID)
Definition: SDL_BApp.h:191
int SDL_SendMouseWheel(SDL_Window *window, SDL_MouseID mouseID, float x, float y, SDL_MouseWheelDirection direction)
Definition: SDL_mouse.c:512
The type used to identify a window.
Definition: SDL_sysvideo.h:73

◆ _HandleWindowMoved()

void SDL_BApp::_HandleWindowMoved ( BMessage *  msg)
inlineprivate

Definition at line 333 of file SDL_BApp.h.

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

Referenced by MessageReceived().

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);
346  SDL_SendWindowEvent(win, SDL_WINDOWEVENT_MOVED, xPos, yPos);
347  }
bool _GetWinID(BMessage *msg, int32 *winID)
Definition: SDL_BApp.h:365
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
SDL_Window * GetSDLWindow(int32 winID)
Definition: SDL_BApp.h:191
The type used to identify a window.
Definition: SDL_sysvideo.h:73

◆ _HandleWindowResized()

void SDL_BApp::_HandleWindowResized ( BMessage *  msg)
inlineprivate

Definition at line 349 of file SDL_BApp.h.

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

Referenced by MessageReceived().

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  }
bool _GetWinID(BMessage *msg, int32 *winID)
Definition: SDL_BApp.h:365
GLfloat GLfloat GLfloat GLfloat h
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
GLubyte GLubyte GLubyte GLubyte w
SDL_Window * GetSDLWindow(int32 winID)
Definition: SDL_BApp.h:191
The type used to identify a window.
Definition: SDL_sysvideo.h:73

◆ _PopBackWindow()

void SDL_BApp::_PopBackWindow ( )
inlineprivate

Definition at line 382 of file SDL_BApp.h.

References _window_map.

382  {
383  _window_map.pop_back();
384  }
std::vector< SDL_Window * > _window_map
Definition: SDL_BApp.h:392

◆ _PushBackWindow()

void SDL_BApp::_PushBackWindow ( SDL_Window win)
inlineprivate

Definition at line 386 of file SDL_BApp.h.

References _window_map.

Referenced by GetID().

386  {
387  _window_map.push_back(win);
388  }
std::vector< SDL_Window * > _window_map
Definition: SDL_BApp.h:392

◆ _SetSDLWindow()

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

Definition at line 373 of file SDL_BApp.h.

References _window_map.

Referenced by GetID().

373  {
374  _window_map[winID] = win;
375  }
std::vector< SDL_Window * > _window_map
Definition: SDL_BApp.h:392

◆ ClearID()

void SDL_BApp::ClearID ( SDL_BWin bwin)

Referenced by GetID().

◆ GetID()

int32 SDL_BApp::GetID ( SDL_Window win)
inline

Definition at line 167 of file SDL_BApp.h.

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

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  }
int32 _GetNumWindowSlots()
Definition: SDL_BApp.h:377
void _SetSDLWindow(SDL_Window *win, int32 winID)
Definition: SDL_BApp.h:373
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:191
#define NULL
Definition: begin_code.h:164
void _PushBackWindow(SDL_Window *win)
Definition: SDL_BApp.h:386

◆ GetSDLWindow()

SDL_Window* SDL_BApp::GetSDLWindow ( int32  winID)
inline

Definition at line 191 of file SDL_BApp.h.

References _window_map.

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

191  {
192  return _window_map[winID];
193  }
std::vector< SDL_Window * > _window_map
Definition: SDL_BApp.h:392

◆ MessageReceived()

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

Definition at line 97 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.

97  {
98  /* Sort out SDL-related messages */
99  switch ( message->what ) {
100  case BAPP_MOUSE_MOVED:
102  break;
103 
104  case BAPP_MOUSE_BUTTON:
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 
140  case BAPP_KEYBOARD_FOCUS:
142  break;
143 
146  break;
147 
148  case BAPP_WINDOW_MOVED:
150  break;
151 
152  case BAPP_WINDOW_RESIZED:
154  break;
155 
156  case BAPP_SCREEN_CHANGED:
157  /* TODO: Handle screen resize or workspace change */
158  break;
159 
160  default:
161  BApplication::MessageReceived(message);
162  break;
163  }
164  }
void _HandleMouseButton(BMessage *msg)
Definition: SDL_BApp.h:237
GLuint GLsizei const GLchar * message
void _HandleWindowMoved(BMessage *msg)
Definition: SDL_BApp.h:333
void _HandleKeyboardFocus(BMessage *msg)
Definition: SDL_BApp.h:314
void _HandleMouseFocus(BMessage *msg)
Definition: SDL_BApp.h:295
void _HandleMouseMove(BMessage *msg)
Definition: SDL_BApp.h:219
void _HandleKey(BMessage *msg)
Definition: SDL_BApp.h:267
void _HandleBasicWindowEvent(BMessage *msg, int32 sdlEventType)
Definition: SDL_BApp.h:207
void _HandleWindowResized(BMessage *msg)
Definition: SDL_BApp.h:349
void _HandleMouseWheel(BMessage *msg)
Definition: SDL_BApp.h:252

◆ SetCurrentContext()

void SDL_BApp::SetCurrentContext ( BGLView *  newContext)
inline

Definition at line 196 of file SDL_BApp.h.

References _current_context.

196  {
197  if(_current_context)
198  _current_context->UnlockGL();
199  _current_context = newContext;
200  if (_current_context)
201  _current_context->LockGL();
202  }
BGLView * _current_context
Definition: SDL_BApp.h:395

Field Documentation

◆ _current_context

BGLView* SDL_BApp::_current_context
private

Definition at line 395 of file SDL_BApp.h.

Referenced by SDL_BApp(), and SetCurrentContext().

◆ _window_map

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

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