Luanti 5.11.0-dev
 
Loading...
Searching...
No Matches
guiScrollBar.h
Go to the documentation of this file.
1/*
2Copyright (C) 2002-2013 Nikolaus Gebhardt
3This file is part of the "Irrlicht Engine".
4For conditions of distribution and use, see copyright notice in irrlicht.h
5
6Modified 2019.05.01 by stujones11, Stuart Jones <stujones111@gmail.com>
7
8This is a heavily modified copy of the Irrlicht CGUIScrollBar class
9which includes automatic scaling of the thumb slider and hiding of
10the arrow buttons where there is insufficient space.
11*/
12
13#pragma once
14
16#include <optional>
17
19
20using namespace irr;
21using namespace gui;
22
23class GUIScrollBar : public IGUIElement
24{
25public:
26 GUIScrollBar(IGUIEnvironment *environment, IGUIElement *parent, s32 id,
27 core::rect<s32> rectangle, bool horizontal, bool auto_scale,
29
36
37 virtual void draw() override;
38 virtual void updateAbsolutePosition() override;
39 virtual bool OnEvent(const SEvent &event) override;
40 virtual void OnPostRender(u32 time_ms) override;
41
42 s32 getMax() const { return max_pos; }
43 s32 getMin() const { return min_pos; }
44 s32 getLargeStep() const { return large_step; }
45 s32 getSmallStep() const { return small_step; }
46 s32 getPos() const;
47 s32 getTargetPos() const;
48 bool isHorizontal() const { return is_horizontal; }
49
50 void setMax(const s32 &max);
51 void setMin(const s32 &min);
52 void setSmallStep(const s32 &step);
53 void setLargeStep(const s32 &step);
55 // setPos does not send EGET_SCROLL_BAR_CHANGED events for you.
56 void setPos(const s32 &pos);
58 void setPosAndSend(const s32 &pos);
60 // If you want to do an interpolated addition, use
61 // setPosInterpolated(getTargetPos() + x).
62 // setPosInterpolated takes care of sending EGET_SCROLL_BAR_CHANGED events.
63 void setPosInterpolated(const s32 &pos);
64 void setPageSize(const s32 &size);
66
67private:
68 void refreshControls();
69 s32 getPosFromMousePos(const core::position2di &p) const;
70 f32 range() const { return f32(max_pos - min_pos); }
71
72 IGUIButton *up_button;
73 IGUIButton *down_button;
90
91 core::rect<s32> slider_rect;
92 video::SColor current_icon_color;
93
95
96 void setPosRaw(const s32 &pos);
97 void updatePos();
98 std::optional<s32> target_pos;
99 u32 last_time_ms = 0;
100 u32 last_delta_ms = 17; // assume 60 FPS
101 void interpolatePos();
102};
Definition guiScrollBar.h:24
ISimpleTextureSource * m_tsrc
Definition guiScrollBar.h:94
virtual void OnPostRender(u32 time_ms) override
Definition guiScrollBar.cpp:218
s32 large_step
Definition guiScrollBar.h:86
bool is_auto_scaling
Definition guiScrollBar.h:77
void setPos(const s32 &pos)
Sets a position immediately, aborting any ongoing interpolation.
Definition guiScrollBar.cpp:278
s32 thumb_size
Definition guiScrollBar.h:82
std::optional< s32 > target_pos
Definition guiScrollBar.h:98
void setPosRaw(const s32 &pos)
Definition guiScrollBar.cpp:252
s32 scroll_pos
Definition guiScrollBar.h:80
bool is_dragging
Definition guiScrollBar.h:75
void setPosAndSend(const s32 &pos)
The same as setPos, but it takes care of sending EGET_SCROLL_BAR_CHANGED events.
Definition guiScrollBar.cpp:284
bool tray_clicked
Definition guiScrollBar.h:79
video::SColor current_icon_color
Definition guiScrollBar.h:92
void updatePos()
Definition guiScrollBar.cpp:247
void setArrowsVisible(ArrowVisibility visible)
Definition guiScrollBar.cpp:354
void setLargeStep(const s32 &step)
Definition guiScrollBar.cpp:319
virtual bool OnEvent(const SEvent &event) override
Definition guiScrollBar.cpp:37
virtual void updateAbsolutePosition() override
Definition guiScrollBar.cpp:225
s32 small_step
Definition guiScrollBar.h:85
u32 last_delta_ms
Definition guiScrollBar.h:100
s32 getTargetPos() const
Definition guiScrollBar.cpp:365
s32 getMin() const
Definition guiScrollBar.h:43
IGUIButton * up_button
Definition guiScrollBar.h:72
void setMax(const s32 &max)
Definition guiScrollBar.cpp:324
s32 page_size
Definition guiScrollBar.h:88
void interpolatePos()
Definition guiScrollBar.cpp:199
void setPosInterpolated(const s32 &pos)
Sets a target position for interpolation.
Definition guiScrollBar.cpp:298
s32 getMax() const
Definition guiScrollBar.h:42
void setSmallStep(const s32 &step)
Definition guiScrollBar.cpp:314
void setMin(const s32 &min)
Definition guiScrollBar.cpp:336
s32 draw_center
Definition guiScrollBar.h:81
ArrowVisibility
Definition guiScrollBar.h:31
@ HIDE
Definition guiScrollBar.h:32
@ DEFAULT
Definition guiScrollBar.h:34
@ SHOW
Definition guiScrollBar.h:33
ArrowVisibility arrow_visibility
Definition guiScrollBar.h:74
f32 range() const
Definition guiScrollBar.h:70
virtual void draw() override
Definition guiScrollBar.cpp:156
bool is_horizontal
Definition guiScrollBar.h:76
s32 getLargeStep() const
Definition guiScrollBar.h:44
s32 min_pos
Definition guiScrollBar.h:83
bool isHorizontal() const
Definition guiScrollBar.h:48
void refreshControls()
Definition guiScrollBar.cpp:374
s32 border_size
Definition guiScrollBar.h:89
s32 max_pos
Definition guiScrollBar.h:84
s32 getSmallStep() const
Definition guiScrollBar.h:45
core::rect< s32 > slider_rect
Definition guiScrollBar.h:91
s32 getPosFromMousePos(const core::position2di &p) const
Definition guiScrollBar.cpp:232
GUIScrollBar(IGUIEnvironment *environment, IGUIElement *parent, s32 id, core::rect< s32 > rectangle, bool horizontal, bool auto_scale, ISimpleTextureSource *tsrc)
Definition guiScrollBar.cpp:19
u32 last_time_ms
Definition guiScrollBar.h:99
s32 getPos() const
Definition guiScrollBar.cpp:360
s32 drag_offset
Definition guiScrollBar.h:87
IGUIButton * down_button
Definition guiScrollBar.h:73
bool dragged_by_slider
Definition guiScrollBar.h:78
void setPageSize(const s32 &size)
Definition guiScrollBar.cpp:348
Definition texturesource.h:25
Definition clientmap.h:30
static std::string p(std::string path)
Definition test_filesys.cpp:53