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 82 of file SDL_BApp.h.

Constructor & Destructor Documentation

◆ SDL_BApp()

SDL_BApp::SDL_BApp ( const char *  signature)
inline

Definition at line 84 of file SDL_BApp.h.

84  :
85  BApplication(signature) {
86 #if SDL_VIDEO_OPENGL
88 #endif
89  }
const char * signature
#define NULL
Definition: begin_code.h:163
BGLView * _current_context
Definition: SDL_BApp.h:416

References _current_context, and NULL.

◆ ~SDL_BApp()

virtual SDL_BApp::~SDL_BApp ( )
inlinevirtual

Definition at line 92 of file SDL_BApp.h.

92  {
93  }

Member Function Documentation

◆ _GetNumWindowSlots()

int32 SDL_BApp::_GetNumWindowSlots ( )
inlineprivate

Definition at line 398 of file SDL_BApp.h.

398  {
399  return _window_map.size();
400  }
std::vector< SDL_Window * > _window_map
Definition: SDL_BApp.h:413

References _window_map.

Referenced by GetID().

◆ _GetWinID()

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

Definition at line 386 of file SDL_BApp.h.

386  {
387  return msg->FindInt32("window-id", winID) == B_OK;
388  }

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

◆ _HandleBasicWindowEvent()

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

Definition at line 212 of file SDL_BApp.h.

212  {
213  SDL_Window *win;
214  int32 winID;
215  if(
216  !_GetWinID(msg, &winID)
217  ) {
218  return;
219  }
220  win = GetSDLWindow(winID);
221  SDL_SendWindowEvent(win, sdlEventType, 0, 0);
222  }
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
SDL_Window * GetSDLWindow(int32 winID)
Definition: SDL_BApp.h:196
bool _GetWinID(BMessage *msg, int32 *winID)
Definition: SDL_BApp.h:386
The type used to identify a window.
Definition: SDL_sysvideo.h:75

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

Referenced by MessageReceived().

◆ _HandleKey()

void SDL_BApp::_HandleKey ( BMessage *  msg)
inlineprivate

Definition at line 288 of file SDL_BApp.h.

288  {
289  int32 scancode, state; /* scancode, pressed/released */
290  if(
291  msg->FindInt32("key-state", &state) != B_OK ||
292  msg->FindInt32("key-scancode", &scancode) != B_OK
293  ) {
294  return;
295  }
296 
297  /* Make sure this isn't a repeated event (key pressed and held) */
298  if(state == SDL_PRESSED && HAIKU_GetKeyState(scancode) == SDL_PRESSED) {
299  return;
300  }
301  HAIKU_SetKeyState(scancode, state);
303 
305  const int8 *keyUtf8;
306  ssize_t count;
307  if (msg->FindData("key-utf8", B_INT8_TYPE, (const void**)&keyUtf8, &count) == B_OK) {
309  SDL_zeroa(text);
310  SDL_memcpy(text, keyUtf8, count);
312  }
313  }
314  }
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:101
#define SDL_TEXTINPUTEVENT_TEXT_SIZE
Definition: SDL_events.h:244
#define SDL_QUERY
Definition: SDL_events.h:792
#define SDL_PRESSED
Definition: SDL_events.h:50
int SDL_SendKeyboardText(const char *text)
Definition: SDL_keyboard.c:848
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
Definition: SDL_keyboard.c:806
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
#define SDL_zeroa(x)
Definition: SDL_stdinc.h:428
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_zeroa, state, and text.

Referenced by MessageReceived().

◆ _HandleKeyboardFocus()

void SDL_BApp::_HandleKeyboardFocus ( BMessage *  msg)
inlineprivate

Definition at line 335 of file SDL_BApp.h.

335  {
336  SDL_Window *win;
337  int32 winID;
338  bool bSetFocus; /* If false, lose focus */
339  if(
340  !_GetWinID(msg, &winID) ||
341  msg->FindBool("focusGained", &bSetFocus) != B_OK
342  ) {
343  return;
344  }
345  win = GetSDLWindow(winID);
346  if(bSetFocus) {
348  } else if(SDL_GetKeyboardFocus() == win) {
349  /* Only lose all focus if this window was the current focus */
351  }
352  }
#define SDL_GetKeyboardFocus
void SDL_SetKeyboardFocus(SDL_Window *window)
Definition: SDL_keyboard.c:634

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

Referenced by MessageReceived().

◆ _HandleMouseButton()

void SDL_BApp::_HandleMouseButton ( BMessage *  msg)
inlineprivate

Definition at line 258 of file SDL_BApp.h.

258  {
259  SDL_Window *win;
260  int32 winID;
261  int32 button, state; /* left/middle/right, pressed/released */
262  if(
263  !_GetWinID(msg, &winID) ||
264  msg->FindInt32("button-id", &button) != B_OK ||
265  msg->FindInt32("button-state", &state) != B_OK
266  ) {
267  return;
268  }
269  win = GetSDLWindow(winID);
270  SDL_SendMouseButton(win, 0, state, button);
271  }
int SDL_SendMouseButton(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button)
Definition: SDL_mouse.c:599
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 316 of file SDL_BApp.h.

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

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

Referenced by MessageReceived().

◆ _HandleMouseMove()

void SDL_BApp::_HandleMouseMove ( BMessage *  msg)
inlineprivate

Definition at line 224 of file SDL_BApp.h.

224  {
225  SDL_Window *win;
226  int32 winID;
227  int32 x = 0, y = 0;
228  if(
229  !_GetWinID(msg, &winID) ||
230  msg->FindInt32("x", &x) != B_OK || /* x movement */
231  msg->FindInt32("y", &y) != B_OK /* y movement */
232  ) {
233  return;
234  }
235  win = GetSDLWindow(winID);
236 
237  // Simple relative mode support for mouse.
238  if (SDL_GetMouse()->relative_mode) {
239  int winWidth, winHeight, winPosX, winPosY;
240  SDL_GetWindowSize(win, &winWidth, &winHeight);
241  SDL_GetWindowPosition(win, &winPosX, &winPosY);
242  int dx = x - (winWidth / 2);
243  int dy = y - (winHeight / 2);
244  SDL_SendMouseMotion(win, 0, SDL_GetMouse()->relative_mode, dx, dy);
245  set_mouse_position((winPosX + winWidth / 2), (winPosY + winHeight / 2));
246  if (!be_app->IsCursorHidden())
247  be_app->HideCursor();
248  } else {
249  SDL_SendMouseMotion(win, 0, 0, x, y);
250  if (SDL_ShowCursor(-1) && be_app->IsCursorHidden())
251  be_app->ShowCursor();
252  }
253 
254  /* Tell the application that the mouse passed over, redraw needed */
256  }
int HAIKU_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect *rects, int numrects)
#define SDL_GetWindowSize
#define SDL_ShowCursor
#define SDL_GetWindowPosition
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:175
int SDL_SendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
Definition: SDL_mouse.c:298
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, SDL_GetMouse(), SDL_GetWindowPosition, SDL_GetWindowSize, SDL_SendMouseMotion(), and SDL_ShowCursor.

Referenced by MessageReceived().

◆ _HandleMouseWheel()

void SDL_BApp::_HandleMouseWheel ( BMessage *  msg)
inlineprivate

Definition at line 273 of file SDL_BApp.h.

273  {
274  SDL_Window *win;
275  int32 winID;
276  int32 xTicks, yTicks;
277  if(
278  !_GetWinID(msg, &winID) ||
279  msg->FindInt32("xticks", &xTicks) != B_OK ||
280  msg->FindInt32("yticks", &yTicks) != B_OK
281  ) {
282  return;
283  }
284  win = GetSDLWindow(winID);
285  SDL_SendMouseWheel(win, 0, xTicks, -yTicks, SDL_MOUSEWHEEL_NORMAL);
286  }
int SDL_SendMouseWheel(SDL_Window *window, SDL_MouseID mouseID, float x, float y, SDL_MouseWheelDirection direction)
Definition: SDL_mouse.c:605
@ 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 354 of file SDL_BApp.h.

354  {
355  SDL_Window *win;
356  int32 winID;
357  int32 xPos, yPos;
358  /* Get the window id and new x/y position of the window */
359  if(
360  !_GetWinID(msg, &winID) ||
361  msg->FindInt32("window-x", &xPos) != B_OK ||
362  msg->FindInt32("window-y", &yPos) != B_OK
363  ) {
364  return;
365  }
366  win = GetSDLWindow(winID);
367  SDL_SendWindowEvent(win, SDL_WINDOWEVENT_MOVED, xPos, yPos);
368  }
@ 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 370 of file SDL_BApp.h.

370  {
371  SDL_Window *win;
372  int32 winID;
373  int32 w, h;
374  /* Get the window id ]and new x/y position of the window */
375  if(
376  !_GetWinID(msg, &winID) ||
377  msg->FindInt32("window-w", &w) != B_OK ||
378  msg->FindInt32("window-h", &h) != B_OK
379  ) {
380  return;
381  }
382  win = GetSDLWindow(winID);
384  }
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 403 of file SDL_BApp.h.

403  {
404  _window_map.pop_back();
405  }

References _window_map.

◆ _PushBackWindow()

void SDL_BApp::_PushBackWindow ( SDL_Window win)
inlineprivate

Definition at line 407 of file SDL_BApp.h.

407  {
408  _window_map.push_back(win);
409  }

References _window_map.

Referenced by GetID().

◆ _SetSDLWindow()

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

Definition at line 394 of file SDL_BApp.h.

394  {
395  _window_map[winID] = win;
396  }

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 172 of file SDL_BApp.h.

172  {
173  int32 i;
174  for(i = 0; i < _GetNumWindowSlots(); ++i) {
175  if( GetSDLWindow(i) == NULL ) {
176  _SetSDLWindow(win, i);
177  return i;
178  }
179  }
180 
181  /* Expand the vector if all slots are full */
182  if( i == _GetNumWindowSlots() ) {
183  _PushBackWindow(win);
184  return i;
185  }
186 
187  /* TODO: error handling */
188  return 0;
189  }
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:398
void _SetSDLWindow(SDL_Window *win, int32 winID)
Definition: SDL_BApp.h:394
void _PushBackWindow(SDL_Window *win)
Definition: SDL_BApp.h:407

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 98 of file SDL_BApp.h.

98  {
99  /* Sort out SDL-related messages */
100  switch ( message->what ) {
101  case BAPP_MOUSE_MOVED:
103  break;
104 
105  case BAPP_MOUSE_BUTTON:
107  break;
108 
109  case BAPP_MOUSE_WHEEL:
111  break;
112 
113  case BAPP_KEY:
115  break;
116 
117  case BAPP_REPAINT:
119  break;
120 
121  case BAPP_MAXIMIZE:
123  break;
124 
125  case BAPP_MINIMIZE:
127  break;
128 
129  case BAPP_SHOW:
131  break;
132 
133  case BAPP_HIDE:
135  break;
136 
137  case BAPP_MOUSE_FOCUS:
139  break;
140 
141  case BAPP_KEYBOARD_FOCUS:
143  break;
144 
147  break;
148 
149  case BAPP_WINDOW_MOVED:
151  break;
152 
153  case BAPP_WINDOW_RESIZED:
155  break;
156 
157  case B_LOCALE_CHANGED:
159  break;
160 
161  case BAPP_SCREEN_CHANGED:
162  /* TODO: Handle screen resize or workspace change */
163  break;
164 
165  default:
166  BApplication::MessageReceived(message);
167  break;
168  }
169  }
@ BAPP_MAXIMIZE
Definition: SDL_BApp.h:66
@ BAPP_SCREEN_CHANGED
Definition: SDL_BApp.h:76
@ BAPP_MOUSE_FOCUS
Definition: SDL_BApp.h:71
@ BAPP_WINDOW_MOVED
Definition: SDL_BApp.h:74
@ BAPP_WINDOW_CLOSE_REQUESTED
Definition: SDL_BApp.h:73
@ BAPP_KEY
Definition: SDL_BApp.h:63
@ BAPP_MOUSE_BUTTON
Definition: SDL_BApp.h:61
@ BAPP_REPAINT
Definition: SDL_BApp.h:64
@ BAPP_HIDE
Definition: SDL_BApp.h:70
@ BAPP_KEYBOARD_FOCUS
Definition: SDL_BApp.h:72
@ BAPP_MOUSE_MOVED
Definition: SDL_BApp.h:60
@ BAPP_SHOW
Definition: SDL_BApp.h:69
@ BAPP_MINIMIZE
Definition: SDL_BApp.h:67
@ BAPP_WINDOW_RESIZED
Definition: SDL_BApp.h:75
@ BAPP_MOUSE_WHEEL
Definition: SDL_BApp.h:62
int SDL_SendLocaleChangedEvent(void)
Definition: SDL_events.c:1072
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:370
void _HandleBasicWindowEvent(BMessage *msg, int32 sdlEventType)
Definition: SDL_BApp.h:212
void _HandleMouseFocus(BMessage *msg)
Definition: SDL_BApp.h:316
void _HandleKeyboardFocus(BMessage *msg)
Definition: SDL_BApp.h:335
void _HandleWindowMoved(BMessage *msg)
Definition: SDL_BApp.h:354
void _HandleMouseWheel(BMessage *msg)
Definition: SDL_BApp.h:273
void _HandleMouseMove(BMessage *msg)
Definition: SDL_BApp.h:224
void _HandleKey(BMessage *msg)
Definition: SDL_BApp.h:288
void _HandleMouseButton(BMessage *msg)
Definition: SDL_BApp.h:258

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_SendLocaleChangedEvent(), SDL_WINDOWEVENT_CLOSE, SDL_WINDOWEVENT_EXPOSED, SDL_WINDOWEVENT_HIDDEN, SDL_WINDOWEVENT_MAXIMIZED, SDL_WINDOWEVENT_MINIMIZED, and SDL_WINDOWEVENT_SHOWN.

◆ SetCurrentContext()

void SDL_BApp::SetCurrentContext ( BGLView *  newContext)
inline

Definition at line 201 of file SDL_BApp.h.

201  {
202  if(_current_context)
203  _current_context->UnlockGL();
204  _current_context = newContext;
205  if (_current_context)
206  _current_context->LockGL();
207  }

References _current_context.

Field Documentation

◆ _current_context

BGLView* SDL_BApp::_current_context
private

Definition at line 416 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: