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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]

#[macro_use]
extern crate bitflags;

use std::os::raw::{c_char, c_uchar, c_int, c_float, c_void};

pub const FONS_INVALID: c_int = -1;

pub type NVGcontext = c_void;

// No reason to use a union here, since the nanovg guys
// only used it for convenience.
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct NVGcolor {
    pub rgba: [c_float; 4],
}

#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct NVGpaint {
    pub xform: [c_float; 6],
    pub extent: [c_float; 2],
    pub radius: c_float,
    pub feather: c_float,
    pub innerColor: NVGcolor,
    pub outerColor: NVGcolor,
    pub image: c_int,
}

bitflags! {
	pub struct NVGwinding: c_int {
		const NVG_CCW = 1;
		const NVG_CW = 2;
	}
}

bitflags! {
	pub struct NVGsolidity: c_int {
		const NVG_SOLID = 1;
		const NVG_HOLE = 2;
	}
}

bitflags! {
	pub struct NVGalign: c_int {
		const NVG_ALIGN_LEFT = 1 << 0;
		const NVG_ALIGN_CENTER = 1 << 1;
		const NVG_ALIGN_RIGHT = 1 << 2;
		const NVG_ALIGN_TOP = 1 << 3;
		const NVG_ALIGN_MIDDLE = 1 << 4;
		const NVG_ALIGN_BOTTOM = 1 << 5;
		const NVG_ALIGN_BASELINE = 1 << 6;
	}
}

bitflags! {
	pub struct NVGblendFactor: c_int {
		const NVG_ZERO = 1<<0;
		const NVG_ONE = 1<<1;
		const NVG_SRC_COLOR = 1<<2;
		const NVG_ONE_MINUS_SRC_COLOR = 1<<3;
		const NVG_DST_COLOR = 1<<4;
		const NVG_ONE_MINUS_DST_COLOR = 1<<5;
		const NVG_SRC_ALPHA = 1<<6;
		const NVG_ONE_MINUS_SRC_ALPHA = 1<<7;
		const NVG_DST_ALPHA = 1<<8;
		const NVG_ONE_MINUS_DST_ALPHA = 1<<9;
		const NVG_SRC_ALPHA_SATURATE = 1<<10;
	}
}

bitflags! {
	pub struct NVGimageFlags: c_int {
		const NVG_IMAGE_GENERATE_MIPMAPS = 1 << 0;
		const NVG_IMAGE_REPEATX = 1 << 1;
		const NVG_IMAGE_REPEATY = 1 << 2;
		const NVG_IMAGE_FLIPY = 1 << 3;
		const NVG_IMAGE_PREMULTIPLIED = 1 << 4;
		const NVG_IMAGE_NEAREST = 1 << 5;
	}
}

bitflags! {
	// #[cfg(any(feature = "gl2", feature = "gl3", feature = "gles2", feature = "gles3"))]
	pub struct NVGcreateFlags: c_int {
		const NVG_ANTIALIAS = 1 << 0;
		const NVG_STENCIL_STROKES = 1 << 1;
		const NVG_DEBUG = 1 << 2;
	}
}

#[repr(C)]
#[derive(Debug)]
pub enum NVGlineCap {
    NVG_BUTT,
    NVG_ROUND,
    NVG_SQUARE,
    NVG_BEVEL,
    NVG_MITER,
}

#[repr(C)]
#[derive(Debug)]
pub enum NVGcompositeOperation {
    NVG_SOURCE_OVER,
    NVG_SOURCE_IN,
    NVG_SOURCE_OUT,
    NVG_ATOP,
    NVG_DESTINATION_OVER,
    NVG_DESTINATION_IN,
    NVG_DESTINATION_OUT,
    NVG_DESTINATION_ATOP,
    NVG_LIGHTER,
    NVG_COPY,
    NVG_XOR,
}

#[repr(C)]
#[derive(Debug)]
pub struct NVGcompositeOperationState {
    pub srcRGB: c_int,
    pub dstRGB: c_int,
    pub srcAlpha: c_int,
    pub dstAlpha: c_int,
}

#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct NVGglyphPosition {
    pub s: *const c_char,
    pub x: c_float,
    pub minx: c_float,
    pub maxx: c_float,
}

#[repr(C)]
#[derive(Debug)]
pub struct NVGtextRow {
    pub start: *const c_char,
    pub end: *const c_char,
    pub next: *const c_char,
    pub width: c_float,
    pub minx: c_float,
    pub maxx: c_float,
}

extern "C" {
	#[cfg(target_os = "windows")]
    pub fn gladLoadGL() -> i32;
    pub fn nvgBeginFrame(
        ctx: *mut NVGcontext,
        windowWidth: c_float,
        windowHeight: c_float,
        devicePixelRatio: c_float,
    );
    pub fn nvgCancelFrame(ctx: *mut NVGcontext);
    pub fn nvgEndFrame(ctx: *mut NVGcontext);
    pub fn nvgGlobalCompositeOperation(ctx: *mut NVGcontext, op: c_int);
    pub fn nvgGlobalCompositeBlendFunc(ctx: *mut NVGcontext, sfactor: c_int, dfactor: c_int);
    pub fn nvgGlobalCompositeBlendFuncSeparate(
        ctx: *mut NVGcontext,
        srcRGB: c_int,
        dstRGB: c_int,
        srcAlpha: c_int,
        dstAlpha: c_int,
    );
    pub fn nvgRGB(r: c_uchar, g: c_uchar, b: c_uchar) -> NVGcolor;
    pub fn nvgRGBf(r: c_float, g: c_float, b: c_float) -> NVGcolor;
    pub fn nvgRGBA(r: c_uchar, g: c_uchar, b: c_uchar, a: c_uchar) -> NVGcolor;
    pub fn nvgRGBAf(r: c_float, g: c_float, b: c_float, a: c_float) -> NVGcolor;
    pub fn nvgLerpRGBA(c0: NVGcolor, c1: NVGcolor, u: c_float) -> NVGcolor;
    pub fn nvgTransRGBA(c0: NVGcolor, a: c_uchar) -> NVGcolor;
    pub fn nvgTransRGBAf(c0: NVGcolor, a: c_float) -> NVGcolor;
    pub fn nvgHSL(h: c_float, s: c_float, l: c_float) -> NVGcolor;
    pub fn nvgHSLA(h: c_float, s: c_float, l: c_float, a: c_uchar) -> NVGcolor;
    pub fn nvgSave(ctx: *mut NVGcontext);
    pub fn nvgRestore(ctx: *mut NVGcontext);
    pub fn nvgReset(ctx: *mut NVGcontext);
    pub fn nvgShapeAntiAlias(ctx: *mut NVGcontext, enabled: c_int);
    pub fn nvgStrokeColor(ctx: *mut NVGcontext, color: NVGcolor);
    pub fn nvgStrokePaint(ctx: *mut NVGcontext, paint: NVGpaint);
    pub fn nvgFillColor(ctx: *mut NVGcontext, color: NVGcolor);
    pub fn nvgFillPaint(ctx: *mut NVGcontext, paint: NVGpaint);
    pub fn nvgMiterLimit(ctx: *mut NVGcontext, limit: c_float);
    pub fn nvgStrokeWidth(ctx: *mut NVGcontext, size: c_float);
    pub fn nvgLineCap(ctx: *mut NVGcontext, cap: c_int);
    pub fn nvgLineJoin(ctx: *mut NVGcontext, join: c_int);
    pub fn nvgGlobalAlpha(ctx: *mut NVGcontext, alpha: c_float);
    pub fn nvgResetTransform(ctx: *mut NVGcontext);
    pub fn nvgTransform(
        ctx: *mut NVGcontext,
        a: c_float,
        b: c_float,
        c: c_float,
        d: c_float,
        e: c_float,
        f: c_float,
    );
    pub fn nvgTranslate(ctx: *mut NVGcontext, x: c_float, y: c_float);
    pub fn nvgRotate(ctx: *mut NVGcontext, angle: c_float);
    pub fn nvgSkewX(ctx: *mut NVGcontext, angle: c_float);
    pub fn nvgSkewY(ctx: *mut NVGcontext, angle: c_float);
    pub fn nvgScale(ctx: *mut NVGcontext, x: c_float, y: c_float);
    pub fn nvgCurrentTransform(ctx: *mut NVGcontext, xform: *mut c_float);
    pub fn nvgTransformIdentity(dst: *mut c_float);
    pub fn nvgTransformTranslate(dst: *mut c_float, tx: c_float, ty: c_float);
    pub fn nvgTransformScale(dst: *mut c_float, sx: c_float, sy: c_float);
    pub fn nvgTransformRotate(dst: *mut c_float, a: c_float);
    pub fn nvgTransformSkewX(dst: *mut c_float, a: c_float);
    pub fn nvgTransformSkewY(dst: *mut c_float, a: c_float);
    pub fn nvgTransformMultiply(dst: *mut c_float, src: *const c_float);
    pub fn nvgTransformPremultiply(dst: *mut c_float, src: *const c_float);
    pub fn nvgTransformInverse(dst: *mut c_float, src: *const c_float) -> c_int;
    pub fn nvgTransformPoint(
        dstx: *mut c_float,
        dsty: *mut c_float,
        xform: *const c_float,
        srcx: c_float,
        srcy: c_float,
    );
    // Degrees <-> radians conversion functions are not exported. Use the rust builtins instead.
    pub fn nvgCreateImage(
        ctx: *mut NVGcontext,
        filename: *const c_char,
        imageFlags: c_int,
    ) -> c_int;
    pub fn nvgCreateImageMem(
        ctx: *mut NVGcontext,
        imageFlags: c_int,
        data: *mut c_uchar,
        ndata: c_int,
    ) -> c_int;
    pub fn nvgCreateImageRGBA(
        ctx: *mut NVGcontext,
        w: c_int,
        h: c_int,
        imageFlags: c_int,
        data: *const c_uchar,
    ) -> c_int;
    pub fn nvgUpdateImage(ctx: *mut NVGcontext, image: c_int, data: *const c_uchar);
    pub fn nvgImageSize(ctx: *mut NVGcontext, image: c_int, w: *mut c_int, h: *mut c_int);
    pub fn nvgDeleteImage(ctx: *mut NVGcontext, image: c_int);
    pub fn nvgLinearGradient(
        ctx: *mut NVGcontext,
        sx: c_float,
        sy: c_float,
        ex: c_float,
        ey: c_float,
        icol: NVGcolor,
        ocol: NVGcolor,
    ) -> NVGpaint;
    pub fn nvgBoxGradient(
        ctx: *mut NVGcontext,
        x: c_float,
        y: c_float,
        w: c_float,
        h: c_float,
        r: c_float,
        f: c_float,
        icol: NVGcolor,
        ocol: NVGcolor,
    ) -> NVGpaint;
    pub fn nvgRadialGradient(
        ctx: *mut NVGcontext,
        cx: c_float,
        cy: c_float,
        inr: c_float,
        outr: c_float,
        icol: NVGcolor,
        ocol: NVGcolor,
    ) -> NVGpaint;
    pub fn nvgImagePattern(
        ctx: *mut NVGcontext,
        ox: c_float,
        oy: c_float,
        ex: c_float,
        ey: c_float,
        angle: c_float,
        image: c_int,
        alpha: c_float,
    ) -> NVGpaint;
    pub fn nvgScissor(ctx: *mut NVGcontext, x: c_float, y: c_float, w: c_float, h: c_float);
    pub fn nvgIntersectScissor(
        ctx: *mut NVGcontext,
        x: c_float,
        y: c_float,
        w: c_float,
        h: c_float,
    );
    pub fn nvgResetScissor(ctx: *mut NVGcontext);
    pub fn nvgBeginPath(ctx: *mut NVGcontext);
    pub fn nvgMoveTo(ctx: *mut NVGcontext, x: c_float, y: c_float);
    pub fn nvgLineTo(ctx: *mut NVGcontext, x: c_float, y: c_float);
    pub fn nvgBezierTo(
        ctx: *mut NVGcontext,
        c1x: c_float,
        c1y: c_float,
        c2x: c_float,
        c2y: c_float,
        x: c_float,
        y: c_float,
    );
    pub fn nvgQuadTo(ctx: *mut NVGcontext, cx: c_float, cy: c_float, x: c_float, y: c_float);
    pub fn nvgArcTo(
        ctx: *mut NVGcontext,
        x1: c_float,
        y1: c_float,
        x2: c_float,
        y2: c_float,
        radius: c_float,
    );
    pub fn nvgClosePath(ctx: *mut NVGcontext);
    pub fn nvgPathWinding(ctx: *mut NVGcontext, dir: c_int);
    pub fn nvgArc(
        ctx: *mut NVGcontext,
        cx: c_float,
        cy: c_float,
        r: c_float,
        a0: c_float,
        a1: c_float,
        dir: c_int,
    );
    pub fn nvgRect(ctx: *mut NVGcontext, x: c_float, y: c_float, w: c_float, h: c_float);
    pub fn nvgRoundedRect(
        ctx: *mut NVGcontext,
        x: c_float,
        y: c_float,
        w: c_float,
        h: c_float,
        r: c_float,
    );
    pub fn nvgRoundedRectVarying(
        ctx: *mut NVGcontext,
        x: c_float,
        y: c_float,
        w: c_float,
        h: c_float,
        radTopLeft: c_float,
        radTopRight: c_float,
        radBottomRight: c_float,
        radBottomLeft: c_float,
    );
    pub fn nvgEllipse(ctx: *mut NVGcontext, cx: c_float, cy: c_float, rx: c_float, ry: c_float);
    pub fn nvgCircle(ctx: *mut NVGcontext, cx: c_float, cy: c_float, r: c_float);
    pub fn nvgFill(ctx: *mut NVGcontext);
    pub fn nvgStroke(ctx: *mut NVGcontext);
    pub fn nvgCreateFont(
        ctx: *mut NVGcontext,
        name: *const c_char,
        filename: *const c_char,
    ) -> c_int;
    pub fn nvgCreateFontMem(
        ctx: *mut NVGcontext,
        name: *const c_char,
        data: *mut c_uchar,
        ndata: c_int,
        freeData: c_int,
    ) -> c_int;
    pub fn nvgFindFont(ctx: *mut NVGcontext, name: *const c_char) -> c_int;
    pub fn nvgAddFallbackFontId(
        ctx: *mut NVGcontext,
        baseFont: c_int,
        fallbackFont: c_int,
    ) -> c_int;
    pub fn nvgAddFallbackFont(
        ctx: *mut NVGcontext,
        baseFont: *const c_char,
        fallbackFont: *const c_char,
    ) -> c_int;
    pub fn nvgFontSize(ctx: *mut NVGcontext, size: c_float);
    pub fn nvgFontBlur(ctx: *mut NVGcontext, blur: c_float);
    pub fn nvgTextLetterSpacing(ctx: *mut NVGcontext, spacing: c_float);
    pub fn nvgTextLineHeight(ctx: *mut NVGcontext, lineHeight: c_float);
    pub fn nvgTextAlign(ctx: *mut NVGcontext, align: c_int);
    pub fn nvgFontFaceId(ctx: *mut NVGcontext, font: c_int);
    pub fn nvgFontFace(ctx: *mut NVGcontext, font: *const c_char);
    pub fn nvgText(
        ctx: *mut NVGcontext,
        x: c_float,
        y: c_float,
        string: *const c_char,
        end: *const c_char,
    ) -> c_float;
    pub fn nvgTextBox(
        ctx: *mut NVGcontext,
        x: c_float,
        y: c_float,
        breakRowWidth: c_float,
        string: *const c_char,
        end: *const c_char,
    );
    pub fn nvgTextBounds(
        ctx: *mut NVGcontext,
        x: c_float,
        y: c_float,
        string: *const c_char,
        end: *const c_char,
        bounds: *mut c_float,
    ) -> c_float;
    pub fn nvgTextBoxBounds(
        ctx: *mut NVGcontext,
        x: c_float,
        y: c_float,
        breakRowWidth: c_float,
        string: *const c_char,
        end: *const c_char,
        bounds: *mut c_float,
    );
    pub fn nvgTextGlyphPositions(
        ctx: *mut NVGcontext,
        x: c_float,
        y: c_float,
        string: *const c_char,
        end: *const c_char,
        positions: *mut NVGglyphPosition,
        maxPositions: c_int,
    ) -> c_int;
    pub fn nvgTextMetrics(
        ctx: *mut NVGcontext,
        ascender: *mut c_float,
        descender: *mut c_float,
        lineh: *mut c_float,
    );
    pub fn nvgTextBreakLines(
        ctx: *mut NVGcontext,
        string: *const c_char,
        end: *const c_char,
        breakRowWidth: c_float,
        rows: *mut NVGtextRow,
        maxRows: c_int,
    ) -> c_int;
	#[cfg(feature = "gl2")]
    pub fn nvgCreateGL2(flags: c_int) -> *mut NVGcontext;
	#[cfg(feature = "gl2")]
    pub fn nvgDeleteGL2(ctx: *mut NVGcontext);
	#[cfg(feature = "gl3")]
    pub fn nvgCreateGL3(flags: c_int) -> *mut NVGcontext;
	#[cfg(feature = "gl3")]
    pub fn nvgDeleteGL3(ctx: *mut NVGcontext);
	#[cfg(feature = "gles2")]
    pub fn nvgCreateGLES2(flags: c_int) -> *mut NVGcontext;
	#[cfg(feature = "gles2")]
    pub fn nvgDeleteGLES2(ctx: *mut NVGcontext);
	#[cfg(feature = "gles3")]
    pub fn nvgCreateGLES3(flags: c_int) -> *mut NVGcontext;
	#[cfg(feature = "gles3")]
    pub fn nvgDeleteGLES3(ctx: *mut NVGcontext);
}