neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
slider.hpp
Go to the documentation of this file.
1// slider.hpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 2015, 2020 Leigh Johnston. All Rights Reserved.
5
6 This program is free software: you can redistribute it and / or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#pragma once
21
22#include <neogfx/neogfx.hpp>
24
25namespace neogfx
26{
27 enum class slider_orientation : uint32_t
28 {
31 };
32}
33
38
39namespace neogfx
40{
41 class slider_impl : public widget<>
42 {
43 meta_object(widget<>)
44 public:
45 define_event(ValueChanged, value_changed)
46 define_event(ConstraintsChanged, constraints_changed)
47 public:
48 slider_impl(slider_orientation aOrientation = slider_orientation::Horizontal);
49 slider_impl(i_widget& aParent, slider_orientation aOrientation = slider_orientation::Horizontal);
50 slider_impl(i_layout& aLayout, slider_orientation aOrientation = slider_orientation::Horizontal);
51 ~slider_impl();
52 public:
53 void set_orientation(slider_orientation aOrientation, bool aUpdateLayout = true);
54 void set_bar_color(const optional_color_or_gradient& aBarColor);
55 public:
56 neogfx::size_policy size_policy() const override;
57 size minimum_size(optional_size const& aAvailableSpace = optional_size{}) const override;
58 public:
59 void paint(i_graphics_context& aGc) const override;
60 public:
61 void mouse_button_pressed(mouse_button aButton, const point& aPosition, key_modifiers_e aKeyModifiers) override;
62 void mouse_button_double_clicked(mouse_button aButton, const point& aPosition, key_modifiers_e aKeyModifiers) override;
63 void mouse_button_released(mouse_button aButton, const point& aPosition) override;
64 bool mouse_wheel_scrolled(mouse_wheel aWheel, const point& aPosition, delta aDelta, key_modifiers_e aKeyModifiers) override;
65 void mouse_moved(const point& aPosition, key_modifiers_e aKeyModifiers) override;
66 public:
67 virtual double normalized_step_value() const = 0;
68 virtual double normalized_value() const = 0;
69 virtual void set_normalized_value(double aValue);
70 protected:
71 bool handling_event() const;
72 private:
73 void init();
74 rect bar_box() const;
75 rect indicator_box() const;
76 double normalized_value_from_position(const point& aPosition) const;
77 point normalized_value_to_position(double aValue) const;
78 private:
79 slider_orientation iOrientation;
81 double iNormalizedValue;
82 optional_point iDragOffset;
83 bool iHandlingEvent;
84 };
85
86 template <typename T>
87 class basic_slider : public slider_impl
88 {
89 public:
90 typedef T value_type;
91 public:
92 basic_slider(slider_orientation aOrientation = slider_orientation::Horizontal);
93 basic_slider(i_widget& aParent, slider_orientation aOrientation = slider_orientation::Horizontal);
94 basic_slider(i_layout& aLayout, slider_orientation aOrientation = slider_orientation::Horizontal);
95 public:
96 value_type minimum() const;
97 void set_minimum(value_type aMinimum);
98 value_type maximum() const;
99 void set_maximum(value_type aMaximum);
100 value_type step() const;
101 void set_step(value_type aStep);
102 value_type value() const;
103 void set_value(value_type aValue);
104 public:
105 virtual double normalized_step_value() const;
106 virtual double normalized_value() const;
107 virtual void set_normalized_value(double aValue);
108 private:
109 value_type iMinimum;
110 value_type iMaximum;
111 value_type iStep;
112 value_type iValue;
113 bool iSettingNormalizedValue;
114 };
115
116 extern template basic_slider<int8_t>;
117 extern template basic_slider<uint8_t>;
118 extern template basic_slider<int16_t>;
119 extern template basic_slider<uint16_t>;
120 extern template basic_slider<int32_t>;
121 extern template basic_slider<uint32_t>;
122 extern template basic_slider<int64_t>;
123 extern template basic_slider<uint64_t>;
124 extern template basic_slider<float>;
125 extern template basic_slider<double>;
126
127 typedef basic_slider<int32_t> slider;
128 typedef basic_slider<double> double_slider;
129}
#define end_declare_enum(enumName)
Definition i_enum.hpp:62
#define declare_enum_string(enumName, enumEnumerator)
Definition i_enum.hpp:59
#define begin_declare_enum(enumName)
Definition i_enum.hpp:52
optional< point > optional_point
gui_rect rect
neolib::optional< color_or_gradient > optional_color_or_gradient
Definition gradient.hpp:150
basic_point< coordinate > point
slider_orientation
Definition slider.hpp:28
basic_size< coordinate > size
#define meta_object(...)
Definition i_object.hpp:28
#define define_event(name, declName,...)
Definition event.hpp:200