Crazy Eddie's GUI System  0.8.4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Thumb.h
1 /***********************************************************************
2  created: 25/4/2004
3  author: Paul D Turner
4 
5  purpose: Interface for a 'Thumb' widget. Intended to be used as
6  part of other widgets such as scrollers and sliders.
7 *************************************************************************/
8 /***************************************************************************
9  * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining
12  * a copy of this software and associated documentation files (the
13  * "Software"), to deal in the Software without restriction, including
14  * without limitation the rights to use, copy, modify, merge, publish,
15  * distribute, sublicense, and/or sell copies of the Software, and to
16  * permit persons to whom the Software is furnished to do so, subject to
17  * the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be
20  * included in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
26  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
27  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28  * OTHER DEALINGS IN THE SOFTWARE.
29  ***************************************************************************/
30 #ifndef _CEGUIThumb_h_
31 #define _CEGUIThumb_h_
32 
33 #include "./PushButton.h"
34 #include <utility>
35 
36 
37 #if defined(_MSC_VER)
38 # pragma warning(push)
39 # pragma warning(disable : 4251)
40 # pragma warning(disable : 4996)
41 #endif
42 
43 
44 // Start of CEGUI namespace section
45 namespace CEGUI
46 {
47 
55 class CEGUIEXPORT Thumb : public PushButton
56 {
57 public:
58  static const String EventNamespace;
59  static const String WidgetTypeName;
60 
61  /*************************************************************************
62  Event name constants
63  *************************************************************************/
64  // generated internally by Window
82 
83 
84  /*************************************************************************
85  Accessor Functions
86  *************************************************************************/
94  bool isHotTracked(void) const {return d_hotTrack;}
95 
104  bool isVertFree(void) const {return d_vertFree;}
105 
114  bool isHorzFree(void) const {return d_horzFree;}
115 
116 
125  std::pair<float, float> getVertRange(void) const;
126 
127 
136  std::pair<float, float> getHorzRange(void) const;
137 
138 
139  /*************************************************************************
140  Manipulator Functions
141  *************************************************************************/
152  void setHotTracked(bool setting) {d_hotTrack = setting;}
153 
154 
165  void setVertFree(bool setting) {d_vertFree = setting;}
166 
167 
178  void setHorzFree(bool setting) {d_horzFree = setting;}
179 
180 
197  void setVertRange(float min, float max);
198 
212  void setVertRange(const std::pair<float, float> &range);
213 
214 
231  void setHorzRange(float min, float max);
245  void setHorzRange(const std::pair<float, float> &range);
246 
247 
248  /*************************************************************************
249  Construction / Destruction
250  *************************************************************************/
255  Thumb(const String& type, const String& name);
256 
257 
262  virtual ~Thumb(void);
263 
264 
265 protected:
266  // overridden from base class
267  void banPropertiesForAutoWindow();
268 
269  /*************************************************************************
270  New Thumb Events
271  *************************************************************************/
276  virtual void onThumbPositionChanged(WindowEventArgs& e);
277 
278 
283  virtual void onThumbTrackStarted(WindowEventArgs& e);
284 
285 
290  virtual void onThumbTrackEnded(WindowEventArgs& e);
291 
292 
293 
294  /*************************************************************************
295  Overridden event handling routines
296  *************************************************************************/
297  virtual void onMouseMove(MouseEventArgs& e);
298  virtual void onMouseButtonDown(MouseEventArgs& e);
299  virtual void onCaptureLost(WindowEventArgs& e);
300 
301 
302  /*************************************************************************
303  Implementation Data
304  *************************************************************************/
305  // general settings
306  bool d_hotTrack;
307  bool d_vertFree;
308  bool d_horzFree;
309 
310  // operational limits
311  float d_vertMin, d_vertMax;
312  float d_horzMin, d_horzMax;
313 
314  // internal state
317 
318 
319 private:
320  /*************************************************************************
321  Private methods
322  *************************************************************************/
323  void addThumbProperties(void);
324 };
325 
326 /*
327 TODO: This is horrible, PropertyHelper for std::pair<float, float> would be fine but enforcing min: %f max: %f is just horrible
328 */
329 template<>
330 class PropertyHelper<std::pair<float,float> >
331 {
332 public:
333  typedef std::pair<float,float> return_type;
334  typedef return_type safe_method_return_type;
335  typedef const std::pair<float,float>& pass_type;
336  typedef String string_return_type;
337 
338  static const String& getDataTypeName()
339  {
340  static String type("std::pair<float,float>");
341 
342  return type;
343  }
344 
345  static return_type fromString(const String& str)
346  {
347  float rangeMin = 0, rangeMax = 0;
348  sscanf(str.c_str(), " min:%f max:%f", &rangeMin, &rangeMax);
349  return std::pair<float,float>(rangeMin,rangeMax);
350  }
351 
352  static string_return_type toString(pass_type val)
353  {
354  char buff[64];
355  sprintf(buff, "min:%f max:%f", val.first, val.second);
356  return buff;
357  }
358 };
359 
360 } // End of CEGUI namespace section
361 
362 #if defined(_MSC_VER)
363 # pragma warning(pop)
364 #endif
365 
366 #endif // end of guard _CEGUIThumb_h_