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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
/**
* @file llfloatercolorpicker.h
* @brief Generic system color picker
*
* $LicenseInfo:firstyear=2004&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library 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;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#ifndef LL_LLFLOATERCOLORPICKER_H
#define LL_LLFLOATERCOLORPICKER_H
#include <vector>
#include "llfloater.h"
#include "llpointer.h"
#include "llcolorswatch.h"
#include "llspinctrl.h"
class LLButton;
class LLLineEditor;
class LLCheckBoxCtrl;
//////////////////////////////////////////////////////////////////////////////
// floater class
class LLFloaterColorPicker
: public LLFloater
{
public:
LLFloaterColorPicker (LLColorSwatchCtrl* swatch, BOOL show_apply_immediate = FALSE);
virtual ~LLFloaterColorPicker ();
// overrides
virtual BOOL postBuild ();
virtual void draw ();
virtual BOOL handleMouseDown ( S32 x, S32 y, MASK mask );
virtual BOOL handleMouseUp ( S32 x, S32 y, MASK mask );
virtual BOOL handleHover ( S32 x, S32 y, MASK mask );
virtual void onMouseCaptureLost();
virtual F32 getSwatchTransparency();
// implicit methods
void createUI ();
void initUI ( F32 rValIn, F32 gValIn, F32 bValIn );
void showUI ();
void destroyUI ();
void cancelSelection ();
LLColorSwatchCtrl* getSwatch () { return mSwatch; };
void setSwatch( LLColorSwatchCtrl* swatch) { mSwatch = swatch; }
// mutator / accessor for original RGB value
void setOrigRgb ( F32 origRIn, F32 origGIn, F32 origBIn );
void getOrigRgb ( F32& origROut, F32& origGOut, F32& origBOut );
F32 getOrigR () { return origR; };
F32 getOrigG () { return origG; };
F32 getOrigB () { return origB; };
// mutator / accessors for currernt RGB value
void setCurRgb ( F32 curRIn, F32 curGIn, F32 curBIn );
void getCurRgb ( F32& curROut, F32& curGOut, F32& curBOut );
F32 getCurR () { return curR; };
F32 getCurG () { return curG; };
F32 getCurB () { return curB; };
// mutator / accessors for currernt HSL value
void setCurHsl ( F32 curHIn, F32 curSIn, F32 curLIn );
void getCurHsl ( F32& curHOut, F32& curSOut, F32& curLOut );
F32 getCurH () { return curH; };
F32 getCurS () { return curS; };
F32 getCurL () { return curL; };
// updates current RGB/HSL values based on point in picker
BOOL updateRgbHslFromPoint ( S32 xPosIn, S32 yPosIn );
// updates text entry fields with current RGB/HSL
void updateTextEntry ();
void stopUsingPipette();
// mutator / accessor for mouse button pressed in region
void setMouseDownInHueRegion ( BOOL mouse_down_in_region );
BOOL getMouseDownInHueRegion () { return mMouseDownInHueRegion; };
void setMouseDownInLumRegion ( BOOL mouse_down_in_region );
BOOL getMouseDownInLumRegion () { return mMouseDownInLumRegion; };
void setMouseDownInSwatch (BOOL mouse_down_in_swatch);
BOOL getMouseDownInSwatch () { return mMouseDownInSwatch; }
// called when text entries (RGB/HSL etc.) are changed by user
void onTextEntryChanged ( LLUICtrl* ctrl );
// convert RGB to HSL and vice-versa
void hslToRgb ( F32 hValIn, F32 sValIn, F32 lValIn, F32& rValOut, F32& gValOut, F32& bValOut );
F32 hueToRgb ( F32 val1In, F32 val2In, F32 valHUeIn );
void setActive(BOOL active);
protected:
// callbacks
static void onClickCancel ( void* data );
static void onClickSelect ( void* data );
void onClickPipette ( );
static void onTextCommit ( LLUICtrl* ctrl, void* data );
static void onImmediateCheck ( LLUICtrl* ctrl, void* data );
void onColorSelect( const class LLTextureEntry& te );
private:
// mutators for color values, can raise event to preview changes at object
void selectCurRgb ( F32 curRIn, F32 curGIn, F32 curBIn );
void selectCurHsl ( F32 curHIn, F32 curSIn, F32 curLIn );
// draws color selection palette
void drawPalette ();
// find a complimentary color to the one passed in that can be used to highlight
const LLColor4& getComplimentaryColor ( const LLColor4& backgroundColor );
// original RGB values
F32 origR, origG, origB;
// current RGB/HSL values
F32 curR, curG, curB;
F32 curH, curS, curL;
const S32 mComponents;
BOOL mMouseDownInLumRegion;
BOOL mMouseDownInHueRegion;
BOOL mMouseDownInSwatch;
const S32 mRGBViewerImageLeft;
const S32 mRGBViewerImageTop;
const S32 mRGBViewerImageWidth;
const S32 mRGBViewerImageHeight;
const S32 mLumRegionLeft;
const S32 mLumRegionTop;
const S32 mLumRegionWidth;
const S32 mLumRegionHeight;
const S32 mLumMarkerSize;
// Preview of the current color.
const S32 mSwatchRegionLeft;
const S32 mSwatchRegionTop;
const S32 mSwatchRegionWidth;
const S32 mSwatchRegionHeight;
LLView* mSwatchView;
const S32 numPaletteColumns;
const S32 numPaletteRows;
std::vector < LLColor4* > mPalette;
S32 highlightEntry;
const S32 mPaletteRegionLeft;
const S32 mPaletteRegionTop;
const S32 mPaletteRegionWidth;
const S32 mPaletteRegionHeight;
// image used to compose color grid
LLPointer<class LLViewerTexture> mRGBImage;
// current swatch in use
LLColorSwatchCtrl* mSwatch;
// are we actively tied to some output?
BOOL mActive;
// enable/disable immediate updates
LLCheckBoxCtrl* mApplyImmediateCheck;
BOOL mCanApplyImmediately;
LLButton* mSelectBtn;
LLButton* mCancelBtn;
LLButton* mPipetteBtn;
F32 mContextConeOpacity;
F32 mContextConeInAlpha;
F32 mContextConeOutAlpha;
F32 mContextConeFadeTime;
};
#endif // LL_LLFLOATERCOLORPICKER_H
|