Torque3D Documentation / _generateds / guiColorPicker.h

guiColorPicker.h

Engine/source/gui/controls/guiColorPicker.h

More...

Classes:

Public Typedefs

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, ColorF &c1, ColorF &c2, ColorF &c3, ColorF &c4);
 86   void drawBlendRangeBox(RectI &bounds, bool vertical, U8 numColors, ColorI *colors);
 87   /// @}
 88
 89   /// @name Core Variables
 90   /// @{
 91   ColorF mPickColor;      ///< Color that has been picked from control
 92   ColorF mBaseColor;      ///< Colour we display (in case of pallet and blend mode)
 93   PickMode mDisplayMode;  ///< Current color display mode of the selector
 94   bool mUseSRGB;          ///< use sRGB color scale
 95   
 96   Point2I mSelectorPos;   ///< Current position of the selector
 97   bool mPositionChanged;  ///< Current position has changed since last render?
 98   bool mMouseOver;     ///< Mouse is over?
 99   bool mMouseDown;     ///< Mouse button down?
100   bool mActionOnMove;     ///< Perform onAction() when position has changed?
101
102   bool mSelectColor;
103   ColorF mSetColor;
104   GBitmap* mBitmap;
105
106   Point2I findColor(const ColorF & color, const Point2I& offset, const Point2I& resolution, GBitmap& bmp);
107   
108   S32   mSelectorGap;     ///< The half-way "gap" between the selector pos and where the selector is allowed to draw. 
109
110   GFXStateBlockRef mStateBlock;
111
112   static ColorI mColorRange[7]; ///< Color range for pHorizColorRange and pVertColorRange
113   /// @}
114
115  public:
116
117   DECLARE_CONOBJECT(GuiColorPickerCtrl);
118   DECLARE_CATEGORY( "Gui Editor" );
119   
120   GuiColorPickerCtrl();
121   ~GuiColorPickerCtrl();
122
123   static void initPersistFields();
124   void onRender(Point2I offset, const RectI &updateRect);
125   bool mShowReticle;       ///< Show reticle on render
126   /// @name Color Value Functions
127   /// @{
128   /// NOTE: setValue only sets baseColor, since setting pickColor wouldn't be useful
129   void setValue(ColorF &value) {mBaseColor = value;}
130   /// NOTE: getValue() returns baseColor if pallet (since pallet controls can't "pick" colours themselves)
131   ColorF getValue() { return mDisplayMode == pPallet ? mBaseColor : mPickColor; }
132   const char *getScriptValue();
133   void setScriptValue(const char *value);
134   void updateColor() {mPositionChanged = true;}
135   /// @}
136
137   /// @name Selector Functions
138   /// @{
139   void setSelectorPos(const Point2I &pos); ///< Set new pos (in local coords)
140   void setSelectorPos(const ColorF & color);
141   Point2I getSelectorPos() {return mSelectorPos;}
142   /// @}
143
144   /// @name Input Events
145   /// @{
146   void onMouseDown(const GuiEvent &);
147   void onMouseUp(const GuiEvent &);
148   void onMouseMove(const GuiEvent &event);
149   void onMouseDragged(const GuiEvent &event);
150
151   void onMouseEnter(const GuiEvent &);
152   void onMouseLeave(const GuiEvent &);
153   /// @}
154};
155
156typedef GuiColorPickerCtrl::PickMode GuiColorPickMode;
157DefineEnumType( GuiColorPickMode );
158
159#endif
160