blob: 08a9e86c4b1b8bbb915f8437d9aa1a9c6abf7e9c [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
msarettd15750c2016-03-18 15:48:49 -07008#include "DecodeFile.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +00009#include "SampleCode.h"
10#include "SkView.h"
11#include "SkCanvas.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000012#include "SkCornerPathEffect.h"
13#include "SkGradientShader.h"
14#include "SkGraphics.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000015#include "SkPath.h"
16#include "SkRandom.h"
17#include "SkRegion.h"
18#include "SkShader.h"
19#include "SkUtils.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000020#include "SkColorPriv.h"
21#include "SkColorFilter.h"
22#include "SkTime.h"
23#include "SkTypeface.h"
24#include "SkXfermode.h"
25
26#include "SkStream.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000027#include "SkColorPriv.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000028
reed@google.com961ddb02011-05-05 14:03:48 +000029class LinesView : public SampleView {
reed@android.com8a1c16f2008-12-17 15:59:43 +000030public:
rmistry@google.comae933ce2012-08-23 18:19:56 +000031 LinesView() {}
32
reed@android.com8a1c16f2008-12-17 15:59:43 +000033protected:
34 // overrides from SkEventSink
mtkleinf0599002015-07-13 06:18:39 -070035 bool onQuery(SkEvent* evt) override {
reed@google.com961ddb02011-05-05 14:03:48 +000036 if (SampleCode::TitleQ(*evt)) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000037 SampleCode::TitleR(evt, "Lines");
38 return true;
39 }
40 return this->INHERITED::onQuery(evt);
41 }
42
reed@android.com8a1c16f2008-12-17 15:59:43 +000043 /*
44 0x1F * x + 0x1F * (32 - x)
45 */
reed@google.com961ddb02011-05-05 14:03:48 +000046 void drawRings(SkCanvas* canvas) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000047 canvas->scale(SkIntToScalar(1)/2, SkIntToScalar(1)/2);
rmistry@google.comae933ce2012-08-23 18:19:56 +000048
49 SkRect r;
reed@android.com8a1c16f2008-12-17 15:59:43 +000050 SkScalar x = SkIntToScalar(10);
51 SkScalar y = SkIntToScalar(10);
52 r.set(x, y, x + SkIntToScalar(100), y + SkIntToScalar(100));
rmistry@google.comae933ce2012-08-23 18:19:56 +000053
reed@android.com8a1c16f2008-12-17 15:59:43 +000054 SkPaint paint;
reed@android.comf2b98d62010-12-20 18:26:13 +000055 // paint.setAntiAlias(true);
reed@android.com8a1c16f2008-12-17 15:59:43 +000056 paint.setStyle(SkPaint::kStroke_Style);
57 paint.setStrokeWidth(SkScalarHalf(SkIntToScalar(3)));
58 paint.setColor(0xFFFF8800);
reed@android.comf2b98d62010-12-20 18:26:13 +000059 // paint.setColor(0xFFFFFFFF);
reed@android.com8a1c16f2008-12-17 15:59:43 +000060 canvas->drawRect(r, paint);
61 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000062
mtkleinf0599002015-07-13 06:18:39 -070063 void onDrawContent(SkCanvas* canvas) override {
reed@android.com8a1c16f2008-12-17 15:59:43 +000064 SkBitmap bm;
msarettd15750c2016-03-18 15:48:49 -070065 decode_file("/kill.gif", &bm);
halcanary96fcdcc2015-08-27 07:41:13 -070066 canvas->drawBitmap(bm, 0, 0, nullptr);
rmistry@google.comae933ce2012-08-23 18:19:56 +000067
reed@android.com8a1c16f2008-12-17 15:59:43 +000068 this->drawRings(canvas);
69 return;
70
71 SkPaint paint;
rmistry@google.comae933ce2012-08-23 18:19:56 +000072
reed@android.com8a1c16f2008-12-17 15:59:43 +000073 // fAlpha = 0x80;
74 paint.setColor(SK_ColorWHITE);
75 paint.setAlpha(fAlpha & 0xFF);
76 SkRect r;
rmistry@google.comae933ce2012-08-23 18:19:56 +000077
reed@android.com8a1c16f2008-12-17 15:59:43 +000078 SkScalar x = SkIntToScalar(10);
79 SkScalar y = SkIntToScalar(10);
80 r.set(x, y, x + SkIntToScalar(100), y + SkIntToScalar(100));
81 canvas->drawRect(r, paint);
82 return;
rmistry@google.comae933ce2012-08-23 18:19:56 +000083
reed@android.com8a1c16f2008-12-17 15:59:43 +000084 paint.setColor(0xffffff00); // yellow
85 paint.setStyle(SkPaint::kStroke_Style);
86 paint.setStrokeWidth(SkIntToScalar(2));
rmistry@google.comae933ce2012-08-23 18:19:56 +000087
reed@android.com8a1c16f2008-12-17 15:59:43 +000088// y += SK_Scalar1/2;
89
90 canvas->drawLine(x, y, x + SkIntToScalar(90), y + SkIntToScalar(90), paint);
91
92 paint.setAntiAlias(true); // with anti-aliasing
93 y += SkIntToScalar(10);
94 canvas->drawLine(x, y, x + SkIntToScalar(90), y + SkIntToScalar(90), paint);
95 }
96
mtklein36352bf2015-03-25 18:17:31 -070097 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned) override {
reed@google.come1ca7052013-12-17 19:22:07 +000098 fAlpha = SkScalarRoundToInt(y);
halcanary96fcdcc2015-08-27 07:41:13 -070099 this->inval(nullptr);
100 return nullptr;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000101 }
102private:
103
104 int fAlpha;
reed@google.com961ddb02011-05-05 14:03:48 +0000105 typedef SampleView INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000106};
107
108//////////////////////////////////////////////////////////////////////////////
109
110static SkView* MyFactory() { return new LinesView; }
111static SkViewRegister reg(MyFactory);