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"
|
|
|
|
|
|
|
|
static void check_for_nonwhite(const SkBitmap& bm, int alpha) {
|
|
|
|
if (bm.config() != SkBitmap::kRGB_565_Config) {
|
|
|
|
return;
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
for (int y = 0; y < bm.height(); y++) {
|
|
|
|
for (int x = 0; x < bm.width(); x++) {
|
|
|
|
uint16_t c = *bm.getAddr16(x, y);
|
|
|
|
if (c != 0xFFFF) {
|
|
|
|
SkDebugf("------ nonwhite alpha=%x [%d %d] %x\n", alpha, x, y, c);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
virtual bool onQuery(SkEvent* evt) {
|
|
|
|
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
|
|
|
|
2011-05-05 01:59:48 +00:00
|
|
|
virtual void onDrawContent(SkCanvas* canvas) {
|
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
|
|
|
|
2013-09-06 14:16:12 +00:00
|
|
|
paint.setMaskFilter(SkBlurMaskFilter::Create(SkBlurMaskFilter::kNormal_BlurStyle,
|
|
|
|
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-06-06 12:09:51 +00:00
|
|
|
if (false) { // avoid bit rot, suppress warning
|
|
|
|
check_for_nonwhite(canvas->getDevice()->accessBitmap(false), fByte);
|
|
|
|
SkDebugf("------ byte %x\n", fByte);
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
if (false) {
|
|
|
|
fByte += 1;
|
|
|
|
fByte &= 0xFF;
|
|
|
|
this->inval(NULL);
|
|
|
|
}
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2013-03-07 20:52:59 +00:00
|
|
|
virtual 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
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
virtual bool onClick(Click* click) {
|
|
|
|
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);
|