mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +00:00
UndoRedo v12 - Guide support
- Guides now have undo/redo support when being moved. If they are moved outside the canvas they get queue_freed. - Updated icon.
This commit is contained in:
parent
66f3e8b00d
commit
122f42b361
|
@ -6,6 +6,7 @@ enum TYPE {HORIZONTAL, VERTICAL}
|
||||||
var font := preload("res://Assets/Fonts/Roboto-Regular.tres")
|
var font := preload("res://Assets/Fonts/Roboto-Regular.tres")
|
||||||
var has_focus := true
|
var has_focus := true
|
||||||
var mouse_pos := Vector2.ZERO
|
var mouse_pos := Vector2.ZERO
|
||||||
|
var previous_points := points
|
||||||
var type = TYPE.HORIZONTAL
|
var type = TYPE.HORIZONTAL
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
@ -28,24 +29,29 @@ func _process(delta) -> void:
|
||||||
has_focus = true
|
has_focus = true
|
||||||
Global.has_focus = false
|
Global.has_focus = false
|
||||||
update()
|
update()
|
||||||
if has_focus && Input.is_action_pressed("left_mouse"):
|
if has_focus:
|
||||||
if type == TYPE.HORIZONTAL:
|
if Input.is_action_just_pressed("left_mouse"):
|
||||||
points[0].y = round(mouse_pos.y)
|
previous_points = points
|
||||||
points[1].y = round(mouse_pos.y)
|
if Input.is_action_pressed("left_mouse"):
|
||||||
else:
|
if type == TYPE.HORIZONTAL:
|
||||||
points[0].x = round(mouse_pos.x)
|
points[0].y = round(mouse_pos.y)
|
||||||
points[1].x = round(mouse_pos.x)
|
points[1].y = round(mouse_pos.y)
|
||||||
if Input.is_action_just_released("left_mouse"):
|
else:
|
||||||
if has_focus:
|
points[0].x = round(mouse_pos.x)
|
||||||
|
points[1].x = round(mouse_pos.x)
|
||||||
|
if Input.is_action_just_released("left_mouse"):
|
||||||
Global.has_focus = true
|
Global.has_focus = true
|
||||||
has_focus = false
|
has_focus = false
|
||||||
update()
|
if !outside_canvas():
|
||||||
if type == TYPE.HORIZONTAL:
|
Global.undos += 1
|
||||||
if points[0].y < 0 || points[0].y > Global.canvas.size.y:
|
Global.undo_redo.create_action("Move Guide")
|
||||||
queue_free()
|
Global.undo_redo.add_do_method(self, "outside_canvas")
|
||||||
else:
|
Global.undo_redo.add_do_property(self, "points", points)
|
||||||
if points[0].x < 0 || points[0].x > Global.canvas.size.x:
|
Global.undo_redo.add_undo_property(self, "points", previous_points)
|
||||||
queue_free()
|
Global.undo_redo.add_undo_method(self, "outside_canvas", true)
|
||||||
|
Global.undo_redo.commit_action()
|
||||||
|
update()
|
||||||
|
|
||||||
|
|
||||||
func _draw() -> void:
|
func _draw() -> void:
|
||||||
if has_focus:
|
if has_focus:
|
||||||
|
@ -58,5 +64,23 @@ func _draw() -> void:
|
||||||
draw_set_transform(Vector2(points[0].x + font.get_height() * zoom.y, Global.camera.offset.y - (viewport_size.y / 2.25) * zoom.y), rotation, zoom * 2)
|
draw_set_transform(Vector2(points[0].x + font.get_height() * zoom.y, Global.camera.offset.y - (viewport_size.y / 2.25) * zoom.y), rotation, zoom * 2)
|
||||||
draw_string(font, Vector2.ZERO, "%spx" % str(round(mouse_pos.x)))
|
draw_string(font, Vector2.ZERO, "%spx" % str(round(mouse_pos.x)))
|
||||||
|
|
||||||
|
func outside_canvas(undo := false) -> bool:
|
||||||
|
if undo:
|
||||||
|
Global.undos -= 1
|
||||||
|
Global.notification_label("Move Guide")
|
||||||
|
if Global.control.redone:
|
||||||
|
if Global.undos < Global.undo_redo.get_version(): #If we did undo and then redo
|
||||||
|
Global.undos = Global.undo_redo.get_version()
|
||||||
|
Global.notification_label("Move Guide")
|
||||||
|
if type == TYPE.HORIZONTAL:
|
||||||
|
if points[0].y < 0 || points[0].y > Global.canvas.size.y:
|
||||||
|
queue_free()
|
||||||
|
return true
|
||||||
|
else:
|
||||||
|
if points[0].x < 0 || points[0].x > Global.canvas.size.x:
|
||||||
|
queue_free()
|
||||||
|
return true
|
||||||
|
return false
|
||||||
|
|
||||||
func point_in_rectangle(p : Vector2, coord1 : Vector2, coord2 : Vector2) -> bool:
|
func point_in_rectangle(p : Vector2, coord1 : Vector2, coord2 : Vector2) -> bool:
|
||||||
return p.x > coord1.x && p.y > coord1.y && p.x < coord2.x && p.y < coord2.y
|
return p.x > coord1.x && p.y > coord1.y && p.x < coord2.x && p.y < coord2.y
|
Loading…
Reference in a new issue