Esempio n. 1
0
void ColorSpectrum::onPaint(ui::PaintEvent& ev)
{
  ui::Graphics* g = ev.graphics();
  SkinTheme* theme = static_cast<SkinTheme*>(this->theme());

  theme->drawRect(g, clientBounds(),
                  theme->parts.editorNormal().get(),
                  bgColor());

  gfx::Rect rc = clientChildrenBounds();
  if (rc.isEmpty())
    return;

  int vmid = (align() & HORIZONTAL ? rc.h/2 : rc.w/2);
  vmid = MAX(1, vmid);

  for (int y=0; y<rc.h; ++y) {
    for (int x=0; x<rc.w; ++x) {
      int u, v, umax;
      if (align() & HORIZONTAL) {
        u = x;
        v = y;
        umax = MAX(1, rc.w-1);
      }
      else {
        u = y;
        v = x;
        umax = MAX(1, rc.h-1);
      }

      double hue = 360.0 * u / umax;
      double sat = (v < vmid ? 100.0 * v / vmid : 100.0);
      double val = (v < vmid ? 100.0 : 100.0-(100.0 * (v-vmid) / vmid));

      gfx::Color color = color_utils::color_for_ui(
        app::Color::fromHsv(
          MID(0.0, hue, 360.0),
          MID(0.0, sat, 100.0),
          MID(0.0, val, 100.0)));

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

  if (m_color.getType() != app::Color::MaskType) {
    double hue = m_color.getHue();
    double sat = m_color.getSaturation();
    double val = m_color.getValue();
    double lit = (200.0 - sat) * val / 200.0;
    gfx::Point pos(rc.x + int(hue * rc.w / 360.0),
                   rc.y + rc.h - int(lit * rc.h / 100.0));

    she::Surface* icon = theme->parts.colorWheelIndicator()->bitmap(0);
    g->drawColoredRgbaSurface(
      icon,
      lit > 50.0 ? gfx::rgba(0, 0, 0): gfx::rgba(255, 255, 255),
      pos.x-icon->width()/2,
      pos.y-icon->height()/2);
  }
}
Esempio n. 2
0
void ColorWheel::onPaint(ui::PaintEvent& ev)
{
  ui::Graphics* g = ev.graphics();
  SkinTheme* theme = static_cast<SkinTheme*>(this->theme());

  theme->drawRect(g, clientBounds(),
                  theme->parts.editorNormal().get(),
                  bgColor());

  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.center() +
        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()->bitmap(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));
    }
  }
}
Esempio n. 3
0
void SearchEntry::onPaint(ui::PaintEvent& ev)
{
  SkinTheme* theme = static_cast<SkinTheme*>(this->theme());
  theme->paintEntry(ev);

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

  if (!text().empty()) {
    icon = theme->parts.iconClose()->bitmap(0);
    ev.graphics()->drawColoredRgbaSurface(
      icon, theme->colors.text(),
      bounds.x + bounds.w - border().right() - childSpacing() - icon->width(),
      bounds.y + bounds.h/2 - icon->height()/2);
  }
}
void ColorCurveEditor::onPaint(ui::PaintEvent& ev)
{
  ui::Graphics* g = ev.graphics();
  gfx::Rect rc = clientBounds();
  gfx::Rect client = clientChildrenBounds();
  gfx::Point pt;
  int c;

  g->fillRect(gfx::rgba(0, 0, 0), rc);
  g->drawRect(gfx::rgba(255, 255, 0), rc);

  // Draw guides
  for (c=1; c<=3; c++)
    g->drawVLine(gfx::rgba(128, 128, 0), c*client.w/4, client.y, client.h);

  for (c=1; c<=3; c++)
    g->drawHLine(gfx::rgba(128, 128, 0), client.x, c*client.h/4, client.w);

  // Get curve values
  std::vector<int> values(m_viewBounds.w);
  m_curve->getValues(m_viewBounds.x, m_viewBounds.x+m_viewBounds.w-1, values);

  // Draw curve
  for (c = client.x; c < client.x+client.w; ++c) {
    pt = clientToView(gfx::Point(c, 0));
    pt.x = MID(m_viewBounds.x, pt.x, m_viewBounds.x+m_viewBounds.w-1);
    pt.y = values[pt.x - m_viewBounds.x];
    pt.y = MID(m_viewBounds.y, pt.y, m_viewBounds.y+m_viewBounds.h-1);
    pt = viewToClient(pt);

    g->putPixel(gfx::rgba(255, 255, 255), c, pt.y);
  }

  // Draw nodes
  for (const gfx::Point& point : *m_curve) {
    pt = viewToClient(point);

    gfx::Rect box(0, 0, 5*guiscale(), 5*guiscale());
    box.offset(pt.x-box.w/2, pt.y-box.h/2);

    g->drawRect(gfx::rgba(0, 0, 255), box);

    if (m_editPoint == &point) {
      box.enlarge(4*guiscale());
      g->drawRect(gfx::rgba(255, 255, 0), box);
    }
    else if (m_hotPoint == &point) {
      box.enlarge(2*guiscale());
      g->drawRect(gfx::rgba(255, 255, 0), box);
    }
  }
}
Esempio n. 5
0
void ColorShades::onPaint(ui::PaintEvent& ev)
{
  auto theme = skin::SkinTheme::instance();
  ui::Graphics* g = ev.graphics();
  gfx::Rect bounds = clientBounds();

  theme->paintWidget(g, this, style(), bounds);

  bounds.shrink(3*ui::guiscale());

  gfx::Rect box(bounds.x, bounds.y, m_boxSize*ui::guiscale(), bounds.h);

  Shade colors = getShade();
  if (colors.size() >= 2) {
    gfx::Rect hotBounds;

    int j = 0;
    for (int i=0; box.x<bounds.x2(); ++i, box.x += box.w) {
      // Make the last box a little bigger to just use all
      // available size
      if (i == int(colors.size())-1) {
        if (bounds.x+bounds.w-box.x <= m_boxSize+m_boxSize/2)
          box.w = bounds.x+bounds.w-box.x;
      }

      app::Color color;

      if (m_dragIndex >= 0 &&
          m_hotIndex == i) {
        color = colors[m_dragIndex];
      }
      else {
        if (j == m_dragIndex) {
          ++j;
        }
        if (j < int(colors.size()))
          color = colors[j++];
        else
          color = app::Color::fromMask();
      }

      draw_color(g, box, color,
                 (doc::ColorMode)app_get_current_pixel_format());

      if (m_hotIndex == i)
        hotBounds = box;
    }

    if (!hotBounds.isEmpty() &&
        isHotEntryVisible()) {
      hotBounds.enlarge(3*ui::guiscale());

      ui::PaintWidgetPartInfo info;
      theme->paintWidgetPart(
        g, theme->styles.shadeSelection(), hotBounds, info);
    }
  }
  else {
    g->fillRect(theme->colors.editorFace(), bounds);
    g->drawAlignedUIText(text(), theme->colors.face(), gfx::ColorNone, bounds,
                         ui::CENTER | ui::MIDDLE);
  }
}
void ColorTintShadeTone::onPaint(ui::PaintEvent& ev)
{
    ui::Graphics* g = ev.graphics();
    SkinTheme* theme = static_cast<SkinTheme*>(this->theme());

    theme->drawRect(g, clientBounds(),
                    theme->parts.editorNormal().get(),
                    bgColor());

    gfx::Rect rc = clientChildrenBounds();
    if (rc.isEmpty())
        return;

    double hue = m_color.getHue();
    int umax, vmax;
    int huebar = getHueBarSize();
    umax = MAX(1, rc.w-1);
    vmax = MAX(1, rc.h-1-huebar);

    for (int y=0; y<rc.h-huebar; ++y) {
        for (int x=0; x<rc.w; ++x) {
            double sat = (100.0 * x / umax);
            double val = (100.0 - 100.0 * y / vmax);

            gfx::Color color = color_utils::color_for_ui(
                                   app::Color::fromHsv(
                                       hue,
                                       MID(0.0, sat, 100.0),
                                       MID(0.0, val, 100.0)));

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

    if (huebar > 0) {
        for (int y=rc.h-huebar; y<rc.h; ++y) {
            for (int x=0; x<rc.w; ++x) {
                gfx::Color color = color_utils::color_for_ui(
                                       app::Color::fromHsv(
                                           (360.0 * x / rc.w), 100.0, 100.0));

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

    if (m_color.getType() != app::Color::MaskType) {
        double sat = m_color.getSaturation();
        double val = m_color.getValue();
        gfx::Point pos(rc.x + int(sat * rc.w / 100.0),
                       rc.y + int((100.0-val) * (rc.h-huebar) / 100.0));

        she::Surface* icon = theme->parts.colorWheelIndicator()->bitmap(0);
        g->drawColoredRgbaSurface(
            icon,
            val > 50.0 ? gfx::rgba(0, 0, 0): gfx::rgba(255, 255, 255),
            pos.x-icon->width()/2,
            pos.y-icon->height()/2);

        if (huebar > 0) {
            pos.x = rc.x + int(rc.w * hue / 360.0);
            pos.y = rc.y + rc.h - huebar/2;
            g->drawColoredRgbaSurface(
                icon,
                gfx::rgba(0, 0, 0),
                pos.x-icon->width()/2,
                pos.y-icon->height()/2);
        }
    }
}