Skip to content

Commit

Permalink
Add an outline to the canvas (fix #299)
Browse files Browse the repository at this point in the history
related to #184
  • Loading branch information
maoschanz committed Jun 24, 2021
1 parent f621be6 commit 68b3c52
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 10 deletions.
1 change: 1 addition & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ drawing (0.8.2) unstable; urgency=low
* refactoring of the optionsbars (bottom panes) of the transform tools
* add a "lock line direction" option to the line tool (#369)
* fix shift+f10 action when using a selection tool on mobile
* add an outline to the canvas (#299, 184)
* lock image proportions by default when scaling with the numerical inputs
* update several translations

Expand Down
7 changes: 6 additions & 1 deletion src/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from .selection_manager import DrSelectionManager
from .properties import DrPropertiesDialog
from .utilities import InvalidFileFormatException
from .utilities_overlay import utilities_generic_canvas_outline

class DrMotionBehavior():
_LIMIT = 10
Expand Down Expand Up @@ -380,7 +381,11 @@ def on_draw(self, area, cairo_context):
cairo_context.paint()

# What the tool is painting
self.active_tool().on_draw(area, cairo_context)
self.active_tool().on_draw_above(area, cairo_context)

# Limit of the canvas (for readability)
utilities_generic_canvas_outline(cairo_context, self.get_pixbuf_width(), \
self.get_pixbuf_height(), self.zoom_level)

def on_press_on_area(self, area, event):
"""Signal callback. Executed when a mouse button is pressed on
Expand Down
7 changes: 2 additions & 5 deletions src/tools/abstract_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,8 @@ def on_unclicked_motion_on_area(self, event, surface):
def on_release_on_area(self, event, surface, event_x, event_y):
pass

def on_draw(self, area, cairo_context):
if not self.accept_selection:
return
if not self.selection_is_active():
return
def on_draw_above(self, area, cairo_context):
pass

############################################################################
################################################################################
Expand Down
2 changes: 1 addition & 1 deletion src/tools/selection_tools/abstract_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def on_release_on_area(self, event, surface, event_x, event_y):
elif self.behavior == 'drag':
self._apply_drag_to(event_x, event_y)

def on_draw(self, area, ccontext):
def on_draw_above(self, area, ccontext):
if not self.selection_is_active():
return
ldx = self.local_dx
Expand Down
2 changes: 1 addition & 1 deletion src/tools/transform_tools/abstract_transform_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def get_handle_cursor_name(self, event_x, event_y):
cursor_name = cursor_name + '-resize'
return cursor_name

def on_draw(self, area, cairo_context):
def on_draw_above(self, area, cairo_context):
pass

def get_deformed_surface(self, source_surface, coefs):
Expand Down
2 changes: 1 addition & 1 deletion src/tools/transform_tools/tool_crop.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def on_release_on_area(self, event, surface, event_x, event_y):

############################################################################

def on_draw(self, area, cairo_context):
def on_draw_above(self, area, cairo_context):
if self.apply_to_selection:
x1 = int(self._x)
y1 = int(self._y)
Expand Down
2 changes: 1 addition & 1 deletion src/tools/transform_tools/tool_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def on_release_on_area(self, event, surface, event_x, event_y):

############################################################################

def on_draw(self, area, cairo_context):
def on_draw_above(self, area, cairo_context):
if self.apply_to_selection:
x1 = int(self._x)
y1 = int(self._y)
Expand Down
21 changes: 21 additions & 0 deletions src/tools/utilities_overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ def utilities_show_overlay_on_context(ccontext, cpath, is_dashed, thickness=1):
ccontext.set_source_rgba(0.5, 0.5, 0.5, 0.5)
ccontext.stroke()

################################################################################
# Transform tools overlay ######################################################

def utilities_show_handles_on_context(cairo_context, x1, x2, y1, y2, thickness=1):
"""Request the drawing of handles for a rectangle pixbuf having the provided
coords. Handles are only decorative objects drawn on the surface to help the
Expand Down Expand Up @@ -109,3 +112,21 @@ def _draw_arc_handle(cairo_context, x, y, rayon, orientation):
cairo_context.stroke()

################################################################################
# Canvas generic ouline ########################################################

def utilities_generic_canvas_outline(cairo_context, w, h, zoom_level):
cairo_context.set_source_rgba(0.0, 0.0, 0.0, 1.0)
cairo_context.set_dash([])
size = max(1, int(1 / zoom_level))
cairo_context.set_line_width(size)
cairo_context.move_to(w + size, 0)
cairo_context.rel_line_to(0, h + size)
cairo_context.line_to(0, h + size)
cairo_context.stroke_preserve()

cairo_context.set_source_rgba(1.0, 1.0, 1.0, 1.0)
cairo_context.set_dash([2 * size, 2 * size])
cairo_context.stroke()

################################################################################

0 comments on commit 68b3c52

Please sign in to comment.