implement onMouseDoubleClick event in UIWidget

This commit is contained in:
Eduardo Bart 2012-02-03 03:25:01 -02:00
parent 4563471790
commit 1340699b01
4 changed files with 22 additions and 0 deletions

View File

@ -27,6 +27,7 @@
void Timer::restart() void Timer::restart()
{ {
m_startTicks = g_clock.ticks(); m_startTicks = g_clock.ticks();
m_stopped = false;
} }
ticks_t Timer::ticksElapsed() ticks_t Timer::ticksElapsed()

View File

@ -31,13 +31,17 @@ public:
Timer() { restart(); } Timer() { restart(); }
void restart(); void restart();
void stop() { m_stopped = true; }
ticks_t startTicks() { return m_startTicks; } ticks_t startTicks() { return m_startTicks; }
ticks_t ticksElapsed(); ticks_t ticksElapsed();
double timeElapsed() { return ticksElapsed()/1000.0; } double timeElapsed() { return ticksElapsed()/1000.0; }
bool running() { return !m_stopped; }
private: private:
ticks_t m_startTicks; ticks_t m_startTicks;
Boolean<false> m_stopped;
}; };
#endif #endif

View File

@ -35,6 +35,7 @@ UIWidget::UIWidget()
{ {
m_lastFocusReason = Fw::ActiveFocusReason; m_lastFocusReason = Fw::ActiveFocusReason;
m_states = Fw::DefaultState; m_states = Fw::DefaultState;
m_clickTimer.stop();
initBaseStyle(); initBaseStyle();
initText(); initText();
@ -1111,6 +1112,14 @@ bool UIWidget::onKeyUp(uchar keyCode, int keyboardModifiers)
bool UIWidget::onMousePress(const Point& mousePos, Fw::MouseButton button) bool UIWidget::onMousePress(const Point& mousePos, Fw::MouseButton button)
{ {
if(button == Fw::MouseLeftButton) {
if(m_clickTimer.running() && m_clickTimer.ticksElapsed() <= 500) {
if(onMouseDoubleClick(mousePos))
return true;
m_clickTimer.stop();
} else
m_clickTimer.restart();
}
return callLuaField<bool>("onMousePress", mousePos, button); return callLuaField<bool>("onMousePress", mousePos, button);
} }
@ -1145,6 +1154,11 @@ bool UIWidget::onMouseWheel(const Point& mousePos, Fw::MouseWheelDirection direc
return callLuaField<bool>("onMouseWheel", mousePos, direction); return callLuaField<bool>("onMouseWheel", mousePos, direction);
} }
bool UIWidget::onMouseDoubleClick(const Point& mousePos)
{
return callLuaField<bool>("onMouseDoubleClick", mousePos);
}
bool UIWidget::propagateOnKeyText(const std::string& keyText) bool UIWidget::propagateOnKeyText(const std::string& keyText)
{ {
// do a backup of children list, because it may change while looping it // do a backup of children list, because it may change while looping it

View File

@ -29,6 +29,7 @@
#include <framework/otml/otmlnode.h> #include <framework/otml/otmlnode.h>
#include <framework/graphics/font.h> #include <framework/graphics/font.h>
#include <framework/graphics/coordsbuffer.h> #include <framework/graphics/coordsbuffer.h>
#include <framework/core/timer.h>
template<typename T = int> template<typename T = int>
struct EdgeGroup { struct EdgeGroup {
@ -71,6 +72,7 @@ protected:
UIWidgetList m_lockedChildren; UIWidgetList m_lockedChildren;
UIWidgetPtr m_focusedChild; UIWidgetPtr m_focusedChild;
OTMLNodePtr m_style; OTMLNodePtr m_style;
Timer m_clickTimer;
Fw::FocusReason m_lastFocusReason; Fw::FocusReason m_lastFocusReason;
public: public:
@ -176,6 +178,7 @@ protected:
virtual bool onMouseRelease(const Point& mousePos, Fw::MouseButton button); virtual bool onMouseRelease(const Point& mousePos, Fw::MouseButton button);
virtual bool onMouseMove(const Point& mousePos, const Point& mouseMoved); virtual bool onMouseMove(const Point& mousePos, const Point& mouseMoved);
virtual bool onMouseWheel(const Point& mousePos, Fw::MouseWheelDirection direction); virtual bool onMouseWheel(const Point& mousePos, Fw::MouseWheelDirection direction);
virtual bool onMouseDoubleClick(const Point& mousePos);
bool propagateOnKeyText(const std::string& keyText); bool propagateOnKeyText(const std::string& keyText);
bool propagateOnKeyDown(uchar keyCode, int keyboardModifiers); bool propagateOnKeyDown(uchar keyCode, int keyboardModifiers);