skia2/gm/stringart.cpp
mtklein 72c9faab45 Fix up all the easy virtual ... SK_OVERRIDE cases.
This fixes every case where virtual and SK_OVERRIDE were on the same line,
which should be the bulk of cases.  We'll have to manually clean up the rest
over time unless I level up in regexes.

for f in (find . -type f); perl -p -i -e 's/virtual (.*)SK_OVERRIDE/\1SK_OVERRIDE/g' $f; end

BUG=skia:

Review URL: https://codereview.chromium.org/806653007
2015-01-09 10:06:40 -08:00

71 lines
1.8 KiB
C++

/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "gm.h"
#include "SkCanvas.h"
#include "SkPath.h"
// Reproduces https://code.google.com/p/chromium/issues/detail?id=279014
static const int kWidth = 640;
static const int kHeight = 480;
static const SkScalar kAngle = 0.305f;
// Renders a string art shape.
// The particular shape rendered can be controlled by adjusting kAngle, from 0 to 1
class StringArtGM : public skiagm::GM {
public:
StringArtGM() {}
protected:
uint32_t onGetFlags() const SK_OVERRIDE {
return kSkipTiled_Flag;
}
SkString onShortName() SK_OVERRIDE {
return SkString("stringart");
}
SkISize onISize() SK_OVERRIDE {
return SkISize::Make(kWidth, kHeight);
}
void onDraw(SkCanvas* canvas) SK_OVERRIDE {
SkScalar angle = kAngle*SK_ScalarPI + SkScalarHalf(SK_ScalarPI);
SkScalar size = SkIntToScalar(SkMin32(kWidth, kHeight));
SkPoint center = SkPoint::Make(SkScalarHalf(kWidth), SkScalarHalf(kHeight));
SkScalar length = 5;
SkScalar step = angle;
SkPath path;
path.moveTo(center);
while (length < (SkScalarHalf(size) - 10.f))
{
SkPoint rp = SkPoint::Make(length*SkScalarCos(step) + center.fX,
length*SkScalarSin(step) + center.fY);
path.lineTo(rp);
length += SkScalarDiv(angle, SkScalarHalf(SK_ScalarPI));
step += angle;
}
path.close();
SkPaint paint;
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kStroke_Style);
paint.setColor(0xFF007700);
canvas->drawPath(path, paint);
}
private:
typedef GM INHERITED;
};
DEF_GM( return new StringArtGM; )