blob: 6e2e950669f968e2327339f26be56c59100b655d [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00008#include "SampleCode.h"
robertphillips@google.comb7061172013-09-06 14:16:12 +00009#include "SkBlurMask.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000010#include "SkBlurMaskFilter.h"
11#include "SkCanvas.h"
caryclark@google.com02939ce2012-06-06 12:09:51 +000012#include "SkDevice.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000013#include "SkGradientShader.h"
14#include "SkGraphics.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000015#include "SkPath.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000016#include "SkRandom.h"
17#include "SkRegion.h"
18#include "SkShader.h"
19#include "SkUtils.h"
20#include "SkXfermode.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000021#include "SkColorPriv.h"
22#include "SkColorFilter.h"
23#include "SkTime.h"
24#include "SkTypeface.h"
robertphillips@google.comb7061172013-09-06 14:16:12 +000025#include "SkView.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000026
reed@android.com8a1c16f2008-12-17 15:59:43 +000027#include "SkOSFile.h"
28#include "SkStream.h"
29
mike@reedtribe.org5fd92432011-05-05 01:59:48 +000030class TextAlphaView : public SampleView {
rmistry@google.comae933ce2012-08-23 18:19:56 +000031public:
32 TextAlphaView() {
reed@android.com8a1c16f2008-12-17 15:59:43 +000033 fByte = 0xFF;
34 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000035
reed@android.com8a1c16f2008-12-17 15:59:43 +000036protected:
37 // overrides from SkEventSink
mtklein36352bf2015-03-25 18:17:31 -070038 bool onQuery(SkEvent* evt) override {
reed@android.com8a1c16f2008-12-17 15:59:43 +000039 if (SampleCode::TitleQ(*evt)) {
tfarina@chromium.org45369a32012-09-30 11:30:01 +000040 SampleCode::TitleR(evt, "TextAlpha");
reed@android.com8a1c16f2008-12-17 15:59:43 +000041 return true;
42 }
43 return this->INHERITED::onQuery(evt);
44 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000045
mtklein36352bf2015-03-25 18:17:31 -070046 void onDrawContent(SkCanvas* canvas) override {
reed@android.com8a1c16f2008-12-17 15:59:43 +000047 const char* str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
48 SkPaint paint;
49 SkScalar x = SkIntToScalar(10);
50 SkScalar y = SkIntToScalar(20);
rmistry@google.comae933ce2012-08-23 18:19:56 +000051
reed@android.com8a1c16f2008-12-17 15:59:43 +000052 paint.setFlags(0x105);
rmistry@google.comae933ce2012-08-23 18:19:56 +000053
reed@android.com8a1c16f2008-12-17 15:59:43 +000054 paint.setARGB(fByte, 0xFF, 0xFF, 0xFF);
rmistry@google.comae933ce2012-08-23 18:19:56 +000055
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000056 paint.setMaskFilter(SkBlurMaskFilter::Create(kNormal_SkBlurStyle,
robertphillips@google.comb7061172013-09-06 14:16:12 +000057 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(3))));
reed@android.com8a1c16f2008-12-17 15:59:43 +000058 paint.getMaskFilter()->unref();
rmistry@google.comae933ce2012-08-23 18:19:56 +000059
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +000060 SkRandom rand;
rmistry@google.comae933ce2012-08-23 18:19:56 +000061
reed@android.com8a1c16f2008-12-17 15:59:43 +000062 for (int ps = 6; ps <= 35; ps++) {
63 paint.setColor(rand.nextU() | (0xFF << 24));
64 paint.setTextSize(SkIntToScalar(ps));
65 paint.setTextSize(SkIntToScalar(24));
66 canvas->drawText(str, strlen(str), x, y, paint);
halcanary96fcdcc2015-08-27 07:41:13 -070067 y += paint.getFontMetrics(nullptr);
reed@android.com8a1c16f2008-12-17 15:59:43 +000068 }
reed@android.com8a1c16f2008-12-17 15:59:43 +000069 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000070
mtklein36352bf2015-03-25 18:17:31 -070071 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned) override {
reed@android.com8a1c16f2008-12-17 15:59:43 +000072 return new Click(this);
73 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000074
mtklein36352bf2015-03-25 18:17:31 -070075 bool onClick(Click* click) override {
reed@android.com8a1c16f2008-12-17 15:59:43 +000076 int y = click->fICurr.fY;
77 if (y < 0) {
78 y = 0;
79 } else if (y > 255) {
80 y = 255;
81 }
82 fByte = y;
halcanary96fcdcc2015-08-27 07:41:13 -070083 this->inval(nullptr);
reed@android.com8a1c16f2008-12-17 15:59:43 +000084 return true;
85 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000086
reed@android.com8a1c16f2008-12-17 15:59:43 +000087private:
88 int fByte;
89
mike@reedtribe.org5fd92432011-05-05 01:59:48 +000090 typedef SampleView INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +000091};
92
93//////////////////////////////////////////////////////////////////////////////
94
95static SkView* MyFactory() { return new TextAlphaView; }
96static SkViewRegister reg(MyFactory);