2011-07-28 18:26:00 +04: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.
|
|
|
|
*/
|
2008-12-17 18:59:43 +03:00
|
|
|
#include "SampleCode.h"
|
|
|
|
#include "SkView.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkGradientShader.h"
|
|
|
|
#include "SkPath.h"
|
|
|
|
#include "SkRegion.h"
|
|
|
|
#include "SkShader.h"
|
|
|
|
#include "SkUtils.h"
|
2008-12-19 22:15:15 +03:00
|
|
|
#include "SkComposeShader.h"
|
2008-12-17 18:59:43 +03:00
|
|
|
#include "Sk1DPathEffect.h"
|
|
|
|
#include "SkCornerPathEffect.h"
|
|
|
|
#include "SkPathMeasure.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkColorPriv.h"
|
|
|
|
#include "SkColorFilter.h"
|
|
|
|
#include "SkLayerRasterizer.h"
|
|
|
|
|
2009-06-05 20:21:03 +04:00
|
|
|
#include "SkParsePath.h"
|
|
|
|
static void testparse() {
|
|
|
|
SkRect r;
|
2012-06-06 16:09:51 +04:00
|
|
|
r.set(0, 0, SkFloatToScalar(10), SkFloatToScalar(10.5f));
|
2009-06-05 20:21:03 +04:00
|
|
|
SkPath p, p2;
|
|
|
|
SkString str, str2;
|
|
|
|
|
|
|
|
p.addRect(r);
|
|
|
|
SkParsePath::ToSVGString(p, &str);
|
|
|
|
SkParsePath::FromSVGString(str.c_str(), &p2);
|
|
|
|
SkParsePath::ToSVGString(p2, &str2);
|
|
|
|
}
|
|
|
|
|
2011-05-05 18:03:48 +04:00
|
|
|
class ArcsView : public SampleView {
|
2008-12-17 18:59:43 +03:00
|
|
|
public:
|
2011-05-05 18:03:48 +04:00
|
|
|
ArcsView() {
|
2009-06-05 20:21:03 +04:00
|
|
|
testparse();
|
2008-12-17 18:59:43 +03:00
|
|
|
fSweep = SkIntToScalar(100);
|
2011-05-05 18:03:48 +04:00
|
|
|
this->setBGColor(0xFFDDDDDD);
|
2008-12-17 18:59:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// overrides from SkEventSink
|
2011-05-05 18:03:48 +04:00
|
|
|
virtual bool onQuery(SkEvent* evt) {
|
|
|
|
if (SampleCode::TitleQ(*evt)) {
|
2008-12-17 18:59:43 +03:00
|
|
|
SampleCode::TitleR(evt, "Arcs");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onQuery(evt);
|
|
|
|
}
|
|
|
|
|
2011-05-05 18:03:48 +04:00
|
|
|
static void drawRectWithLines(SkCanvas* canvas, const SkRect& r, const SkPaint& p) {
|
2008-12-17 18:59:43 +03:00
|
|
|
canvas->drawRect(r, p);
|
|
|
|
canvas->drawLine(r.fLeft, r.fTop, r.fRight, r.fBottom, p);
|
|
|
|
canvas->drawLine(r.fLeft, r.fBottom, r.fRight, r.fTop, p);
|
|
|
|
canvas->drawLine(r.fLeft, r.centerY(), r.fRight, r.centerY(), p);
|
|
|
|
canvas->drawLine(r.centerX(), r.fTop, r.centerX(), r.fBottom, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_label(SkCanvas* canvas, const SkRect& rect,
|
2011-05-05 18:03:48 +04:00
|
|
|
int start, int sweep) {
|
2008-12-17 18:59:43 +03:00
|
|
|
SkPaint paint;
|
|
|
|
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setTextAlign(SkPaint::kCenter_Align);
|
|
|
|
|
|
|
|
SkString str;
|
|
|
|
|
|
|
|
str.appendS32(start);
|
|
|
|
str.append(", ");
|
|
|
|
str.appendS32(sweep);
|
|
|
|
canvas->drawText(str.c_str(), str.size(), rect.centerX(),
|
|
|
|
rect.fBottom + paint.getTextSize() * 5/4, paint);
|
|
|
|
}
|
|
|
|
|
2011-05-05 18:03:48 +04:00
|
|
|
static void drawArcs(SkCanvas* canvas) {
|
2008-12-17 18:59:43 +03:00
|
|
|
SkPaint paint;
|
|
|
|
SkRect r;
|
|
|
|
SkScalar w = SkIntToScalar(75);
|
|
|
|
SkScalar h = SkIntToScalar(50);
|
|
|
|
|
|
|
|
r.set(0, 0, w, h);
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(SkIntToScalar(10), SkIntToScalar(300));
|
|
|
|
|
|
|
|
paint.setStrokeWidth(SkIntToScalar(1));
|
|
|
|
|
|
|
|
static const int gAngles[] = {
|
|
|
|
0, 360,
|
|
|
|
0, 45,
|
|
|
|
0, -45,
|
|
|
|
720, 135,
|
|
|
|
-90, 269,
|
|
|
|
-90, 270,
|
|
|
|
-90, 271,
|
|
|
|
-180, -270,
|
|
|
|
225, 90
|
|
|
|
};
|
|
|
|
|
2011-05-19 23:58:58 +04:00
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gAngles); i += 2) {
|
2008-12-17 18:59:43 +03:00
|
|
|
paint.setColor(SK_ColorBLACK);
|
|
|
|
drawRectWithLines(canvas, r, paint);
|
|
|
|
|
|
|
|
paint.setColor(SK_ColorRED);
|
|
|
|
canvas->drawArc(r, SkIntToScalar(gAngles[i]),
|
|
|
|
SkIntToScalar(gAngles[i+1]), false, paint);
|
|
|
|
|
|
|
|
draw_label(canvas, r, gAngles[i], gAngles[i+1]);
|
|
|
|
|
|
|
|
canvas->translate(w * 8 / 7, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
|
2011-05-05 18:03:48 +04:00
|
|
|
virtual void onDrawContent(SkCanvas* canvas) {
|
2009-11-24 00:07:51 +03:00
|
|
|
fSweep = SampleCode::GetAnimScalar(SkIntToScalar(360)/24,
|
|
|
|
SkIntToScalar(360));
|
2010-04-22 20:07:49 +04:00
|
|
|
// fSweep = SkFloatToScalar(359.99f);
|
2008-12-17 18:59:43 +03:00
|
|
|
|
|
|
|
SkRect r;
|
|
|
|
SkPaint paint;
|
|
|
|
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setStrokeWidth(SkIntToScalar(2));
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
|
|
|
|
r.set(0, 0, SkIntToScalar(200), SkIntToScalar(200));
|
|
|
|
r.offset(SkIntToScalar(20), SkIntToScalar(20));
|
|
|
|
|
|
|
|
if (false) {
|
|
|
|
const SkScalar d = SkIntToScalar(3);
|
|
|
|
const SkScalar rad[] = { d, d, d, d, d, d, d, d };
|
|
|
|
SkPath path;
|
|
|
|
path.addRoundRect(r, rad);
|
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
drawRectWithLines(canvas, r, paint);
|
|
|
|
|
|
|
|
// printf("----- sweep %g %X\n", SkScalarToFloat(fSweep), SkDegreesToRadians(fSweep));
|
|
|
|
|
|
|
|
|
|
|
|
paint.setStyle(SkPaint::kFill_Style);
|
|
|
|
paint.setColor(0x800000FF);
|
|
|
|
canvas->drawArc(r, 0, fSweep, true, paint);
|
|
|
|
|
|
|
|
paint.setColor(0x800FF000);
|
|
|
|
canvas->drawArc(r, 0, fSweep, false, paint);
|
|
|
|
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setColor(SK_ColorRED);
|
|
|
|
canvas->drawArc(r, 0, fSweep, true, paint);
|
|
|
|
|
|
|
|
paint.setStrokeWidth(0);
|
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
canvas->drawArc(r, 0, fSweep, false, paint);
|
|
|
|
|
|
|
|
drawArcs(canvas);
|
|
|
|
this->inval(NULL);
|
|
|
|
}
|
|
|
|
|
2011-05-05 18:03:48 +04:00
|
|
|
virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) {
|
2008-12-17 18:59:43 +03:00
|
|
|
// fSweep += SK_Scalar1;
|
|
|
|
this->inval(NULL);
|
|
|
|
return this->INHERITED::onFindClickHandler(x, y);
|
|
|
|
}
|
|
|
|
|
2011-05-05 18:03:48 +04:00
|
|
|
virtual bool onClick(Click* click) {
|
2008-12-17 18:59:43 +03:00
|
|
|
return this->INHERITED::onClick(click);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkScalar fSweep;
|
|
|
|
|
2011-05-05 18:03:48 +04:00
|
|
|
typedef SampleView INHERITED;
|
2008-12-17 18:59:43 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static SkView* MyFactory() { return new ArcsView; }
|
|
|
|
static SkViewRegister reg(MyFactory);
|
|
|
|
|