]> git.mxchange.org Git - flightgear.git/blobdiff - src/Scripting/NasalCanvas.cxx
Reset: Nasal can be shutdown.
[flightgear.git] / src / Scripting / NasalCanvas.cxx
index 8f6671d2875d6ee2aeb7d5aa92b3f58cae0f9b9f..8ea979998db848a6a5986c808781eabd76289d14 100644 (file)
@@ -24,6 +24,8 @@
 
 #include "NasalCanvas.hxx"
 #include <Canvas/canvas_mgr.hxx>
+#include <Canvas/gui_mgr.hxx>
+#include <Canvas/window.hxx>
 #include <Main/globals.hxx>
 #include <Scripting/NasalSys.hxx>
 
@@ -57,6 +59,7 @@ typedef nasal::Ghost<sc::CanvasPtr> NasalCanvas;
 typedef nasal::Ghost<sc::ElementPtr> NasalElement;
 typedef nasal::Ghost<sc::GroupPtr> NasalGroup;
 typedef nasal::Ghost<sc::TextPtr> NasalText;
+typedef nasal::Ghost<canvas::WindowWeakPtr> NasalWindow;
 
 SGPropertyNode* from_nasal_helper(naContext c, naRef ref, SGPropertyNode**)
 {
@@ -77,12 +80,34 @@ CanvasMgr& requireCanvasMgr(naContext c)
   return *canvas_mgr;
 }
 
+GUIMgr& requireGUIMgr(naContext c)
+{
+  GUIMgr* mgr =
+    static_cast<GUIMgr*>(globals->get_subsystem("CanvasGUI"));
+  if( !mgr )
+    naRuntimeError(c, "Failed to get CanvasGUI subsystem");
+
+  return *mgr;
+}
+
 /**
  * Create new Canvas and get ghost for it.
  */
-static naRef f_createCanvas(naContext c, naRef me, int argc, naRef* args)
+static naRef f_createCanvas(const nasal::CallContext& ctx)
+{
+  return NasalCanvas::create(ctx.c, requireCanvasMgr(ctx.c).createCanvas());
+}
+
+/**
+ * Create new Window and get ghost for it.
+ */
+static naRef f_createWindow(const nasal::CallContext& ctx)
 {
-  return NasalCanvas::create(c, requireCanvasMgr(c).createCanvas());
+  return NasalWindow::create
+  (
+    ctx.c,
+    requireGUIMgr(ctx.c).createWindow( ctx.getArg<std::string>(0) )
+  );
 }
 
 /**
@@ -123,6 +148,14 @@ naRef f_canvasCreateGroup(sc::Canvas& canvas, const nasal::CallContext& ctx)
   );
 }
 
+/**
+ * Get group containing all gui windows
+ */
+naRef f_getDesktop(naContext c, naRef me, int argc, naRef* args)
+{
+  return NasalGroup::create(c, requireGUIMgr(c).getDesktop());
+}
+
 naRef f_elementGetTransformedBounds(sc::Element& el, const nasal::CallContext& ctx)
 {
   osg::BoundingBox bb = el.getTransformedBounds( osg::Matrix::identity() );
@@ -169,11 +202,14 @@ naRef to_nasal_helper(naContext c, const sc::ElementWeakPtr& el)
   return NasalElement::create(c, el.lock());
 }
 
-naRef initNasalCanvas(naRef globals, naContext c, naRef gcSave)
+naRef initNasalCanvas(naRef globals, naContext c)
 {
-  NasalEvent::init("canvas.Event")
+    if (!NasalEvent::isInit()) {
+    
+        NasalEvent::init("canvas.Event")
     .member("type", &sc::Event::getTypeString)
     .member("target", &sc::Event::getTarget)
+    .member("currentTarget", &sc::Event::getCurrentTarget)
     .method("stopPropagation", &sc::Event::stopPropagation);
   NasalMouseEvent::init("canvas.MouseEvent")
     .bases<NasalEvent>()
@@ -191,9 +227,11 @@ naRef initNasalCanvas(naRef globals, naContext c, naRef gcSave)
     .member("size_x", &sc::Canvas::getSizeX)
     .member("size_y", &sc::Canvas::getSizeY)
     .method("_createGroup", &f_canvasCreateGroup)
+    .method("_getGroup", &sc::Canvas::getGroup)
     .method("addEventListener", &sc::Canvas::addEventListener);
   NasalElement::init("canvas.Element")
     .member("_node_ghost", &elementGetNode<sc::Element>)
+    .method("_getParent", &sc::Element::getParent)
     .method("addEventListener", &sc::Element::addEventListener)
     .method("getTransformedBounds", &f_elementGetTransformedBounds);
   NasalGroup::init("canvas.Group")
@@ -205,11 +243,19 @@ naRef initNasalCanvas(naRef globals, naContext c, naRef gcSave)
     .bases<NasalElement>()
     .method("getNearestCursor", &sc::Text::getNearestCursor);
 
+  NasalWindow::init("canvas.Window")
+    .bases<NasalElement>()
+    .member("_node_ghost", &elementGetNode<canvas::Window>)
+    .method("_getCanvasDecoration", &canvas::Window::getCanvasDecoration);
+    }
+    
   nasal::Hash globals_module(globals, c),
               canvas_module = globals_module.createHash("canvas");
 
   canvas_module.set("_newCanvasGhost", f_createCanvas);
+  canvas_module.set("_newWindowGhost", f_createWindow);
   canvas_module.set("_getCanvasGhost", f_getCanvas);
+  canvas_module.set("_getDesktopGhost", f_getDesktop);
 
   return naNil();
 }