Basic drawing now disallows drawing X over existing lines and vice versa
This commit is contained in:
parent
ed2e2c5006
commit
07a4e47201
|
@ -58,69 +58,3 @@ class IntArray2D extends PoolArray2D:
|
||||||
|
|
||||||
func clear_flag(row: int, col: int, value: int):
|
func clear_flag(row: int, col: int, value: int):
|
||||||
_array.set(row + col*_rows, _array[row + col*_rows]&(value^XORMASK))
|
_array.set(row + col*_rows, _array[row + col*_rows]&(value^XORMASK))
|
||||||
|
|
||||||
|
|
||||||
#class ByteArray2D:
|
|
||||||
# var _array: PoolByteArray
|
|
||||||
# var _rows := 1
|
|
||||||
# var _cols := 1
|
|
||||||
# const XORMASK := (1<<8)-1
|
|
||||||
# func _init(rows:=1, cols:=1):
|
|
||||||
# assert(rows>0)
|
|
||||||
# assert(cols>0)
|
|
||||||
# _rows = rows
|
|
||||||
# _cols = cols
|
|
||||||
# _array = PoolByteArray()
|
|
||||||
# _array.resize(rows*cols)
|
|
||||||
#
|
|
||||||
# func set_cell(row: int, col: int, value: int):
|
|
||||||
# assert(row < _rows)
|
|
||||||
# assert(col < _cols)
|
|
||||||
# _array.set(row + col*_rows, value)
|
|
||||||
#
|
|
||||||
# func get_cell(row: int, col: int) -> int:
|
|
||||||
# assert(row < _rows)
|
|
||||||
# assert(col < _cols)
|
|
||||||
# return _array[row + col*_rows]
|
|
||||||
#
|
|
||||||
# func get_flag(row: int, col: int, value: int) -> bool:
|
|
||||||
# return bool(_array[row + col*_rows] & value)
|
|
||||||
#
|
|
||||||
# func set_flag(row: int, col: int, value: int):
|
|
||||||
# _array.set(row + col*_rows, _array[row + col*_rows]|value)
|
|
||||||
#
|
|
||||||
# func clear_flag(row: int, col: int, value: int):
|
|
||||||
# _array.set(row + col*_rows, _array[row + col*_rows]&(value^XORMASK))
|
|
||||||
|
|
||||||
|
|
||||||
#class IntArray2D:
|
|
||||||
# var _array: PoolIntArray
|
|
||||||
# var _rows := 1
|
|
||||||
# var _cols := 1
|
|
||||||
# const XORMASK := (1<<32)-1
|
|
||||||
# func _init(rows:=1, cols:=1):
|
|
||||||
# assert(rows>0)
|
|
||||||
# assert(cols>0)
|
|
||||||
# _rows = rows
|
|
||||||
# _cols = cols
|
|
||||||
# _array = PoolIntArray()
|
|
||||||
# _array.resize(rows*cols)
|
|
||||||
#
|
|
||||||
# func set_cell(row: int, col: int, value: int):
|
|
||||||
# assert(row < _rows)
|
|
||||||
# assert(col < _cols)
|
|
||||||
# _array.set(row + col*_rows, value)
|
|
||||||
#
|
|
||||||
# func get_cell(row: int, col: int) -> int:
|
|
||||||
# assert(row < _rows)
|
|
||||||
# assert(col < _cols)
|
|
||||||
# return _array[row + col*_rows]
|
|
||||||
#
|
|
||||||
# func get_flag(row: int, col: int, value: int) -> bool:
|
|
||||||
# return bool(_array[row + col*_rows] & value)
|
|
||||||
#
|
|
||||||
# func set_flag(row: int, col: int, value: int):
|
|
||||||
# _array.set(row + col*_rows, _array[row + col*_rows] | value)
|
|
||||||
#
|
|
||||||
# func clear_flag(row: int, col: int, value: int):
|
|
||||||
# _array.set(row + col*_rows, _array[row + col*_rows]&(value^XORMASK))
|
|
||||||
|
|
|
@ -242,26 +242,60 @@ func _input(event: InputEvent) -> void:
|
||||||
match drag_action:
|
match drag_action:
|
||||||
DragAction.DRAW_LINE:
|
DragAction.DRAW_LINE:
|
||||||
if adx < threshold and ady > threshold:
|
if adx < threshold and ady > threshold:
|
||||||
corner_marks.set_flag(int(gridpos.y), int(round(gridpos.x)), CornerMark.L_DOWN)
|
set_line_down(int(gridpos.y), int(round(gridpos.x)))
|
||||||
elif adx > threshold and ady < threshold:
|
elif adx > threshold and ady < threshold:
|
||||||
corner_marks.set_flag(int(round(gridpos.y)), int(gridpos.x), CornerMark.L_RIGHT)
|
set_line_right(int(round(gridpos.y)), int(gridpos.x))
|
||||||
DragAction.REMOVE_LINE:
|
DragAction.REMOVE_LINE:
|
||||||
if adx < threshold and ady > threshold:
|
if adx < threshold and ady > threshold:
|
||||||
corner_marks.clear_flag(int(gridpos.y), int(round(gridpos.x)), CornerMark.L_DOWN)
|
clear_line_down(int(gridpos.y), int(round(gridpos.x)))
|
||||||
elif adx > threshold and ady < threshold:
|
elif adx > threshold and ady < threshold:
|
||||||
corner_marks.clear_flag(int(round(gridpos.y)), int(gridpos.x), CornerMark.L_RIGHT)
|
clear_line_right(int(round(gridpos.y)), int(gridpos.x))
|
||||||
DragAction.DRAW_X:
|
DragAction.DRAW_X:
|
||||||
if adx < threshold and ady > threshold:
|
if adx < threshold and ady > threshold:
|
||||||
corner_marks.set_flag(int(gridpos.y), int(round(gridpos.x)), CornerMark.X_DOWN)
|
set_x_down(int(gridpos.y), int(round(gridpos.x)))
|
||||||
elif adx > threshold and ady < threshold:
|
elif adx > threshold and ady < threshold:
|
||||||
corner_marks.set_flag(int(round(gridpos.y)), int(gridpos.x), CornerMark.X_RIGHT)
|
set_x_right(int(round(gridpos.y)), int(gridpos.x))
|
||||||
DragAction.REMOVE_X:
|
DragAction.REMOVE_X:
|
||||||
if adx < threshold and ady > threshold:
|
if adx < threshold and ady > threshold:
|
||||||
corner_marks.clear_flag(int(gridpos.y), int(round(gridpos.x)), CornerMark.X_DOWN)
|
clear_x_down(int(gridpos.y), int(round(gridpos.x)))
|
||||||
elif adx > threshold and ady < threshold:
|
elif adx > threshold and ady < threshold:
|
||||||
corner_marks.clear_flag(int(round(gridpos.y)), int(gridpos.x), CornerMark.X_RIGHT)
|
clear_x_right(int(round(gridpos.y)), int(gridpos.x))
|
||||||
DragAction.DRAW_COLOR:
|
DragAction.DRAW_COLOR:
|
||||||
sel_row = int(gridpos.y)
|
sel_row = int(gridpos.y)
|
||||||
sel_col = int(gridpos.x)
|
sel_col = int(gridpos.x)
|
||||||
cell_colors.set_cell(sel_row, sel_col, drag_color)
|
cell_colors.set_cell(sel_row, sel_col, drag_color)
|
||||||
|
|
||||||
|
var undo_stack = []
|
||||||
|
|
||||||
|
func set_line_right(row, col):
|
||||||
|
if !corner_marks.get_flag(row, col, CornerMark.L_RIGHT) and !corner_marks.get_flag(row, col, CornerMark.X_RIGHT):
|
||||||
|
corner_marks.set_flag(row, col, CornerMark.L_RIGHT)
|
||||||
|
# TODO: Add undo stack entry
|
||||||
|
|
||||||
|
func set_line_down(row, col):
|
||||||
|
if !corner_marks.get_flag(row, col, CornerMark.L_DOWN) and !corner_marks.get_flag(row, col, CornerMark.X_DOWN):
|
||||||
|
corner_marks.set_flag(row, col, CornerMark.L_DOWN)
|
||||||
|
|
||||||
|
func clear_line_right(row, col):
|
||||||
|
if corner_marks.get_flag(row, col, CornerMark.L_RIGHT):
|
||||||
|
corner_marks.clear_flag(row, col, CornerMark.L_RIGHT)
|
||||||
|
|
||||||
|
func clear_line_down(row, col):
|
||||||
|
if corner_marks.get_flag(row, col, CornerMark.L_DOWN):
|
||||||
|
corner_marks.clear_flag(row, col, CornerMark.L_DOWN)
|
||||||
|
|
||||||
|
func set_x_right(row, col):
|
||||||
|
if !corner_marks.get_flag(row, col, CornerMark.L_RIGHT) and !corner_marks.get_flag(row, col, CornerMark.X_RIGHT):
|
||||||
|
corner_marks.set_flag(row, col, CornerMark.X_RIGHT)
|
||||||
|
|
||||||
|
func set_x_down(row, col):
|
||||||
|
if !corner_marks.get_flag(row, col, CornerMark.L_DOWN) and !corner_marks.get_flag(row, col, CornerMark.X_DOWN):
|
||||||
|
corner_marks.set_flag(row, col, CornerMark.X_DOWN)
|
||||||
|
|
||||||
|
func clear_x_right(row, col):
|
||||||
|
if corner_marks.get_flag(row, col, CornerMark.X_RIGHT):
|
||||||
|
corner_marks.clear_flag(row, col, CornerMark.X_RIGHT)
|
||||||
|
|
||||||
|
func clear_x_down(row, col):
|
||||||
|
if corner_marks.get_flag(row, col, CornerMark.X_DOWN):
|
||||||
|
corner_marks.clear_flag(row, col, CornerMark.X_DOWN)
|
||||||
|
|
Loading…
Reference in New Issue