HoverRace  2.0
Slider.h
Go to the documentation of this file.
1 
2 // Slider.h
3 //
4 // Copyright (c) 2014-2016 Michael Imamura.
5 //
6 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // A copy of the license should have been attached to the package from which
10 // you have taken this file. If you can not find the license you can not use
11 // this file.
12 //
13 //
14 // The author makes no representations about the suitability of
15 // this software for any purpose. It is provided "as is" "AS IS",
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17 // implied.
18 //
19 // See the License for the specific language governing permissions
20 // and limitations under the License.
21 
22 #pragma once
23 
24 #include "ClickRegion.h"
25 
26 #if defined(_WIN32) && defined(HR_ENGINE_SHARED)
27 # ifdef MR_ENGINE
28 # define MR_DllDeclare __declspec( dllexport )
29 # else
30 # define MR_DllDeclare __declspec( dllimport )
31 # endif
32 #else
33 # define MR_DllDeclare
34 #endif
35 
36 namespace HoverRace {
37  namespace Display {
38  class Display;
39  class FillBox;
40  class Label;
41  class RuleLine;
42  }
43 }
44 
45 namespace HoverRace {
46 namespace Display {
47 
53 {
54  using SUPER = ClickRegion;
55 
56 public:
57  struct Props
58  {
59  enum {
60  VALUE = SUPER::Props::NEXT_,
62  };
63  };
64 
65 public:
66  Slider(Display &display, double min, double max, double step,
67  uiLayoutFlags_t layoutFlags = 0);
68  virtual ~Slider();
69 
70 public:
71  void AttachView(Display &disp) override { AttachViewDynamic(disp, this); }
72 
73 public:
74  bool OnNavigate(const Control::Nav &nav) override;
75 protected:
76  void OnMouseDrag(const Vec2 &relPos) override;
77 
78 public:
79  using valueChangedSignal_t = boost::signals2::signal<void(double)>;
80  valueChangedSignal_t &GetValueChangedSignal() { return valueChangedSignal; }
81 
82 public:
83  double GetMin() const { return min; }
84  double GetMax() const { return max; }
85  double GetStep() const { return step; }
86 
87  double GetValue() const { return value; }
88  void SetValue(double value);
89 
90  FillBox *GetBackgroundChild() const { return background.get(); }
91  FillBox *GetIndicatorChild() const { return indicator.get(); }
92  RuleLine *GetZeroLineChild() const { return zeroLine.get(); }
93 
94 protected:
95  void Layout() override;
96 
97 public:
98  Vec3 Measure() override;
99  void FireModelUpdate(int prop) override;
100 
101 private:
102  double min;
103  double max;
104  double step;
105  double value;
106 
108 
109  std::unique_ptr<FillBox> background;
110  std::unique_ptr<FillBox> indicator;
111  std::unique_ptr<RuleLine> zeroLine;
112 };
113 
114 } // namespace Display
115 } // namespace HoverRace
116 
117 #undef MR_DllDeclare
double min
Definition: Slider.h:102
A horizontal or vertical line.
Definition: RuleLine.h:54
Definition: Slider.h:57
Base class for UI (2D) components.
Definition: UiViewModel.h:56
double GetValue() const
Definition: Slider.h:87
#define MR_DllDeclare
Definition: Slider.h:33
boost::signals2::signal< void(double)> valueChangedSignal_t
Definition: Slider.h:79
double value
Definition: Slider.h:105
void AttachView(Display &disp) override
Definition: Slider.h:71
double GetMin() const
Definition: Slider.h:83
std::unique_ptr< FillBox > indicator
Definition: Slider.h:110
double max
Definition: Slider.h:103
Definition: Vec.h:38
MR_UInt32 uiLayoutFlags_t
Definition: UiLayoutFlags.h:53
A slider for selecting values from a range.
Definition: Slider.h:52
double GetStep() const
Definition: Slider.h:85
FillBox * GetBackgroundChild() const
Definition: Slider.h:90
Base class for display managers.
Definition: Display.h:73
valueChangedSignal_t valueChangedSignal
Definition: Slider.h:107
std::unique_ptr< RuleLine > zeroLine
Definition: Slider.h:111
FillBox * GetIndicatorChild() const
Definition: Slider.h:91
A navigation direction.
Definition: Nav.h:45
double GetMax() const
Definition: Slider.h:84
A colored rectangle, that&#39;s all.
Definition: FillBox.h:51
valueChangedSignal_t & GetValueChangedSignal()
Definition: Slider.h:80
Base class for clickable areas.
Definition: ClickRegion.h:49
RuleLine * GetZeroLineChild() const
Definition: Slider.h:92
Definition: Announcement.h:24
Definition: Vec.h:114
std::unique_ptr< FillBox > background
Definition: Slider.h:109
double step
Definition: Slider.h:104
First index for subclasses.
Definition: Slider.h:61