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