canvas: Event improvements and new events (dragstart, dragend)
This commit is contained in:
@@ -65,6 +65,11 @@ namespace canvas
|
|||||||
// of the actual event instances.
|
// of the actual event instances.
|
||||||
virtual ~Event();
|
virtual ~Event();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clone event and set to the given type (Same type if not specified)
|
||||||
|
*/
|
||||||
|
virtual Event* clone(int type = 0) const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get whether this events support bubbling
|
* Get whether this events support bubbling
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -114,6 +114,8 @@ namespace canvas
|
|||||||
return handled;
|
return handled;
|
||||||
}
|
}
|
||||||
case Event::DRAG:
|
case Event::DRAG:
|
||||||
|
case Event::DRAG_START:
|
||||||
|
case Event::DRAG_END:
|
||||||
if( !_last_mouse_down.valid() )
|
if( !_last_mouse_down.valid() )
|
||||||
return false;
|
return false;
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ ENUM_MAPPING(MOUSE_UP, "mouseup", MouseEvent)
|
|||||||
ENUM_MAPPING(CLICK, "click", MouseEvent)
|
ENUM_MAPPING(CLICK, "click", MouseEvent)
|
||||||
ENUM_MAPPING(DBL_CLICK, "dblclick", MouseEvent)
|
ENUM_MAPPING(DBL_CLICK, "dblclick", MouseEvent)
|
||||||
ENUM_MAPPING(DRAG, "drag", MouseEvent)
|
ENUM_MAPPING(DRAG, "drag", MouseEvent)
|
||||||
|
ENUM_MAPPING(DRAG_START, "dragstart", MouseEvent)
|
||||||
|
ENUM_MAPPING(DRAG_END, "dragend", MouseEvent)
|
||||||
ENUM_MAPPING(WHEEL, "wheel", MouseEvent)
|
ENUM_MAPPING(WHEEL, "wheel", MouseEvent)
|
||||||
ENUM_MAPPING(MOUSE_MOVE, "mousemove", MouseEvent)
|
ENUM_MAPPING(MOUSE_MOVE, "mousemove", MouseEvent)
|
||||||
ENUM_MAPPING(MOUSE_OVER, "mouseover", MouseEvent)
|
ENUM_MAPPING(MOUSE_OVER, "mouseover", MouseEvent)
|
||||||
|
|||||||
@@ -212,6 +212,19 @@ namespace canvas
|
|||||||
_resize_left = getRegion().l() + offset.x();
|
_resize_left = getRegion().l() + offset.x();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
bool Window::handleEvent(const EventPtr& event)
|
||||||
|
{
|
||||||
|
if( auto mouse_event = dynamic_cast<MouseEvent*>(event.get()) )
|
||||||
|
{
|
||||||
|
mouse_event->local_pos =
|
||||||
|
mouse_event->client_pos =
|
||||||
|
mouse_event->screen_pos - toOsg(getPosition());
|
||||||
|
}
|
||||||
|
|
||||||
|
return Image::handleEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void Window::parseDecorationBorder(const std::string& str)
|
void Window::parseDecorationBorder(const std::string& str)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -96,6 +96,8 @@ namespace canvas
|
|||||||
void handleResize( uint8_t mode,
|
void handleResize( uint8_t mode,
|
||||||
const osg::Vec2f& offset = osg::Vec2f() );
|
const osg::Vec2f& offset = osg::Vec2f() );
|
||||||
|
|
||||||
|
bool handleEvent(const EventPtr& event) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
enum Attributes
|
enum Attributes
|
||||||
|
|||||||
@@ -271,8 +271,7 @@ namespace canvas
|
|||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void Element::setFocus()
|
void Element::setFocus()
|
||||||
{
|
{
|
||||||
CanvasPtr canvas = _canvas.lock();
|
if( auto canvas = _canvas.lock() )
|
||||||
if( canvas )
|
|
||||||
canvas->setFocusElement(this);
|
canvas->setFocusElement(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ namespace canvas
|
|||||||
|
|
||||||
const SGRect<float>& getRegion() const;
|
const SGRect<float>& getRegion() const;
|
||||||
|
|
||||||
bool handleEvent(const EventPtr& event);
|
bool handleEvent(const EventPtr& event) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -46,6 +46,14 @@ namespace canvas
|
|||||||
// assert( type_map.find(type_id) != type_map.end() );
|
// assert( type_map.find(type_id) != type_map.end() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
CustomEvent* CustomEvent::clone(int type) const
|
||||||
|
{
|
||||||
|
auto event = new CustomEvent(*this);
|
||||||
|
event->type = type;
|
||||||
|
return event;
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void CustomEvent::setDetail(StringMap const& data)
|
void CustomEvent::setDetail(StringMap const& data)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ namespace canvas
|
|||||||
bool bubbles = false,
|
bool bubbles = false,
|
||||||
StringMap const& data = StringMap() );
|
StringMap const& data = StringMap() );
|
||||||
|
|
||||||
|
CustomEvent* clone(int type = 0) const override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set user data
|
* Set user data
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -69,6 +69,14 @@ namespace canvas
|
|||||||
// // TODO what to do with wrong event type?
|
// // TODO what to do with wrong event type?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
KeyboardEvent* KeyboardEvent::clone(int type) const
|
||||||
|
{
|
||||||
|
auto event = new KeyboardEvent(*this);
|
||||||
|
event->type = type;
|
||||||
|
return event;
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void KeyboardEvent::setKey(uint32_t key)
|
void KeyboardEvent::setKey(uint32_t key)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ namespace canvas
|
|||||||
|
|
||||||
KeyboardEvent();
|
KeyboardEvent();
|
||||||
KeyboardEvent(const osgGA::GUIEventAdapter& ea);
|
KeyboardEvent(const osgGA::GUIEventAdapter& ea);
|
||||||
|
KeyboardEvent* clone(int type = 0) const override;
|
||||||
|
|
||||||
void setKey(uint32_t key);
|
void setKey(uint32_t key);
|
||||||
void setUnmodifiedKey(uint32_t key);
|
void setUnmodifiedKey(uint32_t key);
|
||||||
|
|||||||
@@ -48,6 +48,14 @@ namespace canvas
|
|||||||
button += 1;
|
button += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
MouseEvent* MouseEvent::clone(int type) const
|
||||||
|
{
|
||||||
|
auto event = new MouseEvent(*this);
|
||||||
|
event->type = type;
|
||||||
|
return event;
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
bool MouseEvent::canBubble() const
|
bool MouseEvent::canBubble() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ namespace canvas
|
|||||||
public:
|
public:
|
||||||
MouseEvent();
|
MouseEvent();
|
||||||
MouseEvent(const osgGA::GUIEventAdapter& ea);
|
MouseEvent(const osgGA::GUIEventAdapter& ea);
|
||||||
|
MouseEvent* clone(int type = 0) const override;
|
||||||
|
|
||||||
virtual bool canBubble() const;
|
virtual bool canBubble() const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user