void TSplitter::DoMouseUp(const TPoint& mouse, TMouseButton button, TModifierState state) { if (fTracking && button == kLeftButton) { TPoint point; ConstrainMouse(mouse, point); if (!fLiveDrag) { TRect rect; GetTrackingRect(fLastMouse, rect); DrawTrackingRect(rect); TRect bounds; GetLocalBounds(bounds); if (fVertical) fRatio = (float)point.h / (float)bounds.GetWidth(); else fRatio = (float)point.v / (float)bounds.GetHeight(); if (fRatio < 0.0) fRatio = 0.0; else if (fRatio > 1.0) fRatio = 1.0; ResizeChildren(); } fTracking = false; } }
void TScrollBar::GetThumb(TRect& r) const { if (fMinimum < fMaximum) { GetThumbArea(r); if (IsVertical()) { TCoord available = r.GetHeight(); if (available > kMinThumbSize) { TCoord thumbSize; if (fProportionalThumbs) thumbSize = ((long long)fBounds.GetHeight() * (long long)available) / (long long)(fMaximum - fMinimum + fBounds.GetHeight()); else thumbSize = fBounds.GetWidth(); if (thumbSize < kMinThumbSize) thumbSize = kMinThumbSize; else if (thumbSize > available) thumbSize = available; available -= thumbSize; r.top += (int)(((long long)(fValue - fMinimum) * (long long)available) / (long long)(fMaximum - fMinimum)); r.bottom = r.top + thumbSize; } } else { TCoord available = r.GetWidth(); if (available > kMinThumbSize) { TCoord thumbSize; if (fProportionalThumbs) thumbSize = ((long long)fBounds.GetWidth() * (long long)available) / (long long)(fMaximum - fMinimum + fBounds.GetWidth()); else thumbSize = fBounds.GetHeight(); if (thumbSize < kMinThumbSize) thumbSize = kMinThumbSize; else if (thumbSize > available) thumbSize = available; available -= thumbSize; r.left += (int)(((long long)(fValue - fMinimum) * (long long)available) / (long long)(fMaximum - fMinimum)); r.right = r.left + thumbSize; } } } else r.SetEmpty(); }
void TWindow::SetBounds(const TRect& bounds) { if (fWindow) XMoveResizeWindow(sDisplay, fWindow, bounds.left, bounds.top, bounds.GetWidth(), bounds.GetHeight()); // do the notification for child windows or unmapped windows. if ((!fWindow || fParent) && bounds != fBounds) { TRect oldBounds(fBounds); fBounds = bounds; NotifyBoundsChanged(oldBounds); } }
void TSplitter::GetSplitterRect(float ratio, TRect& rect) const { ASSERT(ratio >= 0.0 && ratio <= 1.0); GetLocalBounds(rect); if (fVertical) { rect.left = (TCoord)((rect.GetWidth() - kSplitterWidth) * fRatio); rect.right = rect.left + kSplitterWidth; } else { rect.top = (TCoord)((rect.GetHeight() - kSplitterWidth) * fRatio); rect.bottom = rect.top + kSplitterWidth; } }
void TSplitter::DoMouseMoved(const TPoint& mouse, TModifierState state) { if (fTracking) { TPoint point; ConstrainMouse(mouse, point); if ((fVertical && fLastMouse.h != point.h) || (!fVertical && fLastMouse.v != point.v)) { if (fLiveDrag) { TRect bounds; GetLocalBounds(bounds); if (fVertical) fRatio = (float)point.h / (float)bounds.GetWidth(); else fRatio = (float)point.v / (float)bounds.GetHeight(); if (fRatio < 0.0) fRatio = 0.0; else if (fRatio > 1.0) fRatio = 1.0; ResizeChildren(); TDrawContext context(this); DrawSplitterRect(context); } else { TRect rect; GetTrackingRect(fLastMouse, rect); DrawTrackingRect(rect); GetTrackingRect(point, rect); DrawTrackingRect(rect); } } fLastMouse = point; } }