scroll_bar.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*************************************************************************/
  2. /* scroll_bar.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
  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. /**
  34. @author Juan Linietsky <reduzio@gmail.com>
  35. */
  36. class ScrollBar : public Range {
  37. GDCLASS(ScrollBar, Range);
  38. enum HighlightStatus {
  39. HIGHLIGHT_NONE,
  40. HIGHLIGHT_DECR,
  41. HIGHLIGHT_RANGE,
  42. HIGHLIGHT_INCR,
  43. };
  44. static bool focus_by_default;
  45. Orientation orientation;
  46. Size2 size;
  47. float custom_step;
  48. HighlightStatus highlight;
  49. struct Drag {
  50. bool active;
  51. float pos_at_click;
  52. float value_at_click;
  53. } drag;
  54. double get_grabber_size() const;
  55. double get_grabber_min_size() const;
  56. double get_area_size() const;
  57. double get_area_offset() const;
  58. double get_click_pos(const Point2 &p_pos) const;
  59. double get_grabber_offset() const;
  60. static void set_can_focus_by_default(bool p_can_focus);
  61. Node *drag_slave;
  62. NodePath drag_slave_path;
  63. Vector2 drag_slave_speed;
  64. Vector2 drag_slave_accum;
  65. Vector2 drag_slave_from;
  66. Vector2 last_drag_slave_accum;
  67. float last_drag_slave_time;
  68. float time_since_motion;
  69. bool drag_slave_touching;
  70. bool drag_slave_touching_deaccel;
  71. bool click_handled;
  72. bool scrolling;
  73. double target_scroll;
  74. bool smooth_scroll_enabled;
  75. void _drag_slave_exit();
  76. void _drag_slave_input(const Ref<InputEvent> &p_input);
  77. void _gui_input(Ref<InputEvent> p_event);
  78. protected:
  79. void _notification(int p_what);
  80. static void _bind_methods();
  81. public:
  82. void set_custom_step(float p_custom_step);
  83. float get_custom_step() const;
  84. void set_drag_slave(const NodePath &p_path);
  85. NodePath get_drag_slave() const;
  86. void set_smooth_scroll_enabled(bool p_enable);
  87. bool is_smooth_scroll_enabled() const;
  88. virtual Size2 get_minimum_size() const;
  89. ScrollBar(Orientation p_orientation = VERTICAL);
  90. ~ScrollBar();
  91. };
  92. class HScrollBar : public ScrollBar {
  93. GDCLASS(HScrollBar, ScrollBar);
  94. public:
  95. HScrollBar()
  96. : ScrollBar(HORIZONTAL) { set_v_size_flags(0); }
  97. };
  98. class VScrollBar : public ScrollBar {
  99. GDCLASS(VScrollBar, ScrollBar);
  100. public:
  101. VScrollBar()
  102. : ScrollBar(VERTICAL) { set_h_size_flags(0); }
  103. };
  104. #endif