| 1 | /**************************************************************************/ |
| 2 | /* scroll_bar.h */ |
| 3 | /**************************************************************************/ |
| 4 | /* This file is part of: */ |
| 5 | /* GODOT ENGINE */ |
| 6 | /* https://godotengine.org */ |
| 7 | /**************************************************************************/ |
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 10 | /* */ |
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
| 12 | /* a copy of this software and associated documentation files (the */ |
| 13 | /* "Software"), to deal in the Software without restriction, including */ |
| 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
| 16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
| 17 | /* the following conditions: */ |
| 18 | /* */ |
| 19 | /* The above copyright notice and this permission notice shall be */ |
| 20 | /* included in all copies or substantial portions of the Software. */ |
| 21 | /* */ |
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 29 | /**************************************************************************/ |
| 30 | |
| 31 | #ifndef SCROLL_BAR_H |
| 32 | #define SCROLL_BAR_H |
| 33 | |
| 34 | #include "scene/gui/range.h" |
| 35 | |
| 36 | class ScrollBar : public Range { |
| 37 | GDCLASS(ScrollBar, Range); |
| 38 | |
| 39 | enum HighlightStatus { |
| 40 | HIGHLIGHT_NONE, |
| 41 | HIGHLIGHT_DECR, |
| 42 | HIGHLIGHT_RANGE, |
| 43 | HIGHLIGHT_INCR, |
| 44 | }; |
| 45 | |
| 46 | static bool focus_by_default; |
| 47 | |
| 48 | Orientation orientation; |
| 49 | Size2 size; |
| 50 | float custom_step = -1.0; |
| 51 | |
| 52 | HighlightStatus highlight = HIGHLIGHT_NONE; |
| 53 | |
| 54 | bool incr_active = false; |
| 55 | bool decr_active = false; |
| 56 | |
| 57 | struct Drag { |
| 58 | bool active = false; |
| 59 | float pos_at_click = 0.0; |
| 60 | float value_at_click = 0.0; |
| 61 | } drag; |
| 62 | |
| 63 | double get_grabber_size() const; |
| 64 | double get_grabber_min_size() const; |
| 65 | double get_area_size() const; |
| 66 | double get_area_offset() const; |
| 67 | double get_grabber_offset() const; |
| 68 | |
| 69 | static void set_can_focus_by_default(bool p_can_focus); |
| 70 | |
| 71 | Node *drag_node = nullptr; |
| 72 | NodePath drag_node_path; |
| 73 | bool drag_node_enabled = true; |
| 74 | |
| 75 | Vector2 drag_node_speed; |
| 76 | Vector2 drag_node_accum; |
| 77 | Vector2 drag_node_from; |
| 78 | Vector2 last_drag_node_accum; |
| 79 | float last_drag_node_time = 0.0; |
| 80 | float time_since_motion = 0.0; |
| 81 | bool drag_node_touching = false; |
| 82 | bool drag_node_touching_deaccel = false; |
| 83 | bool click_handled = false; |
| 84 | |
| 85 | bool scrolling = false; |
| 86 | double target_scroll = 0.0; |
| 87 | bool smooth_scroll_enabled = false; |
| 88 | |
| 89 | struct ThemeCache { |
| 90 | Ref<StyleBox> scroll_style; |
| 91 | Ref<StyleBox> scroll_focus_style; |
| 92 | Ref<StyleBox> scroll_offset_style; |
| 93 | Ref<StyleBox> grabber_style; |
| 94 | Ref<StyleBox> grabber_hl_style; |
| 95 | Ref<StyleBox> grabber_pressed_style; |
| 96 | |
| 97 | Ref<Texture2D> increment_icon; |
| 98 | Ref<Texture2D> increment_hl_icon; |
| 99 | Ref<Texture2D> increment_pressed_icon; |
| 100 | Ref<Texture2D> decrement_icon; |
| 101 | Ref<Texture2D> decrement_hl_icon; |
| 102 | Ref<Texture2D> decrement_pressed_icon; |
| 103 | } theme_cache; |
| 104 | |
| 105 | void _drag_node_exit(); |
| 106 | void _drag_node_input(const Ref<InputEvent> &p_input); |
| 107 | |
| 108 | virtual void gui_input(const Ref<InputEvent> &p_event) override; |
| 109 | |
| 110 | protected: |
| 111 | void _notification(int p_what); |
| 112 | static void _bind_methods(); |
| 113 | |
| 114 | public: |
| 115 | void set_custom_step(float p_custom_step); |
| 116 | float get_custom_step() const; |
| 117 | |
| 118 | void set_drag_node(const NodePath &p_path); |
| 119 | NodePath get_drag_node() const; |
| 120 | void set_drag_node_enabled(bool p_enable); |
| 121 | |
| 122 | void set_smooth_scroll_enabled(bool p_enable); |
| 123 | bool is_smooth_scroll_enabled() const; |
| 124 | |
| 125 | virtual Size2 get_minimum_size() const override; |
| 126 | ScrollBar(Orientation p_orientation = VERTICAL); |
| 127 | ~ScrollBar(); |
| 128 | }; |
| 129 | |
| 130 | class HScrollBar : public ScrollBar { |
| 131 | GDCLASS(HScrollBar, ScrollBar); |
| 132 | |
| 133 | public: |
| 134 | HScrollBar() : |
| 135 | ScrollBar(HORIZONTAL) { set_v_size_flags(0); } |
| 136 | }; |
| 137 | |
| 138 | class VScrollBar : public ScrollBar { |
| 139 | GDCLASS(VScrollBar, ScrollBar); |
| 140 | |
| 141 | public: |
| 142 | VScrollBar() : |
| 143 | ScrollBar(VERTICAL) { set_h_size_flags(0); } |
| 144 | }; |
| 145 | |
| 146 | #endif // SCROLL_BAR_H |
| 147 | |