


## cartouche.pkg
## Copyright 1988 by the Massachusetts Institute of Technology
# Compiled by:
# src/lib/x-kit/draw/xkit-draw.sublib# Routines to draw/fill rectangles with rounded corners. The implementation
# is lifted from the MIT X11 distribution.
stipulate
include xgeometry; # xgeometry is from src/lib/std/2d/xgeometry.pkg #
package xc = xclient; # xclient is from src/lib/x-kit/xclient/xclient.pkg# package xg = xgeometry; # xgeometry is from src/lib/std/2d/xgeometry.pkgherein
package cartouche
: (weak) Cartouche # Cartouche is from src/lib/x-kit/draw/cartouche.api {
fun draw_cartouche drawable pen { box, corner_radius }
=
{ box -> BOX { col=>x, row=>y, wide=>w, high=>h };
w2 = corner_radius + corner_radius;
h2 = corner_radius + corner_radius;
my (ew, ew2)
=
if (w2 > w) (0, 0);
else (corner_radius, w2);
fi;
my (eh, eh2)
=
if (h2 > h) (0, 0);
else (corner_radius, h2);
fi;
xc::draw_arcs drawable pen [
#
ARC { col=> x, row=> y, wide=> ew2, high=> eh2, angle1=> 180*64, angle2=> -90*64 },
ARC { col=> x+ew, row=> y, wide=> w - ew2, high=> 0, angle1=> 180*64, angle2=> -180*64 },
ARC { col=> x+w - ew2, row=> y, wide=> ew2, high=> eh2, angle1=> 90*64, angle2=> -90*64 },
ARC { col=> x+w, row=> y+eh, wide=> 0, high=> h - eh2, angle1=> 90*64, angle2=> -180*64 },
ARC { col=> x+w - ew2, row=> y+h - eh2, wide=> ew2, high=> eh2, angle1=> 0, angle2=> -90*64 },
ARC { col=> x+ew, row=> y+h, wide=> w - ew2, high=> 0, angle1=> 0, angle2=> -180*64 },
ARC { col=> x, row=> y+h - eh2, wide=> ew2, high=> eh2, angle1=> 270*64, angle2=> -90*64 },
ARC { col=> x, row=> y+eh, wide=> 0, high=> h - eh2, angle1=> 270*64, angle2=> -180*64 }
];
};
fun fill_cartouche drawable pen { box, corner_radius }
=
{ pen = xc::clone_pen (pen, [xc::p::ARC_MODE_PIE_SLICE]);
box -> BOX { col=>x, row=>y, wide=>w, high=>h };
w2 = corner_radius + corner_radius;
h2 = corner_radius + corner_radius;
my (ew, ew2) = if (w2 > w) (0, 0); else (corner_radius, w2); fi;
my (eh, eh2) = if (h2 > h) (0, 0); else (corner_radius, h2); fi;
xc::fill_arcs drawable pen [
#
ARC { col=> x, row=> y, wide=> ew2, high=> eh2, angle1=> 180*64, angle2=> -90*64 },
ARC { col=> x+w - ew2, row=> y, wide=> ew2, high=> eh2, angle1=> 90*64, angle2=> -90*64 },
ARC { col=> x+w - ew2, row=> y+h - eh2, wide=> ew2, high=> eh2, angle1=> 0, angle2=> -90*64 },
ARC { col=> x, row=> y+h - eh2, wide=> ew2, high=> eh2, angle1=> 270*64, angle2=> -90*64 }
];
xc::fill_boxes drawable pen [
#
BOX { col=> x + ew, row=> y, wide=> w - ew*2, high=> h },
BOX { col=> x, row=> y + eh, wide=> ew, high=> h - eh2 },
BOX { col=> x + w - ew, row=> y + eh, wide=> ew, high=> h - eh2 }
];
};
};
end;
## COPYRIGHT (c) 1992 by AT&T Bell Laboratories
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2013,
## released per terms of SMLNJ-COPYRIGHT.


