dran and drop for UIWidget
This commit is contained in:
parent
733039e50e
commit
759b7f43b3
4
TODO
4
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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 };
|
||||
|
||||
|
|
|
@ -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<false> m_drawDebugBoxes;
|
||||
std::map<std::string, OTMLNodePtr> m_styles;
|
||||
|
|
|
@ -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<bool>("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<bool>("onMouseMove", mousePos, mouseMoved);
|
||||
}
|
||||
|
||||
|
|
|
@ -62,6 +62,8 @@ protected:
|
|||
Boolean<false> m_fixedSize;
|
||||
Boolean<false> m_pressed;
|
||||
Boolean<false> m_phantom;
|
||||
Boolean<false> m_dragable;
|
||||
Boolean<false> m_dragging;
|
||||
Boolean<false> 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; }
|
||||
|
||||
|
|
|
@ -108,6 +108,8 @@ void UIWidget::parseBaseStyle(const OTMLNodePtr& styleNode)
|
|||
setVisible(node->value<bool>());
|
||||
else if(node->tag() == "checked")
|
||||
setChecked(node->value<bool>());
|
||||
else if(node->tag() == "dragable")
|
||||
setChecked(node->value<bool>());
|
||||
else if(node->tag() == "on")
|
||||
setOn(node->value<bool>());
|
||||
else if(node->tag() == "focusable")
|
||||
|
|
|
@ -25,6 +25,11 @@
|
|||
#include <framework/graphics/graphics.h>
|
||||
#include <framework/graphics/fontmanager.h>
|
||||
|
||||
UIItem::UIItem()
|
||||
{
|
||||
m_dragable = true;
|
||||
}
|
||||
|
||||
void UIItem::draw()
|
||||
{
|
||||
drawSelf();
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
class UIItem : public UIWidget
|
||||
{
|
||||
public:
|
||||
UIItem();
|
||||
void draw();
|
||||
|
||||
void setItem(const ItemPtr& item) { m_item = item; }
|
||||
|
|
Loading…
Reference in New Issue