blob: 8286177ae7a92c09cb113c5e26b032e75a3ec56b [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00007#include "SampleCode.h"
robertphillips@google.comb7061172013-09-06 14:16:12 +00008#include "SkBlurMask.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +00009#include "SkBlurMaskFilter.h"
10#include "SkCanvas.h"
11#include "SkGradientShader.h"
12#include "SkGraphics.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000013#include "SkPath.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000014#include "SkRandom.h"
15#include "SkRegion.h"
16#include "SkShader.h"
17#include "SkUtils.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000018#include "SkColorPriv.h"
19#include "SkColorFilter.h"
20#include "SkTime.h"
21#include "SkTypeface.h"
robertphillips@google.comb7061172013-09-06 14:16:12 +000022#include "SkView.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000023
reed@android.com8a1c16f2008-12-17 15:59:43 +000024#include "SkOSFile.h"
25#include "SkStream.h"
26
mike@reedtribe.org5fd92432011-05-05 01:59:48 +000027class TextAlphaView : public SampleView {
rmistry@google.comae933ce2012-08-23 18:19:56 +000028public:
29 TextAlphaView() {
reed@android.com8a1c16f2008-12-17 15:59:43 +000030 fByte = 0xFF;
31 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000032
reed@android.com8a1c16f2008-12-17 15:59:43 +000033protected:
34 // overrides from SkEventSink
mtklein36352bf2015-03-25 18:17:31 -070035 bool onQuery(SkEvent* evt) override {
reed@android.com8a1c16f2008-12-17 15:59:43 +000036 if (SampleCode::TitleQ(*evt)) {
tfarina@chromium.org45369a32012-09-30 11:30:01 +000037 SampleCode::TitleR(evt, "TextAlpha");
reed@android.com8a1c16f2008-12-17 15:59:43 +000038 return true;
39 }
40 return this->INHERITED::onQuery(evt);
41 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000042
mtklein36352bf2015-03-25 18:17:31 -070043 void onDrawContent(SkCanvas* canvas) override {
reed@android.com8a1c16f2008-12-17 15:59:43 +000044 const char* str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
45 SkPaint paint;
46 SkScalar x = SkIntToScalar(10);
47 SkScalar y = SkIntToScalar(20);
rmistry@google.comae933ce2012-08-23 18:19:56 +000048
reed@android.com8a1c16f2008-12-17 15:59:43 +000049 paint.setFlags(0x105);
rmistry@google.comae933ce2012-08-23 18:19:56 +000050
reed@android.com8a1c16f2008-12-17 15:59:43 +000051 paint.setARGB(fByte, 0xFF, 0xFF, 0xFF);
rmistry@google.comae933ce2012-08-23 18:19:56 +000052
reedefdfd512016-04-04 10:02:58 -070053 paint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle,
54 SkBlurMask::ConvertRadiusToSigma(3)));
rmistry@google.comae933ce2012-08-23 18:19:56 +000055
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +000056 SkRandom rand;
rmistry@google.comae933ce2012-08-23 18:19:56 +000057
reed@android.com8a1c16f2008-12-17 15:59:43 +000058 for (int ps = 6; ps <= 35; ps++) {
59 paint.setColor(rand.nextU() | (0xFF << 24));
60 paint.setTextSize(SkIntToScalar(ps));
61 paint.setTextSize(SkIntToScalar(24));
62 canvas->drawText(str, strlen(str), x, y, paint);
halcanary96fcdcc2015-08-27 07:41:13 -070063 y += paint.getFontMetrics(nullptr);
reed@android.com8a1c16f2008-12-17 15:59:43 +000064 }
reed@android.com8a1c16f2008-12-17 15:59:43 +000065 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000066
mtklein36352bf2015-03-25 18:17:31 -070067 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned) override {
reed@android.com8a1c16f2008-12-17 15:59:43 +000068 return new Click(this);
69 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000070
mtklein36352bf2015-03-25 18:17:31 -070071 bool onClick(Click* click) override {
reed@android.com8a1c16f2008-12-17 15:59:43 +000072 int y = click->fICurr.fY;
73 if (y < 0) {
74 y = 0;
75 } else if (y > 255) {
76 y = 255;
77 }
78 fByte = y;
halcanary96fcdcc2015-08-27 07:41:13 -070079 this->inval(nullptr);
reed@android.com8a1c16f2008-12-17 15:59:43 +000080 return true;
81 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000082
reed@android.com8a1c16f2008-12-17 15:59:43 +000083private:
84 int fByte;
85
mike@reedtribe.org5fd92432011-05-05 01:59:48 +000086 typedef SampleView INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +000087};
88
89//////////////////////////////////////////////////////////////////////////////
90
91static SkView* MyFactory() { return new TextAlphaView; }
92static SkViewRegister reg(MyFactory);