Skip to content

Commit

Permalink
Simplify some Cairo drawing
Browse files Browse the repository at this point in the history
Instead of generating paths twice, once for filling and once for
stroking, use the path-preserving `fill_preserve` operator instead. As
well, do the filling before stroking for consistency, or else the stroke
might be accidentally covered, as occurred with the child rings.

Also, simplify the map marker which seems to have drawn the elliptical
portion twice.
  • Loading branch information
QuLogic authored and Nick-Hall committed Apr 15, 2024
1 parent 9e83846 commit 3442876
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 66 deletions.
32 changes: 5 additions & 27 deletions gramps/gui/widgets/fanchart.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,22 +577,8 @@ def draw_radbox(
ctx.line_to(radiusin * math.cos(stop_rad), radiusin * math.sin(stop_rad))
ctx.arc_negative(0, 0, radiusin, stop_rad, start_rad)
ctx.close_path()
##path = ctx.copy_path() # not working correct
ctx.set_source_rgba(color[0], color[1], color[2], color[3])
ctx.fill()
# and again for the border
ctx.move_to(radiusout * math.cos(start_rad), radiusout * math.sin(start_rad))
ctx.arc(0, 0, radiusout, start_rad, stop_rad)
if (start_rad - stop_rad) % (2 * math.pi) > 1e-5:
radial_motion_type = ctx.line_to
else:
radial_motion_type = ctx.move_to
radial_motion_type(radiusin * math.cos(stop_rad), radiusin * math.sin(stop_rad))
ctx.arc_negative(0, 0, radiusin, stop_rad, start_rad)
radial_motion_type(
radiusout * math.cos(start_rad), radiusout * math.sin(start_rad)
)
##ctx.append_path(path) # not working correct
ctx.fill_preserve()
ctx.set_source_rgb(0, 0, 0) # black
if thick:
ctx.set_line_width(3)
Expand All @@ -618,24 +604,16 @@ def draw_innerring(self, ctx, person, userdata, start, inc):
ctx.line_to(rmax * math.cos(thetamax), rmax * math.sin(thetamax))
ctx.arc_negative(0, 0, rmax, thetamax, thetamin)
ctx.close_path()
##path = ctx.copy_path() # not working correct
ctx.set_source_rgb(0, 0, 0) # black
ctx.set_line_width(1)
ctx.stroke()
# now again to fill
if person:
red, green, blue, alpha = self.background_box(person, -1, userdata)
else:
red = green = blue = 255
alpha = 1
ctx.move_to(rmin * math.cos(thetamin), rmin * math.sin(thetamin))
ctx.arc(0, 0, rmin, thetamin, thetamax)
ctx.line_to(rmax * math.cos(thetamax), rmax * math.sin(thetamax))
ctx.arc_negative(0, 0, rmax, thetamax, thetamin)
ctx.close_path()
##ctx.append_path(path) # not working correct
ctx.set_source_rgba(red / 255.0, green / 255.0, blue / 255.0, alpha)
ctx.fill()
ctx.fill_preserve()
ctx.set_source_rgb(0, 0, 0) # black
ctx.set_line_width(1)
ctx.stroke()

def draw_person(
self,
Expand Down
3 changes: 1 addition & 2 deletions gramps/plugins/lib/maps/lifewaylayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,9 @@ def do_draw(self, gpsmap, ctx):
ctx.move_to(coord_x1, coord_y1)
ctx.translate(coord_x1, coord_y1 / coz)
ctx.arc(0.0, 0.0, cox, 0.0, 2 * pi)
ctx.fill()
ctx.fill_preserve()
ctx.set_source_rgba(1.0, 0.0, 0.0, 0.5)
ctx.set_line_width(2.0)
ctx.arc(0.0, 0.0, cox, 0.0, 2 * pi)
ctx.stroke()
ctx.restore()

Expand Down
58 changes: 21 additions & 37 deletions gramps/plugins/lib/maps/markerlayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,47 +192,31 @@ def draw_marker(ctx, x01, y01, size, color):
width = 48.0 * size
height = width / 2
color = Gdk.color_parse(color)
ctx.set_source_rgba(
float(color.red / 65535.0),
float(color.green / 65535.0),
float(color.blue / 65535.0),
1.0,
) # transparency
ctx.set_line_width(2.0)
ctx.move_to(x01, y01)
ctx.line_to((x01 + (height / 3)), (y01 - height * 2))
ctx.line_to((x01 - (height / 3)), (y01 - height * 2))
ctx.fill()
ctx.set_source_rgba(1.0, 0.0, 0.0, 0.5)
fill_color = (
color.red / 65535.0,
color.green / 65535.0,
color.blue / 65535.0,
1.0, # transparency
)
stroke_color = (1.0, 0.0, 0.0, 0.5)

ctx.move_to(x01, y01)
ctx.line_to((x01 + (height / 3)), (y01 - height * 2))
ctx.line_to((x01 - (height / 3)), (y01 - height * 2))
ctx.line_to(x01, y01)
ctx.stroke()
ctx.save()
ctx.translate(x01 + width / 4 - (width / 4), y01 - height * 2 - (width / 4))
ctx.scale(width / 2.0, height / 2.0)
ctx.arc(0.0, 0.0, 1.0, 0.0, 2 * PI)
ctx.fill_preserve()
ctx.set_source_rgba(1.0, 0.0, 0.0, 0.5)
ctx.line_to(x01 + width / 6, y01 - height * 2)
ctx.line_to(x01 - width / 6, y01 - height * 2)
ctx.close_path()
ctx.set_line_width(2.0)
ctx.arc(0.0, 0.0, 1.0, 0.0, 2 * PI)
ctx.restore()
ctx.set_source_rgba(*fill_color)
ctx.fill_preserve()
ctx.set_source_rgba(*stroke_color)
ctx.stroke()

ctx.save()
ctx.set_source_rgba(
float(color.red / 65535.0),
float(color.green / 65535.0),
float(color.blue / 65535.0),
1.0,
) # transparency
# ctx.translate(x01 + width/4 - 12.0 , y01 - height*2 - 12.0)
ctx.translate(x01 + width / 4 - (width / 4), y01 - height * 2 - (width / 4))
ctx.scale(width / 2.0, height / 2.0)
ctx.arc(0.0, 0.0, 1.0, 0.0, 2 * PI)
ctx.fill_preserve()
ctx.set_source_rgba(1.0, 0.0, 0.0, 0.5)
ctx.set_line_width(2.0)
ctx.translate(x01, y01 - height * 2 - width / 4)
ctx.scale(width / 2, height / 2)
ctx.arc(0.0, 0.0, 1.0, 0.0, 2 * PI)
ctx.restore()
ctx.set_line_width(2.0)
ctx.set_source_rgba(*fill_color)
ctx.fill_preserve()
ctx.set_source_rgba(*stroke_color)
ctx.stroke()

0 comments on commit 3442876

Please sign in to comment.