PageRenderTime 1038ms CodeModel.GetById 508ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1
  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. #ifndef LL_LLFLOATERCOLORPICKER_H
  27. #define LL_LLFLOATERCOLORPICKER_H
  28. #include <vector>
  29. #include "llfloater.h"
  30. #include "llpointer.h"
  31. #include "llcolorswatch.h"
  32. #include "llspinctrl.h"
  33. #include "lltextureentry.h"
  34. class LLButton;
  35. class LLLineEditor;
  36. class LLCheckBoxCtrl;
  37. //////////////////////////////////////////////////////////////////////////////
  38. // floater class
  39. class LLFloaterColorPicker
  40. : public LLFloater
  41. {
  42. public:
  43. LLFloaterColorPicker (LLColorSwatchCtrl* swatch, BOOL show_apply_immediate = FALSE);
  44. virtual ~LLFloaterColorPicker ();
  45. // overrides
  46. virtual BOOL postBuild ();
  47. virtual void draw ();
  48. virtual BOOL handleMouseDown ( S32 x, S32 y, MASK mask );
  49. virtual BOOL handleMouseUp ( S32 x, S32 y, MASK mask );
  50. virtual BOOL handleHover ( S32 x, S32 y, MASK mask );
  51. virtual void onMouseCaptureLost();
  52. virtual F32 getSwatchTransparency();
  53. // implicit methods
  54. void createUI ();
  55. void initUI ( F32 rValIn, F32 gValIn, F32 bValIn );
  56. void showUI ();
  57. void destroyUI ();
  58. void cancelSelection ();
  59. LLColorSwatchCtrl* getSwatch () { return mSwatch; };
  60. void setSwatch( LLColorSwatchCtrl* swatch) { mSwatch = swatch; }
  61. // mutator / accessor for original RGB value
  62. void setOrigRgb ( F32 origRIn, F32 origGIn, F32 origBIn );
  63. void getOrigRgb ( F32& origROut, F32& origGOut, F32& origBOut );
  64. F32 getOrigR () { return origR; };
  65. F32 getOrigG () { return origG; };
  66. F32 getOrigB () { return origB; };
  67. // mutator / accessors for currernt RGB value
  68. void setCurRgb ( F32 curRIn, F32 curGIn, F32 curBIn );
  69. void getCurRgb ( F32& curROut, F32& curGOut, F32& curBOut );
  70. F32 getCurR () { return curR; };
  71. F32 getCurG () { return curG; };
  72. F32 getCurB () { return curB; };
  73. // mutator / accessors for currernt HSL value
  74. void setCurHsl ( F32 curHIn, F32 curSIn, F32 curLIn );
  75. void getCurHsl ( F32& curHOut, F32& curSOut, F32& curLOut );
  76. F32 getCurH () { return curH; };
  77. F32 getCurS () { return curS; };
  78. F32 getCurL () { return curL; };
  79. // updates current RGB/HSL values based on point in picker
  80. BOOL updateRgbHslFromPoint ( S32 xPosIn, S32 yPosIn );
  81. // updates text entry fields with current RGB/HSL
  82. void updateTextEntry ();
  83. void stopUsingPipette();
  84. // mutator / accessor for mouse button pressed in region
  85. void setMouseDownInHueRegion ( BOOL mouse_down_in_region );
  86. BOOL getMouseDownInHueRegion () { return mMouseDownInHueRegion; };
  87. void setMouseDownInLumRegion ( BOOL mouse_down_in_region );
  88. BOOL getMouseDownInLumRegion () { return mMouseDownInLumRegion; };
  89. void setMouseDownInSwatch (BOOL mouse_down_in_swatch);
  90. BOOL getMouseDownInSwatch () { return mMouseDownInSwatch; }
  91. // called when text entries (RGB/HSL etc.) are changed by user
  92. void onTextEntryChanged ( LLUICtrl* ctrl );
  93. // convert RGB to HSL and vice-versa
  94. void hslToRgb ( F32 hValIn, F32 sValIn, F32 lValIn, F32& rValOut, F32& gValOut, F32& bValOut );
  95. F32 hueToRgb ( F32 val1In, F32 val2In, F32 valHUeIn );
  96. void setActive(BOOL active);
  97. protected:
  98. // callbacks
  99. static void onClickCancel ( void* data );
  100. static void onClickSelect ( void* data );
  101. void onClickPipette ( );
  102. static void onTextCommit ( LLUICtrl* ctrl, void* data );
  103. static void onImmediateCheck ( LLUICtrl* ctrl, void* data );
  104. void onColorSelect( const LLTextureEntry& te );
  105. private:
  106. // draws color selection palette
  107. void drawPalette ();
  108. // find a complimentary color to the one passed in that can be used to highlight
  109. const LLColor4& getComplimentaryColor ( const LLColor4& backgroundColor );
  110. // original RGB values
  111. F32 origR, origG, origB;
  112. // current RGB/HSL values
  113. F32 curR, curG, curB;
  114. F32 curH, curS, curL;
  115. const S32 mComponents;
  116. BOOL mMouseDownInLumRegion;
  117. BOOL mMouseDownInHueRegion;
  118. BOOL mMouseDownInSwatch;
  119. const S32 mRGBViewerImageLeft;
  120. const S32 mRGBViewerImageTop;
  121. const S32 mRGBViewerImageWidth;
  122. const S32 mRGBViewerImageHeight;
  123. const S32 mLumRegionLeft;
  124. const S32 mLumRegionTop;
  125. const S32 mLumRegionWidth;
  126. const S32 mLumRegionHeight;
  127. const S32 mLumMarkerSize;
  128. // Preview of the current color.
  129. const S32 mSwatchRegionLeft;
  130. const S32 mSwatchRegionTop;
  131. const S32 mSwatchRegionWidth;
  132. const S32 mSwatchRegionHeight;
  133. LLView* mSwatchView;
  134. const S32 numPaletteColumns;
  135. const S32 numPaletteRows;
  136. std::vector < LLColor4* > mPalette;
  137. S32 highlightEntry;
  138. const S32 mPaletteRegionLeft;
  139. const S32 mPaletteRegionTop;
  140. const S32 mPaletteRegionWidth;
  141. const S32 mPaletteRegionHeight;
  142. // image used to compose color grid
  143. LLPointer<LLViewerTexture> mRGBImage;
  144. // current swatch in use
  145. LLColorSwatchCtrl* mSwatch;
  146. // are we actively tied to some output?
  147. BOOL mActive;
  148. // enable/disable immediate updates
  149. LLCheckBoxCtrl* mApplyImmediateCheck;
  150. BOOL mCanApplyImmediately;
  151. LLButton* mSelectBtn;
  152. LLButton* mCancelBtn;
  153. LLButton* mPipetteBtn;
  154. F32 mContextConeOpacity;
  155. };
  156. #endif // LL_LLFLOATERCOLORPICKER_H