Torque3D Documentation / _generateds / guiBitmapButtonCtrl.h

guiBitmapButtonCtrl.h

Engine/source/gui/buttons/guiBitmapButtonCtrl.h

More...

Classes:

class

A button control that uses bitmaps as its different button states.

class

Extension of GuiBitmapButtonCtrl that also display a text label on the button.

Public Typedefs

Public Functions

Detailed Description

Public Typedefs

typedef GuiBitmapButtonCtrl::BitmapMode GuiBitmapMode 

Public Functions

DefineEnumType(GuiBitmapMode )

  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 _GUIBITMAPBUTTON_H_
 25#define _GUIBITMAPBUTTON_H_
 26
 27#ifndef _GUIBUTTONCTRL_H_
 28   #include "gui/buttons/guiButtonCtrl.h"
 29#endif
 30#ifndef _GFXTEXTUREMANAGER_H_
 31   #include "gfx/gfxTextureManager.h"
 32#endif
 33
 34
 35/// A button control that uses bitmaps as its different button states.
 36///
 37/// Set 'bitmap' console field to base name of bitmaps to use.  This control will
 38///
 39/// append '_n' for normal
 40/// append '_h' for highlighted
 41/// append '_d' for depressed
 42/// append '_i' for inactive
 43///
 44/// If a bitmap cannot be found it will use the default bitmap to render.
 45///
 46/// Additionally, a bitmap button can be made to react to keyboard modifiers.  These can be
 47/// either CTRL/CMD, ALT, or SHIFT (but no combination of them.)  To assign a different bitmap
 48/// for a modifier state, prepend "_ctrl", _"alt", or "_shift" to the state postfix.
 49///
 50/// To implement different handlers for the modifier states, use the "onDefaultClick",
 51/// "onCtrlClick", "onAltClick", and "onShiftClick" methods.
 52///
 53class GuiBitmapButtonCtrl : public GuiButtonCtrl
 54{
 55   public:
 56   
 57      typedef GuiButtonCtrl Parent;
 58      
 59      enum BitmapMode
 60      {
 61         BitmapStretched,
 62         BitmapCentered,
 63      };
 64
 65   protected:
 66   
 67      enum Modifier
 68      {
 69         ModifierNone,
 70         ModifierCtrl,
 71         ModifierAlt,
 72         ModifierShift,
 73         
 74         NumModifiers
 75      };
 76   
 77      enum State
 78      {
 79         NORMAL,
 80         HILIGHT,
 81         DEPRESSED,
 82         INACTIVE
 83      };
 84      
 85      struct Textures
 86      {
 87         /// Texture for normal state.
 88         GFXTexHandle mTextureNormal;
 89         
 90         /// Texture for highlight state.
 91         GFXTexHandle mTextureHilight;
 92         
 93         /// Texture for depressed state.
 94         GFXTexHandle mTextureDepressed;
 95         
 96         /// Texture for inactive state.
 97         GFXTexHandle mTextureInactive;
 98      };
 99
100      /// Make control extents equal to bitmap size.
101      bool mAutoFitExtents;
102      
103      /// Allow switching out images according to modifier presses.
104      bool mUseModifiers;
105      
106      /// Allow switching images according to mouse states.  On by default.
107      /// Switch off when not needed as it otherwise results in a lot of costly
108      /// texture loads.
109      bool mUseStates;
110      
111      ///
112      BitmapMode mBitmapMode;
113
114      /// File name for bitmap.
115      String mBitmapName;
116      
117      /// alpha masking
118      bool mMasked;
119      
120      ///
121      Textures mTextures[ NumModifiers ];
122      
123      virtual void renderButton( GFXTexHandle &texture, const Point2I& offset, const RectI& updateRect );
124      
125      static bool _setAutoFitExtents( void *object, const char *index, const char *data );
126      static bool _setBitmap( void *object, const char *index, const char *data );
127      
128      State getState() const
129      {
130         if( mActive )
131         {
132            if( mDepressed || mStateOn ) return DEPRESSED;
133            if( mMouseOver ) return HILIGHT;
134            return NORMAL;
135         }
136         else
137            return INACTIVE;
138      }
139      
140      Modifier getCurrentModifier();
141      GFXTexHandle& getTextureForCurrentState();
142      
143      /// @name Callbacks
144      /// @{
145      
146      DECLARE_CALLBACK( void, onDefaultClick, () );
147      DECLARE_CALLBACK( void, onCtrlClick, () );
148      DECLARE_CALLBACK( void, onAltClick, () );
149      DECLARE_CALLBACK( void, onShiftClick, () );
150      
151      /// @}
152
153   public:
154                           
155      GuiBitmapButtonCtrl();
156
157      void setAutoFitExtents( bool state );
158      void setBitmap( const String& name );
159      void setBitmapHandles( GFXTexHandle normal, GFXTexHandle highlighted, GFXTexHandle depressed, GFXTexHandle inactive );
160
161      //Parent methods
162      virtual bool onWake();
163      virtual void onSleep();
164      virtual void onAction();
165      virtual void inspectPostApply();
166
167      virtual void onRender(Point2I offset, const RectI &updateRect);
168
169      static void initPersistFields();
170      bool pointInControl(const Point2I& parentCoordPoint);
171
172      DECLARE_CONOBJECT(GuiBitmapButtonCtrl);
173      DECLARE_DESCRIPTION( "A button control rendered entirely from bitmaps.\n"
174                           "The individual button states are represented with separate bitmaps." );
175};
176
177typedef GuiBitmapButtonCtrl::BitmapMode GuiBitmapMode;
178DefineEnumType( GuiBitmapMode );
179
180/// Extension of GuiBitmapButtonCtrl that also display a text label on the button.
181class GuiBitmapButtonTextCtrl : public GuiBitmapButtonCtrl
182{
183   public:
184   
185      typedef GuiBitmapButtonCtrl Parent;
186      
187   protected:
188   
189      virtual void renderButton( GFXTexHandle &texture, const Point2I& offset, const RectI& updateRect );
190
191   public:
192
193      DECLARE_CONOBJECT( GuiBitmapButtonTextCtrl );
194      DECLARE_DESCRIPTION( "An extension of GuiBitmapButtonCtrl that also renders a text\n"
195                           "label on the button." );
196};
197
198#endif //_GUI_BITMAP_BUTTON_CTRL_H
199