diff --git a/TODO b/TODO index 2bc16ac0..d02f73dc 100644 --- a/TODO +++ b/TODO @@ -45,7 +45,6 @@ change win32 mouse cursor icon rework win32 key input system == UI -[bart] fix massive hotkeys when holding down a key [bart] multiline rich text widget [bart] move layout proprieties to widget style [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] make api to enable/disable capture of events to avoid massive event processing [bart] review style apply system -rework styles rendering order +rework widgets rendering order +cache or preload otui files to avoid freezes from hd == Client make possible to reload modules diff --git a/modules/core_widgets/uicombobox.lua b/modules/core_widgets/uicombobox.lua index 5522a823..676bdf1d 100644 --- a/modules/core_widgets/uicombobox.lua +++ b/modules/core_widgets/uicombobox.lua @@ -50,12 +50,10 @@ end function UIComboBox:onMouseWheel(mousePos, direction) if direction == MouseWheelUp and self.m_currentIndex > 1 then self:setCurrentIndex(self.m_currentIndex - 1) - return true elseif direction == MouseWheelDown and self.m_currentIndex < #self.m_options then self:setCurrentIndex(self.m_currentIndex + 1) - return true end - return false + return true end function UIComboBox:onStyleApply(styleName, styleNode) diff --git a/src/framework/platform/x11window.cpp b/src/framework/platform/x11window.cpp index 87a392a5..bd484075 100644 --- a/src/framework/platform/x11window.cpp +++ b/src/framework/platform/x11window.cpp @@ -592,6 +592,8 @@ void X11Window::poll() if(req->target == targets) { Atom typeList[] = { XInternAtom(m_display, "UTF8_STRING", False), XInternAtom(m_display, "TEXT", False), + XInternAtom(m_display, "STRING", False), + XInternAtom(m_display, "text/plain", False), XInternAtom(m_display, "COMPOUND_TEXT", False), XA_STRING }; diff --git a/src/framework/ui/uimanager.h b/src/framework/ui/uimanager.h index 0c5ef79c..48021f60 100644 --- a/src/framework/ui/uimanager.h +++ b/src/framework/ui/uimanager.h @@ -48,11 +48,12 @@ public: void setMouseReceiver(const UIWidgetPtr& widget) { m_mouseReceiver = widget; } void setKeyboardReceiver(const UIWidgetPtr& widget) { m_keyboardReceiver = widget; } void setDebugBoxesDrawing(bool enabled) { m_drawDebugBoxes = enabled; } + void setDraggingWidget(const UIWidgetPtr& widget) { m_draggingWidget = widget; } void resetMouseReceiver() { m_mouseReceiver = m_rootWidget; } void resetKeyboardReceiver() { m_keyboardReceiver = m_rootWidget; } UIWidgetPtr getMouseReceiver() { return m_mouseReceiver; } UIWidgetPtr getKeyboardReceiver() { return m_keyboardReceiver; } - + UIWidgetPtr getDraggingWidget() { return m_draggingWidget; } UIWidgetPtr getRootWidget() { return m_rootWidget; } bool isOnInputEvent() { return m_isOnInputEvent; } @@ -62,6 +63,7 @@ private: UIWidgetPtr m_rootWidget; UIWidgetPtr m_mouseReceiver; UIWidgetPtr m_keyboardReceiver; + UIWidgetPtr m_draggingWidget; bool m_isOnInputEvent; Boolean m_drawDebugBoxes; std::map m_styles; diff --git a/src/framework/ui/uiwidget.cpp b/src/framework/ui/uiwidget.cpp index 499c0e6b..8346a36e 100644 --- a/src/framework/ui/uiwidget.cpp +++ b/src/framework/ui/uiwidget.cpp @@ -681,6 +681,22 @@ void UIWidget::setPhantom(bool 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) { m_fixedSize = fixed; @@ -1054,6 +1070,21 @@ void UIWidget::onHoverChange(bool hovered) 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) { return callLuaField("onKeyText", keyText); @@ -1084,11 +1115,24 @@ void UIWidget::onMouseRelease(const Point& mousePos, Fw::MouseButton button) if(isPressed() && getRect().contains(mousePos)) 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); } 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("onMouseMove", mousePos, mouseMoved); } diff --git a/src/framework/ui/uiwidget.h b/src/framework/ui/uiwidget.h index afb88065..230aaac0 100644 --- a/src/framework/ui/uiwidget.h +++ b/src/framework/ui/uiwidget.h @@ -62,6 +62,8 @@ protected: Boolean m_fixedSize; Boolean m_pressed; Boolean m_phantom; + Boolean m_dragable; + Boolean m_dragging; Boolean m_destroyed; UILayoutPtr m_layout; UIWidgetWeakPtr m_parent; @@ -112,6 +114,8 @@ public: void setChecked(bool checked); void setFocusable(bool focusable); void setPhantom(bool phantom); + void setDragging(bool dragging); + void setDragable(bool dragable); void setFixedSize(bool fixed); void setLastFocusReason(Fw::FocusReason reason); @@ -161,6 +165,9 @@ protected: virtual void onGeometryChange(const Rect& oldRect, const Rect& newRect); virtual void onFocusChange(bool focused, Fw::FocusReason reason); 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 onKeyDown(uchar keyCode, int keyboardModifiers); virtual bool onKeyPress(uchar keyCode, int keyboardModifiers, bool wouldFilter); @@ -206,6 +213,8 @@ public: bool isExplicitlyVisible() { return m_visible; } bool isFocusable() { return m_focusable; } bool isPhantom() { return m_phantom; } + bool isDragable() { return m_dragable; } + bool isDragging() { return m_dragging; } bool isFixedSize() { return m_fixedSize; } bool isDestroyed() { return m_destroyed; } diff --git a/src/framework/ui/uiwidgetbasestyle.cpp b/src/framework/ui/uiwidgetbasestyle.cpp index aea0ea73..11bf5aba 100644 --- a/src/framework/ui/uiwidgetbasestyle.cpp +++ b/src/framework/ui/uiwidgetbasestyle.cpp @@ -108,6 +108,8 @@ void UIWidget::parseBaseStyle(const OTMLNodePtr& styleNode) setVisible(node->value()); else if(node->tag() == "checked") setChecked(node->value()); + else if(node->tag() == "dragable") + setChecked(node->value()); else if(node->tag() == "on") setOn(node->value()); else if(node->tag() == "focusable") diff --git a/src/otclient/ui/uiitem.cpp b/src/otclient/ui/uiitem.cpp index b0c9693e..2eff3049 100644 --- a/src/otclient/ui/uiitem.cpp +++ b/src/otclient/ui/uiitem.cpp @@ -25,6 +25,11 @@ #include #include +UIItem::UIItem() +{ + m_dragable = true; +} + void UIItem::draw() { drawSelf(); diff --git a/src/otclient/ui/uiitem.h b/src/otclient/ui/uiitem.h index 32a1f867..c16cc0fd 100644 --- a/src/otclient/ui/uiitem.h +++ b/src/otclient/ui/uiitem.h @@ -30,6 +30,7 @@ class UIItem : public UIWidget { public: + UIItem(); void draw(); void setItem(const ItemPtr& item) { m_item = item; }