#include "CanvasEventManager.hxx"
#include "CanvasEventVisitor.hxx"
#include "CanvasPlacement.hxx"
+#include <simgear/canvas/events/KeyboardEvent.hxx>
#include <simgear/canvas/events/MouseEvent.hxx>
#include <simgear/scene/util/parse_color.hxx>
#include <simgear/scene/util/RenderConstants.hxx>
return _root_group;
}
+ //----------------------------------------------------------------------------
+ void Canvas::setLayout(const LayoutRef& layout)
+ {
+ _layout = layout;
+ _layout->setCanvas(this);
+ }
+
+ //----------------------------------------------------------------------------
+ void Canvas::setFocusElement(const ElementPtr& el)
+ {
+ if( el && el->getCanvas().lock() != this )
+ {
+ SG_LOG(SG_GUI, SG_WARN, "setFocusElement: element not from this canvas");
+ return;
+ }
+
+ // TODO focus out/in events
+ _focus_element = el;
+ }
+
+ //----------------------------------------------------------------------------
+ void Canvas::clearFocusElement()
+ {
+ _focus_element.reset();
+ }
+
//----------------------------------------------------------------------------
void Canvas::enableRendering(bool force)
{
//----------------------------------------------------------------------------
void Canvas::update(double delta_time_sec)
{
- if( (!_texture.serviceable() && _status != STATUS_DIRTY)
- || (_status & CREATE_FAILED) )
+ if( _status & (CREATE_FAILED | MISSING_SIZE) )
return;
- if( _status == STATUS_DIRTY )
+ if( _status & STATUS_DIRTY )
{
_texture.setSize(_size_x, _size_y);
}
}
+ if( _layout )
+ _layout->setGeometry(SGRecti(0, 0, _view_width, _view_height));
+
if( _visible || _render_always )
{
BOOST_FOREACH(CanvasWeakPtr canvas_weak, _child_canvases)
const EventListener& cb )
{
if( !_root_group.get() )
- throw std::runtime_error("Canvas::AddEventListener: no root group!");
+ throw std::runtime_error("Canvas::addEventListener: no root group!");
return _root_group->addEventListener(type, cb);
}
+ //----------------------------------------------------------------------------
+ bool Canvas::dispatchEvent(const EventPtr& event)
+ {
+ if( !_root_group.get() )
+ throw std::runtime_error("Canvas::dispatchEvent: no root group!");
+
+ return _root_group->dispatchEvent(event);
+ }
+
//----------------------------------------------------------------------------
void Canvas::setSizeX(int sx)
{
return _event_manager->handleEvent(event, visitor.getPropagationPath());
}
+ //----------------------------------------------------------------------------
+ bool Canvas::handleKeyboardEvent(const KeyboardEventPtr& event)
+ {
+ ElementPtr target = _focus_element.lock();
+ if( !target )
+ target = _root_group;
+ if( !target )
+ return false;
+
+ return target->dispatchEvent(event);
+ }
+
//----------------------------------------------------------------------------
bool Canvas::propagateEvent( EventPtr const& event,
EventPropagationPath const& path )
else if( node->getIndex() == 1 )
setSizeY( node->getIntValue() );
}
+ else if( name == "update" )
+ {
+ if( _root_group )
+ _root_group->update(0);
+ return update(0);
+ }
else if( name == "view" )
{
if( node->getIndex() == 0 )
_status_msg = "Missing size-y";
else if( _status & CREATE_FAILED )
_status_msg = "Creating render target failed";
- else if( _status == STATUS_DIRTY )
+ else if( _status & STATUS_DIRTY )
_status_msg = "Creation pending...";
else
_status_msg = "Ok";