Skip to content

Commit

Permalink
overlay handles: the word for "rayon" is "radius"....
Browse files Browse the repository at this point in the history
  • Loading branch information
maoschanz committed Apr 8, 2022
1 parent a4706a8 commit 7c8e805
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/utilities/utilities_overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def utilities_show_overlay_on_context(ccontext, cpath, thickness=1):
if cpath is None:
raise NoSelectionPathException()
ccontext.new_path()
ccontext.set_antialias(cairo.Antialias.NONE)
ccontext.set_line_width(thickness)
ccontext.set_dash([thickness * 3, thickness * 3])
ccontext.append_path(cpath)
Expand All @@ -27,24 +28,24 @@ 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
user understand the rationale of tools without relying on the mouse cursor."""
rayon = min([(x2 - x1)/5, (y2 - y1)/5, 12 * thickness])
lateral_handles = True # may be a parameter later
if rayon < 4 * thickness:
radius = _get_radius((x2 - x1), (y2 - y1), thickness)
lateral_handles = True # may become a parameter later
if radius < 4 * thickness:
cairo_context.set_line_width(thickness)
elif rayon < 8 * thickness:
elif radius < 8 * thickness:
cairo_context.set_line_width(2 * thickness)
else:
cairo_context.set_line_width(3 * thickness)

_draw_arc_handle(cairo_context, x1, y1, rayon, 'nw')
_draw_arc_handle(cairo_context, x2, y1, rayon, 'ne')
_draw_arc_handle(cairo_context, x2, y2, rayon, 'se')
_draw_arc_handle(cairo_context, x1, y2, rayon, 'sw')
_draw_arc_handle(cairo_context, x1, y1, radius, 'nw')
_draw_arc_handle(cairo_context, x2, y1, radius, 'ne')
_draw_arc_handle(cairo_context, x2, y2, radius, 'se')
_draw_arc_handle(cairo_context, x1, y2, radius, 'sw')
if lateral_handles:
_draw_arc_handle(cairo_context, (x1+x2)/2, y1, rayon, 'n')
_draw_arc_handle(cairo_context, x2, (y1+y2)/2, rayon, 'e')
_draw_arc_handle(cairo_context, (x1+x2)/2, y2, rayon, 's')
_draw_arc_handle(cairo_context, x1, (y1+y2)/2, rayon, 'w')
_draw_arc_handle(cairo_context, (x1+x2)/2, y1, radius, 'n')
_draw_arc_handle(cairo_context, x2, (y1+y2)/2, radius, 'e')
_draw_arc_handle(cairo_context, (x1+x2)/2, y2, radius, 's')
_draw_arc_handle(cairo_context, x1, (y1+y2)/2, radius, 'w')

cairo_context.move_to(x1, y1)
cairo_context.line_to(x1, y2)
Expand All @@ -57,7 +58,7 @@ def utilities_show_handles_on_context(cairo_context, x1, x2, y1, y2, thickness=1
cairo_context.set_source_rgba(0.5, 0.5, 0.5, 0.5)
cairo_context.stroke()

def _draw_arc_handle(cairo_context, x, y, rayon, orientation):
def _draw_arc_handle(cairo_context, x, y, radius, orientation):
"""Draw a moon-like shape with the given orientation and radius. The coords
are the center of the shape. The orientation is an enumeration provided as a
string with the stupid n/nw/w/sw/s/se/e/ne format."""
Expand Down Expand Up @@ -87,13 +88,16 @@ def _draw_arc_handle(cairo_context, x, y, rayon, orientation):
angle_2 = -0.5 * math.pi

cairo_context.move_to(x, y)
cairo_context.arc(x, y, rayon, angle_1, angle_2)
cairo_context.arc(x, y, radius, angle_1, angle_2)
cairo_context.close_path()
cairo_context.set_source_rgba(1.0, 1.0, 1.0, 1.0)
cairo_context.fill_preserve()
cairo_context.set_source_rgba(0.5, 0.5, 0.5, 0.5)
cairo_context.stroke()

def _get_radius(dx, dy, thickness):
return min([dx/5, dy/5, 12 * thickness])

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

Expand Down

0 comments on commit 7c8e805

Please sign in to comment.