Back to index

nux  3.0.0
AbstractButton.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Inalogic® Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License, as
00006  * published by the  Free Software Foundation; either version 2.1 or 3.0
00007  * of the License.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License along with this program. If not, see <http://www.gnu.org/licenses/>
00017  *
00018  * Authored by: Jay Taoko <jaytaoko@inalogic.com>
00019  *
00020  */
00021 
00022 #ifndef ABSTRACTBUTTON_H
00023 #define ABSTRACTBUTTON_H
00024 
00025 #include "View.h"
00026 #include "NuxCore/Property.h"
00027 
00028 namespace nux
00029 {
00030   class StaticText;
00031 
00032   enum ButtonVisualState
00033   {
00034     VISUAL_STATE_PRESSED = 0,
00035     VISUAL_STATE_NORMAL = 1,
00036     VISUAL_STATE_PRELIGHT = 2,
00037     VISUAL_STATE_DISABLED = 3
00038   };
00039 
00041 
00044   class AbstractButton : public View
00045   {
00046     NUX_DECLARE_OBJECT_TYPE(AbstractButton, View);
00047   public:
00048     AbstractButton(NUX_FILE_LINE_PROTO);
00049     virtual ~AbstractButton();
00050 
00051     sigc::signal<void, AbstractButton*> visual_state_change;
00052 
00054 
00059     ButtonVisualState GetVisualState();
00060 
00062 
00068     bool Active() const;
00069 
00071 
00074     virtual void Activate() = 0;
00075 
00077 
00080     virtual void Deactivate() = 0;
00081 
00083 
00088     virtual void SetActive(bool active);
00089 
00091 
00096     void SetLabelColor(const Color &color);
00097 
00099 
00104     Color GetLabelColor();
00105 
00107 
00112     ButtonVisualState GetVisualState() const;
00113 
00114     virtual void SetLabelFontSize(int point);
00115     int GetLabelFontSize() const;
00116 
00117   protected:
00119     bool active_;
00120 
00121     bool mouse_pressed_;
00122 
00124     ButtonVisualState visual_state_;
00125 
00126 
00127     // Common attribute for all the classes that inherit from AbstractButton.
00128     std::string label_;
00129     Color label_color_;
00130     StaticText *static_text_;
00131     int label_font_size_;
00132     bool same_size_as_content_;
00133     int pre_layout_width_;
00134     int pre_layout_height_;
00135 
00136     virtual void RecvMouseUp    (int x, int y, unsigned long button_flags, unsigned long key_flags);
00137     virtual void RecvMouseDown  (int x, int y, unsigned long button_flags, unsigned long key_flags);
00138     virtual void RecvMouseMove  (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
00139     virtual void RecvMouseEnter(int x, int y, unsigned long button_flags, unsigned long key_flags);
00140     virtual void RecvMouseLeave(int x, int y, unsigned long button_flags, unsigned long key_flags);
00141     virtual void RecvClick      (int x, int y, unsigned long button_flags, unsigned long key_flags) = 0;
00142   };
00143 }
00144 
00145 #endif // ABSTRACTBUTTON_H