Exemplo n.º 1
0
void Menu::onDragEnded(vec2 point, MouseButton button)
{
  if (!area().contains(transformToLocal(point)))
    hide();

  Widget::onDragEnded(point, button);
}
Exemplo n.º 2
0
void Menu::onCursorPos(vec2 point)
{
  const vec2 local = transformToLocal(point);
  float itemTop = height() - 2.f;
  int index = 0;

  for (const Item* i : m_items)
  {
    const float itemHeight = i->height();
    if (itemTop - itemHeight < 0.f)
      break;

    if (itemTop - itemHeight <= local.y)
    {
      m_selection = index;
      invalidate();
      break;
    }

    itemTop -= itemHeight;
    index++;
  }

  Widget::onCursorPos(point);
}
Exemplo n.º 3
0
void Menu::onMouseButton(vec2 point,
                         MouseButton button,
                         Action action,
                         uint mods)
{
  if (action == RELEASED)
  {
    const vec2 local = transformToLocal(point);
    float itemTop = height() - 2.f;
    uint index = 0;

    for (const Item* i : m_items)
    {
      const float itemHeight = i->height();
      if (itemTop - itemHeight < 0.f)
        break;

      if (itemTop - itemHeight <= local.y)
      {
        m_itemSelected(*this, index);
        hide();
        break;
      }

      itemTop -= itemHeight;
      index++;
    }
  }

  Widget::onMouseButton(point, button, action, mods);
}
Exemplo n.º 4
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);
  }
}
Exemplo n.º 5
0
void Scroller::onButtonClicked(Widget& widget,
                               const vec2& point,
                               input::Button button,
                               bool clicked)
{
  if (!clicked)
    return;

  const vec2 local = transformToLocal(point);
  const float size = getHandleSize();
  const float offset = getHandleOffset();

  if (orientation == HORIZONTAL)
  {
    if (local.x < offset)
      setValue(value - getValueStep(), true);
    else if (local.x >= offset + size)
      setValue(value + getValueStep(), true);
  }
  else
  {
    if (local.y > getHeight() - offset)
      setValue(value - getValueStep(), true);
    else if (local.y <= getHeight() - offset - size)
      setValue(value + getValueStep(), true);
  }
}
Exemplo n.º 6
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();
}
Exemplo n.º 7
0
void Book::onButtonClicked(Widget& widget,
                           const vec2& point,
                           input::Button button,
                           bool clicked)
{
  const float position = transformToLocal(point).x;
  const float width = getWidth() / pages.size();

  const uint index = (uint) (position / width);

  if (pages[index] != activePage)
    setActivePage(pages[index], true);
}
Exemplo n.º 8
0
void Scroller::onDragMoved(Widget& widget, vec2 point)
{
  const vec2 local = transformToLocal(point);
  const float size = handleSize();

  float scale;

  if (m_orientation == HORIZONTAL)
    scale = (local.x - m_reference) / (width() - size);
  else
    scale = (height() - local.y - m_reference) / (height() - size);

  setValue(m_minValue + (m_maxValue - m_minValue) * scale, true);
}
Exemplo n.º 9
0
void Scroller::onDragMoved(Widget& widget, const vec2& point)
{
  const vec2 local = transformToLocal(point);
  const float size = getHandleSize();

  float scale;

  if (orientation == HORIZONTAL)
    scale = (local.x - reference) / (getWidth() - size);
  else
    scale = (getHeight() - local.y - reference) / (getHeight() - size);

  setValue(minValue + (maxValue - minValue) * scale, true);
}
Exemplo n.º 10
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();
  }
}
Exemplo n.º 11
0
void List::onMouseButton(Widget& widget,
                         vec2 position,
                         MouseButton button,
                         Action action,
                         uint mods)
{
  if (action != PRESSED)
    return;

  const vec2 local = transformToLocal(position);

  float itemTop = height();

  for (uint i = m_offset;  i < m_items.size();  i++)
  {
    const float itemHeight = m_items[i]->height();
    const float itemBottom = itemTop - itemHeight;

    if (itemBottom <= local.y)
    {
      if (itemBottom < 0.f)
        setOffset(m_offset + 1);

      if (m_selection == i)
      {
        if (m_editable)
          beginEditing();
      }
      else
        setSelection(i, true);

      return;
    }

    itemTop = itemBottom;
    if (itemTop < 0.f)
      break;
  }
}