mirror of
https://github.com/Relintai/GraphicsEditor.git
synced 2024-11-12 08:15:17 +01:00
added shortcut labels, added symmetry for pencil
This commit is contained in:
parent
1657ff818c
commit
6e3b61c288
@ -23,6 +23,8 @@ var grid
|
||||
var big_grid
|
||||
var selected_pixels = []
|
||||
|
||||
var symmetry_x = false
|
||||
var symmetry_y = false
|
||||
|
||||
|
||||
func _enter_tree():
|
||||
|
@ -15,6 +15,20 @@ enum Tools {
|
||||
PASTECUT,
|
||||
}
|
||||
|
||||
# Keyboard shortcuts
|
||||
const K_UNDO = KEY_Z
|
||||
const K_REDO = KEY_Y
|
||||
const K_PENCIL = KEY_Q
|
||||
const K_BRUSH = KEY_W
|
||||
const K_BUCKET = KEY_F
|
||||
const K_RAINBOW = KEY_R
|
||||
const K_LINE = KEY_L
|
||||
const K_DARK = KEY_D
|
||||
const K_BRIGHT = KEY_B
|
||||
const K_CUT = KEY_C
|
||||
const K_PICK = KEY_P
|
||||
|
||||
|
||||
var layer_buttons: Control
|
||||
var paint_canvas_container_node
|
||||
var paint_canvas: GECanvas
|
||||
@ -125,11 +139,8 @@ func _input(event):
|
||||
if paint_canvas_container_node == null or paint_canvas == null:
|
||||
return
|
||||
|
||||
if event is InputEventKey:
|
||||
if event.scancode == KEY_Z and event.is_pressed() and not event.is_echo():
|
||||
undo_action()
|
||||
elif event.scancode == KEY_Y and event.is_pressed() and not event.is_echo():
|
||||
redo_action()
|
||||
if event is InputEventKey and event.is_pressed() and not event.is_echo():
|
||||
_handle_shortcuts(event.scancode)
|
||||
|
||||
if is_mouse_in_canvas():
|
||||
_handle_zoom(event)
|
||||
@ -222,6 +233,42 @@ func _process(delta):
|
||||
_last_mouse_pos_canvas_area = get_global_mouse_position() #paint_canvas_container_node.get_local_mouse_position()
|
||||
|
||||
|
||||
func _handle_shortcuts(scancode):
|
||||
match scancode:
|
||||
K_UNDO:
|
||||
undo_action()
|
||||
|
||||
K_REDO:
|
||||
redo_action()
|
||||
|
||||
K_PENCIL:
|
||||
set_brush(Tools.PAINT)
|
||||
|
||||
K_BRUSH:
|
||||
set_brush(Tools.BRUSH)
|
||||
|
||||
K_BUCKET:
|
||||
set_brush(Tools.BUCKET)
|
||||
|
||||
K_RAINBOW:
|
||||
set_brush(Tools.RAINBOW)
|
||||
|
||||
K_LINE:
|
||||
set_brush(Tools.LINE)
|
||||
|
||||
K_DARK:
|
||||
set_brush(Tools.DARKEN)
|
||||
|
||||
K_BRIGHT:
|
||||
set_brush(Tools.BRIGHTEN)
|
||||
|
||||
K_CUT:
|
||||
set_brush(Tools.CUT)
|
||||
|
||||
K_PICK:
|
||||
set_brush(Tools.COLORPICKER)
|
||||
|
||||
|
||||
func _draw_tool_brush():
|
||||
paint_canvas.tool_layer.clear()
|
||||
|
||||
@ -775,3 +822,11 @@ func _on_BrushHLine_pressed():
|
||||
|
||||
func _on_BrushSize_value_changed(value: float):
|
||||
find_node("BrushSizeLabel").text = str(int(value))
|
||||
|
||||
|
||||
func _on_XSymmetry_pressed():
|
||||
paint_canvas.symmetry_x = not paint_canvas.symmetry_x
|
||||
|
||||
|
||||
func _on_YSymmetry_pressed():
|
||||
paint_canvas.symmetry_y = not paint_canvas.symmetry_y
|
||||
|
File diff suppressed because one or more lines are too long
@ -45,3 +45,79 @@ func can_commit() -> bool:
|
||||
return not action_data.redo.empty()
|
||||
|
||||
|
||||
func get_x_sym_points(canvas_width, pixel):
|
||||
var p = int(canvas_width - pixel.x)
|
||||
var all_points = [pixel, Vector2(p-1, pixel.y)]
|
||||
|
||||
var points :Array = []
|
||||
for point in all_points:
|
||||
if point in points:
|
||||
continue
|
||||
points.append(point)
|
||||
return points
|
||||
|
||||
|
||||
func get_y_sym_points(canvas_height, pixel):
|
||||
var p = int(canvas_height - pixel.y)
|
||||
var all_points = [pixel, Vector2(pixel.x, p-1)]
|
||||
|
||||
var points :Array = []
|
||||
for point in all_points:
|
||||
if point in points:
|
||||
continue
|
||||
points.append(point)
|
||||
return points
|
||||
|
||||
|
||||
func get_xy_sym_points(canvas_width, canvas_height, pixel):
|
||||
var all_points = []
|
||||
var xpoints = get_x_sym_points(canvas_width, pixel)
|
||||
|
||||
all_points += get_y_sym_points(canvas_height, xpoints[0])
|
||||
all_points += get_y_sym_points(canvas_height, xpoints[1])
|
||||
|
||||
var points :Array = []
|
||||
for point in all_points:
|
||||
if point in points:
|
||||
continue
|
||||
points.append(point)
|
||||
|
||||
return points
|
||||
|
||||
|
||||
func get_points(canvas, pixel):
|
||||
var points = []
|
||||
if canvas.symmetry_x and canvas.symmetry_y:
|
||||
var sym_points = get_xy_sym_points(canvas.canvas_width, canvas.canvas_height, pixel)
|
||||
for point in sym_points:
|
||||
if point in action_data.undo.cells or canvas.get_pixel_v(point) == null:
|
||||
continue
|
||||
if canvas.is_alpha_locked() and canvas.get_pixel_v(pixel) == Color.transparent:
|
||||
continue
|
||||
points.append(point)
|
||||
elif canvas.symmetry_y:
|
||||
var sym_points = get_y_sym_points(canvas.canvas_height, pixel)
|
||||
for point in sym_points:
|
||||
if point in action_data.undo.cells or canvas.get_pixel_v(point) == null:
|
||||
continue
|
||||
if canvas.is_alpha_locked() and canvas.get_pixel_v(pixel) == Color.transparent:
|
||||
continue
|
||||
points.append(point)
|
||||
elif canvas.symmetry_x:
|
||||
var sym_points = get_x_sym_points(canvas.canvas_width, pixel)
|
||||
for point in sym_points:
|
||||
if point in action_data.undo.cells or canvas.get_pixel_v(point) == null:
|
||||
continue
|
||||
if canvas.is_alpha_locked() and canvas.get_pixel_v(pixel) == Color.transparent:
|
||||
continue
|
||||
points.append(point)
|
||||
else:
|
||||
if pixel in action_data.undo.cells or canvas.get_pixel_v(pixel) == null:
|
||||
return []
|
||||
if canvas.is_alpha_locked() and canvas.get_pixel_v(pixel) == Color.transparent:
|
||||
return []
|
||||
points.append(pixel)
|
||||
|
||||
return points
|
||||
|
||||
|
||||
|
@ -7,18 +7,17 @@ func do_action(canvas, data: Array):
|
||||
|
||||
var pixels = GEUtils.get_pixels_in_line(data[0], data[1])
|
||||
for pixel in pixels:
|
||||
if pixel in action_data.undo.cells or canvas.get_pixel_v(pixel) == null:
|
||||
continue
|
||||
|
||||
if canvas.is_alpha_locked() and canvas.get_pixel_v(pixel) == Color.transparent:
|
||||
continue
|
||||
|
||||
action_data.undo.colors.append(canvas.get_pixel_v(pixel))
|
||||
action_data.undo.cells.append(pixel)
|
||||
canvas.set_pixel_v(pixel, data[2])
|
||||
for p in get_points(canvas, pixel):
|
||||
_set_pixel(canvas, p, data[2])
|
||||
|
||||
|
||||
func _set_pixel(canvas, pixel, color):
|
||||
action_data.undo.colors.append(canvas.get_pixel_v(pixel))
|
||||
action_data.undo.cells.append(pixel)
|
||||
canvas.set_pixel_v(pixel, color)
|
||||
|
||||
action_data.redo.cells.append(pixel)
|
||||
action_data.redo.colors.append(data[2])
|
||||
action_data.redo.cells.append(pixel)
|
||||
action_data.redo.colors.append(color)
|
||||
|
||||
|
||||
func commit_action(canvas):
|
||||
|
Loading…
Reference in New Issue
Block a user