Exemplo n.º 1
0
void Spinner::Private::Draw(const Context &context) {
  angle += 5.f;
  if (angle > 360.f) angle = 0.f;

  Canvas *canvas = context.canvas();
  int scale = context.surface()->GetScale();
  canvas->Scale(scale, scale);

  const RectF &rect = proprietor()->GetBounds();
  float radius = base::Clamp(std::min(rect.width(), rect.height()) / 2.f - 50.f,
                             50.f, 200.f);

  Paint paint;
  paint.SetAntiAlias(true);

  paint.SetColor(background);
  paint.SetStyle(Paint::Style::kStyleFill);
  canvas->DrawRect(rect, paint);

  paint.SetColor(ColorF(foreground));
  paint.SetStyle(Paint::Style::kStyleStroke);
  paint.SetStrokeWidth(6.f);

  canvas->DrawArc(RectF(rect.center_x() - radius,
                        rect.center_y() - radius,
                        rect.center_x() + radius,
                        rect.center_y() + radius),
                  angle, 300.f, false, paint);

  frame_callback.Setup(context.surface());
}
Exemplo n.º 2
0
  virtual void OnDraw(const Context &context) override {
    using wiztk::graphic::Canvas;
    using wiztk::graphic::Paint;

    const RectF &rect = GetBounds();
    int scale = context.surface()->GetScale();

    Canvas *canvas = context.canvas();
    canvas->Save();
    canvas->Scale(scale, scale);

    Paint paint;
    paint.SetColor(ColorF(0.855f, 0.855f, 0.165f, .9f));
    canvas->DrawRect(rect, paint);

    canvas->Restore();

    SkCanvas *sk_canvas = canvas->GetSkCanvas();

    SkImageInfo info = SkImageInfo::MakeN32(400, 400, kPremul_SkAlphaType);
    sk_sp<SkSurface> surface = sk_canvas->makeSurface(info);

    SkCanvas *top_canvas = surface->getCanvas();
    SkRect top_rect = SkRect::MakeXYWH(50, 50, 100, 100);
    SkPaint top_paint;
    top_paint.setColor(0xFFFF0000);

    top_canvas->drawRect(top_rect, top_paint);
    top_canvas->flush();

    surface->draw(sk_canvas, 100, 100, nullptr);

    canvas->Flush();
  }