コード例 #1
0
ファイル: tabs.cpp プロジェクト: optigon/aseprite
void Tabs::calculateHot()
{
  JRect rect = jwidget_get_rect(this);
  JRect box = jrect_new(rect->x1-m_scrollX, rect->y1, 0, rect->y2-1);
  Tab *hot = NULL;
  TabsListIterator it, end = m_list_of_tabs.end();

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

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

    if (jrect_point_in(box, jmouse_x(0), jmouse_y(0))) {
      hot = tab;
      break;
    }

    box->x1 = box->x2;
  }

  if (m_hot != hot) {
    m_hot = hot;

    if (m_delegate)
      m_delegate->mouseOverTab(this, m_hot ? m_hot->data: NULL);

    invalidate();
  }

  jrect_free(rect);
  jrect_free(box);
}
コード例 #2
0
ファイル: system.cpp プロジェクト: eledot/aseprite
void SetDisplay(she::Display* display)
{
  CursorType cursor = jmouse_get_cursor();

  jmouse_set_cursor(kNoCursor);
  ji_screen = (display ? reinterpret_cast<BITMAP*>(display->getSurface()->nativeHandle()): NULL);
  ji_screen_w = (ji_screen ? ji_screen->w: 0);
  ji_screen_h = (ji_screen ? ji_screen->h: 0);

  if (ji_screen != NULL) {
    Manager* manager = Manager::getDefault();
    if (manager) {
      manager->setDisplay(display);

      // Update default-manager size
      if ((jrect_w(manager->rc) != JI_SCREEN_W ||
           jrect_h(manager->rc) != JI_SCREEN_H)) {
        JRect rect = jrect_new(0, 0, JI_SCREEN_W, JI_SCREEN_H);
        jwidget_set_rect(manager, rect);
        jrect_free(rect);
      }
    }

    jmouse_set_cursor(cursor);  // Restore mouse cursor
  }
}
コード例 #3
0
ファイル: tabs.cpp プロジェクト: optigon/aseprite
void Tabs::setScrollX(int scroll_x)
{
  int max_x = getMaxScrollX();

  scroll_x = MID(0, scroll_x, max_x);
  if (m_scrollX != scroll_x) {
    m_scrollX = scroll_x;
    calculateHot();
    invalidate();
  }

  // We need scroll buttons?
  if (max_x > 0) {
    // Add childs
    if (!HAS_ARROWS(this)) {
      addChild(m_button_left);
      addChild(m_button_right);
      invalidate();
    }

    /* disable/enable buttons */
    m_button_left->setEnabled(m_scrollX > 0);
    m_button_right->setEnabled(m_scrollX < max_x);

    /* setup the position of each button */
    {
      JRect rect = jwidget_get_rect(this);
      JRect box = jrect_new(rect->x2-ARROW_W*2, rect->y1,
                            rect->x2-ARROW_W, rect->y2-2);
      jwidget_set_rect(m_button_left, box);

      jrect_moveto(box, box->x1+ARROW_W, box->y1);
      jwidget_set_rect(m_button_right, box);

      jrect_free(box);
      jrect_free(rect);
    }
  }
  // Remove buttons
  else if (HAS_ARROWS(this)) {
    removeChild(m_button_left);
    removeChild(m_button_right);
    invalidate();
  }
}
コード例 #4
0
ファイル: editor_view.cpp プロジェクト: optigon/aseprite
bool EditorView::onProcessMessage(Message* msg)
{
  switch (msg->type) {

    case JM_SETPOS:
      // This avoid the displacement of the widgets in the viewport

      jrect_copy(this->rc, &msg->setpos.rect);
      updateView();
      return true;

    case JM_DRAW:
      {
        Widget* viewport = getViewport();
        Widget* child = reinterpret_cast<JWidget>(jlist_first_data(viewport->children));
        JRect pos = jwidget_get_rect(this);
        SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
        bool selected = false;

        switch (m_type) {

          // Only show the view selected if it is the current editor
          case CurrentEditorMode:
            selected = (child == current_editor);
            break;

          // Always show selected
          case AlwaysSelected:
            selected = true;
            break;

        }

        theme->draw_bounds_nw(ji_screen,
                              pos->x1, pos->y1,
                              pos->x2-1, pos->y2-1,
                              selected ? PART_EDITOR_SELECTED_NW:
                                         PART_EDITOR_NORMAL_NW, false);

        jrect_free(pos);
      }
      return true;

  }

  return View::onProcessMessage(msg);
}
コード例 #5
0
ファイル: palette_view.cpp プロジェクト: optigon/aseprite
Color PaletteView::getColorByPosition(int target_x, int target_y)
{
  Palette* palette = get_current_palette();
  JRect cpos = jwidget_get_child_rect(this);
  div_t d = div(Palette::MaxColors, m_columns);
  int cols = m_columns;
  int rows = d.quot + ((d.rem)? 1: 0);
  int req_w, req_h;
  int x, y, u, v;
  int c;

  request_size(&req_w, &req_h);

  y = cpos->y1;
  c = 0;

  for (v=0; v<rows; v++) {
    x = cpos->x1;

    for (u=0; u<cols; u++) {
      if (c >= palette->size())
        break;

      if ((target_x >= x) && (target_x <= x+m_boxsize) &&
          (target_y >= y) && (target_y <= y+m_boxsize))
        return Color::fromIndex(c);

      x += m_boxsize+this->child_spacing;
      c++;
    }

    y += m_boxsize+this->child_spacing;
  }

  jrect_free(cpos);
  return Color::fromMask();
}
コード例 #6
0
ファイル: color_button.cpp プロジェクト: Skiles/aseprite
void ColorButton::openSelectorDialog()
{
  int x, y;

  if (m_frame == NULL) {
    m_frame = new ColorSelector();
    m_frame->user_data[0] = this;
    m_frame->ColorChange.connect(&ColorButton::onFrameColorChange, this);
  }

  m_frame->setColor(m_color, ColorSelector::ChangeType);
  m_frame->open_window();

  x = MID(0, this->rc->x1, JI_SCREEN_W-jrect_w(m_frame->rc));
  if (this->rc->y2 <= JI_SCREEN_H-jrect_h(m_frame->rc))
    y = MAX(0, this->rc->y2);
  else
    y = MAX(0, this->rc->y1-jrect_h(m_frame->rc));

  m_frame->position_window(x, y);

  jmanager_dispatch_messages(m_frame->getManager());
  m_frame->layout();

  /* setup the hot-region */
  {
    JRect rc = jrect_new(MIN(this->rc->x1, m_frame->rc->x1)-8,
			 MIN(this->rc->y1, m_frame->rc->y1)-8,
			 MAX(this->rc->x2, m_frame->rc->x2)+8,
			 MAX(this->rc->y2, m_frame->rc->y2)+8);
    JRegion rgn = jregion_new(rc, 1);
    jrect_free(rc);

    static_cast<PopupFrame*>(m_frame)->setHotRegion(rgn);
  }
}
コード例 #7
0
ファイル: tabs.cpp プロジェクト: optigon/aseprite
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);
}
コード例 #8
0
ファイル: palette_view.cpp プロジェクト: optigon/aseprite
bool PaletteView::onProcessMessage(Message* msg)
{
  switch (msg->type) {

    case JM_REQSIZE:
      request_size(&msg->reqsize.w, &msg->reqsize.h);
      return true;

    case JM_DRAW: {
      div_t d = div(Palette::MaxColors, m_columns);
      int cols = m_columns;
      int rows = d.quot + ((d.rem)? 1: 0);
      int x, y, u, v;
      int c, color;
      BITMAP *bmp;
      Palette* palette = get_current_palette();
      int bordercolor = makecol(255, 255, 255);

      bmp = create_bitmap(jrect_w(this->rc), jrect_h(this->rc));
      clear_to_color(bmp, makecol(0 , 0, 0));

      y = this->border_width.t;
      c = 0;

      for (v=0; v<rows; v++) {
        x = this->border_width.l;

        for (u=0; u<cols; u++) {
          if (c >= palette->size())
            break;

          if (bitmap_color_depth(ji_screen) == 8)
            color = c;
          else
            color = makecol_depth
              (bitmap_color_depth(ji_screen),
               _rgba_getr(palette->getEntry(c)),
               _rgba_getg(palette->getEntry(c)),
               _rgba_getb(palette->getEntry(c)));

          rectfill(bmp, x, y, x+m_boxsize-1, y+m_boxsize-1, color);

          if (m_selectedEntries[c]) {
            const int max = Palette::MaxColors;
            bool top    = (c >= m_columns            && c-m_columns >= 0  ? m_selectedEntries[c-m_columns]: false);
            bool bottom = (c < max-m_columns         && c+m_columns < max ? m_selectedEntries[c+m_columns]: false);
            bool left   = ((c%m_columns)>0           && c-1         >= 0  ? m_selectedEntries[c-1]: false);
            bool right  = ((c%m_columns)<m_columns-1 && c+1         < max ? m_selectedEntries[c+1]: false);

            if (!top) hline(bmp, x-1, y-1, x+m_boxsize, bordercolor);
            if (!bottom) hline(bmp, x-1, y+m_boxsize, x+m_boxsize, bordercolor);
            if (!left) vline(bmp, x-1, y-1, y+m_boxsize, bordercolor);
            if (!right) vline(bmp, x+m_boxsize, y-1, y+m_boxsize, bordercolor);
          }

          x += m_boxsize+this->child_spacing;
          c++;
        }

        y += m_boxsize+this->child_spacing;
      }

      blit(bmp, ji_screen,
           0, 0, this->rc->x1, this->rc->y1, bmp->w, bmp->h);
      destroy_bitmap(bmp);
      return true;
    }

    case JM_BUTTONPRESSED:
      captureMouse();
      /* continue... */

    case JM_MOTION: {
      JRect cpos = jwidget_get_child_rect(this);

      int req_w, req_h;
      request_size(&req_w, &req_h);

      int mouse_x = MID(cpos->x1, msg->mouse.x, cpos->x1+req_w-this->border_width.r-1);
      int mouse_y = MID(cpos->y1, msg->mouse.y, cpos->y1+req_h-this->border_width.b-1);

      jrect_free(cpos);

      Color color = getColorByPosition(mouse_x, mouse_y);
      if (color.getType() == Color::IndexType) {
        int idx = color.getIndex();

        app_get_statusbar()->showColor(0, "", color, 255);

        if (hasCapture() && idx != m_currentEntry) {
          if (!(msg->any.shifts & KB_CTRL_FLAG))
            clearSelection();

          if (msg->any.shifts & KB_SHIFT_FLAG)
            selectRange(m_rangeAnchor, idx);
          else
            selectColor(idx);

          // Emit signals
          jwidget_emit_signal(this, SIGNAL_PALETTE_EDITOR_CHANGE);
          IndexChange(idx);
        }
      }

      if (hasCapture())
        return true;

      break;
    }

    case JM_BUTTONRELEASED:
      releaseMouse();
      return true;

    case JM_WHEEL: {
      View* view = View::getView(this);
      if (view) {
        gfx::Point scroll = view->getViewScroll();
        scroll.y += (jmouse_z(1)-jmouse_z(0)) * 3 * m_boxsize;
        view->setViewScroll(scroll);
      }
      break;
    }

    case JM_MOUSELEAVE:
      app_get_statusbar()->clearText();
      break;

  }

  return Widget::onProcessMessage(msg);
}