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.
|
|
|
|
*/
|
2018-08-08 15:36:17 +00:00
|
|
|
#include "Sample.h"
|
2018-01-23 16:24:08 +00:00
|
|
|
#include "SkBitmap.h"
|
2011-04-25 12:43:45 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkShader.h"
|
|
|
|
|
|
|
|
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;
|
|
|
|
r.set(0, 0, SkIntToScalar(n), SkIntToScalar(n));
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
class AARectView : public Sample {
|
2011-04-25 12:43:45 +00:00
|
|
|
SkBitmap fBitmap;
|
|
|
|
enum {
|
|
|
|
N = 64
|
|
|
|
};
|
2018-04-10 13:16:41 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void onOnceBeforeDraw() override {
|
2017-12-19 14:18:59 +00:00
|
|
|
fBitmap = createBitmap(N);
|
2017-12-19 20:20:13 +00:00
|
|
|
|
2011-04-25 12:43:45 +00:00
|
|
|
fWidth = N;
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
bool onQuery(Sample::Event* evt) override {
|
|
|
|
if (Sample::TitleQ(*evt)) {
|
|
|
|
Sample::TitleR(evt, "AA Rects");
|
2011-04-25 12:43:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onQuery(evt);
|
|
|
|
}
|
|
|
|
|
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:
|
|
|
|
int fWidth;
|
|
|
|
|
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(); )
|