From: Thomas Geymayer Date: Tue, 15 Oct 2013 15:42:49 +0000 (+0200) Subject: Canvas: simplify code by using new nasal function conversion. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=a37a254a68d67d6e90257c8588a9153ab005615a;p=simgear.git Canvas: simplify code by using new nasal function conversion. --- diff --git a/simgear/canvas/CMakeLists.txt b/simgear/canvas/CMakeLists.txt index 644f62af..086c83cb 100644 --- a/simgear/canvas/CMakeLists.txt +++ b/simgear/canvas/CMakeLists.txt @@ -4,7 +4,6 @@ set(HEADERS canvas_fwd.hxx Canvas.hxx CanvasEvent.hxx - CanvasEventListener.hxx CanvasEventManager.hxx CanvasEventTypes.hxx CanvasEventVisitor.hxx @@ -20,7 +19,6 @@ set(HEADERS set(SOURCES Canvas.cxx CanvasEvent.cxx - CanvasEventListener.cxx CanvasEventManager.cxx CanvasEventVisitor.cxx CanvasMgr.cxx diff --git a/simgear/canvas/Canvas.cxx b/simgear/canvas/Canvas.cxx index 390c3ea0..a95964d6 100644 --- a/simgear/canvas/Canvas.cxx +++ b/simgear/canvas/Canvas.cxx @@ -329,15 +329,6 @@ namespace canvas 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) { diff --git a/simgear/canvas/Canvas.hxx b/simgear/canvas/Canvas.hxx index 481179b1..dba28863 100644 --- a/simgear/canvas/Canvas.hxx +++ b/simgear/canvas/Canvas.hxx @@ -133,7 +133,6 @@ namespace canvas 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); diff --git a/simgear/canvas/CanvasEventListener.cxx b/simgear/canvas/CanvasEventListener.cxx deleted file mode 100644 index 5dcfab51..00000000 --- a/simgear/canvas/CanvasEventListener.cxx +++ /dev/null @@ -1,71 +0,0 @@ -// Listener for canvas (GUI) events being passed to a Nasal function/code -// -// Copyright (C) 2012 Thomas Geymayer -// -// 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 - -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::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 diff --git a/simgear/canvas/CanvasEventListener.hxx b/simgear/canvas/CanvasEventListener.hxx deleted file mode 100644 index 6879345a..00000000 --- a/simgear/canvas/CanvasEventListener.hxx +++ /dev/null @@ -1,49 +0,0 @@ -// Listener for canvas (GUI) events being passed to a Nasal function/code -// -// Copyright (C) 2012 Thomas Geymayer -// -// 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 - -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_ */ diff --git a/simgear/canvas/CanvasEventManager.cxx b/simgear/canvas/CanvasEventManager.cxx index 50e8c49f..bac9d769 100644 --- a/simgear/canvas/CanvasEventManager.cxx +++ b/simgear/canvas/CanvasEventManager.cxx @@ -19,6 +19,7 @@ #include "CanvasEventManager.hxx" #include "MouseEvent.hxx" #include +#include namespace simgear { diff --git a/simgear/canvas/CanvasSystemAdapter.hxx b/simgear/canvas/CanvasSystemAdapter.hxx index 6a250f4d..91fc2740 100644 --- a/simgear/canvas/CanvasSystemAdapter.hxx +++ b/simgear/canvas/CanvasSystemAdapter.hxx @@ -20,7 +20,6 @@ #define SG_CANVAS_SYSTEM_ADAPTER_HXX_ #include "canvas_fwd.hxx" -#include namespace simgear { @@ -36,17 +35,6 @@ namespace canvas 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 diff --git a/simgear/canvas/elements/CanvasElement.cxx b/simgear/canvas/elements/CanvasElement.cxx index 5ffde2a2..3692bf90 100644 --- a/simgear/canvas/elements/CanvasElement.cxx +++ b/simgear/canvas/elements/CanvasElement.cxx @@ -18,7 +18,6 @@ #include "CanvasElement.hxx" #include -#include #include #include #include @@ -178,7 +177,7 @@ namespace canvas { SG_LOG ( - SG_NASAL, + SG_GENERAL, SG_INFO, "addEventListener(" << _node->getPath() << ", " << type_str << ")" ); @@ -186,7 +185,7 @@ namespace canvas 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; @@ -197,19 +196,6 @@ namespace canvas return true; } - //---------------------------------------------------------------------------- - bool Element::addNasalEventListener(const std::string& type, naRef code) - { - SGSharedPtr listener = - new NasalEventListener(code, _canvas.lock()->getSystemAdapter()); - - return addEventListener - ( - type, - boost::bind(&NasalEventListener::operator(), listener, _1) - ); - } - //---------------------------------------------------------------------------- void Element::clearEventListener() { diff --git a/simgear/canvas/elements/CanvasElement.hxx b/simgear/canvas/elements/CanvasElement.hxx index c7191984..f44bee43 100644 --- a/simgear/canvas/elements/CanvasElement.hxx +++ b/simgear/canvas/elements/CanvasElement.hxx @@ -23,13 +23,13 @@ #include #include #include // for uint32_t -#include #include #include #include #include +#include namespace osg { @@ -93,8 +93,6 @@ namespace canvas 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);