Example #1
0
void Tabs::removeTab(void* data)
{
  Tab *tab = getTabByData(data);

  if (tab) {
    if (m_hot == tab) m_hot = NULL;
    if (m_selected == tab) m_selected = NULL;

    TabsListIterator it =
      std::find(m_list_of_tabs.begin(), m_list_of_tabs.end(), tab);

    ASSERT(it != m_list_of_tabs.end() && "Removing a tab that is not part of the Tabs widget");

    it = m_list_of_tabs.erase(it);

    // Width of the removed tab
    if (m_removedTab) {
      delete m_removedTab;
      m_removedTab = NULL;
    }
    m_removedTab = tab;

    // Next tab in the list
    if (it != m_list_of_tabs.end())
      m_nextTabOfTheRemovedOne = *it;
    else
      m_nextTabOfTheRemovedOne = NULL;

    // Update scroll (in the same position if we can)
    setScrollX(m_scrollX);

    startAni(ANI_REMOVING_TAB);
  }
}
Example #2
0
void AdvScrollArea::ensureVisibleY(int y) {
	int ch = getScrollAreaHeight();
	int cy = getScrollY();
	scrollV->setValue(y);
	if (y < cy) {setScrollX(y - ch);}
	if (y > cy + ch) {setScrollY(y);}
}
Example #3
0
void LevelEditor::selectObjectAtIndex(int index) {
  previewScene_.selectObjectAtIndex(index);
  
//  if ((toolManager_.objectEditorSingleGroupIt()->xPos())
//        > (scrollX_ + 50)) {
    setScrollX(toolManager_.objectEditorSingleGroupIt()
                 ->xPos() - (300 / scale()));
    if (scrollX() < 0) {
      setScrollX(0);
    }
    
    setScrollY(toolManager_.objectEditorSingleGroupIt()
                 ->yPos() - (300 / scale()));
    if (scrollY() < 0) {
      setScrollY(0);
    }
//  }
}
Example #4
0
bool LevelEditor::editAndAppendObject() {
  bool result = previewScene_.editAndAppendObject();
  
  if (result) {
    setScrollX(toolManager_.objectEditorSingleGroupIt()
                 ->xPos() - (300 / scale()));
    if (scrollX() < 0) {
      setScrollX(0);
    }
    
    setScrollY(toolManager_.objectEditorSingleGroupIt()
                 ->yPos() - (300 / scale()));
    if (scrollY() < 0) {
      setScrollY(0);
    }
  }
  
  return result;
}
Example #5
0
void Tabs::makeTabVisible(Tab* make_visible_this_tab)
{
  int x = 0;
  int extra_x = getMaxScrollX() > 0 ? ARROW_W*2: 0;
  TabsListIterator it, end = m_list_of_tabs.end();

  for (it = m_list_of_tabs.begin(); it != end; ++it) {
    Tab* tab = *it;

    if (tab == make_visible_this_tab) {
      if (x - m_scrollX < 0) {
        setScrollX(x);
      }
      else if (x + tab->width - m_scrollX > jrect_w(this->rc) - extra_x) {
        setScrollX(x + tab->width - jrect_w(this->rc) + extra_x);
      }
      break;
    }

    x += tab->width;
  }
}
Example #6
0
void Tabs::addTab(const char* text, void* data)
{
  Tab *tab = new Tab(text, data);
  tab->width = calcTabWidth(tab);

  m_list_of_tabs.push_back(tab);

  // Update scroll (in the same position if we can
  setScrollX(m_scrollX);

  startAni(ANI_ADDING_TAB);
  //invalidate();
}
Example #7
0
bool Tabs::onProcessMessage(Message* msg)
{
  SkinTheme* theme = static_cast<SkinTheme*>(this->getTheme());

  switch (msg->type) {

    case JM_REQSIZE:
      msg->reqsize.w = 0; // msg->reqsize.h = 4 + jwidget_get_text_height(widget) + 5;
      msg->reqsize.h =
        theme->get_part(PART_TAB_FILLER)->h +
        theme->get_part(PART_TAB_BOTTOM_NORMAL)->h;
      return true;

    case JM_SETPOS:
      jrect_copy(this->rc, &msg->setpos.rect);
      setScrollX(m_scrollX);
      return true;

    case JM_DRAW: {
      BITMAP *doublebuffer = create_bitmap(jrect_w(&msg->draw.rect),
                                           jrect_h(&msg->draw.rect));
      JRect rect = jwidget_get_rect(this);
      jrect_displace(rect, -msg->draw.rect.x1, -msg->draw.rect.y1);

      JRect box = jrect_new(rect->x1-m_scrollX,
                            rect->y1,
                            rect->x1-m_scrollX+2*jguiscale(),
                            rect->y1+theme->get_part(PART_TAB_FILLER)->h);

      clear_to_color(doublebuffer, theme->get_window_face_color());

      theme->draw_part_as_hline(doublebuffer, box->x1, box->y1, box->x2-1, box->y2-1, PART_TAB_FILLER);
      theme->draw_part_as_hline(doublebuffer, box->x1, box->y2, box->x2-1, rect->y2-1, PART_TAB_BOTTOM_NORMAL);

      box->x1 = box->x2;

      // For each tab...
      TabsListIterator it, end = m_list_of_tabs.end();

      for (it = m_list_of_tabs.begin(); it != end; ++it) {
        Tab* tab = *it;

        box->x2 = box->x1 + tab->width;

        int x_delta = 0;
        int y_delta = 0;

        // Y-delta for animating tabs (intros and outros)
        if (m_ani == ANI_ADDING_TAB && m_selected == tab) {
          y_delta = (box->y2 - box->y1) * (ANI_ADDING_TAB_TICKS - m_ani_t) / ANI_ADDING_TAB_TICKS;
        }
        else if (m_ani == ANI_REMOVING_TAB && m_nextTabOfTheRemovedOne == tab) {
          x_delta += m_removedTab->width - m_removedTab->width*(1.0-std::exp(-10.0 * m_ani_t / (double)ANI_REMOVING_TAB_TICKS));
          x_delta = MID(0, x_delta, m_removedTab->width);

          // Draw deleted tab
          if (m_removedTab) {
            JRect box2 = jrect_new(box->x1, box->y1, box->x1+x_delta, box->y2);
            drawTab(doublebuffer, box2, m_removedTab, 0, false);
            jrect_free(box2);
          }
        }

        box->x1 += x_delta;
        box->x2 += x_delta;

        drawTab(doublebuffer, box, tab, y_delta, (tab == m_selected));

        box->x1 = box->x2;
      }

      if (m_ani == ANI_REMOVING_TAB && m_nextTabOfTheRemovedOne == NULL) {
        // Draw deleted tab
        if (m_removedTab) {
          int x_delta = m_removedTab->width - m_removedTab->width*(1.0-std::exp(-10.0 * m_ani_t / (double)ANI_REMOVING_TAB_TICKS));
          x_delta = MID(0, x_delta, m_removedTab->width);

          JRect box2 = jrect_new(box->x1, box->y1, box->x1+x_delta, box->y2);
          drawTab(doublebuffer, box2, m_removedTab, 0, false);
          jrect_free(box2);

          box->x1 += x_delta;
          box->x2 = box->x1;
        }
      }

      /* fill the gap to the right-side */
      if (box->x1 < rect->x2) {
        theme->draw_part_as_hline(doublebuffer, box->x1, box->y1, rect->x2-1, box->y2-1, PART_TAB_FILLER);
        theme->draw_part_as_hline(doublebuffer, box->x1, box->y2, rect->x2-1, rect->y2-1, PART_TAB_BOTTOM_NORMAL);
      }

      jrect_free(rect);
      jrect_free(box);

      blit(doublebuffer, ji_screen, 0, 0,
           msg->draw.rect.x1,
           msg->draw.rect.y1,
           doublebuffer->w,
           doublebuffer->h);
      destroy_bitmap(doublebuffer);
      return true;
    }

    case JM_MOUSEENTER:
    case JM_MOTION:
      calculateHot();
      return true;

    case JM_MOUSELEAVE:
      if (m_hot != NULL) {
        m_hot = NULL;
        invalidate();
      }
      return true;

    case JM_BUTTONPRESSED:
      if (m_hot != NULL) {
        if (m_selected != m_hot) {
          m_selected = m_hot;
          invalidate();
        }

        if (m_selected && m_delegate)
          m_delegate->clickTab(this,
                               m_selected->data,
                               msg->mouse.flags);
      }
      return true;

    case JM_WHEEL: {
      int dx = (jmouse_z(1) - jmouse_z(0)) * jrect_w(this->rc)/6;
      // setScrollX(m_scrollX+dx);

      m_begScrollX = m_scrollX;
      if (m_ani != ANI_SMOOTH_SCROLL)
        m_endScrollX = m_scrollX + dx;
      else
        m_endScrollX += dx;

      // Limit endScrollX position (to improve animation ending to the correct position)
      {
        int max_x = getMaxScrollX();
        m_endScrollX = MID(0, m_endScrollX, max_x);
      }

      startAni(ANI_SMOOTH_SCROLL);
      return true;
    }

    case JM_TIMER: {
      switch (m_ani) {
        case ANI_NONE:
          // Do nothing
          break;
        case ANI_SCROLL: {
          int dir = (getManager()->getCapture() == m_button_left ? -1: 1);
          setScrollX(m_scrollX + dir*8*msg->timer.count);
          break;
        }
        case ANI_SMOOTH_SCROLL: {
          if (m_ani_t == ANI_SMOOTH_SCROLL_TICKS) {
            stopAni();
            setScrollX(m_endScrollX);
          }
          else {
            // Lineal
            //setScrollX(m_begScrollX + m_endScrollX - m_begScrollX) * m_ani_t / 10);

            // Exponential
            setScrollX(m_begScrollX +
                       (m_endScrollX - m_begScrollX) * (1.0-std::exp(-10.0 * m_ani_t / (double)ANI_SMOOTH_SCROLL_TICKS)));
          }
          break;
        }
        case ANI_ADDING_TAB: {
          if (m_ani_t == ANI_ADDING_TAB_TICKS)
            stopAni();
          invalidate();
          break;
        }
        case ANI_REMOVING_TAB: {
          if (m_ani_t == ANI_REMOVING_TAB_TICKS)
            stopAni();
          invalidate();
          break;
        }
      }
      ++m_ani_t;
      break;
    }

    case JM_SIGNAL:
      if (msg->signal.num == JI_SIGNAL_INIT_THEME) {
        m_button_left->setBgColor(theme->get_tab_selected_face_color());
        m_button_right->setBgColor(theme->get_tab_selected_face_color());
      }
      else if (msg->signal.num == JI_SIGNAL_SET_FONT) {
        TabsListIterator it, end = m_list_of_tabs.end();

        for (it = m_list_of_tabs.begin(); it != end; ++it) {
          Tab* tab = *it;
          tab->width = calcTabWidth(tab);
        }
      }
      else if (msg->signal.num == JI_SIGNAL_INIT_THEME) {
        /* setup the background color */
        jwidget_set_bg_color(this, ji_color_face());
      }
      break;

  }

  return Widget::onProcessMessage(msg);
}
Example #8
0
void AdvScrollArea::ensureVisibleX(int x) {
	int cw = getScrollAreaWidth();
	int cx = getScrollX();
	if (x < cx) {setScrollX(x - cw);}
	if (x > cx + cw) {setScrollX(x);}
}