Back to index

nux  3.0.0
Button.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 
00023 #ifndef BUTTON_H
00024 #define BUTTON_H
00025 #include "AbstractButton.h"
00026 
00027 namespace nux
00028 {
00029   class HLayout;
00030   class VLayout;
00031   class TextureArea;
00032   class StaticText;
00033 
00034   // Deprecated
00035   // Image position with regard to the text
00036   enum Position
00037   {
00038     NUX_POSITION_LEFT,    // image on left, text on the right
00039     NUX_POSITION_RIGHT,   // text on the left, image on right
00040     NUX_POSITION_TOP,     // image above text
00041     NUX_POSITION_BOTTOM   // image below text
00042   };
00043 
00044 
00046 
00050   class Button: public AbstractButton
00051   {
00052     NUX_DECLARE_OBJECT_TYPE(Button, View);
00053   public:
00054 
00055     enum LayoutType
00056     {
00057       HORIZONTAL,
00058       VERTICAL,
00059     };
00060 
00061     enum ItemOrder
00062     {
00063       IMAGE_FIRST,
00064       LABEL_FIRST,
00065     };
00066 
00067     enum Distribution
00068     {
00069       START_OF_LAYOUT,
00070       END_OF_LAYOUT,
00071       CENTER_OF_LAYOUT,
00072       SPREAD_OVER_LAYOUT,
00073     };
00074 
00075     Button(TextureArea *image, NUX_FILE_LINE_PROTO);
00076     Button(const std::string& button_label, NUX_FILE_LINE_PROTO);
00077     Button(const std::string& button_label, TextureArea *image, NUX_FILE_LINE_PROTO);
00078     Button(NUX_FILE_LINE_PROTO);
00079     virtual ~Button();
00080 
00082     sigc::signal<void, Button*> click;
00083 
00085 
00089     sigc::signal<void, Button*> state_change;
00090 
00092 
00098     void SetLabel(const std::string &button_label);
00099 
00101 
00106     std::string GetLabel() const;
00107 
00109 
00118     void SetImage(TextureArea *image);
00119 
00121 
00128     TextureArea* GetImage();
00129 
00131 
00140     void SetImageMinimumSize(int width, int height);
00141     
00143 
00152     void SetImageMaximumSize(int width, int height);
00153 
00155 
00164     void SetLayoutPadding(int top, int right, int bottom, int left);
00165 
00167 
00176     void SetButtonClipRegion(int top_clip, int right_clip, int bottom_clip, int left_clip);
00177 
00179 
00186     void SetDistribution(Distribution distribution);
00187 
00189 
00195     void SetItemOrder(ItemOrder item_order);
00196 
00198 
00205     void SetLayoutType(LayoutType layout_type);
00206 
00208 
00213     void SetSpaceBetweenItems(int space_between_items);
00214 
00216 
00219     void Activate();
00220 
00222 
00225     void Deactivate();
00226 
00227     virtual void SetLabelFontSize(int point);
00228 
00229   protected:
00230     LayoutType layout_type_;    
00231     ItemOrder item_order_;      
00232     Distribution distribution_; 
00233     int space_between_items_;   
00234     bool persistent_active_state_; 
00235 
00236     int layout_left_padding_;
00237     int layout_right_padding_;
00238     int layout_top_padding_;
00239     int layout_bottom_padding_;
00240 
00241     int left_clip_;
00242     int right_clip_;
00243     int top_clip_;
00244     int bottom_clip_;
00245 
00246     bool SetLabelProperty(std::string &value, std::string const &str);
00247 
00248     void Initialize(const std::string &str, TextureArea* texture_area);
00249 
00250     void BuildLayout(const std::string &str, TextureArea* texture_area);
00251 
00252     TextureArea *image_;
00253     Size image_minimum_size_;
00254     Size image_maximum_size_;
00255 
00256     virtual void Draw(GraphicsEngine &graphics_engine, bool force_draw);
00257     virtual void RecvClick(int x, int y, unsigned long button_flags, unsigned long key_flags);
00258 //     virtual void PreLayoutManagement();
00259 //     virtual long PostLayoutManagement(long LayoutResult);
00260     virtual long ComputeContentSize();
00261   };
00262 
00263   //typedef Button ToggleButton;
00264 }
00265 
00266 #endif // BUTTON_H