1 /* 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 */ 7 #include "SampleCode.h" 8 #include "SkBlurMask.h" 9 #include "SkBlurMaskFilter.h" 10 #include "SkCanvas.h" 11 #include "SkGradientShader.h" 12 #include "SkGraphics.h" 13 #include "SkPath.h" 14 #include "SkRandom.h" 15 #include "SkRegion.h" 16 #include "SkShader.h" 17 #include "SkUtils.h" 18 #include "SkColorPriv.h" 19 #include "SkColorFilter.h" 20 #include "SkTime.h" 21 #include "SkTypeface.h" 22 #include "SkView.h" 23 24 #include "SkOSFile.h" 25 #include "SkStream.h" 26 27 class TextAlphaView : public SampleView { 28 public: 29 TextAlphaView() { 30 fByte = 0xFF; 31 } 32 33 protected: 34 // overrides from SkEventSink 35 bool onQuery(SkEvent* evt) override { 36 if (SampleCode::TitleQ(*evt)) { 37 SampleCode::TitleR(evt, "TextAlpha"); 38 return true; 39 } 40 return this->INHERITED::onQuery(evt); 41 } 42 43 void onDrawContent(SkCanvas* canvas) override { 44 const char* str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 45 SkPaint paint; 46 SkScalar x = SkIntToScalar(10); 47 SkScalar y = SkIntToScalar(20); 48 49 paint.setFlags(0x105); 50 51 paint.setARGB(fByte, 0xFF, 0xFF, 0xFF); 52 53 paint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, 54 SkBlurMask::ConvertRadiusToSigma(3))); 55 56 SkRandom rand; 57 58 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->drawString(str, x, y, paint); 63 y += paint.getFontMetrics(nullptr); 64 } 65 } 66 67 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned) override { 68 return new Click(this); 69 } 70 71 bool onClick(Click* click) override { 72 int y = click->fICurr.fY; 73 if (y < 0) { 74 y = 0; 75 } else if (y > 255) { 76 y = 255; 77 } 78 fByte = y; 79 this->inval(nullptr); 80 return true; 81 } 82 83 private: 84 int fByte; 85 86 typedef SampleView INHERITED; 87 }; 88 89 ////////////////////////////////////////////////////////////////////////////// 90 91 static SkView* MyFactory() { return new TextAlphaView; } 92 static SkViewRegister reg(MyFactory); 93