scroll_bar.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*************************************************************************/
  2. /* scroll_bar.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef SCROLL_BAR_H
  30. #define SCROLL_BAR_H
  31. #include "scene/gui/range.h"
  32. /**
  33. @author Juan Linietsky <reduzio@gmail.com>
  34. */
  35. class ScrollBar : public Range {
  36. OBJ_TYPE( ScrollBar, Range );
  37. enum HiliteStatus {
  38. HILITE_NONE,
  39. HILITE_DECR,
  40. HILITE_RANGE,
  41. HILITE_INCR,
  42. };
  43. static bool focus_by_default;
  44. Orientation orientation;
  45. Size2 size;
  46. float custom_step;
  47. HiliteStatus hilite;
  48. struct Drag {
  49. bool active;
  50. float pos_at_click;
  51. float value_at_click;
  52. } drag;
  53. double get_grabber_size() const;
  54. double get_grabber_min_size() const;
  55. double get_area_size() const;
  56. double get_area_offset() const;
  57. double get_click_pos(const Point2& p_pos) const;
  58. double get_grabber_offset() const;
  59. static void set_can_focus_by_default(bool p_can_focus);
  60. Node* drag_slave;
  61. NodePath drag_slave_path;
  62. Vector2 drag_slave_speed;
  63. Vector2 drag_slave_accum;
  64. Vector2 drag_slave_from;
  65. Vector2 last_drag_slave_accum;
  66. float last_drag_slave_time;
  67. float time_since_motion;
  68. bool drag_slave_touching;
  69. bool drag_slave_touching_deaccel;
  70. bool click_handled;
  71. void _drag_slave_exit();
  72. void _drag_slave_input(const InputEvent& p_input);
  73. void _input_event(InputEvent p_event);
  74. protected:
  75. void _notification(int p_what);
  76. static void _bind_methods();
  77. public:
  78. void set_custom_step(float p_custom_step);
  79. float get_custom_step() const;
  80. void set_drag_slave(const NodePath& p_path);
  81. NodePath get_drag_slave() const;
  82. virtual Size2 get_minimum_size() const;
  83. ScrollBar(Orientation p_orientation=VERTICAL);
  84. ~ScrollBar();
  85. };
  86. class HScrollBar : public ScrollBar {
  87. OBJ_TYPE( HScrollBar, ScrollBar );
  88. public:
  89. HScrollBar() : ScrollBar(HORIZONTAL) { set_v_size_flags(0); }
  90. };
  91. class VScrollBar : public ScrollBar {
  92. OBJ_TYPE( VScrollBar, ScrollBar );
  93. public:
  94. VScrollBar() : ScrollBar(VERTICAL) { set_h_size_flags(0); }
  95. };
  96. #endif