summaryrefslogtreecommitdiff
path: root/scene/2d/camera_2d.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/2d/camera_2d.cpp')
-rw-r--r--scene/2d/camera_2d.cpp63
1 files changed, 0 insertions, 63 deletions
diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp
index d8af14a3fb..eeb87a7396 100644
--- a/scene/2d/camera_2d.cpp
+++ b/scene/2d/camera_2d.cpp
@@ -36,7 +36,6 @@
#include "servers/rendering_server.h"
void Camera2D::_update_scroll() {
-
if (!is_inside_tree())
return;
@@ -49,7 +48,6 @@ void Camera2D::_update_scroll() {
return;
if (current) {
-
ERR_FAIL_COND(custom_viewport && !ObjectDB::get_instance(custom_viewport_id));
Transform2D xform = get_camera_transform();
@@ -64,7 +62,6 @@ void Camera2D::_update_scroll() {
}
void Camera2D::_update_process_mode() {
-
if (Engine::get_singleton()->is_editor_hint()) {
set_process_internal(false);
set_physics_process_internal(false);
@@ -78,7 +75,6 @@ void Camera2D::_update_process_mode() {
}
void Camera2D::set_zoom(const Vector2 &p_zoom) {
-
zoom = p_zoom;
Point2 old_smoothed_camera_pos = smoothed_camera_pos;
_update_scroll();
@@ -86,12 +82,10 @@ void Camera2D::set_zoom(const Vector2 &p_zoom) {
};
Vector2 Camera2D::get_zoom() const {
-
return zoom;
};
Transform2D Camera2D::get_camera_transform() {
-
if (!get_tree())
return Transform2D();
@@ -103,14 +97,11 @@ Transform2D Camera2D::get_camera_transform() {
Point2 ret_camera_pos;
if (!first) {
-
if (anchor_mode == ANCHOR_MODE_DRAG_CENTER) {
-
if (h_drag_enabled && !Engine::get_singleton()->is_editor_hint() && !h_offset_changed) {
camera_pos.x = MIN(camera_pos.x, (new_camera_pos.x + screen_size.x * 0.5 * zoom.x * drag_margin[MARGIN_LEFT]));
camera_pos.x = MAX(camera_pos.x, (new_camera_pos.x - screen_size.x * 0.5 * zoom.x * drag_margin[MARGIN_RIGHT]));
} else {
-
if (h_ofs < 0) {
camera_pos.x = new_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_RIGHT] * h_ofs;
} else {
@@ -121,12 +112,10 @@ Transform2D Camera2D::get_camera_transform() {
}
if (v_drag_enabled && !Engine::get_singleton()->is_editor_hint() && !v_offset_changed) {
-
camera_pos.y = MIN(camera_pos.y, (new_camera_pos.y + screen_size.y * 0.5 * zoom.y * drag_margin[MARGIN_TOP]));
camera_pos.y = MAX(camera_pos.y, (new_camera_pos.y - screen_size.y * 0.5 * zoom.y * drag_margin[MARGIN_BOTTOM]));
} else {
-
if (v_ofs < 0) {
camera_pos.y = new_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_BOTTOM] * v_ofs;
} else {
@@ -137,7 +126,6 @@ Transform2D Camera2D::get_camera_transform() {
}
} else if (anchor_mode == ANCHOR_MODE_FIXED_TOP_LEFT) {
-
camera_pos = new_camera_pos;
}
@@ -159,13 +147,11 @@ Transform2D Camera2D::get_camera_transform() {
}
if (smoothing_enabled && !Engine::get_singleton()->is_editor_hint()) {
-
float c = smoothing * (process_mode == CAMERA2D_PROCESS_PHYSICS ? get_physics_process_delta_time() : get_process_delta_time());
smoothed_camera_pos = ((camera_pos - smoothed_camera_pos) * c) + smoothed_camera_pos;
ret_camera_pos = smoothed_camera_pos;
//camera_pos=camera_pos*(1.0-smoothing)+new_camera_pos*smoothing;
} else {
-
ret_camera_pos = smoothed_camera_pos = camera_pos;
}
@@ -218,23 +204,18 @@ Transform2D Camera2D::get_camera_transform() {
}
void Camera2D::_notification(int p_what) {
-
switch (p_what) {
-
case NOTIFICATION_INTERNAL_PROCESS:
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
-
_update_scroll();
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
-
if (!is_processing_internal() && !is_physics_processing_internal())
_update_scroll();
} break;
case NOTIFICATION_ENTER_TREE: {
-
if (custom_viewport && ObjectDB::get_instance(custom_viewport_id)) {
viewport = custom_viewport;
} else {
@@ -256,7 +237,6 @@ void Camera2D::_notification(int p_what) {
} break;
case NOTIFICATION_EXIT_TREE: {
-
if (is_current()) {
if (viewport && !(custom_viewport && !ObjectDB::get_instance(custom_viewport_id))) {
viewport->set_canvas_transform(Transform2D());
@@ -268,7 +248,6 @@ void Camera2D::_notification(int p_what) {
} break;
case NOTIFICATION_DRAW: {
-
if (!is_inside_tree() || !Engine::get_singleton()->is_editor_hint())
break;
@@ -349,40 +328,33 @@ void Camera2D::_notification(int p_what) {
}
void Camera2D::set_offset(const Vector2 &p_offset) {
-
offset = p_offset;
_update_scroll();
}
Vector2 Camera2D::get_offset() const {
-
return offset;
}
void Camera2D::set_anchor_mode(AnchorMode p_anchor_mode) {
-
anchor_mode = p_anchor_mode;
_update_scroll();
}
Camera2D::AnchorMode Camera2D::get_anchor_mode() const {
-
return anchor_mode;
}
void Camera2D::set_rotating(bool p_rotating) {
-
rotating = p_rotating;
_update_scroll();
}
bool Camera2D::is_rotating() const {
-
return rotating;
}
void Camera2D::set_process_mode(Camera2DProcessMode p_mode) {
-
if (process_mode == p_mode)
return;
@@ -391,14 +363,11 @@ void Camera2D::set_process_mode(Camera2DProcessMode p_mode) {
}
Camera2D::Camera2DProcessMode Camera2D::get_process_mode() const {
-
return process_mode;
}
void Camera2D::_make_current(Object *p_which) {
-
if (p_which == this) {
-
current = true;
} else {
current = false;
@@ -406,7 +375,6 @@ void Camera2D::_make_current(Object *p_which) {
}
void Camera2D::_set_current(bool p_current) {
-
if (p_current)
make_current();
@@ -415,12 +383,10 @@ void Camera2D::_set_current(bool p_current) {
}
bool Camera2D::is_current() const {
-
return current;
}
void Camera2D::make_current() {
-
if (!is_inside_tree()) {
current = true;
} else {
@@ -430,7 +396,6 @@ void Camera2D::make_current() {
}
void Camera2D::clear_current() {
-
current = false;
if (is_inside_tree()) {
get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, group_name, "_make_current", (Object *)nullptr);
@@ -438,60 +403,50 @@ void Camera2D::clear_current() {
}
void Camera2D::set_limit(Margin p_margin, int p_limit) {
-
ERR_FAIL_INDEX((int)p_margin, 4);
limit[p_margin] = p_limit;
update();
}
int Camera2D::get_limit(Margin p_margin) const {
-
ERR_FAIL_INDEX_V((int)p_margin, 4, 0);
return limit[p_margin];
}
void Camera2D::set_limit_smoothing_enabled(bool enable) {
-
limit_smoothing_enabled = enable;
_update_scroll();
}
bool Camera2D::is_limit_smoothing_enabled() const {
-
return limit_smoothing_enabled;
}
void Camera2D::set_drag_margin(Margin p_margin, float p_drag_margin) {
-
ERR_FAIL_INDEX((int)p_margin, 4);
drag_margin[p_margin] = p_drag_margin;
update();
}
float Camera2D::get_drag_margin(Margin p_margin) const {
-
ERR_FAIL_INDEX_V((int)p_margin, 4, 0);
return drag_margin[p_margin];
}
Vector2 Camera2D::get_camera_position() const {
-
return camera_pos;
}
void Camera2D::force_update_scroll() {
-
_update_scroll();
}
void Camera2D::reset_smoothing() {
-
smoothed_camera_pos = camera_pos;
_update_scroll();
}
void Camera2D::align() {
-
ERR_FAIL_COND(custom_viewport && !ObjectDB::get_instance(custom_viewport_id));
Size2 screen_size = viewport->get_visible_rect().size;
@@ -509,7 +464,6 @@ void Camera2D::align() {
camera_pos.y = current_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_BOTTOM] * v_ofs;
}
} else if (anchor_mode == ANCHOR_MODE_FIXED_TOP_LEFT) {
-
camera_pos = current_camera_pos;
}
@@ -517,7 +471,6 @@ void Camera2D::align() {
}
void Camera2D::set_follow_smoothing(float p_speed) {
-
smoothing = p_speed;
if (smoothing > 0 && !(is_inside_tree() && Engine::get_singleton()->is_editor_hint()))
set_process_internal(true);
@@ -526,55 +479,45 @@ void Camera2D::set_follow_smoothing(float p_speed) {
}
float Camera2D::get_follow_smoothing() const {
-
return smoothing;
}
Point2 Camera2D::get_camera_screen_center() const {
-
return camera_screen_center;
}
void Camera2D::set_h_drag_enabled(bool p_enabled) {
-
h_drag_enabled = p_enabled;
}
bool Camera2D::is_h_drag_enabled() const {
-
return h_drag_enabled;
}
void Camera2D::set_v_drag_enabled(bool p_enabled) {
-
v_drag_enabled = p_enabled;
}
bool Camera2D::is_v_drag_enabled() const {
-
return v_drag_enabled;
}
void Camera2D::set_v_offset(float p_offset) {
-
v_ofs = p_offset;
v_offset_changed = true;
_update_scroll();
}
float Camera2D::get_v_offset() const {
-
return v_ofs;
}
void Camera2D::set_h_offset(float p_offset) {
-
h_ofs = p_offset;
h_offset_changed = true;
_update_scroll();
}
float Camera2D::get_h_offset() const {
-
return h_ofs;
}
@@ -587,12 +530,10 @@ void Camera2D::_set_old_smoothing(float p_enable) {
}
void Camera2D::set_enable_follow_smoothing(bool p_enabled) {
-
smoothing_enabled = p_enabled;
}
bool Camera2D::is_follow_smoothing_enabled() const {
-
return smoothing_enabled;
}
@@ -612,7 +553,6 @@ void Camera2D::set_custom_viewport(Node *p_viewport) {
}
if (is_inside_tree()) {
-
if (custom_viewport)
viewport = custom_viewport;
else
@@ -627,7 +567,6 @@ void Camera2D::set_custom_viewport(Node *p_viewport) {
}
Node *Camera2D::get_custom_viewport() const {
-
return custom_viewport;
}
@@ -659,7 +598,6 @@ bool Camera2D::is_margin_drawing_enabled() const {
}
void Camera2D::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_offset", "offset"), &Camera2D::set_offset);
ClassDB::bind_method(D_METHOD("get_offset"), &Camera2D::get_offset);
@@ -777,7 +715,6 @@ void Camera2D::_bind_methods() {
}
Camera2D::Camera2D() {
-
anchor_mode = ANCHOR_MODE_DRAG_CENTER;
rotating = false;
current = false;