JNR
uiSlider.h
1 /*
2 
3 Jump'n'Run Engine
4 http://www.atanaslaskov.com/jnr/
5 
6 BSD LICENSE
7 Copyright (c) 2007-2013, Atanas Laskov
8 All rights reserved.
9 
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
12 1. Redistributions of source code must retain the above copyright notice,
13 this list of conditions and the following disclaimer.
14 2. Redistributions in binary form must reproduce the above copyright notice,
15 this list of conditions and the following disclaimer in the documentation
16 and/or other materials provided with the distribution.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL ATANAS LASKOV BE LIABLE FOR ANY
21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 */
29 
31 
32 
38 
41  public uiContainer
42 {
43 protected:
44 
45  //Textrue
46  laTexture _t;
47 
48  //Init
49  virtual void init();
50 
51 public:
52  friend class uiSlider;
53 
54  uiSlidingButton(void) {};
55  ~uiSlidingButton(void) {};
56 
57  // Get/set current position, with regard to the parent's width
58  double getFraction() {
59  return (_ptPos.x()-3) / (_pParent->getSize().x()-13);
60  }
61 
62  void setFraction(double df) {
63  _ptPos.x( df * (_pParent->getSize().x()-13) + 3 );
64  }
65 
66  // Reply & draw
67  virtual void reply();
68  virtual void draw();
69 };
70 
71 class uiSlider :
72  public uiProgress
73 {
74 protected:
75 
76  //Sliding gadget
77  uiSlidingButton _uiBtn;
78 
79  //Value indicator
80  uiLabel _uiValueLabel;
81 
82  //Printed value format
83  char _strValueFormat[16];
84 
85  // Internal construction method,
86  // called by create() and load()
87  virtual void init();
88 
89 public:
90  // Constructor/destructor
91  uiSlider(void);
92  ~uiSlider(void);
93 
94  // Set value
95  void setValue(double val)
96  {
97  uiProgress::setValue(val);
98 
99  _uiBtn.setFraction( (_dCurrent-_dMin) / (_dMax-_dMin) );
100  }
101 
102  // Set value format string
103  void setValueFormat(char* str)
104  {
105  strcpy(_strValueFormat, str);
106  }
107 
108  // Reply & draw
109  virtual void reply();
110  virtual void draw();
111 
112  void load(class laFileParser *fp);
113 };
114 
Sliding button used by uiSlider.
Definition: uiSlider.h:40
laPoint3 _ptPos
Windos position (relative to parent)
Definition: uiWindow.h:75
virtual void reply()
Handle input message.
Definition: uiSlider.cpp:113
GUI Container Window.
Definition: uiContainer.h:42
GUI Slider.
Definition: uiSlider.h:71
virtual void draw()
Display the window.
Definition: uiSlider.cpp:79
uiWindow * _pParent
Pointer to parent window, if any.
Definition: uiWindow.h:71
GUI Progress Bar.
Definition: uiProgress.h:39
2D Texture
Definition: laTexture.h:45
virtual void reply()
Handle input message.
Definition: uiSlider.cpp:69
void load(class laFileParser *fp)
Load a dialog layout form .cui file.
Definition: uiSlider.cpp:56
virtual void draw()
Display the window.
Definition: uiSlider.cpp:126
Text Label.
Definition: uiLabel.h:41
File Parser.
Definition: laFileParser.h:41