blob: ccfed68e6d54d6ff0f2ad34efb09faecb75f3659 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001#include "SampleCode.h"
2#include "SkView.h"
3#include "SkBlurMaskFilter.h"
4#include "SkCanvas.h"
5#include "SkGradientShader.h"
6#include "SkGraphics.h"
7#include "SkImageDecoder.h"
8#include "SkPath.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +00009#include "SkRandom.h"
10#include "SkRegion.h"
11#include "SkShader.h"
12#include "SkUtils.h"
13#include "SkXfermode.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000014#include "SkColorPriv.h"
15#include "SkColorFilter.h"
16#include "SkTime.h"
17#include "SkTypeface.h"
18
reed@android.com8a1c16f2008-12-17 15:59:43 +000019#include "SkOSFile.h"
20#include "SkStream.h"
21
22static void check_for_nonwhite(const SkBitmap& bm, int alpha) {
23 if (bm.config() != SkBitmap::kRGB_565_Config) {
24 return;
25 }
26
27 for (int y = 0; y < bm.height(); y++) {
28 for (int x = 0; x < bm.width(); x++) {
29 uint16_t c = *bm.getAddr16(x, y);
30 if (c != 0xFFFF) {
31 SkDebugf("------ nonwhite alpha=%x [%d %d] %x\n", alpha, x, y, c);
32 return;
33 }
34 }
35 }
36}
37
mike@reedtribe.org5fd92432011-05-05 01:59:48 +000038class TextAlphaView : public SampleView {
reed@android.com8a1c16f2008-12-17 15:59:43 +000039public:
40 TextAlphaView() {
41 fByte = 0xFF;
42 }
43
44protected:
45 // overrides from SkEventSink
46 virtual bool onQuery(SkEvent* evt) {
47 if (SampleCode::TitleQ(*evt)) {
48 SkString str("TextAlpha");
49 SampleCode::TitleR(evt, str.c_str());
50 return true;
51 }
52 return this->INHERITED::onQuery(evt);
53 }
54
mike@reedtribe.org5fd92432011-05-05 01:59:48 +000055 virtual void onDrawContent(SkCanvas* canvas) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000056 const char* str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
57 SkPaint paint;
58 SkScalar x = SkIntToScalar(10);
59 SkScalar y = SkIntToScalar(20);
60
61 paint.setFlags(0x105);
62
63 paint.setARGB(fByte, 0xFF, 0xFF, 0xFF);
64
65 paint.setMaskFilter(SkBlurMaskFilter::Create(SkIntToScalar(3),
66 SkBlurMaskFilter::kNormal_BlurStyle));
67 paint.getMaskFilter()->unref();
68
69 SkRandom rand;
70
71 for (int ps = 6; ps <= 35; ps++) {
72 paint.setColor(rand.nextU() | (0xFF << 24));
73 paint.setTextSize(SkIntToScalar(ps));
74 paint.setTextSize(SkIntToScalar(24));
75 canvas->drawText(str, strlen(str), x, y, paint);
76 y += paint.getFontMetrics(NULL);
77 }
78 //check_for_nonwhite(canvas->getDevice()->accessBitmap(), fByte);
79 //SkDebugf("------ byte %x\n", fByte);
80
81 if (false) {
82 fByte += 1;
83 fByte &= 0xFF;
84 this->inval(NULL);
85 }
86 }
87
88 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) {
89 return new Click(this);
90 }
91
92 virtual bool onClick(Click* click) {
93 int y = click->fICurr.fY;
94 if (y < 0) {
95 y = 0;
96 } else if (y > 255) {
97 y = 255;
98 }
99 fByte = y;
100 this->inval(NULL);
101 return true;
102 }
103
104private:
105 int fByte;
106
mike@reedtribe.org5fd92432011-05-05 01:59:48 +0000107 typedef SampleView INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000108};
109
110//////////////////////////////////////////////////////////////////////////////
111
112static SkView* MyFactory() { return new TextAlphaView; }
113static SkViewRegister reg(MyFactory);
114