Пример #1
0
void WidgetList::SetFocusOnPreviousWidget()
{
  // No widget => exit
  if (widget_list.size() == 0) {
    selected_widget = NULL;
    return;
  }

  Widget* w = GetPreviousWidget(selected_widget, true);
  SetFocusOn(w, true);
}
Пример #2
0
void WidgetList::SetFocusOnNextWidget()
{
  // No widget => exit
  if (widget_list.size() == 0) {
    selected_widget = NULL;
    return;
  }

  MSG_DBG_RTTI("widgetlist", "before %s:%p",
               typeid(selected_widget).name(), selected_widget);

  Widget* w = GetNextWidget(selected_widget, true);
  SetFocusOn(w, true);
}
Пример #3
0
Widget* WidgetList::ClickUp(const Point2i &mousePosition, uint button)
{
  for (wit w=widget_list.begin(); w != widget_list.end(); w++) {
    if ((*w)->Contains(mousePosition)) {
      Widget* child = (*w)->ClickUp(mousePosition,button);

      if (child)
        SetFocusOn(child);

      return child;
    }
  }

  return NULL;
}
Пример #4
0
Widget * ScrollBox::ClickUp(const Point2i & mousePosition, uint button)
{
  ScrollMode old_mode = scroll_mode;
  start_drag_offset = NO_DRAG;
  scroll_mode = SCROLL_MODE_NONE;

  if (!vbox->GetFirstWidget()) {
    return NULL;
  }

  // Handle the click up as a widget click only if we weren't dragging
  // If we click up close to where we clicked down, it will however register
  // as a click and not a scrolling
  if (vbox->Contains(mousePosition) &&
      (start_drag_y==NO_DRAG || abs(start_drag_y-mousePosition.y)<2)) {
    Widget *w = vbox->ClickUp(mousePosition, button);

    if (w) {
      SetFocusOn(w);
      return w;
    }
    // The click was not handled, let's try using it for scrolling
  }

  if (HasScrollBar()) {
    bool is_click   = Mouse::IS_CLICK_BUTTON(button);
    int  max_offset = GetMaxOffset();
    int  new_offset = offset;

    // The event involves the scrollbar or its buttons
    if ((button == SDL_BUTTON_WHEELDOWN && Contains(mousePosition)) ||
        (is_click && m_down->Contains(mousePosition))) {

      // bottom button
      new_offset = offset+SCROLL_SPEED;
    } else if ((button == SDL_BUTTON_WHEELUP && Contains(mousePosition)) ||
               (is_click && m_up->Contains(mousePosition))) {

      // top button
      new_offset = offset-SCROLL_SPEED;
    } else if (is_click) {
      // Was it released after a drag operation?
      if (old_mode!=SCROLL_MODE_NONE /*&& start_drag_y != mousePosition.y*/)
        return this;
      const Rectanglei& scroll_track = GetScrollTrack();
      if (scroll_track.Contains(mousePosition)) {
        // Set this as new scroll thumb position
        int height = scroll_track.GetSizeY();
        new_offset = ((mousePosition.y - scroll_track.GetPositionY()) * (size.y+max_offset)
                      + (height/2)) / scroll_track.GetSizeY();
      }
    }

    // Clip new offset to correct value
    if (new_offset > max_offset)
      new_offset = max_offset;
    if (new_offset < 0)
      new_offset = 0;

    if (new_offset != offset) {
      offset = new_offset;
      Pack();
      NeedRedrawing();
    }

    return this;
  }

  return NULL;
}