diff options
Diffstat (limited to 'scene')
-rw-r--r-- | scene/main/scene_tree.cpp | 28 | ||||
-rw-r--r-- | scene/main/scene_tree.h | 1 | ||||
-rw-r--r-- | scene/main/viewport.cpp | 27 | ||||
-rw-r--r-- | scene/main/viewport.h | 3 |
4 files changed, 53 insertions, 6 deletions
diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 5acb157279..16817a2846 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -484,6 +484,14 @@ bool SceneTree::iteration(float p_time) { return _quit; } +void SceneTree::_update_font_oversampling(float p_ratio) { + + if (use_font_oversampling) { + DynamicFontAtSize::font_oversampling = p_ratio; + DynamicFont::update_oversampling(); + } +} + bool SceneTree::idle(float p_time) { //print_line("ram: "+itos(OS::get_singleton()->get_static_memory_usage())+" sram: "+itos(OS::get_singleton()->get_dynamic_memory_usage())); @@ -515,12 +523,6 @@ bool SceneTree::idle(float p_time) { last_screen_size = win_size; _update_root_rect(); - - if (use_font_oversampling) { - DynamicFontAtSize::font_oversampling = OS::get_singleton()->get_window_size().width / root->get_visible_rect().size.width; - DynamicFont::update_oversampling(); - } - emit_signal("screen_resized"); } @@ -1133,10 +1135,12 @@ void SceneTree::_update_root_rect() { if (stretch_mode == STRETCH_MODE_DISABLED) { + _update_font_oversampling(1.0); root->set_size((last_screen_size / stretch_shrink).floor()); root->set_attach_to_screen_rect(Rect2(Point2(), last_screen_size)); root->set_size_override_stretch(false); root->set_size_override(false, Size2()); + root->update_canvas_items(); return; //user will take care } @@ -1154,6 +1158,9 @@ void SceneTree::_update_root_rect() { //same aspect or ignore aspect viewport_size = desired_res; screen_size = video_mode; + if (use_font_oversampling) { + WARN_PRINT("Font oversampling only works with the following resize modes 'Keep Width', 'Keep Height', and 'Expand'.") + } } else if (viewport_aspect < video_mode_aspect) { // screen ratio is smaller vertically @@ -1208,21 +1215,30 @@ void SceneTree::_update_root_rect() { switch (stretch_mode) { case STRETCH_MODE_DISABLED: { // Already handled above + _update_font_oversampling(1.0); } break; case STRETCH_MODE_2D: { + _update_font_oversampling(screen_size.x / viewport_size.x); //screen / viewport radio drives oversampling root->set_size((screen_size / stretch_shrink).floor()); root->set_attach_to_screen_rect(Rect2(margin, screen_size)); root->set_size_override_stretch(true); root->set_size_override(true, (viewport_size / stretch_shrink).floor()); + root->update_canvas_items(); //force them to update just in case } break; case STRETCH_MODE_VIEWPORT: { + _update_font_oversampling(1.0); root->set_size((viewport_size / stretch_shrink).floor()); root->set_attach_to_screen_rect(Rect2(margin, screen_size)); root->set_size_override_stretch(false); root->set_size_override(false, Size2()); + root->update_canvas_items(); //force them to update just in case + + if (use_font_oversampling) { + WARN_PRINT("Font oversampling does not work in 'Viewport' stretch mode, only '2D'.") + } } break; } diff --git a/scene/main/scene_tree.h b/scene/main/scene_tree.h index d6ab8c37b2..3a1ff5cb06 100644 --- a/scene/main/scene_tree.h +++ b/scene/main/scene_tree.h @@ -153,6 +153,7 @@ private: Size2i stretch_min; real_t stretch_shrink; + void _update_font_oversampling(float p_ratio); void _update_root_rect(); List<ObjectID> delete_queue; diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 8df007dcc7..61d6fc7401 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -693,6 +693,13 @@ bool Viewport::use_arvr() { return arvr; } +void Viewport::update_canvas_items() { + if (!is_inside_tree()) + return; + + _update_canvas_items(this); +} + void Viewport::set_size(const Size2 &p_size) { if (size == p_size.floor()) @@ -1128,6 +1135,26 @@ Transform2D Viewport::get_final_transform() const { return stretch_transform * global_canvas_transform; } +void Viewport::_update_canvas_items(Node *p_node) { + if (p_node != this) { + + Viewport *vp = Object::cast_to<Viewport>(p_node); + if (vp) + return; + + CanvasItem *ci = Object::cast_to<CanvasItem>(p_node); + if (ci) { + ci->update(); + } + } + + int cc = p_node->get_child_count(); + + for (int i = 0; i < cc; i++) { + _update_canvas_items(p_node->get_child(i)); + } +} + void Viewport::set_size_override(bool p_enable, const Size2 &p_size, const Vector2 &p_margin) { if (size_override == p_enable && p_size == size_override_size) diff --git a/scene/main/viewport.h b/scene/main/viewport.h index cdb9d4afb5..4d0a4e8c87 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -385,6 +385,8 @@ private: void _drop_mouse_focus(); + void _update_canvas_items(Node *p_node); + protected: void _notification(int p_what); static void _bind_methods(); @@ -403,6 +405,7 @@ public: bool is_audio_listener_2d() const; void set_size(const Size2 &p_size); + void update_canvas_items(); Size2 get_size() const; Rect2 get_visible_rect() const; |