scroll_bar.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. #ifndef SCROLL_BAR_H
  31. #define SCROLL_BAR_H
  32. #include "scene/gui/range.h"
  33. class ScrollBar : public Range {
  34. GDCLASS(ScrollBar, Range);
  35. enum HighlightStatus {
  36. HIGHLIGHT_NONE,
  37. HIGHLIGHT_DECR,
  38. HIGHLIGHT_RANGE,
  39. HIGHLIGHT_INCR,
  40. };
  41. static bool focus_by_default;
  42. Orientation orientation;
  43. Size2 size;
  44. float custom_step = -1.0;
  45. HighlightStatus highlight = HIGHLIGHT_NONE;
  46. bool incr_active = false;
  47. bool decr_active = false;
  48. struct Drag {
  49. bool active = false;
  50. float pos_at_click = 0.0;
  51. float value_at_click = 0.0;
  52. } drag;
  53. double get_grabber_size() const;
  54. double get_grabber_min_size() const;
  55. double get_area_size() const;
  56. double get_grabber_offset() const;
  57. static void set_can_focus_by_default(bool p_can_focus);
  58. Node *drag_node = nullptr;
  59. NodePath drag_node_path;
  60. bool drag_node_enabled = true;
  61. Vector2 drag_node_speed;
  62. Vector2 drag_node_accum;
  63. Vector2 drag_node_from;
  64. Vector2 last_drag_node_accum;
  65. float last_drag_node_time = 0.0;
  66. float time_since_motion = 0.0;
  67. bool drag_node_touching = false;
  68. bool drag_node_touching_deaccel = false;
  69. bool click_handled = false;
  70. bool scrolling = false;
  71. double target_scroll = 0.0;
  72. bool smooth_scroll_enabled = false;
  73. struct ThemeCache {
  74. Ref<StyleBox> scroll_style;
  75. Ref<StyleBox> scroll_focus_style;
  76. Ref<StyleBox> scroll_offset_style;
  77. Ref<StyleBox> grabber_style;
  78. Ref<StyleBox> grabber_hl_style;
  79. Ref<StyleBox> grabber_pressed_style;
  80. Ref<Texture2D> increment_icon;
  81. Ref<Texture2D> increment_hl_icon;
  82. Ref<Texture2D> increment_pressed_icon;
  83. Ref<Texture2D> decrement_icon;
  84. Ref<Texture2D> decrement_hl_icon;
  85. Ref<Texture2D> decrement_pressed_icon;
  86. } theme_cache;
  87. void _drag_node_exit();
  88. void _drag_node_input(const Ref<InputEvent> &p_input);
  89. virtual void gui_input(const Ref<InputEvent> &p_event) override;
  90. protected:
  91. void _notification(int p_what);
  92. static void _bind_methods();
  93. public:
  94. void scroll(double p_amount);
  95. void scroll_to(double p_position);
  96. void set_custom_step(float p_custom_step);
  97. float get_custom_step() const;
  98. void set_drag_node(const NodePath &p_path);
  99. NodePath get_drag_node() const;
  100. void set_drag_node_enabled(bool p_enable);
  101. void set_smooth_scroll_enabled(bool p_enable);
  102. bool is_smooth_scroll_enabled() const;
  103. virtual Size2 get_minimum_size() const override;
  104. ScrollBar(Orientation p_orientation = VERTICAL);
  105. ~ScrollBar();
  106. };
  107. class HScrollBar : public ScrollBar {
  108. GDCLASS(HScrollBar, ScrollBar);
  109. public:
  110. HScrollBar() :
  111. ScrollBar(HORIZONTAL) { set_v_size_flags(0); }
  112. };
  113. class VScrollBar : public ScrollBar {
  114. GDCLASS(VScrollBar, ScrollBar);
  115. public:
  116. VScrollBar() :
  117. ScrollBar(VERTICAL) { set_h_size_flags(0); }
  118. };
  119. #endif // SCROLL_BAR_H