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