blob: bf43e8b9c48f47044e687eb0486709b7c4a050b5 [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"
reed@android.com8a1c16f2008-12-17 15:59:43 +000024#include "SkStream.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000025#include "SkColorPriv.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000026
reed@google.com961ddb02011-05-05 14:03:48 +000027class LinesView : public SampleView {
reed@android.com8a1c16f2008-12-17 15:59:43 +000028public:
rmistry@google.comae933ce2012-08-23 18:19:56 +000029 LinesView() {}
30
reed@android.com8a1c16f2008-12-17 15:59:43 +000031protected:
32 // overrides from SkEventSink
mtkleinf0599002015-07-13 06:18:39 -070033 bool onQuery(SkEvent* evt) override {
reed@google.com961ddb02011-05-05 14:03:48 +000034 if (SampleCode::TitleQ(*evt)) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000035 SampleCode::TitleR(evt, "Lines");
36 return true;
37 }
38 return this->INHERITED::onQuery(evt);
39 }
40
reed@android.com8a1c16f2008-12-17 15:59:43 +000041 /*
42 0x1F * x + 0x1F * (32 - x)
43 */
reed@google.com961ddb02011-05-05 14:03:48 +000044 void drawRings(SkCanvas* canvas) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000045 canvas->scale(SkIntToScalar(1)/2, SkIntToScalar(1)/2);
rmistry@google.comae933ce2012-08-23 18:19:56 +000046
47 SkRect r;
reed@android.com8a1c16f2008-12-17 15:59:43 +000048 SkScalar x = SkIntToScalar(10);
49 SkScalar y = SkIntToScalar(10);
50 r.set(x, y, x + SkIntToScalar(100), y + SkIntToScalar(100));
rmistry@google.comae933ce2012-08-23 18:19:56 +000051
reed@android.com8a1c16f2008-12-17 15:59:43 +000052 SkPaint paint;
reed@android.comf2b98d62010-12-20 18:26:13 +000053 // paint.setAntiAlias(true);
reed@android.com8a1c16f2008-12-17 15:59:43 +000054 paint.setStyle(SkPaint::kStroke_Style);
55 paint.setStrokeWidth(SkScalarHalf(SkIntToScalar(3)));
56 paint.setColor(0xFFFF8800);
reed@android.comf2b98d62010-12-20 18:26:13 +000057 // paint.setColor(0xFFFFFFFF);
reed@android.com8a1c16f2008-12-17 15:59:43 +000058 canvas->drawRect(r, paint);
59 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000060
mtkleinf0599002015-07-13 06:18:39 -070061 void onDrawContent(SkCanvas* canvas) override {
reed@android.com8a1c16f2008-12-17 15:59:43 +000062 SkBitmap bm;
msarettd15750c2016-03-18 15:48:49 -070063 decode_file("/kill.gif", &bm);
halcanary96fcdcc2015-08-27 07:41:13 -070064 canvas->drawBitmap(bm, 0, 0, nullptr);
rmistry@google.comae933ce2012-08-23 18:19:56 +000065
reed@android.com8a1c16f2008-12-17 15:59:43 +000066 this->drawRings(canvas);
67 return;
68
69 SkPaint paint;
rmistry@google.comae933ce2012-08-23 18:19:56 +000070
reed@android.com8a1c16f2008-12-17 15:59:43 +000071 // fAlpha = 0x80;
72 paint.setColor(SK_ColorWHITE);
73 paint.setAlpha(fAlpha & 0xFF);
74 SkRect r;
rmistry@google.comae933ce2012-08-23 18:19:56 +000075
reed@android.com8a1c16f2008-12-17 15:59:43 +000076 SkScalar x = SkIntToScalar(10);
77 SkScalar y = SkIntToScalar(10);
78 r.set(x, y, x + SkIntToScalar(100), y + SkIntToScalar(100));
79 canvas->drawRect(r, paint);
80 return;
rmistry@google.comae933ce2012-08-23 18:19:56 +000081
reed@android.com8a1c16f2008-12-17 15:59:43 +000082 paint.setColor(0xffffff00); // yellow
83 paint.setStyle(SkPaint::kStroke_Style);
84 paint.setStrokeWidth(SkIntToScalar(2));
rmistry@google.comae933ce2012-08-23 18:19:56 +000085
reed@android.com8a1c16f2008-12-17 15:59:43 +000086// y += SK_Scalar1/2;
87
88 canvas->drawLine(x, y, x + SkIntToScalar(90), y + SkIntToScalar(90), paint);
89
90 paint.setAntiAlias(true); // with anti-aliasing
91 y += SkIntToScalar(10);
92 canvas->drawLine(x, y, x + SkIntToScalar(90), y + SkIntToScalar(90), paint);
93 }
94
mtklein36352bf2015-03-25 18:17:31 -070095 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned) override {
reed@google.come1ca7052013-12-17 19:22:07 +000096 fAlpha = SkScalarRoundToInt(y);
halcanary96fcdcc2015-08-27 07:41:13 -070097 this->inval(nullptr);
98 return nullptr;
reed@android.com8a1c16f2008-12-17 15:59:43 +000099 }
100private:
101
102 int fAlpha;
reed@google.com961ddb02011-05-05 14:03:48 +0000103 typedef SampleView INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000104};
105
106//////////////////////////////////////////////////////////////////////////////
107
108static SkView* MyFactory() { return new LinesView; }
109static SkViewRegister reg(MyFactory);