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.
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SampleCode.h"
|
2013-09-06 14:16:12 +00:00
|
|
|
#include "SkBlurMask.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SkBlurMaskFilter.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkGradientShader.h"
|
|
|
|
#include "SkGraphics.h"
|
|
|
|
#include "SkPath.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkRegion.h"
|
|
|
|
#include "SkShader.h"
|
|
|
|
#include "SkUtils.h"
|
|
|
|
#include "SkColorPriv.h"
|
|
|
|
#include "SkColorFilter.h"
|
|
|
|
#include "SkTime.h"
|
|
|
|
#include "SkTypeface.h"
|
2013-09-06 14:16:12 +00:00
|
|
|
#include "SkView.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
#include "SkOSFile.h"
|
|
|
|
#include "SkStream.h"
|
|
|
|
|
2011-05-05 01:59:48 +00:00
|
|
|
class TextAlphaView : public SampleView {
|
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:
|
|
|
|
// overrides from SkEventSink
|
2015-03-26 01:17:31 +00:00
|
|
|
bool onQuery(SkEvent* evt) override {
|
2008-12-17 15:59:43 +00:00
|
|
|
if (SampleCode::TitleQ(*evt)) {
|
2012-09-30 11:30:01 +00:00
|
|
|
SampleCode::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
|
|
|
|
2016-04-04 17:02:58 +00:00
|
|
|
paint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle,
|
|
|
|
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
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkView::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;
|
|
|
|
|
2011-05-05 01:59:48 +00:00
|
|
|
typedef SampleView INHERITED;
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static SkView* MyFactory() { return new TextAlphaView; }
|
|
|
|
static SkViewRegister reg(MyFactory);
|