Crazy Eddie's GUI System  0.8.4
Thumb.h
00001 /***********************************************************************
00002         created:        25/4/2004
00003         author:         Paul D Turner
00004         
00005         purpose:        Interface for a 'Thumb' widget.  Intended to be used as
00006                                 part of other widgets such as scrollers and sliders.
00007 *************************************************************************/
00008 /***************************************************************************
00009  *   Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
00010  *
00011  *   Permission is hereby granted, free of charge, to any person obtaining
00012  *   a copy of this software and associated documentation files (the
00013  *   "Software"), to deal in the Software without restriction, including
00014  *   without limitation the rights to use, copy, modify, merge, publish,
00015  *   distribute, sublicense, and/or sell copies of the Software, and to
00016  *   permit persons to whom the Software is furnished to do so, subject to
00017  *   the following conditions:
00018  *
00019  *   The above copyright notice and this permission notice shall be
00020  *   included in all copies or substantial portions of the Software.
00021  *
00022  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00023  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00024  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00025  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
00026  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00027  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00028  *   OTHER DEALINGS IN THE SOFTWARE.
00029  ***************************************************************************/
00030 #ifndef _CEGUIThumb_h_
00031 #define _CEGUIThumb_h_
00032 
00033 #include "./PushButton.h"
00034 #include <utility>
00035 
00036 
00037 #if defined(_MSC_VER)
00038 #       pragma warning(push)
00039 #       pragma warning(disable : 4251)
00040 #       pragma warning(disable : 4996)
00041 #endif
00042 
00043 
00044 // Start of CEGUI namespace section
00045 namespace CEGUI
00046 {
00047 
00055 class CEGUIEXPORT Thumb : public PushButton
00056 {
00057 public:
00058         static const String EventNamespace;                             
00059     static const String WidgetTypeName;             
00060 
00061         /*************************************************************************
00062                 Event name constants
00063         *************************************************************************/
00064         // generated internally by Window
00070         static const String EventThumbPositionChanged;
00076         static const String EventThumbTrackStarted;
00081         static const String EventThumbTrackEnded;
00082 
00083 
00084         /*************************************************************************
00085                 Accessor Functions
00086         *************************************************************************/ 
00094         bool    isHotTracked(void) const                        {return d_hotTrack;}
00095 
00104         bool    isVertFree(void) const                          {return d_vertFree;}
00105 
00114         bool    isHorzFree(void) const                          {return d_horzFree;}
00115 
00116 
00125         std::pair<float, float> getVertRange(void) const;
00126 
00127 
00136         std::pair<float, float> getHorzRange(void) const;
00137 
00138 
00139         /*************************************************************************
00140                 Manipulator Functions
00141         *************************************************************************/
00152         void    setHotTracked(bool setting)                             {d_hotTrack = setting;}
00153 
00154 
00165         void    setVertFree(bool setting)                                               {d_vertFree = setting;}
00166 
00167 
00178         void    setHorzFree(bool setting)                                               {d_horzFree = setting;}
00179         
00180 
00197         void    setVertRange(float min, float max);
00198 
00212         void    setVertRange(const std::pair<float, float> &range);
00213 
00214 
00231         void    setHorzRange(float min, float max);
00245         void    setHorzRange(const std::pair<float, float> &range);
00246 
00247 
00248         /*************************************************************************
00249                 Construction / Destruction
00250         *************************************************************************/
00255         Thumb(const String& type, const String& name);
00256 
00257 
00262         virtual ~Thumb(void);
00263 
00264 
00265 protected:
00266     // overridden from base class
00267     void banPropertiesForAutoWindow();
00268 
00269         /*************************************************************************
00270                 New Thumb Events
00271         *************************************************************************/
00276         virtual void    onThumbPositionChanged(WindowEventArgs& e);
00277 
00278 
00283         virtual void    onThumbTrackStarted(WindowEventArgs& e);
00284 
00285 
00290         virtual void    onThumbTrackEnded(WindowEventArgs& e);
00291 
00292 
00293 
00294         /*************************************************************************
00295                 Overridden event handling routines
00296         *************************************************************************/
00297         virtual void    onMouseMove(MouseEventArgs& e);
00298         virtual void    onMouseButtonDown(MouseEventArgs& e);
00299         virtual void    onCaptureLost(WindowEventArgs& e);
00300 
00301 
00302         /*************************************************************************
00303                 Implementation Data
00304         *************************************************************************/
00305         // general settings
00306         bool    d_hotTrack;                                     
00307         bool    d_vertFree;                                     
00308         bool    d_horzFree;                                     
00309 
00310         // operational limits
00311         float   d_vertMin, d_vertMax;           
00312         float   d_horzMin, d_horzMax;           
00313 
00314         // internal state
00315         bool    d_beingDragged;                         
00316         Vector2f d_dragPoint;                           
00317 
00318 
00319 private:
00320         /*************************************************************************
00321                 Private methods
00322         *************************************************************************/
00323         void    addThumbProperties(void);
00324 };
00325 
00326 /*
00327 TODO: This is horrible, PropertyHelper for std::pair<float, float> would be fine but enforcing min: %f max: %f is just horrible
00328 */
00329 template<>
00330 class PropertyHelper<std::pair<float,float> >
00331 {
00332 public:
00333     typedef std::pair<float,float> return_type;
00334     typedef return_type safe_method_return_type;
00335     typedef const std::pair<float,float>& pass_type;
00336     typedef String string_return_type;
00337 
00338     static const String& getDataTypeName()
00339     {
00340         static String type("std::pair<float,float>");
00341 
00342         return type;
00343     }
00344 
00345     static return_type fromString(const String& str)
00346     {
00347         float rangeMin = 0, rangeMax = 0;
00348         sscanf(str.c_str(), " min:%f max:%f", &rangeMin, &rangeMax);
00349         return std::pair<float,float>(rangeMin,rangeMax);
00350     }
00351 
00352     static string_return_type toString(pass_type val)
00353     {
00354         char buff[64];
00355         sprintf(buff, "min:%f max:%f", val.first, val.second);
00356         return buff;
00357     }
00358 };
00359 
00360 } // End of  CEGUI namespace section
00361 
00362 #if defined(_MSC_VER)
00363 #       pragma warning(pop)
00364 #endif
00365 
00366 #endif  // end of guard _CEGUIThumb_h_
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends