blob: 0166bc029691ae44c8324fe45169e515d789e7a2 [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"
27#include "SkXMLParser.h"
28#include "SkColorPriv.h"
29#include "SkImageDecoder.h"
30
reed@google.com961ddb02011-05-05 14:03:48 +000031class LinesView : public SampleView {
reed@android.com8a1c16f2008-12-17 15:59:43 +000032public:
rmistry@google.comae933ce2012-08-23 18:19:56 +000033 LinesView() {}
34
reed@android.com8a1c16f2008-12-17 15:59:43 +000035protected:
36 // overrides from SkEventSink
mtkleinf0599002015-07-13 06:18:39 -070037 bool onQuery(SkEvent* evt) override {
reed@google.com961ddb02011-05-05 14:03:48 +000038 if (SampleCode::TitleQ(*evt)) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000039 SampleCode::TitleR(evt, "Lines");
40 return true;
41 }
42 return this->INHERITED::onQuery(evt);
43 }
44
reed@android.com8a1c16f2008-12-17 15:59:43 +000045 /*
46 0x1F * x + 0x1F * (32 - x)
47 */
reed@google.com961ddb02011-05-05 14:03:48 +000048 void drawRings(SkCanvas* canvas) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000049 canvas->scale(SkIntToScalar(1)/2, SkIntToScalar(1)/2);
rmistry@google.comae933ce2012-08-23 18:19:56 +000050
51 SkRect r;
reed@android.com8a1c16f2008-12-17 15:59:43 +000052 SkScalar x = SkIntToScalar(10);
53 SkScalar y = SkIntToScalar(10);
54 r.set(x, y, x + SkIntToScalar(100), y + SkIntToScalar(100));
rmistry@google.comae933ce2012-08-23 18:19:56 +000055
reed@android.com8a1c16f2008-12-17 15:59:43 +000056 SkPaint paint;
reed@android.comf2b98d62010-12-20 18:26:13 +000057 // paint.setAntiAlias(true);
reed@android.com8a1c16f2008-12-17 15:59:43 +000058 paint.setStyle(SkPaint::kStroke_Style);
59 paint.setStrokeWidth(SkScalarHalf(SkIntToScalar(3)));
60 paint.setColor(0xFFFF8800);
reed@android.comf2b98d62010-12-20 18:26:13 +000061 // paint.setColor(0xFFFFFFFF);
reed@android.com8a1c16f2008-12-17 15:59:43 +000062 canvas->drawRect(r, paint);
63 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000064
mtkleinf0599002015-07-13 06:18:39 -070065 void onDrawContent(SkCanvas* canvas) override {
reed@android.com8a1c16f2008-12-17 15:59:43 +000066 SkBitmap bm;
67 SkImageDecoder::DecodeFile("/kill.gif", &bm);
68 canvas->drawBitmap(bm, 0, 0, NULL);
rmistry@google.comae933ce2012-08-23 18:19:56 +000069
reed@android.com8a1c16f2008-12-17 15:59:43 +000070 this->drawRings(canvas);
71 return;
72
73 SkPaint paint;
rmistry@google.comae933ce2012-08-23 18:19:56 +000074
reed@android.com8a1c16f2008-12-17 15:59:43 +000075 // fAlpha = 0x80;
76 paint.setColor(SK_ColorWHITE);
77 paint.setAlpha(fAlpha & 0xFF);
78 SkRect r;
rmistry@google.comae933ce2012-08-23 18:19:56 +000079
reed@android.com8a1c16f2008-12-17 15:59:43 +000080 SkScalar x = SkIntToScalar(10);
81 SkScalar y = SkIntToScalar(10);
82 r.set(x, y, x + SkIntToScalar(100), y + SkIntToScalar(100));
83 canvas->drawRect(r, paint);
84 return;
rmistry@google.comae933ce2012-08-23 18:19:56 +000085
reed@android.com8a1c16f2008-12-17 15:59:43 +000086 paint.setColor(0xffffff00); // yellow
87 paint.setStyle(SkPaint::kStroke_Style);
88 paint.setStrokeWidth(SkIntToScalar(2));
rmistry@google.comae933ce2012-08-23 18:19:56 +000089
reed@android.com8a1c16f2008-12-17 15:59:43 +000090// y += SK_Scalar1/2;
91
92 canvas->drawLine(x, y, x + SkIntToScalar(90), y + SkIntToScalar(90), paint);
93
94 paint.setAntiAlias(true); // with anti-aliasing
95 y += SkIntToScalar(10);
96 canvas->drawLine(x, y, x + SkIntToScalar(90), y + SkIntToScalar(90), paint);
97 }
98
mtklein36352bf2015-03-25 18:17:31 -070099 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned) override {
reed@google.come1ca7052013-12-17 19:22:07 +0000100 fAlpha = SkScalarRoundToInt(y);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000101 this->inval(NULL);
102 return NULL;
103 }
104private:
105
106 int fAlpha;
reed@google.com961ddb02011-05-05 14:03:48 +0000107 typedef SampleView INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000108};
109
110//////////////////////////////////////////////////////////////////////////////
111
112static SkView* MyFactory() { return new LinesView; }
113static SkViewRegister reg(MyFactory);