1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 17:19:50 +00:00

[Targeted for 0.11.0][Bug FIX] Mirror preview fix (#860)

* fix mirror previews

* Fix incorredt selection resizing of selection

in mirror mode

* Fix mirror previews (selection tools)

* typo
This commit is contained in:
Variable 2023-05-18 15:55:08 +05:00 committed by GitHub
parent fb4b26a060
commit 67a94ccc10
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 98 additions and 12 deletions

View file

@ -221,6 +221,10 @@ func commit_undo() -> void:
func draw_tool(position: Vector2) -> void:
if Global.mirror_view:
# Even brushes are not perfectly centred and are offseted by 1 px so we add it
if int(_stroke_dimensions.x) % 2 == 0:
position.x += 1
_prepare_tool()
var coords_to_draw := _draw_tool(position)
for coord in coords_to_draw:
@ -313,6 +317,11 @@ func _draw_tool(position: Vector2) -> PoolVector2Array:
# Bresenham's Algorithm
# Thanks to https://godotengine.org/qa/35276/tile-based-line-drawing-algorithm-efficiency
func draw_fill_gap(start: Vector2, end: Vector2) -> void:
if Global.mirror_view:
# Even brushes are not perfectly centred and are offseted by 1 px so we add it
if int(_stroke_dimensions.x) % 2 == 0:
start.x += 1
end.x += 1
var dx := int(abs(end.x - start.x))
var dy := int(-abs(end.y - start.y))
var err := dx + dy

View file

@ -53,6 +53,9 @@ func draw_start(position: Vector2) -> void:
_draw_line = Input.is_action_pressed("draw_create_line")
if _draw_line:
if Global.mirror_view:
# mirroring position is ONLY required by "Preview"
position.x = (Global.current_project.size.x - 1) - position.x
_line_start = position
_line_end = position
update_line_polylines(_line_start, _line_end)
@ -72,6 +75,9 @@ func draw_move(position: Vector2) -> void:
return
if _draw_line:
if Global.mirror_view:
# mirroring position is ONLY required by "Preview"
position.x = (Global.current_project.size.x - 1) - position.x
var d := _line_angle_constraint(_line_start, position)
_line_end = d.position
cursor_text = d.text
@ -90,6 +96,10 @@ func draw_end(position: Vector2) -> void:
return
if _draw_line:
if Global.mirror_view:
# now we revert back the coordinates from their mirror form so that line can be drawn
_line_start.x = (Global.current_project.size.x - 1) - _line_start.x
_line_end.x = (Global.current_project.size.x - 1) - _line_end.x
draw_tool(_line_start)
draw_fill_gap(_line_start, _line_end)
_draw_line = false

View file

@ -78,6 +78,9 @@ func draw_start(position: Vector2) -> void:
Global.canvas.selection.transform_content_confirm()
update_mask()
if Global.mirror_view:
# mirroring position is ONLY required by "Preview"
position.x = Global.current_project.size.x - position.x - 1
_original_pos = position
_start = position
_offset = position
@ -94,6 +97,9 @@ func draw_move(position: Vector2) -> void:
return
if _drawing:
if Global.mirror_view:
# mirroring position is ONLY required by "Preview"
position.x = Global.current_project.size.x - position.x - 1
if _displace_origin:
_original_pos += position - _offset
var d := _line_angle_constraint(_original_pos, position)
@ -114,6 +120,17 @@ func draw_end(position: Vector2) -> void:
return
if _drawing:
if Global.mirror_view:
# now we revert back the coordinates from their mirror form so that line can be drawn
_original_pos.x = (Global.current_project.size.x - 1) - _original_pos.x
_start.x = (Global.current_project.size.x - 1) - _start.x
_offset.x = (Global.current_project.size.x - 1) - _offset.x
_dest.x = (Global.current_project.size.x - 1) - _dest.x
if _thickness % 2 == 0:
_original_pos.x += 1
_start.x += 1
_offset.x += 1
_dest.x += 1
_draw_shape()
_original_pos = Vector2.ZERO

View file

@ -116,6 +116,9 @@ func draw_start(position: Vector2) -> void:
_draw_line = Input.is_action_pressed("draw_create_line")
if _draw_line:
_spacing_mode = false # spacing mode is disabled during line mode
if Global.mirror_view:
# mirroring position is ONLY required by "Preview"
position.x = (Global.current_project.size.x - 1) - position.x
_line_start = position
_line_end = position
update_line_polylines(_line_start, _line_end)
@ -138,6 +141,9 @@ func draw_move(position: Vector2) -> void:
if _draw_line:
_spacing_mode = false # spacing mode is disabled during line mode
if Global.mirror_view:
# mirroring position is ONLY required by "Preview"
position.x = (Global.current_project.size.x - 1) - position.x
var d := _line_angle_constraint(_line_start, position)
_line_end = d.position
cursor_text = d.text
@ -159,6 +165,10 @@ func draw_end(position: Vector2) -> void:
if _draw_line:
_spacing_mode = false # spacing mode is disabled during line mode
if Global.mirror_view:
# now we revert back the coordinates from their mirror form so that line can be drawn
_line_start.x = (Global.current_project.size.x - 1) - _line_start.x
_line_end.x = (Global.current_project.size.x - 1) - _line_end.x
draw_tool(_line_start)
draw_fill_gap(_line_start, _line_end)
_draw_line = false

View file

@ -52,14 +52,16 @@ func draw_preview() -> void:
var canvas: Node2D = Global.canvas.previews
var position := canvas.position
var scale := canvas.scale
var temp_rect = _rect
if Global.mirror_view:
position.x = position.x + Global.current_project.size.x
temp_rect.position.x = Global.current_project.size.x - temp_rect.position.x
scale.x = -1
var border := _get_shape_points_filled(_rect.size)
var indicator := _fill_bitmap_with_points(border, _rect.size)
var border := _get_shape_points_filled(temp_rect.size)
var indicator := _fill_bitmap_with_points(border, temp_rect.size)
canvas.draw_set_transform(_rect.position, canvas.rotation, scale)
canvas.draw_set_transform(temp_rect.position, canvas.rotation, scale)
for line in _create_polylines(indicator):
canvas.draw_polyline(PoolVector2Array(line), Color.black)

View file

@ -10,6 +10,8 @@ func _input(event: InputEvent) -> void:
return
if event is InputEventMouseMotion:
_last_position = Global.canvas.current_pixel.floor()
if Global.mirror_view:
_last_position.x = (Global.current_project.size.x - 1) - _last_position.x
elif event is InputEventMouseButton:
if event.doubleclick and event.button_index == tool_slot.button and _draw_points:
$DoubleClickTimer.start()

View file

@ -224,6 +224,9 @@ func draw_start(position: Vector2) -> void:
_draw_line = Input.is_action_pressed("draw_create_line")
if _draw_line:
if Global.mirror_view:
# mirroring position is ONLY required by "Preview"
position.x = (Global.current_project.size.x - 1) - position.x
_line_start = position
_line_end = position
update_line_polylines(_line_start, _line_end)
@ -243,6 +246,9 @@ func draw_move(position: Vector2) -> void:
return
if _draw_line:
if Global.mirror_view:
# mirroring position is ONLY required by "Preview"
position.x = (Global.current_project.size.x - 1) - position.x
var d := _line_angle_constraint(_line_start, position)
_line_end = d.position
cursor_text = d.text
@ -261,6 +267,10 @@ func draw_end(position: Vector2) -> void:
return
if _draw_line:
if Global.mirror_view:
# now we revert back the coordinates from their mirror form so that line can be drawn
_line_start.x = (Global.current_project.size.x - 1) - _line_start.x
_line_end.x = (Global.current_project.size.x - 1) - _line_end.x
draw_tool(_line_start)
draw_fill_gap(_line_start, _line_end)
_draw_line = false

View file

@ -93,6 +93,9 @@ func draw_start(position: Vector2) -> void:
Global.canvas.selection.transform_content_confirm()
update_mask()
if Global.mirror_view:
# mirroring position is ONLY required by "Preview"
position.x = Global.current_project.size.x - position.x - 1
_start = position
_offset = position
_dest = position
@ -108,6 +111,9 @@ func draw_move(position: Vector2) -> void:
return
if _drawing:
if Global.mirror_view:
# mirroring position is ONLY required by "Preview"
position.x = Global.current_project.size.x - position.x - 1
if _displace_origin:
_start += position - _offset
_dest = position
@ -122,6 +128,16 @@ func draw_end(position: Vector2) -> void:
return
if _drawing:
if Global.mirror_view:
# now we revert back the coordinates from their mirror form so that shape can be drawn
_start.x = (Global.current_project.size.x - 1) - _start.x
_offset.x = (Global.current_project.size.x - 1) - _offset.x
_dest.x = (Global.current_project.size.x - 1) - _dest.x
if _thickness % 2 == 0:
_start.x += 1
_offset.x += 1
_dest.x += 1
position.x += 1
_draw_shape(_start, position)
_start = Vector2.ZERO

View file

@ -11,6 +11,7 @@ var is_moving_content := false
var arrow_key_move := false
var is_pasting := false
var big_bounding_rectangle := Rect2() setget _big_bounding_rectangle_changed
var image_current_pixel := Vector2.ZERO # The ACTUAL pixel coordinate of image
var temp_rect := Rect2()
var rect_aspect_ratio := 0.0
@ -51,9 +52,15 @@ class Gizmo:
if direction == Vector2.ZERO:
return Input.CURSOR_POINTING_HAND
elif direction == Vector2(-1, -1) or direction == Vector2(1, 1): # Top left or bottom right
cursor = Input.CURSOR_FDIAGSIZE
if Global.mirror_view:
cursor = Input.CURSOR_BDIAGSIZE
else:
cursor = Input.CURSOR_FDIAGSIZE
elif direction == Vector2(1, -1) or direction == Vector2(-1, 1): # Top right or bottom left
cursor = Input.CURSOR_BDIAGSIZE
if Global.mirror_view:
cursor = Input.CURSOR_FDIAGSIZE
else:
cursor = Input.CURSOR_BDIAGSIZE
elif direction == Vector2(0, -1) or direction == Vector2(0, 1): # Center top or center bottom
cursor = Input.CURSOR_VSIZE
elif direction == Vector2(-1, 0) or direction == Vector2(1, 0): # Center left or center right
@ -77,6 +84,9 @@ func _ready() -> void:
func _input(event: InputEvent) -> void:
image_current_pixel = canvas.current_pixel
if Global.mirror_view:
image_current_pixel.x = Global.current_project.size.x - image_current_pixel.x
if not Global.can_draw:
return
if is_moving_content:
@ -96,7 +106,7 @@ func _input(event: InputEvent) -> void:
var gizmo_hover: Gizmo
if big_bounding_rectangle.size != Vector2.ZERO:
for g in gizmos:
if g.rect.has_point(canvas.current_pixel):
if g.rect.has_point(image_current_pixel):
gizmo_hover = Gizmo.new(g.type, g.direction)
break
@ -104,7 +114,7 @@ func _input(event: InputEvent) -> void:
if event.pressed:
if gizmo_hover and not dragged_gizmo: # Select a gizmo
Global.has_focus = false
mouse_pos_on_gizmo_drag = canvas.current_pixel
mouse_pos_on_gizmo_drag = image_current_pixel
dragged_gizmo = gizmo_hover
if Input.is_action_pressed("transform_move_selection_only"):
transform_content_confirm()
@ -304,14 +314,14 @@ func _gizmo_resize() -> void:
if Input.is_action_pressed("shape_center"):
# Code inspired from https://github.com/GDQuest/godot-open-rpg
if dir.x != 0 and dir.y != 0: # Border gizmos
temp_rect.size = ((canvas.current_pixel - temp_rect_pivot) * 2.0 * dir)
temp_rect.size = ((image_current_pixel - temp_rect_pivot) * 2.0 * dir)
elif dir.y == 0: # Center left and right gizmos
temp_rect.size.x = (canvas.current_pixel.x - temp_rect_pivot.x) * 2.0 * dir.x
temp_rect.size.x = (image_current_pixel.x - temp_rect_pivot.x) * 2.0 * dir.x
elif dir.x == 0: # Center top and bottom gizmos
temp_rect.size.y = (canvas.current_pixel.y - temp_rect_pivot.y) * 2.0 * dir.y
temp_rect.size.y = (image_current_pixel.y - temp_rect_pivot.y) * 2.0 * dir.y
temp_rect = Rect2(-1.0 * temp_rect.size / 2 + temp_rect_pivot, temp_rect.size)
else:
_resize_rect(canvas.current_pixel, dir)
_resize_rect(image_current_pixel, dir)
if Input.is_action_pressed("shape_perfect") or resize_keep_ratio: # Maintain aspect ratio
var end_y := temp_rect.end.y
@ -389,7 +399,7 @@ func resize_selection() -> void:
func _gizmo_rotate() -> void: # Does not work properly yet
var angle := canvas.current_pixel.angle_to_point(mouse_pos_on_gizmo_drag)
var angle := image_current_pixel.angle_to_point(mouse_pos_on_gizmo_drag)
angle = deg2rad(floor(rad2deg(angle)))
if angle == prev_angle:
return