Project

General

Profile

SO3Engine
SCOLBitmapWidget.cpp
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2012 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21
22-----------------------------------------------------------------------------
23*/
24
25
34#include "SCOLPack/SO3SCOL.h"
35
36// Renderer includes
38#include "SO3Renderer/SO3Root.h"
41
42// Scene Graph includes
44
45
61int SO3BitmapWidgetCreate(mmachine m)
62{
63#ifdef SO3_DEBUG
64 MMechostr(MSKDEBUG, "SO3BitmapWidgetCreate\n");
65#endif
66 int z = MTOI(MMpull(m));
67 int h = MTOI(MMpull(m));
68 int w = MTOI(MMpull(m));
69 int topPos = MTOI(MMpull(m));
70 int leftPos = MTOI(MMpull(m));
71 int nam = MMpull(m);
72 int vp = MMpull(m);
73 int s = MMget(m, 0);
74
75 if ((s == NIL) || (vp == NIL) || (nam == NIL) || (w == NIL) || (h == NIL))
76 {
77 MMset(m, 0, NIL);
78 return 0;
79 }
80
81 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
82 if (scene == 0)
83 {
84 MMset(m, 0, NIL);
85 return 0;
86 }
87
88 SViewPort* viewport = MMgetPointer<SViewPort*>(m, MTOP(vp));
89 if (viewport == 0)
90 {
91 MMechostr(MSKDEBUG, "vp is NULL \n");
92 MMset(m, 0, NIL);
93 return 0;
94 }
95
96 std::string name(MMstartstr(m, MTOP(nam)));
97 if (name.empty())
98 {
99 MMechostr(MSKDEBUG, "name is NULL \n");
100 MMset(m, 0, NIL);
101 return 0;
102 }
103
104 SBitmapWidget* bitmapWidget = 0;
105 unsigned int zorder = 0;
106 if (z != NIL)
107 zorder = abs(z);
108
109 try
110 {
111 bitmapWidget = static_cast<SBitmapWidget*> (SWidgetManager::getSingleton().CreateWidget(scene, name, leftPos, topPos, w, h, viewport, zorder, SO3_BITMAP_WIDGET_TYPE));
112 }
113 catch (Ogre::Exception &e)
114 {
115 MMechostr(MSKDEBUG, "An exception has occurred while creating bitmap widget: %s\n", e.what());
116 MMset(m, 0, NIL);
117 return 0;
118 }
119
120 //get scene scol object
121 int p = OBJfindTH(m, SO3SCENETYPE, SCOL_PTR scene);
122 // push channel
123 MMset(m, 0, MMfetch(m, p, OFFOBJCHN));
124
125 if ((MMpushPointer(m, bitmapWidget) != 0))
126 {
127 SWidgetManager::getSingleton().DeleteWidget(bitmapWidget);
128 MMset(m, 0, NIL);
129 return MERRMEM;
130 }
131
132 return OBJcreate(m, SO3WIDGET, SCOL_PTR bitmapWidget, SO3VPTYPE, SCOL_PTR viewport);
133}
134
135
151{
152#ifdef SO3_DEBUG
153 MMechostr(MSKDEBUG, "SO3BitmapWidgetCreateBackground\n");
154#endif
155 int h = MTOI(MMpull(m));
156 int w = MTOI(MMpull(m));
157 int topPos = MTOI(MMpull(m));
158 int leftPos = MTOI(MMpull(m));
159 int nam = MMpull(m);
160 int vp = MMpull(m);
161 int s = MMget(m, 0);
162
163 if ((s == NIL) || (vp == NIL) || (nam == NIL) || (w == NIL) || (h == NIL))
164 {
165 MMset(m, 0, NIL);
166 return 0;
167 }
168
169 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
170 if (scene == 0)
171 {
172 MMset(m, 0, NIL);
173 return 0;
174 }
175
176 SViewPort* viewport = MMgetPointer<SViewPort*>(m, MTOP(vp));
177 if (viewport == 0)
178 {
179 MMechostr(MSKDEBUG, "vp is NULL \n");
180 MMset(m, 0, NIL);
181 return 0;
182 }
183
184 std::string name(MMstartstr(m, MTOP(nam)));
185 if (name.empty())
186 {
187 MMechostr(MSKDEBUG, "name is NULL \n");
188 MMset(m, 0, NIL);
189 return 0;
190 }
191
192 SBitmapWidget* bitmapWidget = 0;
193 try
194 {
195 bitmapWidget = static_cast<SBitmapWidget*> (SWidgetManager::getSingleton().CreateWidget(scene, name, leftPos, topPos, w, h, viewport, SO3_BITMAP_WIDGET_TYPE));
196 }
197 catch (Ogre::Exception &e)
198 {
199 MMechostr(MSKDEBUG, "An exception has occurred while creating bitmap widget: %s\n", e.what());
200 MMset(m, 0, NIL);
201 return 0;
202 }
203
204 //get scene scol object
205 int p = OBJfindTH(m, SO3SCENETYPE, SCOL_PTR scene);
206 // push channel
207 MMset(m, 0, MMfetch(m, p, OFFOBJCHN));
208
209 if ((MMpushPointer(m, bitmapWidget) != 0))
210 {
211 SWidgetManager::getSingleton().DeleteWidget(bitmapWidget);
212 MMset(m, 0, NIL);
213 return MERRMEM;
214 }
215
216 return OBJcreate(m, SO3WIDGET, SCOL_PTR bitmapWidget, SO3VPTYPE, SCOL_PTR viewport);
217}
218
219
237{
238#ifdef SO3_DEBUG
239 MMechostr(MSKDEBUG, "SO3BitmapWidgetCreateOnMaterial\n");
240#endif
241 int index = MTOI(MMpull(m));
242 int pass = MTOI(MMpull(m));
243 int tec = MTOI(MMpull(m));
244 int h = MMpull(m);
245 int w = MMpull(m);
246 int n = MMpull(m);
247 int mat = MMpull(m);
248 int s = MMget(m, 0);
249 if ((s == NIL) || (mat == NIL) || (tec == NIL) || (pass == NIL) || (index == NIL) || (w == NIL) || (h == NIL) || (n == NIL))
250 {
251 MMset(m, 0, NIL);
252 return 0;
253 }
254
255 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
256 if (scene == 0)
257 {
258 MMset(m, 0, NIL);
259 return 0;
260 }
261
262 SMaterial* material = MMgetPointer<SMaterial*>(m, MTOP(mat));
263 if (material == 0)
264 {
265 MMechostr(MSKDEBUG, "material==NULL\n");
266 MMset(m, 0, NIL);
267 return 0;
268 }
269
270 if (material->GetAssociatedWidget() != 0)
271 {
272 MMechostr(MSKDEBUG, "SO3BitmapWidgetCreateOnMaterial : %s already have a widget on it!\n", material->GetName().c_str());
273 MMset(m, 0, NIL);
274 return 0;
275 }
276
277 std::string name(MMstartstr(m, MTOP(n)));
278 if (name.empty())
279 {
280 MMechostr(MSKDEBUG, "name is NULL \n");
281 MMset(m, 0, NIL);
282 return 0;
283 }
284
285 if (!strcmp("BaseWhite", material->getOgreMaterialPointer()->getName().c_str()))
286 {
287 Ogre::LogManager::getSingleton().logMessage("Can't load Bitmap Control : Material BaseWhite is Protected!", Ogre::LML_CRITICAL, true);
288 MMechostr(MSKDEBUG, "Material BaseWhite is Protected \n");
289 MMset(m, 0, NIL);
290 return 0;
291 }
292
293 if (material->GetNumTechniques() < tec + 1)
294 {
295 Ogre::LogManager::getSingleton().logMessage("Can't load Bitmap widget : Material has not enough Technique! ", Ogre::LML_CRITICAL, true);
296 MMset(m, 0, NIL);
297 return 0;
298 }
299
300 if ((material->getOgreMaterialPointer()->getTechnique(tec)->getNumPasses()) < pass + 1)
301 {
302 Ogre::LogManager::getSingleton().logMessage("Can't load Bitmap widget : Material has not enough Pass! ", Ogre::LML_CRITICAL, true);
303 MMset(m, 0, NIL);
304 return 0;
305 }
306
307 if ((material->getOgreMaterialPointer()->getTechnique(tec)->getPass(pass)->getNumTextureUnitStates()) == 0)
308 {
309 Ogre::LogManager::getSingleton().logMessage("Can't load Bitmap widget : Material has not enough Texture! ", Ogre::LML_CRITICAL, true);
310 MMset(m, 0, NIL);
311 return 0;
312 }
313
314 if ((material->getOgreMaterialPointer()->getTechnique(tec)->getPass(pass)->getNumTextureUnitStates()) < index + 1)
315 {
316 Ogre::LogManager::getSingleton().logMessage("Can't load Bitmap widget : Material has not enough Texture! ", Ogre::LML_CRITICAL, true);
317 MMset(m, 0, NIL);
318 return 0;
319 }
320
321 SBitmapWidget* bitmapWidget = 0;
322 try
323 {
324 bitmapWidget = static_cast<SBitmapWidget*> (SWidgetManager::getSingleton().CreateWidget(scene, name, MTOI(w), MTOI(h), material, tec, pass, index, SO3_BITMAP_WIDGET_TYPE));
325 }
326 catch (Ogre::Exception &e)
327 {
328 MMechostr(MSKDEBUG, "An exception has occurred while creating bitmap widget: %s\n", e.what());
329 MMset(m, 0, NIL);
330 return 0;
331 }
332
333 //get scene scol object
334 int p = OBJfindTH(m, SO3SCENETYPE, SCOL_PTR scene);
335 // push channel
336 MMset(m, 0, MMfetch(m, p, OFFOBJCHN));
337
338 if ((MMpushPointer(m, bitmapWidget) != 0))
339 {
340 SWidgetManager::getSingleton().DeleteWidget(bitmapWidget);
341 MMset(m, 0, NIL);
342 return MERRMEM;
343 }
344
345 return OBJcreate(m, SO3WIDGET, SCOL_PTR bitmapWidget, SO3MATERIAL, SCOL_PTR material);
346}
347
348
358int SO3BitmapWidgetBlit(mmachine m)
359{
360#ifdef SO3_DEBUG
361 MMechostr(MSKDEBUG, "SO3BitmapWidgetBlit\n");
362#endif
363
364 int scolBitmap = MMpull(m);
365 int scolBitmapWidget = MMpull(m);
366 if ((scolBitmap == NIL) || (scolBitmapWidget == NIL))
367 {
368 MMpush(m, NIL);
369 return 0;
370 }
371
372 SWidget* widget = MMgetPointer<SWidget*>(m, MTOP(scolBitmapWidget));
373 if (widget == 0)
374 {
375 MMechostr(MSKDEBUG, "widget instance is NULL \n");
376 MMpush(m, NIL);
377 return 0;
378 }
379
380 PtrObjVoid scolVoidPointer = (PtrObjVoid)MMstart(m, MTOP(scolBitmap));
381 if (scolVoidPointer->Type != OBJ_TYPE_BITMAP << 1 || scolVoidPointer->Buffer == 0)
382 {
383 MMpush(m, NIL);
384 return 0;
385 }
386 PtrObjBitmap bitmap = (PtrObjBitmap)MMstart(m, MTOP(scolVoidPointer->Buffer));
387
388 if (bitmap->bits == 0)
389 {
390 MMpush(m, NIL);
391 return 0;
392 }
393
394 // Let's be sure that our widget is a bitmap control
395 if (widget->GetType() != SO3_BITMAP_WIDGET_TYPE)
396 {
397 MMechostr(MSKDEBUG, "bad widget type \n");
398 MMpush(m, NIL);
399 return 0;
400 }
401 SBitmapWidget* bitmapWidget = static_cast <SBitmapWidget*> (widget);
402
403 // update texture buffer
404 bitmapWidget->UpdateRawData(bitmap);
405 MMpush(m, ITOM(1));
406 return 0;
407}
408
409
420{
421#ifdef SO3_DEBUG
422 MMechostr(MSKDEBUG, "SO3BitmapWidgetBlitAlpha\n");
423#endif
424
425 int scolAlphaBitmap = MMpull(m);
426 int scolBitmapWidget = MMpull(m);
427 if ((scolAlphaBitmap == NIL) || (scolBitmapWidget == NIL))
428 {
429 MMpush(m, NIL);
430 return 0;
431 }
432
433 SWidget* widget = MMgetPointer<SWidget*>(m, MTOP(scolBitmapWidget));
434 if (widget == 0)
435 {
436 MMechostr(MSKDEBUG, "widget instance is NULL \n");
437 MMpush(m, NIL);
438 return 0;
439 }
440
441 PtrObjBitmap bitmapAlpha = 0;
442
443 // Get alphabitmap content
444 int scolColorLayer = MMfetch(m, MTOP(scolAlphaBitmap), 0);
445 int scolAlphaLayer = MMfetch(m, MTOP(scolAlphaBitmap), 1);
446
447 PtrObjVoid scolVoidPointer = (PtrObjVoid)MMstart(m, MTOP(scolColorLayer));
448 if (scolVoidPointer->Type != OBJ_TYPE_BITMAP << 1 || scolVoidPointer->Buffer == 0)
449 {
450 MMpush(m, NIL);
451 return 0;
452 }
453 PtrObjBitmap bitmap = (PtrObjBitmap)MMstart(m, MTOP(scolVoidPointer->Buffer));
454
455 if (bitmap->bits == 0)
456 {
457 MMpush(m, NIL);
458 return 0;
459 }
460
461 // Get color layer bitmap
462 if (scolAlphaLayer != NIL)
463 {
464 // Get alpha layer bitmap
465 scolVoidPointer = (PtrObjVoid)MMstart(m, MTOP(scolAlphaLayer));
466 if (scolVoidPointer->Type != OBJ_TYPE_BITMAP << 1 || scolVoidPointer->Buffer == 0)
467 {
468 MMpush(m, NIL);
469 return 0;
470 }
471
472 if (scolVoidPointer != 0)
473 {
474 bitmapAlpha = (PtrObjBitmap)MMstart(m, MTOP(scolVoidPointer->Buffer));
475
476 if (bitmapAlpha->bits == 0)
477 {
478 MMpush(m, NIL);
479 return 0;
480 }
481 }
482 }
483
484 // Let's be sure that our widget is a bitmap control
485 if (widget->GetType() != SO3_BITMAP_WIDGET_TYPE)
486 {
487 MMechostr(MSKDEBUG, "bad widget type \n");
488 MMpush(m, NIL);
489 return 0;
490 }
491 SBitmapWidget* bitmapWidget = static_cast <SBitmapWidget*> (widget);
492
493 // Set rendering quality
494 bitmapWidget->UpdateRawData(bitmap, bitmapAlpha);
495 MMpush(m, ITOM(1));
496 return 0;
497}
498
499
513{
514#ifdef SO3_DEBUG
515 MMechostr(MSKDEBUG, "SO3BitmapWidgetBlitBuffer\n");
516#endif
517
518 int ibitsperpixel = MMpull(m);
519 int iheight = MMpull(m);
520 int iwidth = MMpull(m);
521 int iBuff = MMpull(m);
522 int scolBitmapWidget = MMpull(m);
523 if ((iBuff == NIL) || (scolBitmapWidget == NIL) || (iwidth == NIL) || (iheight == NIL) || (ibitsperpixel == NIL))
524 {
525 MMpush(m, NIL);
526 return 0;
527 }
528
529 SWidget* widget = MMgetPointer<SWidget*>(m, MTOP(scolBitmapWidget));
530 if (widget == 0)
531 {
532 MMechostr(MSKDEBUG, "widget instance is NULL \n");
533 MMpush(m, NIL);
534 return 0;
535 }
536
537 unsigned char* buffer = MMgetPointer<unsigned char*>(m, MTOP(iBuff));
538 if (buffer == 0)
539 {
540 MMpush(m, NIL);
541 return 0;
542 }
543
544 // Let's be sure that our widget is a bitmap control
545 if (widget->GetType() != SO3_BITMAP_WIDGET_TYPE)
546 {
547 MMechostr(MSKDEBUG, "bad widget type \n");
548 MMpush(m, NIL);
549 return 0;
550 }
551 SBitmapWidget* bitmapWidget = static_cast <SBitmapWidget*> (widget);
552
553 // update texture buffer
554 bitmapWidget->UpdateRawData(buffer, MTOI(iwidth), MTOI(iheight), MTOI(ibitsperpixel));
555 MMpush(m, ITOM(1));
556 return 0;
557}
558
559
560NativeDefinition natSO3BmpWidget[] = {
561 { "SO3BitmapWidgetCreate", 8, "fun [SO3_SCENE SO3_VIEWPORT S I I I I I] SO3_WIDGET", SO3BitmapWidgetCreate },
562 { "SO3BitmapWidgetCreateBackground", 7, "fun [SO3_SCENE SO3_VIEWPORT S I I I I] SO3_WIDGET", SO3BitmapWidgetCreateBackground },
563 { "SO3BitmapWidgetCreateOnMaterial", 8, "fun [SO3_SCENE SO3_MATERIAL S I I I I I] SO3_WIDGET", SO3BitmapWidgetCreateOnMaterial },
564 { "SO3BitmapWidgetBlit", 2, "fun [SO3_WIDGET ObjBitmap] I", SO3BitmapWidgetBlit },
565 { "SO3BitmapWidgetBlitAlpha", 2, "fun [SO3_WIDGET AlphaBitmap] I", SO3BitmapWidgetBlitAlpha },
566 { "SO3BitmapWidgetBlitBuffer", 5, "fun [SO3_WIDGET ObjBuff I I I] I", SO3BitmapWidgetBlitBuffer }
567};
568
569
575int SCOLloadBitmapWidget(mmachine m, cbmachine w)
576{
577 return PKhardpak2(m, "SO3BmpWidget.pkg", sizeof(natSO3BmpWidget) / sizeof(natSO3BmpWidget[0]), natSO3BmpWidget);
578}
579
580
586{
587 return 0;
588}
NativeDefinition natSO3BmpWidget[]
int SCOLloadBitmapWidget(mmachine m, cbmachine w)
Load the SO3Engine Bitmap widget function.
int SCOLfreeBitmapWidget()
free the SO3Engine Bitmap widget function
MMechostr(MSKDEBUG, " > Start loading Plugin SO3Engine dll\n")
SCOL_EXPORT int cbmachine w
Definition SO3SCOL.cpp:5150
int SO3MATERIAL
Definition SO3SCOL.cpp:97
int SO3SCENETYPE
Definition SO3SCOL.cpp:88
int SO3VPTYPE
Definition SO3SCOL.cpp:94
int SO3WIDGET
Definition SO3SCOL.cpp:101
int SO3BitmapWidgetBlitBuffer(mmachine m)
SO3BitmapWidgetBlitBuffer : Blit a scol buffer on a "Bitmap Widget".
int SO3BitmapWidgetBlit(mmachine m)
SO3BitmapWidgetBlit : Blit a scol objBitmap on a "Bitmap Widget".
int SO3BitmapWidgetCreateOnMaterial(mmachine m)
SO3BitmapWidgetCreateOnMaterial : Set a texture bitmap on a material.
int SO3BitmapWidgetCreate(mmachine m)
main include
int SO3BitmapWidgetCreateBackground(mmachine m)
SO3BitmapWidgetCreateBackground : Create a new bitmap widget on background.
int SO3BitmapWidgetBlitAlpha(mmachine m)
SO3BitmapWidgetBlitAlpha : Blit a scol AlphaBitmap on a "Bitmap Widget".