SDL  2.0
SDL_BApp Class Reference

#include <SDL_BApp.h>

+ 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 ( const char *  signature)
inline

Definition at line 83 of file SDL_BApp.h.

References _current_context, and NULL.

:
BApplication(signature) {
#if SDL_VIDEO_OPENGL
#endif
}
virtual SDL_BApp::~SDL_BApp ( )
inlinevirtual

Definition at line 91 of file SDL_BApp.h.

{
}

Member Function Documentation

int32 SDL_BApp::_GetNumWindowSlots ( )
inlineprivate

Definition at line 377 of file SDL_BApp.h.

References _window_map.

Referenced by GetID().

{
return _window_map.size();
}
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().

{
return msg->FindInt32("window-id", winID) == B_OK;
}
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().

{
SDL_Window *win;
int32 winID;
if(
!_GetWinID(msg, &winID)
) {
return;
}
win = GetSDLWindow(winID);
SDL_SendWindowEvent(win, sdlEventType, 0, 0);
}
void SDL_BApp::_HandleKey ( BMessage *  msg)
inlineprivate

Definition at line 267 of file SDL_BApp.h.

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().

{
int32 scancode, state; /* scancode, pressed/released */
if(
msg->FindInt32("key-state", &state) != B_OK ||
msg->FindInt32("key-scancode", &scancode) != B_OK
) {
return;
}
/* Make sure this isn't a repeated event (key pressed and held) */
if(state == SDL_PRESSED && HAIKU_GetKeyState(scancode) == SDL_PRESSED) {
return;
}
HAIKU_SetKeyState(scancode, state);
const int8 *keyUtf8;
ssize_t count;
if (msg->FindData("key-utf8", B_INT8_TYPE, (const void**)&keyUtf8, &count) == B_OK) {
SDL_zero(text);
SDL_memcpy(text, keyUtf8, count);
}
}
}
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().

{
SDL_Window *win;
int32 winID;
bool bSetFocus; /* If false, lose focus */
if(
!_GetWinID(msg, &winID) ||
msg->FindBool("focusGained", &bSetFocus) != B_OK
) {
return;
}
win = GetSDLWindow(winID);
if(bSetFocus) {
} else if(SDL_GetKeyboardFocus() == win) {
/* Only lose all focus if this window was the current focus */
}
}
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().

{
SDL_Window *win;
int32 winID;
int32 button, state; /* left/middle/right, pressed/released */
if(
!_GetWinID(msg, &winID) ||
msg->FindInt32("button-id", &button) != B_OK ||
msg->FindInt32("button-state", &state) != B_OK
) {
return;
}
win = GetSDLWindow(winID);
SDL_SendMouseButton(win, 0, state, button);
}
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().

{
SDL_Window *win;
int32 winID;
bool bSetFocus; /* If false, lose focus */
if(
!_GetWinID(msg, &winID) ||
msg->FindBool("focusGained", &bSetFocus) != B_OK
) {
return;
}
win = GetSDLWindow(winID);
if(bSetFocus) {
} else if(SDL_GetMouseFocus() == win) {
/* Only lose all focus if this window was the current focus */
}
}
void SDL_BApp::_HandleMouseMove ( BMessage *  msg)
inlineprivate

Definition at line 219 of file SDL_BApp.h.

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

Referenced by MessageReceived().

{
SDL_Window *win;
int32 winID;
int32 x = 0, y = 0;
if(
!_GetWinID(msg, &winID) ||
msg->FindInt32("x", &x) != B_OK || /* x movement */
msg->FindInt32("y", &y) != B_OK /* y movement */
) {
return;
}
win = GetSDLWindow(winID);
SDL_SendMouseMotion(win, 0, 0, x, y);
/* Tell the application that the mouse passed over, redraw needed */
}
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().

{
SDL_Window *win;
int32 winID;
int32 xTicks, yTicks;
if(
!_GetWinID(msg, &winID) ||
msg->FindInt32("xticks", &xTicks) != B_OK ||
msg->FindInt32("yticks", &yTicks) != B_OK
) {
return;
}
win = GetSDLWindow(winID);
SDL_SendMouseWheel(win, 0, xTicks, yTicks, SDL_MOUSEWHEEL_NORMAL);
}
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().

{
SDL_Window *win;
int32 winID;
int32 xPos, yPos;
/* Get the window id and new x/y position of the window */
if(
!_GetWinID(msg, &winID) ||
msg->FindInt32("window-x", &xPos) != B_OK ||
msg->FindInt32("window-y", &yPos) != B_OK
) {
return;
}
win = GetSDLWindow(winID);
}
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().

{
SDL_Window *win;
int32 winID;
int32 w, h;
/* Get the window id ]and new x/y position of the window */
if(
!_GetWinID(msg, &winID) ||
msg->FindInt32("window-w", &w) != B_OK ||
msg->FindInt32("window-h", &h) != B_OK
) {
return;
}
win = GetSDLWindow(winID);
}
void SDL_BApp::_PopBackWindow ( )
inlineprivate

Definition at line 382 of file SDL_BApp.h.

References _window_map.

{
_window_map.pop_back();
}
void SDL_BApp::_PushBackWindow ( SDL_Window win)
inlineprivate

Definition at line 386 of file SDL_BApp.h.

References _window_map.

Referenced by GetID().

{
_window_map.push_back(win);
}
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().

{
_window_map[winID] = win;
}
void SDL_BApp::ClearID ( SDL_BWin bwin)
int32 SDL_BApp::GetID ( SDL_Window win)
inline

Definition at line 167 of file SDL_BApp.h.

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

{
int32 i;
for(i = 0; i < _GetNumWindowSlots(); ++i) {
if( GetSDLWindow(i) == NULL ) {
_SetSDLWindow(win, i);
return i;
}
}
/* Expand the vector if all slots are full */
if( i == _GetNumWindowSlots() ) {
return i;
}
/* TODO: error handling */
return 0;
}
SDL_Window* SDL_BApp::GetSDLWindow ( int32  winID)
inline
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.

void SDL_BApp::SetCurrentContext ( BGLView *  newContext)
inline

Definition at line 196 of file SDL_BApp.h.

References _current_context.

{
_current_context->UnlockGL();
_current_context = newContext;
_current_context->LockGL();
}

Field Documentation

BGLView* SDL_BApp::_current_context
private

Definition at line 395 of file SDL_BApp.h.

Referenced by SDL_BApp(), and SetCurrentContext().

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

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