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
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (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, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 /*
24 * This code is based on Broken Sword 2.5 engine
25 *
26 * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
27 *
28 * Licensed under GNU GPL v2
29 *
30 */
31
32 #include "sword25/kernel/common.h"
33 #include "sword25/kernel/kernel.h"
34 #include "sword25/script/script.h"
35 #include "sword25/script/luabindhelper.h"
36 #include "sword25/script/luacallback.h"
37 #include "sword25/math/vertex.h"
38
39 #include "sword25/gfx/graphicengine.h"
40 #include "sword25/gfx/renderobject.h"
41 #include "sword25/gfx/bitmap.h"
42 #include "sword25/gfx/animation.h"
43 #include "sword25/gfx/panel.h"
44 #include "sword25/gfx/text.h"
45 #include "sword25/gfx/animationtemplate.h"
46 #include "sword25/gfx/animationtemplateregistry.h"
47
48 namespace Sword25 {
49
50 static bool animationDeleteCallback(uint Data);
51 static bool animationActionCallback(uint Data);
52 static bool animationLoopPointCallback(uint Data);
53
54 namespace {
55 class ActionCallback : public LuaCallback {
56 public:
ActionCallback(lua_State * L)57 ActionCallback(lua_State *L) : LuaCallback(L) {}
58
59 Common::String Action;
60
61 protected:
PreFunctionInvokation(lua_State * L)62 virtual int PreFunctionInvokation(lua_State *L) {
63 lua_pushstring(L, Action.c_str());
64 return 1;
65 }
66 };
67
68 static LuaCallback *loopPointCallbackPtr = 0; // FIXME: should be turned into GraphicEngine member var
69 static ActionCallback *actionCallbackPtr = 0; // FIXME: should be turned into GraphicEngine member var
70 }
71
72 // Die Strings werden als #defines definiert um Stringkomposition zur Compilezeit zu erm�glichen.
73 #define RENDEROBJECT_CLASS_NAME "Gfx.RenderObject"
74 #define BITMAP_CLASS_NAME "Gfx.Bitmap"
75 #define PANEL_CLASS_NAME "Gfx.Panel"
76 #define TEXT_CLASS_NAME "Gfx.Text"
77 #define ANIMATION_CLASS_NAME "Gfx.Animation"
78 #define ANIMATION_TEMPLATE_CLASS_NAME "Gfx.AnimationTemplate"
79 static const char *GFX_LIBRARY_NAME = "Gfx";
80
newUintUserData(lua_State * L,uint value)81 static void newUintUserData(lua_State *L, uint value) {
82 void *userData = lua_newuserdata(L, sizeof(value));
83 memcpy(userData, &value, sizeof(value));
84 }
85
checkAnimationTemplate(lua_State * L,int idx=1)86 static AnimationTemplate *checkAnimationTemplate(lua_State *L, int idx = 1) {
87 // Der erste Parameter muss vom Typ userdata sein und die Metatable der Klasse Gfx.AnimationTemplate
88 uint animationTemplateHandle = *reinterpret_cast<uint *>(LuaBindhelper::my_checkudata(L, idx, ANIMATION_TEMPLATE_CLASS_NAME));
89 if (animationTemplateHandle != 0) {
90 AnimationTemplate *animationTemplatePtr = AnimationTemplateRegistry::instance().resolveHandle(animationTemplateHandle);
91 if (!animationTemplatePtr)
92 luaL_error(L, "The animation template with the handle %d does no longer exist.", animationTemplateHandle);
93 return animationTemplatePtr;
94 } else {
95 luaL_argcheck(L, 0, idx, "'" ANIMATION_TEMPLATE_CLASS_NAME "' expected");
96 return 0;
97 }
98 }
99
100
newAnimationTemplate(lua_State * L)101 static int newAnimationTemplate(lua_State *L) {
102 uint animationTemplateHandle = AnimationTemplate::create(luaL_checkstring(L, 1));
103 AnimationTemplate *animationTemplatePtr = AnimationTemplateRegistry::instance().resolveHandle(animationTemplateHandle);
104 if (animationTemplatePtr && animationTemplatePtr->isValid()) {
105 newUintUserData(L, animationTemplateHandle);
106 //luaL_getmetatable(L, ANIMATION_TEMPLATE_CLASS_NAME);
107 LuaBindhelper::getMetatable(L, ANIMATION_TEMPLATE_CLASS_NAME);
108 assert(!lua_isnil(L, -1));
109 lua_setmetatable(L, -2);
110 } else {
111 lua_pushnil(L);
112 }
113
114 return 1;
115 }
116
at_addFrame(lua_State * L)117 static int at_addFrame(lua_State *L) {
118 AnimationTemplate *pAT = checkAnimationTemplate(L);
119 pAT->addFrame(static_cast<int>(luaL_checknumber(L, 2)));
120 return 0;
121 }
122
at_setFrame(lua_State * L)123 static int at_setFrame(lua_State *L) {
124 AnimationTemplate *pAT = checkAnimationTemplate(L);
125 pAT->setFrame(static_cast<int>(luaL_checknumber(L, 2)), static_cast<int>(luaL_checknumber(L, 3)));
126 return 0;
127 }
128
animationTypeStringToNumber(const char * typeString,Animation::ANIMATION_TYPES & result)129 static bool animationTypeStringToNumber(const char *typeString, Animation::ANIMATION_TYPES &result) {
130 if (strcmp(typeString, "jojo") == 0) {
131 result = Animation::AT_JOJO;
132 return true;
133 } else if (strcmp(typeString, "loop") == 0) {
134 result = Animation::AT_LOOP;
135 return true;
136 } else if (strcmp(typeString, "oneshot") == 0) {
137 result = Animation::AT_ONESHOT;
138 return true;
139 } else
140 return false;
141 }
142
at_setAnimationType(lua_State * L)143 static int at_setAnimationType(lua_State *L) {
144 AnimationTemplate *pAT = checkAnimationTemplate(L);
145 Animation::ANIMATION_TYPES animationType;
146 if (animationTypeStringToNumber(luaL_checkstring(L, 2), animationType)) {
147 pAT->setAnimationType(animationType);
148 } else {
149 luaL_argcheck(L, 0, 2, "Invalid animation type");
150 }
151
152 return 0;
153 }
154
at_setFPS(lua_State * L)155 static int at_setFPS(lua_State *L) {
156 AnimationTemplate *pAT = checkAnimationTemplate(L);
157 pAT->setFPS(static_cast<int>(luaL_checknumber(L, 2)));
158 return 0;
159 }
160
at_finalize(lua_State * L)161 static int at_finalize(lua_State *L) {
162 AnimationTemplate *pAT = checkAnimationTemplate(L);
163 delete pAT;
164 return 0;
165 }
166
167 static const luaL_reg ANIMATION_TEMPLATE_METHODS[] = {
168 {"AddFrame", at_addFrame},
169 {"SetFrame", at_setFrame},
170 {"SetAnimationType", at_setAnimationType},
171 {"SetFPS", at_setFPS},
172 {"__gc", at_finalize},
173 {0, 0}
174 };
175
getGE()176 static GraphicEngine *getGE() {
177 Kernel *pKernel = Kernel::getInstance();
178 assert(pKernel);
179 GraphicEngine *pGE = pKernel->getGfx();
180 assert(pGE);
181 return pGE;
182 }
183
init(lua_State * L)184 static int init(lua_State *L) {
185 GraphicEngine *pGE = getGE();
186
187 switch (lua_gettop(L)) {
188 case 0:
189 lua_pushbooleancpp(L, pGE->init());
190 break;
191 case 1:
192 lua_pushbooleancpp(L, pGE->init(static_cast<int>(luaL_checknumber(L, 1))));
193 break;
194 case 2:
195 lua_pushbooleancpp(L, pGE->init(static_cast<int>(luaL_checknumber(L, 1)), static_cast<int>(luaL_checknumber(L, 2))));
196 break;
197 case 3:
198 lua_pushbooleancpp(L, pGE->init(static_cast<int>(luaL_checknumber(L, 1)), static_cast<int>(luaL_checknumber(L, 2)),
199 static_cast<int>(luaL_checknumber(L, 3))));
200 break;
201 case 4:
202 default:
203 lua_pushbooleancpp(L, pGE->init(static_cast<int>(luaL_checknumber(L, 1)), static_cast<int>(luaL_checknumber(L, 2)),
204 static_cast<int>(luaL_checknumber(L, 3)), static_cast<int>(luaL_checknumber(L, 4))));
205 break;
206 }
207
208
209 #ifdef DEBUG
210 int __startStackDepth = lua_gettop(L);
211 #endif
212
213 // Main-Panel zum Gfx-Modul hinzuf�gen
214 RenderObjectPtr<Panel> mainPanelPtr(getGE()->getMainPanel());
215 assert(mainPanelPtr.isValid());
216
217 lua_pushstring(L, GFX_LIBRARY_NAME);
218 lua_gettable(L, LUA_GLOBALSINDEX);
219 assert(!lua_isnil(L, -1));
220
221 newUintUserData(L, mainPanelPtr->getHandle());
222 assert(!lua_isnil(L, -1));
223 // luaL_getmetatable(L, PANEL_CLASS_NAME);
224 LuaBindhelper::getMetatable(L, PANEL_CLASS_NAME);
225 assert(!lua_isnil(L, -1));
226 lua_setmetatable(L, -2);
227
228 lua_pushstring(L, "MainPanel");
229 lua_insert(L, -2);
230 lua_settable(L, -3);
231
232 lua_pop(L, 1);
233
234 #ifdef DEBUG
235 assert(__startStackDepth == lua_gettop(L));
236 #endif
237
238 return 1;
239 }
240
startFrame(lua_State * L)241 static int startFrame(lua_State *L) {
242 GraphicEngine *pGE = getGE();
243
244 if (lua_gettop(L) == 0)
245 lua_pushbooleancpp(L, pGE->startFrame());
246 else
247 lua_pushbooleancpp(L, pGE->startFrame(lua_tobooleancpp(L, 1)));
248
249 return 1;
250 }
251
endFrame(lua_State * L)252 static int endFrame(lua_State *L) {
253 GraphicEngine *pGE = getGE();
254
255 lua_pushbooleancpp(L, pGE->endFrame());
256
257 return 1;
258 }
259
getBitDepth(lua_State * L)260 static int getBitDepth(lua_State *L) {
261 GraphicEngine *pGE = getGE();
262
263 lua_pushnumber(L, pGE->getBitDepth());
264
265 return 1;
266 }
267
setVsync(lua_State * L)268 static int setVsync(lua_State *L) {
269 GraphicEngine *pGE = getGE();
270
271 pGE->setVsync(lua_tobooleancpp(L, 1));
272
273 return 0;
274 }
275
isVsync(lua_State * L)276 static int isVsync(lua_State *L) {
277 GraphicEngine *pGE = getGE();
278
279 lua_pushbooleancpp(L, pGE->getVsync());
280
281 return 1;
282 }
283
getLastFrameDuration(lua_State * L)284 static int getLastFrameDuration(lua_State *L) {
285 GraphicEngine *pGE = getGE();
286
287 lua_pushnumber(L, pGE->getLastFrameDuration());
288
289 return 1;
290 }
291
stopMainTimer(lua_State * L)292 static int stopMainTimer(lua_State *L) {
293 GraphicEngine *pGE = getGE();
294 pGE->stopMainTimer();
295 return 0;
296 }
297
resumeMainTimer(lua_State * L)298 static int resumeMainTimer(lua_State *L) {
299 GraphicEngine *pGE = getGE();
300 pGE->resumeMainTimer();
301 return 0;
302 }
303
getSecondaryFrameDuration(lua_State * L)304 static int getSecondaryFrameDuration(lua_State *L) {
305 GraphicEngine *pGE = getGE();
306
307 lua_pushnumber(L, pGE->getSecondaryFrameDuration());
308
309 return 1;
310 }
311
saveThumbnailScreenshot(lua_State * L)312 static int saveThumbnailScreenshot(lua_State *L) {
313 GraphicEngine *pGE = getGE();
314 lua_pushbooleancpp(L, pGE->saveThumbnailScreenshot(luaL_checkstring(L, 1)));
315 return 1;
316 }
317
318 // Marks a function that should never be used
dummyFuncError(lua_State * L)319 static int dummyFuncError(lua_State *L) {
320 error("Dummy function invoked by LUA");
321 return 1;
322 }
323
324 static const luaL_reg GFX_FUNCTIONS[] = {
325 {"Init", init},
326 {"StartFrame", startFrame},
327 {"EndFrame", endFrame},
328 {"DrawDebugLine", dummyFuncError},
329 {"SetVsync", setVsync},
330 {"GetDisplayWidth", dummyFuncError},
331 {"GetDisplayHeight", dummyFuncError},
332 {"GetBitDepth", getBitDepth},
333 {"IsVsync", isVsync},
334 {"IsWindowed", dummyFuncError},
335 {"GetFPSCount", dummyFuncError},
336 {"GetLastFrameDuration", getLastFrameDuration},
337 {"StopMainTimer", stopMainTimer},
338 {"ResumeMainTimer", resumeMainTimer},
339 {"GetSecondaryFrameDuration", getSecondaryFrameDuration},
340 {"SaveScreenshot", dummyFuncError},
341 {"NewAnimationTemplate", newAnimationTemplate},
342 {"GetRepaintedPixels", dummyFuncError},
343 {"SaveThumbnailScreenshot", saveThumbnailScreenshot},
344 {0, 0}
345 };
346
checkRenderObject(lua_State * L,bool errorIfRemoved=true)347 static RenderObjectPtr<RenderObject> checkRenderObject(lua_State *L, bool errorIfRemoved = true) {
348 // Der erste Parameter muss vom Typ userdata sein und die Metatable einer Klasse haben, die von Gfx.RenderObject "erbt".
349 uint *userDataPtr;
350 if ((userDataPtr = (uint *)LuaBindhelper::my_checkudata(L, 1, BITMAP_CLASS_NAME)) != 0 ||
351 (userDataPtr = (uint *)LuaBindhelper::my_checkudata(L, 1, ANIMATION_CLASS_NAME)) != 0 ||
352 (userDataPtr = (uint *)LuaBindhelper::my_checkudata(L, 1, PANEL_CLASS_NAME)) != 0 ||
353 (userDataPtr = (uint *)LuaBindhelper::my_checkudata(L, 1, TEXT_CLASS_NAME)) != 0) {
354 RenderObjectPtr<RenderObject> roPtr(*userDataPtr);
355 if (roPtr.isValid())
356 return roPtr;
357 else {
358 if (errorIfRemoved)
359 luaL_error(L, "The renderobject with the handle %d does no longer exist.", *userDataPtr);
360 }
361 } else {
362 luaL_argcheck(L, 0, 1, "'" RENDEROBJECT_CLASS_NAME "' expected");
363 }
364
365 return RenderObjectPtr<RenderObject>();
366 }
367
ro_setPos(lua_State * L)368 static int ro_setPos(lua_State *L) {
369 RenderObjectPtr<RenderObject> roPtr = checkRenderObject(L);
370 assert(roPtr.isValid());
371 Vertex pos;
372 Vertex::luaVertexToVertex(L, 2, pos);
373 roPtr->setPos(pos.x, pos.y);
374 return 0;
375 }
376
ro_setX(lua_State * L)377 static int ro_setX(lua_State *L) {
378 RenderObjectPtr<RenderObject> roPtr = checkRenderObject(L);
379 assert(roPtr.isValid());
380 roPtr->setX(static_cast<int>(luaL_checknumber(L, 2)));
381 return 0;
382 }
383
ro_setY(lua_State * L)384 static int ro_setY(lua_State *L) {
385 RenderObjectPtr<RenderObject> roPtr = checkRenderObject(L);
386 assert(roPtr.isValid());
387 roPtr->setY(static_cast<int>(luaL_checknumber(L, 2)));
388 return 0;
389 }
390
ro_setZ(lua_State * L)391 static int ro_setZ(lua_State *L) {
392 RenderObjectPtr<RenderObject> roPtr = checkRenderObject(L);
393 assert(roPtr.isValid());
394 roPtr->setZ(static_cast<int>(luaL_checknumber(L, 2)));
395 return 0;
396 }
397
ro_setVisible(lua_State * L)398 static int ro_setVisible(lua_State *L) {
399 RenderObjectPtr<RenderObject> roPtr = checkRenderObject(L);
400 assert(roPtr.isValid());
401 roPtr->setVisible(lua_tobooleancpp(L, 2));
402 return 0;
403 }
404
ro_getX(lua_State * L)405 static int ro_getX(lua_State *L) {
406 RenderObjectPtr<RenderObject> roPtr = checkRenderObject(L);
407 assert(roPtr.isValid());
408 lua_pushnumber(L, roPtr->getX());
409
410 return 1;
411 }
412
ro_getY(lua_State * L)413 static int ro_getY(lua_State *L) {
414 RenderObjectPtr<RenderObject> roPtr = checkRenderObject(L);
415 assert(roPtr.isValid());
416 lua_pushnumber(L, roPtr->getY());
417
418 return 1;
419 }
420
ro_getZ(lua_State * L)421 static int ro_getZ(lua_State *L) {
422 RenderObjectPtr<RenderObject> roPtr = checkRenderObject(L);
423 assert(roPtr.isValid());
424 lua_pushnumber(L, roPtr->getZ());
425
426 return 1;
427 }
428
ro_getAbsoluteX(lua_State * L)429 static int ro_getAbsoluteX(lua_State *L) {
430 RenderObjectPtr<RenderObject> roPtr = checkRenderObject(L);
431 assert(roPtr.isValid());
432 lua_pushnumber(L, roPtr->getAbsoluteX());
433
434 return 1;
435 }
436
ro_getAbsoluteY(lua_State * L)437 static int ro_getAbsoluteY(lua_State *L) {
438 RenderObjectPtr<RenderObject> roPtr = checkRenderObject(L);
439 assert(roPtr.isValid());
440 lua_pushnumber(L, roPtr->getAbsoluteY());
441
442 return 1;
443 }
444
ro_getWidth(lua_State * L)445 static int ro_getWidth(lua_State *L) {
446 RenderObjectPtr<RenderObject> roPtr = checkRenderObject(L);
447 assert(roPtr.isValid());
448 lua_pushnumber(L, roPtr->getWidth());
449
450 return 1;
451 }
452
ro_getHeight(lua_State * L)453 static int ro_getHeight(lua_State *L) {
454 RenderObjectPtr<RenderObject> roPtr = checkRenderObject(L);
455 assert(roPtr.isValid());
456 lua_pushnumber(L, roPtr->getHeight());
457
458 return 1;
459 }
460
ro_isVisible(lua_State * L)461 static int ro_isVisible(lua_State *L) {
462 RenderObjectPtr<RenderObject> roPtr = checkRenderObject(L);
463 assert(roPtr.isValid());
464 lua_pushbooleancpp(L, roPtr->isVisible());
465
466 return 1;
467 }
468
ro_addPanel(lua_State * L)469 static int ro_addPanel(lua_State *L) {
470 RenderObjectPtr<RenderObject> roPtr = checkRenderObject(L);
471 assert(roPtr.isValid());
472 RenderObjectPtr<Panel> panelPtr = roPtr->addPanel(static_cast<int>(luaL_checknumber(L, 2)),
473 static_cast<int>(luaL_checknumber(L, 3)),
474 GraphicEngine::luaColorToARGBColor(L, 4));
475 if (panelPtr.isValid()) {
476 newUintUserData(L, panelPtr->getHandle());
477 // luaL_getmetatable(L, PANEL_CLASS_NAME);
478 LuaBindhelper::getMetatable(L, PANEL_CLASS_NAME);
479 assert(!lua_isnil(L, -1));
480 lua_setmetatable(L, -2);
481 } else
482 lua_pushnil(L);
483
484 return 1;
485 }
486
ro_addBitmap(lua_State * L)487 static int ro_addBitmap(lua_State *L) {
488 RenderObjectPtr<RenderObject> roPtr = checkRenderObject(L);
489 assert(roPtr.isValid());
490 RenderObjectPtr<Bitmap> bitmaPtr = roPtr->addBitmap(luaL_checkstring(L, 2));
491 if (bitmaPtr.isValid()) {
492 newUintUserData(L, bitmaPtr->getHandle());
493 // luaL_getmetatable(L, BITMAP_CLASS_NAME);
494 LuaBindhelper::getMetatable(L, BITMAP_CLASS_NAME);
495 assert(!lua_isnil(L, -1));
496 lua_setmetatable(L, -2);
497 } else
498 lua_pushnil(L);
499
500 return 1;
501 }
502
ro_addText(lua_State * L)503 static int ro_addText(lua_State *L) {
504 RenderObjectPtr<RenderObject> roPtr = checkRenderObject(L);
505 assert(roPtr.isValid());
506
507 RenderObjectPtr<Text> textPtr;
508 if (lua_gettop(L) >= 3)
509 textPtr = roPtr->addText(luaL_checkstring(L, 2), luaL_checkstring(L, 3));
510 else
511 textPtr = roPtr->addText(luaL_checkstring(L, 2));
512
513 if (textPtr.isValid()) {
514 newUintUserData(L, textPtr->getHandle());
515 // luaL_getmetatable(L, TEXT_CLASS_NAME);
516 LuaBindhelper::getMetatable(L, TEXT_CLASS_NAME);
517 assert(!lua_isnil(L, -1));
518 lua_setmetatable(L, -2);
519 } else
520 lua_pushnil(L);
521
522 return 1;
523 }
524
ro_addAnimation(lua_State * L)525 static int ro_addAnimation(lua_State *L) {
526 RenderObjectPtr<RenderObject> roPtr = checkRenderObject(L);
527 assert(roPtr.isValid());
528
529 RenderObjectPtr<Animation> animationPtr;
530 if (lua_type(L, 2) == LUA_TUSERDATA)
531 animationPtr = roPtr->addAnimation(*checkAnimationTemplate(L, 2));
532 else
533 animationPtr = roPtr->addAnimation(luaL_checkstring(L, 2));
534
535 if (animationPtr.isValid()) {
536 newUintUserData(L, animationPtr->getHandle());
537 // luaL_getmetatable(L, ANIMATION_CLASS_NAME);
538 LuaBindhelper::getMetatable(L, ANIMATION_CLASS_NAME);
539 assert(!lua_isnil(L, -1));
540 lua_setmetatable(L, -2);
541
542 // Alle Animationscallbacks registrieren.
543 animationPtr->setCallbacks();
544 } else
545 lua_pushnil(L);
546
547 return 1;
548 }
549
setCallbacks()550 void Animation::setCallbacks() {
551 _actionCallback = animationActionCallback;
552 _loopPointCallback = animationLoopPointCallback;
553 _deleteCallback = animationDeleteCallback;
554 }
555
556 static const luaL_reg RENDEROBJECT_METHODS[] = {
557 {"AddAnimation", ro_addAnimation},
558 {"AddText", ro_addText},
559 {"AddBitmap", ro_addBitmap},
560 {"AddPanel", ro_addPanel},
561 {"SetPos", ro_setPos},
562 {"SetX", ro_setX},
563 {"SetY", ro_setY},
564 {"SetZ", ro_setZ},
565 {"SetVisible", ro_setVisible},
566 {"GetX", ro_getX},
567 {"GetY", ro_getY},
568 {"GetZ", ro_getZ},
569 {"GetAbsoluteX", ro_getAbsoluteX},
570 {"GetAbsoluteY", ro_getAbsoluteY},
571 {"GetWidth", ro_getWidth},
572 {"GetHeight", ro_getHeight},
573 {"IsVisible", ro_isVisible},
574 {0, 0}
575 };
576
checkPanel(lua_State * L)577 static RenderObjectPtr<Panel> checkPanel(lua_State *L) {
578 // Der erste Parameter muss vom Typ userdata sein und die Metatable der Klasse Gfx.Panel
579 uint *userDataPtr;
580 if ((userDataPtr = (uint *)LuaBindhelper::my_checkudata(L, 1, PANEL_CLASS_NAME)) != 0) {
581 RenderObjectPtr<RenderObject> roPtr(*userDataPtr);
582 if (roPtr.isValid())
583 return roPtr->toPanel();
584 else
585 luaL_error(L, "The panel with the handle %d does no longer exist.", *userDataPtr);
586 } else {
587 luaL_argcheck(L, 0, 1, "'" PANEL_CLASS_NAME "' expected");
588 }
589
590 return RenderObjectPtr<Panel>();
591 }
592
p_getColor(lua_State * L)593 static int p_getColor(lua_State *L) {
594 RenderObjectPtr<Panel> PanelPtr = checkPanel(L);
595 assert(PanelPtr.isValid());
596 GraphicEngine::ARGBColorToLuaColor(L, PanelPtr->getColor());
597
598 return 1;
599 }
600
p_setColor(lua_State * L)601 static int p_setColor(lua_State *L) {
602 RenderObjectPtr<Panel> PanelPtr = checkPanel(L);
603 assert(PanelPtr.isValid());
604 PanelPtr->setColor(GraphicEngine::luaColorToARGBColor(L, 2));
605 return 0;
606 }
607
p_remove(lua_State * L)608 static int p_remove(lua_State *L) {
609 RenderObjectPtr<RenderObject> roPtr = checkRenderObject(L);
610 assert(roPtr.isValid());
611 roPtr.erase();
612 return 0;
613 }
614
615 static const luaL_reg PANEL_METHODS[] = {
616 {"GetColor", p_getColor},
617 {"SetColor", p_setColor},
618 {"Remove", p_remove},
619 {0, 0}
620 };
621
checkBitmap(lua_State * L)622 static RenderObjectPtr<Bitmap> checkBitmap(lua_State *L) {
623 // Der erste Parameter muss vom Typ userdata sein und die Metatable der Klasse Gfx.Bitmap
624 uint *userDataPtr;
625 if ((userDataPtr = (uint *)LuaBindhelper::my_checkudata(L, 1, BITMAP_CLASS_NAME)) != 0) {
626 RenderObjectPtr<RenderObject> roPtr(*userDataPtr);
627 if (roPtr.isValid())
628 return roPtr->toBitmap();
629 else
630 luaL_error(L, "The bitmap with the handle %d does no longer exist.", *userDataPtr);
631 } else {
632 luaL_argcheck(L, 0, 1, "'" BITMAP_CLASS_NAME "' expected");
633 }
634
635 return RenderObjectPtr<Bitmap>();
636 }
637
b_setAlpha(lua_State * L)638 static int b_setAlpha(lua_State *L) {
639 RenderObjectPtr<Bitmap> bitmapPtr = checkBitmap(L);
640 assert(bitmapPtr.isValid());
641 bitmapPtr->setAlpha(static_cast<uint>(luaL_checknumber(L, 2)));
642 return 0;
643 }
644
b_setTintColor(lua_State * L)645 static int b_setTintColor(lua_State *L) {
646 RenderObjectPtr<Bitmap> bitmapPtr = checkBitmap(L);
647 assert(bitmapPtr.isValid());
648 bitmapPtr->setModulationColor(GraphicEngine::luaColorToARGBColor(L, 2));
649 return 0;
650 }
651
b_setScaleFactor(lua_State * L)652 static int b_setScaleFactor(lua_State *L) {
653 RenderObjectPtr<Bitmap> bitmapPtr = checkBitmap(L);
654 assert(bitmapPtr.isValid());
655 bitmapPtr->setScaleFactor(static_cast<float>(luaL_checknumber(L, 2)));
656 return 0;
657 }
658
b_setScaleFactorX(lua_State * L)659 static int b_setScaleFactorX(lua_State *L) {
660 RenderObjectPtr<Bitmap> bitmapPtr = checkBitmap(L);
661 assert(bitmapPtr.isValid());
662 bitmapPtr->setScaleFactorX(static_cast<float>(luaL_checknumber(L, 2)));
663 return 0;
664 }
665
b_setScaleFactorY(lua_State * L)666 static int b_setScaleFactorY(lua_State *L) {
667 RenderObjectPtr<Bitmap> bitmapPtr = checkBitmap(L);
668 assert(bitmapPtr.isValid());
669 bitmapPtr->setScaleFactorY(static_cast<float>(luaL_checknumber(L, 2)));
670 return 0;
671 }
672
b_setFlipH(lua_State * L)673 static int b_setFlipH(lua_State *L) {
674 RenderObjectPtr<Bitmap> bitmapPtr = checkBitmap(L);
675 assert(bitmapPtr.isValid());
676 bitmapPtr->setFlipH(lua_tobooleancpp(L, 2));
677 return 0;
678 }
679
b_setFlipV(lua_State * L)680 static int b_setFlipV(lua_State *L) {
681 RenderObjectPtr<Bitmap> bitmapPtr = checkBitmap(L);
682 assert(bitmapPtr.isValid());
683 bitmapPtr->setFlipV(lua_tobooleancpp(L, 2));
684 return 0;
685 }
686
b_getAlpha(lua_State * L)687 static int b_getAlpha(lua_State *L) {
688 RenderObjectPtr<Bitmap> bitmapPtr = checkBitmap(L);
689 assert(bitmapPtr.isValid());
690 lua_pushnumber(L, bitmapPtr->getAlpha());
691 return 1;
692 }
693
b_getTintColor(lua_State * L)694 static int b_getTintColor(lua_State *L) {
695 RenderObjectPtr<Bitmap> bitmapPtr = checkBitmap(L);
696 assert(bitmapPtr.isValid());
697 GraphicEngine::ARGBColorToLuaColor(L, bitmapPtr->getModulationColor());
698 return 1;
699 }
700
b_getScaleFactorX(lua_State * L)701 static int b_getScaleFactorX(lua_State *L) {
702 RenderObjectPtr<Bitmap> bitmapPtr = checkBitmap(L);
703 assert(bitmapPtr.isValid());
704 lua_pushnumber(L, bitmapPtr->getScaleFactorX());
705 return 1;
706 }
707
b_getScaleFactorY(lua_State * L)708 static int b_getScaleFactorY(lua_State *L) {
709 RenderObjectPtr<Bitmap> bitmapPtr = checkBitmap(L);
710 assert(bitmapPtr.isValid());
711 lua_pushnumber(L, bitmapPtr->getScaleFactorY());
712 return 1;
713 }
714
b_isFlipH(lua_State * L)715 static int b_isFlipH(lua_State *L) {
716 RenderObjectPtr<Bitmap> bitmapPtr = checkBitmap(L);
717 assert(bitmapPtr.isValid());
718 lua_pushbooleancpp(L, bitmapPtr->isFlipH());
719 return 1;
720 }
721
b_isFlipV(lua_State * L)722 static int b_isFlipV(lua_State *L) {
723 RenderObjectPtr<Bitmap> bitmapPtr = checkBitmap(L);
724 assert(bitmapPtr.isValid());
725 lua_pushbooleancpp(L, bitmapPtr->isFlipV());
726 return 1;
727 }
728
b_getPixel(lua_State * L)729 static int b_getPixel(lua_State *L) {
730 RenderObjectPtr<Bitmap> bitmapPtr = checkBitmap(L);
731 assert(bitmapPtr.isValid());
732 Vertex Pos;
733 Vertex::luaVertexToVertex(L, 2, Pos);
734 GraphicEngine::ARGBColorToLuaColor(L, bitmapPtr->getPixel(Pos.x, Pos.y));
735 return 1;
736 }
737
b_remove(lua_State * L)738 static int b_remove(lua_State *L) {
739 RenderObjectPtr<RenderObject> roPtr = checkRenderObject(L);
740 assert(roPtr.isValid());
741 roPtr.erase();
742 return 0;
743 }
744
745 static const luaL_reg BITMAP_METHODS[] = {
746 {"SetAlpha", b_setAlpha},
747 {"SetTintColor", b_setTintColor},
748 {"SetScaleFactor", b_setScaleFactor},
749 {"SetScaleFactorX", b_setScaleFactorX},
750 {"SetScaleFactorY", b_setScaleFactorY},
751 {"SetFlipH", b_setFlipH},
752 {"SetFlipV", b_setFlipV},
753 {"GetAlpha", b_getAlpha},
754 {"GetTintColor", b_getTintColor},
755 {"GetScaleFactorX", b_getScaleFactorX},
756 {"GetScaleFactorY", b_getScaleFactorY},
757 {"IsFlipH", b_isFlipH},
758 {"IsFlipV", b_isFlipV},
759 {"GetPixel", b_getPixel},
760 {"IsScalingAllowed", dummyFuncError},
761 {"IsAlphaAllowed", dummyFuncError},
762 {"IsTintingAllowed", dummyFuncError},
763 {"Remove", b_remove},
764 {0, 0}
765 };
766
checkAnimation(lua_State * L)767 static RenderObjectPtr<Animation> checkAnimation(lua_State *L) {
768 // Der erste Parameter muss vom Typ userdata sein und die Metatable der Klasse Gfx.Animation
769 uint *userDataPtr;
770 if ((userDataPtr = (uint *)LuaBindhelper::my_checkudata(L, 1, ANIMATION_CLASS_NAME)) != 0) {
771 RenderObjectPtr<RenderObject> roPtr(*userDataPtr);
772 if (roPtr.isValid())
773 return roPtr->toAnimation();
774 else
775 luaL_error(L, "The animation with the handle %d does no longer exist.", *userDataPtr);
776 } else {
777 luaL_argcheck(L, 0, 1, "'" ANIMATION_CLASS_NAME "' expected");
778 }
779
780 return RenderObjectPtr<Animation>();
781 }
782
a_play(lua_State * L)783 static int a_play(lua_State *L) {
784 RenderObjectPtr<Animation> animationPtr = checkAnimation(L);
785 assert(animationPtr.isValid());
786 animationPtr->play();
787 return 0;
788 }
789
a_pause(lua_State * L)790 static int a_pause(lua_State *L) {
791 RenderObjectPtr<Animation> animationPtr = checkAnimation(L);
792 assert(animationPtr.isValid());
793 animationPtr->pause();
794 return 0;
795 }
796
a_stop(lua_State * L)797 static int a_stop(lua_State *L) {
798 RenderObjectPtr<Animation> animationPtr = checkAnimation(L);
799 assert(animationPtr.isValid());
800 animationPtr->stop();
801 return 0;
802 }
803
a_setFrame(lua_State * L)804 static int a_setFrame(lua_State *L) {
805 RenderObjectPtr<Animation> animationPtr = checkAnimation(L);
806 assert(animationPtr.isValid());
807 animationPtr->setFrame(static_cast<uint>(luaL_checknumber(L, 2)));
808 return 0;
809 }
810
a_setAlpha(lua_State * L)811 static int a_setAlpha(lua_State *L) {
812 RenderObjectPtr<Animation> animationPtr = checkAnimation(L);
813 assert(animationPtr.isValid());
814 animationPtr->setAlpha(static_cast<int>(luaL_checknumber(L, 2)));
815 return 0;
816 }
817
a_setTintColor(lua_State * L)818 static int a_setTintColor(lua_State *L) {
819 RenderObjectPtr<Animation> animationPtr = checkAnimation(L);
820 assert(animationPtr.isValid());
821 animationPtr->setModulationColor(GraphicEngine::luaColorToARGBColor(L, 2));
822 return 0;
823 }
824
a_setScaleFactor(lua_State * L)825 static int a_setScaleFactor(lua_State *L) {
826 RenderObjectPtr<Animation> animationPtr = checkAnimation(L);
827 assert(animationPtr.isValid());
828 animationPtr->setScaleFactor(static_cast<float>(luaL_checknumber(L, 2)));
829 return 0;
830 }
831
a_setScaleFactorX(lua_State * L)832 static int a_setScaleFactorX(lua_State *L) {
833 RenderObjectPtr<Animation> animationPtr = checkAnimation(L);
834 assert(animationPtr.isValid());
835 animationPtr->setScaleFactorX(static_cast<float>(luaL_checknumber(L, 2)));
836 return 0;
837 }
838
a_setScaleFactorY(lua_State * L)839 static int a_setScaleFactorY(lua_State *L) {
840 RenderObjectPtr<Animation> animationPtr = checkAnimation(L);
841 assert(animationPtr.isValid());
842 animationPtr->setScaleFactorY(static_cast<float>(luaL_checknumber(L, 2)));
843 return 0;
844 }
845
a_getScaleFactorX(lua_State * L)846 static int a_getScaleFactorX(lua_State *L) {
847 RenderObjectPtr<Animation> animationPtr = checkAnimation(L);
848 assert(animationPtr.isValid());
849 lua_pushnumber(L, animationPtr->getScaleFactorX());
850 return 1;
851 }
852
a_getScaleFactorY(lua_State * L)853 static int a_getScaleFactorY(lua_State *L) {
854 RenderObjectPtr<Animation> animationPtr = checkAnimation(L);
855 assert(animationPtr.isValid());
856 lua_pushnumber(L, animationPtr->getScaleFactorY());
857 return 1;
858 }
859
a_getAnimationType(lua_State * L)860 static int a_getAnimationType(lua_State *L) {
861 RenderObjectPtr<Animation> animationPtr = checkAnimation(L);
862 assert(animationPtr.isValid());
863 switch (animationPtr->getAnimationType()) {
864 case Animation::AT_JOJO:
865 lua_pushstring(L, "jojo");
866 break;
867 case Animation::AT_LOOP:
868 lua_pushstring(L, "loop");
869 break;
870 case Animation::AT_ONESHOT:
871 lua_pushstring(L, "oneshot");
872 break;
873 default:
874 assert(false);
875 }
876 return 1;
877 }
878
a_getFPS(lua_State * L)879 static int a_getFPS(lua_State *L) {
880 RenderObjectPtr<Animation> animationPtr = checkAnimation(L);
881 assert(animationPtr.isValid());
882 lua_pushnumber(L, animationPtr->getFPS());
883 return 1;
884 }
885
a_getFrameCount(lua_State * L)886 static int a_getFrameCount(lua_State *L) {
887 RenderObjectPtr<Animation> animationPtr = checkAnimation(L);
888 assert(animationPtr.isValid());
889 lua_pushnumber(L, animationPtr->getFrameCount());
890 return 1;
891 }
892
a_isScalingAllowed(lua_State * L)893 static int a_isScalingAllowed(lua_State *L) {
894 RenderObjectPtr<Animation> animationPtr = checkAnimation(L);
895 assert(animationPtr.isValid());
896 lua_pushbooleancpp(L, animationPtr->isScalingAllowed());
897 return 1;
898 }
899
a_isAlphaAllowed(lua_State * L)900 static int a_isAlphaAllowed(lua_State *L) {
901 RenderObjectPtr<Animation> animationPtr = checkAnimation(L);
902 assert(animationPtr.isValid());
903 lua_pushbooleancpp(L, animationPtr->isAlphaAllowed());
904 return 1;
905 }
906
a_isTintingAllowed(lua_State * L)907 static int a_isTintingAllowed(lua_State *L) {
908 RenderObjectPtr<Animation> animationPtr = checkAnimation(L);
909 assert(animationPtr.isValid());
910 lua_pushbooleancpp(L, animationPtr->isColorModulationAllowed());
911 return 1;
912 }
913
a_getCurrentFrame(lua_State * L)914 static int a_getCurrentFrame(lua_State *L) {
915 RenderObjectPtr<Animation> animationPtr = checkAnimation(L);
916 assert(animationPtr.isValid());
917 lua_pushnumber(L, animationPtr->getCurrentFrame());
918 return 1;
919 }
920
a_getCurrentAction(lua_State * L)921 static int a_getCurrentAction(lua_State *L) {
922 RenderObjectPtr<Animation> animationPtr = checkAnimation(L);
923 assert(animationPtr.isValid());
924 lua_pushstring(L, animationPtr->getCurrentAction().c_str());
925 return 1;
926 }
927
a_isPlaying(lua_State * L)928 static int a_isPlaying(lua_State *L) {
929 RenderObjectPtr<Animation> animationPtr = checkAnimation(L);
930 assert(animationPtr.isValid());
931 lua_pushbooleancpp(L, animationPtr->isRunning());
932 return 1;
933 }
934
animationLoopPointCallback(uint handle)935 static bool animationLoopPointCallback(uint handle) {
936 lua_State *L = static_cast<lua_State *>(Kernel::getInstance()->getScript()->getScriptObject());
937 loopPointCallbackPtr->invokeCallbackFunctions(L, handle);
938
939 return true;
940 }
941
a_registerLoopPointCallback(lua_State * L)942 static int a_registerLoopPointCallback(lua_State *L) {
943 RenderObjectPtr<Animation> animationPtr = checkAnimation(L);
944 assert(animationPtr.isValid());
945 luaL_checktype(L, 2, LUA_TFUNCTION);
946
947 lua_pushvalue(L, 2);
948 loopPointCallbackPtr->registerCallbackFunction(L, animationPtr->getHandle());
949
950 return 0;
951 }
952
a_unregisterLoopPointCallback(lua_State * L)953 static int a_unregisterLoopPointCallback(lua_State *L) {
954 RenderObjectPtr<Animation> animationPtr = checkAnimation(L);
955 assert(animationPtr.isValid());
956 luaL_checktype(L, 2, LUA_TFUNCTION);
957
958 lua_pushvalue(L, 2);
959 loopPointCallbackPtr->unregisterCallbackFunction(L, animationPtr->getHandle());
960
961 return 0;
962 }
963
animationActionCallback(uint Handle)964 static bool animationActionCallback(uint Handle) {
965 RenderObjectPtr<Animation> animationPtr(Handle);
966 if (animationPtr.isValid()) {
967 actionCallbackPtr->Action = animationPtr->getCurrentAction();
968 lua_State *L = static_cast<lua_State *>(Kernel::getInstance()->getScript()->getScriptObject());
969 actionCallbackPtr->invokeCallbackFunctions(L, animationPtr->getHandle());
970 }
971
972 return true;
973 }
974
a_registerActionCallback(lua_State * L)975 static int a_registerActionCallback(lua_State *L) {
976 RenderObjectPtr<Animation> animationPtr = checkAnimation(L);
977 assert(animationPtr.isValid());
978 luaL_checktype(L, 2, LUA_TFUNCTION);
979
980 lua_pushvalue(L, 2);
981 actionCallbackPtr->registerCallbackFunction(L, animationPtr->getHandle());
982
983 return 0;
984 }
985
a_unregisterActionCallback(lua_State * L)986 static int a_unregisterActionCallback(lua_State *L) {
987 RenderObjectPtr<Animation> animationPtr = checkAnimation(L);
988 assert(animationPtr.isValid());
989 luaL_checktype(L, 2, LUA_TFUNCTION);
990
991 lua_pushvalue(L, 2);
992 actionCallbackPtr->unregisterCallbackFunction(L, animationPtr->getHandle());
993
994 return 0;
995 }
996
animationDeleteCallback(uint Handle)997 static bool animationDeleteCallback(uint Handle) {
998 lua_State *L = static_cast<lua_State *>(Kernel::getInstance()->getScript()->getScriptObject());
999 loopPointCallbackPtr->removeAllObjectCallbacks(L, Handle);
1000
1001 return true;
1002 }
1003
a_remove(lua_State * L)1004 static int a_remove(lua_State *L) {
1005 RenderObjectPtr<Animation> animationPtr = checkAnimation(L);
1006 assert(animationPtr.isValid());
1007 animationPtr.erase();
1008 return 0;
1009 }
1010
1011 static const luaL_reg ANIMATION_METHODS[] = {
1012 {"Play", a_play},
1013 {"Pause", a_pause},
1014 {"Stop", a_stop},
1015 {"SetFrame", a_setFrame},
1016 {"SetAlpha", a_setAlpha},
1017 {"SetTintColor", a_setTintColor},
1018 {"SetScaleFactor", a_setScaleFactor},
1019 {"SetScaleFactorX", a_setScaleFactorX},
1020 {"SetScaleFactorY", a_setScaleFactorY},
1021 {"GetScaleFactorX", a_getScaleFactorX},
1022 {"GetScaleFactorY", a_getScaleFactorY},
1023 {"GetAnimationType", a_getAnimationType},
1024 {"GetFPS", a_getFPS},
1025 {"GetFrameCount", a_getFrameCount},
1026 {"IsScalingAllowed", a_isScalingAllowed},
1027 {"IsAlphaAllowed", a_isAlphaAllowed},
1028 {"IsTintingAllowed", a_isTintingAllowed},
1029 {"GetCurrentFrame", a_getCurrentFrame},
1030 {"GetCurrentAction", a_getCurrentAction},
1031 {"IsPlaying", a_isPlaying},
1032 {"RegisterLoopPointCallback", a_registerLoopPointCallback},
1033 {"UnregisterLoopPointCallback", a_unregisterLoopPointCallback},
1034 {"RegisterActionCallback", a_registerActionCallback},
1035 {"UnregisterActionCallback", a_unregisterActionCallback},
1036 {"Remove", a_remove},
1037 {0, 0}
1038 };
1039
checkText(lua_State * L)1040 static RenderObjectPtr<Text> checkText(lua_State *L) {
1041 // Der erste Parameter muss vom Typ userdata sein und die Metatable der Klasse Gfx.Text
1042 uint *userDataPtr;
1043 if ((userDataPtr = (uint *)LuaBindhelper::my_checkudata(L, 1, TEXT_CLASS_NAME)) != 0) {
1044 RenderObjectPtr<RenderObject> roPtr(*userDataPtr);
1045 if (roPtr.isValid())
1046 return roPtr->toText();
1047 else
1048 luaL_error(L, "The text with the handle %d does no longer exist.", *userDataPtr);
1049 } else {
1050 luaL_argcheck(L, 0, 1, "'" TEXT_CLASS_NAME "' expected");
1051 }
1052
1053 return RenderObjectPtr<Text>();
1054 }
1055
t_setFont(lua_State * L)1056 static int t_setFont(lua_State *L) {
1057 RenderObjectPtr<Text> textPtr = checkText(L);
1058 assert(textPtr.isValid());
1059 textPtr->setFont(luaL_checkstring(L, 2));
1060 return 0;
1061 }
1062
t_setText(lua_State * L)1063 static int t_setText(lua_State *L) {
1064 RenderObjectPtr<Text> textPtr = checkText(L);
1065 assert(textPtr.isValid());
1066 textPtr->setText(luaL_checkstring(L, 2));
1067 return 0;
1068 }
1069
t_setAlpha(lua_State * L)1070 static int t_setAlpha(lua_State *L) {
1071 RenderObjectPtr<Text> textPtr = checkText(L);
1072 assert(textPtr.isValid());
1073 textPtr->setAlpha(static_cast<int>(luaL_checknumber(L, 2)));
1074 return 0;
1075 }
1076
t_setColor(lua_State * L)1077 static int t_setColor(lua_State *L) {
1078 RenderObjectPtr<Text> textPtr = checkText(L);
1079 assert(textPtr.isValid());
1080 textPtr->setColor(GraphicEngine::luaColorToARGBColor(L, 2));
1081 return 0;
1082 }
1083
t_setAutoWrap(lua_State * L)1084 static int t_setAutoWrap(lua_State *L) {
1085 RenderObjectPtr<Text> textPtr = checkText(L);
1086 assert(textPtr.isValid());
1087 textPtr->setAutoWrap(lua_tobooleancpp(L, 2));
1088 return 0;
1089 }
1090
t_setAutoWrapThreshold(lua_State * L)1091 static int t_setAutoWrapThreshold(lua_State *L) {
1092 RenderObjectPtr<Text> textPtr = checkText(L);
1093 assert(textPtr.isValid());
1094 textPtr->setAutoWrapThreshold(static_cast<uint>(luaL_checknumber(L, 2)));
1095 return 0;
1096 }
1097
t_getText(lua_State * L)1098 static int t_getText(lua_State *L) {
1099 RenderObjectPtr<Text> textPtr = checkText(L);
1100 assert(textPtr.isValid());
1101 lua_pushstring(L, textPtr->getText().c_str());
1102 return 1;
1103 }
1104
t_getFont(lua_State * L)1105 static int t_getFont(lua_State *L) {
1106 RenderObjectPtr<Text> textPtr = checkText(L);
1107 assert(textPtr.isValid());
1108 lua_pushstring(L, textPtr->getFont().c_str());
1109 return 1;
1110 }
1111
t_getAlpha(lua_State * L)1112 static int t_getAlpha(lua_State *L) {
1113 RenderObjectPtr<Text> textPtr = checkText(L);
1114 assert(textPtr.isValid());
1115 lua_pushnumber(L, textPtr->getAlpha());
1116 return 1;
1117 }
1118
t_getColor(lua_State * L)1119 static int t_getColor(lua_State *L) {
1120 RenderObjectPtr<Text> textPtr = checkText(L);
1121 assert(textPtr.isValid());
1122 lua_pushnumber(L, textPtr->getColor());
1123 return 1;
1124 }
1125
t_isAutoWrap(lua_State * L)1126 static int t_isAutoWrap(lua_State *L) {
1127 RenderObjectPtr<Text> textPtr = checkText(L);
1128 assert(textPtr.isValid());
1129 lua_pushbooleancpp(L, textPtr->isAutoWrapActive());
1130 return 1;
1131 }
1132
t_getAutoWrapThreshold(lua_State * L)1133 static int t_getAutoWrapThreshold(lua_State *L) {
1134 RenderObjectPtr<Text> textPtr = checkText(L);
1135 assert(textPtr.isValid());
1136 lua_pushnumber(L, textPtr->getAutoWrapThreshold());
1137 return 1;
1138 }
1139
t_remove(lua_State * L)1140 static int t_remove(lua_State *L) {
1141 RenderObjectPtr<Text> textPtr = checkText(L);
1142 assert(textPtr.isValid());
1143 textPtr.erase();
1144 return 0;
1145 }
1146
1147 static const luaL_reg TEXT_METHODS[] = {
1148 {"SetFont", t_setFont},
1149 {"SetText", t_setText},
1150 {"SetAlpha", t_setAlpha},
1151 {"SetColor", t_setColor},
1152 {"SetAutoWrap", t_setAutoWrap},
1153 {"SetAutoWrapThreshold", t_setAutoWrapThreshold},
1154 {"GetText", t_getText},
1155 {"GetFont", t_getFont},
1156 {"GetAlpha", t_getAlpha},
1157 {"GetColor", t_getColor},
1158 {"IsAutoWrap", t_isAutoWrap},
1159 {"GetAutoWrapThreshold", t_getAutoWrapThreshold},
1160 {"Remove", t_remove},
1161 {0, 0}
1162 };
1163
registerScriptBindings()1164 bool GraphicEngine::registerScriptBindings() {
1165 Kernel *pKernel = Kernel::getInstance();
1166 assert(pKernel);
1167 ScriptEngine *pScript = pKernel->getScript();
1168 assert(pScript);
1169 lua_State *L = static_cast<lua_State *>(pScript->getScriptObject());
1170 assert(L);
1171
1172 if (!LuaBindhelper::addMethodsToClass(L, BITMAP_CLASS_NAME, RENDEROBJECT_METHODS)) return false;
1173 if (!LuaBindhelper::addMethodsToClass(L, ANIMATION_CLASS_NAME, RENDEROBJECT_METHODS)) return false;
1174 if (!LuaBindhelper::addMethodsToClass(L, PANEL_CLASS_NAME, RENDEROBJECT_METHODS)) return false;
1175 if (!LuaBindhelper::addMethodsToClass(L, TEXT_CLASS_NAME, RENDEROBJECT_METHODS)) return false;
1176
1177 if (!LuaBindhelper::addMethodsToClass(L, PANEL_CLASS_NAME, PANEL_METHODS)) return false;
1178 if (!LuaBindhelper::addMethodsToClass(L, BITMAP_CLASS_NAME, BITMAP_METHODS)) return false;
1179 if (!LuaBindhelper::addMethodsToClass(L, TEXT_CLASS_NAME, TEXT_METHODS)) return false;
1180 if (!LuaBindhelper::addMethodsToClass(L, ANIMATION_CLASS_NAME, ANIMATION_METHODS)) return false;
1181
1182 if (!LuaBindhelper::addMethodsToClass(L, ANIMATION_TEMPLATE_CLASS_NAME, ANIMATION_TEMPLATE_METHODS)) return false;
1183
1184 if (!LuaBindhelper::addFunctionsToLib(L, GFX_LIBRARY_NAME, GFX_FUNCTIONS)) return false;
1185
1186 assert(loopPointCallbackPtr == 0);
1187 loopPointCallbackPtr = new LuaCallback(L);
1188
1189 assert(actionCallbackPtr == 0);
1190 actionCallbackPtr = new ActionCallback(L);
1191
1192 return true;
1193 }
1194
unregisterScriptBindings()1195 void GraphicEngine::unregisterScriptBindings() {
1196 delete loopPointCallbackPtr;
1197 loopPointCallbackPtr = 0;
1198
1199 delete actionCallbackPtr;
1200 actionCallbackPtr = 0;
1201 }
1202
1203 } // End of namespace Sword25
1204