sdlevent.cpp

Go to the documentation of this file.
00001 /*
00002   libwt - Vassilis Virvilis Toolkit - a widget library
00003   Copyright (C) 2006 Vassilis Virvilis <vasvir2@fastmail.fm>
00004  
00005   This library is free software; you can redistribute it and/or
00006   modify it under the terms of the GNU Lesser General Public
00007   License as published by the Free Software Foundation; either
00008   version 2.1 of the License, or (at your option) any later version.
00009   
00010   This library is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013   Lesser General Public License for more details.
00014   
00015   You should have received a copy of the GNU Lesser General Public
00016   License along with this library; if not, write to the
00017   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018   Boston, MA  02111-1307, SA.
00019 */
00020 
00021 #include <SDL/SDL_events.h>
00022 
00023 #include "fastevents.h"
00024 #include "sdlevent.h"
00025 #include <wt/trace.h>
00026 
00027 namespace Wt {
00028 
00029 const SDLEvent::Member SDLEvent::None = SDL_NOEVENT;
00030 const SDLEvent::Member SDLEvent::Active = SDL_ACTIVEEVENT;
00031 const SDLEvent::Member SDLEvent::KeyDown = SDL_KEYDOWN;
00032 const SDLEvent::Member SDLEvent::KeyUp = SDL_KEYUP;
00033 const SDLEvent::Member SDLEvent::MouseMotion = SDL_MOUSEMOTION;
00034 const SDLEvent::Member SDLEvent::MouseButtonDown = SDL_MOUSEBUTTONDOWN;
00035 const SDLEvent::Member SDLEvent::MouseButtonUp = SDL_MOUSEBUTTONUP;
00036 const SDLEvent::Member SDLEvent::JoyAxisMotion = SDL_JOYAXISMOTION;
00037 const SDLEvent::Member SDLEvent::JoyBallMotion = SDL_JOYBALLMOTION;
00038 const SDLEvent::Member SDLEvent::JoyHatMotion = SDL_JOYHATMOTION;
00039 const SDLEvent::Member SDLEvent::JoyButtonDown = SDL_JOYBUTTONDOWN;
00040 const SDLEvent::Member SDLEvent::JoyButtonUp = SDL_JOYBUTTONUP;
00041 const SDLEvent::Member SDLEvent::Quit = SDL_QUIT;
00042 const SDLEvent::Member SDLEvent::SysWM = SDL_SYSWMEVENT;
00043 const SDLEvent::Member SDLEvent::VideoResize = SDL_VIDEORESIZE;
00044 const SDLEvent::Member SDLEvent::VideoExpose = SDL_VIDEOEXPOSE;
00045 // our events
00046 const SDLEvent::Member SDLEvent::User = SDL_USEREVENT + 3;
00047 const SDLEvent::Member SDLEvent::Time = SDL_USEREVENT;
00048 const SDLEvent::Member SDLEvent::Audio;
00049 const SDLEvent::Member SDLEvent::Net;
00050 /// we can't exceed this
00051 const SDLEvent::Member SDLEvent::NumEvents = SDL_NUMEVENTS;
00052 
00053 std::vector<SDLEvent::SDLEventHandler> SDLEvent::handlers;
00054 
00055 SDLEvent::SDLEvent()
00056         : Singleton<SDLEvent>(this) {
00057     handlers.resize(NumEvents, 0);
00058     // initialize fast events
00059     FE_Init();
00060 }
00061 
00062 SDLEvent::~SDLEvent() {
00063     FE_Quit();
00064 }
00065 
00066 void SDLEvent::push(SDL_Event* event) {
00067     FE_PushEvent(event);
00068 }
00069 
00070 void SDLEvent::handle(const SDL_Event *event) {
00071     //trace("sdlevent", "Incoming SDL_Event type: %d\n", event->type);
00072     assert(event->type <= User);
00073     if (handlers[event->type]) {
00074         handlers[event->type](event);
00075     } else {
00076         Warn("Unhandled event %d\n", event->type);
00077     }
00078 }
00079 
00080 // process all events so far
00081 void SDLEvent::wait() {
00082     SDL_Event event;
00083     FE_WaitEvent(&event);
00084     handle(&event);
00085 }
00086 
00087 SDLEvent::SDLEventHandler& SDLEvent::operator[](int event_type) {
00088     return handlers[event_type];
00089 }
00090 const SDLEvent::SDLEventHandler& SDLEvent::operator[](int event_type) const {
00091     return handlers[event_type];
00092 }
00093 
00094 } // namespace

Generated Fri Jul 28 19:23:00 2006.
Copyright © 1998-2003 by the respective authors.

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.