blob: b23af51b0d63ca31301b053e58904c3125b482a7 [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
38class TextAlphaView : public SkView {
39public:
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
55 void drawBG(SkCanvas* canvas) {
56 canvas->drawColor(SK_ColorWHITE);
57 }
58
59 virtual void onDraw(SkCanvas* canvas) {
60 this->drawBG(canvas);
61
62 const char* str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
63 SkPaint paint;
64 SkScalar x = SkIntToScalar(10);
65 SkScalar y = SkIntToScalar(20);
66
67 paint.setFlags(0x105);
68
69 paint.setARGB(fByte, 0xFF, 0xFF, 0xFF);
70
71 paint.setMaskFilter(SkBlurMaskFilter::Create(SkIntToScalar(3),
72 SkBlurMaskFilter::kNormal_BlurStyle));
73 paint.getMaskFilter()->unref();
74
75 SkRandom rand;
76
77 for (int ps = 6; ps <= 35; ps++) {
78 paint.setColor(rand.nextU() | (0xFF << 24));
79 paint.setTextSize(SkIntToScalar(ps));
80 paint.setTextSize(SkIntToScalar(24));
81 canvas->drawText(str, strlen(str), x, y, paint);
82 y += paint.getFontMetrics(NULL);
83 }
84 //check_for_nonwhite(canvas->getDevice()->accessBitmap(), fByte);
85 //SkDebugf("------ byte %x\n", fByte);
86
87 if (false) {
88 fByte += 1;
89 fByte &= 0xFF;
90 this->inval(NULL);
91 }
92 }
93
94 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) {
95 return new Click(this);
96 }
97
98 virtual bool onClick(Click* click) {
99 int y = click->fICurr.fY;
100 if (y < 0) {
101 y = 0;
102 } else if (y > 255) {
103 y = 255;
104 }
105 fByte = y;
106 this->inval(NULL);
107 return true;
108 }
109
110private:
111 int fByte;
112
113 typedef SkView INHERITED;
114};
115
116//////////////////////////////////////////////////////////////////////////////
117
118static SkView* MyFactory() { return new TextAlphaView; }
119static SkViewRegister reg(MyFactory);
120