~sil2100/nux/revert_640

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*
 * Copyright 2010 Inalogic® Inc.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License, as
 * published by the  Free Software Foundation; either version 2.1 or 3.0
 * of the License.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the applicable version of the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of both the GNU Lesser General Public
 * License along with this program. If not, see <http://www.gnu.org/licenses/>
 *
 * Authored by: Jay Taoko <jaytaoko@inalogic.com>
 *
 */


#ifndef RGBGEVALUATOR_H
#define RGBGEVALUATOR_H

#include "NuxCore/Color.h"
#include "HexRegExpValidator.h"
#include "IntegerValidator.h"
#include "DoubleValidator.h"

namespace nux
{

  class ToggleButton;
  class VLayout;
  class HLayout;
  class EditTextBox;
  class AbstractButton;

  class RGBValuator : public View //public ValuatorAbstraction
  {
    NUX_DECLARE_OBJECT_TYPE (RGBValuator, View);
  public:
    RGBValuator(NUX_FILE_LINE_PROTO);
    RGBValuator(Color const& color, NUX_FILE_LINE_PROTO);
    /*!
        Create an initialize the widget with the appropriate color model and value.

        @param ColorModel The color model (CM_RGB, CM_HSV, CM_HLS)
        @param x Red if CM_RGB, Hue if CM_HSV, Hue if CM_HLS
        @param y Green if CM_RGB, Saturation if CM_HSV, Light if CM_HLS
        @param z Blue if CM_RGB, Value if CM_HSV, Saturation if CM_HLS
        @param alpha
    */
    RGBValuator(color::Model colorModel, float x, float y, float z, float alpha, NUX_FILE_LINE_PROTO);

    ~RGBValuator();

    // API
    void SetColorModel(color::Model cm);
    void SetColorFormat(color::Format cf);
    Color GetColor() const;

    virtual void Draw (GraphicsEngine &graphics_engine, bool force_draw);
    virtual void DrawContent (GraphicsEngine &graphics_engine, bool force_draw);
    virtual void PostDraw (GraphicsEngine &graphics_engine, bool force_draw);

    void SetRGB (Color const& color);
    void SetRGB (float r, float g, float b);
    void SetAlpha (float alpha);
    void SetRGBA (Color const& color);
    void SetRGBA (float r, float g, float b, float a);

    void SetHSV (float h, float s, float v);
    void SetHLS (float h, float l, float s);

    // emitters
    void OnReceiveMouseDown_Red     (int x, int y, unsigned long button_flags, unsigned long key_flags);
    void OnReceiveMouseDown_Green   (int x, int y, unsigned long button_flags, unsigned long key_flags);
    void OnReceiveMouseDown_Blue    (int x, int y, unsigned long button_flags, unsigned long key_flags);
    void OnReceiveMouseDown_Alpha   (int x, int y, unsigned long button_flags, unsigned long key_flags);
    void OnReceiveMouseDrag_Red     (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
    void OnReceiveMouseDrag_Green   (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
    void OnReceiveMouseDrag_Blue    (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
    void OnReceiveMouseDrag_Alpha   (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
    void OnChangeColorModel(AbstractButton* button);
    void OnChangeColorFormat(AbstractButton* button);
    void RecvMouseDownColorModel (int x, int y, unsigned long button_flags, unsigned long key_flags);

    void OnReceiveMouseUp_Red       (int x, int y, unsigned long button_flags, unsigned long key_flags);
    void OnReceiveMouseUp_Green     (int x, int y, unsigned long button_flags, unsigned long key_flags);
    void OnReceiveMouseUp_Blue      (int x, int y, unsigned long button_flags, unsigned long key_flags);

    void OnComponentInput           (EditTextBox *textbox, const NString &s, int componentIndex);
    void OnChannelKeyboardFocus();
    void OnChannelLostKeyboardFocus();
    void OnChannelValidateKeyboardEntry();
    void OnChannelCharacter (unsigned int character, int componentIndex);

    //! Cause the widget to emit sigColorChanged signal.
    /*!
        Cause the widget to emit sigColorChanged signal.
        Useful for initialization of the signal receivers.
    */
    void EmitColorChangedSignal();

    // signals
    //sigc::signal<void, float, float, float> sigSetRGB;
    sigc::signal<void, float, float, float, float> sigColorChanged;

  protected:
    void InitializeWidgets();
    void InitializeLayout();

    virtual bool AcceptKeyNavFocus();

  private:
    void DrawRedMarker (GraphicsEngine &graphics_engine);
    void DrawGreenMarker (GraphicsEngine &graphics_engine);
    void DrawBlueMarker (GraphicsEngine &graphics_engine);
    void DrawAlphaMarker (GraphicsEngine &graphics_engine);

    void DrawRGB (GraphicsEngine &graphics_engine);
    void DrawHSV (GraphicsEngine &graphics_engine);
    void DrawHLS (GraphicsEngine &graphics_engine);

    HLayout *hlayout;
    HLayout *redlayout;
    HLayout *greenlayout;
    HLayout *bluelayout;
    HLayout *alphalayout;
    VLayout *vlayout;
    VLayout *colormodel_layout;

    EditTextBox *m_RedCaption;
    EditTextBox *m_GreenCaption;
    EditTextBox *m_BlueCaption;
    EditTextBox *m_AlphaCaption;
    InputArea *m_RedValuator;
    InputArea *m_GreenValuator;
    InputArea *m_BlueValuator;
    InputArea *m_AlphaValuator;
    InputArea *m_ColorSquare;

    InputArea *m_ComponentLabel0;
    InputArea *m_ComponentLabel1;
    InputArea *m_ComponentLabel2;
    InputArea *m_ComponentAlpha;

    TextureLayer *m_CheckboardLayer;

    color::RedGreenBlue rgb_;
    color::HueSaturationValue hsv_;
    color::HueLightnessSaturation hls_;
    float alpha_;

    ToggleButton *m_ColorModel;
    ToggleButton *m_ColorFormat;

    color::Model m_color_model;
    color::Format m_color_format;

    HexRegExpValidator m_HexRegExp;
    IntegerValidator m_IntRegExp;
    DoubleValidator m_DoubleRegExp;
    virtual long ComputeContentSize();
  };

}

#endif // RGBGEVALUATOR_H