guiGradientCtrl.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _GUIGRADIENTCTRL_H_
  23. #define _GUIGRADIENTCTRL_H_
  24. #ifndef _GUICONTROL_H_
  25. #include "gui/core/guiControl.h"
  26. #endif
  27. #ifndef _GUISWATCHBUTTONCTRL_H_
  28. #include "gui/buttons/guiSwatchButtonCtrl.h"
  29. #endif
  30. class GuiGradientSwatchCtrl : public GuiSwatchButtonCtrl
  31. {
  32. private:
  33. typedef GuiSwatchButtonCtrl Parent;
  34. private:
  35. Point2I mMouseDownPosition;
  36. RectI mOrigBounds;
  37. public:
  38. DECLARE_CONOBJECT(GuiGradientSwatchCtrl);
  39. DECLARE_CALLBACK( void, onMouseDown, ());
  40. DECLARE_CALLBACK( void, onDoubleClick, ());
  41. GuiGradientSwatchCtrl();
  42. void onMouseDown(const GuiEvent &);
  43. void onRightMouseDown(const GuiEvent &);
  44. void onMouseDragged(const GuiEvent &event);
  45. void onRender(Point2I offset, const RectI &updateRect);
  46. bool onWake();
  47. protected:
  48. StringTableEntry mColorFunction;
  49. };
  50. //----------------------------
  51. /// GuiGradientCtrl
  52. class GuiGradientCtrl : public GuiControl
  53. {
  54. typedef GuiControl Parent;
  55. public:
  56. enum PickMode
  57. {
  58. pHorizColorRange, ///< We have a range of base colors going horizontally
  59. pHorizAlphaRange, ///< We have a box which shows a range in alpha going horizontally
  60. };
  61. enum SelectorMode
  62. {
  63. sHorizontal = 0, ///< Horizontal selector with small gap
  64. sVertical, ///< Vertical selector with small gap
  65. };
  66. struct ColorRange
  67. {
  68. GuiGradientSwatchCtrl* swatch;
  69. S32 pos;
  70. LinearColorF color;
  71. };
  72. Vector<ColorRange> mColorRange;
  73. Vector<ColorRange> mAlphaRange;
  74. S32 mSwatchFactor;
  75. RectI mBlendRangeBox;
  76. private:
  77. /// @name Core Rendering functions
  78. /// @{
  79. void renderColorBox(RectI &bounds); ///< Function that draws the actual color box
  80. //void drawSelector(RectI &bounds, Point2I &selectorPos, SelectorMode mode); ///< Function that draws the selection indicator
  81. void drawBlendRangeBox(RectI &bounds, bool vertical, Vector<ColorRange> colorRange);
  82. /// @}
  83. /// @name Core Variables
  84. /// @{
  85. LinearColorF mPickColor; ///< Color that has been picked from control
  86. LinearColorF mBaseColor; ///< Colour we display (in case of pallet and blend mode)
  87. PickMode mDisplayMode; ///< Current color display mode of the selector
  88. PickMode mSaveDisplayMode;
  89. bool mPositionChanged; ///< Current position has changed since last render?
  90. bool mMouseOver; ///< Mouse is over?
  91. bool mMouseDown; ///< Mouse button down?
  92. bool mActionOnMove; ///< Perform onAction() when position has changed?
  93. GFXStateBlockRef mStateBlock;
  94. LinearColorF colorWhite;
  95. LinearColorF colorWhiteBlend;
  96. LinearColorF colorBlack;
  97. LinearColorF colorAlpha;
  98. LinearColorF colorAlphaW;
  99. /// @}
  100. String mColorFunction;
  101. public:
  102. DECLARE_CONOBJECT(GuiGradientCtrl);
  103. DECLARE_CATEGORY( "Gui Editor" );
  104. GuiGradientCtrl();
  105. static void initPersistFields();
  106. void onRender(Point2I offset, const RectI &updateRect);
  107. bool mShowReticle; ///< Show reticle on render
  108. /// @name Color Value Functions
  109. /// @{
  110. /// NOTE: setValue only sets baseColor, since setting pickColor wouldn't be useful
  111. void setValue(LinearColorF &value) {mBaseColor = value;}
  112. /// NOTE: getValue() returns baseColor if pallet (since pallet controls can't "pick" colours themselves)
  113. LinearColorF getValue() {return mPickColor;}
  114. void updateColor() {mPositionChanged = true;}
  115. /// @}
  116. /// @name Input Events
  117. /// @{
  118. void onMouseDown(const GuiEvent &);
  119. void onMouseUp(const GuiEvent &);
  120. void onMouseEnter(const GuiEvent &);
  121. void onMouseLeave(const GuiEvent &);
  122. /// @}
  123. void addColorRange(ColorI color);
  124. void setupDefaultRange();
  125. bool onAdd();
  126. void inspectPreApply();
  127. void inspectPostApply();
  128. void reInitSwatches( GuiGradientCtrl::PickMode );
  129. void addColorRange(Point2I pos, const LinearColorF& color);
  130. void removeColorRange( GuiGradientSwatchCtrl* swatch );
  131. void sortColorRange();
  132. PickMode getDisplayMode() { return mDisplayMode; }
  133. };
  134. typedef GuiGradientCtrl::PickMode GuiGradientPickMode;
  135. DefineEnumType( GuiGradientPickMode );
  136. #endif