WidgetRect CentreUponChangeLayout::getBoundingRect() const { unsigned long now = Misc::Sleeper::getTimeMilliseconds(); if(lastChangedLayout != this) { return normalLayout->getBoundingRect(); } if(now <= lastChanged + centreTime) { return centreRect; } else if(now <= lastChanged + centreTime + transitionTime) { double percent = (now - (lastChanged + centreTime)) / static_cast<double>(transitionTime); // use a quadratic spline function to smooth the interpolation double u = percent * 2; double p = 0.0; if(u < 1.0) { p = u*u / 2.0; } else { p = 1.0 - (2.0 - u)*(2.0 - u) / 2.0; } //LOG(WIDGET, "transition is " << percent << " complete"); WidgetRect normal = normalLayout->getBoundingRect(); WidgetPoint position = normal.getCorner() * p + centreRect.getCorner() * (1.0 - p); WidgetPoint dimensions = normal.getDimensions() * p + centreRect.getDimensions() * (1.0 - p); return WidgetRect(position, dimensions); } else { lastChangedLayout = NULL; return normalLayout->getBoundingRect(); } }
bool MFrame::OnEvent(MEvent* pEvent, MListener* pListener) { if (IsFocusEnable() == false) return false; MRECT TitleBarRect(0, 0, m_Rect.w, MTITLEBAR_HEIGHT); MRECT WidgetRect(0, 0, m_Rect.w, m_Rect.h); MPOINT sp = MClientToScreen(this, pEvent->Pos); switch(pEvent->nMessage){ case MWM_LBUTTONDOWN: if(m_bTitleBar==true && TitleBarRect.InPoint(pEvent->Pos)==true) { if ( m_BtnClose.m_Rect.InPoint(pEvent->Pos)==true) { m_BtnClose.m_bLButtonDown = true; } else if (m_BtnMinimize.m_Rect.InPoint(pEvent->Pos)==true) { m_BtnMinimize.m_bLButtonDown = true; } else { SetCapture(); m_bDragWidget = true; MPOINT wp = MClientToScreen(GetParent(), MPOINT(m_Rect.x, m_Rect.y)); sp.x -= wp.x; sp.y -= wp.y; m_DragPoint = sp; } return true; } else if(WidgetRect.InPoint(pEvent->Pos)==true){ return true; } break; case MWM_LBUTTONUP: if (m_bTitleBar==true && m_BtnClose.m_Rect.InPoint(pEvent->Pos)==true) { if (m_BtnClose.m_bLButtonDown==true) OnCloseButtonClick(); } else if (m_bTitleBar==true && m_BtnMinimize.m_Rect.InPoint(pEvent->Pos)==true) { if (m_BtnMinimize.m_bLButtonDown==true) OnMinimizeButtonClick(); } m_BtnClose.m_bLButtonDown = m_BtnMinimize.m_bLButtonDown = false; if(m_bDragWidget==true){ ReleaseCapture(); m_bDragWidget = false; return true; } break; case MWM_MOUSEMOVE: if(m_bDragWidget==true){ sp.x -= m_DragPoint.x; sp.y -= m_DragPoint.y; if(sp.x<0) sp.x = 0; if(sp.y<0) sp.y = 0; if(sp.x+m_Rect.w>MGetWorkspaceWidth()-1) sp.x = MGetWorkspaceWidth()-m_Rect.w-1; if(sp.y+m_Rect.h>MGetWorkspaceHeight()-1) sp.y = MGetWorkspaceHeight()-m_Rect.h-1; MPOINT p = MScreenToClient(GetParent(), sp); if (m_bMovable == true) { SetPosition(p.x, p.y); } return true; } else if(m_bTitleBar==true) { if(m_BtnClose.m_Rect.InPoint(pEvent->Pos)==true) { if(m_BtnClose.m_bMouseOver==false) m_BtnClose.m_bMouseOver = true; } else { if(m_BtnClose.m_bMouseOver==true) m_BtnClose.m_bMouseOver = false; } if(m_BtnMinimize.m_Rect.InPoint(pEvent->Pos)==true) { if(m_BtnMinimize.m_bMouseOver==false) m_BtnMinimize.m_bMouseOver = true; } else { if(m_BtnMinimize.m_bMouseOver==true) m_BtnMinimize.m_bMouseOver = false; } } break; case MWM_LBUTTONDBLCLK: break; } return false; }