blob: c6f7ad98d93b42314d17f5e09dc28d0615f16548 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
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 */
reed@google.combf0001d2014-01-13 14:53:55 +00007
reed@android.com8a1c16f2008-12-17 15:59:43 +00008#include "SampleCode.h"
9#include "SkView.h"
10#include "SkCanvas.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000011#include "SkCornerPathEffect.h"
12#include "SkGradientShader.h"
13#include "SkGraphics.h"
14#include "SkImageDecoder.h"
15#include "SkKernel33MaskFilter.h"
16#include "SkPath.h"
17#include "SkRandom.h"
18#include "SkRegion.h"
19#include "SkShader.h"
20#include "SkUtils.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000021#include "SkColorPriv.h"
22#include "SkColorFilter.h"
23#include "SkTime.h"
24#include "SkTypeface.h"
25#include "SkXfermode.h"
26
27#include "SkStream.h"
28#include "SkXMLParser.h"
29#include "SkColorPriv.h"
30#include "SkImageDecoder.h"
31
reed@google.com961ddb02011-05-05 14:03:48 +000032class LinesView : public SampleView {
reed@android.com8a1c16f2008-12-17 15:59:43 +000033public:
rmistry@google.comae933ce2012-08-23 18:19:56 +000034 LinesView() {}
35
reed@android.com8a1c16f2008-12-17 15:59:43 +000036protected:
37 // overrides from SkEventSink
reed@google.com961ddb02011-05-05 14:03:48 +000038 virtual bool onQuery(SkEvent* evt) {
39 if (SampleCode::TitleQ(*evt)) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000040 SampleCode::TitleR(evt, "Lines");
41 return true;
42 }
43 return this->INHERITED::onQuery(evt);
44 }
45
reed@android.com8a1c16f2008-12-17 15:59:43 +000046 /*
47 0x1F * x + 0x1F * (32 - x)
48 */
reed@google.com961ddb02011-05-05 14:03:48 +000049 void drawRings(SkCanvas* canvas) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000050 canvas->scale(SkIntToScalar(1)/2, SkIntToScalar(1)/2);
rmistry@google.comae933ce2012-08-23 18:19:56 +000051
52 SkRect r;
reed@android.com8a1c16f2008-12-17 15:59:43 +000053 SkScalar x = SkIntToScalar(10);
54 SkScalar y = SkIntToScalar(10);
55 r.set(x, y, x + SkIntToScalar(100), y + SkIntToScalar(100));
rmistry@google.comae933ce2012-08-23 18:19:56 +000056
reed@android.com8a1c16f2008-12-17 15:59:43 +000057 SkPaint paint;
reed@android.comf2b98d62010-12-20 18:26:13 +000058 // paint.setAntiAlias(true);
reed@android.com8a1c16f2008-12-17 15:59:43 +000059 paint.setStyle(SkPaint::kStroke_Style);
60 paint.setStrokeWidth(SkScalarHalf(SkIntToScalar(3)));
61 paint.setColor(0xFFFF8800);
reed@android.comf2b98d62010-12-20 18:26:13 +000062 // paint.setColor(0xFFFFFFFF);
reed@android.com8a1c16f2008-12-17 15:59:43 +000063 canvas->drawRect(r, paint);
64 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000065
reed@google.com961ddb02011-05-05 14:03:48 +000066 virtual void onDrawContent(SkCanvas* canvas) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000067 SkBitmap bm;
68 SkImageDecoder::DecodeFile("/kill.gif", &bm);
69 canvas->drawBitmap(bm, 0, 0, NULL);
rmistry@google.comae933ce2012-08-23 18:19:56 +000070
reed@android.com8a1c16f2008-12-17 15:59:43 +000071 this->drawRings(canvas);
72 return;
73
74 SkPaint paint;
rmistry@google.comae933ce2012-08-23 18:19:56 +000075
reed@android.com8a1c16f2008-12-17 15:59:43 +000076 // fAlpha = 0x80;
77 paint.setColor(SK_ColorWHITE);
78 paint.setAlpha(fAlpha & 0xFF);
79 SkRect r;
rmistry@google.comae933ce2012-08-23 18:19:56 +000080
reed@android.com8a1c16f2008-12-17 15:59:43 +000081 SkScalar x = SkIntToScalar(10);
82 SkScalar y = SkIntToScalar(10);
83 r.set(x, y, x + SkIntToScalar(100), y + SkIntToScalar(100));
84 canvas->drawRect(r, paint);
85 return;
rmistry@google.comae933ce2012-08-23 18:19:56 +000086
reed@android.com8a1c16f2008-12-17 15:59:43 +000087 paint.setColor(0xffffff00); // yellow
88 paint.setStyle(SkPaint::kStroke_Style);
89 paint.setStrokeWidth(SkIntToScalar(2));
rmistry@google.comae933ce2012-08-23 18:19:56 +000090
reed@android.com8a1c16f2008-12-17 15:59:43 +000091// y += SK_Scalar1/2;
92
93 canvas->drawLine(x, y, x + SkIntToScalar(90), y + SkIntToScalar(90), paint);
94
95 paint.setAntiAlias(true); // with anti-aliasing
96 y += SkIntToScalar(10);
97 canvas->drawLine(x, y, x + SkIntToScalar(90), y + SkIntToScalar(90), paint);
98 }
99
sugoi@google.com9c55f802013-03-07 20:52:59 +0000100 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned) SK_OVERRIDE {
reed@google.come1ca7052013-12-17 19:22:07 +0000101 fAlpha = SkScalarRoundToInt(y);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000102 this->inval(NULL);
103 return NULL;
104 }
105private:
106
107 int fAlpha;
reed@google.com961ddb02011-05-05 14:03:48 +0000108 typedef SampleView INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000109};
110
111//////////////////////////////////////////////////////////////////////////////
112
113static SkView* MyFactory() { return new LinesView; }
114static SkViewRegister reg(MyFactory);