Expose canvas::Window ghost to Nasal.
This commit is contained in:
parent
3d3475e965
commit
53c3033135
3 changed files with 66 additions and 28 deletions
|
@ -157,6 +157,12 @@ GUIMgr::GUIMgr():
|
||||||
stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
|
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()
|
void GUIMgr::init()
|
||||||
{
|
{
|
||||||
|
@ -187,6 +193,30 @@ void GUIMgr::shutdown()
|
||||||
->removeEventHandler( _event_handler );
|
->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)
|
void GUIMgr::elementCreated(simgear::PropertyBasedElementPtr element)
|
||||||
{
|
{
|
||||||
|
@ -213,30 +243,6 @@ void GUIMgr::elementCreated(simgear::PropertyBasedElementPtr element)
|
||||||
layer->addChild(window->getGroup());
|
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)
|
canvas::WindowPtr GUIMgr::getWindow(size_t i)
|
||||||
{
|
{
|
||||||
|
|
|
@ -41,11 +41,11 @@ class GUIMgr:
|
||||||
public:
|
public:
|
||||||
GUIMgr();
|
GUIMgr();
|
||||||
|
|
||||||
|
canvas::WindowPtr createWindow(const std::string& name = "");
|
||||||
|
|
||||||
virtual void init();
|
virtual void init();
|
||||||
virtual void shutdown();
|
virtual void shutdown();
|
||||||
|
|
||||||
virtual void elementCreated(simgear::PropertyBasedElementPtr element);
|
|
||||||
|
|
||||||
bool handleEvent(const osgGA::GUIEventAdapter& ea);
|
bool handleEvent(const osgGA::GUIEventAdapter& ea);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -68,6 +68,8 @@ class GUIMgr:
|
||||||
_last_y;
|
_last_y;
|
||||||
double _last_scroll_time;
|
double _last_scroll_time;
|
||||||
|
|
||||||
|
virtual void elementCreated(simgear::PropertyBasedElementPtr element);
|
||||||
|
|
||||||
canvas::WindowPtr getWindow(size_t i);
|
canvas::WindowPtr getWindow(size_t i);
|
||||||
simgear::canvas::Placements
|
simgear::canvas::Placements
|
||||||
addPlacement(SGPropertyNode*, simgear::canvas::CanvasPtr canvas);
|
addPlacement(SGPropertyNode*, simgear::canvas::CanvasPtr canvas);
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
|
|
||||||
#include "NasalCanvas.hxx"
|
#include "NasalCanvas.hxx"
|
||||||
#include <Canvas/canvas_mgr.hxx>
|
#include <Canvas/canvas_mgr.hxx>
|
||||||
|
#include <Canvas/gui_mgr.hxx>
|
||||||
|
#include <Canvas/window.hxx>
|
||||||
#include <Main/globals.hxx>
|
#include <Main/globals.hxx>
|
||||||
#include <Scripting/NasalSys.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::ElementPtr> NasalElement;
|
||||||
typedef nasal::Ghost<sc::GroupPtr> NasalGroup;
|
typedef nasal::Ghost<sc::GroupPtr> NasalGroup;
|
||||||
typedef nasal::Ghost<sc::TextPtr> NasalText;
|
typedef nasal::Ghost<sc::TextPtr> NasalText;
|
||||||
|
typedef nasal::Ghost<canvas::WindowWeakPtr> NasalWindow;
|
||||||
|
|
||||||
SGPropertyNode* from_nasal_helper(naContext c, naRef ref, SGPropertyNode**)
|
SGPropertyNode* from_nasal_helper(naContext c, naRef ref, SGPropertyNode**)
|
||||||
{
|
{
|
||||||
|
@ -77,12 +80,34 @@ CanvasMgr& requireCanvasMgr(naContext c)
|
||||||
return *canvas_mgr;
|
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.
|
* 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) )
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -191,6 +216,7 @@ naRef initNasalCanvas(naRef globals, naContext c, naRef gcSave)
|
||||||
.member("size_x", &sc::Canvas::getSizeX)
|
.member("size_x", &sc::Canvas::getSizeX)
|
||||||
.member("size_y", &sc::Canvas::getSizeY)
|
.member("size_y", &sc::Canvas::getSizeY)
|
||||||
.method("_createGroup", &f_canvasCreateGroup)
|
.method("_createGroup", &f_canvasCreateGroup)
|
||||||
|
.method("_getGroup", &sc::Canvas::getGroup)
|
||||||
.method("addEventListener", &sc::Canvas::addEventListener);
|
.method("addEventListener", &sc::Canvas::addEventListener);
|
||||||
NasalElement::init("canvas.Element")
|
NasalElement::init("canvas.Element")
|
||||||
.member("_node_ghost", &elementGetNode<sc::Element>)
|
.member("_node_ghost", &elementGetNode<sc::Element>)
|
||||||
|
@ -205,10 +231,14 @@ naRef initNasalCanvas(naRef globals, naContext c, naRef gcSave)
|
||||||
.bases<NasalElement>()
|
.bases<NasalElement>()
|
||||||
.method("getNearestCursor", &sc::Text::getNearestCursor);
|
.method("getNearestCursor", &sc::Text::getNearestCursor);
|
||||||
|
|
||||||
|
NasalWindow::init("canvas.Window")
|
||||||
|
.member("_node_ghost", &elementGetNode<canvas::Window>);
|
||||||
|
|
||||||
nasal::Hash globals_module(globals, c),
|
nasal::Hash globals_module(globals, c),
|
||||||
canvas_module = globals_module.createHash("canvas");
|
canvas_module = globals_module.createHash("canvas");
|
||||||
|
|
||||||
canvas_module.set("_newCanvasGhost", f_createCanvas);
|
canvas_module.set("_newCanvasGhost", f_createCanvas);
|
||||||
|
canvas_module.set("_newWindowGhost", f_createWindow);
|
||||||
canvas_module.set("_getCanvasGhost", f_getCanvas);
|
canvas_module.set("_getCanvasGhost", f_getCanvas);
|
||||||
|
|
||||||
return naNil();
|
return naNil();
|
||||||
|
|
Loading…
Add table
Reference in a new issue