mirror of
https://github.com/1j01/textual-paint.git
synced 2024-12-22 14:21:33 +03:00
I feel like I made it worse...
This commit is contained in:
parent
c3280d20d0
commit
bbdfa794fc
25
paint.py
25
paint.py
@ -974,6 +974,9 @@ class PaintApp(App):
|
|||||||
|
|
||||||
# for shape tools and Select tool
|
# for shape tools and Select tool
|
||||||
mouse_at_start = Offset(0, 0)
|
mouse_at_start = Offset(0, 0)
|
||||||
|
# for Select tool, indicates that the selection is being moved
|
||||||
|
# and defines the offset of the selection from the mouse
|
||||||
|
selection_drag_offset = Offset(0, 0)
|
||||||
|
|
||||||
# flag to prevent setting the filename input when initially expanding the directory tree
|
# flag to prevent setting the filename input when initially expanding the directory tree
|
||||||
expanding_directory_tree = False
|
expanding_directory_tree = False
|
||||||
@ -1594,8 +1597,19 @@ class PaintApp(App):
|
|||||||
self.selected_tool = Tool.pencil
|
self.selected_tool = Tool.pencil
|
||||||
# TODO: support remaining tools
|
# TODO: support remaining tools
|
||||||
|
|
||||||
|
# TODO: use Offset() instead of tuple
|
||||||
|
# and I would say use event.offset, but I'm dynamically
|
||||||
|
# modifying x/y so I need to use those coords for now,
|
||||||
|
# unless there's some getter/setter magic behind the scenes.
|
||||||
self.mouse_at_start = (event.mouse_down_event.x, event.mouse_down_event.y)
|
self.mouse_at_start = (event.mouse_down_event.x, event.mouse_down_event.y)
|
||||||
if self.selected_tool == Tool.select:
|
if self.selected_tool == Tool.select:
|
||||||
|
sel = self.image.selection
|
||||||
|
if sel and sel.region.contains_point(self.mouse_at_start):
|
||||||
|
self.selection_drag_offset = Offset(
|
||||||
|
self.mouse_at_start[0] - sel.region.x,
|
||||||
|
self.mouse_at_start[1] - sel.region.y,
|
||||||
|
)
|
||||||
|
return
|
||||||
self.meld_selection()
|
self.meld_selection()
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -1730,6 +1744,17 @@ class PaintApp(App):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if self.selected_tool == Tool.select:
|
if self.selected_tool == Tool.select:
|
||||||
|
if self.selection_drag_offset:
|
||||||
|
sel = self.image.selection
|
||||||
|
if sel is None:
|
||||||
|
print("WARNING: selection_drag_offset is set but there is no selection")
|
||||||
|
return
|
||||||
|
offset = (
|
||||||
|
self.selection_drag_offset.x + event.mouse_move_event.x,
|
||||||
|
self.selection_drag_offset.y + event.mouse_move_event.y,
|
||||||
|
)
|
||||||
|
sel.region = Region.from_offset(offset, sel.region.size)
|
||||||
|
else:
|
||||||
# This is a tool preview, but it's not in the ToolPreviewUpdate event.
|
# This is a tool preview, but it's not in the ToolPreviewUpdate event.
|
||||||
# Goes to show how the canvas's event names are silly.
|
# Goes to show how the canvas's event names are silly.
|
||||||
# I should've just named them for what they are (i.e. when they occur)
|
# I should've just named them for what they are (i.e. when they occur)
|
||||||
|
Loading…
Reference in New Issue
Block a user