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

View File

@ -143,6 +143,7 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<UIWidget>("recursiveGetChildById", &UIWidget::recursiveGetChildById);
g_lua.bindClassMemberFunction<UIWidget>("recursiveGetChildByPos", &UIWidget::recursiveGetChildByPos);
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>("asUIWidget", &UIWidget::asUIWidget);
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>("isDestroyed", &UIWidget::isDestroyed);
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>("getId", &UIWidget::getId);
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)
{
if(!containsChildPoint(childPos))
if(!containsPaddingPoint(childPos))
return nullptr;
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)
{
if(!containsChildPoint(childPos))
if(!containsPaddingPoint(childPos))
return nullptr;
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 children;
if(!containsChildPoint(childPos))
if(!containsPaddingPoint(childPos))
return children;
for(auto it = m_children.rbegin(); it != m_children.rend(); ++it) {
@ -1134,6 +1134,24 @@ UIWidgetList UIWidget::recursiveGetChildrenByPos(const Point& childPos)
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 widget = getChildById(id);
@ -1580,7 +1598,7 @@ bool UIWidget::propagateOnKeyUp(uchar keyCode, int keyboardModifiers)
bool UIWidget::propagateOnMouseEvent(const Point& mousePos, UIWidgetList& widgetList)
{
bool ret = false;
if(containsChildPoint(mousePos)) {
if(containsPaddingPoint(mousePos)) {
for(auto it = m_children.rbegin(); it != m_children.rend(); ++it) {
const UIWidgetPtr& child = *it;
if(child->isExplicitlyEnabled() && child->isExplicitlyVisible() && child->containsPoint(mousePos)) {

View File

@ -150,6 +150,7 @@ public:
UIWidgetPtr recursiveGetChildById(const std::string& id);
UIWidgetPtr recursiveGetChildByPos(const Point& childPos, bool wantsPhantom);
UIWidgetList recursiveGetChildrenByPos(const Point& childPos);
UIWidgetList recursiveGetChildrenByMarginPos(const Point& childPos);
UIWidgetPtr backwardsGetWidgetById(const std::string& id);
UIWidgetPtr asUIWidget() { return std::static_pointer_cast<UIWidget>(shared_from_this()); }
@ -243,7 +244,8 @@ public:
bool isDestroyed() { return m_destroyed; }
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); }
std::string getId() { return m_id; }