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
8 #include "SampleCode.h"
9 #include "SkView.h"
10 #include "SkCanvas.h"
11 #include "SkCornerPathEffect.h"
12 #include "SkGradientShader.h"
13 #include "SkGraphics.h"
14 #include "SkImageDecoder.h"
15 #include "SkPath.h"
16 #include "SkRandom.h"
17 #include "SkRegion.h"
18 #include "SkShader.h"
19 #include "SkUtils.h"
20 #include "SkColorPriv.h"
21 #include "SkColorFilter.h"
22 #include "SkTime.h"
23 #include "SkTypeface.h"
24 #include "SkXfermode.h"
25
26 #include "SkStream.h"
27 #include "SkXMLParser.h"
28 #include "SkColorPriv.h"
29 #include "SkImageDecoder.h"
30
31 class LinesView : public SampleView {
32 public:
LinesView()33 LinesView() {}
34
35 protected:
36 // overrides from SkEventSink
onQuery(SkEvent * evt)37 bool onQuery(SkEvent* evt) override {
38 if (SampleCode::TitleQ(*evt)) {
39 SampleCode::TitleR(evt, "Lines");
40 return true;
41 }
42 return this->INHERITED::onQuery(evt);
43 }
44
45 /*
46 0x1F * x + 0x1F * (32 - x)
47 */
drawRings(SkCanvas * canvas)48 void drawRings(SkCanvas* canvas) {
49 canvas->scale(SkIntToScalar(1)/2, SkIntToScalar(1)/2);
50
51 SkRect r;
52 SkScalar x = SkIntToScalar(10);
53 SkScalar y = SkIntToScalar(10);
54 r.set(x, y, x + SkIntToScalar(100), y + SkIntToScalar(100));
55
56 SkPaint paint;
57 // paint.setAntiAlias(true);
58 paint.setStyle(SkPaint::kStroke_Style);
59 paint.setStrokeWidth(SkScalarHalf(SkIntToScalar(3)));
60 paint.setColor(0xFFFF8800);
61 // paint.setColor(0xFFFFFFFF);
62 canvas->drawRect(r, paint);
63 }
64
onDrawContent(SkCanvas * canvas)65 void onDrawContent(SkCanvas* canvas) override {
66 SkBitmap bm;
67 SkImageDecoder::DecodeFile("/kill.gif", &bm);
68 canvas->drawBitmap(bm, 0, 0, nullptr);
69
70 this->drawRings(canvas);
71 return;
72
73 SkPaint paint;
74
75 // fAlpha = 0x80;
76 paint.setColor(SK_ColorWHITE);
77 paint.setAlpha(fAlpha & 0xFF);
78 SkRect r;
79
80 SkScalar x = SkIntToScalar(10);
81 SkScalar y = SkIntToScalar(10);
82 r.set(x, y, x + SkIntToScalar(100), y + SkIntToScalar(100));
83 canvas->drawRect(r, paint);
84 return;
85
86 paint.setColor(0xffffff00); // yellow
87 paint.setStyle(SkPaint::kStroke_Style);
88 paint.setStrokeWidth(SkIntToScalar(2));
89
90 // y += SK_Scalar1/2;
91
92 canvas->drawLine(x, y, x + SkIntToScalar(90), y + SkIntToScalar(90), paint);
93
94 paint.setAntiAlias(true); // with anti-aliasing
95 y += SkIntToScalar(10);
96 canvas->drawLine(x, y, x + SkIntToScalar(90), y + SkIntToScalar(90), paint);
97 }
98
onFindClickHandler(SkScalar x,SkScalar y,unsigned)99 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned) override {
100 fAlpha = SkScalarRoundToInt(y);
101 this->inval(nullptr);
102 return nullptr;
103 }
104 private:
105
106 int fAlpha;
107 typedef SampleView INHERITED;
108 };
109
110 //////////////////////////////////////////////////////////////////////////////
111
MyFactory()112 static SkView* MyFactory() { return new LinesView; }
113 static SkViewRegister reg(MyFactory);
114