Ejemplo n.º 1
0
void ButtonSet::Item::onPaint(ui::PaintEvent& ev)
{
  SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
  Graphics* g = ev.getGraphics();
  gfx::Rect rc = getClientBounds();
  gfx::Color face;
  int nw;

  if (!gfx::is_transparent(getBgColor()))
    g->fillRect(getBgColor(), g->getClipBounds());

  if (isSelected() || hasMouseOver()) {
    nw = PART_TOOLBUTTON_HOT_NW;
    face = theme->getColor(ThemeColor::ButtonHotFace);
  }
  else {
    nw = PART_TOOLBUTTON_LAST_NW;
    face = theme->getColor(ThemeColor::ButtonNormalFace);
  }

  Grid::Info info = buttonSet()->getChildInfo(this);
  if (info.col < info.grid_cols-1) rc.w+=1*jguiscale();
  if (info.row < info.grid_rows-1) rc.h+=3*jguiscale();

  theme->draw_bounds_nw(g, rc, nw, face);

  if (m_icon) {
    g->drawRgbaSurface(m_icon,
      rc.x + rc.w/2 - m_icon->width()/2,
      rc.y + rc.h/2 - m_icon->height()/2);
  }
}
Ejemplo n.º 2
0
void ColorBar::ScrollableView::onPaint(ui::PaintEvent& ev)
{
    ui::Graphics* g = ev.getGraphics();
    SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
    theme->draw_bounds_nw(g,
                          getClientBounds(),
                          hasFocus() ? PART_EDITOR_SELECTED_NW:
                          PART_EDITOR_NORMAL_NW,
                          ColorNone);
}
Ejemplo n.º 3
0
void ColorWheel::onPaint(ui::PaintEvent& ev)
{
  ui::Graphics* g = ev.getGraphics();
  SkinTheme* theme = static_cast<SkinTheme*>(getTheme());

  theme->drawRect(g, getClientBounds(),
                  theme->parts.editorNormal().get(),
                  getBgColor());

  const gfx::Rect& rc = m_clientBounds;

  for (int y=rc.y; y<rc.y+rc.h; ++y) {
    for (int x=rc.x; x<rc.x+rc.w; ++x) {
      app::Color appColor =
        ColorWheel::pickColor(gfx::Point(x, y));

      gfx::Color color;
      if (appColor.getType() != app::Color::MaskType) {
        color = color_utils::color_for_ui(appColor);
      }
      else {
        color = theme->colors.editorFace();
      }

      g->putPixel(color, x, y);
    }
  }

  if (m_mainColor.getAlpha() > 0) {
    int n = getHarmonies();
    int boxsize = MIN(rc.w/10, rc.h/10);

    for (int i=0; i<n; ++i) {
      app::Color color = getColorInHarmony(i);
      int hue = color.getHue()-30;
      int sat = color.getSaturation();
      gfx::Point pos =
        m_wheelBounds.getCenter() +
        gfx::Point(int(+std::cos(PI*hue/180)*double(m_wheelRadius)*sat/100.0),
                   int(-std::sin(PI*hue/180)*double(m_wheelRadius)*sat/100.0));

      she::Surface* icon = theme->parts.colorWheelIndicator()->getBitmap(0);
      g->drawRgbaSurface(icon,
                         pos.x-icon->width()/2,
                         pos.y-icon->height()/2);

      g->fillRect(gfx::rgba(color.getRed(),
                            color.getGreen(),
                            color.getBlue(), 255),
                  gfx::Rect(rc.x+rc.w-(n-i)*boxsize,
                            rc.y+rc.h-boxsize,
                            boxsize, boxsize));
    }
  }
}
Ejemplo n.º 4
0
void SearchEntry::onPaint(ui::PaintEvent& ev)
{
  SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
  theme->paintEntry(ev);

  auto icon = theme->parts.iconSearch()->getBitmap(0);
  Rect bounds = getClientBounds();
  ev.getGraphics()->drawColoredRgbaSurface(
    icon, theme->colors.text(),
    bounds.x + border().left(),
    bounds.y + bounds.h/2 - icon->height()/2);

  if (!getText().empty()) {
    icon = theme->parts.iconClose()->getBitmap(0);
    ev.getGraphics()->drawColoredRgbaSurface(
      icon, theme->colors.text(),
      bounds.x + bounds.w - border().right() - childSpacing() - icon->width(),
      bounds.y + bounds.h/2 - icon->height()/2);
  }
}
Ejemplo n.º 5
0
void PaletteView::onPaint(ui::PaintEvent& ev)
{
  ui::Graphics* g = ev.getGraphics();
  gfx::Rect bounds = getClientBounds();
  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;
  Palette* palette = get_current_palette();
  gfx::Color bordercolor = gfx::rgba(255, 255, 255);

  g->fillRect(gfx::rgba(0 , 0, 0), bounds);

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

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

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

      color = gfx::rgba(
        rgba_getr(palette->getEntry(c)),
        rgba_getg(palette->getEntry(c)),
        rgba_getb(palette->getEntry(c)));

      g->fillRect(color, gfx::Rect(x, y, m_boxsize, m_boxsize));

      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   ) g->drawHLine(bordercolor, x-1, y-1, m_boxsize+2);
        if (!bottom) g->drawHLine(bordercolor, x-1, y+m_boxsize, m_boxsize+2);
        if (!left  ) g->drawVLine(bordercolor, x-1, y-1, m_boxsize+2);
        if (!right ) g->drawVLine(bordercolor, x+m_boxsize, y-1, m_boxsize+2);
      }

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

    y += m_boxsize+this->child_spacing;
  }
}
Ejemplo n.º 6
0
void StatusBar::onPaint(ui::PaintEvent& ev)
{
  SkinTheme* theme = static_cast<SkinTheme*>(this->getTheme());
  gfx::Color textColor = theme->getColorById(kStatusBarText);
  Rect rc = getClientBounds();
  Graphics* g = ev.getGraphics();

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

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

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

  // Color
  if (m_state == SHOW_COLOR) {
    // Draw eyedropper icon
    she::Surface* icon = theme->get_toolicon("eyedropper");
    if (icon) {
      g->drawRgbaSurface(icon, x, rc.y + rc.h/2 - icon->height()/2);
      x += icon->width() + 4*guiscale();
    }

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

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

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

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

    x += getFont()->textLength(str.c_str()) + 4*guiscale();
  }

  // Show tool
  if (m_state == SHOW_TOOL) {
    // Draw eyedropper icon
    she::Surface* icon = theme->get_toolicon(m_tool->getId().c_str());
    if (icon) {
      g->drawRgbaSurface(icon, x, rc.y + rc.h/2 - icon->height()/2);
      x += icon->width() + 4*guiscale();
    }
  }

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

    x += getFont()->textLength(getText().c_str()) + 4*guiscale();
  }
}
Ejemplo n.º 7
0
void ToolBar::onPaint(ui::PaintEvent& ev)
{
  gfx::Rect bounds = getClientBounds();
  Graphics* g = ev.getGraphics();
  SkinTheme* theme = static_cast<SkinTheme*>(this->getTheme());
  gfx::Color normalFace = theme->getColor(ThemeColor::ButtonNormalFace);
  gfx::Color hotFace = theme->getColor(ThemeColor::ButtonHotFace);
  ToolBox* toolbox = App::instance()->getToolBox();
  ToolGroupList::iterator it = toolbox->begin_group();
  int groups = toolbox->getGroupsCount();
  Rect toolrc;

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

  for (int c=0; c<groups; ++c, ++it) {
    ToolGroup* tool_group = *it;
    Tool* tool = m_selectedInGroup[tool_group];
    gfx::Color face;
    int nw;

    if (UIContext::instance()->settings()->getCurrentTool() == tool ||
      m_hotIndex == c) {
      nw = PART_TOOLBUTTON_HOT_NW;
      face = hotFace;
    }
    else {
      nw = c >= 0 && c < groups-1 ? PART_TOOLBUTTON_NORMAL_NW:
                                    PART_TOOLBUTTON_LAST_NW;
      face = normalFace;
    }

    toolrc = getToolGroupBounds(c);
    toolrc.offset(-getBounds().x, -getBounds().y);
    theme->draw_bounds_nw(g, toolrc, nw, face);

    // Draw the tool icon
    she::Surface* icon = theme->get_toolicon(tool->getId().c_str());
    if (icon) {
      g->drawRgbaSurface(icon,
        toolrc.x+toolrc.w/2-icon->width()/2,
        toolrc.y+toolrc.h/2-icon->height()/2);
    }
  }

  // Draw button to show tool configuration
  toolrc = getToolGroupBounds(ConfigureToolIndex);
  toolrc.offset(-getBounds().x, -getBounds().y);
  bool isHot = (m_hotIndex == ConfigureToolIndex);
  theme->draw_bounds_nw(g,
    toolrc,
    isHot ? PART_TOOLBUTTON_HOT_NW:
    PART_TOOLBUTTON_LAST_NW,
    isHot ? hotFace: normalFace);

  she::Surface* icon = theme->get_toolicon("configuration");
  if (icon) {
    g->drawRgbaSurface(icon,
      toolrc.x+toolrc.w/2-icon->width()/2,
      toolrc.y+toolrc.h/2-icon->height()/2);
  }

  // Draw button to show/hide mini editor
  toolrc = getToolGroupBounds(MiniEditorVisibilityIndex);
  toolrc.offset(-getBounds().x, -getBounds().y);
  isHot = (m_hotIndex == MiniEditorVisibilityIndex ||
    App::instance()->getMainWindow()->getMiniEditor()->isMiniEditorEnabled());
  theme->draw_bounds_nw(g,
    toolrc,
    isHot ? PART_TOOLBUTTON_HOT_NW:
    PART_TOOLBUTTON_LAST_NW,
    isHot ? hotFace: normalFace);

  icon = theme->get_toolicon("minieditor");
  if (icon) {
    g->drawRgbaSurface(icon,
      toolrc.x+toolrc.w/2-icon->width()/2,
      toolrc.y+toolrc.h/2-icon->height()/2);
  }
}
Ejemplo n.º 8
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();
}
Ejemplo n.º 9
0
void ButtonSet::Item::onPaint(ui::PaintEvent& ev)
{
  SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
  Graphics* g = ev.getGraphics();
  gfx::Rect rc = getClientBounds();
  gfx::Color fg, bg;
  SkinPartPtr nw;
  gfx::Rect boxRc, textRc, iconRc;
  gfx::Size iconSize;
  if (m_icon)
    iconSize = m_icon->getSize();

  getTextIconInfo(
    &boxRc, &textRc, &iconRc,
    CENTER | (hasText() ? BOTTOM: MIDDLE),
    iconSize.w, iconSize.h);

  Grid::Info info = buttonSet()->getChildInfo(this);
  bool isLastCol = (info.col+info.hspan >= info.grid_cols);
  bool isLastRow = (info.row+info.vspan >= info.grid_rows);

  if (m_icon || isLastRow) {
    textRc.y -= 1*guiscale();
    iconRc.y -= 1*guiscale();
  }

  if (!gfx::is_transparent(getBgColor()))
    g->fillRect(getBgColor(), g->getClipBounds());

  if (isSelected() || hasMouseOver()) {
    if (hasCapture()) {
      nw = theme->parts.toolbuttonPushed();
      fg = theme->colors.buttonSelectedText();
      bg = theme->colors.buttonSelectedFace();
    }
    else {
      nw = (hasFocus() ? theme->parts.toolbuttonHotFocused():
                         theme->parts.toolbuttonHot());
      fg = theme->colors.buttonHotText();
      bg = theme->colors.buttonHotFace();
    }
  }
  else {
    nw = (hasFocus() ? theme->parts.toolbuttonFocused():
                       theme->parts.toolbuttonLast());
    fg = theme->colors.buttonNormalText();
    bg = theme->colors.buttonNormalFace();
  }

  if (!isLastCol)
    rc.w += 1*guiscale();

  if (!isLastRow) {
    if (nw == theme->parts.toolbuttonHotFocused())
      rc.h += 2*guiscale();
    else
      rc.h += 3*guiscale();
  }

  theme->drawRect(g, rc, nw.get(), bg);

  if (m_icon) {
    if (isSelected() && hasCapture())
      g->drawColoredRgbaSurface(m_icon->getBitmap(0), theme->colors.buttonSelectedText(),
                                iconRc.x, iconRc.y);
    else
      g->drawRgbaSurface(m_icon->getBitmap(0), iconRc.x, iconRc.y);
  }

  if (hasText()) {
    g->setFont(getFont());
    g->drawUIString(getText(), fg, gfx::ColorNone, textRc.getOrigin(),
                    false);
  }
}
Ejemplo n.º 10
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));
  }
}