Skip to content

Commit

Permalink
Scale custom cursor with UI size - closes #642
Browse files Browse the repository at this point in the history
  • Loading branch information
OverloadedOrama committed Mar 21, 2022
1 parent 0e79138 commit 1c3103e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
33 changes: 25 additions & 8 deletions src/Main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extends Control
var opensprite_file_selected := false
var redone := false
var is_quitting_on_save := false
var cursor_image = preload("res://assets/graphics/cursor.png")
var cursor_image: Texture = preload("res://assets/graphics/cursor.png")

onready var ui := $MenuAndUI/UI/DockableContainer
onready var canvas_preview_container := ui.find_node("CanvasPreviewContainer")
Expand All @@ -19,8 +19,6 @@ func _ready() -> void:
if OS.get_name() == "OSX":
_use_osx_shortcuts()

if !Global.native_cursors:
Input.set_custom_mouse_cursor(cursor_image, Input.CURSOR_CROSS, Vector2(15, 15))
Global.window_title = tr("untitled") + " - Pixelorama " + Global.current_version

Global.current_project.layers[0].name = tr("Layer") + " 0"
Expand Down Expand Up @@ -104,17 +102,18 @@ func _input(event: InputEvent) -> void:


func _setup_application_window_size() -> void:
if OS.get_name() == "HTML5":
return
# Set a minimum window size to prevent UI elements from collapsing on each other.
OS.min_window_size = Vector2(1024, 576)

get_tree().set_screen_stretch(
SceneTree.STRETCH_MODE_DISABLED,
SceneTree.STRETCH_ASPECT_IGNORE,
Vector2(1024, 576),
Global.shrink
)
set_custom_cursor()

if OS.get_name() == "HTML5":
return
# Set a minimum window size to prevent UI elements from collapsing on each other.
OS.min_window_size = Vector2(1024, 576)

# Restore the window position/size if values are present in the configuration cache
if Global.config_cache.has_section_key("window", "screen"):
Expand All @@ -129,6 +128,24 @@ func _setup_application_window_size() -> void:
OS.window_size = Global.config_cache.get_value("window", "size")


func set_custom_cursor() -> void:
if Global.native_cursors:
return

if Global.shrink == 1.0:
Input.set_custom_mouse_cursor(cursor_image, Input.CURSOR_CROSS, Vector2(15, 15))
else:
var cursor_data := cursor_image.get_data()
cursor_data.resize(
cursor_data.get_width() * Global.shrink, cursor_data.get_height() * Global.shrink, 0
)
var new_cursor_tex := ImageTexture.new()
new_cursor_tex.create_from_image(cursor_data, 0)
Input.set_custom_mouse_cursor(
new_cursor_tex, Input.CURSOR_CROSS, Vector2(15, 15) * Global.shrink
)


func _show_splash_screen() -> void:
if not Global.config_cache.has_section_key("preferences", "startup"):
Global.config_cache.set_value("preferences", "startup", true)
Expand Down
7 changes: 3 additions & 4 deletions src/Preferences/PreferencesDialog.gd
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,10 @@ func preference_update(prop: String) -> void:
Tools.set_button_size(Global.tool_button_size)

if prop == "native_cursors":
var image
if Global.native_cursors:
image = null
Input.set_custom_mouse_cursor(null, Input.CURSOR_CROSS, Vector2(15, 15))
else:
image = Global.control.cursor_image
Input.set_custom_mouse_cursor(image, Input.CURSOR_CROSS, Vector2(15, 15))
Global.control.set_custom_cursor()

if prop == "cross_cursor":
if Global.cross_cursor:
Expand Down Expand Up @@ -323,6 +321,7 @@ func _on_ShrinkApplyButton_pressed() -> void:
Vector2(1024, 576),
Global.shrink
)
Global.control.set_custom_cursor()
hide()
popup_centered(Vector2(400, 280))
Global.dialog_open(true)
Expand Down

0 comments on commit 1c3103e

Please sign in to comment.