#include <sdlinput.h>
Inheritance diagram for Wt::SDLInput:
Public Member Functions | |
void | setKeyboardGrabber (Widget *w) |
void | releaseKeyboardGrab () |
Widget * | keyboardGrabber () const |
void | setMouseGrabber (Widget *w) |
Widget * | mouseGrabber () const |
void | releaseMouseGrab () |
Static Public Member Functions | |
static DERIVED * | instance () |
template<class GRANDCHILD> | |
static DERIVED * | instance () |
instantiates the pointer compatible child of DERIVED aka grandchild | |
static DERIVED * | existingInstance () |
static void | init () |
static void | quit () |
Protected Member Functions | |
SDLInput () | |
Static Protected Member Functions | |
static void | handleKeyEvent (const SDL_Event *event) |
static void | handleMouseEvent (const SDL_Event *event) |
static void | handleActiveEvent (const SDL_Event *event) |
static void | handleQuitEvent (const SDL_Event *event) |
static void | handleVideoResizeEvent (const SDL_Event *event) |
static void | handleUnusualEvent (const SDL_Event *event) |
static DERIVED * | load () |
try to load the instance | |
Static Protected Attributes | |
static DERIVED * | instance_ = 0 |
Private Attributes | |
Widget * | keyboard_grabber |
Widget * | mouse_grabber |
Static Private Attributes | |
static EventInfo | previous_position_ |
static EventInfo | previous_button_ |
static const FlagMap | buttonMap |
static members | |
static const FlagMap | wheelMap |
static const FlagMap | keyMap |
Friends | |
class | Singleton< SDLInput > |
Classes | |
class | EventInfo |
converted event to wt semantics More... |
Definition at line 36 of file sdlinput.h.
Wt::SDLInput::SDLInput | ( | ) | [protected] |
Definition at line 131 of file sdlinput.cpp.
References Wt::SDLEvent::Active, handleActiveEvent(), handleKeyEvent(), handleMouseEvent(), handleQuitEvent(), handleUnusualEvent(), handleVideoResizeEvent(), Wt::Singleton< DERIVED >::instance(), Wt::SDLEvent::KeyDown, Wt::SDLEvent::KeyUp, Wt::SDLEvent::MouseButtonDown, Wt::SDLEvent::MouseButtonUp, Wt::SDLEvent::MouseMotion, Wt::SDLEvent::Quit, Wt::SDLEvent::SysWM, Wt::SDLEvent::VideoExpose, and Wt::SDLEvent::VideoResize.
00132 : Singleton<SDLInput>(this), 00133 keyboard_grabber(0), 00134 mouse_grabber(0) { 00135 SDLEvent& sdlevent = *SDLEvent::instance(); 00136 sdlevent[SDLEvent::Active] = &handleActiveEvent; 00137 sdlevent[SDLEvent::KeyDown] = &handleKeyEvent; 00138 sdlevent[SDLEvent::KeyUp] = &handleKeyEvent; 00139 sdlevent[SDLEvent::MouseMotion] = &handleMouseEvent; 00140 sdlevent[SDLEvent::MouseButtonDown] = &handleMouseEvent; 00141 sdlevent[SDLEvent::MouseButtonUp] = &handleMouseEvent; 00142 sdlevent[SDLEvent::Quit] = &handleQuitEvent; 00143 sdlevent[SDLEvent::VideoResize] = &handleVideoResizeEvent; 00144 sdlevent[SDLEvent::SysWM] = &handleUnusualEvent; 00145 sdlevent[SDLEvent::VideoExpose] = &handleUnusualEvent; 00146 }
Here is the call graph for this function:
static DERIVED* Wt::Singleton< DERIVED >::existingInstance | ( | ) | [inline, static, inherited] |
Definition at line 36 of file singleton.h.
Referenced by Wt::Application::exit(), Wt::Application::postEvent(), Wt::Application::sendEvent(), and Wt::Application::sendPostedEvents().
00036 { 00037 return instance_; 00038 }
void Wt::SDLInput::handleActiveEvent | ( | const SDL_Event * | event | ) | [static, protected] |
Definition at line 262 of file sdlinput.cpp.
References Wt::FocusEvent::ActiveWindow, Wt::Event::FocusIn, Wt::Event::FocusOut, Wt::RootWindow::instance(), Wt::Event::Leave, Wt::Application::postEvent(), previous_position_, trace, and Wt::SDLInput::EventInfo::widget.
Referenced by SDLInput().
00262 { 00263 if (event->active.state & SDL_APPMOUSEFOCUS && 00264 !event->active.gain) { 00265 trace("sdlactive", "Application mouse lost...\n"); 00266 // we are out of SDL window. We have to send Leave event 00267 if (previous_position_.widget) { 00268 Application::postEvent(previous_position_.widget, 00269 new Event(Event::Leave)); 00270 } 00271 previous_position_.widget = 0; 00272 } 00273 if (event->active.state & SDL_APPINPUTFOCUS) { 00274 trace("sdlactive", "Application Focus...\n"); 00275 Application::postEvent(RootWindow::instance()->focusWidget(), 00276 new FocusEvent((event->active.gain) ? 00277 Event::FocusIn : 00278 Event::FocusOut, 00279 FocusEvent::ActiveWindow)); 00280 } 00281 // if deiconify 00282 /// this doesn't look usefull 00283 if (event->active.state & SDL_APPACTIVE && event->active.gain) { 00284 trace("sdlactive", "Deiconify...\n"); 00285 //RootWindow::rootWindow()->update(); 00286 } 00287 }
Here is the call graph for this function:
void Wt::SDLInput::handleKeyEvent | ( | const SDL_Event * | event | ) | [static, protected] |
Definition at line 172 of file sdlinput.cpp.
References Wt::Widget::focusWidget(), Wt::Singleton< DERIVED >::instance(), Wt::RootWindow::instance(), Wt::Object::isDescendant(), Wt::Key_Backtab, Wt::Key_Tab, keyMap, Wt::Event::KeyPress, Wt::Event::KeyRelease, Wt::Application::postEvent(), Wt::ShiftButton, and Wt::FlagMap::state().
Referenced by SDLInput().
00172 { 00173 switch(event->type) { 00174 case SDL_KEYDOWN: 00175 case SDL_KEYUP: { 00176 const SDL_KeyboardEvent *ke = reinterpret_cast< 00177 const SDL_KeyboardEvent *>(event); 00178 int keymap_state = keyMap.state(ke->keysym.mod); 00179 int sym = ke->keysym.sym; 00180 if (ke->keysym.sym == SDLK_TAB) { 00181 sym = (keymap_state & ShiftButton) ? Key_Backtab : Key_Tab; 00182 } 00183 Widget *w = RootWindow::instance()->focusWidget(); 00184 Widget *kg = SDLInput::instance()->keyboardGrabber(); 00185 w = (!kg || w->isDescendant(kg)) ? w : kg; 00186 Application::postEvent(w, new KeyEvent((ke->type == SDL_KEYDOWN) ? 00187 Event::KeyPress : 00188 Event::KeyRelease, 00189 sym, keymap_state)); 00190 } 00191 break; 00192 default: 00193 assert(0); 00194 break; 00195 } 00196 return; 00197 }
Here is the call graph for this function:
void Wt::SDLInput::handleMouseEvent | ( | const SDL_Event * | event | ) | [static, protected] |
Definition at line 200 of file sdlinput.cpp.
References Wt::SDLInput::EventInfo::button, Wt::SDLInput::EventInfo::button_event_type, Wt::Event::Enter, Wt::Event::Leave, Wt::Widget::mapFromGlobal(), Wt::Event::MouseButtonDblClick, Wt::MouseButtonMask, Wt::Event::MouseMove, Wt::Widget::mouseTracking, Wt::SDLInput::EventInfo::point, Wt::Application::postEvent(), previous_button_, previous_position_, Wt::SDLInput::EventInfo::state, trace, Wt::SDLInput::EventInfo::wheel_delta, Wt::SDLInput::EventInfo::widget, Wt::Point::x(), and Wt::Point::y().
Referenced by SDLInput().
00200 { 00201 const EventInfo ei(event); 00202 00203 // let's skip this event if we can't find the originating 00204 // widget i.e. window resize 00205 if (!ei.widget) 00206 return; 00207 00208 // position in widget coordinates 00209 const Point& wp = ei.widget->mapFromGlobal(ei.point); 00210 00211 trace("sdlinput", "Position [%d, %d] button %d (%d) state %d wheel %d\n", 00212 ei.point.x(), ei.point.y(), ei.button, 00213 ei.button_event_type, ei.state, ei.wheel_delta); 00214 trace("sdlinput") << "Inside " << ei.widget << std::endl; 00215 trace("sdlinput", "Widget's corrds [%d, %d]\n", wp.x(), wp.y()); 00216 00217 switch(event->type) { 00218 case SDL_MOUSEMOTION: 00219 if ((ei.state & MouseButtonMask) || ei.widget->mouseTracking) { 00220 Application::postEvent(ei.widget, new MouseEvent(Event::MouseMove, 00221 wp, ei.point, ei.button, ei.state)); 00222 } 00223 00224 if (ei.widget != previous_position_.widget) { 00225 if (previous_position_.widget) { 00226 Application::postEvent(previous_position_.widget, 00227 new Event(Event::Leave)); 00228 } 00229 Application::postEvent(ei.widget, 00230 new Event(Event::Enter)); 00231 } 00232 previous_position_ = ei; 00233 break; 00234 case SDL_MOUSEBUTTONDOWN: 00235 if (ei.wheel_delta) { 00236 Application::postEvent(ei.widget, new WheelEvent(wp, 00237 ei.point, ei.wheel_delta, ei.button)); 00238 break; 00239 } 00240 // check for double click 00241 if (ei == previous_button_) { 00242 Application::postEvent(ei.widget, new MouseEvent( 00243 Event::MouseButtonDblClick, wp, 00244 ei.point, ei.button, ei.state)); 00245 break; 00246 } 00247 previous_button_ = ei; 00248 case SDL_MOUSEBUTTONUP: 00249 if (!ei.wheel_delta) { 00250 Application::postEvent(ei.widget, new MouseEvent( 00251 ei.button_event_type, wp, 00252 ei.point, ei.button, ei.state)); 00253 } 00254 break; 00255 default: 00256 assert(0); 00257 break; 00258 } 00259 return; 00260 }
Here is the call graph for this function:
void Wt::SDLInput::handleQuitEvent | ( | const SDL_Event * | event | ) | [static, protected] |
Definition at line 289 of file sdlinput.cpp.
References Wt::Application::exit().
Referenced by SDLInput().
00289 { 00290 Application::exit(); 00291 }
Here is the call graph for this function:
void Wt::SDLInput::handleUnusualEvent | ( | const SDL_Event * | event | ) | [static, protected] |
Definition at line 297 of file sdlinput.cpp.
References Warn.
Referenced by SDLInput().
00297 { 00298 Warn("Unusual SDL_Event type: %d\n", event->type); 00299 }
void Wt::SDLInput::handleVideoResizeEvent | ( | const SDL_Event * | event | ) | [static, protected] |
Definition at line 293 of file sdlinput.cpp.
References Wt::RootWindow::instance(), and Wt::RootWindow::resize().
Referenced by SDLInput().
00293 { 00294 RootWindow::instance()->resize(event->resize.w, event->resize.h); 00295 }
Here is the call graph for this function:
static void Wt::Singleton< DERIVED >::init | ( | ) | [inline, static, inherited] |
Reimplemented in Wt::Application.
Definition at line 49 of file singleton.h.
Referenced by Wt::Application::Application().
00049 { 00050 if (!instance()) { 00051 assert(0); 00052 } 00053 }
static DERIVED* Wt::Singleton< DERIVED >::instance | ( | ) | [inline, static, inherited] |
instantiates the pointer compatible child of DERIVED aka grandchild
it is handy in driver like situations
Definition at line 43 of file singleton.h.
static DERIVED* Wt::Singleton< DERIVED >::instance | ( | ) | [inline, static, inherited] |
Definition at line 32 of file singleton.h.
Referenced by Wt::Audio::Audio(), Wt::Sound::available(), Wt::SDLMixer::Chunk::channel(), Wt::NullAudio::Chunk::channel(), Wt::SDLSurface::defaultDepth(), Wt::SDLInput::EventInfo::EventInfo(), Wt::Dialog::exec(), Wt::Widget::grabKeyboard(), Wt::Widget::grabMouse(), Wt::Audio::handleAudioEvent(), handleKeyEvent(), Wt::Singleton< Wt::Audio >::init(), Wt::SDLTimer::init(), Wt::Sound::isAvailable(), Wt::Widget::keyboardGrabber(), Wt::Audio::load(), Wt::Widget::mouseGrabber(), Wt::SDLMixer::onChannelFinish(), Wt::Audio::onChannelFinish(), Wt::Sound::play(), Wt::Singleton< Wt::Audio >::quit(), Wt::Widget::releaseKeyboard(), Wt::Widget::releaseMouse(), SDLInput(), Wt::SDLMixer::setMusicVolume(), Wt::SDLMixer::Channel::setVolume(), and Wt::SDLMixer::Chunk::setVolume().
Widget * Wt::SDLInput::keyboardGrabber | ( | ) | const |
Definition at line 148 of file sdlinput.cpp.
References keyboard_grabber.
00148 { 00149 return keyboard_grabber; 00150 }
static DERIVED* Wt::Singleton< DERIVED >::load | ( | ) | [inline, static, protected, inherited] |
try to load the instance
if it fails return NULL if it succeeds must return the newly created object
Reimplemented in Wt::Audio, Wt::NullAudio, and Wt::SDLMixer.
Definition at line 86 of file singleton.h.
Widget * Wt::SDLInput::mouseGrabber | ( | ) | const |
Definition at line 160 of file sdlinput.cpp.
References mouse_grabber.
00160 { 00161 return mouse_grabber; 00162 }
static void Wt::Singleton< DERIVED >::quit | ( | ) | [inline, static, inherited] |
Reimplemented in Wt::Application.
Definition at line 55 of file singleton.h.
Referenced by Wt::Application::~Application().
00055 { 00056 delete instance(); 00057 }
void Wt::SDLInput::releaseKeyboardGrab | ( | ) |
Definition at line 156 of file sdlinput.cpp.
References setKeyboardGrabber().
00156 { 00157 setKeyboardGrabber(0); 00158 }
Here is the call graph for this function:
void Wt::SDLInput::releaseMouseGrab | ( | ) |
Definition at line 168 of file sdlinput.cpp.
References setMouseGrabber().
00168 { 00169 setMouseGrabber(0); 00170 }
Here is the call graph for this function:
void Wt::SDLInput::setKeyboardGrabber | ( | Widget * | w | ) |
Definition at line 152 of file sdlinput.cpp.
References keyboard_grabber.
Referenced by releaseKeyboardGrab().
00152 { 00153 keyboard_grabber = w; 00154 }
void Wt::SDLInput::setMouseGrabber | ( | Widget * | w | ) |
Definition at line 164 of file sdlinput.cpp.
References mouse_grabber.
Referenced by releaseMouseGrab().
00164 { 00165 mouse_grabber = w; 00166 }
Definition at line 38 of file sdlinput.h.
const FlagMap Wt::SDLInput::buttonMap [static, private] |
Initial value:
boost::assign::map_list_of (SDL_BUTTON_LEFT, LeftButton) (SDL_BUTTON_MIDDLE, MidButton) (SDL_BUTTON_RIGHT, RightButton)
Definition at line 85 of file sdlinput.h.
Referenced by Wt::SDLInput::EventInfo::EventInfo().
DERIVED * Wt::Singleton< DERIVED >::instance_ = 0 [static, protected, inherited] |
Definition at line 91 of file singleton.h.
Referenced by Wt::Singleton< Wt::Audio >::existingInstance(), Wt::Singleton< Wt::Audio >::instance(), Wt::Singleton< Wt::Audio >::load(), Wt::SDLDisplay::load(), Wt::Audio::load(), Wt::Singleton< Wt::Audio >::Singleton(), and Wt::Singleton< Wt::Audio >::~Singleton().
Widget* Wt::SDLInput::keyboard_grabber [private] |
Definition at line 59 of file sdlinput.h.
Referenced by keyboardGrabber(), and setKeyboardGrabber().
const FlagMap Wt::SDLInput::keyMap [static, private] |
Initial value:
boost::assign::map_list_of (KMOD_LSHIFT, ShiftButton) (KMOD_RSHIFT, ShiftButton) (KMOD_LCTRL, ControlButton) (KMOD_RCTRL, ControlButton) (KMOD_LALT, AltButton) (KMOD_RALT, AltButton) (KMOD_LMETA, MetaButton) (KMOD_RMETA, MetaButton) (KMOD_NUM, Keypad) (KMOD_CAPS, Keypad) (KMOD_MODE, Keypad)
Definition at line 87 of file sdlinput.h.
Referenced by Wt::SDLInput::EventInfo::EventInfo(), and handleKeyEvent().
Widget* Wt::SDLInput::mouse_grabber [private] |
SDLInput::EventInfo Wt::SDLInput::previous_button_ [static, private] |
SDLInput::EventInfo Wt::SDLInput::previous_position_ [static, private] |
Definition at line 81 of file sdlinput.h.
Referenced by handleActiveEvent(), and handleMouseEvent().
const FlagMap Wt::SDLInput::wheelMap [static, private] |
Initial value:
boost::assign::map_list_of (SDL_BUTTON_WHEELUP, 120) (SDL_BUTTON_WHEELDOWN, -120)
Definition at line 86 of file sdlinput.h.
Referenced by Wt::SDLInput::EventInfo::EventInfo().
This document is licensed under the terms of the GNU Free Documentation License and may be freely distributed under the conditions given by this license.