Project

General

Profile

SO3Engine
SCOLObjWindowWidget.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
63{
64#ifdef SO3_DEBUG
65 MMechostr(MSKDEBUG, "SO3ObjWindowWidgetCreate\n");
66#endif
67
68#ifdef _WIN32
69 int scolObjWindowWidget = MMpull(m);
70 int z = MTOI(MMpull(m));
71 int h = MTOI(MMpull(m));
72 int w = MTOI(MMpull(m));
73 int topPos = MTOI(MMpull(m));
74 int leftPos = MTOI(MMpull(m));
75 int nam = MMpull(m);
76 int vp = MMpull(m);
77 int s = MMget(m, 0);
78
79 if ((scolObjWindowWidget == NIL) || (s == NIL) || (vp == NIL) || (nam == NIL) || (w == NIL) || (h == NIL) || (z == NIL))
80 {
81 MMset(m, 0, NIL);
82 return 0;
83 }
84
85 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
86 if (scene == NULL)
87 {
88 MMset(m, 0, NIL);
89 return 0;
90 }
91
92 SViewPort* viewport = MMgetPointer<SViewPort*>(m, MTOP(vp));
93 if (viewport == NULL)
94 {
95 MMechostr(MSKDEBUG, "vp is NULL\n");
96 MMset(m, 0, NIL);
97 return 0;
98 }
99
100 std::string name(MMstartstr(m, MTOP(nam)));
101 if (name.empty())
102 {
103 MMechostr(MSKDEBUG, "name is NULL\n");
104 MMset(m, 0, NIL);
105 return 0;
106 }
107
108 // Get the target window handle, and check that it's a valid one.
109 PtrObjVoid OB = (PtrObjVoid)MMstart(m, MTOP(scolObjWindowWidget));
110 PtrObjWindow W = (PtrObjWindow)MMstart(m, OB->Buffer >> 1);
111 ScolWindowHandle targetWindowHandle = (ScolWindowHandle)W->WHandler;
112 if (targetWindowHandle == 0)
113 {
114 MMechostr(MSKDEBUG, "Target Window handle is NULL\n");
115 MMset(m, 0, NIL);
116 return 0;
117 }
118
119 SObjWindowWidget* objWindowWidget = 0;
120 try
121 {
122 objWindowWidget = static_cast<SObjWindowWidget*> (SWidgetManager::getSingleton().CreateWidget(scene, name, leftPos, topPos, w, h, viewport, z, SO3_OBJ_WINDOW_WIDGET_TYPE));
123 objWindowWidget->SetTargetWindow(targetWindowHandle);
124 }
125 catch (Ogre::Exception &e)
126 {
127 MMechostr(MSKDEBUG, "An exception has occurred while creating ObjWindow widget: %s\n", e.what());
128 MMset(m, 0, NIL);
129 return 0;
130 }
131
132 //get scene scol object
133 int p = OBJfindTH(m, SO3SCENETYPE, SCOL_PTR scene);
134 // push channel
135 MMset(m, 0, MMfetch(m, p, OFFOBJCHN));
136
137 if ((MMpushPointer(m, objWindowWidget) != 0))
138 {
139 SWidgetManager::getSingleton().DeleteWidget(objWindowWidget);
140 MMset(m, 0, NIL);
141 return MERRMEM;
142 }
143
144 return OBJcreate(m, SO3WIDGET, SCOL_PTR objWindowWidget, SO3VPTYPE, SCOL_PTR viewport);
145
146#else
147 MMechostr(MSKRUNTIME, "SO3ObjWindowWidgetCreate NOT implemented\n");
148 SEDROP(m, 9);
149 MMpush(m, NIL);
150 return 0;
151#endif //_WIN32
152}
153
154
171{
172#ifdef SO3_DEBUG
173 MMechostr(MSKDEBUG, "SO3ObjWindowWidgetCreateBackground\n");
174#endif
175
176#ifdef _WIN32
177 int scolObjWindowWidget = MMpull(m);
178 int h = MTOI(MMpull(m));
179 int w = MTOI(MMpull(m));
180 int topPos = MTOI(MMpull(m));
181 int leftPos = MTOI(MMpull(m));
182 int nam = MMpull(m);
183 int vp = MMpull(m);
184 int s = MMget(m, 0);
185
186 if ((scolObjWindowWidget == NIL) || (s == NIL) || (vp == NIL) || (nam == NIL) || (w == NIL) || (h == NIL))
187 {
188 MMset(m, 0, NIL);
189 return 0;
190 }
191
192 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
193 if (scene == NULL)
194 {
195 MMset(m, 0, NIL);
196 return 0;
197 }
198
199 SViewPort* viewport = MMgetPointer<SViewPort*>(m, MTOP(vp));
200 if (viewport == NULL)
201 {
202 MMechostr(MSKDEBUG, "vp is NULL\n");
203 MMset(m, 0, NIL);
204 return 0;
205 }
206
207 std::string name(MMstartstr(m, MTOP(nam)));
208 if (name.empty())
209 {
210 MMechostr(MSKDEBUG, "name is NULL\n");
211 MMset(m, 0, NIL);
212 return 0;
213 }
214
215 // Get the target window handle, and check that it's a valid one.
216 PtrObjVoid OB = (PtrObjVoid)MMstart(m, MTOP(scolObjWindowWidget));
217 PtrObjWindow W = (PtrObjWindow)MMstart(m, OB->Buffer >> 1);
218 ScolWindowHandle targetWindowHandle = (ScolWindowHandle)W->WHandler;
219 if (targetWindowHandle == 0)
220 {
221 MMechostr(MSKDEBUG, "Target Window handle is NULL\n");
222 MMset(m, 0, NIL);
223 return 0;
224 }
225
226 SObjWindowWidget* objWindowWidget = 0;
227 try
228 {
229 objWindowWidget = static_cast<SObjWindowWidget*> (SWidgetManager::getSingleton().CreateWidget(scene, name, leftPos, topPos, w, h, viewport, SO3_OBJ_WINDOW_WIDGET_TYPE));
230 objWindowWidget->SetTargetWindow(targetWindowHandle);
231 }
232 catch (Ogre::Exception &e)
233 {
234 MMechostr(MSKDEBUG, "An exception has occurred while creating objWindow widget: %s\n", e.what());
235 MMset(m, 0, NIL);
236 return 0;
237 }
238
239 //get scene scol object
240 int p = OBJfindTH(m, SO3SCENETYPE, SCOL_PTR scene);
241 // push channel
242 MMset(m, 0, MMfetch(m, p, OFFOBJCHN));
243
244 if ((MMpushPointer(m, objWindowWidget) != 0))
245 {
246 SWidgetManager::getSingleton().DeleteWidget(objWindowWidget);
247 MMset(m, 0, NIL);
248 return MERRMEM;
249 }
250
251 return OBJcreate(m, SO3WIDGET, SCOL_PTR objWindowWidget, SO3VPTYPE, SCOL_PTR viewport);
252
253#else
254 MMechostr(MSKRUNTIME, "SO3ObjWindowWidgetCreateBackground NOT implemented\n");
255 SEDROP(m, 8);
256 MMpush(m, NIL);
257 return 0;
258#endif //_WIN32
259}
260
261
279{
280#ifdef SO3_DEBUG
281 MMechostr(MSKDEBUG, "SO3ObjWindowWidgetCreateOnMaterial\n");
282#endif
283
284#ifdef _WIN32
285 int scolObjWindowWidget = MMpull(m);
286 int index = MTOI(MMpull(m));
287 int pass = MTOI(MMpull(m));
288 int tec = MTOI(MMpull(m));
289 int h = MMpull(m);
290 int w = MMpull(m);
291 int n = MMpull(m);
292 int mat = MMpull(m);
293 int s = MMget(m, 0);
294 if ((scolObjWindowWidget == NIL) || (s == NIL) || (mat == NIL) || (tec == NIL) || (pass == NIL) || (index == NIL) || (w == NIL) || (h == NIL) || (n == NIL))
295 {
296 MMset(m, 0, NIL);
297 return 0;
298 }
299
300 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
301 if (scene == NULL)
302 {
303 MMset(m, 0, NIL);
304 return 0;
305 }
306
307 SMaterial* material = MMgetPointer<SMaterial*>(m, MTOP(mat));
308 if (material == NULL)
309 {
310 MMechostr(MSKDEBUG, "material==NULL\n");
311 MMset(m, 0, NIL);
312 return 0;
313 }
314
315 std::string name(MMstartstr(m, MTOP(n)));
316 if (name.empty())
317 {
318 MMechostr(MSKDEBUG, "name is NULL \n");
319 MMset(m, 0, NIL);
320 return 0;
321 }
322
323 if (!strcmp("BaseWhite", material->getOgreMaterialPointer()->getName().c_str()))
324 {
325 Ogre::LogManager::getSingleton().logMessage("Can't load ObjWindow Control : Material BaseWhite is Protected!", Ogre::LML_CRITICAL, true);
326 MMechostr(MSKDEBUG, "Material BaseWhite is Protected \n");
327 MMset(m, 0, NIL);
328 return 0;
329 }
330
331 if (material->GetNumTechniques() < tec + 1)
332 {
333 Ogre::LogManager::getSingleton().logMessage("Can't load ObjWindow widget : Material has not enough Technique! ", Ogre::LML_CRITICAL, true);
334 MMset(m, 0, NIL);
335 return 0;
336 }
337
338 if ((material->getOgreMaterialPointer()->getTechnique(tec)->getNumPasses()) < pass + 1)
339 {
340 Ogre::LogManager::getSingleton().logMessage("Can't load ObjWindow widget : Material has not enough Pass! ", Ogre::LML_CRITICAL, true);
341 MMset(m, 0, NIL);
342 return 0;
343 }
344
345 if ((material->getOgreMaterialPointer()->getTechnique(tec)->getPass(pass)->getNumTextureUnitStates()) == 0)
346 {
347 Ogre::LogManager::getSingleton().logMessage("Can't load ObjWindow widget : Material has not enough Texture! ", Ogre::LML_CRITICAL, true);
348 MMset(m, 0, NIL);
349 return 0;
350 }
351
352 if ((material->getOgreMaterialPointer()->getTechnique(tec)->getPass(pass)->getNumTextureUnitStates()) < index + 1)
353 {
354 Ogre::LogManager::getSingleton().logMessage("Can't load ObjWindow widget : Material has not enough Texture! ", Ogre::LML_CRITICAL, true);
355 MMset(m, 0, NIL);
356 return 0;
357 }
358
359 // Get the target window handle, and check that it's a valid one.
360 PtrObjVoid OB = (PtrObjVoid)MMstart(m, MTOP(scolObjWindowWidget));
361 PtrObjWindow W = (PtrObjWindow)MMstart(m, OB->Buffer >> 1);
362 ScolWindowHandle targetWindowHandle = (ScolWindowHandle)W->WHandler;
363 if (targetWindowHandle == 0)
364 {
365 MMechostr(MSKDEBUG, "Target Window handle is NULL\n");
366 MMset(m, 0, NIL);
367 return 0;
368 }
369
370 SObjWindowWidget* objWindowWidget = 0;
371 try
372 {
373 objWindowWidget = static_cast<SObjWindowWidget*> (SWidgetManager::getSingleton().CreateWidget(scene, name, MTOI(w), MTOI(h), material, tec, pass, index, SO3_OBJ_WINDOW_WIDGET_TYPE));
374 objWindowWidget->SetTargetWindow(targetWindowHandle);
375 }
376 catch (Ogre::Exception &e)
377 {
378 MMechostr(MSKDEBUG, "An exception has occurred while creating objWindow widget: %s\n", e.what());
379 MMset(m, 0, NIL);
380 return 0;
381 }
382
383 //get scene scol object
384 int p = OBJfindTH(m, SO3SCENETYPE, SCOL_PTR scene);
385 // push channel
386 MMset(m, 0, MMfetch(m, p, OFFOBJCHN));
387
388 if ((MMpushPointer(m, objWindowWidget) != 0))
389 {
390 SWidgetManager::getSingleton().DeleteWidget(objWindowWidget);
391 MMset(m, 0, NIL);
392 return MERRMEM;
393 }
394
395 return OBJcreate(m, SO3WIDGET, SCOL_PTR objWindowWidget, SO3MATERIAL, SCOL_PTR material);
396
397#else
398 MMechostr(MSKRUNTIME, "SO3ObjWindowWidgetCreateOnMaterial NOT implemented\n");
399 SEDROP(m, 9);
400 MMpush(m, NIL);
401 return 0;
402#endif //_WIN32
403}
404
405
416{
417#ifdef SO3_DEBUG
418 MMechostr(MSKDEBUG, "SO3ObjWindowWidgetBlit\n");
419#endif
420
421#ifdef _WIN32
422
423 int scolWindow = MMpull(m);
424 int scolObjWindowWidget = MMpull(m);
425 if ((scolWindow == NIL) || (scolObjWindowWidget == NIL))
426 {
427 MMpush(m, NIL);
428 return 0;
429 }
430
431 SWidget* widget = MMgetPointer<SWidget*>(m, MTOP(scolObjWindowWidget));
432 if (widget == NULL)
433 {
434 MMechostr(MSKDEBUG, "widget instance is NULL \n");
435 MMpush(m, NIL);
436 return 0;
437 }
438
439 /*TODO
440 PtrObjVoid scolVoidPointer = (PtrObjVoid) MMstart(m, MTOP(scolBitmap));
441 if(scolVoidPointer->Type != OBJ_TYPE_BITMAP << 1)
442 {
443 MMpush(m, NIL);
444 return 0;
445 }
446 PtrObjBitmap bitmap = (PtrObjBitmap) MMstart(m, MTOP(scolVoidPointer->Buffer));*/
447
448 // Let's be sure that our widget is a objWindow control
449 if (widget->GetType() != SO3_OBJ_WINDOW_WIDGET_TYPE)
450 {
451 MMechostr(MSKDEBUG, "bad widget type \n");
452 MMpush(m, NIL);
453 return 0;
454 }
455 SObjWindowWidget* objWindowWidget = static_cast <SObjWindowWidget*> (widget);
456
457 // Set rendering quality
458 // TODO objWindowWidget->UpdateRawData(0/*TODO bitmap*/);
459 MMpush(m, ITOM(1));
460 return 0;
461
462#else
463 MMechostr(MSKRUNTIME, "SO3ObjWindowWidgetBlit NOT implemented\n");
464 SEDROP(m, 2);
465 MMpush(m, NIL);
466 return 0;
467#endif //_WIN32
468}
469
470
472{
473#ifdef SO3_DEBUG
474 MMechostr(MSKDEBUG, "SO3ObjWindowWidgetGetBorderVisible\n");
475#endif
476
477#ifdef _WIN32
478 int scolObjWindowWidget = MMget(m, 0);
479 if (scolObjWindowWidget == NIL)
480 {
481 MMset(m, 0, NIL);
482 return 0;
483 }
484
485 SWidget* widget = MMgetPointer<SWidget*>(m, MTOP(scolObjWindowWidget));
486 if (widget == NULL)
487 {
488 MMechostr(MSKDEBUG, "widget instance is NULL \n");
489 MMset(m, 0, NIL);
490 return 0;
491 }
492
493 // Let's be sure that our widget is a objWindow control
494 if (widget->GetType() != SO3_OBJ_WINDOW_WIDGET_TYPE)
495 {
496 MMechostr(MSKDEBUG, "bad widget type \n");
497 MMset(m, 0, NIL);
498 return 0;
499 }
500 SObjWindowWidget* objWindowWidget = static_cast <SObjWindowWidget*> (widget);
501 int bordersAreVisible = 0;
502 if (objWindowWidget->GetBorderVisible())
503 bordersAreVisible = 1;
504
505 MMset(m, 0, ITOM(bordersAreVisible));
506 return 0;
507
508#else
509 MMechostr(MSKRUNTIME, "SO3ObjWindowWidgetGetBorderVisible NOT implemented\n");
510 MMset(m, 0, NIL);
511 return 0;
512#endif //_WIN32
513}
514
516{
517#ifdef SO3_DEBUG
518 MMechostr(MSKDEBUG, "SO3ObjWindowWidgetSetBorderVisible\n");
519#endif
520
521#ifdef _WIN32
522 int scolBorderIsVisible = MMpull(m);
523 int scolObjWindowWidget = MMget(m, 0);
524 if (scolObjWindowWidget == NIL)
525 {
526 MMset(m, 0, NIL);
527 return 0;
528 }
529
530 SWidget* widget = MMgetPointer<SWidget*>(m, MTOP(scolObjWindowWidget));
531 if (widget == NULL)
532 {
533 MMechostr(MSKDEBUG, "widget instance is NULL \n");
534 MMset(m, 0, NIL);
535 return 0;
536 }
537
538 // Let's be sure that our widget is a objWindow control
539 if (widget->GetType() != SO3_OBJ_WINDOW_WIDGET_TYPE)
540 {
541 MMechostr(MSKDEBUG, "bad widget type \n");
542 MMset(m, 0, NIL);
543 return 0;
544 }
545 SObjWindowWidget* objWindowWidget = static_cast <SObjWindowWidget*> (widget);
546 bool bordersAreVisible = false;
547 if (MTOI(scolBorderIsVisible) == 1)
548 bordersAreVisible = true;
549
550 objWindowWidget->SetBorderVisible(bordersAreVisible);
551 MMset(m, 0, ITOM(1));
552 return 0;
553
554#else
555 MMechostr(MSKRUNTIME, "SO3ObjWindowWidgetSetBorderVisible NOT implemented\n");
556 SEDROP(m, 2);
557 MMpush(m, NIL);
558 return 0;
559#endif //_WIN32
560}
561
562
563NativeDefinition natSO3Wwidget[] = {
564 { "SO3ObjWindowWidgetCreate", 9, "fun [SO3_SCENE SO3_VIEWPORT S I I I I I ObjWin] SO3_WIDGET", SO3ObjWindowWidgetCreate },
565 { "SO3ObjWindowWidgetCreateBackground", 8, "fun [SO3_SCENE SO3_VIEWPORT S I I I I ObjWin] SO3_WIDGET", SO3ObjWindowWidgetCreateBackground },
566 { "SO3ObjWindowWidgetCreateOnMaterial", 9, "fun [SO3_SCENE SO3_MATERIAL S I I I I I ObjWin] SO3_WIDGET", SO3ObjWindowWidgetCreateOnMaterial },
567 { "SO3ObjWindowWidgetBlit", 2, "fun [SO3_WIDGET ObjWin] I", SO3ObjWindowWidgetBlit },
568 { "SO3ObjWindowWidgetGetBorderVisible", 1, "fun [SO3_WIDGET] I", SO3ObjWindowWidgetGetBorderVisible },
569 { "SO3ObjWindowWidgetSetBorderVisible", 2, "fun [SO3_WIDGET I] I", SO3ObjWindowWidgetSetBorderVisible }
570};
571
572
578int SCOLloadObjWindowWidget(mmachine m, cbmachine w)
579{
580 return PKhardpak2(m, "SO3Wwidget.pkg", sizeof(natSO3Wwidget) / sizeof(natSO3Wwidget[0]), natSO3Wwidget);
581}
582
583
589{
590 return 0;
591}
NativeDefinition natSO3Wwidget[]
int SO3ObjWindowWidgetSetBorderVisible(mmachine m)
int SO3ObjWindowWidgetGetBorderVisible(mmachine m)
int SCOLloadObjWindowWidget(mmachine m, cbmachine w)
Load the SO3Engine ObjWindow widget function.
int SCOLfreeObjWindowWidget()
free the SO3Engine ObjWindow 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 SO3ObjWindowWidgetBlit(mmachine m)
SO3ObjWindowWidgetBlit : Blit a scol objWindow on a "ObjWindow Widget".
int SO3ObjWindowWidgetCreateOnMaterial(mmachine m)
SO3ObjWindowWidgetCreateOnMaterial : Set a texture objWindow on a material.
int SO3ObjWindowWidgetCreate(mmachine m)
main include
int SO3ObjWindowWidgetCreateBackground(mmachine m)
SO3ObjWindowWidgetCreateBackground : Create a new ObjWindow widget on background.