Back to index

extremetuxracer  0.5beta
widget.h
Go to the documentation of this file.
00001 /* 
00002  * PPRacer 
00003  * Copyright (C) 2004-2005 Volker Stroebel <volker@planetpenguin.de>
00004  * 
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  * 
00010  * This program 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
00013  * GNU General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018  */
00019  
00020 #ifndef _PP_WIDGET_H_
00021 #define _PP_WIDGET_H_
00022 
00023 #include "alg/signal.h"
00024 #include "alg/vec2d.h"
00025 
00026 #include "alignment.h"
00027 
00028 #include <SDL.h>
00029 
00030 namespace pp {
00031 
00032 class Widget {
00033        
00034 protected:
00035 
00036     pp::Vec2d m_position;
00037     pp::Vec2d m_size;
00038        
00040        bool m_clicked;
00041 
00043        bool m_focused;
00044 
00046        bool m_sensitive;
00047 
00049        bool m_visible;
00050 
00052        bool m_active;
00053 
00054        bool m_hasFocus;
00055 
00056        virtual void performClickAction();
00057               
00058 public:
00059        Widget();
00060        virtual ~Widget();
00061 
00062        void setSensitive(bool sensitive);
00063        bool getSensitive() { return m_sensitive; };
00064        void setVisible(bool visible);
00065        void setActive(bool active);
00066        void setPosition(pp::Vec2d pos){m_position = pos;};
00067 
00068        bool isInBox(const int x, const int y) const;
00069 
00070        void mouseDown(int button, int x, int y );
00071        void mouseUp(int button, int x, int y );
00072        void mouseMotion(int x, int y);
00073        virtual bool keyboardEvent(SDLKey key, SDLMod mod, bool release){return false;};
00074               
00075        void removeFocus();
00076        void setFocus(bool focus = true);
00077        bool hasFocus(){return m_hasFocus;};
00078 
00079        void simulateMouseClick();
00080 
00081        virtual void draw()  = 0;
00082 
00083        inline double getWidth() const {return m_size.x;};
00084        inline double getHeight() const {return m_size.y;};
00085 
00086        //signals
00087        pp::Signal0 signalClicked;
00088        
00090        pp::Alignment alignment;
00091 
00092 };
00093 
00094 } //namespace pp
00095 
00096 #endif // _PP_WIDGET_H_