2014-02-10 02:10:30 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* camera_2d.cpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2014-03-14 02:57:24 +01:00
|
|
|
#include "camera_2d.h"
|
2019-06-12 22:35:35 +02:00
|
|
|
|
2022-02-12 02:46:22 +01:00
|
|
|
#include "core/config/project_settings.h"
|
2021-08-13 01:05:59 +02:00
|
|
|
#include "scene/main/window.h"
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2023-08-14 00:14:13 +02:00
|
|
|
bool Camera2D::_is_editing_in_editor() const {
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
return is_part_of_edited_scene();
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif // TOOLS_ENABLED
|
|
|
|
}
|
|
|
|
|
2014-03-14 02:57:24 +01:00
|
|
|
void Camera2D::_update_scroll() {
|
2023-08-14 00:14:13 +02:00
|
|
|
if (!is_inside_tree() || !viewport) {
|
2014-03-14 02:57:24 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2023-08-14 00:14:13 +02:00
|
|
|
if (_is_editing_in_editor()) {
|
2022-12-06 09:56:47 +01:00
|
|
|
queue_redraw();
|
2019-06-03 21:52:50 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-06-03 21:52:50 +02:00
|
|
|
|
2022-09-12 14:47:24 +02:00
|
|
|
if (is_current()) {
|
2016-09-14 20:55:14 +02:00
|
|
|
ERR_FAIL_COND(custom_viewport && !ObjectDB::get_instance(custom_viewport_id));
|
|
|
|
|
2024-02-17 00:57:32 +01:00
|
|
|
Transform2D xform;
|
|
|
|
if (is_physics_interpolated_and_enabled()) {
|
|
|
|
xform = _interpolation_data.xform_prev.interpolate_with(_interpolation_data.xform_curr, Engine::get_singleton()->get_physics_interpolation_fraction());
|
|
|
|
} else {
|
|
|
|
xform = get_camera_transform();
|
|
|
|
}
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2019-06-03 21:52:50 +02:00
|
|
|
viewport->set_canvas_transform(xform);
|
2017-10-26 21:08:40 +02:00
|
|
|
|
2020-04-30 01:45:07 +02:00
|
|
|
Size2 screen_size = _get_camera_screen_size();
|
2017-10-26 21:08:40 +02:00
|
|
|
Point2 screen_offset = (anchor_mode == ANCHOR_MODE_DRAG_CENTER ? (screen_size * 0.5) : Point2());
|
2024-01-17 18:09:52 +01:00
|
|
|
Point2 adj_screen_pos = camera_screen_center - (screen_size * 0.5);
|
2017-10-26 21:08:40 +02:00
|
|
|
|
2024-01-17 18:09:52 +01:00
|
|
|
// TODO: Remove xform and screen_offset when ParallaxBackground/ParallaxLayer is removed.
|
|
|
|
get_tree()->call_group(group_name, SNAME("_camera_moved"), xform, screen_offset, adj_screen_pos);
|
|
|
|
}
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
2021-02-18 19:52:29 +01:00
|
|
|
void Camera2D::_update_process_callback() {
|
2024-02-17 00:57:32 +01:00
|
|
|
if (is_physics_interpolated_and_enabled()) {
|
|
|
|
set_process_internal(is_current());
|
|
|
|
set_physics_process_internal(is_current());
|
|
|
|
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
if (process_callback == CAMERA2D_PROCESS_IDLE) {
|
|
|
|
WARN_PRINT_ONCE("Camera2D overridden to physics process mode due to use of physics interpolation.");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} else if (_is_editing_in_editor()) {
|
2019-01-06 14:57:41 +01:00
|
|
|
set_process_internal(false);
|
|
|
|
set_physics_process_internal(false);
|
|
|
|
} else {
|
2024-02-17 00:57:32 +01:00
|
|
|
if (process_callback == CAMERA2D_PROCESS_IDLE) {
|
|
|
|
set_process_internal(true);
|
|
|
|
set_physics_process_internal(false);
|
|
|
|
} else {
|
|
|
|
set_process_internal(false);
|
|
|
|
set_physics_process_internal(true);
|
|
|
|
}
|
2019-01-06 14:57:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-14 02:57:24 +01:00
|
|
|
void Camera2D::set_zoom(const Vector2 &p_zoom) {
|
2020-10-17 17:00:39 +02:00
|
|
|
// Setting zoom to zero causes 'affine_invert' issues
|
|
|
|
ERR_FAIL_COND_MSG(Math::is_zero_approx(p_zoom.x) || Math::is_zero_approx(p_zoom.y), "Zoom level must be different from 0 (can be negative).");
|
|
|
|
|
2014-03-14 02:57:24 +01:00
|
|
|
zoom = p_zoom;
|
2022-01-29 09:16:55 +01:00
|
|
|
zoom_scale = Vector2(1, 1) / zoom;
|
2015-09-04 00:23:39 +02:00
|
|
|
Point2 old_smoothed_camera_pos = smoothed_camera_pos;
|
2014-03-14 02:57:24 +01:00
|
|
|
_update_scroll();
|
2015-09-04 00:23:39 +02:00
|
|
|
smoothed_camera_pos = old_smoothed_camera_pos;
|
2014-03-14 02:57:24 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Vector2 Camera2D::get_zoom() const {
|
|
|
|
return zoom;
|
|
|
|
};
|
|
|
|
|
2017-01-11 04:52:51 +01:00
|
|
|
Transform2D Camera2D::get_camera_transform() {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!get_tree()) {
|
2017-01-11 04:52:51 +01:00
|
|
|
return Transform2D();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2017-01-11 04:52:51 +01:00
|
|
|
ERR_FAIL_COND_V(custom_viewport && !ObjectDB::get_instance(custom_viewport_id), Transform2D());
|
2016-09-15 13:17:23 +02:00
|
|
|
|
2020-04-30 01:45:07 +02:00
|
|
|
Size2 screen_size = _get_camera_screen_size();
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2021-08-14 10:16:57 +02:00
|
|
|
Point2 new_camera_pos = get_global_position();
|
2014-03-14 02:57:24 +01:00
|
|
|
Point2 ret_camera_pos;
|
|
|
|
|
|
|
|
if (!first) {
|
2015-06-11 14:55:38 +02:00
|
|
|
if (anchor_mode == ANCHOR_MODE_DRAG_CENTER) {
|
2023-08-14 00:14:13 +02:00
|
|
|
if (drag_horizontal_enabled && !_is_editing_in_editor() && !drag_horizontal_offset_changed) {
|
2022-01-29 09:16:55 +01:00
|
|
|
camera_pos.x = MIN(camera_pos.x, (new_camera_pos.x + screen_size.x * 0.5 * zoom_scale.x * drag_margin[SIDE_LEFT]));
|
|
|
|
camera_pos.x = MAX(camera_pos.x, (new_camera_pos.x - screen_size.x * 0.5 * zoom_scale.x * drag_margin[SIDE_RIGHT]));
|
2015-06-11 14:55:38 +02:00
|
|
|
} else {
|
2020-12-09 17:14:29 +01:00
|
|
|
if (drag_horizontal_offset < 0) {
|
|
|
|
camera_pos.x = new_camera_pos.x + screen_size.x * 0.5 * drag_margin[SIDE_RIGHT] * drag_horizontal_offset;
|
2015-06-11 14:55:38 +02:00
|
|
|
} else {
|
2020-12-09 17:14:29 +01:00
|
|
|
camera_pos.x = new_camera_pos.x + screen_size.x * 0.5 * drag_margin[SIDE_LEFT] * drag_horizontal_offset;
|
2015-06-11 14:55:38 +02:00
|
|
|
}
|
2019-03-14 13:58:29 +01:00
|
|
|
|
2020-12-09 17:14:29 +01:00
|
|
|
drag_horizontal_offset_changed = false;
|
2015-06-11 14:55:38 +02:00
|
|
|
}
|
|
|
|
|
2023-08-14 00:14:13 +02:00
|
|
|
if (drag_vertical_enabled && !_is_editing_in_editor() && !drag_vertical_offset_changed) {
|
2022-01-29 09:16:55 +01:00
|
|
|
camera_pos.y = MIN(camera_pos.y, (new_camera_pos.y + screen_size.y * 0.5 * zoom_scale.y * drag_margin[SIDE_TOP]));
|
|
|
|
camera_pos.y = MAX(camera_pos.y, (new_camera_pos.y - screen_size.y * 0.5 * zoom_scale.y * drag_margin[SIDE_BOTTOM]));
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2015-06-11 14:55:38 +02:00
|
|
|
} else {
|
2020-12-09 17:14:29 +01:00
|
|
|
if (drag_vertical_offset < 0) {
|
|
|
|
camera_pos.y = new_camera_pos.y + screen_size.y * 0.5 * drag_margin[SIDE_BOTTOM] * drag_vertical_offset;
|
2020-03-01 00:50:33 +01:00
|
|
|
} else {
|
2020-12-09 17:14:29 +01:00
|
|
|
camera_pos.y = new_camera_pos.y + screen_size.y * 0.5 * drag_margin[SIDE_TOP] * drag_vertical_offset;
|
2015-06-11 14:55:38 +02:00
|
|
|
}
|
2019-03-14 13:58:29 +01:00
|
|
|
|
2020-12-09 17:14:29 +01:00
|
|
|
drag_vertical_offset_changed = false;
|
2015-06-11 14:55:38 +02:00
|
|
|
}
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2015-06-11 14:55:38 +02:00
|
|
|
} else if (anchor_mode == ANCHOR_MODE_FIXED_TOP_LEFT) {
|
|
|
|
camera_pos = new_camera_pos;
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
2022-01-29 09:16:55 +01:00
|
|
|
Point2 screen_offset = (anchor_mode == ANCHOR_MODE_DRAG_CENTER ? (screen_size * 0.5 * zoom_scale) : Point2());
|
|
|
|
Rect2 screen_rect(-screen_offset + camera_pos, screen_size * zoom_scale);
|
2017-03-05 16:44:50 +01:00
|
|
|
|
2016-07-13 11:48:50 +02:00
|
|
|
if (limit_smoothing_enabled) {
|
2020-12-22 17:24:29 +01:00
|
|
|
if (screen_rect.position.x < limit[SIDE_LEFT]) {
|
|
|
|
camera_pos.x -= screen_rect.position.x - limit[SIDE_LEFT];
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
|
2020-12-22 17:24:29 +01:00
|
|
|
if (screen_rect.position.x + screen_rect.size.x > limit[SIDE_RIGHT]) {
|
|
|
|
camera_pos.x -= screen_rect.position.x + screen_rect.size.x - limit[SIDE_RIGHT];
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-07-13 11:48:50 +02:00
|
|
|
|
2020-12-22 17:24:29 +01:00
|
|
|
if (screen_rect.position.y + screen_rect.size.y > limit[SIDE_BOTTOM]) {
|
|
|
|
camera_pos.y -= screen_rect.position.y + screen_rect.size.y - limit[SIDE_BOTTOM];
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-07-13 11:48:50 +02:00
|
|
|
|
2020-12-22 17:24:29 +01:00
|
|
|
if (screen_rect.position.y < limit[SIDE_TOP]) {
|
|
|
|
camera_pos.y -= screen_rect.position.y - limit[SIDE_TOP];
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-07-13 11:48:50 +02:00
|
|
|
}
|
2015-06-11 14:55:38 +02:00
|
|
|
|
2024-02-17 00:57:32 +01:00
|
|
|
// FIXME: There is a bug here, introduced before physics interpolation.
|
|
|
|
// Smoothing occurs rather confusingly during the call to get_camera_transform().
|
|
|
|
// It may be called MULTIPLE TIMES on certain frames,
|
|
|
|
// therefore smoothing is not currently applied only once per frame / tick,
|
|
|
|
// which will result in some haphazard results.
|
2023-08-14 00:14:13 +02:00
|
|
|
if (position_smoothing_enabled && !_is_editing_in_editor()) {
|
2024-02-17 00:57:32 +01:00
|
|
|
bool physics_process = (process_callback == CAMERA2D_PROCESS_PHYSICS) || is_physics_interpolated_and_enabled();
|
|
|
|
real_t delta = physics_process ? get_physics_process_delta_time() : get_process_delta_time();
|
|
|
|
real_t c = position_smoothing_speed * delta;
|
2015-12-12 13:26:13 +01:00
|
|
|
smoothed_camera_pos = ((camera_pos - smoothed_camera_pos) * c) + smoothed_camera_pos;
|
2014-03-14 02:57:24 +01:00
|
|
|
ret_camera_pos = smoothed_camera_pos;
|
2022-09-14 13:38:15 +02:00
|
|
|
//camera_pos=camera_pos*(1.0-position_smoothing_speed)+new_camera_pos*position_smoothing_speed;
|
2014-03-14 02:57:24 +01:00
|
|
|
} else {
|
|
|
|
ret_camera_pos = smoothed_camera_pos = camera_pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
ret_camera_pos = smoothed_camera_pos = camera_pos = new_camera_pos;
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
|
2022-01-29 09:16:55 +01:00
|
|
|
Point2 screen_offset = (anchor_mode == ANCHOR_MODE_DRAG_CENTER ? (screen_size * 0.5 * zoom_scale) : Point2());
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2022-08-13 13:37:10 +02:00
|
|
|
if (!ignore_rotation) {
|
2023-08-14 00:14:13 +02:00
|
|
|
if (rotation_smoothing_enabled && !_is_editing_in_editor()) {
|
2020-04-28 15:34:27 +02:00
|
|
|
real_t step = rotation_smoothing_speed * (process_callback == CAMERA2D_PROCESS_PHYSICS ? get_physics_process_delta_time() : get_process_delta_time());
|
|
|
|
camera_angle = Math::lerp_angle(camera_angle, get_global_rotation(), step);
|
|
|
|
} else {
|
|
|
|
camera_angle = get_global_rotation();
|
|
|
|
}
|
|
|
|
screen_offset = screen_offset.rotated(camera_angle);
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
2022-01-29 09:16:55 +01:00
|
|
|
Rect2 screen_rect(-screen_offset + ret_camera_pos, screen_size * zoom_scale);
|
2017-03-05 16:44:50 +01:00
|
|
|
|
2023-03-02 20:53:25 +01:00
|
|
|
if (!position_smoothing_enabled || !limit_smoothing_enabled) {
|
2021-06-08 00:42:48 +02:00
|
|
|
if (screen_rect.position.x < limit[SIDE_LEFT]) {
|
|
|
|
screen_rect.position.x = limit[SIDE_LEFT];
|
|
|
|
}
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2021-06-08 00:42:48 +02:00
|
|
|
if (screen_rect.position.x + screen_rect.size.x > limit[SIDE_RIGHT]) {
|
|
|
|
screen_rect.position.x = limit[SIDE_RIGHT] - screen_rect.size.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (screen_rect.position.y + screen_rect.size.y > limit[SIDE_BOTTOM]) {
|
|
|
|
screen_rect.position.y = limit[SIDE_BOTTOM] - screen_rect.size.y;
|
|
|
|
}
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2021-06-08 00:42:48 +02:00
|
|
|
if (screen_rect.position.y < limit[SIDE_TOP]) {
|
|
|
|
screen_rect.position.y = limit[SIDE_TOP];
|
|
|
|
}
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (offset != Vector2()) {
|
2017-06-04 00:25:13 +02:00
|
|
|
screen_rect.position += offset;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2017-01-11 04:52:51 +01:00
|
|
|
Transform2D xform;
|
2022-01-29 09:16:55 +01:00
|
|
|
xform.scale_basis(zoom_scale);
|
2022-08-13 13:37:10 +02:00
|
|
|
if (!ignore_rotation) {
|
2020-04-28 15:34:27 +02:00
|
|
|
xform.set_rotation(camera_angle);
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
2022-02-15 18:06:48 +01:00
|
|
|
xform.set_origin(screen_rect.position);
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2023-10-16 09:02:49 +02:00
|
|
|
camera_screen_center = xform.xform(0.5 * screen_size);
|
|
|
|
|
|
|
|
return xform.affine_inverse();
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
2024-02-17 00:57:32 +01:00
|
|
|
void Camera2D::_ensure_update_interpolation_data() {
|
|
|
|
// The "curr -> previous" update can either occur
|
|
|
|
// on NOTIFICATION_INTERNAL_PHYSICS_PROCESS, OR
|
|
|
|
// on NOTIFICATION_TRANSFORM_CHANGED,
|
|
|
|
// if NOTIFICATION_TRANSFORM_CHANGED takes place earlier than
|
|
|
|
// NOTIFICATION_INTERNAL_PHYSICS_PROCESS on a tick.
|
|
|
|
// This is to ensure that the data keeps flowing, but the new data
|
|
|
|
// doesn't overwrite before prev has been set.
|
|
|
|
|
|
|
|
// Keep the data flowing.
|
|
|
|
uint64_t tick = Engine::get_singleton()->get_physics_frames();
|
|
|
|
if (_interpolation_data.last_update_physics_tick != tick) {
|
|
|
|
_interpolation_data.xform_prev = _interpolation_data.xform_curr;
|
|
|
|
_interpolation_data.last_update_physics_tick = tick;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-14 02:57:24 +01:00
|
|
|
void Camera2D::_notification(int p_what) {
|
|
|
|
switch (p_what) {
|
2024-02-17 00:57:32 +01:00
|
|
|
case NOTIFICATION_INTERNAL_PROCESS: {
|
2014-03-14 02:57:24 +01:00
|
|
|
_update_scroll();
|
|
|
|
} break;
|
2022-02-15 18:06:48 +01:00
|
|
|
|
2024-02-17 00:57:32 +01:00
|
|
|
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
|
|
|
|
if (is_physics_interpolated_and_enabled()) {
|
|
|
|
_ensure_update_interpolation_data();
|
|
|
|
_interpolation_data.xform_curr = get_camera_transform();
|
|
|
|
} else {
|
|
|
|
_update_scroll();
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case NOTIFICATION_RESET_PHYSICS_INTERPOLATION: {
|
|
|
|
// Force the limits etc. to update.
|
|
|
|
_interpolation_data.xform_curr = get_camera_transform();
|
|
|
|
_interpolation_data.xform_prev = _interpolation_data.xform_curr;
|
|
|
|
} break;
|
|
|
|
|
2014-03-14 02:57:24 +01:00
|
|
|
case NOTIFICATION_TRANSFORM_CHANGED: {
|
2024-02-17 00:57:32 +01:00
|
|
|
if ((!position_smoothing_enabled && !is_physics_interpolated_and_enabled()) || _is_editing_in_editor()) {
|
2014-03-14 02:57:24 +01:00
|
|
|
_update_scroll();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2024-02-17 00:57:32 +01:00
|
|
|
if (is_physics_interpolated_and_enabled()) {
|
|
|
|
_ensure_update_interpolation_data();
|
|
|
|
_interpolation_data.xform_curr = get_camera_transform();
|
|
|
|
}
|
2014-03-14 02:57:24 +01:00
|
|
|
} break;
|
2022-02-15 18:06:48 +01:00
|
|
|
|
2014-11-06 01:20:42 +01:00
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
2021-10-23 22:30:18 +02:00
|
|
|
ERR_FAIL_COND(!is_inside_tree());
|
2016-09-14 20:55:14 +02:00
|
|
|
if (custom_viewport && ObjectDB::get_instance(custom_viewport_id)) {
|
|
|
|
viewport = custom_viewport;
|
|
|
|
} else {
|
|
|
|
viewport = get_viewport();
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
canvas = get_canvas();
|
|
|
|
|
2017-01-14 15:07:57 +01:00
|
|
|
RID vp = viewport->get_viewport_rid();
|
2014-03-14 02:57:24 +01:00
|
|
|
|
|
|
|
group_name = "__cameras_" + itos(vp.get_id());
|
|
|
|
canvas_group_name = "__cameras_c" + itos(canvas.get_id());
|
|
|
|
add_to_group(group_name);
|
|
|
|
add_to_group(canvas_group_name);
|
|
|
|
|
2023-08-14 00:14:13 +02:00
|
|
|
if (!_is_editing_in_editor() && enabled && !viewport->get_camera_2d()) {
|
2022-09-12 14:47:24 +02:00
|
|
|
make_current();
|
|
|
|
}
|
|
|
|
|
2021-02-18 19:52:29 +01:00
|
|
|
_update_process_callback();
|
2014-03-14 02:57:24 +01:00
|
|
|
first = true;
|
2022-07-28 16:29:38 +02:00
|
|
|
_update_scroll();
|
2024-02-17 00:57:32 +01:00
|
|
|
|
|
|
|
// Note that NOTIFICATION_RESET_PHYSICS_INTERPOLATION
|
|
|
|
// is automatically called before this because Camera2D is inherited
|
|
|
|
// from CanvasItem. However, the camera transform is not up to date
|
|
|
|
// until this point, so we do an extra manual reset.
|
|
|
|
if (is_physics_interpolated_and_enabled()) {
|
|
|
|
_interpolation_data.xform_curr = get_camera_transform();
|
|
|
|
_interpolation_data.xform_prev = _interpolation_data.xform_curr;
|
|
|
|
}
|
2014-03-14 02:57:24 +01:00
|
|
|
} break;
|
2022-02-15 18:06:48 +01:00
|
|
|
|
2014-11-06 01:20:42 +01:00
|
|
|
case NOTIFICATION_EXIT_TREE: {
|
2023-02-01 23:32:13 +01:00
|
|
|
remove_from_group(group_name);
|
|
|
|
remove_from_group(canvas_group_name);
|
2016-09-14 20:55:14 +02:00
|
|
|
if (is_current()) {
|
2022-09-12 14:47:24 +02:00
|
|
|
clear_current();
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
2020-04-02 01:20:12 +02:00
|
|
|
viewport = nullptr;
|
2023-02-10 23:46:55 +01:00
|
|
|
just_exited_tree = true;
|
|
|
|
callable_mp(this, &Camera2D::_reset_just_exited).call_deferred();
|
2014-03-14 02:57:24 +01:00
|
|
|
} break;
|
2022-02-15 18:06:48 +01:00
|
|
|
|
2020-02-10 03:08:18 +01:00
|
|
|
#ifdef TOOLS_ENABLED
|
2016-04-19 15:07:06 +02:00
|
|
|
case NOTIFICATION_DRAW: {
|
2023-08-14 00:14:13 +02:00
|
|
|
if (!is_inside_tree() || !_is_editing_in_editor()) {
|
2016-04-19 15:07:06 +02:00
|
|
|
break;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-04-19 15:07:06 +02:00
|
|
|
|
2017-06-20 23:00:46 +02:00
|
|
|
if (screen_drawing_enabled) {
|
2021-05-27 07:10:16 +02:00
|
|
|
Color area_axis_color(1, 0.4, 1, 0.63);
|
2023-02-24 05:20:24 +01:00
|
|
|
real_t area_axis_width = -1;
|
2017-06-20 23:00:46 +02:00
|
|
|
if (is_current()) {
|
|
|
|
area_axis_width = 3;
|
|
|
|
}
|
2016-04-19 15:07:06 +02:00
|
|
|
|
2017-06-20 23:00:46 +02:00
|
|
|
Transform2D inv_camera_transform = get_camera_transform().affine_inverse();
|
2020-04-30 01:45:07 +02:00
|
|
|
Size2 screen_size = _get_camera_screen_size();
|
2016-04-19 15:07:06 +02:00
|
|
|
|
2017-06-20 23:00:46 +02:00
|
|
|
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))
|
|
|
|
};
|
2016-04-19 15:07:06 +02:00
|
|
|
|
2017-06-20 23:00:46 +02:00
|
|
|
Transform2D inv_transform = get_global_transform().affine_inverse(); // undo global space
|
2016-04-19 15:07:06 +02:00
|
|
|
|
2017-06-20 23:00:46 +02:00
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
draw_line(inv_transform.xform(screen_endpoints[i]), inv_transform.xform(screen_endpoints[(i + 1) % 4]), area_axis_color, area_axis_width);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (limit_drawing_enabled) {
|
2021-05-27 07:10:16 +02:00
|
|
|
Color limit_drawing_color(1, 1, 0.25, 0.63);
|
2023-02-24 05:20:24 +01:00
|
|
|
real_t limit_drawing_width = -1;
|
2017-06-20 23:00:46 +02:00
|
|
|
if (is_current()) {
|
|
|
|
limit_drawing_width = 3;
|
|
|
|
}
|
|
|
|
|
2021-08-14 10:16:57 +02:00
|
|
|
Vector2 camera_origin = get_global_position();
|
|
|
|
Vector2 camera_scale = get_global_scale().abs();
|
2017-06-20 23:00:46 +02:00
|
|
|
Vector2 limit_points[4] = {
|
2020-12-22 17:24:29 +01:00
|
|
|
(Vector2(limit[SIDE_LEFT], limit[SIDE_TOP]) - camera_origin) / camera_scale,
|
|
|
|
(Vector2(limit[SIDE_RIGHT], limit[SIDE_TOP]) - camera_origin) / camera_scale,
|
|
|
|
(Vector2(limit[SIDE_RIGHT], limit[SIDE_BOTTOM]) - camera_origin) / camera_scale,
|
|
|
|
(Vector2(limit[SIDE_LEFT], limit[SIDE_BOTTOM]) - camera_origin) / camera_scale
|
2017-06-20 23:00:46 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
draw_line(limit_points[i], limit_points[(i + 1) % 4], limit_drawing_color, limit_drawing_width);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (margin_drawing_enabled) {
|
2021-05-27 07:10:16 +02:00
|
|
|
Color margin_drawing_color(0.25, 1, 1, 0.63);
|
2023-02-24 05:20:24 +01:00
|
|
|
real_t margin_drawing_width = -1;
|
2017-06-20 23:00:46 +02:00
|
|
|
if (is_current()) {
|
|
|
|
margin_drawing_width = 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
Transform2D inv_camera_transform = get_camera_transform().affine_inverse();
|
2020-04-30 01:45:07 +02:00
|
|
|
Size2 screen_size = _get_camera_screen_size();
|
2017-06-20 23:00:46 +02:00
|
|
|
|
|
|
|
Vector2 margin_endpoints[4] = {
|
2020-12-22 17:24:29 +01:00
|
|
|
inv_camera_transform.xform(Vector2((screen_size.width / 2) - ((screen_size.width / 2) * drag_margin[SIDE_LEFT]), (screen_size.height / 2) - ((screen_size.height / 2) * drag_margin[SIDE_TOP]))),
|
|
|
|
inv_camera_transform.xform(Vector2((screen_size.width / 2) + ((screen_size.width / 2) * drag_margin[SIDE_RIGHT]), (screen_size.height / 2) - ((screen_size.height / 2) * drag_margin[SIDE_TOP]))),
|
|
|
|
inv_camera_transform.xform(Vector2((screen_size.width / 2) + ((screen_size.width / 2) * drag_margin[SIDE_RIGHT]), (screen_size.height / 2) + ((screen_size.height / 2) * drag_margin[SIDE_BOTTOM]))),
|
|
|
|
inv_camera_transform.xform(Vector2((screen_size.width / 2) - ((screen_size.width / 2) * drag_margin[SIDE_LEFT]), (screen_size.height / 2) + ((screen_size.height / 2) * drag_margin[SIDE_BOTTOM])))
|
2017-06-20 23:00:46 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Transform2D inv_transform = get_global_transform().affine_inverse(); // undo global space
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
draw_line(inv_transform.xform(margin_endpoints[i]), inv_transform.xform(margin_endpoints[(i + 1) % 4]), margin_drawing_color, margin_drawing_width);
|
|
|
|
}
|
2016-04-19 15:07:06 +02:00
|
|
|
}
|
|
|
|
} break;
|
2020-02-10 03:08:18 +01:00
|
|
|
#endif
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Camera2D::set_offset(const Vector2 &p_offset) {
|
|
|
|
offset = p_offset;
|
2020-06-15 16:27:59 +02:00
|
|
|
Point2 old_smoothed_camera_pos = smoothed_camera_pos;
|
2014-03-14 02:57:24 +01:00
|
|
|
_update_scroll();
|
2020-06-15 16:27:59 +02:00
|
|
|
smoothed_camera_pos = old_smoothed_camera_pos;
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Vector2 Camera2D::get_offset() const {
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
2015-06-11 14:55:38 +02:00
|
|
|
void Camera2D::set_anchor_mode(AnchorMode p_anchor_mode) {
|
|
|
|
anchor_mode = p_anchor_mode;
|
2014-03-14 02:57:24 +01:00
|
|
|
_update_scroll();
|
|
|
|
}
|
|
|
|
|
2015-06-11 14:55:38 +02:00
|
|
|
Camera2D::AnchorMode Camera2D::get_anchor_mode() const {
|
|
|
|
return anchor_mode;
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
2022-08-13 13:37:10 +02:00
|
|
|
void Camera2D::set_ignore_rotation(bool p_ignore) {
|
|
|
|
ignore_rotation = p_ignore;
|
2020-06-15 16:27:59 +02:00
|
|
|
Point2 old_smoothed_camera_pos = smoothed_camera_pos;
|
2020-04-28 15:34:27 +02:00
|
|
|
|
|
|
|
// Reset back to zero so it matches the camera rotation when ignore_rotation is enabled.
|
|
|
|
if (ignore_rotation) {
|
|
|
|
camera_angle = 0.0;
|
|
|
|
}
|
|
|
|
|
2014-03-14 02:57:24 +01:00
|
|
|
_update_scroll();
|
2020-06-15 16:27:59 +02:00
|
|
|
smoothed_camera_pos = old_smoothed_camera_pos;
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
2022-08-13 13:37:10 +02:00
|
|
|
bool Camera2D::is_ignoring_rotation() const {
|
|
|
|
return ignore_rotation;
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
2021-02-18 19:52:29 +01:00
|
|
|
void Camera2D::set_process_callback(Camera2DProcessCallback p_mode) {
|
|
|
|
if (process_callback == p_mode) {
|
2019-01-06 14:57:41 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-01-06 14:57:41 +01:00
|
|
|
|
2021-02-18 19:52:29 +01:00
|
|
|
process_callback = p_mode;
|
|
|
|
_update_process_callback();
|
2019-01-06 14:57:41 +01:00
|
|
|
}
|
|
|
|
|
2022-09-12 14:47:24 +02:00
|
|
|
void Camera2D::set_enabled(bool p_enabled) {
|
|
|
|
enabled = p_enabled;
|
|
|
|
|
2023-08-14 00:14:13 +02:00
|
|
|
if (!is_inside_tree()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enabled && !viewport->get_camera_2d()) {
|
2022-09-12 14:47:24 +02:00
|
|
|
make_current();
|
|
|
|
} else if (!enabled && is_current()) {
|
|
|
|
clear_current();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Camera2D::is_enabled() const {
|
|
|
|
return enabled;
|
|
|
|
}
|
|
|
|
|
2021-02-18 19:52:29 +01:00
|
|
|
Camera2D::Camera2DProcessCallback Camera2D::get_process_callback() const {
|
|
|
|
return process_callback;
|
2019-01-06 14:57:41 +01:00
|
|
|
}
|
|
|
|
|
2014-03-14 02:57:24 +01:00
|
|
|
void Camera2D::_make_current(Object *p_which) {
|
2023-08-14 00:14:13 +02:00
|
|
|
if (!is_inside_tree() || !viewport) {
|
2023-02-23 23:21:50 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-08-14 00:14:13 +02:00
|
|
|
if (custom_viewport && !ObjectDB::get_instance(custom_viewport_id)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
queue_redraw();
|
|
|
|
|
2024-02-17 00:57:32 +01:00
|
|
|
bool was_current = viewport->get_camera_2d() == this;
|
|
|
|
bool is_current = p_which == this;
|
|
|
|
|
|
|
|
if (is_current) {
|
2023-08-14 00:14:13 +02:00
|
|
|
viewport->_camera_2d_set(this);
|
2024-02-17 00:57:32 +01:00
|
|
|
} else if (was_current) {
|
|
|
|
viewport->_camera_2d_set(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_current != was_current) {
|
|
|
|
_update_process_callback();
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-28 15:34:27 +02:00
|
|
|
void Camera2D::_update_process_internal_for_smoothing() {
|
2023-08-14 00:14:13 +02:00
|
|
|
bool is_not_in_scene_or_editor = !(is_inside_tree() && _is_editing_in_editor());
|
2022-09-14 13:38:15 +02:00
|
|
|
bool is_any_smoothing_valid = position_smoothing_speed > 0 || rotation_smoothing_speed > 0;
|
2020-04-28 15:34:27 +02:00
|
|
|
|
2022-09-12 14:47:24 +02:00
|
|
|
bool enable = is_any_smoothing_valid && is_not_in_scene_or_editor;
|
|
|
|
set_process_internal(enable);
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Camera2D::make_current() {
|
2022-09-12 14:47:24 +02:00
|
|
|
ERR_FAIL_COND(!enabled || !is_inside_tree());
|
|
|
|
get_tree()->call_group(group_name, "_make_current", this);
|
2023-02-10 23:46:55 +01:00
|
|
|
if (just_exited_tree) {
|
|
|
|
// If camera exited the scene tree in the same frame, group call will skip it, so this needs to be called manually.
|
|
|
|
_make_current(this);
|
|
|
|
}
|
2019-01-01 18:47:34 +01:00
|
|
|
_update_scroll();
|
2024-02-17 00:57:32 +01:00
|
|
|
_update_process_callback();
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
2015-03-03 18:39:13 +01:00
|
|
|
void Camera2D::clear_current() {
|
2022-09-12 14:47:24 +02:00
|
|
|
ERR_FAIL_COND(!is_current());
|
2023-08-14 00:14:13 +02:00
|
|
|
|
|
|
|
if (!viewport || !viewport->is_inside_tree()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!custom_viewport || ObjectDB::get_instance(custom_viewport_id)) {
|
2022-09-12 14:47:24 +02:00
|
|
|
viewport->assign_next_enabled_camera_2d(group_name);
|
|
|
|
}
|
2024-02-17 00:57:32 +01:00
|
|
|
|
|
|
|
_update_process_callback();
|
2022-09-12 14:47:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Camera2D::is_current() const {
|
2023-08-14 00:14:13 +02:00
|
|
|
if (!viewport) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!custom_viewport || ObjectDB::get_instance(custom_viewport_id)) {
|
2022-09-12 14:47:24 +02:00
|
|
|
return viewport->get_camera_2d() == this;
|
2015-03-03 18:39:13 +01:00
|
|
|
}
|
2022-09-12 14:47:24 +02:00
|
|
|
return false;
|
2015-03-03 18:39:13 +01:00
|
|
|
}
|
|
|
|
|
2020-12-22 17:24:29 +01:00
|
|
|
void Camera2D::set_limit(Side p_side, int p_limit) {
|
|
|
|
ERR_FAIL_INDEX((int)p_side, 4);
|
|
|
|
limit[p_side] = p_limit;
|
2022-07-28 16:32:45 +02:00
|
|
|
Point2 old_smoothed_camera_pos = smoothed_camera_pos;
|
2022-07-16 17:03:54 +02:00
|
|
|
_update_scroll();
|
2022-07-28 16:32:45 +02:00
|
|
|
smoothed_camera_pos = old_smoothed_camera_pos;
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
2020-12-22 17:24:29 +01:00
|
|
|
int Camera2D::get_limit(Side p_side) const {
|
|
|
|
ERR_FAIL_INDEX_V((int)p_side, 4, 0);
|
|
|
|
return limit[p_side];
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
2016-07-13 11:48:50 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-01-30 05:10:32 +01:00
|
|
|
void Camera2D::set_drag_margin(Side p_side, real_t p_drag_margin) {
|
2020-12-22 17:24:29 +01:00
|
|
|
ERR_FAIL_INDEX((int)p_side, 4);
|
|
|
|
drag_margin[p_side] = p_drag_margin;
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
2021-01-30 05:10:32 +01:00
|
|
|
real_t Camera2D::get_drag_margin(Side p_side) const {
|
2020-12-22 17:24:29 +01:00
|
|
|
ERR_FAIL_INDEX_V((int)p_side, 4, 0);
|
|
|
|
return drag_margin[p_side];
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
2017-09-10 15:37:49 +02:00
|
|
|
Vector2 Camera2D::get_camera_position() const {
|
2014-03-14 02:57:24 +01:00
|
|
|
return camera_pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Camera2D::force_update_scroll() {
|
|
|
|
_update_scroll();
|
|
|
|
}
|
|
|
|
|
2016-06-29 17:39:29 +02:00
|
|
|
void Camera2D::reset_smoothing() {
|
|
|
|
_update_scroll();
|
2021-07-27 12:59:30 +02:00
|
|
|
smoothed_camera_pos = camera_pos;
|
2016-06-29 17:39:29 +02:00
|
|
|
}
|
|
|
|
|
2016-06-29 18:17:11 +02:00
|
|
|
void Camera2D::align() {
|
2016-09-15 13:17:23 +02:00
|
|
|
ERR_FAIL_COND(custom_viewport && !ObjectDB::get_instance(custom_viewport_id));
|
|
|
|
|
2020-04-30 01:45:07 +02:00
|
|
|
Size2 screen_size = _get_camera_screen_size();
|
2016-09-15 13:17:23 +02:00
|
|
|
|
2021-08-14 10:16:57 +02:00
|
|
|
Point2 current_camera_pos = get_global_position();
|
2016-06-29 18:17:11 +02:00
|
|
|
if (anchor_mode == ANCHOR_MODE_DRAG_CENTER) {
|
2020-12-09 17:14:29 +01:00
|
|
|
if (drag_horizontal_offset < 0) {
|
|
|
|
camera_pos.x = current_camera_pos.x + screen_size.x * 0.5 * drag_margin[SIDE_RIGHT] * drag_horizontal_offset;
|
2016-06-29 18:17:11 +02:00
|
|
|
} else {
|
2020-12-09 17:14:29 +01:00
|
|
|
camera_pos.x = current_camera_pos.x + screen_size.x * 0.5 * drag_margin[SIDE_LEFT] * drag_horizontal_offset;
|
2016-06-29 18:17:11 +02:00
|
|
|
}
|
2020-12-09 17:14:29 +01:00
|
|
|
if (drag_vertical_offset < 0) {
|
|
|
|
camera_pos.y = current_camera_pos.y + screen_size.y * 0.5 * drag_margin[SIDE_TOP] * drag_vertical_offset;
|
2016-06-29 18:17:11 +02:00
|
|
|
} else {
|
2020-12-09 17:14:29 +01:00
|
|
|
camera_pos.y = current_camera_pos.y + screen_size.y * 0.5 * drag_margin[SIDE_BOTTOM] * drag_vertical_offset;
|
2016-06-29 18:17:11 +02:00
|
|
|
}
|
|
|
|
} else if (anchor_mode == ANCHOR_MODE_FIXED_TOP_LEFT) {
|
|
|
|
camera_pos = current_camera_pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
_update_scroll();
|
|
|
|
}
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2022-09-14 13:38:15 +02:00
|
|
|
void Camera2D::set_position_smoothing_speed(real_t p_speed) {
|
2024-04-03 12:35:18 +02:00
|
|
|
position_smoothing_speed = MAX(0, p_speed);
|
2020-04-28 15:34:27 +02:00
|
|
|
_update_process_internal_for_smoothing();
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
2022-09-14 13:38:15 +02:00
|
|
|
real_t Camera2D::get_position_smoothing_speed() const {
|
|
|
|
return position_smoothing_speed;
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
2020-04-28 15:34:27 +02:00
|
|
|
void Camera2D::set_rotation_smoothing_speed(real_t p_speed) {
|
2024-04-03 12:35:18 +02:00
|
|
|
rotation_smoothing_speed = MAX(0, p_speed);
|
2020-04-28 15:34:27 +02:00
|
|
|
_update_process_internal_for_smoothing();
|
|
|
|
}
|
|
|
|
|
|
|
|
real_t Camera2D::get_rotation_smoothing_speed() const {
|
|
|
|
return rotation_smoothing_speed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Camera2D::set_rotation_smoothing_enabled(bool p_enabled) {
|
|
|
|
rotation_smoothing_enabled = p_enabled;
|
|
|
|
notify_property_list_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Camera2D::is_rotation_smoothing_enabled() const {
|
|
|
|
return rotation_smoothing_enabled;
|
|
|
|
}
|
|
|
|
|
2014-03-14 02:57:24 +01:00
|
|
|
Point2 Camera2D::get_camera_screen_center() const {
|
|
|
|
return camera_screen_center;
|
|
|
|
}
|
|
|
|
|
2020-04-30 01:45:07 +02:00
|
|
|
Size2 Camera2D::_get_camera_screen_size() const {
|
2023-08-14 00:14:13 +02:00
|
|
|
if (_is_editing_in_editor()) {
|
2022-10-18 16:43:37 +02:00
|
|
|
return Size2(GLOBAL_GET("display/window/size/viewport_width"), GLOBAL_GET("display/window/size/viewport_height"));
|
2020-04-30 01:45:07 +02:00
|
|
|
}
|
|
|
|
return get_viewport_rect().size;
|
|
|
|
}
|
|
|
|
|
2020-12-09 17:14:29 +01:00
|
|
|
void Camera2D::set_drag_horizontal_enabled(bool p_enabled) {
|
|
|
|
drag_horizontal_enabled = p_enabled;
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
2020-12-09 17:14:29 +01:00
|
|
|
bool Camera2D::is_drag_horizontal_enabled() const {
|
|
|
|
return drag_horizontal_enabled;
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
2020-12-09 17:14:29 +01:00
|
|
|
void Camera2D::set_drag_vertical_enabled(bool p_enabled) {
|
|
|
|
drag_vertical_enabled = p_enabled;
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
2020-12-09 17:14:29 +01:00
|
|
|
bool Camera2D::is_drag_vertical_enabled() const {
|
|
|
|
return drag_vertical_enabled;
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
2021-01-30 05:10:32 +01:00
|
|
|
void Camera2D::set_drag_vertical_offset(real_t p_offset) {
|
2020-12-09 17:14:29 +01:00
|
|
|
drag_vertical_offset = p_offset;
|
|
|
|
drag_vertical_offset_changed = true;
|
2020-06-15 16:27:59 +02:00
|
|
|
Point2 old_smoothed_camera_pos = smoothed_camera_pos;
|
2018-01-11 23:35:12 +01:00
|
|
|
_update_scroll();
|
2020-06-15 16:27:59 +02:00
|
|
|
smoothed_camera_pos = old_smoothed_camera_pos;
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
2021-01-30 05:10:32 +01:00
|
|
|
real_t Camera2D::get_drag_vertical_offset() const {
|
2020-12-09 17:14:29 +01:00
|
|
|
return drag_vertical_offset;
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
2021-01-30 05:10:32 +01:00
|
|
|
void Camera2D::set_drag_horizontal_offset(real_t p_offset) {
|
2020-12-09 17:14:29 +01:00
|
|
|
drag_horizontal_offset = p_offset;
|
|
|
|
drag_horizontal_offset_changed = true;
|
2020-06-15 16:27:59 +02:00
|
|
|
Point2 old_smoothed_camera_pos = smoothed_camera_pos;
|
2018-01-11 23:35:12 +01:00
|
|
|
_update_scroll();
|
2020-06-15 16:27:59 +02:00
|
|
|
smoothed_camera_pos = old_smoothed_camera_pos;
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2021-01-30 05:10:32 +01:00
|
|
|
real_t Camera2D::get_drag_horizontal_offset() const {
|
2020-12-09 17:14:29 +01:00
|
|
|
return drag_horizontal_offset;
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
2021-01-30 05:10:32 +01:00
|
|
|
void Camera2D::_set_old_smoothing(real_t p_enable) {
|
2015-12-12 13:26:13 +01:00
|
|
|
//compatibility
|
2017-08-11 21:10:05 +02:00
|
|
|
if (p_enable > 0) {
|
2023-03-02 20:53:25 +01:00
|
|
|
position_smoothing_enabled = true;
|
2022-09-14 13:38:15 +02:00
|
|
|
set_position_smoothing_speed(p_enable);
|
2015-12-12 13:26:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-14 13:38:15 +02:00
|
|
|
void Camera2D::set_position_smoothing_enabled(bool p_enabled) {
|
2023-03-02 20:53:25 +01:00
|
|
|
position_smoothing_enabled = p_enabled;
|
2021-03-04 00:51:35 +01:00
|
|
|
notify_property_list_changed();
|
2015-12-12 13:26:13 +01:00
|
|
|
}
|
|
|
|
|
2022-09-14 13:38:15 +02:00
|
|
|
bool Camera2D::is_position_smoothing_enabled() const {
|
2023-03-02 20:53:25 +01:00
|
|
|
return position_smoothing_enabled;
|
2015-12-12 13:26:13 +01:00
|
|
|
}
|
|
|
|
|
2016-09-14 20:55:14 +02:00
|
|
|
void Camera2D::set_custom_viewport(Node *p_viewport) {
|
|
|
|
ERR_FAIL_NULL(p_viewport);
|
|
|
|
if (is_inside_tree()) {
|
|
|
|
remove_from_group(group_name);
|
|
|
|
remove_from_group(canvas_group_name);
|
|
|
|
}
|
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
custom_viewport = Object::cast_to<Viewport>(p_viewport);
|
2016-09-14 20:55:14 +02:00
|
|
|
|
|
|
|
if (custom_viewport) {
|
2017-08-07 12:17:31 +02:00
|
|
|
custom_viewport_id = custom_viewport->get_instance_id();
|
2016-09-14 20:55:14 +02:00
|
|
|
} else {
|
2020-02-12 18:24:06 +01:00
|
|
|
custom_viewport_id = ObjectID();
|
2016-09-14 20:55:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (is_inside_tree()) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (custom_viewport) {
|
2016-09-14 20:55:14 +02:00
|
|
|
viewport = custom_viewport;
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2016-09-14 20:55:14 +02:00
|
|
|
viewport = get_viewport();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-09-14 20:55:14 +02:00
|
|
|
|
2017-01-14 15:07:57 +01:00
|
|
|
RID vp = viewport->get_viewport_rid();
|
2016-09-14 20:55:14 +02:00
|
|
|
group_name = "__cameras_" + itos(vp.get_id());
|
|
|
|
canvas_group_name = "__cameras_c" + itos(canvas.get_id());
|
|
|
|
add_to_group(group_name);
|
|
|
|
add_to_group(canvas_group_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Node *Camera2D::get_custom_viewport() const {
|
|
|
|
return custom_viewport;
|
|
|
|
}
|
|
|
|
|
2017-06-20 23:00:46 +02:00
|
|
|
void Camera2D::set_screen_drawing_enabled(bool enable) {
|
|
|
|
screen_drawing_enabled = enable;
|
2020-02-10 03:08:18 +01:00
|
|
|
#ifdef TOOLS_ENABLED
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2020-02-10 03:08:18 +01:00
|
|
|
#endif
|
2017-06-20 23:00:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Camera2D::is_screen_drawing_enabled() const {
|
|
|
|
return screen_drawing_enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Camera2D::set_limit_drawing_enabled(bool enable) {
|
|
|
|
limit_drawing_enabled = enable;
|
2020-02-10 03:08:18 +01:00
|
|
|
#ifdef TOOLS_ENABLED
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2020-02-10 03:08:18 +01:00
|
|
|
#endif
|
2017-06-20 23:00:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Camera2D::is_limit_drawing_enabled() const {
|
|
|
|
return limit_drawing_enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Camera2D::set_margin_drawing_enabled(bool enable) {
|
|
|
|
margin_drawing_enabled = enable;
|
2020-02-10 03:08:18 +01:00
|
|
|
#ifdef TOOLS_ENABLED
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2020-02-10 03:08:18 +01:00
|
|
|
#endif
|
2017-06-20 23:00:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Camera2D::is_margin_drawing_enabled() const {
|
|
|
|
return margin_drawing_enabled;
|
|
|
|
}
|
|
|
|
|
2022-08-12 22:57:11 +02:00
|
|
|
void Camera2D::_validate_property(PropertyInfo &p_property) const {
|
2023-03-02 20:53:25 +01:00
|
|
|
if (!position_smoothing_enabled && p_property.name == "position_smoothing_speed") {
|
2022-08-12 22:57:11 +02:00
|
|
|
p_property.usage = PROPERTY_USAGE_NO_EDITOR;
|
2021-03-04 00:51:35 +01:00
|
|
|
}
|
2020-04-28 15:34:27 +02:00
|
|
|
if (!rotation_smoothing_enabled && p_property.name == "rotation_smoothing_speed") {
|
|
|
|
p_property.usage = PROPERTY_USAGE_NO_EDITOR;
|
|
|
|
}
|
2021-03-04 00:51:35 +01:00
|
|
|
}
|
|
|
|
|
2014-03-14 02:57:24 +01:00
|
|
|
void Camera2D::_bind_methods() {
|
2017-02-13 12:47:24 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_offset", "offset"), &Camera2D::set_offset);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_offset"), &Camera2D::get_offset);
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2017-02-13 12:47:24 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_anchor_mode", "anchor_mode"), &Camera2D::set_anchor_mode);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_anchor_mode"), &Camera2D::get_anchor_mode);
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2022-08-13 13:37:10 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_ignore_rotation", "ignore"), &Camera2D::set_ignore_rotation);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_ignoring_rotation"), &Camera2D::is_ignoring_rotation);
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2017-02-13 12:47:24 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("_update_scroll"), &Camera2D::_update_scroll);
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2021-02-18 19:52:29 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_process_callback", "mode"), &Camera2D::set_process_callback);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_process_callback"), &Camera2D::get_process_callback);
|
2019-01-06 14:57:41 +01:00
|
|
|
|
2022-09-12 14:47:24 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &Camera2D::set_enabled);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_enabled"), &Camera2D::is_enabled);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("make_current"), &Camera2D::make_current);
|
2017-02-13 12:47:24 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("is_current"), &Camera2D::is_current);
|
2020-04-28 17:04:07 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("_make_current"), &Camera2D::_make_current);
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2017-02-13 12:47:24 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_limit", "margin", "limit"), &Camera2D::set_limit);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_limit", "margin"), &Camera2D::get_limit);
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2017-02-13 12:47:24 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_limit_smoothing_enabled", "limit_smoothing_enabled"), &Camera2D::set_limit_smoothing_enabled);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_limit_smoothing_enabled"), &Camera2D::is_limit_smoothing_enabled);
|
2016-07-13 11:48:50 +02:00
|
|
|
|
2020-12-09 17:14:29 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_drag_vertical_enabled", "enabled"), &Camera2D::set_drag_vertical_enabled);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_drag_vertical_enabled"), &Camera2D::is_drag_vertical_enabled);
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2020-12-09 17:14:29 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_drag_horizontal_enabled", "enabled"), &Camera2D::set_drag_horizontal_enabled);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_drag_horizontal_enabled"), &Camera2D::is_drag_horizontal_enabled);
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2020-12-09 17:14:29 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_drag_vertical_offset", "offset"), &Camera2D::set_drag_vertical_offset);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_drag_vertical_offset"), &Camera2D::get_drag_vertical_offset);
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2020-12-09 17:14:29 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_drag_horizontal_offset", "offset"), &Camera2D::set_drag_horizontal_offset);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_drag_horizontal_offset"), &Camera2D::get_drag_horizontal_offset);
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2017-02-13 12:47:24 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_drag_margin", "margin", "drag_margin"), &Camera2D::set_drag_margin);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_drag_margin", "margin"), &Camera2D::get_drag_margin);
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2022-08-25 12:04:05 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_target_position"), &Camera2D::get_camera_position);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_screen_center_position"), &Camera2D::get_camera_screen_center);
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2017-02-13 12:47:24 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_zoom", "zoom"), &Camera2D::set_zoom);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_zoom"), &Camera2D::get_zoom);
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2017-08-09 13:19:41 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_custom_viewport", "viewport"), &Camera2D::set_custom_viewport);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_custom_viewport"), &Camera2D::get_custom_viewport);
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2022-09-14 13:38:15 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_position_smoothing_speed", "position_smoothing_speed"), &Camera2D::set_position_smoothing_speed);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_position_smoothing_speed"), &Camera2D::get_position_smoothing_speed);
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2022-09-14 13:38:15 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_position_smoothing_enabled", "position_smoothing_speed"), &Camera2D::set_position_smoothing_enabled);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_position_smoothing_enabled"), &Camera2D::is_position_smoothing_enabled);
|
2015-12-12 13:26:13 +01:00
|
|
|
|
2020-04-28 15:34:27 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_rotation_smoothing_enabled", "enabled"), &Camera2D::set_rotation_smoothing_enabled);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_rotation_smoothing_enabled"), &Camera2D::is_rotation_smoothing_enabled);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_rotation_smoothing_speed", "speed"), &Camera2D::set_rotation_smoothing_speed);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_rotation_smoothing_speed"), &Camera2D::get_rotation_smoothing_speed);
|
|
|
|
|
2017-02-13 12:47:24 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("force_update_scroll"), &Camera2D::force_update_scroll);
|
|
|
|
ClassDB::bind_method(D_METHOD("reset_smoothing"), &Camera2D::reset_smoothing);
|
|
|
|
ClassDB::bind_method(D_METHOD("align"), &Camera2D::align);
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2017-02-13 12:47:24 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("_set_old_smoothing", "follow_smoothing"), &Camera2D::_set_old_smoothing);
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2017-06-20 23:00:46 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_screen_drawing_enabled", "screen_drawing_enabled"), &Camera2D::set_screen_drawing_enabled);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_screen_drawing_enabled"), &Camera2D::is_screen_drawing_enabled);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_limit_drawing_enabled", "limit_drawing_enabled"), &Camera2D::set_limit_drawing_enabled);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_limit_drawing_enabled"), &Camera2D::is_limit_drawing_enabled);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_margin_drawing_enabled", "margin_drawing_enabled"), &Camera2D::set_margin_drawing_enabled);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_margin_drawing_enabled"), &Camera2D::is_margin_drawing_enabled);
|
|
|
|
|
2022-05-20 07:24:41 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "offset", PROPERTY_HINT_NONE, "suffix:px"), "set_offset", "get_offset");
|
2017-02-12 01:11:37 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "anchor_mode", PROPERTY_HINT_ENUM, "Fixed TopLeft,Drag Center"), "set_anchor_mode", "get_anchor_mode");
|
2022-08-13 13:37:10 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ignore_rotation"), "set_ignore_rotation", "is_ignoring_rotation");
|
2022-09-12 14:47:24 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "is_enabled");
|
2022-06-14 16:33:44 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "zoom", PROPERTY_HINT_LINK), "set_zoom", "get_zoom");
|
2021-06-18 01:10:18 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "custom_viewport", PROPERTY_HINT_RESOURCE_TYPE, "Viewport", PROPERTY_USAGE_NONE), "set_custom_viewport", "get_custom_viewport");
|
2021-02-18 19:52:29 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "process_callback", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_process_callback", "get_process_callback");
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2017-01-04 05:16:14 +01:00
|
|
|
ADD_GROUP("Limit", "limit_");
|
2022-05-20 07:24:41 +02:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::INT, "limit_left", PROPERTY_HINT_NONE, "suffix:px"), "set_limit", "get_limit", SIDE_LEFT);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::INT, "limit_top", PROPERTY_HINT_NONE, "suffix:px"), "set_limit", "get_limit", SIDE_TOP);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::INT, "limit_right", PROPERTY_HINT_NONE, "suffix:px"), "set_limit", "get_limit", SIDE_RIGHT);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::INT, "limit_bottom", PROPERTY_HINT_NONE, "suffix:px"), "set_limit", "get_limit", SIDE_BOTTOM);
|
2017-02-12 01:11:37 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "limit_smoothed"), "set_limit_smoothing_enabled", "is_limit_smoothing_enabled");
|
2017-01-04 05:16:14 +01:00
|
|
|
|
2023-03-02 20:53:25 +01:00
|
|
|
ADD_GROUP("Position Smoothing", "position_smoothing_");
|
2022-09-14 13:38:15 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "position_smoothing_enabled"), "set_position_smoothing_enabled", "is_position_smoothing_enabled");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "position_smoothing_speed", PROPERTY_HINT_NONE, "suffix:px/s"), "set_position_smoothing_speed", "get_position_smoothing_speed");
|
2017-01-04 05:16:14 +01:00
|
|
|
|
2020-04-28 15:34:27 +02:00
|
|
|
ADD_GROUP("Rotation Smoothing", "rotation_smoothing_");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "rotation_smoothing_enabled"), "set_rotation_smoothing_enabled", "is_rotation_smoothing_enabled");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "rotation_smoothing_speed"), "set_rotation_smoothing_speed", "get_rotation_smoothing_speed");
|
|
|
|
|
2020-12-09 17:14:29 +01:00
|
|
|
ADD_GROUP("Drag", "drag_");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "drag_horizontal_enabled"), "set_drag_horizontal_enabled", "is_drag_horizontal_enabled");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "drag_vertical_enabled"), "set_drag_vertical_enabled", "is_drag_vertical_enabled");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "drag_horizontal_offset", PROPERTY_HINT_RANGE, "-1,1,0.01"), "set_drag_horizontal_offset", "get_drag_horizontal_offset");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "drag_vertical_offset", PROPERTY_HINT_RANGE, "-1,1,0.01"), "set_drag_vertical_offset", "get_drag_vertical_offset");
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "drag_left_margin", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_drag_margin", "get_drag_margin", SIDE_LEFT);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "drag_top_margin", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_drag_margin", "get_drag_margin", SIDE_TOP);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "drag_right_margin", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_drag_margin", "get_drag_margin", SIDE_RIGHT);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "drag_bottom_margin", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_drag_margin", "get_drag_margin", SIDE_BOTTOM);
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2017-06-20 23:00:46 +02:00
|
|
|
ADD_GROUP("Editor", "editor_");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editor_draw_screen"), "set_screen_drawing_enabled", "is_screen_drawing_enabled");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editor_draw_limits"), "set_limit_drawing_enabled", "is_limit_drawing_enabled");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editor_draw_drag_margin"), "set_margin_drawing_enabled", "is_margin_drawing_enabled");
|
|
|
|
|
2017-08-20 17:45:01 +02:00
|
|
|
BIND_ENUM_CONSTANT(ANCHOR_MODE_FIXED_TOP_LEFT);
|
2017-10-21 20:58:02 +02:00
|
|
|
BIND_ENUM_CONSTANT(ANCHOR_MODE_DRAG_CENTER);
|
2019-01-06 14:57:41 +01:00
|
|
|
BIND_ENUM_CONSTANT(CAMERA2D_PROCESS_PHYSICS);
|
|
|
|
BIND_ENUM_CONSTANT(CAMERA2D_PROCESS_IDLE);
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Camera2D::Camera2D() {
|
2020-12-22 17:24:29 +01:00
|
|
|
limit[SIDE_LEFT] = -10000000;
|
|
|
|
limit[SIDE_TOP] = -10000000;
|
|
|
|
limit[SIDE_RIGHT] = 10000000;
|
|
|
|
limit[SIDE_BOTTOM] = 10000000;
|
|
|
|
|
|
|
|
drag_margin[SIDE_LEFT] = 0.2;
|
|
|
|
drag_margin[SIDE_TOP] = 0.2;
|
|
|
|
drag_margin[SIDE_RIGHT] = 0.2;
|
|
|
|
drag_margin[SIDE_BOTTOM] = 0.2;
|
2019-03-14 13:58:29 +01:00
|
|
|
|
2017-01-13 00:35:46 +01:00
|
|
|
set_notify_transform(true);
|
2023-01-26 13:17:26 +01:00
|
|
|
set_hide_clip_children(true);
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|