epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 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.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 8 | #include "SampleCode.h" |
| 9 | #include "SkView.h" |
| 10 | #include "SkBlurMaskFilter.h" |
| 11 | #include "SkCanvas.h" |
| 12 | #include "SkGradientShader.h" |
| 13 | #include "SkGraphics.h" |
| 14 | #include "SkImageDecoder.h" |
| 15 | #include "SkPath.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 16 | #include "SkRandom.h" |
| 17 | #include "SkRegion.h" |
| 18 | #include "SkShader.h" |
| 19 | #include "SkUtils.h" |
| 20 | #include "SkXfermode.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 21 | #include "SkColorPriv.h" |
| 22 | #include "SkColorFilter.h" |
| 23 | #include "SkTime.h" |
| 24 | #include "SkTypeface.h" |
| 25 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 26 | #include "SkOSFile.h" |
| 27 | #include "SkStream.h" |
| 28 | |
| 29 | static void check_for_nonwhite(const SkBitmap& bm, int alpha) { |
| 30 | if (bm.config() != SkBitmap::kRGB_565_Config) { |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | for (int y = 0; y < bm.height(); y++) { |
| 35 | for (int x = 0; x < bm.width(); x++) { |
| 36 | uint16_t c = *bm.getAddr16(x, y); |
| 37 | if (c != 0xFFFF) { |
| 38 | SkDebugf("------ nonwhite alpha=%x [%d %d] %x\n", alpha, x, y, c); |
| 39 | return; |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | |
mike@reedtribe.org | 5fd9243 | 2011-05-05 01:59:48 +0000 | [diff] [blame] | 45 | class TextAlphaView : public SampleView { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 46 | public: |
| 47 | TextAlphaView() { |
| 48 | fByte = 0xFF; |
| 49 | } |
| 50 | |
| 51 | protected: |
| 52 | // overrides from SkEventSink |
| 53 | virtual bool onQuery(SkEvent* evt) { |
| 54 | if (SampleCode::TitleQ(*evt)) { |
| 55 | SkString str("TextAlpha"); |
| 56 | SampleCode::TitleR(evt, str.c_str()); |
| 57 | return true; |
| 58 | } |
| 59 | return this->INHERITED::onQuery(evt); |
| 60 | } |
| 61 | |
mike@reedtribe.org | 5fd9243 | 2011-05-05 01:59:48 +0000 | [diff] [blame] | 62 | virtual void onDrawContent(SkCanvas* canvas) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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 | |
| 111 | private: |
| 112 | int fByte; |
| 113 | |
mike@reedtribe.org | 5fd9243 | 2011-05-05 01:59:48 +0000 | [diff] [blame] | 114 | typedef SampleView INHERITED; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | ////////////////////////////////////////////////////////////////////////////// |
| 118 | |
| 119 | static SkView* MyFactory() { return new TextAlphaView; } |
| 120 | static SkViewRegister reg(MyFactory); |
| 121 | |