improve miniwindow moving

This commit is contained in:
Eduardo Bart 2012-06-11 11:10:03 -03:00
parent bae578a35a
commit 8cef6463b3
4 changed files with 37 additions and 16 deletions

View File

@ -29,7 +29,7 @@ end
function UIMiniWindow:onDragMove(mousePos, mouseMoved) function UIMiniWindow:onDragMove(mousePos, mouseMoved)
local oldMousePosY = mousePos.y - mouseMoved.y local oldMousePosY = mousePos.y - mouseMoved.y
local children = rootWidget:recursiveGetChildrenByPos(mousePos) local children = rootWidget:recursiveGetChildrenByMarginPos(mousePos)
local overAnyWidget = false local overAnyWidget = false
for i=1,#children do for i=1,#children do
local child = children[i] local child = children[i]
@ -42,27 +42,26 @@ function UIMiniWindow:onDragMove(mousePos, mouseMoved)
end end
if self.movedWidget then if self.movedWidget then
self.widgetSetMargin(self.movedWidget, self.widgetGetMargin(self.movedWidget) - 10) self.setMovedChildMargin(0)
self.setMovedChildMargin = nil
end end
if mousePos.y < childCenterY then if mousePos.y < childCenterY then
self.widgetSetMargin = child.setMarginTop self.setMovedChildMargin = function(v) child:setMarginTop(v) end
self.widgetGetMargin = child.getMarginTop
self.movedIndex = 0 self.movedIndex = 0
else else
self.widgetSetMargin = child.setMarginBottom self.setMovedChildMargin = function(v) child:setMarginBottom(v) end
self.widgetGetMargin = child.getMarginBottom
self.movedIndex = 1 self.movedIndex = 1
end end
self.widgetSetMargin(child, self.widgetGetMargin(child) + 10)
self.movedWidget = child self.movedWidget = child
self.setMovedChildMargin(self:getHeight())
break break
end end
end end
if not overAnyWidget and self.movedWidget then if not overAnyWidget and self.movedWidget then
self.widgetSetMargin(self.movedWidget, self.widgetGetMargin(self.movedWidget) - 10) self.setMovedChildMargin(0)
self.movedWidget = nil self.movedWidget = nil
end end
@ -80,10 +79,9 @@ end
function UIMiniWindow:onDragLeave(droppedWidget, mousePos) function UIMiniWindow:onDragLeave(droppedWidget, mousePos)
if self.movedWidget then if self.movedWidget then
self.widgetSetMargin(self.movedWidget, self.widgetGetMargin(self.movedWidget) - 10) self.setMovedChildMargin(0)
self.movedWidget = nil self.movedWidget = nil
self.widgetSetMargin = nil self.setMovedChildMargin = nil
self.widgetGetMargin = nil
self.movedIndex = nil self.movedIndex = nil
end end
end end

View File

@ -143,6 +143,7 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<UIWidget>("recursiveGetChildById", &UIWidget::recursiveGetChildById); g_lua.bindClassMemberFunction<UIWidget>("recursiveGetChildById", &UIWidget::recursiveGetChildById);
g_lua.bindClassMemberFunction<UIWidget>("recursiveGetChildByPos", &UIWidget::recursiveGetChildByPos); g_lua.bindClassMemberFunction<UIWidget>("recursiveGetChildByPos", &UIWidget::recursiveGetChildByPos);
g_lua.bindClassMemberFunction<UIWidget>("recursiveGetChildrenByPos", &UIWidget::recursiveGetChildrenByPos); g_lua.bindClassMemberFunction<UIWidget>("recursiveGetChildrenByPos", &UIWidget::recursiveGetChildrenByPos);
g_lua.bindClassMemberFunction<UIWidget>("recursiveGetChildrenByMarginPos", &UIWidget::recursiveGetChildrenByMarginPos);
g_lua.bindClassMemberFunction<UIWidget>("backwardsGetWidgetById", &UIWidget::backwardsGetWidgetById); g_lua.bindClassMemberFunction<UIWidget>("backwardsGetWidgetById", &UIWidget::backwardsGetWidgetById);
g_lua.bindClassMemberFunction<UIWidget>("asUIWidget", &UIWidget::asUIWidget); g_lua.bindClassMemberFunction<UIWidget>("asUIWidget", &UIWidget::asUIWidget);
g_lua.bindClassMemberFunction<UIWidget>("resize", &UIWidget::resize); g_lua.bindClassMemberFunction<UIWidget>("resize", &UIWidget::resize);
@ -174,6 +175,8 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<UIWidget>("isClipping", &UIWidget::isClipping); g_lua.bindClassMemberFunction<UIWidget>("isClipping", &UIWidget::isClipping);
g_lua.bindClassMemberFunction<UIWidget>("isDestroyed", &UIWidget::isDestroyed); g_lua.bindClassMemberFunction<UIWidget>("isDestroyed", &UIWidget::isDestroyed);
g_lua.bindClassMemberFunction<UIWidget>("hasChildren", &UIWidget::hasChildren); g_lua.bindClassMemberFunction<UIWidget>("hasChildren", &UIWidget::hasChildren);
g_lua.bindClassMemberFunction<UIWidget>("containsMarginPoint", &UIWidget::containsMarginPoint);
g_lua.bindClassMemberFunction<UIWidget>("containsPaddingPoint", &UIWidget::containsPaddingPoint);
g_lua.bindClassMemberFunction<UIWidget>("containsPoint", &UIWidget::containsPoint); g_lua.bindClassMemberFunction<UIWidget>("containsPoint", &UIWidget::containsPoint);
g_lua.bindClassMemberFunction<UIWidget>("getId", &UIWidget::getId); g_lua.bindClassMemberFunction<UIWidget>("getId", &UIWidget::getId);
g_lua.bindClassMemberFunction<UIWidget>("getParent", &UIWidget::getParent); g_lua.bindClassMemberFunction<UIWidget>("getParent", &UIWidget::getParent);

View File

@ -1065,7 +1065,7 @@ UIWidgetPtr UIWidget::getChildById(const std::string& childId)
UIWidgetPtr UIWidget::getChildByPos(const Point& childPos) UIWidgetPtr UIWidget::getChildByPos(const Point& childPos)
{ {
if(!containsChildPoint(childPos)) if(!containsPaddingPoint(childPos))
return nullptr; return nullptr;
for(auto it = m_children.rbegin(); it != m_children.rend(); ++it) { for(auto it = m_children.rbegin(); it != m_children.rend(); ++it) {
@ -1100,7 +1100,7 @@ UIWidgetPtr UIWidget::recursiveGetChildById(const std::string& id)
UIWidgetPtr UIWidget::recursiveGetChildByPos(const Point& childPos, bool wantsPhantom) UIWidgetPtr UIWidget::recursiveGetChildByPos(const Point& childPos, bool wantsPhantom)
{ {
if(!containsChildPoint(childPos)) if(!containsPaddingPoint(childPos))
return nullptr; return nullptr;
for(auto it = m_children.rbegin(); it != m_children.rend(); ++it) { for(auto it = m_children.rbegin(); it != m_children.rend(); ++it) {
@ -1119,7 +1119,7 @@ UIWidgetPtr UIWidget::recursiveGetChildByPos(const Point& childPos, bool wantsPh
UIWidgetList UIWidget::recursiveGetChildrenByPos(const Point& childPos) UIWidgetList UIWidget::recursiveGetChildrenByPos(const Point& childPos)
{ {
UIWidgetList children; UIWidgetList children;
if(!containsChildPoint(childPos)) if(!containsPaddingPoint(childPos))
return children; return children;
for(auto it = m_children.rbegin(); it != m_children.rend(); ++it) { for(auto it = m_children.rbegin(); it != m_children.rend(); ++it) {
@ -1134,6 +1134,24 @@ UIWidgetList UIWidget::recursiveGetChildrenByPos(const Point& childPos)
return children; return children;
} }
UIWidgetList UIWidget::recursiveGetChildrenByMarginPos(const Point& childPos)
{
UIWidgetList children;
if(!containsPaddingPoint(childPos))
return children;
for(auto it = m_children.rbegin(); it != m_children.rend(); ++it) {
const UIWidgetPtr& child = (*it);
if(child->isExplicitlyVisible() && child->containsMarginPoint(childPos)) {
UIWidgetList subChildren = child->recursiveGetChildrenByMarginPos(childPos);
if(!subChildren.empty())
children.insert(children.end(), subChildren.begin(), subChildren.end());
children.push_back(child);
}
}
return children;
}
UIWidgetPtr UIWidget::backwardsGetWidgetById(const std::string& id) UIWidgetPtr UIWidget::backwardsGetWidgetById(const std::string& id)
{ {
UIWidgetPtr widget = getChildById(id); UIWidgetPtr widget = getChildById(id);
@ -1580,7 +1598,7 @@ bool UIWidget::propagateOnKeyUp(uchar keyCode, int keyboardModifiers)
bool UIWidget::propagateOnMouseEvent(const Point& mousePos, UIWidgetList& widgetList) bool UIWidget::propagateOnMouseEvent(const Point& mousePos, UIWidgetList& widgetList)
{ {
bool ret = false; bool ret = false;
if(containsChildPoint(mousePos)) { if(containsPaddingPoint(mousePos)) {
for(auto it = m_children.rbegin(); it != m_children.rend(); ++it) { for(auto it = m_children.rbegin(); it != m_children.rend(); ++it) {
const UIWidgetPtr& child = *it; const UIWidgetPtr& child = *it;
if(child->isExplicitlyEnabled() && child->isExplicitlyVisible() && child->containsPoint(mousePos)) { if(child->isExplicitlyEnabled() && child->isExplicitlyVisible() && child->containsPoint(mousePos)) {

View File

@ -150,6 +150,7 @@ public:
UIWidgetPtr recursiveGetChildById(const std::string& id); UIWidgetPtr recursiveGetChildById(const std::string& id);
UIWidgetPtr recursiveGetChildByPos(const Point& childPos, bool wantsPhantom); UIWidgetPtr recursiveGetChildByPos(const Point& childPos, bool wantsPhantom);
UIWidgetList recursiveGetChildrenByPos(const Point& childPos); UIWidgetList recursiveGetChildrenByPos(const Point& childPos);
UIWidgetList recursiveGetChildrenByMarginPos(const Point& childPos);
UIWidgetPtr backwardsGetWidgetById(const std::string& id); UIWidgetPtr backwardsGetWidgetById(const std::string& id);
UIWidgetPtr asUIWidget() { return std::static_pointer_cast<UIWidget>(shared_from_this()); } UIWidgetPtr asUIWidget() { return std::static_pointer_cast<UIWidget>(shared_from_this()); }
@ -243,7 +244,8 @@ public:
bool isDestroyed() { return m_destroyed; } bool isDestroyed() { return m_destroyed; }
bool hasChildren() { return m_children.size() > 0; } bool hasChildren() { return m_children.size() > 0; }
bool containsChildPoint(const Point& point) { return getPaddingRect().contains(point); } bool containsMarginPoint(const Point& point) { return getMarginRect().contains(point); }
bool containsPaddingPoint(const Point& point) { return getPaddingRect().contains(point); }
bool containsPoint(const Point& point) { return m_rect.contains(point); } bool containsPoint(const Point& point) { return m_rect.contains(point); }
std::string getId() { return m_id; } std::string getId() { return m_id; }