Godot Engine – Multi-platform 2D and 3D game engine
[DisplayServer] Add enum for screen sensor orientation
Anish Kumar727227570de4
diff --git a/doc/classes/DisplayServer.xml b/doc/classes/DisplayServer.xmlindex ab037aa890b..6afa3e89661 100644--- a/doc/classes/DisplayServer.xml+++ b/doc/classes/DisplayServer.xml@@ -2689,10 +2689,9 @@</methods><signals><signal name="orientation_changed">- <param index="0" name="orientation" type="int" />+ <param index="0" name="orientation" type="int" enum="DisplayServer.SensorOrientation" /><description>- Emitted when the device orientation changes. [param orientation] is the new orientation.- Returns [code]1[/code] for portrait, [code]2[/code] for landscape, and [code]0[/code] if the orientation is undefined.+ Emitted when the screen orientation changes. [param orientation] is the new orientation.[b]Note:[/b] This method is implemented on Android and iOS.</description></signal>@@ -3168,6 +3167,15 @@<constant name="SCREEN_SENSOR" value="6" enum="ScreenOrientation">Automatic landscape or portrait orientation (default or reverse depending on sensor).</constant>+ <constant name="SENSOR_ORIENTATION_UNDEFINED" value="0" enum="SensorOrientation">+ Unspecified screen sensor orientation.+ </constant>+ <constant name="SENSOR_ORIENTATION_PORTRAIT" value="1" enum="SensorOrientation">+ Portrait orientation (either standard portrait or reverse portrait).+ </constant>+ <constant name="SENSOR_ORIENTATION_LANDSCAPE" value="2" enum="SensorOrientation">+ Landscape orientation (either standard landscape or reverse landscape).+ </constant><constant name="KEYBOARD_TYPE_DEFAULT" value="0" enum="VirtualKeyboardType">Default text virtual keyboard.</constant>diff --git a/drivers/apple_embedded/godot_view_controller.mm b/drivers/apple_embedded/godot_view_controller.mmindex a1866bc3456..1c7dd1fdec7 100644--- a/drivers/apple_embedded/godot_view_controller.mm+++ b/drivers/apple_embedded/godot_view_controller.mm@@ -290,11 +290,11 @@DisplayServer *display_server = DisplayServer::get_singleton();if (display_server) {- int out = 0;+ int out = DisplayServerEnums::SENSOR_ORIENTATION_UNDEFINED;if (UIInterfaceOrientationIsPortrait(orientation)) {- out = 1;+ out = DisplayServerEnums::SENSOR_ORIENTATION_PORTRAIT;} else if (UIInterfaceOrientationIsLandscape(orientation)) {- out = 2;+ out = DisplayServerEnums::SENSOR_ORIENTATION_LANDSCAPE;}display_server->emit_signal("orientation_changed", out);}diff --git a/misc/extension_api_validation/4.7-stable/GH-121895.txt b/misc/extension_api_validation/4.7-stable/GH-121895.txtnew file mode 100644index 00000000000..66e3b4b59f0--- /dev/null+++ b/misc/extension_api_validation/4.7-stable/GH-121895.txt@@ -0,0 +1,6 @@+GH-121895+---------++Validate extension JSON: Error: Field 'classes/DisplayServer/signals/orientation_changed/arguments/0': type changed value in new API, from "int" to "enum::DisplayServer.SensorOrientation".++Added a dedicated enum for the `orientation_changed` signal to make it easier to validate the orientation returned by the signal. The underlying int values remain unchanged.diff --git a/servers/display/display_server.cpp b/servers/display/display_server.cppindex 81249efcac1..0bbc9b1e11a 100644--- a/servers/display/display_server.cpp+++ b/servers/display/display_server.cpp@@ -1363,7 +1363,7 @@ void DisplayServer::unregister_additional_output(Object *p_object) {}void DisplayServer::_bind_methods() {- ADD_SIGNAL(MethodInfo("orientation_changed", PropertyInfo(Variant::INT, "orientation")));+ ADD_SIGNAL(MethodInfo("orientation_changed", PropertyInfo(Variant::INT, "orientation", PROPERTY_HINT_NONE, String(), PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_CLASS_IS_ENUM, "DisplayServer.SensorOrientation")));ClassDB::bind_method(D_METHOD("has_feature", "feature"), &DisplayServer::has_feature);ClassDB::bind_method(D_METHOD("get_name"), &DisplayServer::get_name);@@ -1898,6 +1898,10 @@ void DisplayServer::_bind_methods() {BIND_ENUM_CONSTANT(DisplayServerEnums::SCREEN_SENSOR_PORTRAIT);BIND_ENUM_CONSTANT(DisplayServerEnums::SCREEN_SENSOR);+ BIND_ENUM_CONSTANT(DisplayServerEnums::SENSOR_ORIENTATION_UNDEFINED);+ BIND_ENUM_CONSTANT(DisplayServerEnums::SENSOR_ORIENTATION_PORTRAIT);+ BIND_ENUM_CONSTANT(DisplayServerEnums::SENSOR_ORIENTATION_LANDSCAPE);+BIND_ENUM_CONSTANT(DisplayServerEnums::KEYBOARD_TYPE_DEFAULT);BIND_ENUM_CONSTANT(DisplayServerEnums::KEYBOARD_TYPE_MULTILINE);BIND_ENUM_CONSTANT(DisplayServerEnums::KEYBOARD_TYPE_NUMBER);diff --git a/servers/display/display_server.h b/servers/display/display_server.hindex b49f986f711..482e82be1db 100644--- a/servers/display/display_server.h+++ b/servers/display/display_server.h@@ -646,6 +646,7 @@ VARIANT_ENUM_CAST_EXT(DisplayServerEnums::MouseMode, DisplayServer::MouseMode)VARIANT_ENUM_CAST_EXT(DisplayServerEnums::CursorShape, DisplayServer::CursorShape)VARIANT_ENUM_CAST_EXT(DisplayServerEnums::VirtualKeyboardType, DisplayServer::VirtualKeyboardType)VARIANT_ENUM_CAST_EXT(DisplayServerEnums::ScreenOrientation, DisplayServer::ScreenOrientation)+VARIANT_ENUM_CAST_EXT(DisplayServerEnums::SensorOrientation, DisplayServer::SensorOrientation)VARIANT_ENUM_CAST_EXT(DisplayServerEnums::HandleType, DisplayServer::HandleType)VARIANT_ENUM_CAST_EXT(DisplayServerEnums::WindowMode, DisplayServer::WindowMode)VARIANT_ENUM_CAST_EXT(DisplayServerEnums::WindowFlags, DisplayServer::WindowFlags)diff --git a/servers/display/display_server_enums.h b/servers/display/display_server_enums.hindex 5c8b7e997ce..ea956ddf799 100644--- a/servers/display/display_server_enums.h+++ b/servers/display/display_server_enums.h@@ -172,6 +172,15 @@ enum ScreenOrientation {SCREEN_SENSOR,};+// Values returned by the DisplayServer `orientation_changed` signal.+// Unlike ScreenOrientation, which represents the desired screen orientation and can be used to get or set the screen orientation,+// SensorOrientation represents the actual screen orientation detected. It can be used with ScreenOrientation::SCREEN_SENSOR.+enum SensorOrientation {+ SENSOR_ORIENTATION_UNDEFINED,+ SENSOR_ORIENTATION_PORTRAIT,+ SENSOR_ORIENTATION_LANDSCAPE,+};+/* WINDOW */typedef int WindowID;