Ejemplo 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();
}