Rename ViewportContainer to SubViewportContainer

This commit is contained in:
Michael Alexsander 2020-04-01 15:28:09 -03:00
parent ff14d071cc
commit 0c6851ae53
13 changed files with 74 additions and 73 deletions

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="SubViewportContainer" inherits="Container" version="4.0">
<brief_description>
Control for holding [SubViewport]s.
</brief_description>
<description>
A [Container] node that holds a [SubViewport], automatically setting its size.
</description>
<tutorials>
</tutorials>
<methods>
</methods>
<members>
<member name="stretch" type="bool" setter="set_stretch" getter="is_stretch_enabled" default="false">
If [code]true[/code], the sub-viewport will be scaled to the control's size.
</member>
<member name="stretch_shrink" type="int" setter="set_stretch_shrink" getter="get_stretch_shrink" default="1">
Divides the sub-viewport's effective resolution by this value while preserving its scale. This can be used to speed up rendering.
For example, a 1280×720 sub-viewport with [member stretch_shrink] set to [code]2[/code] will be rendered at 640×360 while occupying the same size in the container.
[b]Note:[/b] [member stretch] must be [code]true[/code] for this property to work.
</member>
</members>
<constants>
</constants>
</class>

View File

@ -6,7 +6,7 @@
<description>
A Viewport creates a different view into the screen, or a sub-view inside another viewport. Children 2D Nodes will display on it, and children Camera3D 3D nodes will render on it too.
Optionally, a viewport can have its own 2D or 3D world, so they don't share what they draw with other viewports.
If a viewport is a child of a [ViewportContainer], it will automatically take up its size, otherwise it must be set manually.
If a viewport is a child of a [SubViewportContainer], it will automatically take up its size, otherwise it must be set manually.
Viewports can also choose to be audio listeners, so they generate positional audio depending on a 2D or 3D camera child of it.
Also, viewports can be assigned to different screens in case the devices have multiple screens.
Finally, viewports can also behave as render targets, in which case they will not be visible unless the associated texture is used to draw.

View File

@ -1,25 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="ViewportContainer" inherits="Container" version="4.0">
<brief_description>
Control for holding [Viewport]s.
</brief_description>
<description>
A [Container] node that holds a [Viewport], automatically setting its size.
</description>
<tutorials>
</tutorials>
<methods>
</methods>
<members>
<member name="stretch" type="bool" setter="set_stretch" getter="is_stretch_enabled" default="false">
If [code]true[/code], the viewport will be scaled to the control's size.
</member>
<member name="stretch_shrink" type="int" setter="set_stretch_shrink" getter="get_stretch_shrink" default="1">
Divides the viewport's effective resolution by this value while preserving its scale. This can be used to speed up rendering.
For example, a 1280×720 viewport with [member stretch_shrink] set to [code]2[/code] will be rendered at 640×360 while occupying the same size in the container.
[b]Note:[/b] [member stretch] must be [code]true[/code] for this property to work.
</member>
</members>
<constants>
</constants>
</class>

View File

Before

Width:  |  Height:  |  Size: 557 B

After

Width:  |  Height:  |  Size: 557 B

View File

@ -48,7 +48,7 @@
#include "scene/2d/touch_screen_button.h"
#include "scene/gui/grid_container.h"
#include "scene/gui/nine_patch_rect.h"
#include "scene/gui/viewport_container.h"
#include "scene/gui/subviewport_container.h"
#include "scene/main/canvas_layer.h"
#include "scene/main/window.h"
#include "scene/resources/packed_scene.h"
@ -5434,7 +5434,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
viewport_scrollable->set_h_size_flags(Control::SIZE_EXPAND_FILL);
viewport_scrollable->connect("draw", callable_mp(this, &CanvasItemEditor::_update_scrollbars));
ViewportContainer *scene_tree = memnew(ViewportContainer);
SubViewportContainer *scene_tree = memnew(SubViewportContainer);
viewport_scrollable->add_child(scene_tree);
scene_tree->set_stretch(true);
scene_tree->set_anchors_and_margins_preset(Control::PRESET_WIDE);

View File

@ -31,7 +31,7 @@
#include "material_editor_plugin.h"
#include "editor/editor_scale.h"
#include "scene/gui/viewport_container.h"
#include "scene/gui/subviewport_container.h"
#include "scene/resources/particles_material.h"
#include "scene/resources/sky_material.h"
@ -110,7 +110,7 @@ void MaterialEditor::_bind_methods() {
MaterialEditor::MaterialEditor() {
vc = memnew(ViewportContainer);
vc = memnew(SubViewportContainer);
vc->set_stretch(true);
add_child(vc);
vc->set_anchors_and_margins_preset(PRESET_WIDE);

View File

@ -41,13 +41,13 @@
#include "scene/3d/mesh_instance_3d.h"
#include "scene/resources/material.h"
class ViewportContainer;
class SubViewportContainer;
class MaterialEditor : public Control {
GDCLASS(MaterialEditor, Control);
ViewportContainer *vc;
SubViewportContainer *vc;
SubViewport *viewport;
MeshInstance3D *sphere_instance;
MeshInstance3D *box_instance;

View File

@ -36,12 +36,12 @@
#include "scene/3d/camera_3d.h"
#include "scene/3d/light_3d.h"
#include "scene/3d/mesh_instance_3d.h"
#include "scene/gui/viewport_container.h"
#include "scene/gui/subviewport_container.h"
#include "scene/resources/material.h"
class MeshEditor : public ViewportContainer {
class MeshEditor : public SubViewportContainer {
GDCLASS(MeshEditor, ViewportContainer);
GDCLASS(MeshEditor, SubViewportContainer);
float rot_x;
float rot_y;

View File

@ -48,7 +48,7 @@
#include "scene/3d/mesh_instance_3d.h"
#include "scene/3d/physics_body_3d.h"
#include "scene/3d/visual_instance_3d.h"
#include "scene/gui/viewport_container.h"
#include "scene/gui/subviewport_container.h"
#include "scene/resources/packed_scene.h"
#include "scene/resources/surface_tool.h"
#include "servers/display_server.h"
@ -418,12 +418,12 @@ Vector3 Node3DEditorViewport::_get_camera_position() const {
Point2 Node3DEditorViewport::_point_to_screen(const Vector3 &p_point) {
return camera->unproject_position(p_point) * viewport_container->get_stretch_shrink();
return camera->unproject_position(p_point) * subviewport_container->get_stretch_shrink();
}
Vector3 Node3DEditorViewport::_get_ray_pos(const Vector2 &p_pos) const {
return camera->project_ray_origin(p_pos / viewport_container->get_stretch_shrink());
return camera->project_ray_origin(p_pos / subviewport_container->get_stretch_shrink());
}
Vector3 Node3DEditorViewport::_get_camera_normal() const {
@ -433,7 +433,7 @@ Vector3 Node3DEditorViewport::_get_camera_normal() const {
Vector3 Node3DEditorViewport::_get_ray(const Vector2 &p_pos) const {
return camera->project_ray_normal(p_pos / viewport_container->get_stretch_shrink());
return camera->project_ray_normal(p_pos / subviewport_container->get_stretch_shrink());
}
void Node3DEditorViewport::_clear_selected() {
@ -494,7 +494,7 @@ ObjectID Node3DEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, b
Vector3 ray = _get_ray(p_pos);
Vector3 pos = _get_ray_pos(p_pos);
Vector2 shrinked_pos = p_pos / viewport_container->get_stretch_shrink();
Vector2 shrinked_pos = p_pos / subviewport_container->get_stretch_shrink();
Vector<ObjectID> instances = RenderingServer::get_singleton()->instances_cull_ray(pos, ray, get_tree()->get_root()->get_world()->get_scenario());
Set<Ref<EditorNode3DGizmo>> found_gizmos;
@ -2472,8 +2472,8 @@ void Node3DEditorViewport::_notification(int p_what) {
bool shrink = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_HALF_RESOLUTION));
if (shrink != (viewport_container->get_stretch_shrink() > 1)) {
viewport_container->set_stretch_shrink(shrink ? 2 : 1);
if (shrink != (subviewport_container->get_stretch_shrink() > 1)) {
subviewport_container->set_stretch_shrink(shrink ? 2 : 1);
}
//update msaa if changed
@ -3237,8 +3237,8 @@ void Node3DEditorViewport::update_transform_gizmo_view() {
const int viewport_base_height = 400 * MAX(1, EDSCALE);
gizmo_scale =
(gizmo_size / Math::abs(dd)) * MAX(1, EDSCALE) *
MIN(viewport_base_height, viewport_container->get_size().height) / viewport_base_height /
viewport_container->get_stretch_shrink();
MIN(viewport_base_height, subviewport_container->get_size().height) / viewport_base_height /
subviewport_container->get_stretch_shrink();
Vector3 scale = Vector3(1, 1, 1) * gizmo_scale;
xform.basis.scale(scale);
@ -3398,7 +3398,7 @@ Dictionary Node3DEditorViewport::get_state() const {
d["gizmos"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_GIZMOS));
d["information"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_INFORMATION));
d["fps"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_FPS));
d["half_res"] = viewport_container->get_stretch_shrink() > 1;
d["half_res"] = subviewport_container->get_stretch_shrink() > 1;
d["cinematic_preview"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_CINEMATIC_PREVIEW));
if (previewing)
d["previewing"] = EditorNode::get_singleton()->get_edited_scene()->get_path_to(previewing);
@ -3829,8 +3829,8 @@ Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, Edito
zoom_indicator_delay = 0.0;
spatial_editor = p_spatial_editor;
ViewportContainer *c = memnew(ViewportContainer);
viewport_container = c;
SubViewportContainer *c = memnew(SubViewportContainer);
subviewport_container = c;
c->set_stretch(true);
add_child(c);
c->set_anchors_and_margins_preset(Control::PRESET_WIDE);

View File

@ -43,7 +43,7 @@ class Camera3D;
class Node3DEditor;
class EditorNode3DGizmoPlugin;
class Node3DEditorViewport;
class ViewportContainer;
class SubViewportContainer;
class EditorNode3DGizmo : public Node3DGizmo {
@ -256,7 +256,7 @@ private:
UndoRedo *undo_redo;
CheckBox *preview_camera;
ViewportContainer *viewport_container;
SubViewportContainer *subviewport_container;
MenuButton *view_menu;
PopupMenu *display_submenu;

View File

@ -1,5 +1,5 @@
/*************************************************************************/
/* viewport_container.cpp */
/* subviewport_container.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -28,12 +28,12 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "viewport_container.h"
#include "subviewport_container.h"
#include "core/engine.h"
#include "scene/main/viewport.h"
Size2 ViewportContainer::get_minimum_size() const {
Size2 SubViewportContainer::get_minimum_size() const {
if (stretch)
return Size2();
@ -52,19 +52,19 @@ Size2 ViewportContainer::get_minimum_size() const {
return ms;
}
void ViewportContainer::set_stretch(bool p_enable) {
void SubViewportContainer::set_stretch(bool p_enable) {
stretch = p_enable;
queue_sort();
update();
}
bool ViewportContainer::is_stretch_enabled() const {
bool SubViewportContainer::is_stretch_enabled() const {
return stretch;
}
void ViewportContainer::set_stretch_shrink(int p_shrink) {
void SubViewportContainer::set_stretch_shrink(int p_shrink) {
ERR_FAIL_COND(p_shrink < 1);
if (shrink == p_shrink)
@ -87,12 +87,12 @@ void ViewportContainer::set_stretch_shrink(int p_shrink) {
update();
}
int ViewportContainer::get_stretch_shrink() const {
int SubViewportContainer::get_stretch_shrink() const {
return shrink;
}
void ViewportContainer::_notification(int p_what) {
void SubViewportContainer::_notification(int p_what) {
if (p_what == NOTIFICATION_RESIZED) {
@ -142,7 +142,7 @@ void ViewportContainer::_notification(int p_what) {
}
}
void ViewportContainer::_input(const Ref<InputEvent> &p_event) {
void SubViewportContainer::_input(const Ref<InputEvent> &p_event) {
if (Engine::get_singleton()->is_editor_hint())
return;
@ -167,7 +167,7 @@ void ViewportContainer::_input(const Ref<InputEvent> &p_event) {
}
}
void ViewportContainer::_unhandled_input(const Ref<InputEvent> &p_event) {
void SubViewportContainer::_unhandled_input(const Ref<InputEvent> &p_event) {
if (Engine::get_singleton()->is_editor_hint())
return;
@ -192,21 +192,21 @@ void ViewportContainer::_unhandled_input(const Ref<InputEvent> &p_event) {
}
}
void ViewportContainer::_bind_methods() {
void SubViewportContainer::_bind_methods() {
ClassDB::bind_method(D_METHOD("_unhandled_input", "event"), &ViewportContainer::_unhandled_input);
ClassDB::bind_method(D_METHOD("_input", "event"), &ViewportContainer::_input);
ClassDB::bind_method(D_METHOD("set_stretch", "enable"), &ViewportContainer::set_stretch);
ClassDB::bind_method(D_METHOD("is_stretch_enabled"), &ViewportContainer::is_stretch_enabled);
ClassDB::bind_method(D_METHOD("_unhandled_input", "event"), &SubViewportContainer::_unhandled_input);
ClassDB::bind_method(D_METHOD("_input", "event"), &SubViewportContainer::_input);
ClassDB::bind_method(D_METHOD("set_stretch", "enable"), &SubViewportContainer::set_stretch);
ClassDB::bind_method(D_METHOD("is_stretch_enabled"), &SubViewportContainer::is_stretch_enabled);
ClassDB::bind_method(D_METHOD("set_stretch_shrink", "amount"), &ViewportContainer::set_stretch_shrink);
ClassDB::bind_method(D_METHOD("get_stretch_shrink"), &ViewportContainer::get_stretch_shrink);
ClassDB::bind_method(D_METHOD("set_stretch_shrink", "amount"), &SubViewportContainer::set_stretch_shrink);
ClassDB::bind_method(D_METHOD("get_stretch_shrink"), &SubViewportContainer::get_stretch_shrink);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "stretch"), "set_stretch", "is_stretch_enabled");
ADD_PROPERTY(PropertyInfo(Variant::INT, "stretch_shrink"), "set_stretch_shrink", "get_stretch_shrink");
}
ViewportContainer::ViewportContainer() {
SubViewportContainer::SubViewportContainer() {
stretch = false;
shrink = 1;

View File

@ -1,5 +1,5 @@
/*************************************************************************/
/* viewport_container.h */
/* subviewport_container.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -33,9 +33,9 @@
#include "scene/gui/container.h"
class ViewportContainer : public Container {
class SubViewportContainer : public Container {
GDCLASS(ViewportContainer, Container);
GDCLASS(SubViewportContainer, Container);
bool stretch;
int shrink;
@ -55,7 +55,7 @@ public:
virtual Size2 get_minimum_size() const;
ViewportContainer();
SubViewportContainer();
};
#endif // VIEWPORTCONTAINER_H

View File

@ -110,6 +110,7 @@
#include "scene/gui/slider.h"
#include "scene/gui/spin_box.h"
#include "scene/gui/split_container.h"
#include "scene/gui/subviewport_container.h"
#include "scene/gui/tab_container.h"
#include "scene/gui/tabs.h"
#include "scene/gui/text_edit.h"
@ -119,7 +120,6 @@
#include "scene/gui/tool_button.h"
#include "scene/gui/tree.h"
#include "scene/gui/video_player.h"
#include "scene/gui/viewport_container.h"
#include "scene/main/canvas_item.h"
#include "scene/main/canvas_layer.h"
#include "scene/main/http_request.h"
@ -357,7 +357,7 @@ void register_scene_types() {
ClassDB::register_class<ConfirmationDialog>();
ClassDB::register_class<MarginContainer>();
ClassDB::register_class<ViewportContainer>();
ClassDB::register_class<SubViewportContainer>();
ClassDB::register_virtual_class<SplitContainer>();
ClassDB::register_class<HSplitContainer>();
ClassDB::register_class<VSplitContainer>();
@ -842,6 +842,7 @@ void register_scene_types() {
ClassDB::add_compatibility_class("StaticBody", "StaticBody3D");
ClassDB::add_compatibility_class("VehicleBody", "VehicleBody3D");
ClassDB::add_compatibility_class("VehicleWheel", "VehicleWheel3D");
ClassDB::add_compatibility_class("ViewportContainer", "SubViewportContainer");
ClassDB::add_compatibility_class("VisibilityEnabler", "VisibilityEnabler3D");
ClassDB::add_compatibility_class("VisibilityNotifier", "VisibilityNotifier3D");
ClassDB::add_compatibility_class("VisualServer", "RenderingServer");