ScummVM API documentation
art.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22/*
23 * This code is based on Libart_LGPL - library of basic graphic primitives
24 *
25 * Copyright (c) 1998 Raph Levien
26 *
27 * Licensed under GNU LGPL v2
28 *
29 */
30
31/* Simple macros to set up storage allocation and basic types for libart
32 functions. */
33
34#ifndef __ART_H__
35#define __ART_H__
36
37#include "common/scummsys.h"
38
39namespace Sword25 {
40
41/* These aren't, strictly speaking, configuration macros, but they're
42 damn handy to have around, and may be worth playing with for
43 debugging. */
44#define art_new(type, n) ((type *)malloc ((n) * sizeof(type)))
45
46#define art_renew(p, type, n) ((type *)realloc (p, (n) * sizeof(type)))
47
48/* This one must be used carefully - in particular, p and max should
49 be variables. They can also be pstruct->el lvalues. */
50#define art_expand(p, type, max) \
51 do { \
52 if (max) {\
53 type *tmp = art_renew(p, type, max <<= 1); \
54 if (!tmp) error("Cannot reallocate memory for art data"); \
55 p = tmp; \
56 } else { \
57 max = 1; \
58 p = art_new(type, 1); \
59 if (!p) error("Cannot allocate memory for art data"); \
60 } \
61 } while (0)
62
63struct ArtDRect {
64 /*< public >*/
65 double x0, y0, x1, y1;
66};
67
68struct ArtPoint {
69 /*< public >*/
70 double x, y;
71};
72
73/* Basic data structures and constructors for sorted vector paths */
74
75struct ArtSVPSeg {
76 int n_points;
77 int dir; /* == 0 for "up", 1 for "down" */
78 ArtDRect bbox;
79 ArtPoint *points;
80};
81
82struct ArtSVP {
83 int n_segs;
84 ArtSVPSeg segs[1];
85};
86
87void art_svp_free(ArtSVP *svp);
88
89/* Basic data structures and constructors for bezier paths */
90
91enum ArtPathcode {
92 ART_MOVETO,
93 ART_MOVETO_OPEN,
94 ART_CURVETO,
95 ART_LINETO,
96 ART_END
97};
98
99struct ArtBpath {
100 /*< public >*/
101 ArtPathcode code;
102 double x1;
103 double y1;
104 double x2;
105 double y2;
106 double x3;
107 double y3;
108};
109
110/* Basic data structures and constructors for simple vector paths */
111
112/* CURVETO is not allowed! */
113struct ArtVpath {
114 ArtPathcode code;
115 double x;
116 double y;
117};
118
119/* Some of the functions need to go into their own modules */
120
121void art_vpath_add_point(ArtVpath **p_vpath, int *pn_points, int *pn_points_max,
122 ArtPathcode code, double x, double y);
123
124ArtVpath *art_bez_path_to_vec(const ArtBpath *bez, double flatness);
125
126/* The funky new SVP intersector. */
127
128#ifndef ART_WIND_RULE_DEFINED
129#define ART_WIND_RULE_DEFINED
130enum ArtWindRule {
131 ART_WIND_RULE_NONZERO,
132 ART_WIND_RULE_INTERSECT,
133 ART_WIND_RULE_ODDEVEN,
134 ART_WIND_RULE_POSITIVE
135};
136#endif
137
139 int (*add_segment)(ArtSvpWriter *self, int wind_left, int delta_wind,
140 double x, double y);
141 void (*add_point)(ArtSvpWriter *self, int seg_id, double x, double y);
142 void (*close_segment)(ArtSvpWriter *self, int seg_id);
143};
144
145ArtSvpWriter *art_svp_writer_rewind_new(ArtWindRule rule);
146
147ArtSVP *art_svp_writer_rewind_reap(ArtSvpWriter *self);
148
149int art_svp_seg_compare(const void *s1, const void *s2);
150
151void art_svp_intersector(const ArtSVP *in, ArtSvpWriter *out);
152
153
154/* Sort vector paths into sorted vector paths. */
155
156ArtSVP *art_svp_from_vpath(ArtVpath *vpath);
157
158/* Sort vector paths into sorted vector paths. */
159
160enum ArtPathStrokeJoinType {
161 ART_PATH_STROKE_JOIN_MITER,
162 ART_PATH_STROKE_JOIN_ROUND,
163 ART_PATH_STROKE_JOIN_BEVEL
164};
165
166enum ArtPathStrokeCapType {
167 ART_PATH_STROKE_CAP_BUTT,
168 ART_PATH_STROKE_CAP_ROUND,
169 ART_PATH_STROKE_CAP_SQUARE
170};
171
172ArtSVP *art_svp_vpath_stroke(ArtVpath *vpath,
173 ArtPathStrokeJoinType join,
174 ArtPathStrokeCapType cap,
175 double line_width,
176 double miter_limit,
177 double flatness);
178
179/* This version may have winding numbers exceeding 1. */
180ArtVpath *art_svp_vpath_stroke_raw(ArtVpath *vpath,
181 ArtPathStrokeJoinType join,
182 ArtPathStrokeCapType cap,
183 double line_width,
184 double miter_limit,
185 double flatness);
186
187
188/* The spiffy antialiased renderer for sorted vector paths. */
189
191 int x;
192 int delta; /* stored with 16 fractional bits */
193};
194
195struct ArtSVPRenderAAIter;
196
197ArtSVPRenderAAIter *art_svp_render_aa_iter(const ArtSVP *svp,
198 int x0, int y0, int x1, int y1);
199
200void art_svp_render_aa_iter_step(ArtSVPRenderAAIter *iter, int *p_start,
201 ArtSVPRenderAAStep **p_steps, int *p_n_steps);
202
203void art_svp_render_aa_iter_done(ArtSVPRenderAAIter *iter);
204
205void art_svp_render_aa(const ArtSVP *svp,
206 int x0, int y0, int x1, int y1,
207 void (*callback)(void *callback_data,
208 int y,
209 int start,
210 ArtSVPRenderAAStep *steps, int n_steps),
211 void *callback_data);
212
213} // End of namespace Sword25
214
215#endif /* __ART_H__ */
Definition: console.h:27
Definition: art.h:99
Definition: art.h:63
Definition: art.h:68
Definition: art.h:82
Definition: art.h:190
Definition: art.h:75
Definition: art.h:138
Definition: art.h:113