blob: da5fa57681e218f87c20332038b6fffafcd71cfe [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"
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"
28#include "SkImageDecoder.h"
29
reed@google.com961ddb02011-05-05 14:03:48 +000030class LinesView : public SampleView {
reed@android.com8a1c16f2008-12-17 15:59:43 +000031public:
rmistry@google.comae933ce2012-08-23 18:19:56 +000032 LinesView() {}
33
reed@android.com8a1c16f2008-12-17 15:59:43 +000034protected:
35 // overrides from SkEventSink
mtkleinf0599002015-07-13 06:18:39 -070036 bool onQuery(SkEvent* evt) override {
reed@google.com961ddb02011-05-05 14:03:48 +000037 if (SampleCode::TitleQ(*evt)) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000038 SampleCode::TitleR(evt, "Lines");
39 return true;
40 }
41 return this->INHERITED::onQuery(evt);
42 }
43
reed@android.com8a1c16f2008-12-17 15:59:43 +000044 /*
45 0x1F * x + 0x1F * (32 - x)
46 */
reed@google.com961ddb02011-05-05 14:03:48 +000047 void drawRings(SkCanvas* canvas) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000048 canvas->scale(SkIntToScalar(1)/2, SkIntToScalar(1)/2);
rmistry@google.comae933ce2012-08-23 18:19:56 +000049
50 SkRect r;
reed@android.com8a1c16f2008-12-17 15:59:43 +000051 SkScalar x = SkIntToScalar(10);
52 SkScalar y = SkIntToScalar(10);
53 r.set(x, y, x + SkIntToScalar(100), y + SkIntToScalar(100));
rmistry@google.comae933ce2012-08-23 18:19:56 +000054
reed@android.com8a1c16f2008-12-17 15:59:43 +000055 SkPaint paint;
reed@android.comf2b98d62010-12-20 18:26:13 +000056 // paint.setAntiAlias(true);
reed@android.com8a1c16f2008-12-17 15:59:43 +000057 paint.setStyle(SkPaint::kStroke_Style);
58 paint.setStrokeWidth(SkScalarHalf(SkIntToScalar(3)));
59 paint.setColor(0xFFFF8800);
reed@android.comf2b98d62010-12-20 18:26:13 +000060 // paint.setColor(0xFFFFFFFF);
reed@android.com8a1c16f2008-12-17 15:59:43 +000061 canvas->drawRect(r, paint);
62 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000063
mtkleinf0599002015-07-13 06:18:39 -070064 void onDrawContent(SkCanvas* canvas) override {
reed@android.com8a1c16f2008-12-17 15:59:43 +000065 SkBitmap bm;
66 SkImageDecoder::DecodeFile("/kill.gif", &bm);
halcanary96fcdcc2015-08-27 07:41:13 -070067 canvas->drawBitmap(bm, 0, 0, nullptr);
rmistry@google.comae933ce2012-08-23 18:19:56 +000068
reed@android.com8a1c16f2008-12-17 15:59:43 +000069 this->drawRings(canvas);
70 return;
71
72 SkPaint paint;
rmistry@google.comae933ce2012-08-23 18:19:56 +000073
reed@android.com8a1c16f2008-12-17 15:59:43 +000074 // fAlpha = 0x80;
75 paint.setColor(SK_ColorWHITE);
76 paint.setAlpha(fAlpha & 0xFF);
77 SkRect r;
rmistry@google.comae933ce2012-08-23 18:19:56 +000078
reed@android.com8a1c16f2008-12-17 15:59:43 +000079 SkScalar x = SkIntToScalar(10);
80 SkScalar y = SkIntToScalar(10);
81 r.set(x, y, x + SkIntToScalar(100), y + SkIntToScalar(100));
82 canvas->drawRect(r, paint);
83 return;
rmistry@google.comae933ce2012-08-23 18:19:56 +000084
reed@android.com8a1c16f2008-12-17 15:59:43 +000085 paint.setColor(0xffffff00); // yellow
86 paint.setStyle(SkPaint::kStroke_Style);
87 paint.setStrokeWidth(SkIntToScalar(2));
rmistry@google.comae933ce2012-08-23 18:19:56 +000088
reed@android.com8a1c16f2008-12-17 15:59:43 +000089// y += SK_Scalar1/2;
90
91 canvas->drawLine(x, y, x + SkIntToScalar(90), y + SkIntToScalar(90), paint);
92
93 paint.setAntiAlias(true); // with anti-aliasing
94 y += SkIntToScalar(10);
95 canvas->drawLine(x, y, x + SkIntToScalar(90), y + SkIntToScalar(90), paint);
96 }
97
mtklein36352bf2015-03-25 18:17:31 -070098 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned) override {
reed@google.come1ca7052013-12-17 19:22:07 +000099 fAlpha = SkScalarRoundToInt(y);
halcanary96fcdcc2015-08-27 07:41:13 -0700100 this->inval(nullptr);
101 return nullptr;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000102 }
103private:
104
105 int fAlpha;
reed@google.com961ddb02011-05-05 14:03:48 +0000106 typedef SampleView INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000107};
108
109//////////////////////////////////////////////////////////////////////////////
110
111static SkView* MyFactory() { return new LinesView; }
112static SkViewRegister reg(MyFactory);