2013-06-26 17:06:45 +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/SkScalar.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
2013-06-26 17:06:45 +00:00
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
// Draw rects with various stroke widths at 1/8 pixel increments
|
|
|
|
class ThinStrokedRectsGM : public GM {
|
|
|
|
public:
|
|
|
|
ThinStrokedRectsGM() {
|
|
|
|
this->setBGColor(0xFF000000);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2013-06-26 17:06:45 +00:00
|
|
|
return SkString("thinstrokedrects");
|
|
|
|
}
|
|
|
|
|
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-06-26 17:06:45 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2013-06-26 17:06:45 +00:00
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(SK_ColorWHITE);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr SkRect rect = { 0, 0, 10, 10 };
|
|
|
|
constexpr SkRect rect2 = { 0, 0, 20, 20 };
|
2013-06-26 17:06:45 +00:00
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr SkScalar gStrokeWidths[] = {
|
2013-06-26 17:06:45 +00:00
|
|
|
4, 2, 1, 0.5f, 0.25f, 0.125f, 0
|
|
|
|
};
|
|
|
|
|
|
|
|
canvas->translate(5, 5);
|
|
|
|
for (int i = 0; i < 8; ++i) {
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(i*0.125f, i*30.0f);
|
|
|
|
for (size_t j = 0; j < SK_ARRAY_COUNT(gStrokeWidths); ++j) {
|
|
|
|
paint.setStrokeWidth(gStrokeWidths[j]);
|
|
|
|
canvas->drawRect(rect, paint);
|
|
|
|
canvas->translate(15, 0);
|
|
|
|
}
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw a second time in red with a scale
|
|
|
|
paint.setColor(SK_ColorRED);
|
|
|
|
canvas->translate(0, 15);
|
|
|
|
for (int i = 0; i < 8; ++i) {
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(i*0.125f, i*30.0f);
|
|
|
|
canvas->scale(0.5f, 0.5f);
|
|
|
|
for (size_t j = 0; j < SK_ARRAY_COUNT(gStrokeWidths); ++j) {
|
|
|
|
paint.setStrokeWidth(2.0f * gStrokeWidths[j]);
|
|
|
|
canvas->drawRect(rect2, paint);
|
|
|
|
canvas->translate(30, 0);
|
|
|
|
}
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_GM(return new ThinStrokedRectsGM;)
|
2013-06-26 17:06:45 +00:00
|
|
|
}
|