2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkShader.h"
|
|
|
|
#include "samplecode/Sample.h"
|
2011-04-25 12:43:45 +00:00
|
|
|
|
|
|
|
static SkBitmap createBitmap(int n) {
|
|
|
|
SkBitmap bitmap;
|
2014-02-17 02:55:57 +00:00
|
|
|
bitmap.allocN32Pixels(n, n);
|
2011-04-25 12:43:45 +00:00
|
|
|
bitmap.eraseColor(SK_ColorGREEN);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2011-04-25 12:43:45 +00:00
|
|
|
SkCanvas canvas(bitmap);
|
|
|
|
SkRect r;
|
2019-08-24 23:39:13 +00:00
|
|
|
r.setWH(SkIntToScalar(n), SkIntToScalar(n));
|
2011-04-25 12:43:45 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2011-04-25 12:43:45 +00:00
|
|
|
paint.setColor(SK_ColorRED);
|
|
|
|
canvas.drawOval(r, paint);
|
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
paint.setStrokeWidth(SkIntToScalar(n)/15);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
canvas.drawLine(0, 0, r.fRight, r.fBottom, paint);
|
|
|
|
canvas.drawLine(0, r.fBottom, r.fRight, 0, paint);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2011-04-25 12:43:45 +00:00
|
|
|
return bitmap;
|
|
|
|
}
|
|
|
|
|
2019-07-17 13:08:11 +00:00
|
|
|
static constexpr int N = 64;
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
class AARectView : public Sample {
|
2011-04-25 12:43:45 +00:00
|
|
|
SkBitmap fBitmap;
|
2018-04-10 13:16:41 +00:00
|
|
|
|
|
|
|
void onOnceBeforeDraw() override {
|
2017-12-19 14:18:59 +00:00
|
|
|
fBitmap = createBitmap(N);
|
2011-04-25 12:43:45 +00:00
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2019-07-03 14:55:44 +00:00
|
|
|
SkString name() override { return SkString("AA Rects"); }
|
2011-04-25 12:43:45 +00:00
|
|
|
|
2018-04-10 13:16:41 +00:00
|
|
|
void onDrawContent(SkCanvas* canvas) override {
|
2011-04-25 12:43:45 +00:00
|
|
|
canvas->translate(SkIntToScalar(10), SkIntToScalar(10));
|
|
|
|
|
|
|
|
SkPaint bluePaint;
|
|
|
|
bluePaint.setARGB(0xff, 0x0, 0x0, 0xff);
|
|
|
|
SkPaint bmpPaint;
|
2019-04-08 17:20:23 +00:00
|
|
|
bmpPaint.setShader(fBitmap.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat));
|
2011-04-25 12:43:45 +00:00
|
|
|
bluePaint.setStrokeWidth(3);
|
|
|
|
bmpPaint.setStrokeWidth(3);
|
|
|
|
|
|
|
|
SkPaint paints[] = { bluePaint, bmpPaint };
|
|
|
|
|
|
|
|
SkRect rect;
|
|
|
|
|
|
|
|
SkScalar dx = SkIntToScalar(80);
|
|
|
|
SkScalar dy = SkIntToScalar(100);
|
|
|
|
SkMatrix matrix;
|
2011-05-19 19:58:58 +00:00
|
|
|
for (size_t p = 0; p < SK_ARRAY_COUNT(paints); ++p) {
|
2011-04-25 12:43:45 +00:00
|
|
|
for (int stroke = 0; stroke < 2; ++stroke) {
|
|
|
|
paints[p].setStyle(stroke ? SkPaint::kStroke_Style : SkPaint::kFill_Style);
|
|
|
|
for (int a = 0; a < 3; ++ a) {
|
|
|
|
paints[p].setAntiAlias(a > 0);
|
|
|
|
paints[p].setAlpha(a > 1 ? 0x80 : 0xff);
|
|
|
|
|
|
|
|
canvas->save();
|
2013-11-25 19:44:07 +00:00
|
|
|
rect = SkRect::MakeLTRB(0.f,
|
|
|
|
0.f,
|
|
|
|
40.f,
|
|
|
|
40.f);
|
2011-04-25 12:43:45 +00:00
|
|
|
canvas->drawRect(rect, paints[p]);
|
|
|
|
canvas->translate(dx, 0);
|
|
|
|
|
2013-11-25 19:44:07 +00:00
|
|
|
rect = SkRect::MakeLTRB(0.5f,
|
|
|
|
0.5f,
|
|
|
|
40.5f,
|
|
|
|
40.5f);
|
2011-04-25 12:43:45 +00:00
|
|
|
canvas->drawRect(rect, paints[p]);
|
|
|
|
canvas->translate(dx, 0);
|
|
|
|
|
2013-11-25 19:44:07 +00:00
|
|
|
rect = SkRect::MakeLTRB(0.5f,
|
|
|
|
0.5f,
|
|
|
|
40.f,
|
|
|
|
40.f);
|
2011-04-25 12:43:45 +00:00
|
|
|
canvas->drawRect(rect, paints[p]);
|
|
|
|
canvas->translate(dx, 0);
|
|
|
|
|
2013-11-25 19:44:07 +00:00
|
|
|
rect = SkRect::MakeLTRB(0.75f,
|
|
|
|
0.75f,
|
|
|
|
40.75f,
|
|
|
|
40.75f);
|
2011-04-25 12:43:45 +00:00
|
|
|
canvas->drawRect(rect, paints[p]);
|
|
|
|
canvas->translate(dx, 0);
|
|
|
|
|
|
|
|
canvas->save();
|
2013-11-25 19:44:07 +00:00
|
|
|
canvas->translate(.33f, .67f);
|
|
|
|
rect = SkRect::MakeLTRB(0.0f,
|
|
|
|
0.0f,
|
|
|
|
40.0f,
|
|
|
|
40.0f);
|
2011-04-25 12:43:45 +00:00
|
|
|
canvas->drawRect(rect, paints[p]);
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(dx, 0);
|
|
|
|
|
|
|
|
canvas->save();
|
2013-11-25 19:44:07 +00:00
|
|
|
matrix.setRotate(45.f);
|
2011-04-25 12:43:45 +00:00
|
|
|
canvas->concat(matrix);
|
2013-11-25 19:44:07 +00:00
|
|
|
canvas->translate(20.0f / sqrtf(2.f),
|
|
|
|
20.0f / sqrtf(2.f));
|
|
|
|
rect = SkRect::MakeLTRB(-20.0f,
|
|
|
|
-20.0f,
|
|
|
|
20.0f,
|
|
|
|
20.0f);
|
2011-04-25 12:43:45 +00:00
|
|
|
canvas->drawRect(rect, paints[p]);
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(dx, 0);
|
|
|
|
|
|
|
|
canvas->save();
|
2013-11-25 19:44:07 +00:00
|
|
|
canvas->rotate(90.f);
|
|
|
|
rect = SkRect::MakeLTRB(0.0f,
|
|
|
|
0.0f,
|
|
|
|
40.0f,
|
|
|
|
-40.0f);
|
2011-04-25 12:43:45 +00:00
|
|
|
canvas->drawRect(rect, paints[p]);
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(dx, 0);
|
|
|
|
|
|
|
|
canvas->save();
|
2013-11-25 19:44:07 +00:00
|
|
|
canvas->rotate(90.f);
|
|
|
|
rect = SkRect::MakeLTRB(0.5f,
|
|
|
|
0.5f,
|
|
|
|
40.5f,
|
|
|
|
-40.5f);
|
2011-04-25 12:43:45 +00:00
|
|
|
canvas->drawRect(rect, paints[p]);
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(dx, 0);
|
|
|
|
|
|
|
|
canvas->save();
|
2013-11-25 19:44:07 +00:00
|
|
|
matrix.setScale(-1.f, -1.f);
|
2011-04-25 12:43:45 +00:00
|
|
|
canvas->concat(matrix);
|
2013-11-25 19:44:07 +00:00
|
|
|
rect = SkRect::MakeLTRB(0.5f,
|
|
|
|
0.5f,
|
|
|
|
-40.5f,
|
|
|
|
-40.5f);
|
2011-04-25 12:43:45 +00:00
|
|
|
canvas->drawRect(rect, paints[p]);
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(dx, 0);
|
|
|
|
|
|
|
|
canvas->save();
|
2013-11-25 19:44:07 +00:00
|
|
|
matrix.setScale(2.1f, 4.1f);
|
2011-04-25 12:43:45 +00:00
|
|
|
canvas->concat(matrix);
|
2013-11-25 19:44:07 +00:00
|
|
|
rect = SkRect::MakeLTRB(0.1f,
|
|
|
|
0.1f,
|
|
|
|
19.1f,
|
|
|
|
9.1f);
|
2011-04-25 12:43:45 +00:00
|
|
|
canvas->drawRect(rect, paints[p]);
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(dx, 0);
|
|
|
|
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(0, dy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2011-04-25 12:43:45 +00:00
|
|
|
private:
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
typedef Sample INHERITED;
|
2011-04-25 12:43:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
DEF_SAMPLE( return new AARectView(); )
|