guiColorPicker.h
Engine/source/gui/controls/guiColorPicker.h
Classes:
Public Typedefs
GuiColorPickMode
Public Functions
Detailed Description
Public Typedefs
typedef GuiColorPickerCtrl::PickMode GuiColorPickMode
Public Functions
DefineEnumType(GuiColorPickMode )
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23#ifndef _GUICOLORPICKER_H_ 24#define _GUICOLORPICKER_H_ 25 26#ifndef _GUICONTROL_H_ 27#include "gui/core/guiControl.h" 28#endif 29 30//---------------------------- 31/// GuiColorPickerCtrl 32/// 33/// This control draws a box containing a color specified by mPickColor, 34/// in a way according to one of the PickMode enum's, stored as mDisplayMode. 35/// 36/// The color the box represents is stored as mBaseColour (for pPallete, pBlendColorRange), 37/// whilst the color chosen by the box is stored as mPickColor. 38/// 39/// Whenever the control is clicked, it will do one of many things : 40/// 41/// -# If its in pPallete mode, execute the regular "command" 42/// -# If its in pBlendColorRange mode, update the selector position. The position will be re-read upon the next render. In addition, a cross will be drawn where the color has been selected from. As with 1, "command" will be executed. 43/// -# If its in pHorizColorRange or pVertColorRange mode, it will function in a similar manner to 2, but the selector will resemble a horizontal or vertical bar. 44/// -# If its in pHorizAlphaRange or pVertAlphaRange mode, it will also function the same way as 3 45/// -# If its in pDropperBackground mode, nothing will happen 46/// 47/// Colours are drawn in different ways according to mDisplayMode: 48/// 49/// -# With pPallete, a box with a blank color, mBaseColor is drawn. 50/// -# With pHorizColorRange, a horizontal box with colors blending in the range, mColorRange. 51/// -# With pVertColorRange, a vertical box with colors blending in the range, mColorRange. 52/// -# With pBlendColorRange, a box, the bottom colors being black, but the top left being white, and the top right being mBaseColor. 53/// -# With pHorizAlphaRange, a horizontal box with black blending with an alpha from 0 to 255 54/// -# With pVertAlphaRange, a vertical box with black blending with an apha from 0 to 255 55/// -# With pDropperBackground, nothing is drawn 56class GuiColorPickerCtrl : public GuiControl 57{ 58 typedef GuiControl Parent; 59 60 public: 61 enum PickMode 62 { 63 pPallet = 0, ///< We just have a solid color; We just act like a pallet 64 pHorizColorRange, ///< We have a range of base colors going horizontally 65 pVertColorRange, ///< We have a range of base colors going vertically 66 pHorizColorBrightnessRange, ///< HorizColorRange with brightness 67 pVertColorBrightnessRange, ///< VertColorRange with brightness 68 pBlendColorRange, ///< We have a box which shows a range in brightness of the color 69 pHorizAlphaRange, ///< We have a box which shows a range in alpha going horizontally 70 pVertAlphaRange, ///< We have a box which shows a range in alpha going vertically 71 pDropperBackground ///< The control does not draw anything; Only does something when you click, or move the mouse (when active) 72 }; 73 74 enum SelectorMode 75 { 76 sHorizontal = 0, ///< Horizontal selector with small gap 77 sVertical, ///< Vertical selector with small gap 78 }; 79 80 protected: 81 /// @name Core Rendering functions 82 /// @{ 83 void renderColorBox(RectI &bounds); ///< Function that draws the actual color box 84 void drawSelector(RectI &bounds, Point2I &selectorPos, SelectorMode mode); /// < Function that draws the selection indicator 85 void drawBlendBox(RectI &bounds, LinearColorF &c1, LinearColorF &c2, LinearColorF &c3, LinearColorF &c4); 86 void drawBlendRangeBox(RectI &bounds, bool vertical, U8 numColors, ColorI *colors); 87 /// @} 88 89 /// @name Core Variables 90 /// @{ 91 LinearColorF mPickColor; ///< Color that has been picked from control 92 LinearColorF mBaseColor; ///< Colour we display (in case of pallet and blend mode) 93 PickMode mDisplayMode; ///< Current color display mode of the selector 94 95 Point2I mSelectorPos; ///< Current position of the selector 96 bool mPositionChanged; ///< Current position has changed since last render? 97 bool mMouseOver; ///< Mouse is over? 98 bool mMouseDown; ///< Mouse button down? 99 bool mActionOnMove; ///< Perform onAction() when position has changed? 100 101 bool mSelectColor; 102 LinearColorF mSetColor; 103 GBitmap* mBitmap; 104 105 Point2I findColor(const LinearColorF & color, const Point2I& offset, const Point2I& resolution, GBitmap& bmp); 106 107 S32 mSelectorGap; ///< The half-way "gap" between the selector pos and where the selector is allowed to draw. 108 109 GFXStateBlockRef mStateBlock; 110 111 static ColorI mColorRange[7]; ///< Color range for pHorizColorRange and pVertColorRange 112 /// @} 113 114 public: 115 116 DECLARE_CONOBJECT(GuiColorPickerCtrl); 117 DECLARE_CATEGORY( "Gui Editor" ); 118 119 GuiColorPickerCtrl(); 120 ~GuiColorPickerCtrl(); 121 122 static void initPersistFields(); 123 void onRender(Point2I offset, const RectI &updateRect); 124 bool mShowReticle; ///< Show reticle on render 125 /// @name Color Value Functions 126 /// @{ 127 /// NOTE: setValue only sets baseColor, since setting pickColor wouldn't be useful 128 void setValue(LinearColorF &value) {mBaseColor = value;} 129 /// NOTE: getValue() returns baseColor if pallet (since pallet controls can't "pick" colours themselves) 130 LinearColorF getValue() { return mDisplayMode == pPallet ? mBaseColor : mPickColor; } 131 const char *getScriptValue(); 132 void setScriptValue(const char *value); 133 void updateColor() {mPositionChanged = true;} 134 /// @} 135 136 /// @name Selector Functions 137 /// @{ 138 void setSelectorPos(const Point2I &pos); ///< Set new pos (in local coords) 139 void setSelectorPos(const LinearColorF & color); 140 Point2I getSelectorPos() {return mSelectorPos;} 141 /// @} 142 143 /// @name Input Events 144 /// @{ 145 void onMouseDown(const GuiEvent &); 146 void onMouseUp(const GuiEvent &); 147 void onMouseMove(const GuiEvent &event); 148 void onMouseDragged(const GuiEvent &event); 149 150 void onMouseEnter(const GuiEvent &); 151 void onMouseLeave(const GuiEvent &); 152 /// @} 153}; 154 155typedef GuiColorPickerCtrl::PickMode GuiColorPickMode; 156DefineEnumType( GuiColorPickMode ); 157 158#endif 159