123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- //-----------------------------------------------------------------------------
- // Copyright (c) 2012 GarageGames, LLC
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to
- // deal in the Software without restriction, including without limitation the
- // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- // sell copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- // IN THE SOFTWARE.
- //-----------------------------------------------------------------------------
- #ifndef _GUIGRADIENTCTRL_H_
- #define _GUIGRADIENTCTRL_H_
- #ifndef _GUICONTROL_H_
- #include "gui/core/guiControl.h"
- #endif
- #ifndef _GUISWATCHBUTTONCTRL_H_
- #include "gui/buttons/guiSwatchButtonCtrl.h"
- #endif
- class GuiGradientSwatchCtrl : public GuiSwatchButtonCtrl
- {
- private:
- typedef GuiSwatchButtonCtrl Parent;
- private:
- Point2I mMouseDownPosition;
- RectI mOrigBounds;
- public:
- DECLARE_CONOBJECT(GuiGradientSwatchCtrl);
- DECLARE_CALLBACK( void, onMouseDown, ());
- DECLARE_CALLBACK( void, onDoubleClick, ());
- GuiGradientSwatchCtrl();
- void onMouseDown(const GuiEvent &);
- void onRightMouseDown(const GuiEvent &);
- void onMouseDragged(const GuiEvent &event);
- void onRender(Point2I offset, const RectI &updateRect);
- bool onWake();
- protected:
- StringTableEntry mColorFunction;
- };
- //----------------------------
- /// GuiGradientCtrl
- class GuiGradientCtrl : public GuiControl
- {
- typedef GuiControl Parent;
-
- public:
- enum PickMode
- {
- pHorizColorRange, ///< We have a range of base colors going horizontally
- pHorizAlphaRange, ///< We have a box which shows a range in alpha going horizontally
- };
-
- enum SelectorMode
- {
- sHorizontal = 0, ///< Horizontal selector with small gap
- sVertical, ///< Vertical selector with small gap
- };
-
- struct ColorRange
- {
- GuiGradientSwatchCtrl* swatch;
- S32 pos;
- LinearColorF color;
- };
- Vector<ColorRange> mColorRange;
- Vector<ColorRange> mAlphaRange;
- S32 mSwatchFactor;
- RectI mBlendRangeBox;
- private:
-
- /// @name Core Rendering functions
- /// @{
- void renderColorBox(RectI &bounds); ///< Function that draws the actual color box
- //void drawSelector(RectI &bounds, Point2I &selectorPos, SelectorMode mode); ///< Function that draws the selection indicator
- void drawBlendRangeBox(RectI &bounds, bool vertical, Vector<ColorRange> colorRange);
- /// @}
- /// @name Core Variables
- /// @{
- LinearColorF mPickColor; ///< Color that has been picked from control
- LinearColorF mBaseColor; ///< Colour we display (in case of pallet and blend mode)
- PickMode mDisplayMode; ///< Current color display mode of the selector
- PickMode mSaveDisplayMode;
- bool mPositionChanged; ///< Current position has changed since last render?
- bool mMouseOver; ///< Mouse is over?
- bool mMouseDown; ///< Mouse button down?
- bool mActionOnMove; ///< Perform onAction() when position has changed?
- GFXStateBlockRef mStateBlock;
-
- LinearColorF colorWhite;
- LinearColorF colorWhiteBlend;
- LinearColorF colorBlack;
- LinearColorF colorAlpha;
- LinearColorF colorAlphaW;
- /// @}
- String mColorFunction;
-
- public:
-
- DECLARE_CONOBJECT(GuiGradientCtrl);
- DECLARE_CATEGORY( "Gui Editor" );
-
- GuiGradientCtrl();
- static void initPersistFields();
- void onRender(Point2I offset, const RectI &updateRect);
- bool mShowReticle; ///< Show reticle on render
- /// @name Color Value Functions
- /// @{
- /// NOTE: setValue only sets baseColor, since setting pickColor wouldn't be useful
- void setValue(LinearColorF &value) {mBaseColor = value;}
- /// NOTE: getValue() returns baseColor if pallet (since pallet controls can't "pick" colours themselves)
- LinearColorF getValue() {return mPickColor;}
- void updateColor() {mPositionChanged = true;}
- /// @}
-
- /// @name Input Events
- /// @{
- void onMouseDown(const GuiEvent &);
- void onMouseUp(const GuiEvent &);
- void onMouseEnter(const GuiEvent &);
- void onMouseLeave(const GuiEvent &);
- /// @}
- void addColorRange(ColorI color);
- void setupDefaultRange();
- bool onAdd();
- void inspectPreApply();
- void inspectPostApply();
- void reInitSwatches( GuiGradientCtrl::PickMode );
- void addColorRange(Point2I pos, const LinearColorF& color);
- void removeColorRange( GuiGradientSwatchCtrl* swatch );
- void sortColorRange();
- PickMode getDisplayMode() { return mDisplayMode; }
- };
- typedef GuiGradientCtrl::PickMode GuiGradientPickMode;
- DefineEnumType( GuiGradientPickMode );
- #endif
|