guiScrollBar: move directly to clicked pos if clicked into tray
[oweals/minetest.git] / src / gui / guiScrollBar.h
1 /*
2 Copyright (C) 2002-2013 Nikolaus Gebhardt
3 This file is part of the "Irrlicht Engine".
4 For conditions of distribution and use, see copyright notice in irrlicht.h
5
6 Modified 2019.05.01 by stujones11, Stuart Jones <stujones111@gmail.com>
7
8 This is a heavily modified copy of the Irrlicht CGUIScrollBar class
9 which includes automatic scaling of the thumb slider and hiding of
10 the arrow buttons where there is insufficient space.
11 */
12
13 #pragma once
14
15 #include "irrlichttypes_extrabloated.h"
16
17 using namespace irr;
18 using namespace gui;
19
20 class guiScrollBar : public IGUIElement
21 {
22 public:
23         guiScrollBar(IGUIEnvironment *environment, IGUIElement *parent, s32 id,
24                         core::rect<s32> rectangle, bool horizontal, bool auto_scale);
25
26         virtual void draw();
27         virtual void updateAbsolutePosition();
28         virtual bool OnEvent(const SEvent &event);
29
30         s32 getMax() const { return max_pos; }
31         s32 getMin() const { return min_pos; }
32         s32 getLargeStep() const { return large_step; }
33         s32 getSmallStep() const { return small_step; }
34         s32 getPos() const;
35
36         void setMax(const s32 &max);
37         void setMin(const s32 &min);
38         void setSmallStep(const s32 &step);
39         void setLargeStep(const s32 &step);
40         void setPos(const s32 &pos);
41         void setPageSize(const s32 &size);
42
43 private:
44         void refreshControls();
45         s32 getPosFromMousePos(const core::position2di &p) const;
46         f32 range() const { return f32(max_pos - min_pos); }
47
48         IGUIButton *up_button;
49         IGUIButton *down_button;
50         bool is_dragging;
51         bool is_horizontal;
52         bool is_auto_scaling;
53         bool dragged_by_slider;
54         bool tray_clicked;
55         s32 scroll_pos;
56         s32 draw_center;
57         s32 thumb_size;
58         s32 min_pos;
59         s32 max_pos;
60         s32 small_step;
61         s32 large_step;
62         u32 last_change;
63         s32 drag_offset;
64         s32 page_size;
65         s32 border_size;
66
67         core::rect<s32> slider_rect;
68         video::SColor current_icon_color;
69 };