Grid size and color in preferences, update_texture optimization

- Added grid size and color in preferences
- Canvas' update_texture() updates the frame button's texture only when the user releases a mouse button. This should optimize drawing in large images.
- Cursor is no longer invisible inside the canvas
- Minor UI changes
- Added some more translations. This is going to be a common thing in commits from now on.
This commit is contained in:
OverloadedOrama 2019-12-07 19:34:54 +02:00
parent ade2d05a1b
commit d81d7ee5ef
7 changed files with 211 additions and 141 deletions

View file

@ -112,8 +112,6 @@ func _process(delta : float) -> void:
Input.set_custom_mouse_cursor(preload("res://Assets/Graphics/Tools/Bucket_Cursor.png"), 0, Vector2(6, 27))
elif Global.current_left_tool == "ColorPicker":
Input.set_custom_mouse_cursor(preload("res://Assets/Graphics/Tools/ColorPicker_Cursor.png"), 0, Vector2(5, 28))
elif Global.current_left_tool != "RectSelect":
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
else:
if !Input.is_mouse_button_pressed(BUTTON_LEFT) && !Input.is_mouse_button_pressed(BUTTON_RIGHT):
if mouse_inside_canvas:
@ -121,10 +119,8 @@ func _process(delta : float) -> void:
Global.cursor_position_label.text = "[%s×%s]" % [size.x, size.y]
if cursor_inside_canvas:
cursor_inside_canvas = false
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
Input.set_custom_mouse_cursor(null)
#Handle Undo/Redo
var can_handle : bool = mouse_in_canvas && Global.can_draw && Global.has_focus
var mouse_pressed : bool = (Input.is_action_just_pressed("left_mouse") && !Input.is_action_pressed("right_mouse")) || (Input.is_action_just_pressed("right_mouse") && !Input.is_action_pressed("left_mouse"))
@ -276,7 +272,7 @@ func _process(delta : float) -> void:
previous_action = current_action
if sprite_changed_this_frame:
update_texture(current_layer_index)
update_texture(current_layer_index, (Input.is_action_just_released("left_mouse") || Input.is_action_just_released("right_mouse")))
func handle_undo(action : String) -> void:
var canvases := []
@ -319,22 +315,23 @@ func handle_redo(action : String) -> void:
Global.undo_redo.add_do_method(Global, "redo", canvases, layer_index)
Global.undo_redo.commit_action()
func update_texture(layer_index : int) -> void:
func update_texture(layer_index : int, update_frame_tex := true) -> void:
layers[layer_index][1].create_from_image(layers[layer_index][0], 0)
var layer_container := get_layer_container(layer_index)
if layer_container:
layer_container.get_child(0).get_child(1).texture = layers[layer_index][1]
#This code is used to update the texture in the animation timeline frame button
#but blend_rect causes major performance issues on large images
var whole_image := Image.new()
whole_image.create(size.x, size.y, false, Image.FORMAT_RGBA8)
for layer in layers:
whole_image.blend_rect(layer[0], Rect2(position, size), Vector2.ZERO)
layer[0].lock()
var whole_image_texture := ImageTexture.new()
whole_image_texture.create_from_image(whole_image, 0)
frame_texture_rect.texture = whole_image_texture
if update_frame_tex:
#This code is used to update the texture in the animation timeline frame button
#but blend_rect causes major performance issues on large images
var whole_image := Image.new()
whole_image.create(size.x, size.y, false, Image.FORMAT_RGBA8)
for layer in layers:
whole_image.blend_rect(layer[0], Rect2(position, size), Vector2.ZERO)
layer[0].lock()
var whole_image_texture := ImageTexture.new()
whole_image_texture.create_from_image(whole_image, 0)
frame_texture_rect.texture = whole_image_texture
func frame_changed(value : int) -> void:
frame = value
@ -394,10 +391,10 @@ func _draw() -> void:
#Idea taken from flurick (on GitHub)
if Global.draw_grid:
for x in size.x:
draw_line(Vector2(x, location.y), Vector2(x, size.y), Color.black, true)
for y in size.y:
draw_line(Vector2(location.x, y), Vector2(size.x, y), Color.black, true)
for x in range(0, size.x, Global.grid_width):
draw_line(Vector2(x, location.y), Vector2(x, size.y), Global.grid_color, true)
for y in range(0, size.y, Global.grid_height):
draw_line(Vector2(location.x, y), Vector2(size.x, y), Global.grid_color, true)
#Draw rectangle to indicate the pixel currently being hovered on
var mouse_pos := get_local_mouse_position() + location

View file

@ -15,6 +15,12 @@ var hidden_canvases := []
# warning-ignore:unused_class_variable
var selected_pixels := []
var image_clipboard : Image
# warning-ignore:unused_class_variable
var grid_width := 1
# warning-ignore:unused_class_variable
var grid_height := 1
# warning-ignore:unused_class_variable
var grid_color := Color.black
#Tools & options
# warning-ignore:unused_class_variable

View file

@ -38,7 +38,7 @@ func _ready() -> void:
# Set the language option menu's default selected option to the loaded locale
var locale_index := loaded_locales.find(saved_locale)
$PreferencesDialog/LanguageContainer/LanguageOption.selected = locale_index + 1
$PreferencesDialog/VBoxContainer/OptionsContainer/LanguageOption.selected = locale_index + 1
else: # If the user doesn't have a language preference, set it to their OS' locale
TranslationServer.set_locale(OS.get_locale())
@ -309,9 +309,9 @@ func help_menu_id_pressed(id : int) -> void:
Global.can_draw = false
func _on_CreateNewImage_confirmed() -> void:
var width = $CreateNewImage/VBoxContainer/WidthCont/WidthValue.value
var height = $CreateNewImage/VBoxContainer/HeightCont/HeightValue.value
var fill_color : Color = $CreateNewImage/VBoxContainer/FillColor/FillColor.color
var width : int = $CreateNewImage/VBoxContainer/OptionsContainer/WidthValue.value
var height : int = $CreateNewImage/VBoxContainer/OptionsContainer/HeightValue.value
var fill_color : Color = $CreateNewImage/VBoxContainer/OptionsContainer/FillColor.color
clear_canvases()
Global.canvas = load("res://Prefabs/Canvas.tscn").instance()
Global.canvas.size = Vector2(width, height).floor()
@ -591,9 +591,9 @@ func save_spritesheet() -> void:
OS.alert("Can't save file")
func _on_ScaleImage_confirmed() -> void:
var width = $ScaleImage/VBoxContainer/WidthCont/WidthValue.value
var height = $ScaleImage/VBoxContainer/HeightCont/HeightValue.value
var interpolation = $ScaleImage/VBoxContainer/InterpolationContainer/InterpolationType.selected
var width : int = $ScaleImage/VBoxContainer/OptionsContainer/WidthValue.value
var height : int = $ScaleImage/VBoxContainer/OptionsContainer/HeightValue.value
var interpolation : int = $ScaleImage/VBoxContainer/OptionsContainer/InterpolationType.selected
Global.undos += 1
Global.undo_redo.create_action("Scale")
Global.undo_redo.add_do_property(Global.canvas, "size", Vector2(width, height).floor())
@ -618,6 +618,15 @@ func _on_LanguageOption_item_selected(ID : int) -> void:
config_cache.set_value("preferences", "locale", TranslationServer.get_locale())
config_cache.save("user://cache.ini")
func _on_GridWidthValue_value_changed(value : float) -> void:
Global.grid_width = value
func _on_GridHeightValue_value_changed(value : float) -> void:
Global.grid_height = value
func _on_GridColor_color_changed(color : Color) -> void:
Global.grid_color = color
func _on_ImportSprites_popup_hide() -> void:
if !opensprite_file_selected:
Global.can_draw = true
@ -1003,4 +1012,3 @@ func _exit_tree() -> void:
config_cache.set_value("window", "position", OS.window_position)
config_cache.set_value("window", "size", OS.window_size)
config_cache.save("user://cache.ini")