canvas_fwd.hxx
Canvas.hxx
CanvasEvent.hxx
- CanvasEventListener.hxx
CanvasEventManager.hxx
CanvasEventTypes.hxx
CanvasEventVisitor.hxx
set(SOURCES
Canvas.cxx
CanvasEvent.cxx
- CanvasEventListener.cxx
CanvasEventManager.cxx
CanvasEventVisitor.cxx
CanvasMgr.cxx
return _root_group->addEventListener(type, cb);
}
- //----------------------------------------------------------------------------
- bool Canvas::addNasalEventListener(const std::string& type, naRef code)
- {
- if( !_root_group.get() )
- throw std::runtime_error("Canvas::AddNasalEventListener: no root group!");
-
- return _root_group->addNasalEventListener(type, code);
- }
-
//----------------------------------------------------------------------------
void Canvas::setSizeX(int sx)
{
void update(double delta_time_sec);
bool addEventListener(const std::string& type, const EventListener& cb);
- bool addNasalEventListener(const std::string& type, naRef code);
void setSizeX(int sx);
void setSizeY(int sy);
+++ /dev/null
-// Listener for canvas (GUI) events being passed to a Nasal function/code
-//
-// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Library General Public
-// License as published by the Free Software Foundation; either
-// version 2 of the License, or (at your option) any later version.
-//
-// This library 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
-// Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
-
-#include "CanvasEvent.hxx"
-#include "CanvasEventListener.hxx"
-#include "CanvasSystemAdapter.hxx"
-
-#include <simgear/nasal/cppbind/Ghost.hxx>
-
-namespace simgear
-{
-namespace canvas
-{
-
- //----------------------------------------------------------------------------
- NasalEventListener::NasalEventListener( naRef code,
- const SystemAdapterPtr& sys_adapter ):
- _code(code),
- _gc_key(-1),
- _sys(sys_adapter)
- {
- assert( sys_adapter );
- if( !naIsCode(code)
- && !naIsCCode(code)
- && !naIsFunc(code) )
- throw std::runtime_error
- (
- "canvas::NasalEventListener: invalid function argument"
- );
-
- _gc_key = naGCSave(_code);
- }
-
- //----------------------------------------------------------------------------
- NasalEventListener::~NasalEventListener()
- {
- naGCRelease(_gc_key);
- }
-
- //----------------------------------------------------------------------------
- void NasalEventListener::operator()(const canvas::EventPtr& event) const
- {
- SystemAdapterPtr sys = _sys.lock();
- if( !sys )
- return;
-
- naRef args[] = {
- nasal::Ghost<EventPtr>::create(sys->getNasalContext(), event)
- };
- const int num_args = sizeof(args)/sizeof(args[0]);
-
- sys->callMethod(_code, naNil(), num_args, args, naNil());
- }
-
-} // namespace canvas
-} // namespace simgear
+++ /dev/null
-// Listener for canvas (GUI) events being passed to a Nasal function/code
-//
-// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Library General Public
-// License as published by the Free Software Foundation; either
-// version 2 of the License, or (at your option) any later version.
-//
-// This library 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
-// Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
-
-#ifndef CANVAS_EVENT_LISTENER_HXX_
-#define CANVAS_EVENT_LISTENER_HXX_
-
-#include "canvas_fwd.hxx"
-#include <simgear/nasal/naref.h>
-
-namespace simgear
-{
-namespace canvas
-{
-
- class NasalEventListener:
- public SGReferenced
- {
- public:
- NasalEventListener( naRef code,
- const SystemAdapterPtr& sys_adapter );
- ~NasalEventListener();
-
- void operator()(const canvas::EventPtr& event) const;
-
- protected:
- naRef _code;
- int _gc_key;
- SystemAdapterWeakPtr _sys;
- };
-
-} // namespace canvas
-} // namespace simgear
-
-#endif /* CANVAS_EVENT_LISTENER_HXX_ */
#include "CanvasEventManager.hxx"
#include "MouseEvent.hxx"
#include <simgear/canvas/elements/CanvasElement.hxx>
+#include <cmath>
namespace simgear
{
#define SG_CANVAS_SYSTEM_ADAPTER_HXX_
#include "canvas_fwd.hxx"
-#include <simgear/nasal/nasal.h>
namespace simgear
{
virtual void addCamera(osg::Camera* camera) const = 0;
virtual void removeCamera(osg::Camera* camera) const = 0;
virtual osg::Image* getImage(const std::string& path) const = 0;
-
- virtual naContext getNasalContext() const = 0;
-
- /**
- * Call a Nasal function with the given environment and arguments.
- */
- virtual naRef callMethod( naRef code,
- naRef self,
- int argc,
- naRef* args,
- naRef locals ) = 0;
};
} // namespace canvas
#include "CanvasElement.hxx"
#include <simgear/canvas/Canvas.hxx>
-#include <simgear/canvas/CanvasEventListener.hxx>
#include <simgear/canvas/CanvasEventVisitor.hxx>
#include <simgear/canvas/MouseEvent.hxx>
#include <simgear/math/SGMisc.hxx>
{
SG_LOG
(
- SG_NASAL,
+ SG_GENERAL,
SG_INFO,
"addEventListener(" << _node->getPath() << ", " << type_str << ")"
);
Event::Type type = Event::strToType(type_str);
if( type == Event::UNKNOWN )
{
- SG_LOG( SG_NASAL,
+ SG_LOG( SG_GENERAL,
SG_WARN,
"addEventListener: Unknown event type " << type_str );
return false;
return true;
}
- //----------------------------------------------------------------------------
- bool Element::addNasalEventListener(const std::string& type, naRef code)
- {
- SGSharedPtr<NasalEventListener> listener =
- new NasalEventListener(code, _canvas.lock()->getSystemAdapter());
-
- return addEventListener
- (
- type,
- boost::bind(&NasalEventListener::operator(), listener, _1)
- );
- }
-
//----------------------------------------------------------------------------
void Element::clearEventListener()
{
#include <simgear/canvas/CanvasEvent.hxx>
#include <simgear/props/PropertyBasedElement.hxx>
#include <simgear/misc/stdint.hxx> // for uint32_t
-#include <simgear/nasal/cppbind/Ghost.hxx>
#include <osg/BoundingBox>
#include <osg/MatrixTransform>
#include <boost/bind.hpp>
#include <boost/function.hpp>
+#include <boost/type_traits/is_base_of.hpp>
namespace osg
{
virtual void update(double dt);
bool addEventListener(const std::string& type, const EventListener& cb);
- bool addNasalEventListener(const std::string& type, naRef code);
-
virtual void clearEventListener();
virtual bool accept(EventVisitor& visitor);