summaryrefslogtreecommitdiff
path: root/editor/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'editor/plugins')
-rw-r--r--editor/plugins/spatial_editor_plugin.cpp40
-rw-r--r--editor/plugins/spatial_editor_plugin.h4
2 files changed, 44 insertions, 0 deletions
diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp
index 2c16157b6a..f38c2b3f12 100644
--- a/editor/plugins/spatial_editor_plugin.cpp
+++ b/editor/plugins/spatial_editor_plugin.cpp
@@ -2099,6 +2099,29 @@ void SpatialEditorViewport::_notification(int p_what) {
}
}
+ // FPS Counter.
+ bool show_fps = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_FPS));
+ if (show_fps != fps->is_visible()) {
+ if (show_fps)
+ fps->show();
+ else
+ fps->hide();
+ }
+
+ if (show_fps) {
+ String text;
+ const float temp_fps = Engine::get_singleton()->get_frames_per_second();
+ text += TTR("FPS") + ": " + itos(temp_fps) + " (" + String::num(1000.0f / temp_fps, 2) + " ms)";
+
+ if (fps_label->get_text() != text || surface->get_size() != prev_size) {
+ fps_label->set_text(text);
+ Size2 ms = fps->get_size();
+ Size2 size = surface->get_size();
+ size.y = ms.y + 20;
+ fps->set_position(size - ms - Vector2(20, 0) * EDSCALE);
+ }
+ }
+
prev_size = surface->get_size();
}
@@ -2109,6 +2132,7 @@ void SpatialEditorViewport::_notification(int p_what) {
surface->connect("mouse_entered", this, "_smouseenter");
surface->connect("mouse_exited", this, "_smouseexit");
info->add_style_override("panel", get_stylebox("panel", "Panel"));
+ fps->add_style_override("panel", get_stylebox("panel", "Panel"));
preview_camera->set_icon(get_icon("Camera", "EditorIcons"));
_init_gizmo_instance(index);
}
@@ -2431,6 +2455,13 @@ void SpatialEditorViewport::_menu_option(int p_option) {
view_menu->get_popup()->set_item_checked(idx, !current);
} break;
+ case VIEW_FPS: {
+
+ int idx = view_menu->get_popup()->get_item_index(VIEW_FPS);
+ bool current = view_menu->get_popup()->is_item_checked(idx);
+ view_menu->get_popup()->set_item_checked(idx, !current);
+
+ } break;
case VIEW_DISPLAY_NORMAL: {
viewport->set_debug_draw(Viewport::DEBUG_DRAW_DISABLED);
@@ -3149,6 +3180,7 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed
view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_environment", TTR("View Environment")), VIEW_ENVIRONMENT);
view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_gizmos", TTR("View Gizmos")), VIEW_GIZMOS);
view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_information", TTR("View Information")), VIEW_INFORMATION);
+ view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_fps", TTR("View FPS")), VIEW_FPS);
view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_ENVIRONMENT), true);
view_menu->get_popup()->add_separator();
view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_half_resolution", TTR("Half Resolution")), VIEW_HALF_RESOLUTION);
@@ -3191,6 +3223,14 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed
info->add_child(info_label);
info->hide();
+ // FPS Counter.
+ fps = memnew(PanelContainer);
+ fps->set_self_modulate(Color(1, 1, 1, 0.4));
+ surface->add_child(fps);
+ fps_label = memnew(Label);
+ fps->add_child(fps_label);
+ fps->hide();
+
accept = NULL;
freelook_active = false;
diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h
index 0ef85b72d9..4870e961a8 100644
--- a/editor/plugins/spatial_editor_plugin.h
+++ b/editor/plugins/spatial_editor_plugin.h
@@ -88,6 +88,7 @@ class SpatialEditorViewport : public Control {
VIEW_AUDIO_DOPPLER,
VIEW_GIZMOS,
VIEW_INFORMATION,
+ VIEW_FPS,
VIEW_DISPLAY_NORMAL,
VIEW_DISPLAY_WIREFRAME,
VIEW_DISPLAY_OVERDRAW,
@@ -138,6 +139,9 @@ private:
PanelContainer *info;
Label *info_label;
+ PanelContainer *fps;
+ Label *fps_label;
+
struct _RayResult {
Spatial *item;