Skip to content

Commit

Permalink
Optimize canvas drawing by only calling update when the image has cha…
Browse files Browse the repository at this point in the history
…nged
  • Loading branch information
OverloadedOrama committed Nov 6, 2023
1 parent ac1a438 commit ac6a4db
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/Tools/3DShapeEdit.gd
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ onready var object_properties := {
func sprite_changed_this_frame():
_checker_update_qued = true
_old_cel_image = _cel.get_image()
Global.canvas.sprite_changed_this_frame = true


func _input(_event: InputEvent) -> void:
Expand Down
3 changes: 3 additions & 0 deletions src/Tools/Move.gd
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func draw_start(position: Vector2) -> void:
if Global.current_project.has_selection:
selection_node.transform_content_start()
_content_transformation_check = selection_node.is_moving_content
Global.canvas.sprite_changed_this_frame = true


func draw_move(position: Vector2) -> void:
Expand All @@ -63,6 +64,7 @@ func draw_move(position: Vector2) -> void:
else:
Global.canvas.move_preview_location = position - _start_pos
_offset = position
Global.canvas.sprite_changed_this_frame = true


func draw_end(position: Vector2) -> void:
Expand Down Expand Up @@ -92,6 +94,7 @@ func draw_end(position: Vector2) -> void:

_start_pos = Vector2.INF
_snap_to_grid = false
Global.canvas.sprite_changed_this_frame = true


func _snap_position(position: Vector2) -> Vector2:
Expand Down
6 changes: 2 additions & 4 deletions src/UI/Canvas/Canvas.gd
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,12 @@ func _input(event: InputEvent) -> void:
var tmp_transform := get_canvas_transform().affine_inverse()
current_pixel = tmp_transform.basis_xform(tmp_position) + tmp_transform.origin

if Global.has_focus:
update()

sprite_changed_this_frame = false

Tools.handle_draw(current_pixel.floor(), event)

if sprite_changed_this_frame:
if Global.has_focus:
update()
update_selected_cels_textures()


Expand Down
7 changes: 7 additions & 0 deletions src/UI/Canvas/Selection.gd
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ func resize_selection() -> void:
Global.current_project.selection_map = selection_map_copy
Global.current_project.selection_map_changed()
update()
Global.canvas.update()


func _gizmo_rotate() -> void: # Does not work properly yet
Expand Down Expand Up @@ -430,6 +431,7 @@ func _gizmo_rotate() -> void: # Does not work properly yet
Global.current_project.selection_map_changed()
self.big_bounding_rectangle = bitmap_image.get_used_rect()
update()
Global.canvas.update()


func select_rect(rect: Rect2, operation: int = SelectionOperation.ADD) -> void:
Expand Down Expand Up @@ -482,6 +484,7 @@ func move_borders(move: Vector2) -> void:
marching_ants_outline.offset += move
self.big_bounding_rectangle.position += move
update()
Global.canvas.update()


func move_borders_end() -> void:
Expand All @@ -494,6 +497,7 @@ func move_borders_end() -> void:
else:
Global.current_project.selection_map_changed()
update()
Global.canvas.update()


func transform_content_start() -> void:
Expand All @@ -510,6 +514,7 @@ func transform_content_start() -> void:
original_big_bounding_rectangle = big_bounding_rectangle
original_offset = Global.current_project.selection_offset
update()
Global.canvas.update()


func move_content(move: Vector2) -> void:
Expand Down Expand Up @@ -554,6 +559,7 @@ func transform_content_confirm() -> void:
is_moving_content = false
is_pasting = false
update()
Global.canvas.update()


func transform_content_cancel() -> void:
Expand Down Expand Up @@ -584,6 +590,7 @@ func transform_content_cancel() -> void:
original_bitmap = SelectionMap.new()
is_pasting = false
update()
Global.canvas.update()


func commit_undo(action: String, undo_data_tmp: Dictionary) -> void:
Expand Down

0 comments on commit ac6a4db

Please sign in to comment.