1 #include "lxgui/gui_slider.hpp"
3 #include "lxgui/gui_alive_checker.hpp"
4 #include "lxgui/gui_frame.hpp"
5 #include "lxgui/gui_manager.hpp"
6 #include "lxgui/gui_out.hpp"
7 #include "lxgui/gui_region_tpl.hpp"
8 #include "lxgui/gui_texture.hpp"
19 value = std::round(value / step) * step;
23 frame(block, mgr, attr) {
32 std::ostringstream str;
35 str << tab <<
" # Orientation: " << utils::to_string(
orientation_) <<
"\n";
36 str << tab <<
" # Value : " <<
value_ <<
"\n";
37 str << tab <<
" # Min value : " <<
min_value_ <<
"\n";
38 str << tab <<
" # Max value : " <<
max_value_ <<
"\n";
55 if (script_name ==
"OnDragStart") {
57 thumb_texture_->is_in_region({data.get<float>(2), data.get<float>(3)})) {
67 }
else if (script_name ==
"OnDragStop") {
74 }
else if (script_name ==
"OnMouseDown") {
81 value = offset / apparent_size.
x;
85 value = offset / apparent_size.
y;
95 const slider* slider_obj = down_cast<slider>(&obj);
109 attr.
name = thumb->get_raw_name();
112 auto tex = this->create_layered_region<texture>(thumb->get_draw_layer(), std::move(attr));
115 tex->set_manually_inherited(
true);
116 tex->notify_loaded();
151 new_offset =
vector2f(apparent_size.
x * coef, 0);
153 new_offset =
vector2f(0, apparent_size.
y * coef);
155 if (new_offset != a.
offset) {
351 return get_type_list_impl_<slider>();
Utility class for safe checking of region validity.
bool is_alive() const
Check if the wrapped region is still alive.
Stores a position for a UI region.
Stores a variable number of arguments for an event.
const utils::variant & get(std::size_t index) const
Returns a parameter of this event.
A region that can contain other regions and react to events.
std::string serialize(const std::string &tab) const override
Prints all relevant information about this region in a string.
bool is_in_region(const vector2f &position) const override
Checks if the provided coordinates are inside this frame.
void copy_from(const region &obj) override
Copies a region's parameters into this frame (inheritance).
void enable_mouse()
Marks this frame as able to receive mouse input (click & move).
virtual void fire_script(const std::string &script_name, const event_data &data=event_data{})
Calls a script.
virtual bool can_use_script(const std::string &script_name) const
Returns 'true' if this frame can use a script.
void enable_drag(const std::string &button_name)
Tells this frame to react to mouse drag.
Manages the user interface.
root & get_root()
Returns the UI root object, which contains root frames.
The base class of all elements in the GUI.
void initialize_(T &self, const region_core_attributes &attr)
Set up function to call in all derived class constructors.
manager & get_manager()
Returns this region's manager.
vector2f get_apparent_dimensions() const
Returns this region's apparent width and height (in pixels).
virtual void notify_borders_need_update()
Tells this region that its borders need updating.
bool is_moving(const region &obj) const
Checks if the given object is allowed to move.
void start_moving(utils::observer_ptr< region > obj, anchor *a=nullptr, constraint constraint=constraint::none, std::function< void()> apply_constraint_func=nullptr)
Start manually moving a region with the mouse.
void stop_moving()
Stops movement for the current object.
A frame with a movable texture.
void set_value(float value, bool silent=false)
Sets this slider's value.
bool allow_clicks_outside_thumb_
void notify_borders_need_update() override
Tells this region that its borders need updating.
void set_orientation(orientation orient)
Sets the orientation of this slider.
void set_min_value(float min_value)
Sets this slider's minimum value.
layer get_thumb_draw_layer() const
Returns the draw layer of this slider's thumb texture.
void fire_script(const std::string &script_name, const event_data &data=event_data{}) override
Calls a script.
bool is_in_region(const vector2f &position) const override
Checks if the provided coordinates are in the slider.
float get_value() const
Returns this slider's value.
void set_min_max_values(float min_value, float max_value)
Sets the slider's value range.
void set_thumb_texture(utils::observer_ptr< texture > tex)
Sets the texture to use for the thumb.
const utils::observer_ptr< texture > & get_thumb_texture()
Returns the texture used for the thumb.
void notify_thumb_texture_needs_update_()
const std::vector< std::string > & get_type_list_() const override
utils::observer_ptr< texture > thumb_texture_
void update_thumb_texture_()
float get_value_step() const
Returns this slider's value step.
orientation get_orientation() const
Returns the orientation of this slider.
bool can_use_script(const std::string &script_name) const override
Returns 'true' if this slider can use a script.
void set_thumb_draw_layer(layer thumb_layer)
Sets the draw layer of this slider's thumb texture.
void set_value_step(float value_step)
Sets this slider's value step.
float get_min_value() const
Returns this slider's minimum value.
void set_max_value(float max_value)
Sets this slider's maximum value.
bool are_clicks_outside_thumb_allowed() const
Checks if clicks are allowed outside of the thumb.
slider(utils::control_block &block, manager &mgr, const frame_core_attributes &attr)
Constructor.
void copy_from(const region &obj) override
Copies a region's parameters into this slider (inheritance).
void set_allow_clicks_outside_thumb(bool allow)
Allows the user to click anywhere in the slider to relocate the thumb.
float get_max_value() const
Returns this slider's maximum value.
std::string serialize(const std::string &tab) const override
Prints all relevant information about this region in a string.
A layered_region that can draw images and colored rectangles.
layer
ID of a layer for rendering inside a frame.
vector2< float > vector2f
Holds 2D coordinates (as floats)
void step_value(float &value, float step)
Struct holding all the core information about a frame necessary for its creation.
Struct holding all the core information about a region necessary for its creation.
std::vector< utils::observer_ptr< const region > > inheritance