Added uiDrawClip() and implemented it on GTK+.

This commit is contained in:
Pietro Gagliardi 2015-10-13 11:16:06 -04:00
parent 2fd6ba8081
commit cc827919b8
3 changed files with 57 additions and 2 deletions

View File

@ -1299,7 +1299,46 @@ static void drawCSArcNegative(uiAreaDrawParams *p)
uiDrawFreePath(path);
}
// TODO clip
// clip
static void drawCSClip(uiAreaDrawParams *p)
{
uiDrawBrush source;
uiDrawStrokeParams sp;
uiDrawPath *path;
crsourcergba(&source, 0, 0, 0, 1);
sp.Cap = uiDrawLineCapFlat;
sp.Join = uiDrawLineJoinMiter;
sp.MiterLimit = uiDrawDefaultMiterLimit;
path = uiDrawNewPath(uiDrawFillModeWinding);
uiDrawPathNewFigureWithArc(path,
128.0, 128.0,
76.8,
0, 2 * M_PI,
0);
uiDrawPathEnd(path);
uiDrawClip(p->Context, path);
uiDrawFreePath(path);
path = uiDrawNewPath(uiDrawFillModeWinding);
uiDrawPathAddRectangle(path, 0, 0, 256, 256);
uiDrawPathEnd(path);
uiDrawFill(p->Context, path, &source);
uiDrawFreePath(path);
crsourcergba(&source, 0, 1, 0, 1);
path = uiDrawNewPath(uiDrawFillModeWinding);
uiDrawPathNewFigure(path, 0, 0);
uiDrawPathLineTo(path, 256, 256);
uiDrawPathNewFigure(path, 256, 0);
uiDrawPathLineTo(path, 0, 256);
uiDrawPathEnd(path);
sp.Thickness = 10.0;
uiDrawStroke(p->Context, path, &source, &sp);
uiDrawFreePath(path);
}
// TODO clip image
@ -1772,6 +1811,7 @@ static const struct drawtest tests[] = {
{ "Direct2D: How to Draw and Fill a Complex Shape", drawD2DComplexShape },
{ "cairo samples: arc", drawCSArc },
{ "cairo samples: arc negative", drawCSArcNegative },
{ "cairo samples: clip", drawCSClip },
{ "cairo samples: curve rectangle", drawCSCurveRectangle },
{ "cairo samples: curve to", drawCSCurveTo },
{ "cairo samples: fill and stroke2", drawCSFillAndStroke2 },

3
ui.h
View File

@ -425,7 +425,8 @@ _UI_EXTERN void uiDrawMatrixTransformSize(uiDrawMatrix *m, double *x, double *y)
_UI_EXTERN void uiDrawTransform(uiDrawContext *c, uiDrawMatrix *m);
// TODO put uiDrawClip here
// TODO add a uiDrawPathStrokeToFill() or something like that
_UI_EXTERN void uiDrawClip(uiDrawContext *c, uiDrawPath *path);
_UI_EXTERN void uiDrawSave(uiDrawContext *c);
_UI_EXTERN void uiDrawRestore(uiDrawContext *c);

View File

@ -422,6 +422,20 @@ void uiDrawTransform(uiDrawContext *c, uiDrawMatrix *m)
cairo_transform(c->cr, &cm);
}
void uiDrawClip(uiDrawContext *c, uiDrawPath *path)
{
runPath(path, c->cr);
switch (path->fillMode) {
case uiDrawFillModeWinding:
cairo_set_fill_rule(c->cr, CAIRO_FILL_RULE_WINDING);
break;
case uiDrawFillModeAlternate:
cairo_set_fill_rule(c->cr, CAIRO_FILL_RULE_EVEN_ODD);
break;
}
cairo_clip(c->cr);
}
void uiDrawSave(uiDrawContext *c)
{
cairo_save(c->cr);