camera_2d.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*************************************************************************/
  2. /* camera_2d.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 CAMERA_2D_H
  30. #define CAMERA_2D_H
  31. #include "scene/2d/node_2d.h"
  32. #include "scene/main/viewport.h"
  33. class Camera2D : public Node2D {
  34. OBJ_TYPE( Camera2D, Node2D );
  35. public:
  36. enum AnchorMode {
  37. ANCHOR_MODE_FIXED_TOP_LEFT,
  38. ANCHOR_MODE_DRAG_CENTER
  39. };
  40. protected:
  41. Point2 camera_pos;
  42. Point2 smoothed_camera_pos;
  43. bool first;
  44. Viewport *viewport;
  45. StringName group_name;
  46. StringName canvas_group_name;
  47. RID canvas;
  48. Vector2 offset;
  49. Vector2 zoom;
  50. AnchorMode anchor_mode;
  51. bool rotating;
  52. bool current;
  53. float smoothing;
  54. bool smoothing_enabled;
  55. int limit[4];
  56. float drag_margin[4];
  57. bool h_drag_enabled;
  58. bool v_drag_enabled;
  59. float h_ofs;
  60. float v_ofs;
  61. Point2 camera_screen_center;
  62. void _update_scroll();
  63. void _make_current(Object *p_which);
  64. void _set_current(bool p_current);
  65. void _set_old_smoothing(float p_enable);
  66. protected:
  67. virtual Matrix32 get_camera_transform();
  68. void _notification(int p_what);
  69. static void _bind_methods();
  70. public:
  71. void set_offset(const Vector2& p_offset);
  72. Vector2 get_offset() const;
  73. void set_anchor_mode(AnchorMode p_anchor_mode);
  74. AnchorMode get_anchor_mode() const;
  75. void set_rotating(bool p_rotating);
  76. bool is_rotating() const;
  77. void set_limit(Margin p_margin,int p_limit);
  78. int get_limit(Margin p_margin) const;
  79. void set_h_drag_enabled(bool p_enabled);
  80. bool is_h_drag_enabled() const;
  81. void set_v_drag_enabled(bool p_enabled);
  82. bool is_v_drag_enabled() const;
  83. void set_drag_margin(Margin p_margin,float p_drag_margin);
  84. float get_drag_margin(Margin p_margin) const;
  85. void set_v_offset(float p_offset);
  86. float get_v_offset() const;
  87. void set_h_offset(float p_offset);
  88. float get_h_offset() const;
  89. void set_enable_follow_smoothing(bool p_enabled);
  90. bool is_follow_smoothing_enabled() const;
  91. void set_follow_smoothing(float p_speed);
  92. float get_follow_smoothing() const;
  93. void make_current();
  94. void clear_current();
  95. bool is_current() const;
  96. void set_zoom(const Vector2& p_zoom);
  97. Vector2 get_zoom() const;
  98. Point2 get_camera_screen_center() const;
  99. Vector2 get_camera_pos() const;
  100. void force_update_scroll();
  101. Camera2D();
  102. };
  103. VARIANT_ENUM_CAST(Camera2D::AnchorMode);
  104. #endif // CAMERA_2D_H