Canvas: move Window class to simgear.
This commit is contained in:
parent
5743ae48eb
commit
bd29974683
10 changed files with 54 additions and 515 deletions
|
@ -4,14 +4,12 @@ set(SOURCES
|
|||
canvas_mgr.cxx
|
||||
FGCanvasSystemAdapter.cxx
|
||||
gui_mgr.cxx
|
||||
window.cxx
|
||||
)
|
||||
|
||||
set(HEADERS
|
||||
canvas_mgr.hxx
|
||||
FGCanvasSystemAdapter.hxx
|
||||
gui_mgr.hxx
|
||||
window.hxx
|
||||
)
|
||||
|
||||
flightgear_component(Canvas "${SOURCES}" "${HEADERS}")
|
|
@ -99,6 +99,13 @@ namespace canvas
|
|||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
SGSubsystem*
|
||||
FGCanvasSystemAdapter::getSubsystem(const std::string& name) const
|
||||
{
|
||||
return globals->get_subsystem(name.c_str());
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
simgear::HTTP::Client* FGCanvasSystemAdapter::getHTTPClient() const
|
||||
{
|
||||
|
|
|
@ -31,6 +31,7 @@ namespace canvas
|
|||
virtual void addCamera(osg::Camera* camera) const;
|
||||
virtual void removeCamera(osg::Camera* camera) const;
|
||||
virtual osg::Image* getImage(const std::string& path) const;
|
||||
virtual SGSubsystem* getSubsystem(const std::string& name) const;
|
||||
virtual simgear::HTTP::Client* getHTTPClient() const;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
// Canvas forward declarations
|
||||
//
|
||||
// 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.
|
||||
|
||||
#ifndef CANVAS_FWD_HPP_
|
||||
#define CANVAS_FWD_HPP_
|
||||
|
||||
#include <simgear/structure/SGSharedPtr.hxx>
|
||||
|
||||
namespace canvas
|
||||
{
|
||||
class Window;
|
||||
typedef SGSharedPtr<Window> WindowPtr;
|
||||
typedef SGWeakPtr<Window> WindowWeakPtr;
|
||||
}
|
||||
|
||||
#endif /* CANVAS_FWD_HPP_ */
|
|
@ -17,7 +17,6 @@
|
|||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
#include "gui_mgr.hxx"
|
||||
#include <Canvas/window.hxx>
|
||||
|
||||
#include <Main/fg_os.hxx>
|
||||
#include <Main/fg_props.hxx>
|
||||
|
@ -27,6 +26,7 @@
|
|||
|
||||
#include <simgear/canvas/Canvas.hxx>
|
||||
#include <simgear/canvas/CanvasPlacement.hxx>
|
||||
#include <simgear/canvas/CanvasWindow.hxx>
|
||||
#include <simgear/scene/util/OsgMath.hxx>
|
||||
|
||||
#include <osg/BlendFunc>
|
||||
|
@ -40,6 +40,8 @@ class DesktopGroup;
|
|||
typedef SGSharedPtr<DesktopGroup> DesktopPtr;
|
||||
typedef SGWeakPtr<DesktopGroup> DesktopWeakPtr;
|
||||
|
||||
namespace sc = simgear::canvas;
|
||||
|
||||
/**
|
||||
* Event handler
|
||||
*/
|
||||
|
@ -62,12 +64,12 @@ class GUIEventHandler:
|
|||
* Track a canvas placement on a window
|
||||
*/
|
||||
class WindowPlacement:
|
||||
public simgear::canvas::Placement
|
||||
public sc::Placement
|
||||
{
|
||||
public:
|
||||
WindowPlacement( SGPropertyNode* node,
|
||||
canvas::WindowPtr window,
|
||||
simgear::canvas::CanvasPtr canvas ):
|
||||
sc::WindowPtr window,
|
||||
sc::CanvasPtr canvas ):
|
||||
Placement(node),
|
||||
_window(window),
|
||||
_canvas(canvas)
|
||||
|
@ -78,23 +80,23 @@ class WindowPlacement:
|
|||
*/
|
||||
virtual ~WindowPlacement()
|
||||
{
|
||||
canvas::WindowPtr window = _window.lock();
|
||||
simgear::canvas::CanvasPtr canvas = _canvas.lock();
|
||||
sc::WindowPtr window = _window.lock();
|
||||
sc::CanvasPtr canvas = _canvas.lock();
|
||||
|
||||
if( window && canvas && canvas == window->getCanvasContent().lock() )
|
||||
window->setCanvasContent( simgear::canvas::CanvasPtr() );
|
||||
window->setCanvasContent( sc::CanvasPtr() );
|
||||
}
|
||||
|
||||
private:
|
||||
canvas::WindowWeakPtr _window;
|
||||
simgear::canvas::CanvasWeakPtr _canvas;
|
||||
sc::WindowWeakPtr _window;
|
||||
sc::CanvasWeakPtr _canvas;
|
||||
};
|
||||
|
||||
/**
|
||||
* Desktop root group
|
||||
*/
|
||||
class DesktopGroup:
|
||||
public simgear::canvas::Group
|
||||
public sc::Group
|
||||
{
|
||||
public:
|
||||
DesktopGroup();
|
||||
|
@ -110,9 +112,9 @@ class DesktopGroup:
|
|||
simgear::PropertyObject<int> _width,
|
||||
_height;
|
||||
|
||||
canvas::WindowWeakPtr _last_push,
|
||||
_last_mouse_over,
|
||||
_resize_window;
|
||||
sc::WindowWeakPtr _last_push,
|
||||
_last_mouse_over,
|
||||
_resize_window;
|
||||
uint8_t _resize;
|
||||
int _last_cursor;
|
||||
|
||||
|
@ -128,11 +130,11 @@ class DesktopGroup:
|
|||
/**
|
||||
*
|
||||
*/
|
||||
simgear::canvas::ElementFactory
|
||||
sc::ElementFactory
|
||||
getChildFactory(const std::string& type) const
|
||||
{
|
||||
if( type == "window" )
|
||||
return &Element::create<canvas::Window>;
|
||||
return &Element::create<sc::Window>;
|
||||
|
||||
return Group::getChildFactory(type);
|
||||
}
|
||||
|
@ -160,14 +162,14 @@ bool GUIEventHandler::handle( const osgGA::GUIEventAdapter& ea,
|
|||
|
||||
//------------------------------------------------------------------------------
|
||||
DesktopGroup::DesktopGroup():
|
||||
Group(simgear::canvas::CanvasPtr(), fgGetNode("/sim/gui/canvas", true)),
|
||||
Group(sc::CanvasPtr(), fgGetNode("/sim/gui/canvas", true)),
|
||||
_cb_mouse_mode( this,
|
||||
&DesktopGroup::handleMouseMode,
|
||||
fgGetNode("/devices/status/mice/mouse[0]/mode") ),
|
||||
_handle_events(true),
|
||||
_width(_node, "size[0]"),
|
||||
_height(_node, "size[1]"),
|
||||
_resize(canvas::Window::NONE),
|
||||
_resize(sc::Window::NONE),
|
||||
_last_cursor(MOUSE_CURSOR_NONE),
|
||||
_last_x(-1),
|
||||
_last_y(-1),
|
||||
|
@ -267,7 +269,7 @@ bool DesktopGroup::handleMouse(const osgGA::GUIEventAdapter& ea)
|
|||
switch( ea.getEventType() )
|
||||
{
|
||||
case osgGA::GUIEventAdapter::RELEASE:
|
||||
_resize_window.lock()->handleResize(canvas::Window::NONE);
|
||||
_resize_window.lock()->handleResize(sc::Window::NONE);
|
||||
_resize_window.reset();
|
||||
break;
|
||||
case osgGA::GUIEventAdapter::DRAG:
|
||||
|
@ -279,7 +281,7 @@ bool DesktopGroup::handleMouse(const osgGA::GUIEventAdapter& ea)
|
|||
}
|
||||
}
|
||||
|
||||
canvas::WindowPtr window_at_cursor;
|
||||
sc::WindowPtr window_at_cursor;
|
||||
for( int i = _transform->getNumChildren() - 1; i >= 0; --i )
|
||||
{
|
||||
osg::Group *element = _transform->getChild(i)->asGroup();
|
||||
|
@ -287,8 +289,8 @@ bool DesktopGroup::handleMouse(const osgGA::GUIEventAdapter& ea)
|
|||
assert(element);
|
||||
assert(element->getUserData());
|
||||
|
||||
canvas::WindowPtr window =
|
||||
dynamic_cast<canvas::Window*>
|
||||
sc::WindowPtr window =
|
||||
dynamic_cast<sc::Window*>
|
||||
(
|
||||
static_cast<sc::Element::OSGUserData*>(
|
||||
element->getUserData()
|
||||
|
@ -327,14 +329,14 @@ bool DesktopGroup::handleMouse(const osgGA::GUIEventAdapter& ea)
|
|||
_resize = 0;
|
||||
|
||||
if( event->getScreenX() <= reg.l() + resize_corner )
|
||||
_resize |= canvas::Window::LEFT;
|
||||
_resize |= sc::Window::LEFT;
|
||||
else if( event->getScreenX() >= reg.r() - resize_corner )
|
||||
_resize |= canvas::Window::RIGHT;
|
||||
_resize |= sc::Window::RIGHT;
|
||||
|
||||
if( event->getScreenY() <= reg.t() + resize_corner )
|
||||
_resize |= canvas::Window::TOP;
|
||||
_resize |= sc::Window::TOP;
|
||||
else if( event->getScreenY() >= reg.b() - resize_corner )
|
||||
_resize |= canvas::Window::BOTTOM;
|
||||
_resize |= sc::Window::BOTTOM;
|
||||
|
||||
static const int cursor_mapping[] =
|
||||
{
|
||||
|
@ -354,7 +356,7 @@ bool DesktopGroup::handleMouse(const osgGA::GUIEventAdapter& ea)
|
|||
_drag_start = event->screen_pos;
|
||||
|
||||
window_at_cursor->raise();
|
||||
window_at_cursor->handleResize(_resize | canvas::Window::INIT);
|
||||
window_at_cursor->handleResize(_resize | sc::Window::INIT);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -368,7 +370,7 @@ bool DesktopGroup::handleMouse(const osgGA::GUIEventAdapter& ea)
|
|||
return true;
|
||||
}
|
||||
|
||||
canvas::WindowPtr target_window = window_at_cursor;
|
||||
sc::WindowPtr target_window = window_at_cursor;
|
||||
switch( ea.getEventType() )
|
||||
{
|
||||
case osgGA::GUIEventAdapter::PUSH:
|
||||
|
@ -399,7 +401,7 @@ bool DesktopGroup::handleMouse(const osgGA::GUIEventAdapter& ea)
|
|||
break;
|
||||
case osgGA::GUIEventAdapter::MOVE:
|
||||
{
|
||||
canvas::WindowPtr last_mouse_over = _last_mouse_over.lock();
|
||||
sc::WindowPtr last_mouse_over = _last_mouse_over.lock();
|
||||
if( last_mouse_over != window_at_cursor && last_mouse_over )
|
||||
{
|
||||
sc::MouseEventPtr move_event( new sc::MouseEvent(*event) );
|
||||
|
@ -417,7 +419,7 @@ bool DesktopGroup::handleMouse(const osgGA::GUIEventAdapter& ea)
|
|||
{
|
||||
event->type = sc::Event::MOUSE_UP;
|
||||
|
||||
canvas::WindowPtr last_push = _last_push.lock();
|
||||
sc::WindowPtr last_push = _last_push.lock();
|
||||
_last_push.reset();
|
||||
|
||||
if( last_push && last_push != target_window )
|
||||
|
@ -484,9 +486,9 @@ GUIMgr::GUIMgr()
|
|||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
canvas::WindowPtr GUIMgr::createWindow(const std::string& name)
|
||||
sc::WindowPtr GUIMgr::createWindow(const std::string& name)
|
||||
{
|
||||
canvas::WindowPtr window = _desktop->createChild<canvas::Window>(name);
|
||||
sc::WindowPtr window = _desktop->createChild<sc::Window>(name);
|
||||
if( name.empty() )
|
||||
window->set<std::string>
|
||||
(
|
||||
|
@ -516,7 +518,7 @@ void GUIMgr::init()
|
|||
// GUI is on top of everything so lets install as first event handler
|
||||
.push_front( _event_handler );
|
||||
|
||||
simgear::canvas::Canvas::addPlacementFactory
|
||||
sc::Canvas::addPlacementFactory
|
||||
(
|
||||
"window",
|
||||
boost::bind(&GUIMgr::addWindowPlacement, this, _1, _2)
|
||||
|
@ -530,7 +532,7 @@ void GUIMgr::shutdown()
|
|||
{
|
||||
_desktop->destroy();
|
||||
_desktop.reset();
|
||||
simgear::canvas::Canvas::removePlacementFactory("window");
|
||||
sc::Canvas::removePlacementFactory("window");
|
||||
|
||||
globals->get_renderer()
|
||||
->getViewer()
|
||||
|
@ -545,25 +547,25 @@ void GUIMgr::update(double dt)
|
|||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
simgear::canvas::GroupPtr GUIMgr::getDesktop()
|
||||
sc::GroupPtr GUIMgr::getDesktop()
|
||||
{
|
||||
return _desktop;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
simgear::canvas::Placements
|
||||
sc::Placements
|
||||
GUIMgr::addWindowPlacement( SGPropertyNode* placement,
|
||||
simgear::canvas::CanvasPtr canvas )
|
||||
sc::CanvasPtr canvas )
|
||||
{
|
||||
const std::string& id = placement->getStringValue("id");
|
||||
|
||||
simgear::canvas::Placements placements;
|
||||
canvas::WindowPtr window = _desktop->getChild<canvas::Window>(id);
|
||||
sc::Placements placements;
|
||||
sc::WindowPtr window = _desktop->getChild<sc::Window>(id);
|
||||
if( window )
|
||||
{
|
||||
window->setCanvasContent(canvas);
|
||||
placements.push_back(
|
||||
simgear::canvas::PlacementPtr(
|
||||
sc::PlacementPtr(
|
||||
new WindowPlacement(placement, window, canvas)
|
||||
));
|
||||
}
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
#ifndef CANVAS_GUI_MGR_HXX_
|
||||
#define CANVAS_GUI_MGR_HXX_
|
||||
|
||||
#include "canvas_fwd.hpp"
|
||||
|
||||
#include <simgear/canvas/canvas_fwd.hxx>
|
||||
#include <simgear/canvas/elements/CanvasGroup.hxx>
|
||||
#include <simgear/props/PropertyBasedMgr.hxx>
|
||||
|
@ -42,7 +40,7 @@ class GUIMgr:
|
|||
public:
|
||||
GUIMgr();
|
||||
|
||||
canvas::WindowPtr createWindow(const std::string& name = "");
|
||||
simgear::canvas::WindowPtr createWindow(const std::string& name = "");
|
||||
|
||||
virtual void init();
|
||||
virtual void shutdown();
|
||||
|
|
|
@ -1,311 +0,0 @@
|
|||
// Window for placing a Canvas onto it (for dialogs, menus, etc.)
|
||||
//
|
||||
// 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 "window.hxx"
|
||||
#include <Main/globals.hxx>
|
||||
#include <simgear/canvas/Canvas.hxx>
|
||||
#include <simgear/scene/util/OsgMath.hxx>
|
||||
|
||||
#include <osgGA/GUIEventHandler>
|
||||
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
namespace canvas
|
||||
{
|
||||
namespace sc = simgear::canvas;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
const std::string Window::TYPE_NAME = "window";
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
Window::Window( const simgear::canvas::CanvasWeakPtr& canvas,
|
||||
const SGPropertyNode_ptr& node,
|
||||
const Style& parent_style,
|
||||
Element* parent ):
|
||||
Image(canvas, node, parent_style, parent),
|
||||
_attributes_dirty(0),
|
||||
_resizable(false),
|
||||
_capture_events(true),
|
||||
_resize_top(node, "resize-top"),
|
||||
_resize_right(node, "resize-right"),
|
||||
_resize_bottom(node, "resize-bottom"),
|
||||
_resize_left(node, "resize-left"),
|
||||
_resize_status(node, "resize-status")
|
||||
{
|
||||
node->setFloatValue("source/right", 1);
|
||||
node->setFloatValue("source/bottom", 1);
|
||||
node->setBoolValue("source/normalized", true);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
Window::~Window()
|
||||
{
|
||||
if( _canvas_decoration )
|
||||
_canvas_decoration->destroy();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void Window::update(double delta_time_sec)
|
||||
{
|
||||
if( _attributes_dirty & DECORATION )
|
||||
{
|
||||
updateDecoration();
|
||||
_attributes_dirty &= ~DECORATION;
|
||||
}
|
||||
|
||||
Image::update(delta_time_sec);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void Window::valueChanged(SGPropertyNode * node)
|
||||
{
|
||||
bool handled = false;
|
||||
if( node->getParent() == _node )
|
||||
{
|
||||
handled = true;
|
||||
const std::string& name = node->getNameString();
|
||||
if( name == "resize" )
|
||||
_resizable = node->getBoolValue();
|
||||
else if( name == "update" )
|
||||
update(0);
|
||||
else if( name == "capture-events" )
|
||||
_capture_events = node->getBoolValue();
|
||||
else if( name == "decoration-border" )
|
||||
parseDecorationBorder(node->getStringValue());
|
||||
else if( boost::starts_with(name, "shadow-")
|
||||
|| name == "content-size" )
|
||||
_attributes_dirty |= DECORATION;
|
||||
else
|
||||
handled = false;
|
||||
}
|
||||
|
||||
if( !handled )
|
||||
Image::valueChanged(node);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
osg::Group* Window::getGroup()
|
||||
{
|
||||
return getMatrixTransform();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
const SGVec2<float> Window::getPosition() const
|
||||
{
|
||||
const osg::Matrix& m = getMatrixTransform()->getMatrix();
|
||||
return SGVec2<float>( m(3, 0), m(3, 1) );
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
const SGRect<float> Window::getScreenRegion() const
|
||||
{
|
||||
return getPosition() + getRegion();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void Window::setCanvasContent(sc::CanvasPtr canvas)
|
||||
{
|
||||
_canvas_content = canvas;
|
||||
|
||||
if( _image_content )
|
||||
// Placement within decoration canvas
|
||||
_image_content->setSrcCanvas(canvas);
|
||||
else
|
||||
setSrcCanvas(canvas);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
sc::CanvasWeakPtr Window::getCanvasContent() const
|
||||
{
|
||||
return _canvas_content;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
sc::CanvasPtr Window::getCanvasDecoration()
|
||||
{
|
||||
return _canvas_decoration;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool Window::isResizable() const
|
||||
{
|
||||
return _resizable;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool Window::isCapturingEvents() const
|
||||
{
|
||||
return _capture_events;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void Window::raise()
|
||||
{
|
||||
// on writing the z-index the window always is moved to the top of all other
|
||||
// windows with the same z-index.
|
||||
set<int>("z-index", get<int>("z-index", 0));
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void Window::handleResize( uint8_t mode,
|
||||
const osg::Vec2f& offset )
|
||||
{
|
||||
if( mode == NONE )
|
||||
{
|
||||
_resize_status = 0;
|
||||
return;
|
||||
}
|
||||
else if( mode & INIT )
|
||||
{
|
||||
_resize_top = getRegion().t();
|
||||
_resize_right = getRegion().r();
|
||||
_resize_bottom = getRegion().b();
|
||||
_resize_left = getRegion().l();
|
||||
_resize_status = 1;
|
||||
}
|
||||
|
||||
if( mode & BOTTOM )
|
||||
_resize_bottom = getRegion().b() + offset.y();
|
||||
else if( mode & TOP )
|
||||
_resize_top = getRegion().t() + offset.y();
|
||||
|
||||
if( mode & canvas::Window::RIGHT )
|
||||
_resize_right = getRegion().r() + offset.x();
|
||||
else if( mode & canvas::Window::LEFT )
|
||||
_resize_left = getRegion().l() + offset.x();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void Window::parseDecorationBorder(const std::string& str)
|
||||
{
|
||||
_decoration_border = simgear::CSSBorder::parse(str);
|
||||
_attributes_dirty |= DECORATION;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void Window::updateDecoration()
|
||||
{
|
||||
int shadow_radius = get<float>("shadow-radius") + 0.5;
|
||||
if( shadow_radius < 2 )
|
||||
shadow_radius = 0;
|
||||
|
||||
sc::CanvasPtr content = _canvas_content.lock();
|
||||
SGRect<int> content_view
|
||||
(
|
||||
0,
|
||||
0,
|
||||
get<int>("content-size[0]", content ? content->getViewWidth() : 400),
|
||||
get<int>("content-size[1]", content ? content->getViewHeight() : 300)
|
||||
);
|
||||
|
||||
if( _decoration_border.isNone() && !shadow_radius )
|
||||
{
|
||||
setSrcCanvas(content);
|
||||
set<int>("size[0]", content_view.width());
|
||||
set<int>("size[1]", content_view.height());
|
||||
|
||||
_image_content.reset();
|
||||
_image_shadow.reset();
|
||||
if( _canvas_decoration )
|
||||
_canvas_decoration->destroy();
|
||||
_canvas_decoration.reset();
|
||||
return;
|
||||
}
|
||||
|
||||
if( !_canvas_decoration )
|
||||
{
|
||||
CanvasMgr* mgr =
|
||||
dynamic_cast<CanvasMgr*>(globals->get_subsystem("Canvas"));
|
||||
|
||||
if( !mgr )
|
||||
{
|
||||
SG_LOG(SG_GENERAL, SG_WARN, "canvas::Window: no canvas manager!");
|
||||
return;
|
||||
}
|
||||
|
||||
_canvas_decoration = mgr->createCanvas("window-decoration");
|
||||
_canvas_decoration->getProps()
|
||||
->setStringValue("background", "rgba(0,0,0,0)");
|
||||
setSrcCanvas(_canvas_decoration);
|
||||
|
||||
_image_content = _canvas_decoration->getRootGroup()
|
||||
->createChild<sc::Image>("content");
|
||||
_image_content->setSrcCanvas(content);
|
||||
|
||||
// Draw content on top of decoration
|
||||
_image_content->set<int>("z-index", 1);
|
||||
}
|
||||
|
||||
sc::GroupPtr group_decoration =
|
||||
_canvas_decoration->getOrCreateGroup("decoration");
|
||||
group_decoration->set<int>("tf/t[0]", shadow_radius);
|
||||
group_decoration->set<int>("tf/t[1]", shadow_radius);
|
||||
// TODO do we need clipping or shall we trust the decorator not to draw over
|
||||
// the shadow?
|
||||
|
||||
simgear::CSSBorder::Offsets const border =
|
||||
_decoration_border.getAbsOffsets(content_view);
|
||||
|
||||
int shad2 = 2 * shadow_radius,
|
||||
outer_width = border.l + content_view.width() + border.r + shad2,
|
||||
outer_height = border.t + content_view.height() + border.b + shad2;
|
||||
|
||||
_canvas_decoration->setSizeX( outer_width );
|
||||
_canvas_decoration->setSizeY( outer_height );
|
||||
_canvas_decoration->setViewWidth( outer_width );
|
||||
_canvas_decoration->setViewHeight( outer_height );
|
||||
|
||||
set<int>("size[0]", outer_width - shad2);
|
||||
set<int>("size[1]", outer_height - shad2);
|
||||
set<int>("outset", shadow_radius);
|
||||
|
||||
assert(_image_content);
|
||||
_image_content->set<int>("x", shadow_radius + border.l);
|
||||
_image_content->set<int>("y", shadow_radius + border.t);
|
||||
_image_content->set<int>("size[0]", content_view.width());
|
||||
_image_content->set<int>("size[1]", content_view.height());
|
||||
|
||||
if( !shadow_radius )
|
||||
{
|
||||
if( _image_shadow )
|
||||
{
|
||||
_image_shadow->destroy();
|
||||
_image_shadow.reset();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int shadow_inset = std::max<int>(get<float>("shadow-inset") + 0.5, 0),
|
||||
slice_width = shadow_radius + shadow_inset;
|
||||
|
||||
_image_shadow = _canvas_decoration->getRootGroup()
|
||||
->getOrCreateChild<sc::Image>("shadow");
|
||||
_image_shadow->set<std::string>("src", "gui/images/shadow.png");
|
||||
_image_shadow->set<float>("slice", 7);
|
||||
_image_shadow->set<std::string>("fill", "#000000");
|
||||
_image_shadow->set<float>("slice-width", slice_width);
|
||||
_image_shadow->set<int>("size[0]", outer_width);
|
||||
_image_shadow->set<int>("size[1]", outer_height);
|
||||
|
||||
// Draw shadow below decoration
|
||||
_image_shadow->set<int>("z-index", -1);
|
||||
}
|
||||
|
||||
} // namespace canvas
|
|
@ -1,123 +0,0 @@
|
|||
// Window for placing a Canvas onto it (for dialogs, menus, etc.)
|
||||
//
|
||||
// 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.
|
||||
|
||||
#ifndef CANVAS_WINDOW_HXX_
|
||||
#define CANVAS_WINDOW_HXX_
|
||||
|
||||
#include <simgear/canvas/elements/CanvasImage.hxx>
|
||||
#include <simgear/canvas/MouseEvent.hxx>
|
||||
#include <simgear/props/PropertyBasedElement.hxx>
|
||||
#include <simgear/props/propertyObject.hxx>
|
||||
#include <simgear/misc/CSSBorder.hxx>
|
||||
|
||||
#include <osg/Geode>
|
||||
#include <osg/Geometry>
|
||||
|
||||
namespace canvas
|
||||
{
|
||||
class Window:
|
||||
public simgear::canvas::Image
|
||||
{
|
||||
public:
|
||||
static const std::string TYPE_NAME;
|
||||
|
||||
enum Resize
|
||||
{
|
||||
NONE = 0,
|
||||
LEFT = 1,
|
||||
RIGHT = LEFT << 1,
|
||||
TOP = RIGHT << 1,
|
||||
BOTTOM = TOP << 1,
|
||||
INIT = BOTTOM << 1
|
||||
};
|
||||
|
||||
typedef simgear::canvas::Style Style;
|
||||
|
||||
/**
|
||||
* @param node Property node containing settings for this window:
|
||||
* capture-events Disable/Enable event capturing
|
||||
* content-size[0-1] Size of content area (excluding
|
||||
* decoration border)
|
||||
* decoration-border Size of decoration border
|
||||
* resize Enable resize cursor and properties
|
||||
* shadow-inset Inset of shadow image
|
||||
* shadow-radius Radius/outset of shadow image
|
||||
*/
|
||||
Window( const simgear::canvas::CanvasWeakPtr& canvas,
|
||||
const SGPropertyNode_ptr& node,
|
||||
const Style& parent_style = Style(),
|
||||
Element* parent = 0 );
|
||||
virtual ~Window();
|
||||
|
||||
virtual void update(double delta_time_sec);
|
||||
virtual void valueChanged(SGPropertyNode* node);
|
||||
|
||||
osg::Group* getGroup();
|
||||
const SGVec2<float> getPosition() const;
|
||||
const SGRect<float> getScreenRegion() const;
|
||||
|
||||
void setCanvasContent(simgear::canvas::CanvasPtr canvas);
|
||||
simgear::canvas::CanvasWeakPtr getCanvasContent() const;
|
||||
|
||||
simgear::canvas::CanvasPtr getCanvasDecoration();
|
||||
|
||||
bool isResizable() const;
|
||||
bool isCapturingEvents() const;
|
||||
|
||||
/**
|
||||
* Moves window on top of all other windows with the same z-index.
|
||||
*
|
||||
* @note If no z-index is set it defaults to 0.
|
||||
*/
|
||||
void raise();
|
||||
|
||||
void handleResize( uint8_t mode,
|
||||
const osg::Vec2f& offset = osg::Vec2f() );
|
||||
|
||||
protected:
|
||||
|
||||
enum Attributes
|
||||
{
|
||||
DECORATION = 1
|
||||
};
|
||||
|
||||
uint32_t _attributes_dirty;
|
||||
|
||||
simgear::canvas::CanvasPtr _canvas_decoration;
|
||||
simgear::canvas::CanvasWeakPtr _canvas_content;
|
||||
|
||||
simgear::canvas::ImagePtr _image_content,
|
||||
_image_shadow;
|
||||
|
||||
bool _resizable,
|
||||
_capture_events;
|
||||
|
||||
simgear::PropertyObject<int> _resize_top,
|
||||
_resize_right,
|
||||
_resize_bottom,
|
||||
_resize_left,
|
||||
_resize_status;
|
||||
|
||||
simgear::CSSBorder _decoration_border;
|
||||
|
||||
void parseDecorationBorder(const std::string& str);
|
||||
void updateDecoration();
|
||||
};
|
||||
} // namespace canvas
|
||||
|
||||
#endif /* CANVAS_WINDOW_HXX_ */
|
|
@ -21,8 +21,6 @@
|
|||
#ifndef _OD_GAUGE_HXX
|
||||
#define _OD_GAUGE_HXX
|
||||
|
||||
#include <Canvas/canvas_fwd.hpp>
|
||||
|
||||
#include <simgear/canvas/ODGauge.hxx>
|
||||
#include <simgear/canvas/CanvasPlacement.hxx>
|
||||
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#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>
|
||||
|
||||
|
@ -34,6 +33,7 @@
|
|||
#include <simgear/sg_inlines.h>
|
||||
|
||||
#include <simgear/canvas/Canvas.hxx>
|
||||
#include <simgear/canvas/CanvasWindow.hxx>
|
||||
#include <simgear/canvas/elements/CanvasElement.hxx>
|
||||
#include <simgear/canvas/elements/CanvasText.hxx>
|
||||
#include <simgear/canvas/MouseEvent.hxx>
|
||||
|
@ -59,7 +59,7 @@ typedef nasal::Ghost<sc::CanvasPtr> NasalCanvas;
|
|||
typedef nasal::Ghost<sc::ElementPtr> NasalElement;
|
||||
typedef nasal::Ghost<sc::GroupPtr> NasalGroup;
|
||||
typedef nasal::Ghost<sc::TextPtr> NasalText;
|
||||
typedef nasal::Ghost<canvas::WindowWeakPtr> NasalWindow;
|
||||
typedef nasal::Ghost<sc::WindowWeakPtr> NasalWindow;
|
||||
|
||||
naRef to_nasal_helper(naContext c, const osg::BoundingBox& bb)
|
||||
{
|
||||
|
@ -256,8 +256,8 @@ naRef initNasalCanvas(naRef globals, naContext c)
|
|||
|
||||
NasalWindow::init("canvas.Window")
|
||||
.bases<NasalElement>()
|
||||
.member("_node_ghost", &elementGetNode<canvas::Window>)
|
||||
.method("_getCanvasDecoration", &canvas::Window::getCanvasDecoration);
|
||||
.member("_node_ghost", &elementGetNode<sc::Window>)
|
||||
.method("_getCanvasDecoration", &sc::Window::getCanvasDecoration);
|
||||
|
||||
nasal::Hash globals_module(globals, c),
|
||||
canvas_module = globals_module.createHash("canvas");
|
||||
|
|
Loading…
Add table
Reference in a new issue