aboutsummaryrefslogtreecommitdiff
path: root/canvas.lv2
diff options
context:
space:
mode:
Diffstat (limited to 'canvas.lv2')
-rw-r--r--canvas.lv2/canvas.h3
-rw-r--r--canvas.lv2/forge.h7
-rw-r--r--canvas.lv2/render.h41
3 files changed, 48 insertions, 3 deletions
diff --git a/canvas.lv2/canvas.h b/canvas.lv2/canvas.h
index 24f753e..d6ca8de 100644
--- a/canvas.lv2/canvas.h
+++ b/canvas.lv2/canvas.h
@@ -41,6 +41,7 @@ extern "C" {
#define CANVAS__LineTo CANVAS_PREFIX"LineTo"
#define CANVAS__MoveTo CANVAS_PREFIX"MoveTo"
#define CANVAS__Rectangle CANVAS_PREFIX"Rectangle"
+#define CANVAS__PolyLine CANVAS_PREFIX"PolyLine"
#define CANVAS__Style CANVAS_PREFIX"Style"
#define CANVAS__LineWidth CANVAS_PREFIX"LineWidth"
#define CANVAS__LineDash CANVAS_PREFIX"LineDash"
@@ -92,6 +93,7 @@ struct _LV2_Canvas_URID {
LV2_URID Canvas_LineTo;
LV2_URID Canvas_MoveTo;
LV2_URID Canvas_Rectangle;
+ LV2_URID Canvas_PolyLine;
LV2_URID Canvas_Style;
LV2_URID Canvas_LineWidth;
LV2_URID Canvas_LineDash;
@@ -144,6 +146,7 @@ lv2_canvas_urid_init(LV2_Canvas_URID *urid, LV2_URID_Map *map)
urid->Canvas_LineTo = map->map(map->handle, CANVAS__LineTo);
urid->Canvas_MoveTo = map->map(map->handle, CANVAS__MoveTo);
urid->Canvas_Rectangle = map->map(map->handle, CANVAS__Rectangle);
+ urid->Canvas_PolyLine = map->map(map->handle, CANVAS__PolyLine);
urid->Canvas_Style = map->map(map->handle, CANVAS__Style);
urid->Canvas_LineWidth = map->map(map->handle, CANVAS__LineWidth);
urid->Canvas_LineDash = map->map(map->handle, CANVAS__LineDash);
diff --git a/canvas.lv2/forge.h b/canvas.lv2/forge.h
index aa10720..43aa1d5 100644
--- a/canvas.lv2/forge.h
+++ b/canvas.lv2/forge.h
@@ -185,6 +185,13 @@ lv2_canvas_forge_rectangle(LV2_Atom_Forge *forge, LV2_Canvas_URID *urid,
}
static inline LV2_Atom_Forge_Ref
+lv2_canvas_forge_polyLine(LV2_Atom_Forge *forge, LV2_Canvas_URID *urid,
+ uint32_t n, const float *vec)
+{
+ return _lv2_canvas_forge_vec(forge, urid, urid->Canvas_PolyLine, n, vec);
+}
+
+static inline LV2_Atom_Forge_Ref
lv2_canvas_forge_style(LV2_Atom_Forge *forge, LV2_Canvas_URID *urid,
uint32_t style)
{
diff --git a/canvas.lv2/render.h b/canvas.lv2/render.h
index d3ee02d..50683e6 100644
--- a/canvas.lv2/render.h
+++ b/canvas.lv2/render.h
@@ -28,7 +28,7 @@
extern "C" {
#endif
-#define LV2_CANVAS_NUM_METHODS 24
+#define LV2_CANVAS_NUM_METHODS 25
typedef struct _LV2_Canvas_Meth LV2_Canvas_Meth;
typedef struct _LV2_Canvas LV2_Canvas;
@@ -46,16 +46,27 @@ struct _LV2_Canvas {
};
static inline const float *
-_lv2_canvas_render_get_float_vec(LV2_Canvas_URID *urid, const LV2_Atom *body, uint32_t N)
+_lv2_canvas_render_get_float_vecs(LV2_Canvas_URID *urid, const LV2_Atom *body,
+ uint32_t *n)
{
const LV2_Atom_Vector *vec = (const LV2_Atom_Vector *)body;
const float *flt = LV2_ATOM_CONTENTS_CONST(LV2_Atom_Vector, vec);
- const uint32_t n = (vec->atom.type == urid->forge.Vector)
+ *n = (vec->atom.type == urid->forge.Vector)
&& (vec->body.child_type == urid->forge.Float)
&& (vec->body.child_size == sizeof(float))
? (vec->atom.size - sizeof(LV2_Atom_Vector_Body)) / vec->body.child_size
: 0;
+ return flt;
+}
+
+static inline const float *
+_lv2_canvas_render_get_float_vec(LV2_Canvas_URID *urid, const LV2_Atom *body,
+ uint32_t n)
+{
+ uint32_t N;
+ const float *flt = _lv2_canvas_render_get_float_vecs(urid, body, &N);
+
return n == N ? flt : NULL;
}
@@ -142,6 +153,27 @@ _lv2_canvas_render_rectangle(cairo_t *ctx,
}
static inline void
+_lv2_canvas_render_polyline(cairo_t *ctx,
+ LV2_Canvas_URID *urid, const LV2_Atom *body)
+{
+ uint32_t N;
+ const float *v = _lv2_canvas_render_get_float_vecs(urid, body, &N);
+
+ if(v)
+ {
+ for(uint32_t i = 0; i < 2; i += 2)
+ {
+ cairo_move_to(ctx, v[i], v[i+1]);
+ }
+
+ for(uint32_t i = 2; i < N; i += 2)
+ {
+ cairo_line_to(ctx, v[i], v[i+1]);
+ }
+ }
+}
+
+static inline void
_lv2_canvas_render_style(cairo_t *ctx,
LV2_Canvas_URID *urid, const LV2_Atom *body)
{
@@ -420,6 +452,9 @@ lv2_canvas_init(LV2_Canvas *canvas, LV2_URID_Map *map)
canvas->methods[ptr].command = canvas->urid.Canvas_Rectangle;
canvas->methods[ptr++].func = _lv2_canvas_render_rectangle;
+ canvas->methods[ptr].command = canvas->urid.Canvas_PolyLine;
+ canvas->methods[ptr++].func = _lv2_canvas_render_polyline;
+
canvas->methods[ptr].command = canvas->urid.Canvas_Style;
canvas->methods[ptr++].func = _lv2_canvas_render_style;