// NasalCanvas.cxx -- expose Canvas classes to Nasal // // Written by James Turner, started 2012. // // Copyright (C) 2012 James Turner // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as // published by the Free Software Foundation; either version 2 of the // License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #ifdef HAVE_CONFIG_H # include "config.h" #endif #include "NasalCanvas.hxx" #include #include
#include #include #include #include #include #include #include #include extern naRef propNodeGhostCreate(naContext c, SGPropertyNode* n); namespace sc = simgear::canvas; template naRef elementGetNode(naContext c, Element& element) { return propNodeGhostCreate(c, element.getProps()); } typedef nasal::Ghost NasalCanvas; typedef nasal::Ghost NasalElement; typedef nasal::Ghost NasalGroup; #if 0 typedef osg::ref_ptr GUIEventPtr; class NasalCanvasEvent: public NasalObject { public: naRef getEventType(naContext c, const GUIEventPtr& event) { #define RET_EVENT_STR(type, str)\ case osgGA::GUIEventAdapter::type:\ return nasal::to_nasal(c, str); switch( event->getEventType() ) { RET_EVENT_STR(PUSH, "push"); RET_EVENT_STR(RELEASE, "release"); RET_EVENT_STR(DOUBLECLICK, "double-click"); RET_EVENT_STR(DRAG, "drag"); RET_EVENT_STR(MOVE, "move"); RET_EVENT_STR(SCROLL, "scroll"); RET_EVENT_STR(KEYUP, "key-up"); RET_EVENT_STR(KEYDOWN, "key-down"); #undef RET_EVENT_STR default: return naNil(); } } }; #endif static naRef f_createCanvas(naContext c, naRef me, int argc, naRef* args) { CanvasMgr* canvas_mgr = static_cast(globals->get_subsystem("Canvas")); if( !canvas_mgr ) return naNil(); return NasalCanvas::create(c, canvas_mgr->createCanvas()); } naRef f_canvasCreateGroup( sc::Canvas& canvas, naContext c, int argc, naRef* args ) { std::string name; if( argc > 0 ) name = nasal::from_nasal(c, args[0]); return NasalGroup::create(c, canvas.createGroup(name)); } naRef initNasalCanvas(naRef globals, naContext c, naRef gcSave) { NasalCanvas::init("Canvas") .member("_node_ghost", &elementGetNode) .member("size_x", &sc::Canvas::getSizeX) .member("size_y", &sc::Canvas::getSizeY) .method_func<&f_canvasCreateGroup>("createGroup"); NasalElement::init("canvas.Element") .member("_node_ghost", &elementGetNode); NasalGroup::init("canvas.Group") .bases(); nasal::Hash globals_module(globals, c), canvas_module = globals_module.createHash("canvas"); canvas_module.set("_newCanvasGhost", f_createCanvas); return naNil(); }