Esempio n. 1
0
void StatusBar::onPaint(ui::PaintEvent& ev)
{
  SkinTheme* theme = static_cast<SkinTheme*>(this->getTheme());
  ui::Color textColor = theme->getColorById(kStatusBarText);
  Rect rc = getClientBounds();
  Graphics* g = ev.getGraphics();

  g->fillRect(getBgColor(), rc);

  rc.shrink(Border(2, 1, 2, 2)*jguiscale());

  int x = rc.x + 4*jguiscale();

  // Color
  if (m_state == SHOW_COLOR) {
    // Draw eyedropper icon
    BITMAP* icon = theme->get_toolicon("eyedropper");
    if (icon) {
      g->drawAlphaBitmap(icon, x, rc.y + rc.h/2 - icon->h/2);
      x += icon->w + 4*jguiscale();
    }

    // Draw color
    draw_color_button(g, gfx::Rect(x, rc.y, 32*jguiscale(), rc.h),
      true, true, true, true,
      true, true, true, true,
      app_get_current_pixel_format(), m_color,
      false, false);

    x += (32+4)*jguiscale();

    // Draw color description
    std::string str = m_color.toHumanReadableString(app_get_current_pixel_format(),
      app::Color::LongHumanReadableString);
    if (m_alpha < 255) {
      char buf[512];
      usprintf(buf, ", Alpha %d", m_alpha);
      str += buf;
    }

    g->drawString(str, textColor, ColorNone, false,
      gfx::Point(x, rc.y + rc.h/2 - text_height(getFont())/2));

    x += ji_font_text_len(getFont(), str.c_str()) + 4*jguiscale();
  }

  // Show tool
  if (m_state == SHOW_TOOL) {
    // Draw eyedropper icon
    BITMAP* icon = theme->get_toolicon(m_tool->getId().c_str());
    if (icon) {
      g->drawAlphaBitmap(icon, x, rc.y + rc.h/2 - icon->h/2);
      x += icon->w + 4*jguiscale();
    }
  }

  // Status bar text
  if (getTextLength() > 0) {
    g->drawString(getText(), textColor, ColorNone, false,
      gfx::Point(x, rc.y + rc.h/2 - text_height(getFont())/2));

    x += ji_font_text_len(getFont(), getText().c_str()) + 4*jguiscale();
  }

  // Draw progress bar
  if (!m_progress.empty()) {
    int width = 64;
    int x = rc.x2() - (width+4);

    for (ProgressList::iterator it = m_progress.begin(); it != m_progress.end(); ++it) {
      Progress* progress = *it;

      theme->paintProgressBar(g,
        gfx::Rect(x, rc.y, width, rc.h),
        progress->getPos());

      x -= width+4;
    }
  }

  updateSubwidgetsVisibility();
}
Esempio n. 2
0
void FileList::onPaint(ui::PaintEvent& ev)
{
  Graphics* g = ev.getGraphics();
  SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
  View* view = View::getView(this);
  gfx::Rect vp = view->getViewportBounds();
  gfx::Rect bounds = getClientBounds();
  int x, y = bounds.y;
  int evenRow = 0;
  gfx::Color bgcolor;
  gfx::Color fgcolor;
  she::Surface* thumbnail = NULL;
  int thumbnail_y = 0;

  g->fillRect(theme->getColor(ThemeColor::Background), bounds);

  // rows
  for (FileItemList::iterator
         it=m_list.begin(), end=m_list.end(); it!=end; ++it) {
    IFileItem* fi = *it;
    gfx::Size itemSize = getFileItemSize(fi);

    if (fi == m_selected) {
      fgcolor = theme->getColor(ThemeColor::FileListSelectedRowText);
      bgcolor = theme->getColor(ThemeColor::FileListSelectedRowFace);
    }
    else {
      bgcolor = evenRow ? theme->getColor(ThemeColor::FileListEvenRowFace):
                          theme->getColor(ThemeColor::FileListOddRowFace);

      if (fi->isFolder() && !fi->isBrowsable())
        fgcolor = theme->getColor(ThemeColor::FileListDisabledRowText);
      else
        fgcolor = evenRow ? theme->getColor(ThemeColor::FileListEvenRowText):
                            theme->getColor(ThemeColor::FileListOddRowText);
    }

    x = bounds.x+2*jguiscale();

    // Item background
    g->fillRect(bgcolor, gfx::Rect(bounds.x, y, bounds.w, itemSize.h));

    if (fi->isFolder()) {
      int icon_w = getFont()->textLength("[+]");

      g->drawUIString("[+]", fgcolor, bgcolor, gfx::Point(x, y+2*jguiscale()));
      x += icon_w+2*jguiscale();
    }

    // item name
    g->drawString(
      fi->getDisplayName().c_str(),
      fgcolor, bgcolor, gfx::Point(x, y+2*jguiscale()));

    // draw progress bars
    double progress;
    ThumbnailGenerator::WorkerStatus workerStatus =
      ThumbnailGenerator::instance()->getWorkerStatus(fi, progress);

    if (workerStatus == ThumbnailGenerator::WorkingOnThumbnail) {
      int barw = 64*jguiscale();

      theme->paintProgressBar(g,
        gfx::Rect(
          bounds.x2()-2*jguiscale()-barw,
          y+itemSize.h/2-3*jguiscale(),
          barw, 6*jguiscale()),
        progress);
    }

    // Thumbnail position
    if (fi == m_selected) {
      thumbnail = fi->getThumbnail();
      if (thumbnail)
        thumbnail_y = y + itemSize.h/2;
    }

    y += itemSize.h;
    evenRow ^= 1;
  }

  // Draw the thumbnail
  if (thumbnail) {
    x = vp.x+vp.w - 2*jguiscale() - thumbnail->width();
    y = thumbnail_y - thumbnail->height()/2 + getBounds().y;
    y = MID(vp.y+2*jguiscale(), y, vp.y+vp.h-3*jguiscale()-thumbnail->height());
    x -= getBounds().x;
    y -= getBounds().y;

    g->blit(thumbnail, 0, 0, x, y, thumbnail->width(), thumbnail->height());
    g->drawRect(gfx::rgba(0, 0, 0),
      gfx::Rect(x-1, y-1, thumbnail->width()+1, thumbnail->height()+1));
  }
}