@@ -365,33 +365,44 @@ func get_min_ui_scale() -> float:
365365 return maxf (snappedf (get_max_ui_scale () / 2.0 - 0.125 , 0.25 ), 0.75 )
366366
367367func get_auto_ui_scale () -> float :
368- # Usable rect might not be reliable on web, so attempt to use devicePixelRatio.
369- if OS .get_name () == "Web" :
370- var pixel_ratio : float = JavaScriptBridge .eval ("window.devicePixelRatio || 1" , true )
371- if is_finite (pixel_ratio ):
372- return snappedf (pixel_ratio , 0.25 )
373-
374- var screen_size := get_usable_rect ()
375- if screen_size .x == 0 or screen_size .y == 0 :
376- return 1.0
377-
378- # The wider the screen, the bigger the automatically chosen UI scale.
379- var aspect_ratio := screen_size .aspect ()
380- var auto_scale := get_max_ui_scale () * clampf (aspect_ratio * 0.375 , 0.6 , 0.8 )
381- if OS .get_name () == "Android" :
382- auto_scale *= 1.1 # Default to giving mobile a bit more space.
383- return clampf (snappedf (auto_scale , 0.25 ), get_min_ui_scale (), get_max_ui_scale ())
368+ var dpi := DisplayServer .screen_get_dpi (DisplayServer .window_get_current_screen ())
369+ print (dpi )
370+ if dpi <= 120 :
371+ return 0.75 # ldpi
372+ elif dpi <= 160 :
373+ return 1.0 # mdpi
374+ elif dpi <= 240 :
375+ return 1.5 # hdpi
376+ elif dpi <= 320 :
377+ return 2.0 # xhdpi
378+ elif dpi <= 400 :
379+ return 2.5
380+ elif dpi <= 480 :
381+ return 3.0 # xxhdpi
382+ elif dpi <= 640 :
383+ return 4.0 # xxxhdpi
384+ else :
385+ return 5.0
384386
385387
386388func update_ui_scale () -> void :
387389 var window := get_window ()
388390 if not window .is_node_ready ():
389391 await window .ready
390- if Configs .savedata .ui_scale == SaveData .ScalingApproach .AUTO :
391- window .content_scale_factor = _calculate_auto_scale ()
392- else :
393- var final_scale := minf (Configs .savedata .ui_scale , 4.0 )
394- window .content_scale_factor = final_scale
392+ var ui_scaling_approach := Configs .savedata .ui_scale
393+ var final_scale : float
394+ match ui_scaling_approach :
395+ SaveData .ScalingApproach .AUTO : final_scale = get_auto_ui_scale ()
396+ SaveData .ScalingApproach .CONSTANT_075 : final_scale = 0.75
397+ SaveData .ScalingApproach .CONSTANT_100 : final_scale = 1.0
398+ SaveData .ScalingApproach .CONSTANT_125 : final_scale = 1.25
399+ SaveData .ScalingApproach .CONSTANT_150 : final_scale = 1.50
400+ SaveData .ScalingApproach .CONSTANT_175 : final_scale = 1.75
401+ SaveData .ScalingApproach .CONSTANT_200 : final_scale = 2.0
402+ SaveData .ScalingApproach .CONSTANT_250 : final_scale = 2.5
403+ SaveData .ScalingApproach .CONSTANT_300 : final_scale = 3.0
404+ SaveData .ScalingApproach .CONSTANT_400 : final_scale = 4.0
405+ window .content_scale_factor = final_scale
395406
396407
397408func prompt_quit () -> void :
@@ -482,25 +493,6 @@ func open_export() -> void:
482493 confirm_dialog .setup (Translator .translate ("Export SVG" ), message ,
483494 Translator .translate ("Export" ), FileUtils .open_export_dialog .bind (svg_export_data ))
484495
485- func _calculate_auto_scale () -> float :
486- var dpi := DisplayServer .screen_get_dpi (DisplayServer .window_get_current_screen ())
487-
488- # if dpi <= 120:
489- # return 0.75 # ldpi
490- if dpi <= 160 :
491- return 1.0 # mdpi (baseline)
492- elif dpi <= 240 :
493- return 1.5 # hdpi
494- elif dpi <= 320 :
495- return 2.0 # xhdpi
496- elif dpi <= 480 :
497- return 3.0 # xxhdpi
498- elif dpi <= 640 :
499- return 4.0 # xxxhdpi
500- else :
501- return 5.0 # Beyond xxxhdpi
502-
503-
504496func update_window_title () -> void :
505497 if Configs .savedata .use_filename_for_window_title and \
506498 not Configs .savedata .get_active_tab ().svg_file_path .is_empty ():
0 commit comments