reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1 | #include "SampleCode.h" |
| 2 | #include "SkView.h" |
| 3 | #include "SkCanvas.h" |
| 4 | #include "Sk64.h" |
| 5 | #include "SkCornerPathEffect.h" |
| 6 | #include "SkGradientShader.h" |
| 7 | #include "SkGraphics.h" |
| 8 | #include "SkImageDecoder.h" |
| 9 | #include "SkKernel33MaskFilter.h" |
| 10 | #include "SkPath.h" |
| 11 | #include "SkRandom.h" |
| 12 | #include "SkRegion.h" |
| 13 | #include "SkShader.h" |
| 14 | #include "SkUtils.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 15 | #include "SkColorPriv.h" |
| 16 | #include "SkColorFilter.h" |
| 17 | #include "SkTime.h" |
| 18 | #include "SkTypeface.h" |
| 19 | #include "SkXfermode.h" |
| 20 | |
| 21 | #include "SkStream.h" |
| 22 | #include "SkXMLParser.h" |
| 23 | #include "SkColorPriv.h" |
| 24 | #include "SkImageDecoder.h" |
| 25 | |
| 26 | class LinesView : public SkView { |
| 27 | public: |
| 28 | LinesView() |
| 29 | { |
| 30 | unsigned r = 0x1F; |
| 31 | unsigned g = 0x3F; |
| 32 | for (unsigned a = 0; a <= 0xF; a++) { |
| 33 | unsigned scale = 16 - SkAlpha15To16(a); |
| 34 | unsigned sr = (a << 1) | (a >> 3); |
| 35 | unsigned dr = r * scale >> 4; |
| 36 | unsigned sg = (a << 2) | (a >> 2); |
| 37 | unsigned dg = g * scale >> 4; |
| 38 | |
| 39 | unsigned ssg = sg & ~(~(a >> 3) & 1); |
| 40 | |
| 41 | printf("4444 sa=%d sr=%d sg=%d da=%d dr=%d dg=%d total-r=%d total-g=%d %d\n", |
| 42 | a, sr, sg, scale, dr, dg, sr+dr, sg+dg, ssg+dg); |
| 43 | } |
| 44 | |
| 45 | for (unsigned aa = 0; aa <= 0xFF; aa++) { |
| 46 | unsigned invScale = SkAlpha255To256(255 - aa); |
| 47 | unsigned dst = SkAlphaMul(0xFF, invScale); |
| 48 | printf("8888 sa=%02x dst=%02x sum=%d %s\n", aa, dst, aa+dst, |
| 49 | (aa+dst) > 0xFF ? "OVERFLOW" : ""); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | protected: |
| 54 | // overrides from SkEventSink |
| 55 | virtual bool onQuery(SkEvent* evt) |
| 56 | { |
| 57 | if (SampleCode::TitleQ(*evt)) |
| 58 | { |
| 59 | SampleCode::TitleR(evt, "Lines"); |
| 60 | return true; |
| 61 | } |
| 62 | return this->INHERITED::onQuery(evt); |
| 63 | } |
| 64 | |
| 65 | void drawBG(SkCanvas* canvas) |
| 66 | { |
| 67 | // canvas->drawColor(0xFFDDDDDD); |
| 68 | canvas->drawColor(SK_ColorWHITE); |
| 69 | // canvas->drawColor(SK_ColorBLACK); |
| 70 | } |
| 71 | |
| 72 | /* |
| 73 | 0x1F * x + 0x1F * (32 - x) |
| 74 | */ |
| 75 | void drawRings(SkCanvas* canvas) |
| 76 | { |
| 77 | canvas->scale(SkIntToScalar(1)/2, SkIntToScalar(1)/2); |
| 78 | |
| 79 | SkRect r; |
| 80 | SkScalar x = SkIntToScalar(10); |
| 81 | SkScalar y = SkIntToScalar(10); |
| 82 | r.set(x, y, x + SkIntToScalar(100), y + SkIntToScalar(100)); |
| 83 | |
| 84 | SkPaint paint; |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 85 | // paint.setAntiAlias(true); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 86 | paint.setStyle(SkPaint::kStroke_Style); |
| 87 | paint.setStrokeWidth(SkScalarHalf(SkIntToScalar(3))); |
| 88 | paint.setColor(0xFFFF8800); |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 89 | // paint.setColor(0xFFFFFFFF); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 90 | canvas->drawRect(r, paint); |
| 91 | } |
| 92 | |
| 93 | virtual void onDraw(SkCanvas* canvas) |
| 94 | { |
| 95 | this->drawBG(canvas); |
| 96 | |
| 97 | SkBitmap bm; |
| 98 | SkImageDecoder::DecodeFile("/kill.gif", &bm); |
| 99 | canvas->drawBitmap(bm, 0, 0, NULL); |
| 100 | |
| 101 | this->drawRings(canvas); |
| 102 | return; |
| 103 | |
| 104 | SkPaint paint; |
| 105 | |
| 106 | // fAlpha = 0x80; |
| 107 | paint.setColor(SK_ColorWHITE); |
| 108 | paint.setAlpha(fAlpha & 0xFF); |
| 109 | SkRect r; |
| 110 | |
| 111 | SkScalar x = SkIntToScalar(10); |
| 112 | SkScalar y = SkIntToScalar(10); |
| 113 | r.set(x, y, x + SkIntToScalar(100), y + SkIntToScalar(100)); |
| 114 | canvas->drawRect(r, paint); |
| 115 | return; |
| 116 | |
| 117 | paint.setColor(0xffffff00); // yellow |
| 118 | paint.setStyle(SkPaint::kStroke_Style); |
| 119 | paint.setStrokeWidth(SkIntToScalar(2)); |
| 120 | |
| 121 | // y += SK_Scalar1/2; |
| 122 | |
| 123 | canvas->drawLine(x, y, x + SkIntToScalar(90), y + SkIntToScalar(90), paint); |
| 124 | |
| 125 | paint.setAntiAlias(true); // with anti-aliasing |
| 126 | y += SkIntToScalar(10); |
| 127 | canvas->drawLine(x, y, x + SkIntToScalar(90), y + SkIntToScalar(90), paint); |
| 128 | } |
| 129 | |
| 130 | virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) |
| 131 | { |
| 132 | fAlpha = SkScalarRound(y); |
| 133 | this->inval(NULL); |
| 134 | return NULL; |
| 135 | } |
| 136 | private: |
| 137 | |
| 138 | int fAlpha; |
| 139 | typedef SkView INHERITED; |
| 140 | }; |
| 141 | |
| 142 | ////////////////////////////////////////////////////////////////////////////// |
| 143 | |
| 144 | static SkView* MyFactory() { return new LinesView; } |
| 145 | static SkViewRegister reg(MyFactory); |
| 146 | |