1 //=============================================================================
2 //
3 // Adventure Game Studio (AGS)
4 //
5 // Copyright (C) 1999-2011 Chris Jones and 2011-20xx others
6 // The full list of copyright holders can be found in the Copyright.txt
7 // file, which is part of this source code distribution.
8 //
9 // The AGS source code is provided under the Artistic License 2.0.
10 // A copy of this license can be found in the file License.txt and at
11 // http://www.opensource.org/licenses/artistic-license-2.0.php
12 //
13 //=============================================================================
14
15 #include <math.h>
16 #include "ac/dynamicsprite.h"
17 #include "ac/common.h"
18 #include "ac/charactercache.h"
19 #include "ac/draw.h"
20 #include "ac/gamesetupstruct.h"
21 #include "ac/global_dynamicsprite.h"
22 #include "ac/global_game.h"
23 #include "ac/math.h" // M_PI
24 #include "ac/objectcache.h"
25 #include "ac/path_helper.h"
26 #include "ac/roomobject.h"
27 #include "ac/roomstatus.h"
28 #include "ac/roomstruct.h"
29 #include "ac/system.h"
30 #include "debug/debug_log.h"
31 #include "gui/guibutton.h"
32 #include "ac/spritecache.h"
33 #include "platform/base/override_defines.h"
34 #include "gfx/graphicsdriver.h"
35 #include "script/runtimescriptvalue.h"
36
37 using namespace Common;
38 using namespace Engine;
39
40 extern GameSetupStruct game;
41 extern SpriteCache spriteset;
42 extern int spritewidth[MAX_SPRITES],spriteheight[MAX_SPRITES];
43 extern roomstruct thisroom;
44 extern RoomObject*objs;
45 extern RoomStatus*croom;
46 extern CharacterCache *charcache;
47 extern ObjectCache objcache[MAX_INIT_SPR];
48
49 extern color palette[256];
50 extern AGS::Engine::IGraphicsDriver *gfxDriver;
51
52 char check_dynamic_sprites_at_exit = 1;
53
54 // ** SCRIPT DYNAMIC SPRITE
55
DynamicSprite_Delete(ScriptDynamicSprite * sds)56 void DynamicSprite_Delete(ScriptDynamicSprite *sds) {
57 if (sds->slot) {
58 free_dynamic_sprite(sds->slot);
59 sds->slot = 0;
60 }
61 }
62
DynamicSprite_GetDrawingSurface(ScriptDynamicSprite * dss)63 ScriptDrawingSurface* DynamicSprite_GetDrawingSurface(ScriptDynamicSprite *dss)
64 {
65 ScriptDrawingSurface *surface = new ScriptDrawingSurface();
66 surface->dynamicSpriteNumber = dss->slot;
67
68 if ((game.spriteflags[dss->slot] & SPF_ALPHACHANNEL) != 0)
69 surface->hasAlphaChannel = true;
70
71 ccRegisterManagedObject(surface, surface);
72 return surface;
73 }
74
DynamicSprite_GetGraphic(ScriptDynamicSprite * sds)75 int DynamicSprite_GetGraphic(ScriptDynamicSprite *sds) {
76 if (sds->slot == 0)
77 quit("!DynamicSprite.Graphic: Cannot get graphic, sprite has been deleted");
78 return sds->slot;
79 }
80
DynamicSprite_GetWidth(ScriptDynamicSprite * sds)81 int DynamicSprite_GetWidth(ScriptDynamicSprite *sds) {
82 return divide_down_coordinate(spritewidth[sds->slot]);
83 }
84
DynamicSprite_GetHeight(ScriptDynamicSprite * sds)85 int DynamicSprite_GetHeight(ScriptDynamicSprite *sds) {
86 return divide_down_coordinate(spriteheight[sds->slot]);
87 }
88
DynamicSprite_GetColorDepth(ScriptDynamicSprite * sds)89 int DynamicSprite_GetColorDepth(ScriptDynamicSprite *sds) {
90 int depth = spriteset[sds->slot]->GetColorDepth();
91 if (depth == 15)
92 depth = 16;
93 if (depth == 24)
94 depth = 32;
95 return depth;
96 }
97
DynamicSprite_Resize(ScriptDynamicSprite * sds,int width,int height)98 void DynamicSprite_Resize(ScriptDynamicSprite *sds, int width, int height) {
99 if ((width < 1) || (height < 1))
100 quit("!DynamicSprite.Resize: width and height must be greater than zero");
101 if (sds->slot == 0)
102 quit("!DynamicSprite.Resize: sprite has been deleted");
103
104 multiply_up_coordinates(&width, &height);
105
106 if (width * height >= 25000000)
107 quitprintf("!DynamicSprite.Resize: new size is too large: %d x %d", width, height);
108
109 // resize the sprite to the requested size
110 Bitmap *newPic = BitmapHelper::CreateBitmap(width, height, spriteset[sds->slot]->GetColorDepth());
111 newPic->StretchBlt(spriteset[sds->slot],
112 RectWH(0, 0, spritewidth[sds->slot], spriteheight[sds->slot]),
113 RectWH(0, 0, width, height));
114
115 delete spriteset[sds->slot];
116
117 // replace the bitmap in the sprite set
118 add_dynamic_sprite(sds->slot, newPic, (game.spriteflags[sds->slot] & SPF_ALPHACHANNEL) != 0);
119 }
120
DynamicSprite_Flip(ScriptDynamicSprite * sds,int direction)121 void DynamicSprite_Flip(ScriptDynamicSprite *sds, int direction) {
122 if ((direction < 1) || (direction > 3))
123 quit("!DynamicSprite.Flip: invalid direction");
124 if (sds->slot == 0)
125 quit("!DynamicSprite.Flip: sprite has been deleted");
126
127 // resize the sprite to the requested size
128 Bitmap *newPic = BitmapHelper::CreateTransparentBitmap(spritewidth[sds->slot], spriteheight[sds->slot], spriteset[sds->slot]->GetColorDepth());
129
130 if (direction == 1)
131 newPic->FlipBlt(spriteset[sds->slot], 0, 0, Common::kBitmap_HFlip);
132 else if (direction == 2)
133 newPic->FlipBlt(spriteset[sds->slot], 0, 0, Common::kBitmap_VFlip);
134 else if (direction == 3)
135 newPic->FlipBlt(spriteset[sds->slot], 0, 0, Common::kBitmap_HVFlip);
136
137 delete spriteset[sds->slot];
138
139 // replace the bitmap in the sprite set
140 add_dynamic_sprite(sds->slot, newPic, (game.spriteflags[sds->slot] & SPF_ALPHACHANNEL) != 0);
141 }
142
DynamicSprite_CopyTransparencyMask(ScriptDynamicSprite * sds,int sourceSprite)143 void DynamicSprite_CopyTransparencyMask(ScriptDynamicSprite *sds, int sourceSprite) {
144 if (sds->slot == 0)
145 quit("!DynamicSprite.CopyTransparencyMask: sprite has been deleted");
146
147 if ((spritewidth[sds->slot] != spritewidth[sourceSprite]) ||
148 (spriteheight[sds->slot] != spriteheight[sourceSprite]))
149 {
150 quit("!DynamicSprite.CopyTransparencyMask: sprites are not the same size");
151 }
152
153 Bitmap *target = spriteset[sds->slot];
154 Bitmap *source = spriteset[sourceSprite];
155
156 if (target->GetColorDepth() != source->GetColorDepth())
157 {
158 quit("!DynamicSprite.CopyTransparencyMask: sprites are not the same colour depth");
159 }
160
161 // set the target's alpha channel depending on the source
162 bool dst_has_alpha = (game.spriteflags[sds->slot] & SPF_ALPHACHANNEL) != 0;
163 bool src_has_alpha = (game.spriteflags[sourceSprite] & SPF_ALPHACHANNEL) != 0;
164 game.spriteflags[sds->slot] &= ~SPF_ALPHACHANNEL;
165 if (src_has_alpha)
166 {
167 game.spriteflags[sds->slot] |= SPF_ALPHACHANNEL;
168 }
169
170 BitmapHelper::CopyTransparency(target, source, dst_has_alpha, src_has_alpha);
171 }
172
DynamicSprite_ChangeCanvasSize(ScriptDynamicSprite * sds,int width,int height,int x,int y)173 void DynamicSprite_ChangeCanvasSize(ScriptDynamicSprite *sds, int width, int height, int x, int y)
174 {
175 if (sds->slot == 0)
176 quit("!DynamicSprite.ChangeCanvasSize: sprite has been deleted");
177 if ((width < 1) || (height < 1))
178 quit("!DynamicSprite.ChangeCanvasSize: new size is too small");
179
180 multiply_up_coordinates(&x, &y);
181 multiply_up_coordinates(&width, &height);
182
183 Bitmap *newPic = BitmapHelper::CreateTransparentBitmap(width, height, spriteset[sds->slot]->GetColorDepth());
184 // blit it into the enlarged image
185 newPic->Blit(spriteset[sds->slot], 0, 0, x, y, spritewidth[sds->slot], spriteheight[sds->slot]);
186
187 delete spriteset[sds->slot];
188
189 // replace the bitmap in the sprite set
190 add_dynamic_sprite(sds->slot, newPic, (game.spriteflags[sds->slot] & SPF_ALPHACHANNEL) != 0);
191 }
192
DynamicSprite_Crop(ScriptDynamicSprite * sds,int x1,int y1,int width,int height)193 void DynamicSprite_Crop(ScriptDynamicSprite *sds, int x1, int y1, int width, int height) {
194 if ((width < 1) || (height < 1))
195 quit("!DynamicSprite.Crop: co-ordinates do not make sense");
196 if (sds->slot == 0)
197 quit("!DynamicSprite.Crop: sprite has been deleted");
198
199 multiply_up_coordinates(&x1, &y1);
200 multiply_up_coordinates(&width, &height);
201
202 if ((width > spritewidth[sds->slot]) || (height > spriteheight[sds->slot]))
203 quit("!DynamicSprite.Crop: requested to crop an area larger than the source");
204
205 Bitmap *newPic = BitmapHelper::CreateBitmap(width, height, spriteset[sds->slot]->GetColorDepth());
206 // blit it cropped
207 newPic->Blit(spriteset[sds->slot], x1, y1, 0, 0, newPic->GetWidth(), newPic->GetHeight());
208
209 delete spriteset[sds->slot];
210
211 // replace the bitmap in the sprite set
212 add_dynamic_sprite(sds->slot, newPic, (game.spriteflags[sds->slot] & SPF_ALPHACHANNEL) != 0);
213 }
214
DynamicSprite_Rotate(ScriptDynamicSprite * sds,int angle,int width,int height)215 void DynamicSprite_Rotate(ScriptDynamicSprite *sds, int angle, int width, int height) {
216 if ((angle < 1) || (angle > 359))
217 quit("!DynamicSprite.Rotate: invalid angle (must be 1-359)");
218 if (sds->slot == 0)
219 quit("!DynamicSprite.Rotate: sprite has been deleted");
220
221 if ((width == SCR_NO_VALUE) || (height == SCR_NO_VALUE)) {
222 // calculate the new image size automatically
223 // 1 degree = 181 degrees in terms of x/y size, so % 180
224 int useAngle = angle % 180;
225 // and 0..90 is the same as 180..90
226 if (useAngle > 90)
227 useAngle = 180 - useAngle;
228 // useAngle is now between 0 and 90 (otherwise the sin/cos stuff doesn't work)
229 double angleInRadians = (double)useAngle * (M_PI / 180.0);
230 double sinVal = sin(angleInRadians);
231 double cosVal = cos(angleInRadians);
232
233 width = (cosVal * (double)spritewidth[sds->slot] + sinVal * (double)spriteheight[sds->slot]);
234 height = (sinVal * (double)spritewidth[sds->slot] + cosVal * (double)spriteheight[sds->slot]);
235 }
236 else {
237 multiply_up_coordinates(&width, &height);
238 }
239
240 // convert to allegro angle
241 angle = (angle * 256) / 360;
242
243 // resize the sprite to the requested size
244 Bitmap *newPic = BitmapHelper::CreateTransparentBitmap(width, height, spriteset[sds->slot]->GetColorDepth());
245
246 // rotate the sprite about its centre
247 // (+ width%2 fixes one pixel offset problem)
248 newPic->RotateBlt(spriteset[sds->slot], width / 2 + width % 2, height / 2,
249 spritewidth[sds->slot] / 2, spriteheight[sds->slot] / 2, itofix(angle));
250
251 delete spriteset[sds->slot];
252
253 // replace the bitmap in the sprite set
254 add_dynamic_sprite(sds->slot, newPic, (game.spriteflags[sds->slot] & SPF_ALPHACHANNEL) != 0);
255 }
256
DynamicSprite_Tint(ScriptDynamicSprite * sds,int red,int green,int blue,int saturation,int luminance)257 void DynamicSprite_Tint(ScriptDynamicSprite *sds, int red, int green, int blue, int saturation, int luminance)
258 {
259 Bitmap *source = spriteset[sds->slot];
260 Bitmap *newPic = BitmapHelper::CreateBitmap(source->GetWidth(), source->GetHeight(), source->GetColorDepth());
261
262 tint_image(newPic, source, red, green, blue, saturation, (luminance * 25) / 10);
263
264 delete source;
265 // replace the bitmap in the sprite set
266 add_dynamic_sprite(sds->slot, newPic, (game.spriteflags[sds->slot] & SPF_ALPHACHANNEL) != 0);
267 }
268
DynamicSprite_SaveToFile(ScriptDynamicSprite * sds,const char * namm)269 int DynamicSprite_SaveToFile(ScriptDynamicSprite *sds, const char* namm)
270 {
271 if (sds->slot == 0)
272 quit("!DynamicSprite.SaveToFile: sprite has been deleted");
273
274 String filename = namm;
275 if (filename.FindChar('.') == -1)
276 filename.Append(".bmp");
277
278 String path, alt_path; // alt_path is unused here, because it's a write op
279 if (!ResolveScriptPath(filename, false, path, alt_path))
280 return 0;
281 return spriteset[sds->slot]->SaveToFile(path, palette) ? 1 : 0;
282 }
283
DynamicSprite_CreateFromSaveGame(int sgslot,int width,int height)284 ScriptDynamicSprite* DynamicSprite_CreateFromSaveGame(int sgslot, int width, int height) {
285 int slotnum = LoadSaveSlotScreenshot(sgslot, width, height);
286 if (slotnum) {
287 ScriptDynamicSprite *new_spr = new ScriptDynamicSprite(slotnum);
288 return new_spr;
289 }
290 return NULL;
291 }
292
DynamicSprite_CreateFromFile(const char * filename)293 ScriptDynamicSprite* DynamicSprite_CreateFromFile(const char *filename) {
294 int slotnum = LoadImageFile(filename);
295 if (slotnum) {
296 ScriptDynamicSprite *new_spr = new ScriptDynamicSprite(slotnum);
297 return new_spr;
298 }
299 return NULL;
300 }
301
DynamicSprite_CreateFromScreenShot(int width,int height)302 ScriptDynamicSprite* DynamicSprite_CreateFromScreenShot(int width, int height) {
303
304 // TODO: refactor and merge with create_savegame_screenshot()
305 int gotSlot = spriteset.findFreeSlot();
306
307 if (gotSlot <= 0)
308 return NULL;
309
310 const Rect &viewport = play.viewport;
311 if (width <= 0)
312 width = viewport.GetWidth();
313 else
314 width = multiply_up_coordinate(width);
315
316 if (height <= 0)
317 height = viewport.GetHeight();
318 else
319 height = multiply_up_coordinate(height);
320
321 Bitmap *newPic = CopyScreenIntoBitmap(width, height);
322
323 update_polled_stuff_if_runtime();
324
325 // replace the bitmap in the sprite set
326 add_dynamic_sprite(gotSlot, ReplaceBitmapWithSupportedFormat(newPic));
327 ScriptDynamicSprite *new_spr = new ScriptDynamicSprite(gotSlot);
328 return new_spr;
329 }
330
DynamicSprite_CreateFromExistingSprite(int slot,int preserveAlphaChannel)331 ScriptDynamicSprite* DynamicSprite_CreateFromExistingSprite(int slot, int preserveAlphaChannel) {
332
333 int gotSlot = spriteset.findFreeSlot();
334 if (gotSlot <= 0)
335 return NULL;
336
337 if (!spriteset.doesSpriteExist(slot))
338 quitprintf("DynamicSprite.CreateFromExistingSprite: sprite %d does not exist", slot);
339
340 // create a new sprite as a copy of the existing one
341 Bitmap *newPic = BitmapHelper::CreateBitmapCopy(spriteset[slot]);
342 if (newPic == NULL)
343 return NULL;
344
345 bool hasAlpha = (preserveAlphaChannel) && ((game.spriteflags[slot] & SPF_ALPHACHANNEL) != 0);
346
347 // replace the bitmap in the sprite set
348 add_dynamic_sprite(gotSlot, newPic, hasAlpha);
349 ScriptDynamicSprite *new_spr = new ScriptDynamicSprite(gotSlot);
350 return new_spr;
351 }
352
DynamicSprite_CreateFromDrawingSurface(ScriptDrawingSurface * sds,int x,int y,int width,int height)353 ScriptDynamicSprite* DynamicSprite_CreateFromDrawingSurface(ScriptDrawingSurface *sds, int x, int y, int width, int height)
354 {
355 int gotSlot = spriteset.findFreeSlot();
356 if (gotSlot <= 0)
357 return NULL;
358
359 // use DrawingSurface resolution
360 sds->MultiplyCoordinates(&x, &y);
361 sds->MultiplyCoordinates(&width, &height);
362
363 Bitmap *ds = sds->StartDrawing();
364
365 if ((x < 0) || (y < 0) || (x + width > ds->GetWidth()) || (y + height > ds->GetHeight()))
366 quit("!DynamicSprite.CreateFromDrawingSurface: requested area is outside the surface");
367
368 int colDepth = ds->GetColorDepth();
369
370 Bitmap *newPic = BitmapHelper::CreateBitmap(width, height, colDepth);
371 if (newPic == NULL)
372 return NULL;
373
374 newPic->Blit(ds, x, y, 0, 0, width, height);
375
376 sds->FinishedDrawingReadOnly();
377
378 add_dynamic_sprite(gotSlot, newPic, (sds->hasAlphaChannel != 0));
379 ScriptDynamicSprite *new_spr = new ScriptDynamicSprite(gotSlot);
380 return new_spr;
381 }
382
DynamicSprite_Create(int width,int height,int alphaChannel)383 ScriptDynamicSprite* DynamicSprite_Create(int width, int height, int alphaChannel)
384 {
385 multiply_up_coordinates(&width, &height);
386
387 int gotSlot = spriteset.findFreeSlot();
388 if (gotSlot <= 0)
389 return NULL;
390
391 Bitmap *newPic = BitmapHelper::CreateTransparentBitmap(width, height, game.GetColorDepth());
392 if (newPic == NULL)
393 return NULL;
394
395 if ((alphaChannel) && (game.GetColorDepth() < 32))
396 alphaChannel = false;
397
398 add_dynamic_sprite(gotSlot, ReplaceBitmapWithSupportedFormat(newPic), alphaChannel != 0);
399 ScriptDynamicSprite *new_spr = new ScriptDynamicSprite(gotSlot);
400 return new_spr;
401 }
402
DynamicSprite_CreateFromExistingSprite_Old(int slot)403 ScriptDynamicSprite* DynamicSprite_CreateFromExistingSprite_Old(int slot)
404 {
405 return DynamicSprite_CreateFromExistingSprite(slot, 0);
406 }
407
DynamicSprite_CreateFromBackground(int frame,int x1,int y1,int width,int height)408 ScriptDynamicSprite* DynamicSprite_CreateFromBackground(int frame, int x1, int y1, int width, int height) {
409
410 if (frame == SCR_NO_VALUE) {
411 frame = play.bg_frame;
412 }
413 else if ((frame < 0) || (frame >= thisroom.num_bscenes))
414 quit("!DynamicSprite.CreateFromBackground: invalid frame specified");
415
416 if (x1 == SCR_NO_VALUE) {
417 x1 = 0;
418 y1 = 0;
419 width = play.room_width;
420 height = play.room_height;
421 }
422 else if ((x1 < 0) || (y1 < 0) || (width < 1) || (height < 1) ||
423 (x1 + width > play.room_width) || (y1 + height > play.room_height))
424 quit("!DynamicSprite.CreateFromBackground: invalid co-ordinates specified");
425
426 multiply_up_coordinates(&x1, &y1);
427 multiply_up_coordinates(&width, &height);
428
429 int gotSlot = spriteset.findFreeSlot();
430 if (gotSlot <= 0)
431 return NULL;
432
433 // create a new sprite as a copy of the existing one
434 Bitmap *newPic = BitmapHelper::CreateBitmap(width, height, thisroom.ebscene[frame]->GetColorDepth());
435 if (newPic == NULL)
436 return NULL;
437
438 newPic->Blit(thisroom.ebscene[frame], x1, y1, 0, 0, width, height);
439
440 // replace the bitmap in the sprite set
441 add_dynamic_sprite(gotSlot, newPic);
442 ScriptDynamicSprite *new_spr = new ScriptDynamicSprite(gotSlot);
443 return new_spr;
444 }
445
446 //=============================================================================
447
add_dynamic_sprite(int gotSlot,Bitmap * redin,bool hasAlpha)448 void add_dynamic_sprite(int gotSlot, Bitmap *redin, bool hasAlpha) {
449
450 spriteset.set(gotSlot, redin);
451
452 game.spriteflags[gotSlot] = SPF_DYNAMICALLOC;
453
454 if (redin->GetColorDepth() > 8)
455 game.spriteflags[gotSlot] |= SPF_HICOLOR;
456 if (redin->GetColorDepth() > 16)
457 game.spriteflags[gotSlot] |= SPF_TRUECOLOR;
458 if (hasAlpha)
459 game.spriteflags[gotSlot] |= SPF_ALPHACHANNEL;
460
461 spritewidth[gotSlot] = redin->GetWidth();
462 spriteheight[gotSlot] = redin->GetHeight();
463 }
464
free_dynamic_sprite(int gotSlot)465 void free_dynamic_sprite (int gotSlot) {
466 int tt;
467
468 if ((gotSlot < 0) || (gotSlot >= spriteset.elements))
469 quit("!FreeDynamicSprite: invalid slot number");
470
471 if ((game.spriteflags[gotSlot] & SPF_DYNAMICALLOC) == 0)
472 quitprintf("!DeleteSprite: Attempted to free static sprite %d that was not loaded by the script", gotSlot);
473
474 delete spriteset[gotSlot];
475 spriteset.set(gotSlot, NULL);
476
477 game.spriteflags[gotSlot] = 0;
478 spritewidth[gotSlot] = 0;
479 spriteheight[gotSlot] = 0;
480
481 // ensure it isn't still on any GUI buttons
482 for (tt = 0; tt < numguibuts; tt++) {
483 if (guibuts[tt].IsDeleted())
484 continue;
485 if (guibuts[tt].pic == gotSlot)
486 guibuts[tt].pic = 0;
487 if (guibuts[tt].usepic == gotSlot)
488 guibuts[tt].usepic = 0;
489 if (guibuts[tt].overpic == gotSlot)
490 guibuts[tt].overpic = 0;
491 if (guibuts[tt].pushedpic == gotSlot)
492 guibuts[tt].pushedpic = 0;
493 }
494
495 // force refresh of any object caches using the sprite
496 if (croom != NULL)
497 {
498 for (tt = 0; tt < croom->numobj; tt++)
499 {
500 if (objs[tt].num == gotSlot)
501 {
502 objs[tt].num = 0;
503 objcache[tt].sppic = -1;
504 }
505 else if (objcache[tt].sppic == gotSlot)
506 objcache[tt].sppic = -1;
507 }
508 }
509 }
510
511 //=============================================================================
512 //
513 // Script API Functions
514 //
515 //=============================================================================
516
517 #include "debug/out.h"
518 #include "script/script_api.h"
519 #include "script/script_runtime.h"
520
521 // void (ScriptDynamicSprite *sds, int width, int height, int x, int y)
Sc_DynamicSprite_ChangeCanvasSize(void * self,const RuntimeScriptValue * params,int32_t param_count)522 RuntimeScriptValue Sc_DynamicSprite_ChangeCanvasSize(void *self, const RuntimeScriptValue *params, int32_t param_count)
523 {
524 API_OBJCALL_VOID_PINT4(ScriptDynamicSprite, DynamicSprite_ChangeCanvasSize);
525 }
526
527 // void (ScriptDynamicSprite *sds, int sourceSprite)
Sc_DynamicSprite_CopyTransparencyMask(void * self,const RuntimeScriptValue * params,int32_t param_count)528 RuntimeScriptValue Sc_DynamicSprite_CopyTransparencyMask(void *self, const RuntimeScriptValue *params, int32_t param_count)
529 {
530 API_OBJCALL_VOID_PINT(ScriptDynamicSprite, DynamicSprite_CopyTransparencyMask);
531 }
532
533 // void (ScriptDynamicSprite *sds, int x1, int y1, int width, int height)
Sc_DynamicSprite_Crop(void * self,const RuntimeScriptValue * params,int32_t param_count)534 RuntimeScriptValue Sc_DynamicSprite_Crop(void *self, const RuntimeScriptValue *params, int32_t param_count)
535 {
536 API_OBJCALL_VOID_PINT4(ScriptDynamicSprite, DynamicSprite_Crop);
537 }
538
539 // void (ScriptDynamicSprite *sds)
Sc_DynamicSprite_Delete(void * self,const RuntimeScriptValue * params,int32_t param_count)540 RuntimeScriptValue Sc_DynamicSprite_Delete(void *self, const RuntimeScriptValue *params, int32_t param_count)
541 {
542 API_OBJCALL_VOID(ScriptDynamicSprite, DynamicSprite_Delete);
543 }
544
545 // void (ScriptDynamicSprite *sds, int direction)
Sc_DynamicSprite_Flip(void * self,const RuntimeScriptValue * params,int32_t param_count)546 RuntimeScriptValue Sc_DynamicSprite_Flip(void *self, const RuntimeScriptValue *params, int32_t param_count)
547 {
548 API_OBJCALL_VOID_PINT(ScriptDynamicSprite, DynamicSprite_Flip);
549 }
550
551 // ScriptDrawingSurface* (ScriptDynamicSprite *dss)
Sc_DynamicSprite_GetDrawingSurface(void * self,const RuntimeScriptValue * params,int32_t param_count)552 RuntimeScriptValue Sc_DynamicSprite_GetDrawingSurface(void *self, const RuntimeScriptValue *params, int32_t param_count)
553 {
554 API_OBJCALL_OBJAUTO(ScriptDynamicSprite, ScriptDrawingSurface, DynamicSprite_GetDrawingSurface);
555 }
556
557 // void (ScriptDynamicSprite *sds, int width, int height)
Sc_DynamicSprite_Resize(void * self,const RuntimeScriptValue * params,int32_t param_count)558 RuntimeScriptValue Sc_DynamicSprite_Resize(void *self, const RuntimeScriptValue *params, int32_t param_count)
559 {
560 API_OBJCALL_VOID_PINT2(ScriptDynamicSprite, DynamicSprite_Resize);
561 }
562
563 // void (ScriptDynamicSprite *sds, int angle, int width, int height)
Sc_DynamicSprite_Rotate(void * self,const RuntimeScriptValue * params,int32_t param_count)564 RuntimeScriptValue Sc_DynamicSprite_Rotate(void *self, const RuntimeScriptValue *params, int32_t param_count)
565 {
566 API_OBJCALL_VOID_PINT3(ScriptDynamicSprite, DynamicSprite_Rotate);
567 }
568
569 // int (ScriptDynamicSprite *sds, const char* namm)
Sc_DynamicSprite_SaveToFile(void * self,const RuntimeScriptValue * params,int32_t param_count)570 RuntimeScriptValue Sc_DynamicSprite_SaveToFile(void *self, const RuntimeScriptValue *params, int32_t param_count)
571 {
572 API_OBJCALL_INT_POBJ(ScriptDynamicSprite, DynamicSprite_SaveToFile, const char);
573 }
574
575 // void (ScriptDynamicSprite *sds, int red, int green, int blue, int saturation, int luminance)
Sc_DynamicSprite_Tint(void * self,const RuntimeScriptValue * params,int32_t param_count)576 RuntimeScriptValue Sc_DynamicSprite_Tint(void *self, const RuntimeScriptValue *params, int32_t param_count)
577 {
578 API_OBJCALL_VOID_PINT5(ScriptDynamicSprite, DynamicSprite_Tint);
579 }
580
581 // int (ScriptDynamicSprite *sds)
Sc_DynamicSprite_GetColorDepth(void * self,const RuntimeScriptValue * params,int32_t param_count)582 RuntimeScriptValue Sc_DynamicSprite_GetColorDepth(void *self, const RuntimeScriptValue *params, int32_t param_count)
583 {
584 API_OBJCALL_INT(ScriptDynamicSprite, DynamicSprite_GetColorDepth);
585 }
586
587 // int (ScriptDynamicSprite *sds)
Sc_DynamicSprite_GetGraphic(void * self,const RuntimeScriptValue * params,int32_t param_count)588 RuntimeScriptValue Sc_DynamicSprite_GetGraphic(void *self, const RuntimeScriptValue *params, int32_t param_count)
589 {
590 API_OBJCALL_INT(ScriptDynamicSprite, DynamicSprite_GetGraphic);
591 }
592
593 // int (ScriptDynamicSprite *sds)
Sc_DynamicSprite_GetHeight(void * self,const RuntimeScriptValue * params,int32_t param_count)594 RuntimeScriptValue Sc_DynamicSprite_GetHeight(void *self, const RuntimeScriptValue *params, int32_t param_count)
595 {
596 API_OBJCALL_INT(ScriptDynamicSprite, DynamicSprite_GetHeight);
597 }
598
599 // int (ScriptDynamicSprite *sds)
Sc_DynamicSprite_GetWidth(void * self,const RuntimeScriptValue * params,int32_t param_count)600 RuntimeScriptValue Sc_DynamicSprite_GetWidth(void *self, const RuntimeScriptValue *params, int32_t param_count)
601 {
602 API_OBJCALL_INT(ScriptDynamicSprite, DynamicSprite_GetWidth);
603 }
604
605 // ScriptDynamicSprite* (int width, int height, int alphaChannel)
Sc_DynamicSprite_Create(const RuntimeScriptValue * params,int32_t param_count)606 RuntimeScriptValue Sc_DynamicSprite_Create(const RuntimeScriptValue *params, int32_t param_count)
607 {
608 API_SCALL_OBJAUTO_PINT3(ScriptDynamicSprite, DynamicSprite_Create);
609 }
610
611 // ScriptDynamicSprite* (int frame, int x1, int y1, int width, int height)
Sc_DynamicSprite_CreateFromBackground(const RuntimeScriptValue * params,int32_t param_count)612 RuntimeScriptValue Sc_DynamicSprite_CreateFromBackground(const RuntimeScriptValue *params, int32_t param_count)
613 {
614 API_SCALL_OBJAUTO_PINT5(ScriptDynamicSprite, DynamicSprite_CreateFromBackground);
615 }
616
617 // ScriptDynamicSprite* (ScriptDrawingSurface *sds, int x, int y, int width, int height)
Sc_DynamicSprite_CreateFromDrawingSurface(const RuntimeScriptValue * params,int32_t param_count)618 RuntimeScriptValue Sc_DynamicSprite_CreateFromDrawingSurface(const RuntimeScriptValue *params, int32_t param_count)
619 {
620 API_SCALL_OBJAUTO_POBJ_PINT4(ScriptDynamicSprite, DynamicSprite_CreateFromDrawingSurface, ScriptDrawingSurface);
621 }
622
623 // ScriptDynamicSprite* (int slot)
Sc_DynamicSprite_CreateFromExistingSprite_Old(const RuntimeScriptValue * params,int32_t param_count)624 RuntimeScriptValue Sc_DynamicSprite_CreateFromExistingSprite_Old(const RuntimeScriptValue *params, int32_t param_count)
625 {
626 API_SCALL_OBJAUTO_PINT(ScriptDynamicSprite, DynamicSprite_CreateFromExistingSprite_Old);
627 }
628
629 // ScriptDynamicSprite* (int slot, int preserveAlphaChannel)
Sc_DynamicSprite_CreateFromExistingSprite(const RuntimeScriptValue * params,int32_t param_count)630 RuntimeScriptValue Sc_DynamicSprite_CreateFromExistingSprite(const RuntimeScriptValue *params, int32_t param_count)
631 {
632 API_SCALL_OBJAUTO_PINT2(ScriptDynamicSprite, DynamicSprite_CreateFromExistingSprite);
633 }
634
635 // ScriptDynamicSprite* (const char *filename)
Sc_DynamicSprite_CreateFromFile(const RuntimeScriptValue * params,int32_t param_count)636 RuntimeScriptValue Sc_DynamicSprite_CreateFromFile(const RuntimeScriptValue *params, int32_t param_count)
637 {
638 API_SCALL_OBJAUTO_POBJ(ScriptDynamicSprite, DynamicSprite_CreateFromFile, const char);
639 }
640
641 // ScriptDynamicSprite* (int sgslot, int width, int height)
Sc_DynamicSprite_CreateFromSaveGame(const RuntimeScriptValue * params,int32_t param_count)642 RuntimeScriptValue Sc_DynamicSprite_CreateFromSaveGame(const RuntimeScriptValue *params, int32_t param_count)
643 {
644 API_SCALL_OBJAUTO_PINT3(ScriptDynamicSprite, DynamicSprite_CreateFromSaveGame);
645 }
646
647 // ScriptDynamicSprite* (int width, int height)
Sc_DynamicSprite_CreateFromScreenShot(const RuntimeScriptValue * params,int32_t param_count)648 RuntimeScriptValue Sc_DynamicSprite_CreateFromScreenShot(const RuntimeScriptValue *params, int32_t param_count)
649 {
650 API_SCALL_OBJAUTO_PINT2(ScriptDynamicSprite, DynamicSprite_CreateFromScreenShot);
651 }
652
653
RegisterDynamicSpriteAPI()654 void RegisterDynamicSpriteAPI()
655 {
656 ccAddExternalObjectFunction("DynamicSprite::ChangeCanvasSize^4", Sc_DynamicSprite_ChangeCanvasSize);
657 ccAddExternalObjectFunction("DynamicSprite::CopyTransparencyMask^1", Sc_DynamicSprite_CopyTransparencyMask);
658 ccAddExternalObjectFunction("DynamicSprite::Crop^4", Sc_DynamicSprite_Crop);
659 ccAddExternalObjectFunction("DynamicSprite::Delete", Sc_DynamicSprite_Delete);
660 ccAddExternalObjectFunction("DynamicSprite::Flip^1", Sc_DynamicSprite_Flip);
661 ccAddExternalObjectFunction("DynamicSprite::GetDrawingSurface^0", Sc_DynamicSprite_GetDrawingSurface);
662 ccAddExternalObjectFunction("DynamicSprite::Resize^2", Sc_DynamicSprite_Resize);
663 ccAddExternalObjectFunction("DynamicSprite::Rotate^3", Sc_DynamicSprite_Rotate);
664 ccAddExternalObjectFunction("DynamicSprite::SaveToFile^1", Sc_DynamicSprite_SaveToFile);
665 ccAddExternalObjectFunction("DynamicSprite::Tint^5", Sc_DynamicSprite_Tint);
666 ccAddExternalObjectFunction("DynamicSprite::get_ColorDepth", Sc_DynamicSprite_GetColorDepth);
667 ccAddExternalObjectFunction("DynamicSprite::get_Graphic", Sc_DynamicSprite_GetGraphic);
668 ccAddExternalObjectFunction("DynamicSprite::get_Height", Sc_DynamicSprite_GetHeight);
669 ccAddExternalObjectFunction("DynamicSprite::get_Width", Sc_DynamicSprite_GetWidth);
670 ccAddExternalStaticFunction("DynamicSprite::Create^3", Sc_DynamicSprite_Create);
671 ccAddExternalStaticFunction("DynamicSprite::CreateFromBackground", Sc_DynamicSprite_CreateFromBackground);
672 ccAddExternalStaticFunction("DynamicSprite::CreateFromDrawingSurface^5", Sc_DynamicSprite_CreateFromDrawingSurface);
673 ccAddExternalStaticFunction("DynamicSprite::CreateFromExistingSprite^1", Sc_DynamicSprite_CreateFromExistingSprite_Old);
674 ccAddExternalStaticFunction("DynamicSprite::CreateFromExistingSprite^2", Sc_DynamicSprite_CreateFromExistingSprite);
675 ccAddExternalStaticFunction("DynamicSprite::CreateFromFile", Sc_DynamicSprite_CreateFromFile);
676 ccAddExternalStaticFunction("DynamicSprite::CreateFromSaveGame", Sc_DynamicSprite_CreateFromSaveGame);
677 ccAddExternalStaticFunction("DynamicSprite::CreateFromScreenShot", Sc_DynamicSprite_CreateFromScreenShot);
678
679 /* ----------------------- Registering unsafe exports for plugins -----------------------*/
680
681 ccAddExternalFunctionForPlugin("DynamicSprite::ChangeCanvasSize^4", (void*)DynamicSprite_ChangeCanvasSize);
682 ccAddExternalFunctionForPlugin("DynamicSprite::CopyTransparencyMask^1", (void*)DynamicSprite_CopyTransparencyMask);
683 ccAddExternalFunctionForPlugin("DynamicSprite::Crop^4", (void*)DynamicSprite_Crop);
684 ccAddExternalFunctionForPlugin("DynamicSprite::Delete", (void*)DynamicSprite_Delete);
685 ccAddExternalFunctionForPlugin("DynamicSprite::Flip^1", (void*)DynamicSprite_Flip);
686 ccAddExternalFunctionForPlugin("DynamicSprite::GetDrawingSurface^0", (void*)DynamicSprite_GetDrawingSurface);
687 ccAddExternalFunctionForPlugin("DynamicSprite::Resize^2", (void*)DynamicSprite_Resize);
688 ccAddExternalFunctionForPlugin("DynamicSprite::Rotate^3", (void*)DynamicSprite_Rotate);
689 ccAddExternalFunctionForPlugin("DynamicSprite::SaveToFile^1", (void*)DynamicSprite_SaveToFile);
690 ccAddExternalFunctionForPlugin("DynamicSprite::Tint^5", (void*)DynamicSprite_Tint);
691 ccAddExternalFunctionForPlugin("DynamicSprite::get_ColorDepth", (void*)DynamicSprite_GetColorDepth);
692 ccAddExternalFunctionForPlugin("DynamicSprite::get_Graphic", (void*)DynamicSprite_GetGraphic);
693 ccAddExternalFunctionForPlugin("DynamicSprite::get_Height", (void*)DynamicSprite_GetHeight);
694 ccAddExternalFunctionForPlugin("DynamicSprite::get_Width", (void*)DynamicSprite_GetWidth);
695 ccAddExternalFunctionForPlugin("DynamicSprite::Create^3", (void*)DynamicSprite_Create);
696 ccAddExternalFunctionForPlugin("DynamicSprite::CreateFromBackground", (void*)DynamicSprite_CreateFromBackground);
697 ccAddExternalFunctionForPlugin("DynamicSprite::CreateFromDrawingSurface^5", (void*)DynamicSprite_CreateFromDrawingSurface);
698 ccAddExternalFunctionForPlugin("DynamicSprite::CreateFromExistingSprite^1", (void*)DynamicSprite_CreateFromExistingSprite_Old);
699 ccAddExternalFunctionForPlugin("DynamicSprite::CreateFromExistingSprite^2", (void*)DynamicSprite_CreateFromExistingSprite);
700 ccAddExternalFunctionForPlugin("DynamicSprite::CreateFromFile", (void*)DynamicSprite_CreateFromFile);
701 ccAddExternalFunctionForPlugin("DynamicSprite::CreateFromSaveGame", (void*)DynamicSprite_CreateFromSaveGame);
702 ccAddExternalFunctionForPlugin("DynamicSprite::CreateFromScreenShot", (void*)DynamicSprite_CreateFromScreenShot);
703 }
704