当前位置: 首页>>代码示例>>C++>>正文


C++ PaintEvent::graphics方法代码示例

本文整理汇总了C++中ui::PaintEvent::graphics方法的典型用法代码示例。如果您正苦于以下问题:C++ PaintEvent::graphics方法的具体用法?C++ PaintEvent::graphics怎么用?C++ PaintEvent::graphics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ui::PaintEvent的用法示例。


在下文中一共展示了PaintEvent::graphics方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: onPaint

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);
  }
}
开发者ID:Doraenmon,项目名称:aseprite,代码行数:60,代码来源:color_spectrum.cpp

示例2: onPaint

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));
    }
  }
}
开发者ID:sliekasirdis79,项目名称:aseprite,代码行数:55,代码来源:color_wheel.cpp

示例3: onPaint

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);
  }
}
开发者ID:imeteora,项目名称:aseprite,代码行数:20,代码来源:search_entry.cpp

示例4: onPaint

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);
    }
  }
}
开发者ID:pseudogames,项目名称:aseprite,代码行数:52,代码来源:color_curve_editor.cpp

示例5: onPaint

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);
  }
}
开发者ID:webbie1887,项目名称:aseprite,代码行数:63,代码来源:color_shades.cpp

示例6: onPaint

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);
        }
    }
}
开发者ID:Censacrof,项目名称:aseprite,代码行数:70,代码来源:color_tint_shade_tone.cpp


注:本文中的ui::PaintEvent::graphics方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。