b2c4ea6219
What is left of the SkView system is used only by samples or viewer. As a result, move it out of the Skia source tree and re-organize so it is a bit easier to understand and use more shared code. Move samplecode/ClockFaceView.cpp to samplecode/SampleTextEffects.cpp, sice that's what's actually in it. Move SkAnimTimer.h to tools/timer, since it's actually shared between gm and samples. Change-Id: I55dafd94c64e4f930ddbd19168e0f812af86c455 Reviewed-on: https://skia-review.googlesource.com/146161 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Ben Wagner <bungeman@google.com>
72 lines
2.0 KiB
C++
72 lines
2.0 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 "Sample.h"
|
|
#include "SkCanvas.h"
|
|
#include "SkPath.h"
|
|
|
|
// Reproduces https://code.google.com/p/chromium/issues/detail?id=279014
|
|
|
|
// Renders a string art shape.
|
|
// The particular shape rendered can be controlled by clicking horizontally, thereby
|
|
// generating an angle from 0 to 1.
|
|
|
|
class StringArtView : public Sample {
|
|
public:
|
|
StringArtView() : fAngle(0.305f) {}
|
|
|
|
protected:
|
|
bool onQuery(Sample::Event* evt) override {
|
|
if (Sample::TitleQ(*evt)) {
|
|
Sample::TitleR(evt, "StringArt");
|
|
return true;
|
|
}
|
|
return this->INHERITED::onQuery(evt);
|
|
}
|
|
|
|
void onDrawContent(SkCanvas* canvas) override {
|
|
SkScalar angle = fAngle*SK_ScalarPI + SkScalarHalf(SK_ScalarPI);
|
|
|
|
SkPoint center = SkPoint::Make(SkScalarHalf(this->width()), SkScalarHalf(this->height()));
|
|
SkScalar length = 5;
|
|
SkScalar step = angle;
|
|
|
|
SkPath path;
|
|
path.moveTo(center);
|
|
|
|
while (length < (SkScalarHalf(SkMinScalar(this->width(), this->height())) - 10.f))
|
|
{
|
|
SkPoint rp = SkPoint::Make(length*SkScalarCos(step) + center.fX,
|
|
length*SkScalarSin(step) + center.fY);
|
|
path.lineTo(rp);
|
|
length += 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);
|
|
}
|
|
|
|
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned) override {
|
|
fAngle = x/width();
|
|
return nullptr;
|
|
}
|
|
private:
|
|
|
|
SkScalar fAngle;
|
|
typedef Sample INHERITED;
|
|
};
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
DEF_SAMPLE( return new StringArtView(); )
|