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.
|
|
|
|
*/
|
2014-01-13 14:53:55 +00:00
|
|
|
|
2019-03-20 16:55:08 +00:00
|
|
|
#include "AnimTimer.h"
|
2018-08-08 15:36:17 +00:00
|
|
|
#include "Sample.h"
|
2011-07-07 14:38:03 +00:00
|
|
|
#include "SkCanvas.h"
|
2019-01-03 17:59:14 +00:00
|
|
|
#include "SkFont.h"
|
2011-07-07 14:38:03 +00:00
|
|
|
#include "SkGradientShader.h"
|
2013-10-11 18:50:45 +00:00
|
|
|
#include "SkString.h"
|
2011-07-07 14:38:03 +00:00
|
|
|
|
|
|
|
static void draw_gradient2(SkCanvas* canvas, const SkRect& rect, SkScalar delta) {
|
|
|
|
SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorMAGENTA };
|
2013-11-25 19:44:07 +00:00
|
|
|
SkScalar pos[] = { 0, 0.25f, 0.75f, SK_Scalar1 };
|
2011-07-07 14:38:03 +00:00
|
|
|
|
|
|
|
SkScalar l = rect.fLeft;
|
|
|
|
SkScalar t = rect.fTop;
|
|
|
|
SkScalar w = rect.width();
|
|
|
|
SkScalar h = rect.height();
|
|
|
|
|
|
|
|
SkASSERT(0 == SkScalarMod(w, SK_Scalar1 * 5));
|
|
|
|
|
|
|
|
SkPoint c0 = { l + 2 * w / 5 + delta, t + h / 2 };
|
|
|
|
SkPoint c1 = { l + 3 * w / 5, t + h / 2 };
|
|
|
|
SkScalar r0 = w / 5;
|
|
|
|
SkScalar r1 = 2 * w / 5;
|
|
|
|
SkPaint paint;
|
2016-03-09 02:50:00 +00:00
|
|
|
paint.setShader(SkGradientShader::MakeTwoPointConical(c0, r0, c1, r1, colors,
|
|
|
|
pos, SK_ARRAY_COUNT(pos),
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode::kClamp));
|
2011-07-07 14:38:03 +00:00
|
|
|
canvas->drawRect(rect, paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
class DegenerateTwoPtRadialsView : public Sample {
|
2011-07-07 14:38:03 +00:00
|
|
|
public:
|
|
|
|
DegenerateTwoPtRadialsView() {
|
|
|
|
fTime = 0;
|
|
|
|
this->setBGColor(0xFFDDDDDD);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2018-08-08 15:36:17 +00:00
|
|
|
bool onQuery(Sample::Event* evt) override {
|
|
|
|
if (Sample::TitleQ(*evt)) {
|
|
|
|
Sample::TitleR(evt, "DegenerateTwoPtRadials");
|
2011-07-07 14:38:03 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onQuery(evt);
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDrawContent(SkCanvas* canvas) override {
|
2011-07-07 14:38:03 +00:00
|
|
|
SkScalar delta = fTime / 15.f;
|
2013-12-17 19:22:07 +00:00
|
|
|
int intPart = SkScalarFloorToInt(delta);
|
2011-07-07 14:38:03 +00:00
|
|
|
delta = delta - SK_Scalar1 * intPart;
|
|
|
|
if (intPart % 2) {
|
|
|
|
delta = SK_Scalar1 - delta;
|
|
|
|
}
|
|
|
|
delta -= SK_ScalarHalf;
|
|
|
|
static const int DELTA_SCALE = 500;
|
|
|
|
delta /= DELTA_SCALE;
|
|
|
|
|
|
|
|
SkScalar w = SK_Scalar1 * 500;
|
|
|
|
SkScalar h = SK_Scalar1 * 500;
|
|
|
|
SkScalar l = SK_Scalar1 * 100;
|
|
|
|
SkScalar t = SK_Scalar1 * 100;
|
|
|
|
draw_gradient2(canvas, SkRect::MakeXYWH(l, t, w, h), delta);
|
2013-10-11 18:50:45 +00:00
|
|
|
SkString txt;
|
|
|
|
txt.appendf("gap at \"tangent\" pt = %f", SkScalarToFloat(delta));
|
2019-01-07 14:36:09 +00:00
|
|
|
canvas->drawString(txt, l + w / 2 + w * DELTA_SCALE * delta, t + h + SK_Scalar1 * 10,
|
|
|
|
SkFont(), SkPaint());
|
2015-02-02 03:01:04 +00:00
|
|
|
}
|
|
|
|
|
2019-03-20 16:55:08 +00:00
|
|
|
bool onAnimate(const AnimTimer& timer) override {
|
2015-02-02 20:55:02 +00:00
|
|
|
fTime = SkDoubleToScalar(timer.secs() / 15);
|
2015-02-02 03:01:04 +00:00
|
|
|
return true;
|
2011-07-07 14:38:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkScalar fTime;
|
2018-08-08 15:36:17 +00:00
|
|
|
typedef Sample INHERITED;
|
2011-07-07 14:38:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
DEF_SAMPLE( return new DegenerateTwoPtRadialsView(); )
|