dran and drop for UIWidget

This commit is contained in:
Eduardo Bart 2012-01-19 23:16:10 -02:00
parent 733039e50e
commit 759b7f43b3
9 changed files with 69 additions and 6 deletions

4
TODO
View File

@ -45,7 +45,6 @@ change win32 mouse cursor icon
rework win32 key input system rework win32 key input system
== UI == UI
[bart] fix massive hotkeys when holding down a key
[bart] multiline rich text widget [bart] multiline rich text widget
[bart] move layout proprieties to widget style [bart] move layout proprieties to widget style
[bart] multiline text editor widget [bart] multiline text editor widget
@ -61,7 +60,8 @@ rework win32 key input system
[bart] check for recursive anchors and print a error instead of crashing [bart] check for recursive anchors and print a error instead of crashing
[bart] make api to enable/disable capture of events to avoid massive event processing [bart] make api to enable/disable capture of events to avoid massive event processing
[bart] review style apply system [bart] review style apply system
rework styles rendering order rework widgets rendering order
cache or preload otui files to avoid freezes from hd
== Client == Client
make possible to reload modules make possible to reload modules

View File

@ -50,12 +50,10 @@ end
function UIComboBox:onMouseWheel(mousePos, direction) function UIComboBox:onMouseWheel(mousePos, direction)
if direction == MouseWheelUp and self.m_currentIndex > 1 then if direction == MouseWheelUp and self.m_currentIndex > 1 then
self:setCurrentIndex(self.m_currentIndex - 1) self:setCurrentIndex(self.m_currentIndex - 1)
return true
elseif direction == MouseWheelDown and self.m_currentIndex < #self.m_options then elseif direction == MouseWheelDown and self.m_currentIndex < #self.m_options then
self:setCurrentIndex(self.m_currentIndex + 1) self:setCurrentIndex(self.m_currentIndex + 1)
return true
end end
return false return true
end end
function UIComboBox:onStyleApply(styleName, styleNode) function UIComboBox:onStyleApply(styleName, styleNode)

View File

@ -592,6 +592,8 @@ void X11Window::poll()
if(req->target == targets) { if(req->target == targets) {
Atom typeList[] = { XInternAtom(m_display, "UTF8_STRING", False), Atom typeList[] = { XInternAtom(m_display, "UTF8_STRING", False),
XInternAtom(m_display, "TEXT", False), XInternAtom(m_display, "TEXT", False),
XInternAtom(m_display, "STRING", False),
XInternAtom(m_display, "text/plain", False),
XInternAtom(m_display, "COMPOUND_TEXT", False), XInternAtom(m_display, "COMPOUND_TEXT", False),
XA_STRING }; XA_STRING };

View File

@ -48,11 +48,12 @@ public:
void setMouseReceiver(const UIWidgetPtr& widget) { m_mouseReceiver = widget; } void setMouseReceiver(const UIWidgetPtr& widget) { m_mouseReceiver = widget; }
void setKeyboardReceiver(const UIWidgetPtr& widget) { m_keyboardReceiver = widget; } void setKeyboardReceiver(const UIWidgetPtr& widget) { m_keyboardReceiver = widget; }
void setDebugBoxesDrawing(bool enabled) { m_drawDebugBoxes = enabled; } void setDebugBoxesDrawing(bool enabled) { m_drawDebugBoxes = enabled; }
void setDraggingWidget(const UIWidgetPtr& widget) { m_draggingWidget = widget; }
void resetMouseReceiver() { m_mouseReceiver = m_rootWidget; } void resetMouseReceiver() { m_mouseReceiver = m_rootWidget; }
void resetKeyboardReceiver() { m_keyboardReceiver = m_rootWidget; } void resetKeyboardReceiver() { m_keyboardReceiver = m_rootWidget; }
UIWidgetPtr getMouseReceiver() { return m_mouseReceiver; } UIWidgetPtr getMouseReceiver() { return m_mouseReceiver; }
UIWidgetPtr getKeyboardReceiver() { return m_keyboardReceiver; } UIWidgetPtr getKeyboardReceiver() { return m_keyboardReceiver; }
UIWidgetPtr getDraggingWidget() { return m_draggingWidget; }
UIWidgetPtr getRootWidget() { return m_rootWidget; } UIWidgetPtr getRootWidget() { return m_rootWidget; }
bool isOnInputEvent() { return m_isOnInputEvent; } bool isOnInputEvent() { return m_isOnInputEvent; }
@ -62,6 +63,7 @@ private:
UIWidgetPtr m_rootWidget; UIWidgetPtr m_rootWidget;
UIWidgetPtr m_mouseReceiver; UIWidgetPtr m_mouseReceiver;
UIWidgetPtr m_keyboardReceiver; UIWidgetPtr m_keyboardReceiver;
UIWidgetPtr m_draggingWidget;
bool m_isOnInputEvent; bool m_isOnInputEvent;
Boolean<false> m_drawDebugBoxes; Boolean<false> m_drawDebugBoxes;
std::map<std::string, OTMLNodePtr> m_styles; std::map<std::string, OTMLNodePtr> m_styles;

View File

@ -681,6 +681,22 @@ void UIWidget::setPhantom(bool phantom)
m_phantom = phantom; m_phantom = phantom;
} }
void UIWidget::setDragging(bool dragging)
{
if(dragging) {
g_ui.setDraggingWidget(asUIWidget());
} else {
if(g_ui.getDraggingWidget() == asUIWidget())
g_ui.setDraggingWidget(nullptr);
}
m_dragging = dragging;
}
void UIWidget::setDragable(bool dragable)
{
m_dragable = dragable;
}
void UIWidget::setFixedSize(bool fixed) void UIWidget::setFixedSize(bool fixed)
{ {
m_fixedSize = fixed; m_fixedSize = fixed;
@ -1054,6 +1070,21 @@ void UIWidget::onHoverChange(bool hovered)
g_ui.getRootWidget()->updateState(Fw::HoverState); g_ui.getRootWidget()->updateState(Fw::HoverState);
} }
void UIWidget::onDragEnter(const Point& mousePos)
{
callLuaField("onDragEnter", mousePos);
}
void UIWidget::onDragLeave(UIWidgetPtr droppedWidget, const Point& mousePos)
{
callLuaField("onDragLeave", droppedWidget, mousePos);
}
void UIWidget::onDrop(UIWidgetPtr draggedWidget, const Point& mousePos)
{
callLuaField("onDrop", draggedWidget, mousePos);
}
bool UIWidget::onKeyText(const std::string& keyText) bool UIWidget::onKeyText(const std::string& keyText)
{ {
return callLuaField<bool>("onKeyText", keyText); return callLuaField<bool>("onKeyText", keyText);
@ -1084,11 +1115,24 @@ void UIWidget::onMouseRelease(const Point& mousePos, Fw::MouseButton button)
if(isPressed() && getRect().contains(mousePos)) if(isPressed() && getRect().contains(mousePos))
callLuaField("onClick"); callLuaField("onClick");
UIWidgetPtr draggedWidget = g_ui.getDraggingWidget();
if(draggedWidget && containsPoint(mousePos) && button == Fw::MouseLeftButton) {
onDrop(draggedWidget, mousePos);
draggedWidget->onDragLeave(asUIWidget(), mousePos);
draggedWidget->setDragging(false);
}
callLuaField("onMouseRelease", mousePos, button); callLuaField("onMouseRelease", mousePos, button);
} }
bool UIWidget::onMouseMove(const Point& mousePos, const Point& mouseMoved) bool UIWidget::onMouseMove(const Point& mousePos, const Point& mouseMoved)
{ {
if(isDragable() && isPressed() && !m_dragging && !g_ui.getDraggingWidget()) {
setDragging(true);
g_ui.setDraggingWidget(asUIWidget());
onDragEnter(mousePos - mouseMoved);
}
return callLuaField<bool>("onMouseMove", mousePos, mouseMoved); return callLuaField<bool>("onMouseMove", mousePos, mouseMoved);
} }

View File

@ -62,6 +62,8 @@ protected:
Boolean<false> m_fixedSize; Boolean<false> m_fixedSize;
Boolean<false> m_pressed; Boolean<false> m_pressed;
Boolean<false> m_phantom; Boolean<false> m_phantom;
Boolean<false> m_dragable;
Boolean<false> m_dragging;
Boolean<false> m_destroyed; Boolean<false> m_destroyed;
UILayoutPtr m_layout; UILayoutPtr m_layout;
UIWidgetWeakPtr m_parent; UIWidgetWeakPtr m_parent;
@ -112,6 +114,8 @@ public:
void setChecked(bool checked); void setChecked(bool checked);
void setFocusable(bool focusable); void setFocusable(bool focusable);
void setPhantom(bool phantom); void setPhantom(bool phantom);
void setDragging(bool dragging);
void setDragable(bool dragable);
void setFixedSize(bool fixed); void setFixedSize(bool fixed);
void setLastFocusReason(Fw::FocusReason reason); void setLastFocusReason(Fw::FocusReason reason);
@ -161,6 +165,9 @@ protected:
virtual void onGeometryChange(const Rect& oldRect, const Rect& newRect); virtual void onGeometryChange(const Rect& oldRect, const Rect& newRect);
virtual void onFocusChange(bool focused, Fw::FocusReason reason); virtual void onFocusChange(bool focused, Fw::FocusReason reason);
virtual void onHoverChange(bool hovered); virtual void onHoverChange(bool hovered);
virtual void onDragEnter(const Point& mousePos);
virtual void onDragLeave(UIWidgetPtr droppedWidget, const Point& mousePos);
virtual void onDrop(UIWidgetPtr draggedWidget, const Point& mousePos);
virtual bool onKeyText(const std::string& keyText); virtual bool onKeyText(const std::string& keyText);
virtual bool onKeyDown(uchar keyCode, int keyboardModifiers); virtual bool onKeyDown(uchar keyCode, int keyboardModifiers);
virtual bool onKeyPress(uchar keyCode, int keyboardModifiers, bool wouldFilter); virtual bool onKeyPress(uchar keyCode, int keyboardModifiers, bool wouldFilter);
@ -206,6 +213,8 @@ public:
bool isExplicitlyVisible() { return m_visible; } bool isExplicitlyVisible() { return m_visible; }
bool isFocusable() { return m_focusable; } bool isFocusable() { return m_focusable; }
bool isPhantom() { return m_phantom; } bool isPhantom() { return m_phantom; }
bool isDragable() { return m_dragable; }
bool isDragging() { return m_dragging; }
bool isFixedSize() { return m_fixedSize; } bool isFixedSize() { return m_fixedSize; }
bool isDestroyed() { return m_destroyed; } bool isDestroyed() { return m_destroyed; }

View File

@ -108,6 +108,8 @@ void UIWidget::parseBaseStyle(const OTMLNodePtr& styleNode)
setVisible(node->value<bool>()); setVisible(node->value<bool>());
else if(node->tag() == "checked") else if(node->tag() == "checked")
setChecked(node->value<bool>()); setChecked(node->value<bool>());
else if(node->tag() == "dragable")
setChecked(node->value<bool>());
else if(node->tag() == "on") else if(node->tag() == "on")
setOn(node->value<bool>()); setOn(node->value<bool>());
else if(node->tag() == "focusable") else if(node->tag() == "focusable")

View File

@ -25,6 +25,11 @@
#include <framework/graphics/graphics.h> #include <framework/graphics/graphics.h>
#include <framework/graphics/fontmanager.h> #include <framework/graphics/fontmanager.h>
UIItem::UIItem()
{
m_dragable = true;
}
void UIItem::draw() void UIItem::draw()
{ {
drawSelf(); drawSelf();

View File

@ -30,6 +30,7 @@
class UIItem : public UIWidget class UIItem : public UIWidget
{ {
public: public:
UIItem();
void draw(); void draw();
void setItem(const ItemPtr& item) { m_item = item; } void setItem(const ItemPtr& item) { m_item = item; }