Example #1
0
bool GuiList::OnMouseButtonEvent(const MouseButtonEvent& mbe)
{
  if (!IsVisible())
  {
    return false;
  }

  Vec2f cursorPos(mbe.x, mbe.y);
 
  if (mbe.button == AMJU_BUTTON_MOUSE_LEFT &&
      mbe.isDown)
  {
    // Stop scrolling, no?
    GuiScroll* scroll = dynamic_cast<GuiScroll*>(GetParent());
    Assert(scroll);
    scroll->StopScrolling();

    // Check each item
    int selected = -1;
    for (unsigned int i = 0; i < m_children.size(); i++)
    {
      GuiElement* item = m_children[i];

      Rect r = GetRect(item);

      if (r.IsPointIn(cursorPos))
      {
        selected = i;
        break; 
      }
    }

    if (selected != -1)
    {
      // TODO Should react on mouse up when up item == down item ??

      if (IsMultiSel())
      {
        // Toggle selected flag for this child
        SetSelected(selected, !IsSelected(selected));
      }
      else
      {
        SetSelected(selected, true);
        if (m_singleClickFunc)
        {
          m_singleClickFunc(this, selected);
        }
      }

      // TODO Why is this a bad idea ?
      //m_items[m_selected]->ExecuteCommand(); 

      // Problem with nested item, but should open up on mouse over anyway...
//      SetVisible(false); // TODO flag for this behaviour
      return true; // handled
    }
  }
  return false; // not handled
}
Example #2
0
bool GuiTextEdit::OnCursorEvent(const CursorEvent& ce)
{
  // TODO In drag mode, select part of the text

  Rect r = GetRect(this);
  if (!r.IsPointIn(Vec2f(ce.x, ce.y)))
  {
    //return false; // not handled - cursor not in edit box
    // We do want to hande this, e.g. if we drag mouse past the right hand end, we want to select all text.
  }

  if (s_drag && HasFocus())
  {
    m_selectedText = CalcCursorPos(ce.x);
    m_triListSelection = 0;
      
#ifdef TEXT_EDIT_DEBUG
std::cout << "Selected: m_caret: " << m_caret << " m_selectedText: " << m_selectedText << ": \"";
if (m_caret > m_selectedText)
{
  std::cout << m_text.substr(m_selectedText, m_caret - m_selectedText);
}
else
{
  std::cout << m_text.substr(m_caret, m_selectedText - m_caret);
}
std::cout << "\"\n";
#endif
  }

  return false;
}
Example #3
0
bool GuiList::OnDoubleClickEvent(const DoubleClickEvent& dce)
{
  if (dce.button != AMJU_BUTTON_MOUSE_LEFT)
  {
    return false;
  }

  if (!IsVisible())
  {
    return false;
  }

  if (m_doubleClickFunc)
  {
    Vec2f cursorPos(dce.x, dce.y);
    for (unsigned int i = 0; i < m_children.size(); i++)
    {
      GuiElement* item = m_children[i];
      Rect r = GetRect(item);
      if (r.IsPointIn(cursorPos))
      {
        m_doubleClickFunc(this, i);
        return true; 
      }
    }
  }

  return false;
}
Example #4
0
bool GuiTextEdit::OnMouseButtonEvent(const MouseButtonEvent& mbe)
{
  if (!IsVisible())
  {
    return false;
  }

  Rect r = GetRect(this);
  if (!r.IsPointIn(Vec2f(mbe.x, mbe.y)))
  {
    return false; // not handled - cursor not in edit box
  }

  // We want to drag to select text even if this is not the focus ?
  //if (HasFocus())
  {
    s_drag = mbe.isDown;
#ifdef TEXT_EDIT_DEBUG
std::cout << "GuiTextEdit Drag is now " << (s_drag ? "ON" : "OFF") << "\n";
#endif
  }

  // If clicked in bounding rect, this element gets focus
  SetHasFocus(true);

  if (!mbe.isDown)
  {
    return true;  
  }

  m_caret = CalcCursorPos(mbe.x);
  m_selectedText = m_caret;
  m_triListSelection = 0;

#ifdef TEXT_EDIT_DEBUG
std::cout << "MB down, resetting selection trilist.\n";
#endif

  return true; // ?
}