aboutsummaryrefslogtreecommitdiff
path: root/canvas.lv2/canvas.lv2/forge.h
blob: c5ce5fe0355a9c4f20a92d849f6d34d03134931b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
/*
 * Copyright (c) 2016 Hanspeter Portner (dev@open-music-kontrollers.ch)
 *
 * This is free software: you can redistribute it and/or modify
 * it under the terms of the Artistic License 2.0 as published by
 * The Perl Foundation.
 *
 * This source is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * Artistic License 2.0 for more details.
 *
 * You should have received a copy of the Artistic License 2.0
 * along the source as a COPYING file. If not, obtain it from
 * http://www.perlfoundation.org/artistic_license_2_0.
 */

#ifndef _LV2_CANVAS_FORGE_H
#define _LV2_CANVAS_FORGE_H

#include <canvas.lv2/canvas.h>

#ifdef __cplusplus
extern "C" {
#endif

static inline LV2_Atom_Forge_Ref
_lv2_canvas_forge_simple(LV2_Atom_Forge *forge, LV2_URID otype)
{
	LV2_Atom_Forge_Ref ref;
	LV2_Atom_Forge_Frame frame;

	ref = lv2_atom_forge_object(forge, &frame, 0, otype);
	if(ref)
		lv2_atom_forge_pop(forge, &frame);

	return ref;
}

static inline LV2_Atom_Forge_Ref
_lv2_canvas_forge_vec(LV2_Atom_Forge *forge, LV2_Canvas_URID *urid,
	LV2_URID otype, uint32_t n, const float *vec)
{
	LV2_Atom_Forge_Ref ref;
	LV2_Atom_Forge_Frame frame;

	ref = lv2_atom_forge_object(forge, &frame, 0, otype);
	if(ref)
		ref = lv2_atom_forge_key(forge, urid->Canvas_body);
	if(ref)
		ref = lv2_atom_forge_vector(forge, sizeof(float), forge->Float, n, vec);
	if(ref)
		lv2_atom_forge_pop(forge, &frame);

	return ref;
}

static inline LV2_Atom_Forge_Ref
_lv2_canvas_forge_flt(LV2_Atom_Forge *forge, LV2_Canvas_URID *urid,
	LV2_URID otype, float flt)
{
	LV2_Atom_Forge_Ref ref;
	LV2_Atom_Forge_Frame frame;

	ref = lv2_atom_forge_object(forge, &frame, 0, otype);
	if(ref)
		ref = lv2_atom_forge_key(forge, urid->Canvas_body);
	if(ref)
		ref = lv2_atom_forge_float(forge, flt);
	if(ref)
		lv2_atom_forge_pop(forge, &frame);

	return ref;
}

static inline LV2_Atom_Forge_Ref
_lv2_canvas_forge_lng(LV2_Atom_Forge *forge, LV2_Canvas_URID *urid,
	LV2_URID otype, int64_t lng)
{
	LV2_Atom_Forge_Ref ref;
	LV2_Atom_Forge_Frame frame;

	ref = lv2_atom_forge_object(forge, &frame, 0, otype);
	if(ref)
		ref = lv2_atom_forge_key(forge, urid->Canvas_body);
	if(ref)
		ref = lv2_atom_forge_long(forge, lng);
	if(ref)
		lv2_atom_forge_pop(forge, &frame);

	return ref;
}

static inline LV2_Atom_Forge_Ref
_lv2_canvas_forge_prp(LV2_Atom_Forge *forge, LV2_Canvas_URID *urid,
	LV2_URID otype, LV2_URID prop)
{
	LV2_Atom_Forge_Ref ref;
	LV2_Atom_Forge_Frame frame;

	ref = lv2_atom_forge_object(forge, &frame, 0, otype);
	if(ref)
		ref = lv2_atom_forge_key(forge, urid->Canvas_body);
	if(ref)
		ref = lv2_atom_forge_urid(forge, prop);
	if(ref)
		lv2_atom_forge_pop(forge, &frame);

	return ref;
}

static inline LV2_Atom_Forge_Ref
_lv2_canvas_forge_str(LV2_Atom_Forge *forge, LV2_Canvas_URID *urid,
	LV2_URID otype, const char *text)
{
	LV2_Atom_Forge_Ref ref;
	LV2_Atom_Forge_Frame frame;

	ref = lv2_atom_forge_object(forge, &frame, 0, otype);
	if(ref)
		ref = lv2_atom_forge_key(forge, urid->Canvas_body);
	if(ref)
		ref = lv2_atom_forge_string(forge, text, strlen(text));
	if(ref)
		lv2_atom_forge_pop(forge, &frame);

	return ref;
}

static inline LV2_Atom_Forge_Ref
lv2_canvas_forge_beginPath(LV2_Atom_Forge *forge, LV2_Canvas_URID *urid)
{
	return _lv2_canvas_forge_simple(forge, urid->Canvas_BeginPath);
}

static inline LV2_Atom_Forge_Ref
lv2_canvas_forge_closePath(LV2_Atom_Forge *forge, LV2_Canvas_URID *urid)
{
	return _lv2_canvas_forge_simple(forge, urid->Canvas_ClosePath);
}

static inline LV2_Atom_Forge_Ref
lv2_canvas_forge_arc(LV2_Atom_Forge *forge, LV2_Canvas_URID *urid,
	float x, float y, float r, float a1, float a2)
{
	const float vec [5] = {x, y, r, a1, a2};

	return _lv2_canvas_forge_vec(forge, urid, urid->Canvas_Arc, 5, vec);
}

static inline LV2_Atom_Forge_Ref
lv2_canvas_forge_curveTo(LV2_Atom_Forge *forge, LV2_Canvas_URID *urid,
	float x1, float y1, float x2, float y2, float x3, float y3)
{
	const float vec [6] = {x1, y1, x2, y2, x3, y3};

	return _lv2_canvas_forge_vec(forge, urid, urid->Canvas_CurveTo, 6, vec);
}

static inline LV2_Atom_Forge_Ref
lv2_canvas_forge_lineTo(LV2_Atom_Forge *forge, LV2_Canvas_URID *urid,
	float x, float y)
{
	const float vec [2] = {x, y};

	return _lv2_canvas_forge_vec(forge, urid, urid->Canvas_LineTo, 2, vec);
}

static inline LV2_Atom_Forge_Ref
lv2_canvas_forge_moveTo(LV2_Atom_Forge *forge, LV2_Canvas_URID *urid,
	float x, float y)
{
	const float vec [2] = {x, y};

	return _lv2_canvas_forge_vec(forge, urid, urid->Canvas_MoveTo, 2, vec);
}

static inline LV2_Atom_Forge_Ref
lv2_canvas_forge_rectangle(LV2_Atom_Forge *forge, LV2_Canvas_URID *urid,
	float x, float y, float w, float h)
{
	const float vec [4] = {x, y, w, h};

	return _lv2_canvas_forge_vec(forge, urid, urid->Canvas_Rectangle, 4, vec);
}

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)
{
	return _lv2_canvas_forge_lng(forge, urid, urid->Canvas_Style, style);
}

static inline LV2_Atom_Forge_Ref
lv2_canvas_forge_lineWidth(LV2_Atom_Forge *forge, LV2_Canvas_URID *urid,
	float line_width)
{
	return _lv2_canvas_forge_flt(forge, urid, urid->Canvas_LineWidth, line_width);
}

static inline LV2_Atom_Forge_Ref
lv2_canvas_forge_lineDash(LV2_Atom_Forge *forge, LV2_Canvas_URID *urid,
	float dash_length, float separator_length)
{
	const float vec [2] = {dash_length, separator_length};

	return _lv2_canvas_forge_vec(forge, urid, urid->Canvas_LineDash, 2, vec);
}

static inline LV2_Atom_Forge_Ref
lv2_canvas_forge_lineCap(LV2_Atom_Forge *forge, LV2_Canvas_URID *urid,
	LV2_URID line_cap)
{
	return _lv2_canvas_forge_prp(forge, urid, urid->Canvas_LineCap, line_cap);
}

static inline LV2_Atom_Forge_Ref
lv2_canvas_forge_lineJoin(LV2_Atom_Forge *forge, LV2_Canvas_URID *urid,
	LV2_URID line_join)
{
	return _lv2_canvas_forge_prp(forge, urid, urid->Canvas_LineJoin, line_join);
}

static inline LV2_Atom_Forge_Ref
lv2_canvas_forge_miterLimit(LV2_Atom_Forge *forge, LV2_Canvas_URID *urid,
	float miter_limit)
{
	return _lv2_canvas_forge_flt(forge, urid, urid->Canvas_MiterLimit, miter_limit);
}

static inline LV2_Atom_Forge_Ref
lv2_canvas_forge_stroke(LV2_Atom_Forge *forge, LV2_Canvas_URID *urid)
{
	return _lv2_canvas_forge_simple(forge, urid->Canvas_Stroke);
}

static inline LV2_Atom_Forge_Ref
lv2_canvas_forge_fill(LV2_Atom_Forge *forge, LV2_Canvas_URID *urid)
{
	return _lv2_canvas_forge_simple(forge, urid->Canvas_Fill);
}

static inline LV2_Atom_Forge_Ref
lv2_canvas_forge_clip(LV2_Atom_Forge *forge, LV2_Canvas_URID *urid)
{
	return _lv2_canvas_forge_simple(forge, urid->Canvas_Clip);
}

static inline LV2_Atom_Forge_Ref
lv2_canvas_forge_save(LV2_Atom_Forge *forge, LV2_Canvas_URID *urid)
{
	return _lv2_canvas_forge_simple(forge, urid->Canvas_Save);
}

static inline LV2_Atom_Forge_Ref
lv2_canvas_forge_restore(LV2_Atom_Forge *forge, LV2_Canvas_URID *urid)
{
	return _lv2_canvas_forge_simple(forge, urid->Canvas_Restore);
}

static inline LV2_Atom_Forge_Ref
lv2_canvas_forge_translate(LV2_Atom_Forge *forge, LV2_Canvas_URID *urid,
	float x, float y)
{
	const float vec [2] = {x, y};

	return _lv2_canvas_forge_vec(forge, urid, urid->Canvas_Translate, 2, vec);
}

static inline LV2_Atom_Forge_Ref
lv2_canvas_forge_scale(LV2_Atom_Forge *forge, LV2_Canvas_URID *urid,
	float w, float h)
{
	const float vec [2] = {w, h};

	return _lv2_canvas_forge_vec(forge, urid, urid->Canvas_Scale, 2, vec);
}

static inline LV2_Atom_Forge_Ref
lv2_canvas_forge_rotate(LV2_Atom_Forge *forge, LV2_Canvas_URID *urid,
	float a)
{
	return _lv2_canvas_forge_flt(forge, urid, urid->Canvas_Rotate, a);
}

static inline LV2_Atom_Forge_Ref
lv2_canvas_forge_transform(LV2_Atom_Forge *forge, LV2_Canvas_URID *urid,
	float xx, float xy, float x0, float yy, float yx, float y0)
{
	const float vec [6] = {xx, xy, x0, yy, yx, y0};

	return _lv2_canvas_forge_vec(forge, urid, urid->Canvas_Transform, 6, vec);
}

static inline LV2_Atom_Forge_Ref
lv2_canvas_forge_reset(LV2_Atom_Forge *forge, LV2_Canvas_URID *urid)
{
	return _lv2_canvas_forge_simple(forge, urid->Canvas_Reset);
}

static inline LV2_Atom_Forge_Ref
lv2_canvas_forge_fontSize(LV2_Atom_Forge *forge, LV2_Canvas_URID *urid,
	float size)
{
	return _lv2_canvas_forge_flt(forge, urid, urid->Canvas_FontSize, size);
}

static inline LV2_Atom_Forge_Ref
lv2_canvas_forge_fillText(LV2_Atom_Forge *forge, LV2_Canvas_URID *urid,
	const char *text)
{
	return _lv2_canvas_forge_str(forge, urid, urid->Canvas_FillText, text);
}

#ifdef __cplusplus
}
#endif

#endif // _LV2_CANVAS_FORGE_H