blob: 1ec474891ab9073e9067cbf539bc30a5762920d8 [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"
Ben Wagnerb2c4ea62018-08-08 11:36:17 -04009#include "Sample.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000010#include "SkCanvas.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000011#include "SkCornerPathEffect.h"
12#include "SkGradientShader.h"
13#include "SkGraphics.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000014#include "SkPath.h"
15#include "SkRandom.h"
16#include "SkRegion.h"
17#include "SkShader.h"
Hal Canaryea60b952018-08-21 11:45:46 -040018#include "SkUTF.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000019#include "SkColorPriv.h"
20#include "SkColorFilter.h"
21#include "SkTime.h"
22#include "SkTypeface.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000023#include "SkStream.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000024#include "SkColorPriv.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000025
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040026class LinesView : public Sample {
reed@android.com8a1c16f2008-12-17 15:59:43 +000027public:
rmistry@google.comae933ce2012-08-23 18:19:56 +000028 LinesView() {}
29
reed@android.com8a1c16f2008-12-17 15:59:43 +000030protected:
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040031 bool onQuery(Sample::Event* evt) override {
32 if (Sample::TitleQ(*evt)) {
33 Sample::TitleR(evt, "Lines");
reed@android.com8a1c16f2008-12-17 15:59:43 +000034 return true;
35 }
36 return this->INHERITED::onQuery(evt);
37 }
38
reed@android.com8a1c16f2008-12-17 15:59:43 +000039 /*
40 0x1F * x + 0x1F * (32 - x)
41 */
reed@google.com961ddb02011-05-05 14:03:48 +000042 void drawRings(SkCanvas* canvas) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000043 canvas->scale(SkIntToScalar(1)/2, SkIntToScalar(1)/2);
rmistry@google.comae933ce2012-08-23 18:19:56 +000044
45 SkRect r;
reed@android.com8a1c16f2008-12-17 15:59:43 +000046 SkScalar x = SkIntToScalar(10);
47 SkScalar y = SkIntToScalar(10);
48 r.set(x, y, x + SkIntToScalar(100), y + SkIntToScalar(100));
rmistry@google.comae933ce2012-08-23 18:19:56 +000049
reed@android.com8a1c16f2008-12-17 15:59:43 +000050 SkPaint paint;
reed@android.comf2b98d62010-12-20 18:26:13 +000051 // paint.setAntiAlias(true);
reed@android.com8a1c16f2008-12-17 15:59:43 +000052 paint.setStyle(SkPaint::kStroke_Style);
53 paint.setStrokeWidth(SkScalarHalf(SkIntToScalar(3)));
54 paint.setColor(0xFFFF8800);
reed@android.comf2b98d62010-12-20 18:26:13 +000055 // paint.setColor(0xFFFFFFFF);
reed@android.com8a1c16f2008-12-17 15:59:43 +000056 canvas->drawRect(r, paint);
57 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000058
mtkleinf0599002015-07-13 06:18:39 -070059 void onDrawContent(SkCanvas* canvas) override {
reed@android.com8a1c16f2008-12-17 15:59:43 +000060 SkBitmap bm;
msarettd15750c2016-03-18 15:48:49 -070061 decode_file("/kill.gif", &bm);
halcanary96fcdcc2015-08-27 07:41:13 -070062 canvas->drawBitmap(bm, 0, 0, nullptr);
rmistry@google.comae933ce2012-08-23 18:19:56 +000063
reed@android.com8a1c16f2008-12-17 15:59:43 +000064 this->drawRings(canvas);
65 return;
66
67 SkPaint paint;
rmistry@google.comae933ce2012-08-23 18:19:56 +000068
reed@android.com8a1c16f2008-12-17 15:59:43 +000069 // fAlpha = 0x80;
70 paint.setColor(SK_ColorWHITE);
71 paint.setAlpha(fAlpha & 0xFF);
72 SkRect r;
rmistry@google.comae933ce2012-08-23 18:19:56 +000073
reed@android.com8a1c16f2008-12-17 15:59:43 +000074 SkScalar x = SkIntToScalar(10);
75 SkScalar y = SkIntToScalar(10);
76 r.set(x, y, x + SkIntToScalar(100), y + SkIntToScalar(100));
77 canvas->drawRect(r, paint);
78 return;
rmistry@google.comae933ce2012-08-23 18:19:56 +000079
reed@android.com8a1c16f2008-12-17 15:59:43 +000080 paint.setColor(0xffffff00); // yellow
81 paint.setStyle(SkPaint::kStroke_Style);
82 paint.setStrokeWidth(SkIntToScalar(2));
rmistry@google.comae933ce2012-08-23 18:19:56 +000083
reed@android.com8a1c16f2008-12-17 15:59:43 +000084// y += SK_Scalar1/2;
85
86 canvas->drawLine(x, y, x + SkIntToScalar(90), y + SkIntToScalar(90), paint);
87
88 paint.setAntiAlias(true); // with anti-aliasing
89 y += SkIntToScalar(10);
90 canvas->drawLine(x, y, x + SkIntToScalar(90), y + SkIntToScalar(90), paint);
91 }
92
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040093 Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned) override {
reed@google.come1ca7052013-12-17 19:22:07 +000094 fAlpha = SkScalarRoundToInt(y);
halcanary96fcdcc2015-08-27 07:41:13 -070095 return nullptr;
reed@android.com8a1c16f2008-12-17 15:59:43 +000096 }
97private:
98
99 int fAlpha;
Ben Wagnerb2c4ea62018-08-08 11:36:17 -0400100 typedef Sample INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000101};
102
103//////////////////////////////////////////////////////////////////////////////
104
Ben Wagnerb2c4ea62018-08-08 11:36:17 -0400105DEF_SAMPLE( return new LinesView(); )