2015-09-06 19:02:01 -05:00
|
|
|
// 6 september 2015
|
2015-10-08 17:24:09 -05:00
|
|
|
#include "uipriv_unix.h"
|
2016-05-05 17:23:54 -05:00
|
|
|
#include "draw.h"
|
2015-10-08 07:47:36 -05:00
|
|
|
|
|
|
|
uiDrawContext *newContext(cairo_t *cr)
|
|
|
|
{
|
|
|
|
uiDrawContext *c;
|
|
|
|
|
2015-10-09 02:43:29 -05:00
|
|
|
c = uiNew(uiDrawContext);
|
2015-10-08 07:47:36 -05:00
|
|
|
c->cr = cr;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2015-10-09 02:43:29 -05:00
|
|
|
void freeContext(uiDrawContext *c)
|
|
|
|
{
|
|
|
|
uiFree(c);
|
|
|
|
}
|
|
|
|
|
2015-10-08 07:47:36 -05:00
|
|
|
static cairo_pattern_t *mkbrush(uiDrawBrush *b)
|
|
|
|
{
|
|
|
|
cairo_pattern_t *pat;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
switch (b->Type) {
|
|
|
|
case uiDrawBrushTypeSolid:
|
|
|
|
pat = cairo_pattern_create_rgba(b->R, b->G, b->B, b->A);
|
|
|
|
break;
|
|
|
|
case uiDrawBrushTypeLinearGradient:
|
|
|
|
pat = cairo_pattern_create_linear(b->X0, b->Y0, b->X1, b->Y1);
|
|
|
|
break;
|
|
|
|
case uiDrawBrushTypeRadialGradient:
|
|
|
|
// make the start circle radius 0 to make it a point
|
|
|
|
pat = cairo_pattern_create_radial(
|
|
|
|
b->X0, b->Y0, 0,
|
|
|
|
b->X1, b->Y1, b->OuterRadius);
|
|
|
|
break;
|
|
|
|
// case uiDrawBrushTypeImage:
|
|
|
|
}
|
|
|
|
if (cairo_pattern_status(pat) != CAIRO_STATUS_SUCCESS)
|
2015-10-09 02:43:29 -05:00
|
|
|
complain("error creating pattern in mkbrush(): %s",
|
2015-10-08 07:47:36 -05:00
|
|
|
cairo_status_to_string(cairo_pattern_status(pat)));
|
|
|
|
switch (b->Type) {
|
|
|
|
case uiDrawBrushTypeLinearGradient:
|
|
|
|
case uiDrawBrushTypeRadialGradient:
|
|
|
|
for (i = 0; i < b->NumStops; i++)
|
|
|
|
cairo_pattern_add_color_stop_rgba(pat,
|
|
|
|
b->Stops[i].Pos,
|
|
|
|
b->Stops[i].R,
|
|
|
|
b->Stops[i].G,
|
|
|
|
b->Stops[i].B,
|
|
|
|
b->Stops[i].A);
|
|
|
|
}
|
|
|
|
return pat;
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiDrawStroke(uiDrawContext *c, uiDrawPath *path, uiDrawBrush *b, uiDrawStrokeParams *p)
|
|
|
|
{
|
|
|
|
cairo_pattern_t *pat;
|
|
|
|
|
|
|
|
runPath(path, c->cr);
|
|
|
|
pat = mkbrush(b);
|
|
|
|
cairo_set_source(c->cr, pat);
|
2015-09-06 19:02:01 -05:00
|
|
|
switch (p->Cap) {
|
|
|
|
case uiDrawLineCapFlat:
|
|
|
|
cairo_set_line_cap(c->cr, CAIRO_LINE_CAP_BUTT);
|
|
|
|
break;
|
|
|
|
case uiDrawLineCapRound:
|
|
|
|
cairo_set_line_cap(c->cr, CAIRO_LINE_CAP_ROUND);
|
|
|
|
break;
|
|
|
|
case uiDrawLineCapSquare:
|
|
|
|
cairo_set_line_cap(c->cr, CAIRO_LINE_CAP_SQUARE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch (p->Join) {
|
|
|
|
case uiDrawLineJoinMiter:
|
|
|
|
cairo_set_line_join(c->cr, CAIRO_LINE_JOIN_MITER);
|
|
|
|
cairo_set_miter_limit(c->cr, p->MiterLimit);
|
|
|
|
break;
|
|
|
|
case uiDrawLineJoinRound:
|
|
|
|
cairo_set_line_join(c->cr, CAIRO_LINE_JOIN_ROUND);
|
|
|
|
break;
|
|
|
|
case uiDrawLineJoinBevel:
|
|
|
|
cairo_set_line_join(c->cr, CAIRO_LINE_JOIN_BEVEL);
|
|
|
|
break;
|
|
|
|
}
|
2015-09-10 22:54:54 -05:00
|
|
|
cairo_set_line_width(c->cr, p->Thickness);
|
2015-10-16 09:09:41 -05:00
|
|
|
cairo_set_dash(c->cr, p->Dashes, p->NumDashes, p->DashPhase);
|
2015-09-06 19:02:01 -05:00
|
|
|
cairo_stroke(c->cr);
|
2015-10-08 07:47:36 -05:00
|
|
|
cairo_pattern_destroy(pat);
|
2015-09-06 19:02:01 -05:00
|
|
|
}
|
2015-09-07 09:25:59 -05:00
|
|
|
|
2015-10-08 07:47:36 -05:00
|
|
|
void uiDrawFill(uiDrawContext *c, uiDrawPath *path, uiDrawBrush *b)
|
2015-09-07 09:25:59 -05:00
|
|
|
{
|
2015-10-08 07:47:36 -05:00
|
|
|
cairo_pattern_t *pat;
|
|
|
|
|
|
|
|
runPath(path, c->cr);
|
|
|
|
pat = mkbrush(b);
|
|
|
|
cairo_set_source(c->cr, pat);
|
2016-05-05 17:23:54 -05:00
|
|
|
switch (pathFillMode(path)) {
|
2015-09-07 09:25:59 -05:00
|
|
|
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_fill(c->cr);
|
2015-10-08 07:47:36 -05:00
|
|
|
cairo_pattern_destroy(pat);
|
2015-09-07 09:25:59 -05:00
|
|
|
}
|
2015-10-11 10:13:01 -05:00
|
|
|
|
2016-05-05 20:49:50 -05:00
|
|
|
void uiDrawTransform(uiDrawContext *c, uiDrawMatrix *m)
|
|
|
|
{
|
|
|
|
cairo_matrix_t cm;
|
|
|
|
|
|
|
|
m2c(m, &cm);
|
|
|
|
cairo_transform(c->cr, &cm);
|
|
|
|
}
|
|
|
|
|
2015-10-13 10:16:06 -05:00
|
|
|
void uiDrawClip(uiDrawContext *c, uiDrawPath *path)
|
|
|
|
{
|
|
|
|
runPath(path, c->cr);
|
2016-05-05 17:23:54 -05:00
|
|
|
switch (pathFillMode(path)) {
|
2015-10-13 10:16:06 -05:00
|
|
|
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);
|
|
|
|
}
|
2016-05-05 20:49:50 -05:00
|
|
|
|
|
|
|
void uiDrawSave(uiDrawContext *c)
|
|
|
|
{
|
|
|
|
cairo_save(c->cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiDrawRestore(uiDrawContext *c)
|
|
|
|
{
|
|
|
|
cairo_restore(c->cr);
|
|
|
|
}
|