Merge pull request #43554 from lawnjelly/refactor_pixel_snap
Add 2d snap transforms option
This commit is contained in:
commit
4d667dadb9
7 changed files with 15 additions and 4 deletions
|
@ -228,6 +228,7 @@ Engine::Engine() {
|
||||||
_target_fps = 0;
|
_target_fps = 0;
|
||||||
_time_scale = 1.0;
|
_time_scale = 1.0;
|
||||||
_pixel_snap = false;
|
_pixel_snap = false;
|
||||||
|
_snap_2d_transforms = false;
|
||||||
_physics_frames = 0;
|
_physics_frames = 0;
|
||||||
_idle_frames = 0;
|
_idle_frames = 0;
|
||||||
_in_physics = false;
|
_in_physics = false;
|
||||||
|
|
|
@ -62,6 +62,7 @@ private:
|
||||||
int _target_fps;
|
int _target_fps;
|
||||||
float _time_scale;
|
float _time_scale;
|
||||||
bool _pixel_snap;
|
bool _pixel_snap;
|
||||||
|
bool _snap_2d_transforms;
|
||||||
uint64_t _physics_frames;
|
uint64_t _physics_frames;
|
||||||
float _physics_interpolation_fraction;
|
float _physics_interpolation_fraction;
|
||||||
|
|
||||||
|
@ -110,6 +111,7 @@ public:
|
||||||
Object *get_singleton_object(const String &p_name) const;
|
Object *get_singleton_object(const String &p_name) const;
|
||||||
|
|
||||||
_FORCE_INLINE_ bool get_use_pixel_snap() const { return _pixel_snap; }
|
_FORCE_INLINE_ bool get_use_pixel_snap() const { return _pixel_snap; }
|
||||||
|
bool get_snap_2d_transforms() const { return _snap_2d_transforms; }
|
||||||
|
|
||||||
#ifdef TOOLS_ENABLED
|
#ifdef TOOLS_ENABLED
|
||||||
_FORCE_INLINE_ void set_editor_hint(bool p_enabled) { editor_hint = p_enabled; }
|
_FORCE_INLINE_ void set_editor_hint(bool p_enabled) { editor_hint = p_enabled; }
|
||||||
|
|
|
@ -1113,6 +1113,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
|
||||||
}
|
}
|
||||||
|
|
||||||
Engine::get_singleton()->_pixel_snap = GLOBAL_DEF("rendering/quality/2d/use_pixel_snap", false);
|
Engine::get_singleton()->_pixel_snap = GLOBAL_DEF("rendering/quality/2d/use_pixel_snap", false);
|
||||||
|
Engine::get_singleton()->_snap_2d_transforms = GLOBAL_DEF("rendering/quality/2d/use_transform_snap", false);
|
||||||
OS::get_singleton()->_keep_screen_on = GLOBAL_DEF("display/window/energy_saving/keep_screen_on", true);
|
OS::get_singleton()->_keep_screen_on = GLOBAL_DEF("display/window/energy_saving/keep_screen_on", true);
|
||||||
if (rtm == -1) {
|
if (rtm == -1) {
|
||||||
rtm = GLOBAL_DEF("rendering/threads/thread_model", OS::RENDER_THREAD_SAFE);
|
rtm = GLOBAL_DEF("rendering/threads/thread_model", OS::RENDER_THREAD_SAFE);
|
||||||
|
|
|
@ -452,7 +452,7 @@ void AnimatedSprite::_notification(int p_what) {
|
||||||
if (centered)
|
if (centered)
|
||||||
ofs -= s / 2;
|
ofs -= s / 2;
|
||||||
|
|
||||||
if (Engine::get_singleton()->get_use_pixel_snap()) {
|
if (Engine::get_singleton()->get_snap_2d_transforms()) {
|
||||||
ofs = ofs.floor();
|
ofs = ofs.floor();
|
||||||
}
|
}
|
||||||
Rect2 dst_rect(ofs, s);
|
Rect2 dst_rect(ofs, s);
|
||||||
|
|
|
@ -99,7 +99,7 @@ void Sprite::_get_rects(Rect2 &r_src_rect, Rect2 &r_dst_rect, bool &r_filter_cli
|
||||||
Point2 dest_offset = offset;
|
Point2 dest_offset = offset;
|
||||||
if (centered)
|
if (centered)
|
||||||
dest_offset -= frame_size / 2;
|
dest_offset -= frame_size / 2;
|
||||||
if (Engine::get_singleton()->get_use_pixel_snap()) {
|
if (Engine::get_singleton()->get_snap_2d_transforms()) {
|
||||||
dest_offset = dest_offset.floor();
|
dest_offset = dest_offset.floor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -378,7 +378,7 @@ Rect2 Sprite::get_rect() const {
|
||||||
Point2 ofs = offset;
|
Point2 ofs = offset;
|
||||||
if (centered)
|
if (centered)
|
||||||
ofs -= Size2(s) / 2;
|
ofs -= Size2(s) / 2;
|
||||||
if (Engine::get_singleton()->get_use_pixel_snap()) {
|
if (Engine::get_singleton()->get_snap_2d_transforms()) {
|
||||||
ofs = ofs.floor();
|
ofs = ofs.floor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,12 @@ void VisualServerCanvas::_render_canvas_item(Item *p_canvas_item, const Transfor
|
||||||
}
|
}
|
||||||
|
|
||||||
Rect2 rect = ci->get_rect();
|
Rect2 rect = ci->get_rect();
|
||||||
Transform2D xform = p_transform * ci->xform;
|
Transform2D xform = ci->xform;
|
||||||
|
if (snap_2d_transforms) {
|
||||||
|
xform.elements[2] = xform.elements[2].floor();
|
||||||
|
}
|
||||||
|
xform = p_transform * xform;
|
||||||
|
|
||||||
Rect2 global_rect = xform.xform(rect);
|
Rect2 global_rect = xform.xform(rect);
|
||||||
global_rect.position += p_clip_rect.position;
|
global_rect.position += p_clip_rect.position;
|
||||||
|
|
||||||
|
@ -1477,6 +1482,7 @@ VisualServerCanvas::VisualServerCanvas() {
|
||||||
z_last_list = (RasterizerCanvas::Item **)memalloc(z_range * sizeof(RasterizerCanvas::Item *));
|
z_last_list = (RasterizerCanvas::Item **)memalloc(z_range * sizeof(RasterizerCanvas::Item *));
|
||||||
|
|
||||||
disable_scale = false;
|
disable_scale = false;
|
||||||
|
snap_2d_transforms = Engine::get_singleton()->get_snap_2d_transforms();
|
||||||
}
|
}
|
||||||
|
|
||||||
VisualServerCanvas::~VisualServerCanvas() {
|
VisualServerCanvas::~VisualServerCanvas() {
|
||||||
|
|
|
@ -158,6 +158,7 @@ public:
|
||||||
RID_Owner<RasterizerCanvas::Light> canvas_light_owner;
|
RID_Owner<RasterizerCanvas::Light> canvas_light_owner;
|
||||||
|
|
||||||
bool disable_scale;
|
bool disable_scale;
|
||||||
|
bool snap_2d_transforms;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _render_canvas_item_tree(Item *p_canvas_item, const Transform2D &p_transform, const Rect2 &p_clip_rect, const Color &p_modulate, RasterizerCanvas::Light *p_lights);
|
void _render_canvas_item_tree(Item *p_canvas_item, const Transform2D &p_transform, const Rect2 &p_clip_rect, const Color &p_modulate, RasterizerCanvas::Light *p_lights);
|
||||||
|
|
Loading…
Reference in a new issue