nux-1.16.0
RGBValuator.h
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 RGBGEVALUATOR_H
00024 #define RGBGEVALUATOR_H
00025 
00026 #include "NuxCore/Color.h"
00027 #include "HexRegExpValidator.h"
00028 #include "IntegerValidator.h"
00029 #include "DoubleValidator.h"
00030 
00031 namespace nux
00032 {
00033 
00034   class ToggleButton;
00035   class VLayout;
00036   class HLayout;
00037   class EditTextBox;
00038 
00039   class RGBValuator : public View //public ValuatorAbstraction
00040   {
00041     NUX_DECLARE_OBJECT_TYPE (RGBValuator, View);
00042   public:
00043     RGBValuator(NUX_FILE_LINE_PROTO);
00044     RGBValuator(Color const& color, NUX_FILE_LINE_PROTO);
00054     RGBValuator(color::Model colorModel, float x, float y, float z, float alpha, NUX_FILE_LINE_PROTO);
00055 
00056     ~RGBValuator();
00057 
00058     // API
00059     void SetColorModel(color::Model cm);
00060     void SetColorFormat(color::Format cf);
00061     Color GetColor() const;
00062 
00063     virtual void Draw (GraphicsEngine &GfxContext, bool force_draw);
00064     virtual void DrawContent (GraphicsEngine &GfxContext, bool force_draw);
00065     virtual void PostDraw (GraphicsEngine &GfxContext, bool force_draw);
00066 
00067     void SetRGB (Color const& color);
00068     void SetRGB (float r, float g, float b);
00069     void SetAlpha (float alpha);
00070     void SetRGBA (Color const& color);
00071     void SetRGBA (float r, float g, float b, float a);
00072 
00073     void SetHSV (float h, float s, float v);
00074     void SetHLS (float h, float l, float s);
00075 
00076     // emitters
00077     void OnReceiveMouseDown_Red     (int x, int y, unsigned long button_flags, unsigned long key_flags);
00078     void OnReceiveMouseDown_Green   (int x, int y, unsigned long button_flags, unsigned long key_flags);
00079     void OnReceiveMouseDown_Blue    (int x, int y, unsigned long button_flags, unsigned long key_flags);
00080     void OnReceiveMouseDown_Alpha   (int x, int y, unsigned long button_flags, unsigned long key_flags);
00081     void OnReceiveMouseDrag_Red     (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
00082     void OnReceiveMouseDrag_Green   (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
00083     void OnReceiveMouseDrag_Blue    (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
00084     void OnReceiveMouseDrag_Alpha   (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
00085     void OnChangeColorModel();
00086     void OnChangeColorFormat();
00087     void RecvMouseDownColorModel (int x, int y, unsigned long button_flags, unsigned long key_flags);
00088 
00089     void OnReceiveMouseUp_Red       (int x, int y, unsigned long button_flags, unsigned long key_flags);
00090     void OnReceiveMouseUp_Green     (int x, int y, unsigned long button_flags, unsigned long key_flags);
00091     void OnReceiveMouseUp_Blue      (int x, int y, unsigned long button_flags, unsigned long key_flags);
00092 
00093     void OnComponentInput           (EditTextBox *textbox, const NString &s, int componentIndex);
00094     void OnChannelKeyboardFocus();
00095     void OnChannelLostKeyboardFocus();
00096     void OnChannelValidateKeyboardEntry();
00097     void OnChannelCharacter (unsigned int character, int componentIndex);
00098 
00100 
00104     void EmitColorChangedSignal();
00105 
00106     // signals
00107     //sigc::signal<void, float, float, float> sigSetRGB;
00108     sigc::signal<void, float, float, float, float> sigColorChanged;
00109 
00110   protected:
00111     void InitializeWidgets();
00112     void InitializeLayout();
00113 
00114     virtual bool AcceptKeyNavFocus();
00115 
00116   private:
00117     void DrawRedMarker (GraphicsEngine &GfxContext);
00118     void DrawGreenMarker (GraphicsEngine &GfxContext);
00119     void DrawBlueMarker (GraphicsEngine &GfxContext);
00120     void DrawAlphaMarker (GraphicsEngine &GfxContext);
00121 
00122     void DrawRGB (GraphicsEngine &GfxContext);
00123     void DrawHSV (GraphicsEngine &GfxContext);
00124     void DrawHLS (GraphicsEngine &GfxContext);
00125 
00126     HLayout *hlayout;
00127     HLayout *redlayout;
00128     HLayout *greenlayout;
00129     HLayout *bluelayout;
00130     HLayout *alphalayout;
00131     VLayout *vlayout;
00132     VLayout *colormodel_layout;
00133 
00134     EditTextBox *m_RedCaption;
00135     EditTextBox *m_GreenCaption;
00136     EditTextBox *m_BlueCaption;
00137     EditTextBox *m_AlphaCaption;
00138     InputArea *m_RedValuator;
00139     InputArea *m_GreenValuator;
00140     InputArea *m_BlueValuator;
00141     InputArea *m_AlphaValuator;
00142     InputArea *m_ColorSquare;
00143 
00144     InputArea *m_ComponentLabel0;
00145     InputArea *m_ComponentLabel1;
00146     InputArea *m_ComponentLabel2;
00147     InputArea *m_ComponentAlpha;
00148 
00149     TextureLayer *m_CheckboardLayer;
00150 
00151     color::RedGreenBlue rgb_;
00152     color::HueSaturationValue hsv_;
00153     color::HueLightnessSaturation hls_;
00154     float alpha_;
00155 
00156     ToggleButton *m_ColorModel;
00157     ToggleButton *m_ColorFormat;
00158 
00159     color::Model m_color_model;
00160     color::Format m_color_format;
00161 
00162     HexRegExpValidator m_HexRegExp;
00163     IntegerValidator m_IntRegExp;
00164     DoubleValidator m_DoubleRegExp;
00165     virtual long ComputeChildLayout();
00166   };
00167 
00168 }
00169 
00170 #endif // RGBGEVALUATOR_H
00171 
00172 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends