Back to index

nux  3.0.0
ColorEditor.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 COLOREDITOR_H
00024 #define COLOREDITOR_H
00025 
00026 #include "NuxGraphics/GpuDevice.h"
00027 #include "NuxGraphics/GLDeviceObjects.h"
00028 #include "NuxGraphics/GLSh_DrawFunction.h"
00029 #include "DoubleValidator.h"
00030 #include "TimerProc.h"
00031 
00032 namespace nux
00033 {
00034 
00035   class GLSh_ColorPicker;
00036   class HLayout;
00037   class VLayout;
00038   class EditTextBox;
00039   class CheckBox;
00040   class AbstractButton;
00041   class RadioButton;
00042   class RadioButtonGroup;
00043   class Button;
00044 
00045   class ColorEditor;
00046   class ColorPreview;
00047 
00048   class ColorDialogProxy
00049   {
00050   public:
00051     ColorDialogProxy(bool ModalWindow);
00052     ~ColorDialogProxy();
00053 
00054     void RecvDialogOk(ColorEditor *coloreditor);
00055     void RecvDialogCancel(ColorEditor *coloreditor);
00056     void RecvDialogChange(ColorEditor *coloreditor);
00057 
00058     void Start();
00059     bool IsActive();
00060     void StopThreadMonitoring();
00061 
00062     void SetColor(Color color);
00063     Color GetColor();
00064     void SetPreviousColor(Color color);
00065     Color GetPreviousColor();
00066     void SetColorModel(color::Model color_model);
00067     color::Model GetColorModel();
00068     void SetColorChannel(color::Channel color_model);
00069     color::Channel GetColorChannel();
00070 
00071   private:
00072     bool m_bDialogChange;
00073     bool m_bDialogRunning;
00074     unsigned int m_DialogThreadID;
00075     Color m_RGBColor;
00076     Color m_PreviousRGBColor;
00077     color::Model m_ColorModel;
00078     color::Channel color_channel_;
00079     bool m_ModalWindow;
00080     NThread *m_Thread;
00081 
00082     friend class ColorPreview;
00083   };
00084 
00085   class ColorEditor : public View
00086   {
00087   public:
00088     ColorEditor(NUX_FILE_LINE_PROTO);
00089     ~ColorEditor();
00090 
00091     void SetRed(double r);
00092     void SetGreen(double g);
00093     void SetBlue(double b);
00094     void SetHue(double h);
00095     void SetSaturation(double s);
00096     void SetValue(double v);
00097 
00098     void SetRGB(double r, double g, double b);
00099     void SetHSV(double h, double s, double v);
00100     void SetRGB(Color const& rgb);
00101     Color GetRGBColor() const;
00102 
00103     void SetColorModel(color::Model, color::Channel);
00104     color::Model GetColorModel() const;
00105     color::Channel GetColorChannel() const;
00106 
00107     void RecvMouseDown(int x, int y, unsigned long button_flags, unsigned long key_flags);
00108     void RecvMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags);
00109     void RecvMouseDrag(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
00110 
00111     void RecvPickerMouseDown(int x, int y, unsigned long button_flags, unsigned long key_flags);
00112     void RecvPickerMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags);
00113     void RecvPickerMouseDrag(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
00114 
00115     void RecvCheckColorModel(bool, color::Model, color::Channel);
00116     void RecvCheckColorModel0(AbstractButton *button, color::Model color_mode, color::Channel channel);
00117 
00118     sigc::signal< void, ColorEditor * > sigChange;
00119 
00120   protected:
00121     virtual void Draw(GraphicsEngine &graphics_engine, bool force_draw);
00122     virtual void DrawContent(GraphicsEngine &graphics_engine, bool force_draw);
00123     virtual void PreLayoutManagement();
00124     virtual bool AcceptKeyNavFocus();
00125   private:
00126 
00128 
00131     virtual void SetMinimumHeight(){};
00132 
00134 
00137     virtual void SetMaximumHeight(){};
00138 
00140 
00143     virtual void SetMinimumWidth(){};
00144 
00146 
00149     virtual void SetMaximumWidth(){};
00150 
00151     void DrawBaseChannelMarker(GraphicsEngine &graphics_engine);
00152     void DrawRGB(GraphicsEngine &graphics_engine, bool force_draw);
00153     void DrawHSV(GraphicsEngine &graphics_engine, bool force_draw);
00154 
00155     color::Channel   color_channel_;
00156     color::Model     m_ColorModel;
00157     InputArea       *picker_area_;
00158     InputArea       *channel_area_;
00159     InputArea       *selected_color_area_;
00160     HLayout        *m_hlayout;
00161     VLayout        *ctrllayout;
00162 
00163     GLSh_ColorPicker *m_RedShader;
00164     GLSh_ColorPicker *m_GreenShader;
00165     GLSh_ColorPicker *m_BlueShader;
00166 
00167     GLSh_ColorPicker *m_HueShader;
00168     GLSh_ColorPicker *m_SaturationShader;
00169     GLSh_ColorPicker *m_ValueShader;
00170 
00171     Point m_MarkerPosition;
00172     Point m_VertMarkerPosition;
00173 
00174     color::RedGreenBlue rgb_;
00175     color::HueSaturationValue hsv_;
00176 
00177     HLayout *redlayout;
00178     HLayout *greenlayout;
00179     HLayout *bluelayout;
00180 
00181     RadioButton *redcheck;
00182     EditTextBox *redtext;
00183     RadioButton *greencheck;
00184     EditTextBox *greentext;
00185     RadioButton *bluecheck;
00186     EditTextBox *bluetext;
00187 
00188     HLayout *huelayout;
00189     HLayout *saturationlayout;
00190     HLayout *valuelayout;
00191 
00192     RadioButton *huecheck;
00193     EditTextBox *hue_text_entry_;
00194     RadioButton *saturationcheck;
00195     EditTextBox *saturation_text_entry_;
00196     RadioButton *valuecheck;
00197     EditTextBox *value_text_entry_;
00198 
00199     Button *OkButton;
00200     Button *CancelButton;
00201     RadioButtonGroup *radiogroup;
00202 
00203     DoubleValidator m_Validator;
00204 
00205     static Size picker_area_size;
00206     static int channel_area_width;
00207   };
00208 
00209 
00210 }
00211 
00212 #endif // COLOREDITOR_H
00213