Torque3D Documentation / _generateds / guiGradientCtrl.h

guiGradientCtrl.h

Engine/source/gui/controls/guiGradientCtrl.h

More...

Classes:

Public Typedefs

GuiGradientPickMode 

Detailed Description

Public Typedefs

typedef GuiGradientCtrl::PickMode GuiGradientPickMode 

Public Functions

DefineEnumType(GuiGradientPickMode )

  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 _GUIGRADIENTCTRL_H_
 24#define _GUIGRADIENTCTRL_H_
 25
 26#ifndef _GUICONTROL_H_
 27#include "gui/core/guiControl.h"
 28#endif
 29
 30#ifndef _GUISWATCHBUTTONCTRL_H_
 31#include "gui/buttons/guiSwatchButtonCtrl.h"
 32#endif
 33
 34class GuiGradientSwatchCtrl : public GuiSwatchButtonCtrl
 35{
 36private:    
 37   typedef GuiSwatchButtonCtrl Parent;
 38private:
 39   Point2I mMouseDownPosition;
 40   RectI mOrigBounds;
 41public:
 42   DECLARE_CONOBJECT(GuiGradientSwatchCtrl);
 43   DECLARE_CALLBACK( void, onMouseDown, ());
 44   DECLARE_CALLBACK( void, onDoubleClick, ());
 45   GuiGradientSwatchCtrl();
 46   void onMouseDown(const GuiEvent &);
 47   void onRightMouseDown(const GuiEvent &);
 48   void onMouseDragged(const GuiEvent &event);
 49   void onRender(Point2I offset, const RectI &updateRect);
 50   bool onWake();
 51protected:
 52   StringTableEntry  mColorFunction;
 53};
 54//----------------------------
 55/// GuiGradientCtrl
 56
 57class GuiGradientCtrl : public GuiControl
 58{
 59   typedef GuiControl Parent;
 60   
 61public:
 62   enum PickMode
 63   {
 64      pHorizColorRange,    ///< We have a range of base colors going horizontally
 65      pHorizAlphaRange,    ///< We have a box which shows a range in alpha going horizontally
 66   };
 67   
 68   enum SelectorMode
 69   {
 70      sHorizontal = 0,     ///< Horizontal selector with small gap
 71      sVertical,        ///< Vertical selector with small gap
 72   };
 73   
 74   struct ColorRange
 75   {
 76      GuiGradientSwatchCtrl* swatch;
 77      S32 pos;
 78      LinearColorF color;
 79   };
 80
 81   Vector<ColorRange> mColorRange;
 82   Vector<ColorRange> mAlphaRange;
 83   S32 mSwatchFactor;
 84   RectI mBlendRangeBox;
 85
 86private:
 87   
 88   /// @name Core Rendering functions
 89   /// @{
 90   void renderColorBox(RectI &bounds);       ///< Function that draws the actual color box
 91   //void drawSelector(RectI &bounds, Point2I &selectorPos, SelectorMode mode);  ///< Function that draws the selection indicator
 92   void drawBlendRangeBox(RectI &bounds, bool vertical, Vector<ColorRange> colorRange);
 93   /// @}
 94
 95   /// @name Core Variables
 96   /// @{
 97   LinearColorF mPickColor;      ///< Color that has been picked from control
 98   LinearColorF mBaseColor;      ///< Colour we display (in case of pallet and blend mode)
 99   PickMode mDisplayMode;  ///< Current color display mode of the selector
100   PickMode mSaveDisplayMode;
101
102   bool mPositionChanged;  ///< Current position has changed since last render?
103   bool mMouseOver;     ///< Mouse is over?
104   bool mMouseDown;     ///< Mouse button down?
105   bool mActionOnMove;     ///< Perform onAction() when position has changed?
106
107   GFXStateBlockRef mStateBlock;
108   
109   LinearColorF colorWhite;
110   LinearColorF colorWhiteBlend;
111   LinearColorF colorBlack;
112   LinearColorF colorAlpha;
113   LinearColorF colorAlphaW;
114   /// @}
115   String mColorFunction;
116   
117public:   
118   
119   DECLARE_CONOBJECT(GuiGradientCtrl);
120   DECLARE_CATEGORY( "Gui Editor" );
121   
122   GuiGradientCtrl();
123
124   static void initPersistFields();
125   void onRender(Point2I offset, const RectI &updateRect);
126   bool mShowReticle;       ///< Show reticle on render
127   /// @name Color Value Functions
128   /// @{
129   /// NOTE: setValue only sets baseColor, since setting pickColor wouldn't be useful
130   void setValue(LinearColorF &value) {mBaseColor = value;}
131   /// NOTE: getValue() returns baseColor if pallet (since pallet controls can't "pick" colours themselves)
132   LinearColorF getValue() {return mPickColor;}
133   void updateColor() {mPositionChanged = true;}
134   /// @}
135   
136   /// @name Input Events
137   /// @{
138   void onMouseDown(const GuiEvent &);
139   void onMouseUp(const GuiEvent &);
140
141   void onMouseEnter(const GuiEvent &);
142   void onMouseLeave(const GuiEvent &);
143   /// @}
144
145   void addColorRange(ColorI color);
146   void setupDefaultRange();
147
148   bool onAdd();
149   void inspectPreApply();
150   void inspectPostApply();
151   void reInitSwatches( GuiGradientCtrl::PickMode );
152   void addColorRange(Point2I pos, const LinearColorF& color);
153   void removeColorRange( GuiGradientSwatchCtrl* swatch );
154   void sortColorRange();
155
156   PickMode getDisplayMode() { return mDisplayMode; }
157};
158
159typedef GuiGradientCtrl::PickMode GuiGradientPickMode;
160DefineEnumType( GuiGradientPickMode );
161
162#endif
163