2015-09-10 13:27:45 -05:00
|
|
|
// 6 september 2015
|
2015-10-09 11:33:45 -05:00
|
|
|
#import "uipriv_darwin.h"
|
2017-01-06 22:53:23 -06:00
|
|
|
#import "draw.h"
|
2015-09-10 13:27:45 -05:00
|
|
|
|
2015-10-08 10:49:24 -05:00
|
|
|
struct uiDrawPath {
|
|
|
|
CGMutablePathRef path;
|
|
|
|
uiDrawFillMode fillMode;
|
|
|
|
BOOL ended;
|
2015-09-10 13:27:45 -05:00
|
|
|
};
|
|
|
|
|
2015-10-08 10:49:24 -05:00
|
|
|
uiDrawPath *uiDrawNewPath(uiDrawFillMode mode)
|
2015-09-10 13:27:45 -05:00
|
|
|
{
|
2015-10-08 10:49:24 -05:00
|
|
|
uiDrawPath *p;
|
2015-09-10 13:27:45 -05:00
|
|
|
|
2018-04-15 15:05:24 -05:00
|
|
|
p = uiprivNew(uiDrawPath);
|
2015-10-08 11:19:48 -05:00
|
|
|
p->path = CGPathCreateMutable();
|
2015-10-08 10:49:24 -05:00
|
|
|
p->fillMode = mode;
|
|
|
|
return p;
|
2015-09-10 13:27:45 -05:00
|
|
|
}
|
|
|
|
|
2015-10-08 10:49:24 -05:00
|
|
|
void uiDrawFreePath(uiDrawPath *p)
|
2015-09-10 13:27:45 -05:00
|
|
|
{
|
2015-10-08 10:49:24 -05:00
|
|
|
CGPathRelease((CGPathRef) (p->path));
|
2018-04-15 15:05:24 -05:00
|
|
|
uiprivFree(p);
|
2015-09-10 13:27:45 -05:00
|
|
|
}
|
|
|
|
|
2015-10-08 10:49:24 -05:00
|
|
|
void uiDrawPathNewFigure(uiDrawPath *p, double x, double y)
|
2015-09-10 13:27:45 -05:00
|
|
|
{
|
2015-10-08 10:49:24 -05:00
|
|
|
if (p->ended)
|
2018-04-15 20:46:08 -05:00
|
|
|
uiprivUserBug("You cannot call uiDrawPathNewFigure() on a uiDrawPath that has already been ended. (path; %p)", p);
|
2015-10-08 10:49:24 -05:00
|
|
|
CGPathMoveToPoint(p->path, NULL, x, y);
|
2015-09-10 13:27:45 -05:00
|
|
|
}
|
|
|
|
|
2015-10-11 22:48:40 -05:00
|
|
|
void uiDrawPathNewFigureWithArc(uiDrawPath *p, double xCenter, double yCenter, double radius, double startAngle, double sweep, int negative)
|
2015-10-08 10:49:24 -05:00
|
|
|
{
|
2015-10-08 11:19:48 -05:00
|
|
|
double sinStart, cosStart;
|
|
|
|
double startx, starty;
|
|
|
|
|
2015-10-08 10:49:24 -05:00
|
|
|
if (p->ended)
|
2018-04-15 20:46:08 -05:00
|
|
|
uiprivUserBug("You cannot call uiDrawPathNewFigureWithArc() on a uiDrawPath that has already been ended. (path; %p)", p);
|
2015-10-08 11:19:48 -05:00
|
|
|
sinStart = sin(startAngle);
|
|
|
|
cosStart = cos(startAngle);
|
|
|
|
startx = xCenter + radius * cosStart;
|
2015-10-11 19:24:06 -05:00
|
|
|
starty = yCenter + radius * sinStart;
|
2015-10-08 10:49:24 -05:00
|
|
|
CGPathMoveToPoint(p->path, NULL, startx, starty);
|
2015-10-11 22:48:40 -05:00
|
|
|
uiDrawPathArcTo(p, xCenter, yCenter, radius, startAngle, sweep, negative);
|
2015-10-08 10:49:24 -05:00
|
|
|
}
|
2015-09-10 13:27:45 -05:00
|
|
|
|
2015-10-08 10:49:24 -05:00
|
|
|
void uiDrawPathLineTo(uiDrawPath *p, double x, double y)
|
2015-09-10 13:27:45 -05:00
|
|
|
{
|
2016-05-13 19:14:46 -05:00
|
|
|
// TODO refine this to require being in a path
|
2015-10-08 10:49:24 -05:00
|
|
|
if (p->ended)
|
2018-04-15 20:46:08 -05:00
|
|
|
uiprivImplBug("attempt to add line to ended path in uiDrawPathLineTo()");
|
2015-10-08 10:49:24 -05:00
|
|
|
CGPathAddLineToPoint(p->path, NULL, x, y);
|
2015-09-10 13:27:45 -05:00
|
|
|
}
|
|
|
|
|
2015-10-11 22:48:40 -05:00
|
|
|
void uiDrawPathArcTo(uiDrawPath *p, double xCenter, double yCenter, double radius, double startAngle, double sweep, int negative)
|
2015-09-10 13:27:45 -05:00
|
|
|
{
|
2015-10-11 22:48:40 -05:00
|
|
|
bool cw;
|
|
|
|
|
2016-05-13 19:14:46 -05:00
|
|
|
// TODO likewise
|
2015-10-08 10:49:24 -05:00
|
|
|
if (p->ended)
|
2018-04-15 20:46:08 -05:00
|
|
|
uiprivImplBug("attempt to add arc to ended path in uiDrawPathArcTo()");
|
2016-05-22 11:00:44 -05:00
|
|
|
if (sweep > 2 * uiPi)
|
|
|
|
sweep = 2 * uiPi;
|
2015-10-11 22:48:40 -05:00
|
|
|
cw = false;
|
|
|
|
if (negative)
|
|
|
|
cw = true;
|
|
|
|
CGPathAddArc(p->path, NULL,
|
2015-10-08 10:49:24 -05:00
|
|
|
xCenter, yCenter,
|
|
|
|
radius,
|
2015-10-11 22:48:40 -05:00
|
|
|
startAngle, startAngle + sweep,
|
|
|
|
cw);
|
2015-09-10 13:27:45 -05:00
|
|
|
}
|
|
|
|
|
2015-10-08 10:49:24 -05:00
|
|
|
void uiDrawPathBezierTo(uiDrawPath *p, double c1x, double c1y, double c2x, double c2y, double endX, double endY)
|
2015-09-10 13:27:45 -05:00
|
|
|
{
|
2016-05-13 19:14:46 -05:00
|
|
|
// TODO likewise
|
2015-10-08 10:49:24 -05:00
|
|
|
if (p->ended)
|
2018-04-15 20:46:08 -05:00
|
|
|
uiprivImplBug("attempt to add bezier to ended path in uiDrawPathBezierTo()");
|
2015-10-08 10:49:24 -05:00
|
|
|
CGPathAddCurveToPoint(p->path, NULL,
|
|
|
|
c1x, c1y,
|
|
|
|
c2x, c2y,
|
|
|
|
endX, endY);
|
2015-09-10 13:27:45 -05:00
|
|
|
}
|
|
|
|
|
2015-10-08 10:49:24 -05:00
|
|
|
void uiDrawPathCloseFigure(uiDrawPath *p)
|
2015-09-10 13:27:45 -05:00
|
|
|
{
|
2016-05-13 19:14:46 -05:00
|
|
|
// TODO likewise
|
2015-10-08 10:49:24 -05:00
|
|
|
if (p->ended)
|
2018-04-15 20:46:08 -05:00
|
|
|
uiprivImplBug("attempt to close figure of ended path in uiDrawPathCloseFigure()");
|
2015-10-08 10:49:24 -05:00
|
|
|
CGPathCloseSubpath(p->path);
|
2015-09-10 13:27:45 -05:00
|
|
|
}
|
|
|
|
|
2015-10-08 10:49:24 -05:00
|
|
|
void uiDrawPathAddRectangle(uiDrawPath *p, double x, double y, double width, double height)
|
2015-09-10 13:27:45 -05:00
|
|
|
{
|
2015-10-08 10:49:24 -05:00
|
|
|
if (p->ended)
|
2018-04-15 20:46:08 -05:00
|
|
|
uiprivUserBug("You cannot call uiDrawPathAddRectangle() on a uiDrawPath that has already been ended. (path; %p)", p);
|
2015-10-08 10:49:24 -05:00
|
|
|
CGPathAddRect(p->path, NULL, CGRectMake(x, y, width, height));
|
2015-09-10 13:27:45 -05:00
|
|
|
}
|
|
|
|
|
2015-10-08 10:49:24 -05:00
|
|
|
void uiDrawPathEnd(uiDrawPath *p)
|
2015-09-10 13:27:45 -05:00
|
|
|
{
|
2015-10-08 10:49:24 -05:00
|
|
|
p->ended = TRUE;
|
2015-09-10 13:27:45 -05:00
|
|
|
}
|
|
|
|
|
2016-01-08 12:51:39 -06:00
|
|
|
uiDrawContext *newContext(CGContextRef ctxt, CGFloat height)
|
2015-09-10 13:27:45 -05:00
|
|
|
{
|
2015-10-08 10:49:24 -05:00
|
|
|
uiDrawContext *c;
|
|
|
|
|
2018-04-15 15:05:24 -05:00
|
|
|
c = uiprivNew(uiDrawContext);
|
2015-10-08 10:49:24 -05:00
|
|
|
c->c = ctxt;
|
2016-01-08 12:51:39 -06:00
|
|
|
c->height = height;
|
2015-10-08 10:49:24 -05:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2015-10-09 11:33:45 -05:00
|
|
|
void freeContext(uiDrawContext *c)
|
|
|
|
{
|
2018-04-15 15:05:24 -05:00
|
|
|
uiprivFree(c);
|
2015-10-09 11:33:45 -05:00
|
|
|
}
|
|
|
|
|
2015-10-08 10:49:24 -05:00
|
|
|
// a stroke is identical to a fill of a stroked path
|
|
|
|
// we need to do this in order to stroke with a gradient; see http://stackoverflow.com/a/25034854/3408572
|
|
|
|
// doing this for other brushes works too
|
|
|
|
void uiDrawStroke(uiDrawContext *c, uiDrawPath *path, uiDrawBrush *b, uiDrawStrokeParams *p)
|
|
|
|
{
|
|
|
|
CGLineCap cap;
|
|
|
|
CGLineJoin join;
|
2015-10-16 10:05:08 -05:00
|
|
|
CGPathRef dashPath;
|
|
|
|
CGFloat *dashes;
|
|
|
|
size_t i;
|
2015-10-08 10:49:24 -05:00
|
|
|
uiDrawPath p2;
|
|
|
|
|
|
|
|
if (!path->ended)
|
2018-04-15 20:46:08 -05:00
|
|
|
uiprivUserBug("You cannot call uiDrawStroke() on a uiDrawPath that has not been ended. (path: %p)", path);
|
2015-10-08 10:49:24 -05:00
|
|
|
|
2015-09-10 13:27:45 -05:00
|
|
|
switch (p->Cap) {
|
|
|
|
case uiDrawLineCapFlat:
|
2015-10-08 10:49:24 -05:00
|
|
|
cap = kCGLineCapButt;
|
2015-09-10 13:27:45 -05:00
|
|
|
break;
|
|
|
|
case uiDrawLineCapRound:
|
2015-10-08 10:49:24 -05:00
|
|
|
cap = kCGLineCapRound;
|
2015-09-10 13:27:45 -05:00
|
|
|
break;
|
|
|
|
case uiDrawLineCapSquare:
|
2015-10-08 10:49:24 -05:00
|
|
|
cap = kCGLineCapSquare;
|
2015-09-10 13:27:45 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch (p->Join) {
|
|
|
|
case uiDrawLineJoinMiter:
|
2015-10-08 10:49:24 -05:00
|
|
|
join = kCGLineJoinMiter;
|
2015-09-10 13:27:45 -05:00
|
|
|
break;
|
|
|
|
case uiDrawLineJoinRound:
|
2015-10-08 10:49:24 -05:00
|
|
|
join = kCGLineJoinRound;
|
2015-09-10 13:27:45 -05:00
|
|
|
break;
|
|
|
|
case uiDrawLineJoinBevel:
|
2015-10-08 10:49:24 -05:00
|
|
|
join = kCGLineJoinBevel;
|
2015-09-10 13:27:45 -05:00
|
|
|
break;
|
|
|
|
}
|
2015-10-08 10:49:24 -05:00
|
|
|
|
|
|
|
// create a temporary path identical to the previous one
|
2015-10-16 10:05:08 -05:00
|
|
|
dashPath = (CGPathRef) path->path;
|
|
|
|
if (p->NumDashes != 0) {
|
2018-04-15 15:05:24 -05:00
|
|
|
dashes = (CGFloat *) uiprivAlloc(p->NumDashes * sizeof (CGFloat), "CGFloat[]");
|
2015-10-16 10:05:08 -05:00
|
|
|
for (i = 0; i < p->NumDashes; i++)
|
|
|
|
dashes[i] = p->Dashes[i];
|
|
|
|
dashPath = CGPathCreateCopyByDashingPath(path->path,
|
|
|
|
NULL,
|
|
|
|
p->DashPhase,
|
|
|
|
dashes,
|
|
|
|
p->NumDashes);
|
2018-04-15 15:05:24 -05:00
|
|
|
uiprivFree(dashes);
|
2015-10-16 10:05:08 -05:00
|
|
|
}
|
|
|
|
// the documentation is wrong: this produces a path suitable for calling CGPathCreateCopyByStrokingPath(), not for filling directly
|
2015-10-08 10:49:24 -05:00
|
|
|
// the cast is safe; we never modify the CGPathRef and always cast it back to a CGPathRef anyway
|
2015-10-16 10:05:08 -05:00
|
|
|
p2.path = (CGMutablePathRef) CGPathCreateCopyByStrokingPath(dashPath,
|
2015-10-08 10:49:24 -05:00
|
|
|
NULL,
|
|
|
|
p->Thickness,
|
|
|
|
cap,
|
|
|
|
join,
|
|
|
|
p->MiterLimit);
|
2015-10-16 10:05:08 -05:00
|
|
|
if (p->NumDashes != 0)
|
|
|
|
CGPathRelease(dashPath);
|
|
|
|
|
2015-10-11 23:27:34 -05:00
|
|
|
// always draw stroke fills using the winding rule
|
|
|
|
// otherwise intersecting figures won't draw correctly
|
|
|
|
p2.fillMode = uiDrawFillModeWinding;
|
2015-10-08 10:49:24 -05:00
|
|
|
p2.ended = path->ended;
|
|
|
|
uiDrawFill(c, &p2, b);
|
|
|
|
// and clean up
|
|
|
|
CGPathRelease((CGPathRef) (p2.path));
|
|
|
|
}
|
|
|
|
|
|
|
|
// for a solid fill, we can merely have Core Graphics fill directly
|
|
|
|
static void fillSolid(CGContextRef ctxt, uiDrawPath *p, uiDrawBrush *b)
|
|
|
|
{
|
2016-05-28 17:01:25 -05:00
|
|
|
// TODO this uses DeviceRGB; switch to sRGB
|
2015-10-08 10:49:24 -05:00
|
|
|
CGContextSetRGBFillColor(ctxt, b->R, b->G, b->B, b->A);
|
|
|
|
switch (p->fillMode) {
|
|
|
|
case uiDrawFillModeWinding:
|
|
|
|
CGContextFillPath(ctxt);
|
|
|
|
break;
|
|
|
|
case uiDrawFillModeAlternate:
|
|
|
|
CGContextEOFillPath(ctxt);
|
|
|
|
break;
|
2015-09-10 13:27:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-08 10:49:24 -05:00
|
|
|
// for a gradient fill, we need to clip to the path and then draw the gradient
|
|
|
|
// see http://stackoverflow.com/a/25034854/3408572
|
|
|
|
static void fillGradient(CGContextRef ctxt, uiDrawPath *p, uiDrawBrush *b)
|
2015-09-10 13:27:45 -05:00
|
|
|
{
|
2015-10-08 10:49:24 -05:00
|
|
|
CGGradientRef gradient;
|
|
|
|
CGColorSpaceRef colorspace;
|
|
|
|
CGFloat *colors;
|
|
|
|
CGFloat *locations;
|
2015-10-08 11:19:48 -05:00
|
|
|
size_t i;
|
2015-10-08 10:49:24 -05:00
|
|
|
|
|
|
|
// gradients need a color space
|
|
|
|
// for consistency with windows, use sRGB
|
|
|
|
colorspace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
|
2017-02-12 19:27:47 -06:00
|
|
|
if (colorspace == NULL) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
// TODO add NULL check to other uses of CGColorSpace
|
2015-10-08 10:49:24 -05:00
|
|
|
|
|
|
|
// make the gradient
|
2018-04-15 15:05:24 -05:00
|
|
|
colors = uiprivAlloc(b->NumStops * 4 * sizeof (CGFloat), "CGFloat[]");
|
|
|
|
locations = uiprivAlloc(b->NumStops * sizeof (CGFloat), "CGFloat[]");
|
2015-10-08 10:49:24 -05:00
|
|
|
for (i = 0; i < b->NumStops; i++) {
|
|
|
|
colors[i * 4 + 0] = b->Stops[i].R;
|
|
|
|
colors[i * 4 + 1] = b->Stops[i].G;
|
|
|
|
colors[i * 4 + 2] = b->Stops[i].B;
|
|
|
|
colors[i * 4 + 3] = b->Stops[i].A;
|
|
|
|
locations[i] = b->Stops[i].Pos;
|
2015-09-10 13:27:45 -05:00
|
|
|
}
|
2015-10-08 10:49:24 -05:00
|
|
|
gradient = CGGradientCreateWithColorComponents(colorspace, colors, locations, b->NumStops);
|
2018-04-15 15:05:24 -05:00
|
|
|
uiprivFree(locations);
|
|
|
|
uiprivFree(colors);
|
2015-10-08 10:49:24 -05:00
|
|
|
|
2015-10-08 11:19:48 -05:00
|
|
|
// because we're mucking with clipping, we need to save the graphics state and restore it later
|
|
|
|
CGContextSaveGState(ctxt);
|
|
|
|
|
2015-10-08 10:49:24 -05:00
|
|
|
// clip
|
|
|
|
switch (p->fillMode) {
|
2015-09-10 13:27:45 -05:00
|
|
|
case uiDrawFillModeWinding:
|
2015-10-08 10:49:24 -05:00
|
|
|
CGContextClip(ctxt);
|
2015-09-10 13:27:45 -05:00
|
|
|
break;
|
|
|
|
case uiDrawFillModeAlternate:
|
2015-10-08 10:49:24 -05:00
|
|
|
CGContextEOClip(ctxt);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// draw the gradient
|
|
|
|
switch (b->Type) {
|
|
|
|
case uiDrawBrushTypeLinearGradient:
|
|
|
|
CGContextDrawLinearGradient(ctxt,
|
|
|
|
gradient,
|
|
|
|
CGPointMake(b->X0, b->Y0),
|
|
|
|
CGPointMake(b->X1, b->Y1),
|
|
|
|
kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation);
|
2015-09-10 13:27:45 -05:00
|
|
|
break;
|
2015-10-08 10:49:24 -05:00
|
|
|
case uiDrawBrushTypeRadialGradient:
|
|
|
|
CGContextDrawRadialGradient(ctxt,
|
|
|
|
gradient,
|
|
|
|
CGPointMake(b->X0, b->Y0),
|
|
|
|
// make the start circle radius 0 to make it a point
|
|
|
|
0,
|
|
|
|
CGPointMake(b->X1, b->Y1),
|
|
|
|
b->OuterRadius,
|
|
|
|
kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// and clean up
|
2015-10-08 11:19:48 -05:00
|
|
|
CGContextRestoreGState(ctxt);
|
2015-10-08 10:49:24 -05:00
|
|
|
CGGradientRelease(gradient);
|
|
|
|
CGColorSpaceRelease(colorspace);
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiDrawFill(uiDrawContext *c, uiDrawPath *path, uiDrawBrush *b)
|
|
|
|
{
|
|
|
|
if (!path->ended)
|
2018-04-15 20:46:08 -05:00
|
|
|
uiprivUserBug("You cannot call uiDrawStroke() on a uiDrawPath that has not been ended. (path: %p)", path);
|
2015-10-08 11:19:48 -05:00
|
|
|
CGContextAddPath(c->c, (CGPathRef) (path->path));
|
2015-10-08 10:49:24 -05:00
|
|
|
switch (b->Type) {
|
|
|
|
case uiDrawBrushTypeSolid:
|
|
|
|
fillSolid(c->c, path, b);
|
|
|
|
return;
|
|
|
|
case uiDrawBrushTypeLinearGradient:
|
|
|
|
case uiDrawBrushTypeRadialGradient:
|
|
|
|
fillGradient(c->c, path, b);
|
|
|
|
return;
|
|
|
|
// case uiDrawBrushTypeImage:
|
|
|
|
// TODO
|
|
|
|
return;
|
2015-09-10 13:27:45 -05:00
|
|
|
}
|
2018-04-15 20:46:08 -05:00
|
|
|
uiprivUserBug("Unknown brush type %d passed to uiDrawFill().", b->Type);
|
2015-09-10 13:27:45 -05:00
|
|
|
}
|
2015-10-11 12:53:47 -05:00
|
|
|
|
|
|
|
static void m2c(uiDrawMatrix *m, CGAffineTransform *c)
|
|
|
|
{
|
|
|
|
c->a = m->M11;
|
|
|
|
c->b = m->M12;
|
|
|
|
c->c = m->M21;
|
|
|
|
c->d = m->M22;
|
|
|
|
c->tx = m->M31;
|
|
|
|
c->ty = m->M32;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void c2m(CGAffineTransform *c, uiDrawMatrix *m)
|
|
|
|
{
|
|
|
|
m->M11 = c->a;
|
|
|
|
m->M12 = c->b;
|
|
|
|
m->M21 = c->c;
|
|
|
|
m->M22 = c->d;
|
|
|
|
m->M31 = c->tx;
|
|
|
|
m->M32 = c->ty;
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiDrawMatrixTranslate(uiDrawMatrix *m, double x, double y)
|
|
|
|
{
|
|
|
|
CGAffineTransform c;
|
|
|
|
|
|
|
|
m2c(m, &c);
|
|
|
|
c = CGAffineTransformTranslate(c, x, y);
|
|
|
|
c2m(&c, m);
|
|
|
|
}
|
|
|
|
|
2015-10-12 00:43:12 -05:00
|
|
|
void uiDrawMatrixScale(uiDrawMatrix *m, double xCenter, double yCenter, double x, double y)
|
2015-10-11 12:53:47 -05:00
|
|
|
{
|
|
|
|
CGAffineTransform c;
|
2015-10-12 00:43:12 -05:00
|
|
|
double xt, yt;
|
2015-10-11 12:53:47 -05:00
|
|
|
|
|
|
|
m2c(m, &c);
|
2015-10-12 00:43:12 -05:00
|
|
|
xt = x;
|
|
|
|
yt = y;
|
2018-04-15 21:39:34 -05:00
|
|
|
uiprivScaleCenter(xCenter, yCenter, &xt, &yt);
|
2015-10-12 00:43:12 -05:00
|
|
|
c = CGAffineTransformTranslate(c, xt, yt);
|
2015-10-11 12:53:47 -05:00
|
|
|
c = CGAffineTransformScale(c, x, y);
|
2016-05-22 21:52:29 -05:00
|
|
|
c = CGAffineTransformTranslate(c, -xt, -yt);
|
2015-10-11 12:53:47 -05:00
|
|
|
c2m(&c, m);
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiDrawMatrixRotate(uiDrawMatrix *m, double x, double y, double amount)
|
|
|
|
{
|
|
|
|
CGAffineTransform c;
|
|
|
|
|
|
|
|
m2c(m, &c);
|
|
|
|
c = CGAffineTransformTranslate(c, x, y);
|
2015-10-12 00:18:08 -05:00
|
|
|
c = CGAffineTransformRotate(c, amount);
|
2015-10-11 12:53:47 -05:00
|
|
|
c = CGAffineTransformTranslate(c, -x, -y);
|
|
|
|
c2m(&c, m);
|
|
|
|
}
|
|
|
|
|
2015-10-12 06:58:07 -05:00
|
|
|
void uiDrawMatrixSkew(uiDrawMatrix *m, double x, double y, double xamount, double yamount)
|
2015-10-11 12:53:47 -05:00
|
|
|
{
|
2018-04-15 21:39:34 -05:00
|
|
|
uiprivFallbackSkew(m, x, y, xamount, yamount);
|
2015-10-11 12:53:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void uiDrawMatrixMultiply(uiDrawMatrix *dest, uiDrawMatrix *src)
|
|
|
|
{
|
|
|
|
CGAffineTransform c;
|
|
|
|
CGAffineTransform d;
|
|
|
|
|
|
|
|
m2c(dest, &c);
|
|
|
|
m2c(src, &d);
|
|
|
|
c = CGAffineTransformConcat(c, d);
|
|
|
|
c2m(&c, dest);
|
|
|
|
}
|
|
|
|
|
|
|
|
// there is no test for invertibility; CGAffineTransformInvert() is merely documented as returning the matrix unchanged if it isn't invertible
|
|
|
|
// therefore, special care must be taken to catch matrices who are their own inverses
|
|
|
|
// TODO figure out which matrices these are and do so
|
|
|
|
int uiDrawMatrixInvertible(uiDrawMatrix *m)
|
|
|
|
{
|
|
|
|
CGAffineTransform c, d;
|
|
|
|
|
|
|
|
m2c(m, &c);
|
|
|
|
d = CGAffineTransformInvert(c);
|
|
|
|
return CGAffineTransformEqualToTransform(c, d) == false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int uiDrawMatrixInvert(uiDrawMatrix *m)
|
|
|
|
{
|
|
|
|
CGAffineTransform c, d;
|
|
|
|
|
|
|
|
m2c(m, &c);
|
|
|
|
d = CGAffineTransformInvert(c);
|
|
|
|
if (CGAffineTransformEqualToTransform(c, d))
|
|
|
|
return 0;
|
|
|
|
c2m(&d, m);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiDrawMatrixTransformPoint(uiDrawMatrix *m, double *x, double *y)
|
|
|
|
{
|
|
|
|
CGAffineTransform c;
|
|
|
|
CGPoint p;
|
|
|
|
|
|
|
|
m2c(m, &c);
|
|
|
|
p = CGPointApplyAffineTransform(CGPointMake(*x, *y), c);
|
|
|
|
*x = p.x;
|
|
|
|
*y = p.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiDrawMatrixTransformSize(uiDrawMatrix *m, double *x, double *y)
|
|
|
|
{
|
|
|
|
CGAffineTransform c;
|
|
|
|
CGSize s;
|
|
|
|
|
|
|
|
m2c(m, &c);
|
|
|
|
s = CGSizeApplyAffineTransform(CGSizeMake(*x, *y), c);
|
|
|
|
*x = s.width;
|
|
|
|
*y = s.height;
|
|
|
|
}
|
|
|
|
|
2015-10-12 20:11:42 -05:00
|
|
|
void uiDrawTransform(uiDrawContext *c, uiDrawMatrix *m)
|
|
|
|
{
|
|
|
|
CGAffineTransform cm;
|
|
|
|
|
|
|
|
m2c(m, &cm);
|
|
|
|
CGContextConcatCTM(c->c, cm);
|
|
|
|
}
|
|
|
|
|
2015-10-13 12:53:24 -05:00
|
|
|
void uiDrawClip(uiDrawContext *c, uiDrawPath *path)
|
|
|
|
{
|
|
|
|
if (!path->ended)
|
2018-04-15 20:46:08 -05:00
|
|
|
uiprivUserBug("You cannot call uiDrawCilp() on a uiDrawPath that has not been ended. (path: %p)", path);
|
2015-10-13 12:53:24 -05:00
|
|
|
CGContextAddPath(c->c, (CGPathRef) (path->path));
|
|
|
|
switch (path->fillMode) {
|
|
|
|
case uiDrawFillModeWinding:
|
|
|
|
CGContextClip(c->c);
|
|
|
|
break;
|
|
|
|
case uiDrawFillModeAlternate:
|
|
|
|
CGContextEOClip(c->c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-11 12:53:47 -05:00
|
|
|
// TODO figure out what besides transforms these save/restore on all platforms
|
|
|
|
void uiDrawSave(uiDrawContext *c)
|
|
|
|
{
|
|
|
|
CGContextSaveGState(c->c);
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiDrawRestore(uiDrawContext *c)
|
|
|
|
{
|
|
|
|
CGContextRestoreGState(c->c);
|
|
|
|
}
|