aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Hanspeter Portner <dev@open-music-kontrollers.ch>2018-04-03 09:23:02 +0200
committerGravatar Hanspeter Portner <dev@open-music-kontrollers.ch>2018-04-03 09:23:02 +0200
commit0bd71bd43b83748f3f645089b466969568423b6b (patch)
tree1b050c84f2326eddc9b7865d56e81b4a2a7021d6
parent0f2dae056ca94b79813c51f16e33840f5d425b49 (diff)
downloadcanvas.lv2-0bd71bd43b83748f3f645089b466969568423b6b.zip
canvas.lv2-0bd71bd43b83748f3f645089b466969568423b6b.tar.gz
canvas.lv2-0bd71bd43b83748f3f645089b466969568423b6b.tar.bz2
canvas.lv2-0bd71bd43b83748f3f645089b466969568423b6b.tar.xz
add canvas:polyLine instruction.
-rw-r--r--VERSION2
-rw-r--r--canvas.lv2/canvas.h3
-rw-r--r--canvas.lv2/forge.h7
-rw-r--r--canvas.lv2/render.h41
-rw-r--r--test/canvas.c42
5 files changed, 75 insertions, 20 deletions
diff --git a/VERSION b/VERSION
index dfdc368..a1dad2a 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.3.21
+0.3.23
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;
diff --git a/test/canvas.c b/test/canvas.c
index 730549f..fddd551 100644
--- a/test/canvas.c
+++ b/test/canvas.c
@@ -94,32 +94,42 @@ _unlock(atomic_flag *lock)
atomic_flag_clear_explicit(lock, memory_order_release);
}
+static const float lv2_L [] = {
+ 0.05, 0.275,
+ 0.05, 0.73463521816969,
+ 0.39996786383766, 0.73463521816969,
+ 0.35805418792799, 0.61981755929103,
+ 0.16950515672412, 0.61981755929103,
+ 0.16950515672412, 0.275,
+ 0.05, 0.275
+};
+
+static const float lv2_V [] = {
+ 0.44035674587458, 0.73463521816969,
+ 0.27321237521861, 0.275,
+ 0.39612954205777, 0.275,
+ 0.5215250619933, 0.61980400005209,
+ 0.64678627651808, 0.275,
+ 0.76999411666921, 0.275,
+ 0.60269884777111, 0.73463521816969,
+ 0.44035674587458, 0.73463521816969
+};
+
static inline LV2_Atom_Forge_Ref
_lv2_logo_forge(LV2_Atom_Forge *forge, LV2_Canvas_URID *urid)
{
const uint32_t fg = 0xbb6600ff;
LV2_Atom_Forge_Ref ref;
-
+
if( (ref = lv2_canvas_forge_beginPath(forge, urid))
- && (ref = lv2_canvas_forge_moveTo(forge, urid, 0.05, 0.275))
- && (ref = lv2_canvas_forge_lineTo(forge, urid, 0.05, 0.73463521816969))
- && (ref = lv2_canvas_forge_lineTo(forge, urid, 0.39996786383766, 0.73463521816969))
- && (ref = lv2_canvas_forge_lineTo(forge, urid, 0.35805418792799, 0.61981755929103))
- && (ref = lv2_canvas_forge_lineTo(forge, urid, 0.16950515672412, 0.61981755929103))
- && (ref = lv2_canvas_forge_lineTo(forge, urid, 0.16950515672412, 0.275))
- && (ref = lv2_canvas_forge_lineTo(forge, urid, 0.05, 0.275))
+ && (ref = lv2_canvas_forge_polyLine(forge, urid, sizeof(lv2_L)/sizeof(float), lv2_L))
+ && (ref = lv2_canvas_forge_closePath(forge, urid))
&& (ref = lv2_canvas_forge_style(forge, urid, fg))
&& (ref = lv2_canvas_forge_stroke(forge, urid))
&& (ref = lv2_canvas_forge_beginPath(forge, urid))
- && (ref = lv2_canvas_forge_moveTo(forge, urid, 0.44035674587458, 0.73463521816969))
- && (ref = lv2_canvas_forge_lineTo(forge, urid, 0.27321237521861, 0.275))
- && (ref = lv2_canvas_forge_lineTo(forge, urid, 0.39612954205777, 0.275))
- && (ref = lv2_canvas_forge_lineTo(forge, urid, 0.5215250619933, 0.61980400005209))
- && (ref = lv2_canvas_forge_lineTo(forge, urid, 0.64678627651808, 0.275))
- && (ref = lv2_canvas_forge_lineTo(forge, urid, 0.76999411666921, 0.275))
- && (ref = lv2_canvas_forge_lineTo(forge, urid, 0.60269884777111, 0.73463521816969))
- && (ref = lv2_canvas_forge_lineTo(forge, urid, 0.44035674587458, 0.73463521816969))
+ && (ref = lv2_canvas_forge_polyLine(forge, urid, sizeof(lv2_L)/sizeof(float), lv2_V))
+ && (ref = lv2_canvas_forge_closePath(forge, urid))
&& (ref = lv2_canvas_forge_style(forge, urid, fg))
&& (ref = lv2_canvas_forge_stroke(forge, urid))