sdlinput.h

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 #ifndef WT_SDLINPUT_H
00022 #define WT_SDLINPUT_H
00023 
00024 #include <wt/singleton.h>
00025 #include <wt/flagmap.h>
00026 #include <wt/point.h>
00027 #include <wt/datetime.h>
00028 
00029 union SDL_Event;
00030 
00031 namespace Wt {
00032 
00033 class Widget;
00034 
00035 /// useful for transforming SDL events to normal Event
00036 class SDLInput : public Singleton<SDLInput> {
00037     // The Singleton part
00038     friend class Singleton<SDLInput>;
00039 
00040 public:
00041     void setKeyboardGrabber(Widget *w);
00042     void releaseKeyboardGrab();
00043     Widget *keyboardGrabber() const;
00044     void setMouseGrabber(Widget *w);
00045     Widget *mouseGrabber() const;
00046     void releaseMouseGrab();
00047 
00048     // The handling part
00049 protected:
00050     SDLInput();
00051     static void handleKeyEvent(const SDL_Event *event);
00052     static void handleMouseEvent(const SDL_Event *event);
00053     static void handleActiveEvent(const SDL_Event *event);
00054     static void handleQuitEvent(const SDL_Event *event);
00055     static void handleVideoResizeEvent(const SDL_Event *event);
00056     static void handleUnusualEvent(const SDL_Event *event);
00057 
00058 private:
00059     Widget *keyboard_grabber;
00060     Widget *mouse_grabber;
00061 
00062     /// converted event to wt semantics
00063     class EventInfo {
00064     public:
00065         EventInfo();
00066         EventInfo(const SDL_Event *event);
00067         bool operator==(const EventInfo& other) const;
00068 
00069         int button;
00070         int state;
00071         int wheel_delta;
00072         int button_event_type;
00073         Point point;
00074         Widget *widget;
00075         Time time;
00076 
00077         static const int delta_proximity = 10;
00078         static const int delta_delay = 300; // in miliseconds
00079     };
00080 
00081     static EventInfo previous_position_;
00082     static EventInfo previous_button_;
00083 
00084     /// static const conversion tables
00085     static const FlagMap buttonMap;
00086     static const FlagMap wheelMap;
00087     static const FlagMap keyMap;
00088 };
00089 
00090 } // namespace
00091 
00092 #endif //WT_SDLINPUT_H

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.