-
Notifications
You must be signed in to change notification settings - Fork 0
/
jaggies.h
107 lines (78 loc) · 2.09 KB
/
jaggies.h
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
/*
Jaggies - a tiny vector graphics library
Example use:
void setPixel(void* context, char color) {
SomeBitmap* bmp = (SomeBitmap*) context;
...
}
SomeBitmap *bmp = createBitmapSomehow();
// Clear the global scene..
jaggieClear();
jaggiePoint square[] = {
{4, 0}, // 4 points follow
{10, 10},
{100, 10},
{100, 100},
{10, 100}
};
// ..add a polygon..
jaggiePoly(square);
// ..and render!
jaggieRender(150, 150, 0, setPixel, bmp);
*/
#ifndef JAGGIE_INT
#define JAGGIE_INT short
#endif
#ifndef JAGGIE_COLOR
#define JAGGIE_COLOR unsigned char
#endif
#ifndef JAGGIE_MAX_POLYS
#define JAGGIE_MAX_POLYS 16
#endif
#ifndef JAGGIE_MAX_LINES
#define JAGGIE_MAX_LINES (JAGGIE_MAX_POLYS*3)
#endif
/*
Point type
*/
typedef struct Point {
JAGGIE_INT x, y;
} jaggiePoint;
/*
Adds a polygon to the render state.
Polygons are described by a list of points
prefixed with a (count, last) point.
Polygons are automatically closed, there is no need
to repeat the first point.
Multiple sections can optionally be added to the same
polygon by setting last=0 in the prefix point.
This can be used to cut a hole in a polygon.
Returns zero on failure.
*/
JAGGIE_INT jaggiePoly(jaggiePoint* points);
/*
Adds a line to the render state.
The start and end pixels are included in the line drawn.
Returns zero on failure.
*/
JAGGIE_INT jaggieLine(JAGGIE_INT x1, JAGGIE_INT y1, JAGGIE_INT x2, JAGGIE_INT y2);
/*
Sets the render state color.
*/
void jaggieColor(JAGGIE_COLOR color);
/*
Clears the render state
*/
void jaggieClear();
/*
Pixel setter callback.
Will always be called sequentially, row by row, from top to bottom,
to cover the whole frame specified by the current call to `jaggieRender`.
*/
typedef void(*pixelSetter)(void* context, JAGGIE_COLOR color);
/*
Renders the current state to a frame of size (width, height)
using the provided pixel setter and background color.
The generic context will be passed on to the pixel setter.
*/
void jaggieRender(JAGGIE_INT width, JAGGIE_INT height, JAGGIE_COLOR bg, pixelSetter, void* context);