Skip to content

Commit

Permalink
UI scaling related fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
RodZill4 committed Nov 7, 2024
1 parent b5330fa commit ee830de
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 13 deletions.
3 changes: 1 addition & 2 deletions addons/flexible_layout/flexible_layout.gd
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,7 @@ class FlexLayout:
if rect.size.x == 0 or rect.size.y == 0:
return
if top:
var scale : float = control.get_window().content_scale_factor
rect.size = Vector2i(Vector2(rect.size)/scale)
rect.size = Vector2i(Vector2(rect.size))
top.layout(rect)
main_control.layout_changed.emit()

Expand Down
8 changes: 8 additions & 0 deletions material_maker/globals.gd
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ func _enter_tree():
func _exit_tree():
config.save("user://mm_config.ini")

# Config

func has_config(key : String) -> bool:
return config.has_section_key("config", key)

Expand All @@ -52,6 +54,7 @@ func get_config(key : String):
func set_config(key : String, value):
config.set_value("config", key, value)

# Clipboard parsing

func try_parse_palette(hex_values_str : String) -> Dictionary:
var points = []
Expand Down Expand Up @@ -137,5 +140,10 @@ func parse_paste_data(data : String):
last_parsed_paste_data = { type=type, graph=graph }
return { type=type, graph=graph }

# Misc. UI functions

func screen_space_mouse_position(control : Control) -> Vector2:
return control.get_local_mouse_position()*control.get_viewport().content_scale_factor+control.get_screen_position()

func set_tip_text(tip : String, timeout : float = 0.0):
main_window.set_tip_text(tip, timeout)
6 changes: 6 additions & 0 deletions material_maker/main_window.gd
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ func _ready() -> void:

mm_logger.message("Material Maker "+ProjectSettings.get_setting("application/config/actual_release"))

size = get_viewport().size/get_viewport().content_scale_factor
position = Vector2i(0, 0)


var menu_update_requested : bool = false

func update_menus() -> void:
Expand Down Expand Up @@ -287,6 +291,8 @@ func on_config_changed() -> void:
# This prevents UI elements from being too small on hiDPI displays.
ui_scale = 2 if DisplayServer.screen_get_dpi() >= 192 and DisplayServer.screen_get_size().x >= 2048 else 1
get_viewport().content_scale_factor = ui_scale
size = get_viewport().size/get_viewport().content_scale_factor
position = Vector2i(0, 0)
#ProjectSettings.set_setting("display/window/stretch/scale", scale)

# Clamp to reasonable values to avoid crashes on startup.
Expand Down
6 changes: 3 additions & 3 deletions material_maker/nodes/base.gd
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func randomness_button_create_popup():
if ! generator.is_seed_locked() and DisplayServer.clipboard_get().left(5) == "seed=":
menu.add_item(tr("Paste seed"), 2)
add_child(menu)
menu.popup(Rect2i(get_local_mouse_position()+get_screen_position(), Vector2i(0, 0)))
menu.popup(Rect2(mm_globals.screen_space_mouse_position(self), Vector2(0, 0)))
menu.connect("popup_hide", Callable(menu, "queue_free"))
menu.connect("id_pressed", Callable(self, "_on_seed_menu"))

Expand All @@ -96,7 +96,7 @@ func buffer_button_create_popup():
menu.add_separator()
menu.add_item(tr("Dump buffers"), MENU_BUFFER_DUMP)
add_child(menu)
menu.popup(Rect2(get_local_mouse_position()+get_screen_position(), Vector2(0, 0)))
menu.popup(Rect2(mm_globals.screen_space_mouse_position(self), Vector2(0, 0)))
menu.connect("popup_hide",Callable(menu,"queue_free"))
menu.connect("id_pressed",Callable(self,"_on_buffer_menu"))

Expand Down Expand Up @@ -281,7 +281,7 @@ func _on_gui_input(event) -> void:
add_child(menu)
menu.popup_hide.connect(menu.queue_free)
menu.id_pressed.connect(self._on_menu_id_pressed)
menu.popup(Rect2(get_local_mouse_position()+get_screen_position(), Vector2(0, 0)))
menu.popup(Rect2(mm_globals.screen_space_mouse_position(self), Vector2(0, 0)))
else:
menu.free()
elif doubleclicked:
Expand Down
2 changes: 1 addition & 1 deletion material_maker/nodes/generic/generic.gd
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func generic_button_create_popup():
add_child(popup_menu)
popup_menu.connect("popup_hide",Callable(popup_menu,"queue_free"))
popup_menu.connect("id_pressed",Callable(self,"update_generic"))
popup_menu.popup(Rect2(get_local_mouse_position()+get_screen_position(), Vector2(0, 0)))
popup_menu.popup(Rect2(mm_globals.screen_space_mouse_position(self), Vector2(0, 0)))



Expand Down
2 changes: 1 addition & 1 deletion material_maker/panels/library/library.gd
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func _on_Tree_item_rmb_selected(mouse_position : Vector2i):
item_menu.set_item_disabled(0, read_only)
item_menu.set_item_disabled(1, read_only)
item_menu.set_item_disabled(2, read_only)
item_menu.popup(Rect2(get_local_mouse_position()+get_screen_position(), Vector2(0, 0)))
item_menu.popup(Rect2(mm_globals.screen_space_mouse_position(self), Vector2(0, 0)))

func _on_PopupMenu_index_pressed(index):
var library_index : int = 0
Expand Down
2 changes: 1 addition & 1 deletion material_maker/panels/preview_2d/preview_2d_panel.gd
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func _on_gui_input(event):
elif event.is_command_or_control_pressed():
zooming = true
MOUSE_BUTTON_RIGHT:
$ContextMenu.popup(Rect2(get_local_mouse_position()+get_screen_position(), Vector2(0, 0)))
$ContextMenu.popup(Rect2(mm_globals.screen_space_mouse_position(self), Vector2(0, 0)))
else:
dragging = false
zooming = false
Expand Down
2 changes: 1 addition & 1 deletion material_maker/panels/preview_3d/preview_3d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func on_gui_input(event) -> void:

if event.pressed and lpressed != rpressed: # xor
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
_mouse_start_position = event.global_position/get_window().content_scale_factor
_mouse_start_position = event.global_position
moving = true
elif not lpressed and not rpressed:
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) # allow and hide cursor warp
Expand Down
3 changes: 1 addition & 2 deletions material_maker/panels/preview_3d/preview_3d_panel.gd
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ func on_right_click():
#todo $MaterialPreview.keep_3d_linear = true
await get_tree().process_frame
await get_tree().process_frame
await get_tree().process_frame
# Pick position in image
var texture : ViewportTexture = $MaterialPreview.get_texture()
var image : Image = texture.get_image()
Expand All @@ -36,7 +35,7 @@ func on_right_click():
# Reset normal rendering
current_object.set_surface_override_material(0, material_save)
$TextureRect.visible = false
$PopupMenu.popup(Rect2(get_local_mouse_position()+get_screen_position(), Vector2(0, 0)))
$PopupMenu.popup(Rect2(mm_globals.screen_space_mouse_position(self), Vector2(0, 0)))

func _on_PopupMenu_id_pressed(id):
var pivot = get_node("MaterialPreview/Preview3d/ObjectsPivot/Objects")
Expand Down
2 changes: 1 addition & 1 deletion material_maker/panels/reference/reference_panel.gd
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func _on_Image_gui_input(event) -> void:
elif event.button_index == MOUSE_BUTTON_MIDDLE:
dragging = true
elif event.button_index == MOUSE_BUTTON_RIGHT:
$ContextMenu.popup(Rect2(get_local_mouse_position()+get_screen_position(), Vector2(0, 0)))
$ContextMenu.popup(Rect2(mm_globals.screen_space_mouse_position(self), Vector2(0, 0)))
elif event.button_index == MOUSE_BUTTON_MIDDLE:
dragging = false
elif event.button_index == MOUSE_BUTTON_LEFT:
Expand Down
2 changes: 1 addition & 1 deletion material_maker/windows/sdf_builder/sdf_builder.gd
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func show_menu(current_item : TreeItem):
add_child(menu)
menu.id_pressed.connect(self._on_menu.bind(current_item))
menu.popup_hide.connect(menu.queue_free)
menu.popup(Rect2($VBoxContainer.get_local_mouse_position()+$VBoxContainer.get_screen_position(), Vector2(0, 0)))
menu.popup(Rect2(mm_globals.screen_space_mouse_position($VBoxContainer), Vector2(0, 0)))

func _on_Tree_gui_input(event : InputEvent):
if event is InputEventMouseButton:
Expand Down

0 comments on commit ee830de

Please sign in to comment.