blob: 03dd30feed6a3c0d6d254fb862b6e2e484092da1 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001#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.com8a1c16f2008-12-17 15:59:43 +000015#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
reed@google.com961ddb02011-05-05 14:03:48 +000026class LinesView : public SampleView {
reed@android.com8a1c16f2008-12-17 15:59:43 +000027public:
reed@google.com2f3dc9d2011-05-02 17:33:45 +000028 LinesView() {}
reed@android.com8a1c16f2008-12-17 15:59:43 +000029
30protected:
31 // overrides from SkEventSink
reed@google.com961ddb02011-05-05 14:03:48 +000032 virtual bool onQuery(SkEvent* evt) {
33 if (SampleCode::TitleQ(*evt)) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000034 SampleCode::TitleR(evt, "Lines");
35 return true;
36 }
37 return this->INHERITED::onQuery(evt);
38 }
39
reed@android.com8a1c16f2008-12-17 15:59:43 +000040 /*
41 0x1F * x + 0x1F * (32 - x)
42 */
reed@google.com961ddb02011-05-05 14:03:48 +000043 void drawRings(SkCanvas* canvas) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000044 canvas->scale(SkIntToScalar(1)/2, SkIntToScalar(1)/2);
45
46 SkRect r;
47 SkScalar x = SkIntToScalar(10);
48 SkScalar y = SkIntToScalar(10);
49 r.set(x, y, x + SkIntToScalar(100), y + SkIntToScalar(100));
50
51 SkPaint paint;
reed@android.comf2b98d62010-12-20 18:26:13 +000052 // paint.setAntiAlias(true);
reed@android.com8a1c16f2008-12-17 15:59:43 +000053 paint.setStyle(SkPaint::kStroke_Style);
54 paint.setStrokeWidth(SkScalarHalf(SkIntToScalar(3)));
55 paint.setColor(0xFFFF8800);
reed@android.comf2b98d62010-12-20 18:26:13 +000056 // paint.setColor(0xFFFFFFFF);
reed@android.com8a1c16f2008-12-17 15:59:43 +000057 canvas->drawRect(r, paint);
58 }
59
reed@google.com961ddb02011-05-05 14:03:48 +000060 virtual void onDrawContent(SkCanvas* canvas) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000061 SkBitmap bm;
62 SkImageDecoder::DecodeFile("/kill.gif", &bm);
63 canvas->drawBitmap(bm, 0, 0, NULL);
64
65 this->drawRings(canvas);
66 return;
67
68 SkPaint paint;
69
70 // fAlpha = 0x80;
71 paint.setColor(SK_ColorWHITE);
72 paint.setAlpha(fAlpha & 0xFF);
73 SkRect r;
74
75 SkScalar x = SkIntToScalar(10);
76 SkScalar y = SkIntToScalar(10);
77 r.set(x, y, x + SkIntToScalar(100), y + SkIntToScalar(100));
78 canvas->drawRect(r, paint);
79 return;
80
81 paint.setColor(0xffffff00); // yellow
82 paint.setStyle(SkPaint::kStroke_Style);
83 paint.setStrokeWidth(SkIntToScalar(2));
84
85// y += SK_Scalar1/2;
86
87 canvas->drawLine(x, y, x + SkIntToScalar(90), y + SkIntToScalar(90), paint);
88
89 paint.setAntiAlias(true); // with anti-aliasing
90 y += SkIntToScalar(10);
91 canvas->drawLine(x, y, x + SkIntToScalar(90), y + SkIntToScalar(90), paint);
92 }
93
reed@google.com961ddb02011-05-05 14:03:48 +000094 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000095 fAlpha = SkScalarRound(y);
96 this->inval(NULL);
97 return NULL;
98 }
99private:
100
101 int fAlpha;
reed@google.com961ddb02011-05-05 14:03:48 +0000102 typedef SampleView INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000103};
104
105//////////////////////////////////////////////////////////////////////////////
106
107static SkView* MyFactory() { return new LinesView; }
108static SkViewRegister reg(MyFactory);
109