More drawing API work.

This commit is contained in:
Pietro Gagliardi 2015-09-06 22:48:25 -04:00
parent c8384f4579
commit 917a0b17e2
3 changed files with 35 additions and 11 deletions

View File

@ -36,6 +36,12 @@ void uiDrawLineTo(uiDrawContext *c, intmax_t x, intmax_t y)
cairo_line_to(c->cr, (double) x + 0.5, (double) y + 0.5);
}
void uiDrawCloseFigure(uiDrawContext *c)
{
prepPath(c);
cairo_close_path(c->cr);
}
#define R(c) (((c) >> 16) & 0xFF)
#define G(c) (((c) >> 8) & 0xFF)
#define B(c) ((c) & 0xFF)
@ -69,7 +75,8 @@ void uiDrawStroke(uiDrawContext *c, uiDrawStrokeParams *p)
cairo_set_line_join(c->cr, CAIRO_LINE_JOIN_BEVEL);
break;
}
cairo_set_line_width(c->cr, p->Thickness);
// TODO comment the /2 here
cairo_set_line_width(c->cr, ((double) p->Thickness) / 2);
cairo_stroke(c->cr);
c->hasPath = FALSE;
}

View File

@ -22,16 +22,18 @@ static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *p)
sp.Cap = uiDrawLineCapFlat;
sp.Join = uiDrawLineJoinMiter;
sp.Thickness = 1;
sp.MiterLimit = 10;
sp.MiterLimit = uiDrawDefaultMiterLimit;
uiDrawStroke(p->Context, &sp);
uiDrawMoveTo(p->Context, p->ClipX, p->ClipY);
uiDrawLineTo(p->Context, p->ClipX + p->ClipWidth, p->ClipY);
uiDrawLineTo(p->Context, 50, 150);
uiDrawLineTo(p->Context, 50, 50);
uiDrawCloseFigure(p->Context);
sp.RGB = 0x000080;
sp.Cap = uiDrawLineCapFlat;
sp.Join = uiDrawLineJoinMiter;
sp.Thickness = 1;
sp.MiterLimit = 10;
sp.Join = uiDrawLineJoinRound;
sp.Thickness = 5;
uiDrawStroke(p->Context, &sp);
}

View File

@ -30,16 +30,14 @@ struct uiAreaDrawParams {
intmax_t VScrollPos;
};
// TODO default miter limit?
// cairo - 10.0
// GDI - ?
// Core Graphics - ?
// TODO proper sources
// TODO dotting/dashing
typedef struct uiDrawStrokeParams uiDrawStrokeParams;
typedef struct uiDrawFillParams uiDrawFillParams;
typedef enum uiDrawLineCap uiDrawLineCap;
typedef enum uiDrawLineJoin uiDrawLineJoin;
typedef enum uiDrawFillMode uiDrawFillMode;
typedef uint32_t uiRGB;
@ -55,14 +53,31 @@ enum uiDrawLineJoin {
uiDrawLineJoinBevel,
};
// this is the default for botoh cairo and GDI
// Core Graphics doesn't explicitly specify a default, but NSBezierPath allows you to choose one, and this is the initial value
// so we're good to use it too!
#define uiDrawDefaultMiterLimit 10.0
enum uiDrawFillMode {
uiDrawFillModeWinding,
uiDrawFillModeAlternate,
};
struct uiDrawStrokeParams {
uiRGB RGB;
uiDrawLineCap Cap;
uiDrawLineJoin Join;
intmax_t Thickness;
intmax_t MiterLimit;
// TODO float for GDI?
double MiterLimit;
};
struct uiDrawFillParams {
uiRGB RGB;
uiDrawFillMode FillMode;
};
void uiDrawMoveTo(uiDrawContext *, intmax_t, intmax_t);
void uiDrawLineTo(uiDrawContext *, intmax_t, intmax_t);
void uiDrawCloseFigure(uiDrawContext *);
void uiDrawStroke(uiDrawContext *, uiDrawStrokeParams *);