Torque3D Documentation / _generateds / guiSliderCtrl.h

guiSliderCtrl.h

Engine/source/gui/controls/guiSliderCtrl.h

More...

Classes:

class

A slider control that selects out of a floating-point value range.

Detailed Description

  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
 24#ifndef _GUISLIDERCTRL_H_
 25#define _GUISLIDERCTRL_H_
 26
 27#ifndef _GUICONTROL_H_
 28#include "gui/core/guiControl.h"
 29#endif
 30
 31
 32/// A slider control that selects out of a floating-point value range.
 33class GuiSliderCtrl : public GuiControl
 34{
 35   public:
 36   
 37      typedef GuiControl Parent;
 38
 39   protected:
 40
 41      Point2F mRange;
 42      U32  mTicks;
 43      bool mSnap;
 44      F32  mValue;
 45      RectI   mThumb;
 46      Point2I mThumbSize;
 47      S32 mShiftPoint;
 48      S32 mShiftExtent;
 49      F32 mIncAmount;
 50      bool mDisplayValue;
 51      bool mDepressed;
 52      bool mMouseOver;
 53      bool mMouseDragged;
 54      bool mHasTexture;
 55
 56      enum
 57      {
 58         SliderLineLeft = 0,
 59         SliderLineCenter,
 60         SliderLineRight,
 61         SliderButtonNormal,
 62         SliderButtonHighlight,
 63         NumBitmaps
 64      };
 65         RectI *mBitmapBounds;
 66
 67      F32 _getThumbValue( const GuiEvent& event );
 68      void _updateThumb( F32 value, bool snap = true, bool onWake = false, bool doCallback = true );
 69      
 70      /// @name Callbacks
 71      /// @{
 72      
 73      DECLARE_CALLBACK( void, onMouseDragged, () );
 74      
 75      /// @}
 76      
 77      static bool _setValue( void* object, const char* index, const char* data ) { static_cast< GuiSliderCtrl* >( object )->setValue( dAtof( data ) ); return false; }
 78
 79   public:
 80         
 81      GuiSliderCtrl();
 82      
 83      bool isThumbBeingDragged() const { return mDepressed; }
 84         
 85      const Point2F& getRange() const { return mRange; }
 86
 87      // GuiControl.
 88      bool onWake();
 89
 90      void onMouseDown(const GuiEvent &event);
 91      void onMouseDragged(const GuiEvent &event);
 92      void onMouseUp(const GuiEvent &);
 93      void onMouseLeave(const GuiEvent &);
 94      void onMouseEnter(const GuiEvent &);
 95      bool onMouseWheelUp(const GuiEvent &event);
 96      bool onMouseWheelDown(const GuiEvent &event);
 97      
 98      void setActive( bool value );
 99
100      F32 getValue() const { return mValue; }
101      void setScriptValue(const char *val) { setValue(dAtof(val)); }
102      void setValue(F32 val, bool doCallback=false);
103
104      void onRender(Point2I offset, const RectI &updateRect);
105      
106      virtual bool resize( const Point2I& newSize, const Point2I& newExtent );
107      virtual void parentResized( const RectI& oldParentRect, const RectI& newParentRect );
108
109      static void initPersistFields();
110
111      DECLARE_CONOBJECT(GuiSliderCtrl);
112      DECLARE_CATEGORY( "Gui Values" );
113      DECLARE_DESCRIPTION( "A control that implements a horizontal or vertical slider to\n"
114                           "select/represent values in a certain range." )
115};
116
117#endif
118