libAlgAudio  v1.99-440-g08538e5-dirty
The development library for AlgAudio framework.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UISlider.hpp
Go to the documentation of this file.
1 #ifndef UISLIDER_HPP
2 #define UISLIDER_HPP
3 /*
4 This file is part of AlgAudio.
5 
6 AlgAudio, Copyright (C) 2015 CeTA - Audiovisual Technology Center
7 
8 AlgAudio is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as
10 published by the Free Software Foundation, either version 3 of the
11 License, or (at your option) any later version.
12 
13 AlgAudio is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Lesser General Public License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public License
19 along with AlgAudio. If not, see <http://www.gnu.org/licenses/>.
20 */
21 #include "UI/UIWidget.hpp"
22 #include "UI/UIBox.hpp"
23 #include "UI/UITextEntry.hpp"
24 
25 namespace AlgAudio{
26 
27 class ParamController;
28 
29 class UISlider : public UIContainerSingle{
30 public:
31  static std::shared_ptr<UISlider> Create(std::weak_ptr<Window> parent_window, std::shared_ptr<ParamController> controller);
32  void CustomDraw(DrawContext& c) override;
33  virtual bool CustomMousePress(bool down, MouseButton b,Point2D pos) override;
34  virtual void CustomMouseMotion(Point2D pos1,Point2D pos2) override;
35  virtual void CustomMouseEnter(Point2D pos) override;
36  virtual void CustomMouseLeave(Point2D pos) override;
37  virtual void OnFocusChanged(bool has_focus) override;
38  virtual void CustomResize(Size2D size) override;
39  virtual Point2D GetChildPos() const override {return GetBodyRect().a;}
40  Rect GetInputRect() const;
43  Rect GetBodyRect() const;
44 
45  void DragStart();
46  void DragStep(Point2D_<float> offset);
47  void DragEnd();
48 
49  void SetName(std::string name);
50  void SetRangeMin(float x);
51  void SetRangeMax(float x);
52 
53  enum class Mode{
54  Slider,
55  Display,
56  };
57  void SetMode(Mode m){
58  mode = m;
60  }
61 
62  std::string param_id;
63 protected:
64  UISlider(std::weak_ptr<Window> parent_window, std::shared_ptr<ParamController> controller);
65 private:
66  void Init(std::shared_ptr<ParamController> controller);
67  std::weak_ptr<ParamController> controller;
68  std::shared_ptr<SDLTextTexture> name_texture;
69 
70  float current_value;
71  float current_range_min, current_range_max;
72  // This flag indicates whether text textures need to be re-rendered with new
73  // values.
74  bool text_textures_invalid = true;
75  std::shared_ptr<SDLTextTexture> value_texture, value_texture_big;
76  std::shared_ptr<SDLTextTexture> range_min_texture, range_max_texture;
77 
78  bool dragged = false;
79  float drag_start_q;
80 
81  Mode mode = Mode::Slider;
82 
83  enum class PointMode{ None, Input, Center, OutputAbsolute, OutputRelative };
84  PointMode point_mode = PointMode::None;
85 
86  inline int GetBodyStart() const{ return (mode == Mode::Slider)? 12 : 0 ;}
87  inline int GetBodyEnd() const{ return (mode == Mode::Slider)? (current_size.width - 12) : (current_size.width - 25) ;}
88  inline int GetBodyWidth() const{ return current_size.width - 25;}
89 
90  bool editted = false;
91  std::shared_ptr<UIHBox> edit_box;
92  std::shared_ptr<UITextEntry> edit_entry_min;
93  std::shared_ptr<UITextEntry> edit_entry_val;
94  std::shared_ptr<UITextEntry> edit_entry_max;
96  void SetEditMode(bool enabled);
97  void ApplyEdittedValues();
98 };
99 
100 
101 } // namespace AlgAudio
102 
103 #endif // UISLIDER_HPP
void SetMode(Mode m)
Definition: UISlider.hpp:57
Definition: Utilities.hpp:104
Definition: UIContainer.hpp:27
Definition: DrawContext.hpp:65
Mode
Definition: UISlider.hpp:53
Size2D current_size
Definition: UIWidget.hpp:174
void SetName(std::string name)
MouseButton
Definition: Utilities.hpp:190
Rect GetBodyRect() const
Definition: UISlider.hpp:29
std::string param_id
Definition: UISlider.hpp:62
virtual void CustomMouseLeave(Point2D pos) override
UISlider(std::weak_ptr< Window > parent_window, std::shared_ptr< ParamController > controller)
void CustomDraw(DrawContext &c) override
void SetRangeMin(float x)
static std::shared_ptr< UISlider > Create(std::weak_ptr< Window > parent_window, std::shared_ptr< ParamController > controller)
int width
Definition: Utilities.hpp:46
virtual void CustomResize(Size2D size) override
Definition: Alertable.hpp:26
virtual void OnFocusChanged(bool has_focus) override
Point2D a
Definition: Utilities.hpp:105
void SetRangeMax(float x)
Rect GetRelativeOutputRect() const
virtual bool CustomMousePress(bool down, MouseButton b, Point2D pos) override
Rect GetAbsoluteOutputRect() const
void DragStep(Point2D_< float > offset)
virtual void CustomMouseEnter(Point2D pos) override
virtual Point2D GetChildPos() const override
Definition: UISlider.hpp:39
virtual void CustomMouseMotion(Point2D pos1, Point2D pos2) override
Rect GetInputRect() const
Definition: Utilities.hpp:40