stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
}
+//------------------------------------------------------------------------------
+canvas::WindowPtr GUIMgr::createWindow(const std::string& name)
+{
+ return boost::static_pointer_cast<canvas::Window>( createElement(name) );
+}
+
//------------------------------------------------------------------------------
void GUIMgr::init()
{
->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)
{
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)
{
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:
_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);
#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>
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**)
{
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(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<std::string>(0) )
+ );
}
/**
.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>)
.bases<NasalElement>()
.method("getNearestCursor", &sc::Text::getNearestCursor);
+ NasalWindow::init("canvas.Window")
+ .member("_node_ghost", &elementGetNode<canvas::Window>);
+
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();