bool nuiScrollView::Draw(nuiDrawContext* pContext) { nuiSize scrollv = (mpVertical->IsVisible() && !mForceNoVertical && !mVerticalIsExternal)?mBarSize:0; nuiSize scrollh = (mpHorizontal->IsVisible() && !mForceNoHorizontal && !mHorizontalIsExternal)?mBarSize:0; nuiRect rect(0.0f,0.0f,mRect.GetWidth()-scrollv, mRect.GetHeight()-scrollh); IteratorPtr pIt; for (pIt = GetFirstChild(); pIt && pIt->IsValid(); GetNextChild(pIt)) { nuiWidgetPtr pItem = pIt->GetWidget(); nuiRect intersect; if (intersect.Intersect(rect, pItem->GetOverDrawRect(true, true))) { DrawChild(pContext, pItem); } } delete pIt; if (GetDebug()) { pContext->SetStrokeColor(nuiColor("red")); pContext->DrawRect(GetRect().Size(), eStrokeShape); pContext->SetStrokeColor(nuiColor("blue")); pContext->DrawRect(GetIdealRect().Size(), eStrokeShape); pContext->SetStrokeColor("yellow"); float h = GetRect().GetHeight() - scrollh - 1; pContext->DrawLine(0, h, GetRect().GetWidth(), h); } return true; }
bool nuiZoomView::SetRect(const nuiRect& rRect) { nuiWidget::SetRect(rRect); nuiSize XOffset = 0; nuiSize YOffset = 0; if (mpHorizontalScrollbar) XOffset = (nuiSize)ToNearest(mpHorizontalScrollbar->GetRange().GetValue()); if (mpVerticalScrollbar) YOffset = (nuiSize)ToNearest(mpVerticalScrollbar->GetRange().GetValue()); nuiSize HorizontalZoomLevel = mHorizontalZoomLevel; nuiSize VerticalZoomLevel = mVerticalZoomLevel; if (mpVerticalSlider) VerticalZoomLevel = mpVerticalSlider->GetRange().GetValue(); if (mpHorizontalSlider) HorizontalZoomLevel = mpHorizontalSlider->GetRange().GetValue(); nuiSize x; nuiSize y; nuiSize xx = rRect.GetWidth(); nuiSize yy = rRect.GetHeight(); if (mCalcWidthFromIdealSize) x = GetIdealRect().GetWidth(); else x = xx * HorizontalZoomLevel; if (mCalcHeightFromIdealSize) y = GetIdealRect().GetHeight(); else y = yy * VerticalZoomLevel; bool needv = y > yy; bool needh = x > xx; if (mpHorizontalScrollbar) { nuiRange& hrange = mpHorizontalScrollbar->GetRange(); hrange.SetRange(0,x); hrange.SetPageSize(MAX(0, xx)); hrange.SetIncrement(16.0f); hrange.SetPageIncrement(MAX(0, xx - xx / 8.f)); // 1/8th of page skip overlaps with the next and previous hrange.EnableEvents(false); hrange.SetValue(XOffset); hrange.EnableEvents(true); XOffset = hrange.GetValue(); } if (mpVerticalScrollbar) { nuiRange& vrange = mpVerticalScrollbar->GetRange(); vrange.SetRange(0,y); vrange.SetPageSize(MAX(0, yy)); vrange.SetIncrement(16.0f); vrange.SetPageIncrement(MAX(0, yy - yy / 8.f)); // 1/8th of page skip overlaps with the next and previous vrange.EnableEvents(false); vrange.SetValue(YOffset); vrange.EnableEvents(true); YOffset = vrange.GetValue(); } if (x < xx) x = xx; if (y < yy) y = yy; IteratorPtr pIt; for (pIt = GetFirstChild(); pIt && pIt->IsValid(); GetNextChild(pIt)) { nuiWidgetPtr pItem = pIt->GetWidget(); nuiRect rect(-XOffset, -YOffset, x, y); pItem->SetLayout(rect); } delete pIt; needv = needv | mAlwaysDisplayVScrollbar; needh = needh | mAlwaysDisplayHScrollbar; if (mpVerticalScrollbar) mpVerticalScrollbar->SetVisible(needv); if (mpHorizontalScrollbar) mpHorizontalScrollbar->SetVisible(needh); return true; }
bool nuiScrollView::SetRect(const nuiRect& rRect) { #ifdef _DEBUG_LAYOUT if (GetDebug()) { NGL_OUT(_T("nuiScrollView::SetRect: %s\n"), rRect.GetValue().GetChars()); } #endif nuiWidget::SetRect(rRect); if (!mpHorizontal || !mpVertical) return false; nuiSize XOffset = mpHorizontal->GetRange().GetValue(); nuiSize YOffset = mpVertical->GetRange().GetValue(); if (mSmoothScrolling) { if (!mHThumbPressed) XOffset = mXOffset; if (!mVThumbPressed) YOffset = mYOffset; } mXOffset = XOffset; mYOffset = YOffset; XOffset = (nuiSize)ToNearest(XOffset); YOffset = (nuiSize)ToNearest(YOffset); GetIdealRect(); nuiRect rIdealRect(mChildrenUnionRect); ///< needed because GetIdealRect may return a UserRect if (mMinimalResize) { rIdealRect.Right() = MAX(rIdealRect.Right(), mOldIdealRect.Right()); rIdealRect.Bottom() = MAX(rIdealRect.Bottom(), mOldIdealRect.Bottom()); mOldIdealRect = rIdealRect; } nuiSize x = rIdealRect.GetWidth(); nuiSize y = rIdealRect.GetHeight(); nuiRange& hrange = mpHorizontal->GetRange(); nuiRange& vrange = mpVertical->GetRange(); if (mMinimalResize) { if( (hrange.GetValue() + hrange.GetPageSize()) < hrange.GetMaximum() ) { x = mChildrenUnionRect.GetWidth(); mOldIdealRect = mChildrenUnionRect; } if( (vrange.GetValue() + vrange.GetPageSize()) < vrange.GetMaximum() ) { y = mChildrenUnionRect.GetHeight(); mOldIdealRect = mChildrenUnionRect; } } nuiSize xx = rRect.GetWidth(); nuiSize yy = rRect.GetHeight(); bool needv = y > yy; bool needh = x > xx; needh = needh && !mForceNoHorizontal; needv = needv && !mForceNoVertical; nuiSize scrollh = (needh && !mHorizontalIsExternal) ? mBarSize:0; nuiSize scrollv = (needv && !mVerticalIsExternal) ? mBarSize:0; for (int i = 0; i<2; i++) { if (needv && !mForceNoHorizontal) { needh = x > (xx - scrollv); if (!mVerticalIsExternal) scrollv = needv?mBarSize:0; } if (needh && !mForceNoVertical) { needv = y > (yy - scrollh); if (!mHorizontalIsExternal) scrollh = needh?mBarSize:0; } } if (needh) { double pagesize = xx - scrollv; if (mHideScrollBars) pagesize = xx; hrange.SetRange(0, x); hrange.SetPageSize(MAX(0, pagesize)); hrange.SetPageIncrement(MAX(0, pagesize)); hrange.SetIncrement(mHIncrement); hrange.EnableEvents(false); nuiSize oldv = hrange.GetValue(); hrange.SetValue(hrange.GetValue()); if (hrange.GetValue() != oldv) { mXOffset = hrange.GetValue(); } hrange.EnableEvents(true); } else { double pagesize = x; hrange.SetRange(0, x); hrange.SetPageSize(MAX(0, pagesize)); hrange.SetPageIncrement(MAX(0, pagesize)); hrange.SetIncrement(mHIncrement); mXOffset = XOffset= 0.f; hrange.EnableEvents(false); hrange.SetValue(XOffset); hrange.EnableEvents(true); } if (needv) { double pagesize = yy - scrollh; if (mHideScrollBars) pagesize = yy; vrange.SetRange(0, y); vrange.SetPageSize(MAX(0, pagesize)); vrange.SetPageIncrement(MAX(0, pagesize)); vrange.SetIncrement(mVIncrement); vrange.EnableEvents(false); nuiSize oldv = vrange.GetValue(); vrange.SetValue(vrange.GetValue()); if (vrange.GetValue() != oldv) { mYOffset = vrange.GetValue(); } vrange.EnableEvents(true); } else { double pagesize = y; vrange.SetRange(0, y); vrange.SetPageSize(MAX(0, pagesize)); vrange.SetPageIncrement(MAX(0, pagesize)); vrange.SetIncrement(mVIncrement); mYOffset = YOffset = 0.f; vrange.EnableEvents(false); vrange.SetValue(YOffset); vrange.EnableEvents(true); } OffsetsChanged(); nuiSize scrollbarH = scrollh; nuiSize scrollbarV = scrollv; if (mHideScrollBars) { scrollbarH = 0; scrollbarV = 0; } SetChildrenRect(x, y, xx, yy, scrollbarV, scrollbarH); if (!mHorizontalIsExternal) { mpHorizontal->SetVisible(needh); mpHorizontal->SetLayout(nuiRect(0.0f, yy-scrollh, xx - scrollv, scrollh)); } if (!mVerticalIsExternal) { mpVertical->SetVisible(needv); mpVertical->SetLayout(nuiRect(xx - scrollv, 0.0f, scrollv, yy-scrollh)); } return true; }
bool nuiWindow::MouseMoved(nuiSize X, nuiSize Y) { nuiSize dx, dy; LocalToLocal(GetParent(), X, Y); dx = X - mClickX; dy = Y - mClickY; if (mMoving == ePreMove) { if (abs((int)dx) > WINDOW_MINIMOVE || abs((int)dy) > WINDOW_MINIMOVE) { mMoving = eMove; SetAlpha(0.5f); } else return true; } mClickX = X; mClickY = Y; if (mMoving == eMove) { nuiRect wRect = GetIdealRect(); wRect.RoundToNearest(); nuiRect woriginal = wRect; switch (mClickPos) { case nuiCenter: { wRect.Move(dx, dy); } break; case nuiTopLeft: { wRect.mTop += dy; wRect.mLeft += dx; if (wRect.GetHeight() < mMinimumHeight) wRect.mTop += wRect.GetHeight() - mMinimumHeight; if (wRect.GetWidth() < mMinimumWidth) wRect.mLeft += wRect.GetWidth() - mMinimumWidth; } break; case nuiBottomLeft: { wRect.mBottom += dy; wRect.mLeft += dx; if (wRect.GetHeight() < mMinimumHeight) wRect.SetSize(wRect.GetWidth(), mMinimumHeight); if (wRect.GetWidth() < mMinimumWidth) wRect.mLeft += wRect.GetWidth() - mMinimumWidth; } break; case nuiLeft: { wRect.mLeft += dx; if (wRect.GetWidth() < mMinimumWidth) wRect.mLeft += wRect.GetWidth() - mMinimumWidth; } break; case nuiTopRight: { wRect.mTop += dy; wRect.mRight += dx; if (wRect.GetHeight() < mMinimumHeight) wRect.mTop += wRect.GetHeight() - mMinimumHeight; if (wRect.GetWidth() < mMinimumWidth) wRect.SetSize(mMinimumWidth, wRect.GetHeight()); } break; case nuiBottomRight: { wRect.mBottom += dy; wRect.mRight += dx; if (wRect.GetWidth() < mMinimumWidth) wRect.SetSize(mMinimumWidth, wRect.GetHeight()); if (wRect.GetHeight() < mMinimumHeight) wRect.SetSize(wRect.GetWidth(), mMinimumHeight); } break; case nuiRight: { wRect.mRight += dx; if (wRect.GetWidth() < mMinimumWidth) wRect.SetSize(mMinimumWidth, wRect.GetHeight()); } break; case nuiTop: { wRect.mTop += dy; if (wRect.GetHeight() < mMinimumHeight) wRect.mTop += wRect.GetHeight() - mMinimumHeight; } break; case nuiBottom: { wRect.mBottom += dy; if (wRect.GetHeight() < mMinimumHeight) wRect.SetSize(wRect.GetWidth(), mMinimumHeight); } break; default: return true; break; } wRect.RoundToNearest(); if (mpManager) mpManager->ValidateWindowRect(wRect); if (GetRect().GetWidth() == wRect.GetWidth() && GetRect().GetHeight() == wRect.GetHeight()) SetUserPos(wRect.mLeft, wRect.mTop); else SetUserRect(wRect); return true; } else { if (IsInsideFromParent(X,Y)) { nuiRect _Rect = GetRect(); _Rect.Transform(GetMatrix()); nuiTheme* pTheme = GetTheme(); NGL_ASSERT(pTheme); mClickPos= pTheme->GetWindowPart(_Rect, X, Y, GetFlags(), false); pTheme->Release(); SetMouseCursor(eCursorDoNotSet); switch (mClickPos) { case nuiCenter: if (!mNoMove) SetMouseCursor(eCursorHand); break; case nuiTopLeft: if (!mNoResize) SetMouseCursor(eCursorResizeNW); break; case nuiBottomLeft: if (!mNoResize) SetMouseCursor(eCursorResizeSW); break; case nuiLeft: if (!mNoResize) SetMouseCursor(eCursorResizeW); break; case nuiTopRight: if (!mNoResize) SetMouseCursor(eCursorResizeNE); break; case nuiBottomRight: if (!mNoResize) SetMouseCursor(eCursorResizeSE); break; case nuiRight: if (!mNoResize) SetMouseCursor(eCursorResizeE); break; case nuiTop: if (!mNoResize) SetMouseCursor(eCursorResizeN); break; case nuiBottom: if (!mNoResize) SetMouseCursor(eCursorResizeS); break; default: break; } } } return true; // Always block mouse event that are not from this window }