diff --git a/src/Canvas/gui_mgr.cxx b/src/Canvas/gui_mgr.cxx index 006dd2d68..3bb86bc69 100644 --- a/src/Canvas/gui_mgr.cxx +++ b/src/Canvas/gui_mgr.cxx @@ -157,6 +157,12 @@ GUIMgr::GUIMgr(): stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF); } +//------------------------------------------------------------------------------ +canvas::WindowPtr GUIMgr::createWindow(const std::string& name) +{ + return boost::static_pointer_cast( createElement(name) ); +} + //------------------------------------------------------------------------------ void GUIMgr::init() { @@ -187,6 +193,30 @@ void GUIMgr::shutdown() ->removeEventHandler( _event_handler ); } +//------------------------------------------------------------------------------ +bool GUIMgr::handleEvent(const osgGA::GUIEventAdapter& ea) +{ + switch( ea.getEventType() ) + { + case osgGA::GUIEventAdapter::PUSH: + case osgGA::GUIEventAdapter::RELEASE: +// case osgGA::GUIEventAdapter::DOUBLECLICK: +// // DOUBLECLICK doesn't seem to be triggered... + case osgGA::GUIEventAdapter::DRAG: + case osgGA::GUIEventAdapter::MOVE: + case osgGA::GUIEventAdapter::SCROLL: + return handleMouse(ea); + case osgGA::GUIEventAdapter::RESIZE: + handleResize( ea.getWindowX(), + ea.getWindowY(), + ea.getWindowWidth(), + ea.getWindowHeight() ); + return false; // Let other event handlers also consume resize events + default: + return false; + } +} + //------------------------------------------------------------------------------ void GUIMgr::elementCreated(simgear::PropertyBasedElementPtr element) { @@ -213,30 +243,6 @@ void GUIMgr::elementCreated(simgear::PropertyBasedElementPtr element) layer->addChild(window->getGroup()); } -//------------------------------------------------------------------------------ -bool GUIMgr::handleEvent(const osgGA::GUIEventAdapter& ea) -{ - switch( ea.getEventType() ) - { - case osgGA::GUIEventAdapter::PUSH: - case osgGA::GUIEventAdapter::RELEASE: -// case osgGA::GUIEventAdapter::DOUBLECLICK: -// // DOUBLECLICK doesn't seem to be triggered... - case osgGA::GUIEventAdapter::DRAG: - case osgGA::GUIEventAdapter::MOVE: - case osgGA::GUIEventAdapter::SCROLL: - return handleMouse(ea); - case osgGA::GUIEventAdapter::RESIZE: - handleResize( ea.getWindowX(), - ea.getWindowY(), - ea.getWindowWidth(), - ea.getWindowHeight() ); - return false; // Let other event handlers also consume resize events - default: - return false; - } -} - //------------------------------------------------------------------------------ canvas::WindowPtr GUIMgr::getWindow(size_t i) { diff --git a/src/Canvas/gui_mgr.hxx b/src/Canvas/gui_mgr.hxx index 00319dd47..408dd62c5 100644 --- a/src/Canvas/gui_mgr.hxx +++ b/src/Canvas/gui_mgr.hxx @@ -41,11 +41,11 @@ class GUIMgr: public: GUIMgr(); + canvas::WindowPtr createWindow(const std::string& name = ""); + virtual void init(); virtual void shutdown(); - virtual void elementCreated(simgear::PropertyBasedElementPtr element); - bool handleEvent(const osgGA::GUIEventAdapter& ea); protected: @@ -68,6 +68,8 @@ class GUIMgr: _last_y; double _last_scroll_time; + virtual void elementCreated(simgear::PropertyBasedElementPtr element); + canvas::WindowPtr getWindow(size_t i); simgear::canvas::Placements addPlacement(SGPropertyNode*, simgear::canvas::CanvasPtr canvas); diff --git a/src/Scripting/NasalCanvas.cxx b/src/Scripting/NasalCanvas.cxx index 8f6671d28..f6ab47ac5 100644 --- a/src/Scripting/NasalCanvas.cxx +++ b/src/Scripting/NasalCanvas.cxx @@ -24,6 +24,8 @@ #include "NasalCanvas.hxx" #include +#include +#include #include
#include @@ -57,6 +59,7 @@ typedef nasal::Ghost NasalCanvas; typedef nasal::Ghost NasalElement; typedef nasal::Ghost NasalGroup; typedef nasal::Ghost NasalText; +typedef nasal::Ghost 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(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(c, requireCanvasMgr(c).createCanvas()); + 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 NasalWindow::create + ( + ctx.c, + requireGUIMgr(ctx.c).createWindow( ctx.getArg(0) ) + ); } /** @@ -191,6 +216,7 @@ 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) @@ -205,10 +231,14 @@ naRef initNasalCanvas(naRef globals, naContext c, naRef gcSave) .bases() .method("getNearestCursor", &sc::Text::getNearestCursor); + NasalWindow::init("canvas.Window") + .member("_node_ghost", &elementGetNode); + 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); return naNil();