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.cpp45
1 files changed, 38 insertions, 7 deletions
diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp
index 67c1733759..fd8a0ed0f3 100644
--- a/scene/2d/camera_2d.cpp
+++ b/scene/2d/camera_2d.cpp
@@ -37,8 +37,7 @@ void Camera2D::_update_scroll() {
return;
if (get_tree()->is_editor_hint()) {
- // update(); //will just be drawn
- //??
+ update(); //will just be drawn
return;
}
@@ -85,7 +84,7 @@ Matrix32 Camera2D::get_camera_transform() {
if (anchor_mode==ANCHOR_MODE_DRAG_CENTER) {
- if (h_drag_enabled) {
+ if (h_drag_enabled && !get_tree()->is_editor_hint()) {
camera_pos.x = MIN( camera_pos.x, (new_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_RIGHT]));
camera_pos.x = MAX( camera_pos.x, (new_camera_pos.x - screen_size.x * 0.5 * drag_margin[MARGIN_LEFT]));
} else {
@@ -97,7 +96,7 @@ Matrix32 Camera2D::get_camera_transform() {
}
}
- if (v_drag_enabled) {
+ if (v_drag_enabled && !get_tree()->is_editor_hint()) {
camera_pos.y = MIN( camera_pos.y, (new_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_BOTTOM]));
camera_pos.y = MAX( camera_pos.y, (new_camera_pos.y - screen_size.y * 0.5 * drag_margin[MARGIN_TOP]));
@@ -118,7 +117,7 @@ Matrix32 Camera2D::get_camera_transform() {
- if (smoothing_enabled) {
+ if (smoothing_enabled && !get_tree()->is_editor_hint()) {
float c = smoothing*get_fixed_process_delta_time();
smoothed_camera_pos = ((camera_pos-smoothed_camera_pos)*c)+smoothed_camera_pos;
@@ -145,7 +144,7 @@ Matrix32 Camera2D::get_camera_transform() {
screen_offset = screen_offset.rotated(angle);
}
- Rect2 screen_rect(-screen_offset+ret_camera_pos,screen_size);
+ Rect2 screen_rect(-screen_offset+ret_camera_pos,screen_size*zoom);
if (screen_rect.pos.x + screen_rect.size.x > limit[MARGIN_RIGHT])
screen_rect.pos.x = limit[MARGIN_RIGHT] - screen_rect.size.x;
@@ -241,6 +240,10 @@ void Camera2D::_notification(int p_what) {
add_to_group(group_name);
add_to_group(canvas_group_name);
+ if(get_tree()->is_editor_hint()) {
+ set_fixed_process(false);
+ }
+
_update_scroll();
first=true;
@@ -258,6 +261,34 @@ void Camera2D::_notification(int p_what) {
viewport=NULL;
} break;
+ case NOTIFICATION_DRAW: {
+
+ if (!is_inside_tree() || !get_tree()->is_editor_hint())
+ break;
+
+ Color area_axis_color(0.5, 0.42, 0.87, 0.63);
+ float area_axis_width = 1;
+ if(current)
+ area_axis_width = 3;
+
+ Matrix32 inv_camera_transform = get_camera_transform().affine_inverse();
+ Size2 screen_size = get_viewport_rect().size;
+
+ Vector2 screen_endpoints[4]= {
+ inv_camera_transform.xform(Vector2(0, 0)),
+ inv_camera_transform.xform(Vector2(screen_size.width,0)),
+ inv_camera_transform.xform(Vector2(screen_size.width, screen_size.height)),
+ inv_camera_transform.xform(Vector2(0, screen_size.height))
+ };
+
+ Matrix32 inv_transform = get_transform().affine_inverse(); // undo global space
+ draw_set_transform(inv_transform.get_origin(), inv_transform.get_rotation(), inv_transform.get_scale());
+
+ for(int i=0;i<4;i++) {
+ draw_line(screen_endpoints[i], screen_endpoints[(i+1)%4], area_axis_color, area_axis_width);
+ }
+
+ } break;
}
}
@@ -383,7 +414,7 @@ void Camera2D::force_update_scroll() {
void Camera2D::set_follow_smoothing(float p_speed) {
smoothing=p_speed;
- if (smoothing>0)
+ if (smoothing>0 && !(is_inside_tree() && get_tree()->is_editor_hint()))
set_fixed_process(true);
else
set_fixed_process(false);