llfloatercolorpicker.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /**
  2. * @file llfloatercolorpicker.h
  3. * @brief Generic system color picker
  4. *
  5. * $LicenseInfo:firstyear=2004&license=viewergpl$
  6. *
  7. * Copyright(c) 2004-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. *("GPL"), unless you have obtained a separate licensing agreement
  13. *("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLFLOATERCOLORPICKER_H
  33. #define LL_LLFLOATERCOLORPICKER_H
  34. #include <vector>
  35. #include "llfloater.h"
  36. #include "llpointer.h"
  37. #include "llspinctrl.h"
  38. #include "lltextureentry.h"
  39. #include "llcolorswatch.h"
  40. class LLButton;
  41. class LLCheckBoxCtrl;
  42. class LLFloaterColorPicker final : public LLFloater
  43. {
  44. protected:
  45. LOG_CLASS(LLFloaterColorPicker);
  46. public:
  47. LLFloaterColorPicker(LLColorSwatchCtrl* swatch,
  48. bool show_apply_immediately = false);
  49. ~LLFloaterColorPicker() override;
  50. void initUI(F32 r, F32 g, F32 b);
  51. void showUI();
  52. void cancelSelection();
  53. // Mutator for original RGB value
  54. LL_INLINE void setOrigRgb(F32 r, F32 g, F32 b)
  55. {
  56. mOrigR = r;
  57. mOrigG = g;
  58. mOrigB = b;
  59. }
  60. // Mutator for current RGB value (also syncs HSL values)
  61. void setCurRgb(F32 r, F32 g, F32 b);
  62. // Mutator for current HSL value (also syncs RGB values)
  63. void setCurHsl(F32 h, F32 s, F32 l);
  64. // Accessors for current RGB value
  65. LL_INLINE F32 getCurR() { return mCurR; }
  66. LL_INLINE F32 getCurG() { return mCurG; }
  67. LL_INLINE F32 getCurB() { return mCurB; }
  68. void setActive(bool active);
  69. protected:
  70. bool postBuild() override;
  71. void draw() override;
  72. bool handleMouseDown(S32 x, S32 y, MASK mask) override;
  73. bool handleMouseUp(S32 x, S32 y, MASK mask) override;
  74. bool handleHover(S32 x, S32 y, MASK mask) override;
  75. void onMouseCaptureLost() override;
  76. void onClose(bool app_quitting) override;
  77. void stopUsingPipette();
  78. // Mutators for mouse buttons pressed in region
  79. void setMouseDownInHueRegion(bool mouse_down_in_region);
  80. void setMouseDownInLumRegion(bool mouse_down_in_region);
  81. void setMouseDownInSwatch(bool mouse_down_in_swatch);
  82. // Updates current RGB/HSL values based on point in picker
  83. bool updateRgbHslFromPoint(S32 x, S32 y);
  84. // Called when text entries (RGB/HSL etc) are changed by user
  85. void onTextEntryChanged(LLUICtrl* ctrl);
  86. // Updates text entry fields with current RGB/HSL
  87. void updateTextEntry();
  88. // Converts RGB to HSL and vice-versa
  89. void hslToRgb(F32 h, F32 s, F32 l, F32& r, F32& g, F32& b);
  90. F32 hueToRgb(F32 h1, F32 h2, F32 h3);
  91. // Callbacks
  92. static void onClickCancel(void* data);
  93. static void onClickSelect(void* data);
  94. static void onClickPipette(void* data);
  95. static void onTextCommit(LLUICtrl* ctrl, void* data);
  96. static void onImmediateCheck(LLUICtrl* ctrl, void* data);
  97. static void onColorSelect(const LLTextureEntry& te, void *data);
  98. private:
  99. // Turns on or off text entry commit call backs
  100. void enableTextCallbacks(bool stateIn);
  101. // Draws color selection palette
  102. void drawPalette();
  103. // Finds a complementary color to the one passed in that can be used to
  104. // highlight
  105. const LLColor4& getComplementaryColor(const LLColor4& bg_col);
  106. private:
  107. LLButton* mSelectBtn;
  108. LLButton* mCancelBtn;
  109. LLButton* mPipetteBtn;
  110. LLCheckBoxCtrl* mApplyImmediateCheck;
  111. // Current swatch in use
  112. LLColorSwatchCtrl* mSwatch;
  113. // Image used to compose color grid
  114. LLPointer<LLViewerTexture> mRGBImage;
  115. std::vector<LLColor4> mPalette;
  116. // Original RGB values
  117. F32 mOrigR;
  118. F32 mOrigG;
  119. F32 mOrigB;
  120. // Current RGB values
  121. F32 mCurR;
  122. F32 mCurG;
  123. F32 mCurB;
  124. // Current HSL values
  125. F32 mCurH;
  126. F32 mCurS;
  127. F32 mCurL;
  128. F32 mContextConeOpacity;
  129. S32 mHighlightEntry;
  130. const S32 mComponents;
  131. const S32 mRGBViewerImageLeft;
  132. const S32 mRGBViewerImageTop;
  133. const S32 mRGBViewerImageWidth;
  134. const S32 mRGBViewerImageHeight;
  135. const S32 mLumRegionLeft;
  136. const S32 mLumRegionTop;
  137. const S32 mLumRegionWidth;
  138. const S32 mLumRegionHeight;
  139. const S32 mLumMarkerSize;
  140. // Preview of the current color.
  141. const S32 mSwatchRegionLeft;
  142. const S32 mSwatchRegionTop;
  143. const S32 mSwatchRegionWidth;
  144. const S32 mSwatchRegionHeight;
  145. const S32 mPaletteCols;
  146. const S32 mPaletteRows;
  147. const S32 mPaletteRegionLeft;
  148. const S32 mPaletteRegionTop;
  149. const S32 mPaletteRegionWidth;
  150. const S32 mPaletteRegionHeight;
  151. // Are we actively tied to some output ?
  152. bool mActive;
  153. // Set to true when we have been cancelled (used to avoid cancel callbacks
  154. // recursions). HB
  155. bool mCancelled;
  156. // Enable/disable immediate updates
  157. bool mCanApplyImmediately;
  158. bool mMouseDownInLumRegion;
  159. bool mMouseDownInHueRegion;
  160. bool mMouseDownInSwatch;
  161. };
  162. #endif // LL_LLFLOATERCOLORPICKER_H