- Refactor and unify common functionality of canvas::Window and canvas::Image - Make canvas::Image actually work - Allow using canvases inside canvas::Image * Use new canvas:// "protocol" to allow using canvases in place of images - Prepare for categorizing canvases: * Move canvases to /canvas/by-index * Later support linking to other nodes in subbranches of /canvas
66 lines
1.9 KiB
C++
66 lines
1.9 KiB
C++
// Canvas with 2D rendering api
|
|
//
|
|
// Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
|
|
//
|
|
// This program is free software; you can redistribute it and/or
|
|
// modify it under the terms of the GNU General Public License as
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
// License, or (at your option) any later version.
|
|
//
|
|
// This program 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
|
|
// General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program; if not, write to the Free Software
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
#include "canvas_mgr.hxx"
|
|
#include "canvas.hxx"
|
|
|
|
#include <boost/bind.hpp>
|
|
|
|
typedef boost::shared_ptr<Canvas> CanvasPtr;
|
|
CanvasPtr canvasFactory(SGPropertyNode* node)
|
|
{
|
|
return CanvasPtr(new Canvas(node));
|
|
}
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
CanvasMgr::CanvasMgr():
|
|
PropertyBasedMgr("/canvas/by-index", "texture", &canvasFactory)
|
|
{
|
|
Canvas::addPlacementFactory
|
|
(
|
|
"object",
|
|
boost::bind
|
|
(
|
|
&FGODGauge::set_texture,
|
|
_1,
|
|
boost::bind(&Canvas::getTexture, _2),
|
|
boost::bind(&Canvas::getCullCallback, _2)
|
|
)
|
|
);
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
CanvasPtr CanvasMgr::getCanvas(size_t index) const
|
|
{
|
|
if( index >= _elements.size()
|
|
|| !_elements[index] )
|
|
return CanvasPtr();
|
|
|
|
return boost::static_pointer_cast<Canvas>(_elements[index]);
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
unsigned int CanvasMgr::getCanvasTexId(size_t index) const
|
|
{
|
|
CanvasPtr canvas = getCanvas(index);
|
|
if( canvas )
|
|
return canvas->getTexId();
|
|
else
|
|
return 0;
|
|
}
|