PageRenderTime 33ms CodeModel.GetById 21ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llfloatercolorpicker.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 194 lines | 109 code | 38 blank | 47 comment | 0 complexity | 728fdd2d3e64b7a4c4c085a4b7d0a939 MD5 | raw file
  1/** 
  2 * @file llfloatercolorpicker.h
  3 * @brief Generic system color picker
  4 *
  5 * $LicenseInfo:firstyear=2004&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LL_LLFLOATERCOLORPICKER_H
 28#define LL_LLFLOATERCOLORPICKER_H
 29
 30#include <vector>
 31
 32#include "llfloater.h"
 33#include "llpointer.h"
 34#include "llcolorswatch.h"
 35#include "llspinctrl.h"
 36#include "lltextureentry.h"
 37
 38class LLButton;
 39class LLLineEditor;
 40class LLCheckBoxCtrl;
 41
 42//////////////////////////////////////////////////////////////////////////////
 43// floater class
 44class LLFloaterColorPicker 
 45	: public LLFloater
 46{
 47	public:
 48		LLFloaterColorPicker (LLColorSwatchCtrl* swatch, BOOL show_apply_immediate = FALSE);
 49		virtual ~LLFloaterColorPicker ();
 50
 51		// overrides
 52		virtual BOOL postBuild ();
 53		virtual void draw ();
 54		virtual BOOL handleMouseDown ( S32 x, S32 y, MASK mask );
 55		virtual BOOL handleMouseUp ( S32 x, S32 y, MASK mask );
 56		virtual BOOL handleHover ( S32 x, S32 y, MASK mask );
 57		virtual void onMouseCaptureLost();
 58		virtual F32  getSwatchTransparency();
 59
 60		// implicit methods
 61		void createUI ();
 62		void initUI ( F32 rValIn, F32 gValIn, F32 bValIn );
 63		void showUI ();
 64		void destroyUI ();
 65		void cancelSelection ();
 66		LLColorSwatchCtrl* getSwatch () { return mSwatch; };
 67		void setSwatch( LLColorSwatchCtrl* swatch) { mSwatch = swatch; }
 68
 69		// mutator / accessor for original RGB value
 70		void setOrigRgb ( F32 origRIn, F32 origGIn, F32 origBIn );
 71		void getOrigRgb ( F32& origROut, F32& origGOut, F32& origBOut );
 72		F32 getOrigR () { return origR; };
 73		F32 getOrigG () { return origG; };
 74		F32 getOrigB () { return origB; };
 75
 76		// mutator / accessors for currernt RGB value
 77		void setCurRgb ( F32 curRIn, F32 curGIn, F32 curBIn );
 78		void getCurRgb ( F32& curROut, F32& curGOut, F32& curBOut );
 79		F32	 getCurR () { return curR; };
 80		F32	 getCurG () { return curG; };
 81		F32	 getCurB () { return curB; };
 82
 83		// mutator / accessors for currernt HSL value
 84		void setCurHsl ( F32 curHIn, F32 curSIn, F32 curLIn );
 85		void getCurHsl ( F32& curHOut, F32& curSOut, F32& curLOut );
 86		F32	 getCurH () { return curH; };
 87		F32	 getCurS () { return  curS; };
 88		F32	 getCurL () { return curL; };
 89
 90		// updates current RGB/HSL values based on point in picker
 91		BOOL updateRgbHslFromPoint ( S32 xPosIn, S32 yPosIn );
 92
 93		// updates text entry fields with current RGB/HSL
 94		void updateTextEntry ();
 95
 96		void stopUsingPipette();
 97
 98		// mutator / accessor for mouse button pressed in region
 99		void setMouseDownInHueRegion ( BOOL mouse_down_in_region );
100		BOOL getMouseDownInHueRegion () { return mMouseDownInHueRegion; };
101
102		void setMouseDownInLumRegion ( BOOL mouse_down_in_region );
103		BOOL getMouseDownInLumRegion () { return mMouseDownInLumRegion; };
104
105		void setMouseDownInSwatch (BOOL mouse_down_in_swatch);
106		BOOL getMouseDownInSwatch () { return mMouseDownInSwatch; }
107
108		// called when text entries (RGB/HSL etc.) are changed by user
109		void onTextEntryChanged ( LLUICtrl* ctrl );
110
111		// convert RGB to HSL and vice-versa
112		void hslToRgb ( F32 hValIn, F32 sValIn, F32 lValIn, F32& rValOut, F32& gValOut, F32& bValOut );
113		F32	 hueToRgb ( F32 val1In, F32 val2In, F32 valHUeIn );
114
115		void setActive(BOOL active);
116
117	protected:
118		// callbacks
119		static void onClickCancel ( void* data );
120		static void onClickSelect ( void* data );
121			   void onClickPipette ( );
122		static void onTextCommit ( LLUICtrl* ctrl, void* data );
123		static void onImmediateCheck ( LLUICtrl* ctrl, void* data );
124			   void onColorSelect( const LLTextureEntry& te );
125	private:
126		// draws color selection palette
127		void drawPalette ();
128
129		// find a complimentary color to the one passed in that can be used to highlight 
130		const LLColor4& getComplimentaryColor ( const LLColor4& backgroundColor );
131
132		// original RGB values
133		F32 origR, origG, origB;
134
135		// current RGB/HSL values
136		F32 curR, curG, curB;
137		F32 curH, curS, curL;
138
139		const S32 mComponents;
140
141		BOOL mMouseDownInLumRegion;
142		BOOL mMouseDownInHueRegion;
143		BOOL mMouseDownInSwatch;
144
145		const S32 mRGBViewerImageLeft;
146		const S32 mRGBViewerImageTop;
147		const S32 mRGBViewerImageWidth;
148		const S32 mRGBViewerImageHeight;
149
150		const S32 mLumRegionLeft;
151		const S32 mLumRegionTop;
152		const S32 mLumRegionWidth;
153		const S32 mLumRegionHeight;
154		const S32 mLumMarkerSize;
155
156		// Preview of the current color.
157		const S32 mSwatchRegionLeft;
158		const S32 mSwatchRegionTop;
159		const S32 mSwatchRegionWidth;
160		const S32 mSwatchRegionHeight;
161
162		LLView* mSwatchView;
163
164		const S32 numPaletteColumns;
165		const S32 numPaletteRows;
166        std::vector < LLColor4* > mPalette;
167		S32 highlightEntry;
168		const S32 mPaletteRegionLeft;
169		const S32 mPaletteRegionTop;
170		const S32 mPaletteRegionWidth;
171		const S32 mPaletteRegionHeight;
172
173		// image used to compose color grid
174		LLPointer<LLViewerTexture> mRGBImage;
175
176		// current swatch in use
177		LLColorSwatchCtrl* mSwatch;
178
179		// are we actively tied to some output?
180		BOOL	mActive;
181
182		// enable/disable immediate updates
183		LLCheckBoxCtrl* mApplyImmediateCheck;
184		BOOL mCanApplyImmediately;
185
186		LLButton* mSelectBtn;
187		LLButton* mCancelBtn;
188
189		LLButton* mPipetteBtn;
190
191		F32		  mContextConeOpacity;
192};
193
194#endif // LL_LLFLOATERCOLORPICKER_H