Exemplo n.º 1
0
void ScrollBox::__Update(const Point2i & mousePosition,
                         const Point2i & /*lastMousePosition*/)
{
  // update position of items because of dragging
  if (HasScrollBar() && scroll_mode!=SCROLL_MODE_NONE) {
    int max_offset = GetMaxOffset();
    int new_offset = offset;

    if (scroll_mode == SCROLL_MODE_THUMB) {
      Point2i track_pos  = GetScrollTrackPos();
      int     height     = GetTrackHeight();

      new_offset = start_drag_offset +
                   ((mousePosition.y - start_drag_y) * (size.y+max_offset))/height;
    } else if (scroll_mode == SCROLL_MODE_DRAG) {
      // Act as if the scroll corresponds to bringing the starting point to the
      // current point
      new_offset = start_drag_offset + start_drag_y - mousePosition.y;
    }

    if (new_offset < 0)
      new_offset = 0;
    if (new_offset > max_offset)
      new_offset = max_offset;

    if (new_offset != offset) {
      offset = new_offset;
      Pack();
    }
  }
}
Exemplo n.º 2
0
//
/// Responds to the specified horizontal scrollEvent by calling ScrollBy or ScrollTo.
/// The type of scroll event is identified by the corresponding SB_ constants.
/// The 16-bit thumbPos argument is ignored. The function retrieves the 32-bit value
/// directly from the scroll bar instead.
//
void
TScroller::HScroll(uint scrollEvent, int)
{
    switch (scrollEvent) {
    case SB_LINEDOWN:
        ScrollBy(XLine, 0);
        break;

    case SB_LINEUP:
        ScrollBy(-XLine, 0);
        break;

    case SB_PAGEDOWN:
        ScrollBy(XPage, 0);
        break;

    case SB_PAGEUP:
        ScrollBy(-XPage, 0);
        break;

    case SB_TOP:
        ScrollTo(0, YPos);
        break;

    case SB_BOTTOM:
        ScrollTo(XRange, YPos);
        break;

    case SB_THUMBPOSITION:
        ScrollTo(GetScrollTrackPos(SB_HORZ), YPos);
        break;

    case SB_THUMBTRACK:
    {
        int thumbPos32 = GetScrollTrackPos(SB_HORZ);
        if (TrackMode)
            ScrollTo(thumbPos32, YPos);
        if (Window && HasHScrollBar)
            SetScrollPos(SB_HORZ, thumbPos32, true);
        break;
    }
    }
}
Exemplo n.º 3
0
//
/// Responds to the specified vertical scrollEvent by calling ScrollBy or ScrollTo.
/// The type of scroll event is identified by the corresponding SB_ constants.
/// The 16-bit thumbPos argument is ignored. The function retrieves the 32-bit value
/// directly from the scroll bar instead.
//
void
TScroller::VScroll(uint scrollEvent, int)
{
    switch (scrollEvent) {
    case SB_LINEDOWN:
        ScrollBy(0, YLine);
        break;

    case SB_LINEUP:
        ScrollBy(0, -YLine);
        break;

    case SB_PAGEDOWN:
        ScrollBy(0, YPage);
        break;

    case SB_PAGEUP:
        ScrollBy(0, -YPage);
        break;

    case SB_TOP:
        ScrollTo(XPos, 0);
        break;

    case SB_BOTTOM:
        ScrollTo(XPos, YRange);
        break;

    case SB_THUMBPOSITION:
        ScrollTo(XPos, GetScrollTrackPos(SB_VERT));
        break;

    case SB_THUMBTRACK:
    {
        int thumbPos32 = GetScrollTrackPos(SB_VERT);
        if (TrackMode)
            ScrollTo(XPos, thumbPos32);
        if (Window && HasVScrollBar)
            SetScrollPos(SB_VERT, thumbPos32, true);
        break;
    }
    }
}