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