guiGradientCtrl.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. GFXTexHandle mPointer;
  49. StringTableEntry mColorFunction;
  50. };
  51. //----------------------------
  52. /// GuiGradientCtrl
  53. class GuiGradientCtrl : public GuiControl
  54. {
  55. typedef GuiControl Parent;
  56. public:
  57. enum PickMode
  58. {
  59. pHorizColorRange, ///< We have a range of base colors going horizontally
  60. pHorizAlphaRange, ///< We have a box which shows a range in alpha going horizontally
  61. };
  62. enum SelectorMode
  63. {
  64. sHorizontal = 0, ///< Horizontal selector with small gap
  65. sVertical, ///< Vertical selector with small gap
  66. };
  67. struct ColorRange
  68. {
  69. GuiGradientSwatchCtrl* swatch;
  70. S32 pos;
  71. ColorF color;
  72. };
  73. Vector<ColorRange> mColorRange;
  74. Vector<ColorRange> mAlphaRange;
  75. S32 mSwatchFactor;
  76. RectI mBlendRangeBox;
  77. private:
  78. /// @name Core Rendering functions
  79. /// @{
  80. void renderColorBox(RectI &bounds); ///< Function that draws the actual color box
  81. //void drawSelector(RectI &bounds, Point2I &selectorPos, SelectorMode mode); ///< Function that draws the selection indicator
  82. void drawBlendRangeBox(RectI &bounds, bool vertical, Vector<ColorRange> colorRange);
  83. /// @}
  84. /// @name Core Variables
  85. /// @{
  86. ColorF mPickColor; ///< Color that has been picked from control
  87. ColorF mBaseColor; ///< Colour we display (in case of pallet and blend mode)
  88. PickMode mDisplayMode; ///< Current color display mode of the selector
  89. PickMode mSaveDisplayMode;
  90. bool mPositionChanged; ///< Current position has changed since last render?
  91. bool mMouseOver; ///< Mouse is over?
  92. bool mMouseDown; ///< Mouse button down?
  93. bool mActionOnMove; ///< Perform onAction() when position has changed?
  94. GFXStateBlockRef mStateBlock;
  95. ColorF colorWhite;
  96. ColorF colorWhiteBlend;
  97. ColorF colorBlack;
  98. ColorF colorAlpha;
  99. ColorF colorAlphaW;
  100. /// @}
  101. String mColorFunction;
  102. public:
  103. DECLARE_CONOBJECT(GuiGradientCtrl);
  104. DECLARE_CATEGORY( "Gui Editor" );
  105. GuiGradientCtrl();
  106. static void initPersistFields();
  107. void onRender(Point2I offset, const RectI &updateRect);
  108. bool mShowReticle; ///< Show reticle on render
  109. /// @name Color Value Functions
  110. /// @{
  111. /// NOTE: setValue only sets baseColor, since setting pickColor wouldn't be useful
  112. void setValue(ColorF &value) {mBaseColor = value;}
  113. /// NOTE: getValue() returns baseColor if pallet (since pallet controls can't "pick" colours themselves)
  114. ColorF getValue() {return mPickColor;}
  115. void updateColor() {mPositionChanged = true;}
  116. /// @}
  117. /// @name Input Events
  118. /// @{
  119. void onMouseDown(const GuiEvent &);
  120. void onMouseUp(const GuiEvent &);
  121. void onMouseEnter(const GuiEvent &);
  122. void onMouseLeave(const GuiEvent &);
  123. /// @}
  124. void addColorRange(ColorI color);
  125. void setupDefaultRange();
  126. bool onAdd();
  127. void inspectPreApply();
  128. void inspectPostApply();
  129. void reInitSwatches( GuiGradientCtrl::PickMode );
  130. void addColorRange( Point2I pos, ColorF color );
  131. void removeColorRange( GuiGradientSwatchCtrl* swatch );
  132. void sortColorRange();
  133. PickMode getDisplayMode() { return mDisplayMode; }
  134. };
  135. typedef GuiGradientCtrl::PickMode GuiGradientPickMode;
  136. DefineEnumType( GuiGradientPickMode );
  137. #endif