2
0

camera_2d.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*************************************************************************/
  2. /* camera_2d.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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 CAMERA_2D_H
  31. #define CAMERA_2D_H
  32. #include "scene/2d/node_2d.h"
  33. #include "scene/main/viewport.h"
  34. class Camera2D : public Node2D {
  35. GDCLASS(Camera2D, Node2D);
  36. public:
  37. enum AnchorMode {
  38. ANCHOR_MODE_FIXED_TOP_LEFT,
  39. ANCHOR_MODE_DRAG_CENTER
  40. };
  41. enum Camera2DProcessMode {
  42. CAMERA2D_PROCESS_PHYSICS,
  43. CAMERA2D_PROCESS_IDLE
  44. };
  45. protected:
  46. Point2 camera_pos;
  47. Point2 smoothed_camera_pos;
  48. bool first;
  49. ObjectID custom_viewport_id; // to check validity
  50. Viewport *custom_viewport;
  51. Viewport *viewport;
  52. StringName group_name;
  53. StringName canvas_group_name;
  54. RID canvas;
  55. Vector2 offset;
  56. Vector2 zoom;
  57. AnchorMode anchor_mode;
  58. bool rotating;
  59. bool current;
  60. float smoothing;
  61. bool smoothing_enabled;
  62. int limit[4];
  63. bool limit_smoothing_enabled;
  64. float drag_margin[4];
  65. bool h_drag_enabled;
  66. bool v_drag_enabled;
  67. float h_ofs;
  68. float v_ofs;
  69. Point2 camera_screen_center;
  70. void _update_process_mode();
  71. void _update_scroll();
  72. void _make_current(Object *p_which);
  73. void _set_current(bool p_current);
  74. void _set_old_smoothing(float p_enable);
  75. bool screen_drawing_enabled;
  76. bool limit_drawing_enabled;
  77. bool margin_drawing_enabled;
  78. Camera2DProcessMode process_mode;
  79. protected:
  80. virtual Transform2D get_camera_transform();
  81. void _notification(int p_what);
  82. static void _bind_methods();
  83. public:
  84. void set_offset(const Vector2 &p_offset);
  85. Vector2 get_offset() const;
  86. void set_anchor_mode(AnchorMode p_anchor_mode);
  87. AnchorMode get_anchor_mode() const;
  88. void set_rotating(bool p_rotating);
  89. bool is_rotating() const;
  90. void set_limit(Margin p_margin, int p_limit);
  91. int get_limit(Margin p_margin) const;
  92. void set_limit_smoothing_enabled(bool enable);
  93. bool is_limit_smoothing_enabled() const;
  94. void set_h_drag_enabled(bool p_enabled);
  95. bool is_h_drag_enabled() const;
  96. void set_v_drag_enabled(bool p_enabled);
  97. bool is_v_drag_enabled() const;
  98. void set_drag_margin(Margin p_margin, float p_drag_margin);
  99. float get_drag_margin(Margin p_margin) const;
  100. void set_v_offset(float p_offset);
  101. float get_v_offset() const;
  102. void set_h_offset(float p_offset);
  103. float get_h_offset() const;
  104. void set_enable_follow_smoothing(bool p_enabled);
  105. bool is_follow_smoothing_enabled() const;
  106. void set_follow_smoothing(float p_speed);
  107. float get_follow_smoothing() const;
  108. void set_process_mode(Camera2DProcessMode p_mode);
  109. Camera2DProcessMode get_process_mode() const;
  110. void make_current();
  111. void clear_current();
  112. bool is_current() const;
  113. void set_zoom(const Vector2 &p_zoom);
  114. Vector2 get_zoom() const;
  115. Point2 get_camera_screen_center() const;
  116. void set_custom_viewport(Node *p_viewport);
  117. Node *get_custom_viewport() const;
  118. Vector2 get_camera_position() const;
  119. void force_update_scroll();
  120. void reset_smoothing();
  121. void align();
  122. void set_screen_drawing_enabled(bool enable);
  123. bool is_screen_drawing_enabled() const;
  124. void set_limit_drawing_enabled(bool enable);
  125. bool is_limit_drawing_enabled() const;
  126. void set_margin_drawing_enabled(bool enable);
  127. bool is_margin_drawing_enabled() const;
  128. Camera2D();
  129. };
  130. VARIANT_ENUM_CAST(Camera2D::AnchorMode);
  131. VARIANT_ENUM_CAST(Camera2D::Camera2DProcessMode);
  132. #endif // CAMERA_2D_H