Back to index

nux  3.0.0
RGBValuator.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 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   class AbstractButton;
00039 
00040   class RGBValuator : public View //public ValuatorAbstraction
00041   {
00042     NUX_DECLARE_OBJECT_TYPE(RGBValuator, View);
00043   public:
00044     RGBValuator(NUX_FILE_LINE_PROTO);
00045     RGBValuator(Color const& color, NUX_FILE_LINE_PROTO);
00055     RGBValuator(color::Model colorModel, float x, float y, float z, float alpha, NUX_FILE_LINE_PROTO);
00056 
00057     ~RGBValuator();
00058 
00059     // API
00060     void SetColorModel(color::Model cm);
00061     void SetColorFormat(color::Format cf);
00062     Color GetColor() const;
00063 
00064     void SetRGB(Color const& color);
00065     void SetRGB(float r, float g, float b);
00066     void SetAlpha(float alpha);
00067     void SetRGBA(Color const& color);
00068     void SetRGBA(float r, float g, float b, float a);
00069 
00070     void SetHSV(float h, float s, float v);
00071     void SetHLS(float h, float l, float s);
00072 
00073     // emitters
00074     void OnReceiveMouseDown_Red     (int x, int y, unsigned long button_flags, unsigned long key_flags);
00075     void OnReceiveMouseDown_Green   (int x, int y, unsigned long button_flags, unsigned long key_flags);
00076     void OnReceiveMouseDown_Blue    (int x, int y, unsigned long button_flags, unsigned long key_flags);
00077     void OnReceiveMouseDown_Alpha   (int x, int y, unsigned long button_flags, unsigned long key_flags);
00078     void OnReceiveMouseDrag_Red     (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
00079     void OnReceiveMouseDrag_Green   (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
00080     void OnReceiveMouseDrag_Blue    (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
00081     void OnReceiveMouseDrag_Alpha   (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
00082     void OnChangeColorModel(AbstractButton* button);
00083     void OnChangeColorFormat(AbstractButton* button);
00084     void RecvMouseDownColorModel(int x, int y, unsigned long button_flags, unsigned long key_flags);
00085 
00086     void OnReceiveMouseUp_Red       (int x, int y, unsigned long button_flags, unsigned long key_flags);
00087     void OnReceiveMouseUp_Green     (int x, int y, unsigned long button_flags, unsigned long key_flags);
00088     void OnReceiveMouseUp_Blue      (int x, int y, unsigned long button_flags, unsigned long key_flags);
00089 
00090     void OnComponentInput           (EditTextBox *textbox, const NString &s, int componentIndex);
00091     void OnChannelKeyboardFocus();
00092     void OnChannelLostKeyboardFocus();
00093     void OnChannelValidateKeyboardEntry();
00094     void OnChannelCharacter(unsigned int character, int componentIndex);
00095 
00097 
00101     void EmitColorChangedSignal();
00102 
00103     // signals
00104     //sigc::signal<void, float, float, float> sigSetRGB;
00105     sigc::signal<void, float, float, float, float> sigColorChanged;
00106 
00107   protected:
00108     virtual void Draw(GraphicsEngine &graphics_engine, bool force_draw);
00109     virtual void DrawContent(GraphicsEngine &graphics_engine, bool force_draw);
00110     virtual void PreLayoutManagement();
00111 
00112     void InitializeWidgets();
00113     void InitializeLayout();
00114 
00115     virtual bool AcceptKeyNavFocus();
00116 
00117   private:
00119 
00122     virtual void SetMinimumHeight(){};
00123 
00125 
00128     virtual void SetMaximumHeight(){};
00129 
00130     void DrawRedMarker(GraphicsEngine &graphics_engine);
00131     void DrawGreenMarker(GraphicsEngine &graphics_engine);
00132     void DrawBlueMarker(GraphicsEngine &graphics_engine);
00133     void DrawAlphaMarker(GraphicsEngine &graphics_engine);
00134 
00135     void DrawRGB(GraphicsEngine &graphics_engine);
00136     void DrawHSV(GraphicsEngine &graphics_engine);
00137     void DrawHLS(GraphicsEngine &graphics_engine);
00138 
00139     HLayout *hlayout;
00140     HLayout *redlayout;
00141     HLayout *greenlayout;
00142     HLayout *bluelayout;
00143     HLayout *alphalayout;
00144     VLayout *vlayout;
00145     VLayout *colormodel_layout;
00146 
00147     EditTextBox *red_caption_;
00148     EditTextBox *green_caption_;
00149     EditTextBox *blue_caption_;
00150     EditTextBox *alpha_caption_;
00151     InputArea *red_valuator_;
00152     InputArea *green_valuator_;
00153     InputArea *blue_valuator_;
00154     InputArea *alpha_valuator_;
00155     InputArea *color_square_;
00156 
00157     InputArea *m_ComponentLabel0;
00158     InputArea *m_ComponentLabel1;
00159     InputArea *m_ComponentLabel2;
00160     InputArea *m_ComponentAlpha;
00161 
00162     TextureLayer *m_CheckboardLayer;
00163 
00164     color::RedGreenBlue rgb_;
00165     color::HueSaturationValue hsv_;
00166     color::HueLightnessSaturation hls_;
00167     float alpha_;
00168 
00169     ToggleButton *m_ColorModel;
00170     ToggleButton *m_ColorFormat;
00171 
00172     color::Model m_color_model;
00173     color::Format m_color_format;
00174 
00175     HexRegExpValidator m_HexRegExp;
00176     IntegerValidator m_IntRegExp;
00177     DoubleValidator m_DoubleRegExp;
00178   };
00179 
00180 }
00181 
00182 #endif // RGBGEVALUATOR_H
00183 
00184