2013-05-14 16:37:31 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 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 "gm/gm.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
2013-05-14 16:37:31 +00:00
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
// Draw various width thin rects at 1/8 horizontal pixel increments
|
|
|
|
class ThinRectsGM : public GM {
|
|
|
|
public:
|
|
|
|
ThinRectsGM() {
|
|
|
|
this->setBGColor(0xFF000000);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2013-05-14 16:37:31 +00:00
|
|
|
return SkString("thinrects");
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2014-06-10 06:59:03 +00:00
|
|
|
return SkISize::Make(240, 320);
|
2013-05-14 16:37:31 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2013-05-14 16:37:31 +00:00
|
|
|
|
|
|
|
SkPaint white;
|
|
|
|
white.setColor(SK_ColorWHITE);
|
|
|
|
white.setAntiAlias(true);
|
|
|
|
|
|
|
|
SkPaint green;
|
|
|
|
green.setColor(SK_ColorGREEN);
|
|
|
|
green.setAntiAlias(true);
|
|
|
|
|
|
|
|
for (int i = 0; i < 8; ++i) {
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(i*0.125f, i*40.0f);
|
|
|
|
DrawVertRects(canvas, white);
|
|
|
|
|
|
|
|
canvas->translate(40.0f, 0.0f);
|
|
|
|
DrawVertRects(canvas, green);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(80.0f, i*40.0f + i*0.125f);
|
|
|
|
DrawHorizRects(canvas, white);
|
|
|
|
|
|
|
|
canvas->translate(40.0f, 0.0f);
|
|
|
|
DrawHorizRects(canvas, green);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
canvas->save();
|
2013-05-15 07:01:09 +00:00
|
|
|
canvas->translate(160.0f + i*0.125f,
|
2013-05-14 16:37:31 +00:00
|
|
|
i*40.0f + i*0.125f);
|
|
|
|
DrawSquares(canvas, white);
|
|
|
|
|
|
|
|
canvas->translate(40.0f, 0.0f);
|
|
|
|
DrawSquares(canvas, green);
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static void DrawVertRects(SkCanvas* canvas, const SkPaint& p) {
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr SkRect vertRects[] = {
|
2013-05-14 16:37:31 +00:00
|
|
|
{ 1, 1, 5.0f, 21 }, // 4 pix wide
|
|
|
|
{ 8, 1, 10.0f, 21 }, // 2 pix wide
|
|
|
|
{ 13, 1, 14.0f, 21 }, // 1 pix wide
|
|
|
|
{ 17, 1, 17.5f, 21 }, // 1/2 pix wide
|
|
|
|
{ 21, 1, 21.25f, 21 }, // 1/4 pix wide
|
|
|
|
{ 25, 1, 25.125f, 21 }, // 1/8 pix wide
|
|
|
|
{ 29, 1, 29.0f, 21 } // 0 pix wide
|
|
|
|
};
|
|
|
|
|
2013-05-14 16:43:02 +00:00
|
|
|
for (size_t j = 0; j < SK_ARRAY_COUNT(vertRects); ++j) {
|
2013-05-14 16:37:31 +00:00
|
|
|
canvas->drawRect(vertRects[j], p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DrawHorizRects(SkCanvas* canvas, const SkPaint& p) {
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr SkRect horizRects[] = {
|
2013-05-14 16:37:31 +00:00
|
|
|
{ 1, 1, 21, 5.0f }, // 4 pix high
|
|
|
|
{ 1, 8, 21, 10.0f }, // 2 pix high
|
|
|
|
{ 1, 13, 21, 14.0f }, // 1 pix high
|
|
|
|
{ 1, 17, 21, 17.5f }, // 1/2 pix high
|
|
|
|
{ 1, 21, 21, 21.25f }, // 1/4 pix high
|
|
|
|
{ 1, 25, 21, 25.125f }, // 1/8 pix high
|
|
|
|
{ 1, 29, 21, 29.0f } // 0 pix high
|
|
|
|
};
|
|
|
|
|
2013-05-14 16:43:02 +00:00
|
|
|
for (size_t j = 0; j < SK_ARRAY_COUNT(horizRects); ++j) {
|
2013-05-14 16:37:31 +00:00
|
|
|
canvas->drawRect(horizRects[j], p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DrawSquares(SkCanvas* canvas, const SkPaint& p) {
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr SkRect squares[] = {
|
2013-05-14 16:37:31 +00:00
|
|
|
{ 1, 1, 5.0f, 5.0f }, // 4 pix
|
|
|
|
{ 8, 8, 10.0f, 10.0f }, // 2 pix
|
|
|
|
{ 13, 13, 14.0f, 14.0f }, // 1 pix
|
|
|
|
{ 17, 17, 17.5f, 17.5f }, // 1/2 pix
|
|
|
|
{ 21, 21, 21.25f, 21.25f }, // 1/4 pix
|
|
|
|
{ 25, 25, 25.125f, 25.125f }, // 1/8 pix
|
|
|
|
{ 29, 29, 29.0f, 29.0f } // 0 pix
|
|
|
|
};
|
|
|
|
|
2013-05-14 16:43:02 +00:00
|
|
|
for (size_t j = 0; j < SK_ARRAY_COUNT(squares); ++j) {
|
2013-05-14 16:37:31 +00:00
|
|
|
canvas->drawRect(squares[j], p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = GM;
|
2013-05-14 16:37:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-01-23 15:22:01 +00:00
|
|
|
DEF_GM( return new ThinRectsGM; )
|
2013-05-14 16:37:31 +00:00
|
|
|
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace skiagm
|