Browse Source

added custom ui scaling

Jonathan Higgins 3 months ago
parent
commit
60eb62af2a

+ 1 - 0
Global/config_handler.gd

@@ -20,6 +20,7 @@ func _ready():
 	ensure_setting("interface_settings", "invert_theme", false)
 	ensure_setting("interface_settings", "high_contrast_selected_cables", false)
 	ensure_setting("interface_settings", "swap_zoom_and_move", false)
+	ensure_setting("interface_settings", "ui_scale_multiplier", 1.0)
 	ensure_setting("interface_settings", "delete_intermediate", true)
 	ensure_setting("interface_settings", "reuse_output_folder", true)
 	ensure_setting("interface_settings", "last_used_output_folder", "no_file")

+ 22 - 6
scenes/main/scripts/control.gd

@@ -16,7 +16,8 @@ var helpfile #tracks which help file the user was trying to load when savechange
 var outfilename #links to the user name for outputfile field
 var foldertoggle #links to the reuse folder button
 #var lastoutputfolder = "none" #tracks last output folder, this can in future be used to replace global.outfile but i cba right now
-var uiscale = 1.0 #tracks scaling for retina screens
+var uiscale = 0.0 # tracks the overal ui scale after hidpi adjustment and user offset
+var retina_scaling = 1.0 #tracks scaling for retina screens
 var use_anyway #used to store the folder selected for cdprogs when it appears the wrong folder is selected but the user wants to use it anyway
 var main_theme = preload("res://theme/main_theme.tres") #load the theme
 var default_input_node #stores a reference to the input node created on launch to allow auto loading a wav file
@@ -90,16 +91,28 @@ func make_signal_connections():
 	get_node("Settings").console_on_top.connect(change_console_settings)
 	get_node("Settings").invert_ui.connect(invert_theme_toggled)
 	get_node("Settings").swap_zoom_and_move.connect(swap_zoom_and_move)
+	get_node("Settings").ui_scale_multiplier_changed.connect(scale_ui)
 	
 func hidpi_adjustment():
 	#checks if display is hidpi and scales ui accordingly hidpi - 144
 	if DisplayServer.screen_get_dpi(0) >= 144:
-		uiscale = 2.0
-		get_window().content_scale_factor = uiscale
-		#goes through popup_windows group and scales all popups and resizes them
-		for window in get_tree().get_nodes_in_group("popup_windows"):
+		retina_scaling = 2.0
+	else:
+		retina_scaling = 1.0
+		
+
+func scale_ui(scale_multiplier: float):
+	var old_uiscale = uiscale
+	uiscale = retina_scaling * scale_multiplier
+	get_window().content_scale_factor = uiscale
+	#goes through popup_windows group and scales all popups and resizes them
+	for window in get_tree().get_nodes_in_group("popup_windows"):
+		if old_uiscale != 0: #if ui scale = 0 this is the first time this is being adjusted so no need to revert values back to default first
+			window.size = (window.size / old_uiscale) * uiscale
+		else:
 			window.size = window.size * uiscale
-			window.content_scale_factor = uiscale
+		window.content_scale_factor = uiscale
+	
 
 func load_from_filesystem():
 	#checks if user has opened a file from the system file menu and loads it
@@ -207,6 +220,9 @@ func check_user_preferences():
 	#set the theme to either the main theme or inverted theme depending on user preferences
 	invert_theme_toggled(interface_settings.invert_theme)
 	swap_zoom_and_move(interface_settings.swap_zoom_and_move)
+	
+	#scale ui
+	scale_ui(interface_settings.ui_scale_multiplier)
 
 		
 func show_cdp_location():

+ 7 - 0
scenes/main/scripts/settings.gd

@@ -3,6 +3,7 @@ signal open_cdp_location
 signal console_on_top
 signal invert_ui
 signal swap_zoom_and_move
+signal ui_scale_multiplier_changed
 
 var interface_settings
 var main_theme = preload("res://theme/main_theme.tres")
@@ -30,6 +31,7 @@ func _on_about_to_popup() -> void:
 	$VBoxContainer/HBoxContainer/CustomColourPicker.color = Color(interface_settings.theme_custom_colour)
 	$VBoxContainer/invert_ui_container/InvertUI.button_pressed = interface_settings.invert_theme
 	$VBoxContainer/high_contrast_cables_container/HighContrastCablesToggle.button_pressed = interface_settings.high_contrast_selected_cables
+	$VBoxContainer/ui_scale_container2/UIScaleOffsetSpinbox.value = interface_settings.ui_scale_multiplier
 	$VBoxContainer/HBoxContainer8/SwapZoomAndMoveToggle.button_pressed = interface_settings.swap_zoom_and_move
 	$VBoxContainer/HBoxContainer2/PvocWarning.button_pressed = interface_settings.disable_pvoc_warning
 	$VBoxContainer/HBoxContainer6/ProgressBar.button_pressed = interface_settings.disable_progress_bar
@@ -88,3 +90,8 @@ func _on_swap_zoom_and_move_toggle_toggled(toggled_on: bool) -> void:
 
 func _on_high_contrast_cables_toggle_toggled(toggled_on: bool) -> void:
 	ConfigHandler.save_interface_settings("high_contrast_selected_cables", toggled_on)
+
+
+func _on_ui_scale_offset_spinbox_value_changed(value: float) -> void:
+	ConfigHandler.save_interface_settings("ui_scale_multiplier", value)
+	ui_scale_multiplier_changed.emit(value)

+ 18 - 2
scenes/main/settings.tscn

@@ -7,7 +7,7 @@
 auto_translate_mode = 1
 title = "SoundThread Settings"
 initial_position = 2
-size = Vector2i(500, 545)
+size = Vector2i(500, 607)
 transient = true
 unresizable = true
 always_on_top = true
@@ -15,7 +15,7 @@ script = ExtResource("1_uey6c")
 
 [node name="ColorRect" type="ColorRect" parent="." groups=["invertable_background"]]
 offset_right = 506.0
-offset_bottom = 550.0
+offset_bottom = 616.0
 color = Color(0.101961, 0.101961, 0.101961, 0.6)
 script = ExtResource("2_bym2s")
 
@@ -118,6 +118,21 @@ text = "High Contrast Selected Cables:"
 layout_mode = 2
 size_flags_horizontal = 3
 
+[node name="ui_scale_container2" type="HBoxContainer" parent="VBoxContainer"]
+layout_mode = 2
+
+[node name="Label" type="Label" parent="VBoxContainer/ui_scale_container2"]
+layout_mode = 2
+size_flags_horizontal = 3
+text = "Ui Scale:"
+
+[node name="UIScaleOffsetSpinbox" type="SpinBox" parent="VBoxContainer/ui_scale_container2"]
+layout_mode = 2
+min_value = 0.1
+max_value = 5.0
+step = 0.1
+value = 1.0
+
 [node name="Controls" type="Label" parent="VBoxContainer"]
 layout_mode = 2
 theme_override_font_sizes/font_size = 18
@@ -191,6 +206,7 @@ size_flags_horizontal = 3
 [connection signal="color_changed" from="VBoxContainer/HBoxContainer/CustomColourPicker" to="." method="_on_custom_colour_picker_color_changed"]
 [connection signal="toggled" from="VBoxContainer/invert_ui_container/InvertUI" to="." method="_on_invert_ui_toggled"]
 [connection signal="toggled" from="VBoxContainer/high_contrast_cables_container/HighContrastCablesToggle" to="." method="_on_high_contrast_cables_toggle_toggled"]
+[connection signal="value_changed" from="VBoxContainer/ui_scale_container2/UIScaleOffsetSpinbox" to="." method="_on_ui_scale_offset_spinbox_value_changed"]
 [connection signal="toggled" from="VBoxContainer/HBoxContainer8/SwapZoomAndMoveToggle" to="." method="_on_swap_zoom_and_move_toggle_toggled"]
 [connection signal="toggled" from="VBoxContainer/HBoxContainer2/PvocWarning" to="." method="_on_pvoc_warning_toggled"]
 [connection signal="toggled" from="VBoxContainer/HBoxContainer6/ProgressBar" to="." method="_on_progress_bar_toggled"]

File diff suppressed because it is too large
+ 3 - 1
theme/main_theme.tres


Some files were not shown because too many files changed in this diff