Base canvas::Window on simgear::canvas::Image
This commit is contained in:
parent
1c24acf41e
commit
2dee846930
3 changed files with 31 additions and 75 deletions
|
@ -92,19 +92,6 @@ class WindowPlacement:
|
|||
simgear::canvas::CanvasWeakPtr _canvas;
|
||||
};
|
||||
|
||||
/**
|
||||
* Store pointer to window as user data
|
||||
*/
|
||||
class WindowUserData:
|
||||
public osg::Referenced
|
||||
{
|
||||
public:
|
||||
canvas::WindowWeakPtr window;
|
||||
WindowUserData(canvas::WindowPtr window):
|
||||
window(window)
|
||||
{}
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
typedef boost::shared_ptr<canvas::Window> WindowPtr;
|
||||
WindowPtr windowFactory(SGPropertyNode* node)
|
||||
|
@ -240,7 +227,7 @@ void GUIMgr::elementCreated(simgear::PropertyBasedElementPtr element)
|
|||
_transform->addChild(layer);
|
||||
}
|
||||
}
|
||||
window->getGroup()->setUserData(new WindowUserData(window));
|
||||
|
||||
layer->addChild(window->getGroup());
|
||||
}
|
||||
|
||||
|
@ -345,8 +332,13 @@ bool GUIMgr::handleMouse(const osgGA::GUIEventAdapter& ea)
|
|||
{
|
||||
assert(layer->getChild(j)->getUserData());
|
||||
canvas::WindowPtr window =
|
||||
static_cast<WindowUserData*>(layer->getChild(j)->getUserData())
|
||||
->window.lock();
|
||||
boost::static_pointer_cast<canvas::Window>
|
||||
(
|
||||
static_cast<sc::Element::OSGUserData*>
|
||||
(
|
||||
layer->getChild(j)->getUserData()
|
||||
)->element
|
||||
);
|
||||
|
||||
if( !window->isCapturingEvents() || !window->isVisible() )
|
||||
continue;
|
||||
|
@ -463,7 +455,7 @@ bool GUIMgr::handleMouse(const osgGA::GUIEventAdapter& ea)
|
|||
move_event->client_pos -= toOsg(last_mouse_over->getPosition());
|
||||
move_event->local_pos = move_event->client_pos;
|
||||
|
||||
last_mouse_over->handleMouseEvent(move_event);
|
||||
last_mouse_over->handleEvent(move_event);
|
||||
}
|
||||
_last_mouse_over = window_at_cursor;
|
||||
event->type = sc::Event::MOUSE_MOVE;
|
||||
|
@ -488,7 +480,7 @@ bool GUIMgr::handleMouse(const osgGA::GUIEventAdapter& ea)
|
|||
{
|
||||
event->client_pos -= toOsg(target_window->getPosition());
|
||||
event->local_pos = event->client_pos;
|
||||
return target_window->handleMouseEvent(event);
|
||||
return target_window->handleEvent(event);
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
|
|
@ -33,9 +33,8 @@ namespace canvas
|
|||
|
||||
//----------------------------------------------------------------------------
|
||||
Window::Window(SGPropertyNode* node):
|
||||
PropertyBasedElement(node),
|
||||
Image(sc::CanvasPtr(), node),
|
||||
_attributes_dirty(0),
|
||||
_image(sc::CanvasPtr(), node),
|
||||
_resizable(false),
|
||||
_capture_events(true),
|
||||
_resize_top(node, "resize-top"),
|
||||
|
@ -44,8 +43,6 @@ namespace canvas
|
|||
_resize_left(node, "resize-left"),
|
||||
_resize_status(node, "resize-status")
|
||||
{
|
||||
_image.removeListener();
|
||||
|
||||
node->setFloatValue("source/right", 1);
|
||||
node->setFloatValue("source/bottom", 1);
|
||||
node->setBoolValue("source/normalized", true);
|
||||
|
@ -67,7 +64,7 @@ namespace canvas
|
|||
_attributes_dirty &= ~DECORATION;
|
||||
}
|
||||
|
||||
_image.update(delta_time_sec);
|
||||
Image::update(delta_time_sec);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
@ -95,37 +92,19 @@ namespace canvas
|
|||
}
|
||||
|
||||
if( !handled )
|
||||
_image.valueChanged(node);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void Window::childAdded(SGPropertyNode* parent, SGPropertyNode* child)
|
||||
{
|
||||
_image.childAdded(parent, child);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void Window::childRemoved(SGPropertyNode* parent, SGPropertyNode* child)
|
||||
{
|
||||
_image.childRemoved(parent, child);
|
||||
Image::valueChanged(node);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
osg::Group* Window::getGroup()
|
||||
{
|
||||
return _image.getMatrixTransform();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
const SGRect<float>& Window::getRegion() const
|
||||
{
|
||||
return _image.getRegion();
|
||||
return getMatrixTransform();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
const SGVec2<float> Window::getPosition() const
|
||||
{
|
||||
const osg::Matrix& m = _image.getMatrixTransform()->getMatrix();
|
||||
const osg::Matrix& m = getMatrixTransform()->getMatrix();
|
||||
return SGVec2<float>( m(3, 0), m(3, 1) );
|
||||
}
|
||||
|
||||
|
@ -139,13 +118,13 @@ namespace canvas
|
|||
void Window::setCanvas(sc::CanvasPtr canvas)
|
||||
{
|
||||
_canvas_content = canvas;
|
||||
_image.setSrcCanvas(canvas);
|
||||
setSrcCanvas(canvas);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
sc::CanvasWeakPtr Window::getCanvas() const
|
||||
{
|
||||
return _image.getSrcCanvas();
|
||||
return getSrcCanvas();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
@ -154,12 +133,6 @@ namespace canvas
|
|||
return _canvas_decoration;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool Window::isVisible() const
|
||||
{
|
||||
return _image.isVisible();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool Window::isResizable() const
|
||||
{
|
||||
|
@ -172,12 +145,6 @@ namespace canvas
|
|||
return _capture_events;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool Window::handleMouseEvent(const sc::MouseEventPtr& event)
|
||||
{
|
||||
return _image.handleEvent(event);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void Window::handleResize(uint8_t mode, const osg::Vec2f& delta)
|
||||
{
|
||||
|
@ -212,13 +179,17 @@ namespace canvas
|
|||
if( node_raise && !node_raise->getBoolValue() )
|
||||
return;
|
||||
|
||||
// Keep a reference to ensure the window is not deleted between removing and
|
||||
// adding it back to the scenegraph
|
||||
osg::ref_ptr<osg::Group> window = getGroup();
|
||||
|
||||
BOOST_FOREACH(osg::Group* parent, getGroup()->getParents())
|
||||
{
|
||||
// Remove window...
|
||||
parent->removeChild(getGroup());
|
||||
parent->removeChild(window);
|
||||
|
||||
// ...and add again as topmost window
|
||||
parent->addChild(getGroup());
|
||||
parent->addChild(window);
|
||||
}
|
||||
|
||||
if( node_raise )
|
||||
|
@ -242,9 +213,9 @@ namespace canvas
|
|||
if( _decoration_border.isNone() && !shadow_radius )
|
||||
{
|
||||
sc::CanvasPtr canvas_content = _canvas_content.lock();
|
||||
_image.setSrcCanvas(canvas_content);
|
||||
_image.set<int>("size[0]", canvas_content->getViewWidth());
|
||||
_image.set<int>("size[1]", canvas_content->getViewHeight());
|
||||
setSrcCanvas(canvas_content);
|
||||
set<int>("size[0]", canvas_content->getViewWidth());
|
||||
set<int>("size[1]", canvas_content->getViewHeight());
|
||||
|
||||
_image_content.reset();
|
||||
_image_shadow.reset();
|
||||
|
@ -268,7 +239,7 @@ namespace canvas
|
|||
_canvas_decoration = mgr->createCanvas("window-decoration");
|
||||
_canvas_decoration->getProps()
|
||||
->setStringValue("background", "rgba(0,0,0,0)");
|
||||
_image.setSrcCanvas(_canvas_decoration);
|
||||
setSrcCanvas(_canvas_decoration);
|
||||
|
||||
_image_content = _canvas_decoration->getRootGroup()
|
||||
->createChild<sc::Image>("content");
|
||||
|
@ -297,9 +268,9 @@ namespace canvas
|
|||
_canvas_decoration->setViewWidth( outer_width );
|
||||
_canvas_decoration->setViewHeight( outer_height );
|
||||
|
||||
_image.set<int>("size[0]", outer_width - shad2);
|
||||
_image.set<int>("size[1]", outer_height - shad2);
|
||||
_image.set<int>("outset", shadow_radius);
|
||||
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);
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
namespace canvas
|
||||
{
|
||||
class Window:
|
||||
public simgear::PropertyBasedElement
|
||||
public simgear::canvas::Image
|
||||
{
|
||||
public:
|
||||
|
||||
|
@ -50,11 +50,8 @@ namespace canvas
|
|||
|
||||
virtual void update(double delta_time_sec);
|
||||
virtual void valueChanged(SGPropertyNode* node);
|
||||
virtual void childAdded(SGPropertyNode* parent, SGPropertyNode* child);
|
||||
virtual void childRemoved(SGPropertyNode* parent, SGPropertyNode* child);
|
||||
|
||||
osg::Group* getGroup();
|
||||
const SGRect<float>& getRegion() const;
|
||||
const SGVec2<float> getPosition() const;
|
||||
const SGRect<float> getScreenRegion() const;
|
||||
|
||||
|
@ -63,12 +60,9 @@ namespace canvas
|
|||
|
||||
simgear::canvas::CanvasPtr getCanvasDecoration();
|
||||
|
||||
bool isVisible() const;
|
||||
bool isResizable() const;
|
||||
bool isCapturingEvents() const;
|
||||
|
||||
bool handleMouseEvent(const simgear::canvas::MouseEventPtr& event);
|
||||
|
||||
void handleResize(uint8_t mode, const osg::Vec2f& delta = osg::Vec2f());
|
||||
|
||||
void doRaise(SGPropertyNode* node_raise = 0);
|
||||
|
@ -85,7 +79,6 @@ namespace canvas
|
|||
simgear::canvas::CanvasPtr _canvas_decoration;
|
||||
simgear::canvas::CanvasWeakPtr _canvas_content;
|
||||
|
||||
simgear::canvas::Image _image;
|
||||
simgear::canvas::ImagePtr _image_content,
|
||||
_image_shadow;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue