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-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkColorFilter.h"
|
|
|
|
#include "include/core/SkColorPriv.h"
|
|
|
|
#include "include/core/SkColorPriv.h"
|
|
|
|
#include "include/core/SkGraphics.h"
|
|
|
|
#include "include/core/SkPath.h"
|
|
|
|
#include "include/core/SkRegion.h"
|
|
|
|
#include "include/core/SkShader.h"
|
|
|
|
#include "include/core/SkStream.h"
|
|
|
|
#include "include/core/SkTime.h"
|
|
|
|
#include "include/core/SkTypeface.h"
|
|
|
|
#include "include/effects/SkCornerPathEffect.h"
|
|
|
|
#include "include/effects/SkGradientShader.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
|
|
|
#include "samplecode/DecodeFile.h"
|
|
|
|
#include "samplecode/Sample.h"
|
|
|
|
#include "src/utils/SkUTF.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
class LinesView : public Sample {
|
2008-12-17 15:59:43 +00:00
|
|
|
public:
|
2012-08-23 18:19:56 +00:00
|
|
|
LinesView() {}
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
protected:
|
2018-08-08 15:36:17 +00:00
|
|
|
bool onQuery(Sample::Event* evt) override {
|
|
|
|
if (Sample::TitleQ(*evt)) {
|
|
|
|
Sample::TitleR(evt, "Lines");
|
2008-12-17 15:59:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onQuery(evt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
0x1F * x + 0x1F * (32 - x)
|
|
|
|
*/
|
2011-05-05 14:03:48 +00:00
|
|
|
void drawRings(SkCanvas* canvas) {
|
2008-12-17 15:59:43 +00:00
|
|
|
canvas->scale(SkIntToScalar(1)/2, SkIntToScalar(1)/2);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
|
|
|
SkRect r;
|
2008-12-17 15:59:43 +00:00
|
|
|
SkScalar x = SkIntToScalar(10);
|
|
|
|
SkScalar y = SkIntToScalar(10);
|
|
|
|
r.set(x, y, x + SkIntToScalar(100), y + SkIntToScalar(100));
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
SkPaint paint;
|
2010-12-20 18:26:13 +00:00
|
|
|
// paint.setAntiAlias(true);
|
2008-12-17 15:59:43 +00:00
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(SkScalarHalf(SkIntToScalar(3)));
|
|
|
|
paint.setColor(0xFFFF8800);
|
2010-12-20 18:26:13 +00:00
|
|
|
// paint.setColor(0xFFFFFFFF);
|
2008-12-17 15:59:43 +00:00
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2015-07-13 13:18:39 +00:00
|
|
|
void onDrawContent(SkCanvas* canvas) override {
|
2008-12-17 15:59:43 +00:00
|
|
|
SkBitmap bm;
|
2016-03-18 22:48:49 +00:00
|
|
|
decode_file("/kill.gif", &bm);
|
2015-08-27 14:41:13 +00:00
|
|
|
canvas->drawBitmap(bm, 0, 0, nullptr);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
this->drawRings(canvas);
|
|
|
|
return;
|
|
|
|
|
|
|
|
SkPaint paint;
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
// fAlpha = 0x80;
|
|
|
|
paint.setColor(SK_ColorWHITE);
|
|
|
|
paint.setAlpha(fAlpha & 0xFF);
|
|
|
|
SkRect r;
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
SkScalar x = SkIntToScalar(10);
|
|
|
|
SkScalar y = SkIntToScalar(10);
|
|
|
|
r.set(x, y, x + SkIntToScalar(100), y + SkIntToScalar(100));
|
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
return;
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
paint.setColor(0xffffff00); // yellow
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(SkIntToScalar(2));
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
// y += SK_Scalar1/2;
|
|
|
|
|
|
|
|
canvas->drawLine(x, y, x + SkIntToScalar(90), y + SkIntToScalar(90), paint);
|
|
|
|
|
|
|
|
paint.setAntiAlias(true); // with anti-aliasing
|
|
|
|
y += SkIntToScalar(10);
|
|
|
|
canvas->drawLine(x, y, x + SkIntToScalar(90), y + SkIntToScalar(90), paint);
|
|
|
|
}
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned) override {
|
2013-12-17 19:22:07 +00:00
|
|
|
fAlpha = SkScalarRoundToInt(y);
|
2015-08-27 14:41:13 +00:00
|
|
|
return nullptr;
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
|
|
|
|
int fAlpha;
|
2018-08-08 15:36:17 +00:00
|
|
|
typedef Sample INHERITED;
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
DEF_SAMPLE( return new LinesView(); )
|