Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable stroke while panning or zooming #302

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
# Mono-specific ignores
.mono/
data_*/

# Visual Studio Code-specific ignores
.vscode/
5 changes: 5 additions & 0 deletions lorien/InfiniteCanvas/InfiniteCanvas.gd
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ func _ready() -> void:
_camera.zoom_changed.connect(Callable(child, "_on_zoom_changed"))
_camera.position_changed.connect(Callable(child, "_on_canvas_position_changed"))

for child in get_children():
if child is CanvasTool:
_camera.is_panning.connect(Callable(child, "_on_is_panning"))
_camera.is_zooming.connect(Callable(child, "_on_is_zooming"))
Zacrain marked this conversation as resolved.
Show resolved Hide resolved

_camera.zoom_changed.connect(_on_zoom_changed)
_camera.position_changed.connect(_on_camera_moved)
#_viewport.size = get_window().size
Expand Down
8 changes: 8 additions & 0 deletions lorien/InfiniteCanvas/PanZoomCamera.gd
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
extends Camera2D

# -------------------------------------------------------------------------------------------------
signal is_zooming(value: bool)
Zacrain marked this conversation as resolved.
Show resolved Hide resolved
signal zoom_changed(value: float)
signal is_panning(value: bool)
signal position_changed(value: Vector2)

# -------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -39,8 +41,10 @@ func tool_event(event: InputEvent) -> void:
if event is InputEventKey:
if Utils.is_action_pressed("canvas_pan_key", event):
_pan_active = true
is_panning.emit(true)
if Utils.is_action_released("canvas_pan_key", event):
_pan_active = false
is_panning.emit(false)
if event is InputEventMouseButton:

# Scroll wheel up/down to zoom
Expand All @@ -55,10 +59,14 @@ func tool_event(event: InputEvent) -> void:
if event.button_index == MOUSE_BUTTON_MIDDLE:
if !event.ctrl_pressed:
_pan_active = event.is_pressed()
is_panning.emit(_pan_active)
_zoom_active = false
is_zooming.emit(false)
else:
_zoom_active = event.is_pressed()
is_zooming.emit(_zoom_active)
_pan_active = false
is_panning.emit(false)
_start_mouse_pos = get_local_mouse_position()

elif event is InputEventMouseMotion:
Expand Down
4 changes: 3 additions & 1 deletion lorien/InfiniteCanvas/Tools/BrushTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ func tool_event(event: InputEvent) -> void:
_current_pressure = event.pressure
if performing_stroke:
_cursor.set_pressure(event.pressure)
if zooming_detected && performing_stroke:
end_stroke()

elif event is InputEventMouseButton:
elif event is InputEventMouseButton && !disable_stroke:
if event.button_index == MOUSE_BUTTON_LEFT:
if event.pressed:
start_stroke()
Expand Down
16 changes: 16 additions & 0 deletions lorien/InfiniteCanvas/Tools/CanvasTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ var _cursor: BaseCursor
var _canvas: InfiniteCanvas
var enabled := false: get = get_enabled, set = set_enabled
var performing_stroke := false
var disable_stroke := false
Zacrain marked this conversation as resolved.
Show resolved Hide resolved
var panning_detected := false
var zooming_detected := false

# -------------------------------------------------------------------------------------------------
func _ready() -> void:
Expand All @@ -32,6 +35,16 @@ func _on_brush_color_changed(color: Color) -> void:
func _on_brush_size_changed(size: int) -> void:
_cursor.change_size(size)

# -------------------------------------------------------------------------------------------------
func _on_is_panning(is_panning: bool) -> void:
panning_detected = is_panning
eval_disable_stroke()

# -------------------------------------------------------------------------------------------------
func _on_is_zooming(is_zooming: bool) -> void:
zooming_detected = is_zooming
eval_disable_stroke()

# -------------------------------------------------------------------------------------------------
func get_cursor() -> BaseCursor:
return _cursor
Expand Down Expand Up @@ -89,6 +102,9 @@ func end_stroke() -> void:
_canvas.end_stroke()
performing_stroke = false

func eval_disable_stroke() -> void:
Zacrain marked this conversation as resolved.
Show resolved Hide resolved
disable_stroke = panning_detected || zooming_detected

# TODO(gd4): probably don't need this anymore
# -------------------------------------------------------------------------------------------------
#func xform_vector2(v: Vector2) -> Vector2:
Expand Down
2 changes: 1 addition & 1 deletion lorien/InfiniteCanvas/Tools/CircleTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func tool_event(event: InputEvent) -> void:
_make_ellipse(PRESSURE, STEP_IN_MOTION, should_draw_circle)

# Start + End
elif event is InputEventMouseButton:
elif event is InputEventMouseButton && !disable_stroke:
if event.button_index == MOUSE_BUTTON_LEFT:
if event.pressed:
start_stroke()
Expand Down
2 changes: 1 addition & 1 deletion lorien/InfiniteCanvas/Tools/EraserTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var _bounding_box_cache := {} # BrushStroke -> Rect2
func tool_event(event: InputEvent) -> void:
if event is InputEventMouseMotion:
_last_mouse_position = _cursor.global_position
if event is InputEventMouseButton:
if event is InputEventMouseButton && !disable_stroke:
if event.button_index == MOUSE_BUTTON_LEFT:
if event.pressed:
if _bounding_box_cache.is_empty():
Expand Down
2 changes: 1 addition & 1 deletion lorien/InfiniteCanvas/Tools/LineTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func tool_event(event: InputEvent) -> void:
_tail = _add_point_at_mouse_pos(0.5)

# Start + End
elif event is InputEventMouseButton:
elif event is InputEventMouseButton && !disable_stroke:
if event.button_index == MOUSE_BUTTON_LEFT:
if event.pressed:
start_stroke()
Expand Down
2 changes: 1 addition & 1 deletion lorien/InfiniteCanvas/Tools/RectangleTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func tool_event(event: InputEvent) -> void:
_make_rectangle(PRESSURE)

# Start + End
elif event is InputEventMouseButton:
elif event is InputEventMouseButton && !disable_stroke:
if event.button_index == MOUSE_BUTTON_LEFT:
if event.pressed:
start_stroke()
Expand Down
2 changes: 1 addition & 1 deletion lorien/InfiniteCanvas/Tools/SelectionTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func tool_event(event: InputEvent) -> void:
_cursor.mode = SelectionCursor.Mode.MOVE
_paste_strokes(strokes)

if event is InputEventMouseButton:
if event is InputEventMouseButton && !disable_stroke:
if event.button_index == MOUSE_BUTTON_LEFT:
# LMB down - decide if we should select/multiselect or move the selection
if event.pressed:
Expand Down