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.
|
|
|
|
*/
|
2018-03-14 17:01:17 +00:00
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
#include "Sample.h"
|
2013-09-06 14:16:12 +00:00
|
|
|
#include "SkBlurMask.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkGradientShader.h"
|
|
|
|
#include "SkGraphics.h"
|
2018-03-14 17:01:17 +00:00
|
|
|
#include "SkMaskFilter.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SkPath.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkRegion.h"
|
|
|
|
#include "SkShader.h"
|
2018-08-21 15:45:46 +00:00
|
|
|
#include "SkUTF.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SkColorPriv.h"
|
|
|
|
#include "SkColorFilter.h"
|
|
|
|
#include "SkTime.h"
|
|
|
|
#include "SkTypeface.h"
|
|
|
|
|
|
|
|
#include "SkOSFile.h"
|
|
|
|
#include "SkStream.h"
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
class TextAlphaView : public Sample {
|
2012-08-23 18:19:56 +00:00
|
|
|
public:
|
|
|
|
TextAlphaView() {
|
2008-12-17 15:59:43 +00:00
|
|
|
fByte = 0xFF;
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
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, "TextAlpha");
|
2008-12-17 15:59:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onQuery(evt);
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDrawContent(SkCanvas* canvas) override {
|
2008-12-17 15:59:43 +00:00
|
|
|
const char* str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
|
|
SkPaint paint;
|
|
|
|
SkScalar x = SkIntToScalar(10);
|
|
|
|
SkScalar y = SkIntToScalar(20);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
paint.setFlags(0x105);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
paint.setARGB(fByte, 0xFF, 0xFF, 0xFF);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2018-03-14 17:01:17 +00:00
|
|
|
paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle,
|
2016-04-04 17:02:58 +00:00
|
|
|
SkBlurMask::ConvertRadiusToSigma(3)));
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
for (int ps = 6; ps <= 35; ps++) {
|
|
|
|
paint.setColor(rand.nextU() | (0xFF << 24));
|
|
|
|
paint.setTextSize(SkIntToScalar(ps));
|
|
|
|
paint.setTextSize(SkIntToScalar(24));
|
2017-04-28 19:35:12 +00:00
|
|
|
canvas->drawString(str, x, y, paint);
|
2015-08-27 14:41:13 +00:00
|
|
|
y += paint.getFontMetrics(nullptr);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned) override {
|
2008-12-17 15:59:43 +00:00
|
|
|
return new Click(this);
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool onClick(Click* click) override {
|
2008-12-17 15:59:43 +00:00
|
|
|
int y = click->fICurr.fY;
|
|
|
|
if (y < 0) {
|
|
|
|
y = 0;
|
|
|
|
} else if (y > 255) {
|
|
|
|
y = 255;
|
|
|
|
}
|
|
|
|
fByte = y;
|
|
|
|
return true;
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
private:
|
|
|
|
int fByte;
|
|
|
|
|
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 TextAlphaView(); )
|