Exemple #1
0
void Scroller::onMouseButton(Widget& widget,
                             vec2 point,
                             MouseButton button,
                             Action action,
                             uint mods)
{
  if (action != PRESSED)
    return;

  const vec2 local = transformToLocal(point);
  const float size = handleSize();
  const float offset = handleOffset();

  if (m_orientation == HORIZONTAL)
  {
    if (local.x < offset)
      setValue(m_value - valueStep(), true);
    else if (local.x >= offset + size)
      setValue(m_value + valueStep(), true);
  }
  else
  {
    if (local.y > height() - offset)
      setValue(m_value - valueStep(), true);
    else if (local.y <= height() - offset - size)
      setValue(m_value + valueStep(), true);
  }
}
Exemple #2
0
void Scroller::onDragBegun(vec2 point, MouseButton button)
{
  if (button == MOUSE_BUTTON_LEFT)
  {
    const vec2 local = transformToLocal(point);
    const float size = handleSize();
    const float offset = handleOffset();

    if (m_orientation == HORIZONTAL)
    {
      if (local.x >= offset && local.x < offset + size)
        m_reference = local.x - offset;
      else
        cancelDragging();
    }
    else
    {
      if (local.y <= height() - offset && local.y > height() - offset - size)
        m_reference = height() - local.y - offset;
      else
        cancelDragging();
    }

    Widget::onDragBegun(point, button);
  }
  else
    cancelDragging();
}
Exemple #3
0
void Scroller::onDragBegun(Widget& widget, vec2 point)
{
  const vec2 local = transformToLocal(point);
  const float size = handleSize();
  const float offset = handleOffset();

  if (m_orientation == HORIZONTAL)
  {
    if (local.x >= offset && local.x < offset + size)
      m_reference = local.x - offset;
    else
      cancelDragging();
  }
  else
  {
    if (local.y <= height() - offset && local.y > height() - offset - size)
      m_reference = height() - local.y - offset;
    else
      cancelDragging();
  }
}
Exemple #4
0
void Scroller::draw() const
{
  Drawer& drawer = layer().drawer();

  const Rect area = globalArea();
  if (drawer.pushClipArea(area))
  {
    drawer.drawWell(area, state());

    if (m_minValue != m_maxValue)
    {
      const float size = handleSize();
      const float offset = handleOffset();

      Rect handleArea;

      if (m_orientation == HORIZONTAL)
      {
        handleArea.set(area.position.x + offset,
                       area.position.y,
                       size,
                       area.size.y);
      }
      else
      {
        handleArea.set(area.position.x,
                       area.position.y + area.size.y - offset - size,
                       area.size.x,
                       size);
      }

      drawer.drawHandle(handleArea, state());
    }

    Widget::draw();

    drawer.popClipArea();
  }
}