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"
|
2012-06-06 12:09:51 +00:00
|
|
|
#include "SkDevice.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SkGradientShader.h"
|
|
|
|
#include "SkGraphics.h"
|
|
|
|
#include "SkImageDecoder.h"
|
|
|
|
#include "SkPath.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkRegion.h"
|
|
|
|
#include "SkShader.h"
|
|
|
|
#include "SkUtils.h"
|
|
|
|
#include "SkXfermode.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-01-09 18:06:39 +00:00
|
|
|
bool onQuery(SkEvent* evt) SK_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-01-09 18:06:39 +00:00
|
|
|
void onDrawContent(SkCanvas* canvas) SK_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
|
|
|
|
2014-04-28 16:25:35 +00:00
|
|
|
paint.setMaskFilter(SkBlurMaskFilter::Create(kNormal_SkBlurStyle,
|
2013-09-06 14:16:12 +00:00
|
|
|
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(3))));
|
2008-12-17 15:59:43 +00:00
|
|
|
paint.getMaskFilter()->unref();
|
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));
|
|
|
|
canvas->drawText(str, strlen(str), x, y, paint);
|
|
|
|
y += paint.getFontMetrics(NULL);
|
|
|
|
}
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2015-01-09 18:06:39 +00:00
|
|
|
SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned) SK_OVERRIDE {
|
2008-12-17 15:59:43 +00:00
|
|
|
return new Click(this);
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2015-01-09 18:06:39 +00:00
|
|
|
bool onClick(Click* click) SK_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;
|
|
|
|
this->inval(NULL);
|
|
|
|
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);
|