-
Notifications
You must be signed in to change notification settings - Fork 1
/
flirt.h
364 lines (254 loc) · 8.37 KB
/
flirt.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
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
/*
Flirt, an SWF rendering library
Copyright (c) 2004-2006 Dave Hayden <[email protected]>
All rights reserved.
http://www.opaque.net/flirt/
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright notice
and URL, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice and URL, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef DD_FLIRT_H_INCLUDED
#define DD_FLIRT_H_INCLUDED
#include <math.h>
typedef int fixed; /* signed 22.10 */
typedef int boolean;
#define FIXED_SHIFT 10
#define FIXED_I(i) ((i)<<FIXED_SHIFT)
/* doesn't work for d<1:
#define FIXED_D(d) (((int)floor(d))<<FIXED_SHIFT) */
#define FIXED_D(d) ((int)floor((d)*(1<<FIXED_SHIFT)+0.5))
/* fixed from twips */
#define FIXED_T(t) (((t)<<FIXED_SHIFT)/20)
/* XXX - slight rounding error in above. need to determine if
((t)<<FIXED_SHIFT)/20 would be feasible */
/* shouldn't ever need this, inside dd all units are fixed screen coords
and twips are never exposed to the user */
#define TWIPS_F(f) (((f)*20)>>FIXED_SHIFT)
#define TWIPS_I(i) ((i)*20)
#define DOUBLE_F(f) ((f)/(double)(1<<FIXED_SHIFT))
#define INT_F(f) ((f)>>FIXED_SHIFT)
/* the fractional part of f, left scaled up as an int */
#define FRACT_F(f) ((f)&((1<<FIXED_SHIFT)-1))
/* XXX - should be optimized: */
static fixed inline fixed_mult(fixed a, fixed b)
{
return (fixed)(((long long)a*b) >> FIXED_SHIFT);
}
static fixed inline fixed_divide(fixed a, fixed b)
{
return FIXED_D(DOUBLE_F(a)/DOUBLE_F(b));
}
typedef unsigned int ddColor;
#define COLOR_ALPHA(c) (((c)>>24)&0xff)
#define COLOR_RED(c) (((c)>>16)&0xff)
#define COLOR_GREEN(c) (((c)>>8)&0xff)
#define COLOR_BLUE(c) ((c)&0xff)
#define DDCOLOR(a,r,g,b) ((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff))
ddColor
ddColor_scale(ddColor color, int scale); /* 0x100 = 1.0 */
typedef struct _ddImage ddImage;
ddImage*
dd_newImage(int width, int height);
ddImage*
dd_newImageFromBuffer(char* buffer, int width, int rowBytes, int height);
void
ddImage_setBuffer(ddImage* image, char* buffer);
char*
ddImage_getData(ddImage* image);
int
ddImage_getRowstride(ddImage* image);
void
dd_destroyImage(ddImage* image);
void
ddImage_clear(ddImage* image, ddColor color);
typedef struct _ddRect ddRect;
struct _ddRect
{
fixed left;
fixed right;
fixed top;
fixed bottom;
};
typedef struct _ddPlayer ddPlayer;
void
dd_destroyPlayer(ddPlayer* player);
ddPlayer*
dd_newPlayer_file(FILE *f, ddImage* image);
int
ddPlayer_readMovie(ddPlayer* player);
void
ddPlayer_setImage(ddPlayer* player, ddImage* image);
void
ddPlayer_step(ddPlayer* player);
void
ddPlayer_updateDisplay(ddPlayer* player, ddRect** outRects, int* outCount);
float
ddPlayer_getFrameRate(ddPlayer* player);
ddColor
ddPlayer_getBackgroundColor(ddPlayer* player);
#define DD_SAMPLE_MAX_POS 0x00ffffff
#define DD_SAMPLE_MAX_NEG 0xff800000
#define DD_SAMPLE_SINT16(s) \
(short)(((s)>DD_SAMPLE_MAX_POS)?0x7fff:(((s)<DD_SAMPLE_MAX_NEG)?0x8000:(s)))
typedef struct
{
int left;
int right;
} ddAudioSample;
boolean
ddPlayer_renderFrameSoundIntoBuffer(ddPlayer* player, ddAudioSample* buffer, int* ioSize);
typedef struct _ddActionMovieClip ddActionMovieClip;
ddActionMovieClip*
ddPlayer_getRootClip(ddPlayer* player);
#ifndef min
#define dd_min(a,b) (((a)<(b))?(a):(b))
#endif
#ifndef max
#define dd_max(a,b) (((a)>(b))?(a):(b))
#endif
#ifdef WIN32
#include <float.h>
#define rint(a) floor((a)+0.5)
#define isnan(a) _isnan(a)
#define finite(a) _finite(a)
#endif
#ifndef DD_FALSE
#define DD_FALSE (boolean)0
#endif
#ifndef DD_TRUE
#define DD_TRUE (boolean)1
#endif
#ifndef M_PI
#define M_PI 3.14159265358979
#endif
void dd_setErrorFunction(void (*error)(char *msg, ...));
void dd_setWarnFunction(void (*warn)(char *msg, ...));
boolean dd_init();
unsigned long dd_getTicks();
void
dd_setActionTraceFunction(ddPlayer* player, void (*trace)(const char* message, void* userdata), void* userdata);
typedef enum
{
DD_ARROW_CURSOR = 0,
DD_BUTTON_CURSOR,
DD_TEXTFIELD_CURSOR
} ddCursorType;
ddCursorType
ddPlayer_doMouseMove(ddPlayer* player, int x, int y);
void
ddPlayer_doMouseDown(ddPlayer* player, int x, int y);
void
ddPlayer_doMouseUp(ddPlayer* player, int x, int y);
void
ddPlayer_doKeyDown(ddPlayer* player, unsigned short code);
void
ddPlayer_doKeyUp(ddPlayer* player, unsigned short code);
typedef struct _ddMovieClip ddMovieClip;
ddMovieClip*
ddPlayer_getMovieClip(ddPlayer* player);
typedef struct _ddDrawClip ddDrawClip;
void
ddDrawClip_renderInImage(ddDrawClip* clip, ddImage* image, ddColor background);
ddDrawClip*
ddActionMovieClip_getDrawClip(ddActionMovieClip* clip);
typedef struct _ddActionObject ddActionObject;
typedef struct _ddActionHash ddActionHash;
typedef struct _ddActionContext ddActionContext;
typedef struct _ddActionFunction ddActionFunction;
typedef enum
{
VALUE_NULL,
VALUE_UNDEF,
VALUE_INTEGER,
VALUE_DOUBLE,
VALUE_BOOLEAN,
VALUE_STRING,
VALUE_OBJECT,
VALUE_FUNCTION
} ddActionValueType;
struct _ddActionValue
{
ddActionValueType type;
union
{
int intValue;
double doubleValue;
ddActionObject* objectValue;
ddActionFunction* functionValue;
char* stringValue;
} data;
};
typedef struct _ddActionValue ddActionValue;
extern ddActionValue ddNullValue;
extern ddActionValue ddTrueValue;
extern ddActionValue ddFalseValue;
ddActionObject*
ddActionValue_getObjectValue(ddActionValue value);
ddActionObject*
ddActionObject_retain(ddActionObject* object);
void
ddActionObject_release(ddActionObject* object);
char*
ddActionValue_getStringValue(ddActionContext* context, ddActionValue value);
int
ddActionValue_getIntValue(ddActionValue value);
ddActionValue
dd_newActionValue_object(ddActionObject* object);
typedef struct _ddActionClass ddActionClass;
struct _ddActionObject
{
int refCount;
ddActionObject* proto;
ddActionHash* properties;
void (*cachedSetProperty)(ddActionContext* context, ddActionObject* obj, char* name, ddActionValue value);
ddActionValue (*cachedGetProperty)(ddActionContext* context, ddActionObject* obj, const char* name);
ddActionClass* nativeClass;
};
void
ddActionObject_init(ddActionObject* object);
extern ddActionClass* ddActionArrayClass;
extern ddActionClass* ddActionColorClass;
extern ddActionClass* ddActionDateClass;
extern ddActionClass* ddActionFunctionClass;
extern ddActionClass* ddActionMovieClipClass;
extern ddActionClass* ddActionObjectClass;
extern ddActionClass* ddActionStringClass;
#define FUNCTION_VARARGS -1 /* if it's doing its own arg handling */
typedef ddActionValue (*ddNativeFunction)(ddActionObject* object, ddActionContext* context, int nargs);
ddActionClass*
ddPlayer_addClass(ddPlayer* player, ddActionClass* superclass, const char* name, ddNativeFunction constructor, int nargs);
ddActionClass*
dd_newActionClass();
void
ddActionClass_setSuperclass(ddActionClass* classObject, ddActionClass* superclass);
void
ddActionClass_addNativeMethod(ddActionClass* classObject, char* name, ddNativeFunction function, int nargs);
ddActionFunction*
dd_newActionNativeFunction(ddNativeFunction function, int nargs);
boolean
ddActionObject_isKindOfClass(ddActionObject* object, ddActionClass* classPrototype);
void
ddActionObject_setClass(ddActionObject* object, ddActionClass* class);
ddActionObject*
ddActionObject_getPrototype(ddActionObject* object);
ddActionValue
ddActionContext_popValue(ddActionContext* context);
ddPlayer*
ddContext_getPlayer(ddActionContext* context);
#endif /* DD_FLIRT_H_INCLUDED */