blob: 05b28eb818fcaf4338152343aa4b4d8f6d163380 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00008#include "SampleCode.h"
9#include "SkView.h"
10#include "SkCanvas.h"
11#include "SkDevice.h"
12#include "SkPaint.h"
13
14static void DrawRoundRect() {
15#ifdef SK_SCALAR_IS_FIXED
16 bool ret = false;
17 SkPaint paint;
18 SkBitmap bitmap;
19 SkCanvas canvas;
20 SkMatrix matrix;
21 matrix.reset();
22
23 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1370, 812);
24 bitmap.allocPixels();
25 canvas.setBitmapDevice(bitmap);
26
27 // set up clipper
28 SkRect skclip;
29 skclip.set(SkIntToFixed(284), SkIntToFixed(40), SkIntToFixed(1370), SkIntToFixed(708));
30
31 ret = canvas.clipRect(skclip);
32 SkASSERT(ret);
33
34 matrix.set(SkMatrix::kMTransX, SkFloatToFixed(-1153.28));
35 matrix.set(SkMatrix::kMTransY, SkFloatToFixed(1180.50));
36
37 matrix.set(SkMatrix::kMScaleX, SkFloatToFixed(0.177171));
38 matrix.set(SkMatrix::kMScaleY, SkFloatToFixed(0.177043));
39
40 matrix.set(SkMatrix::kMSkewX, SkFloatToFixed(0.126968));
41 matrix.set(SkMatrix::kMSkewY, SkFloatToFixed(-0.126876));
42
43 matrix.set(SkMatrix::kMPersp0, SkFloatToFixed(0.0));
44 matrix.set(SkMatrix::kMPersp1, SkFloatToFixed(0.0));
45
46 ret = canvas.concat(matrix);
47
48 paint.setAntiAlias(true);
49 paint.setColor(0xb2202020);
50 paint.setStyle(SkPaint::kStroke_Style);
51 paint.setStrokeWidth(SkFloatToFixed(68.13));
52
53 SkRect r;
54 r.set(SkFloatToFixed(-313.714417), SkFloatToFixed(-4.826389), SkFloatToFixed(18014.447266), SkFloatToFixed(1858.154541));
55 canvas.drawRoundRect(r, SkFloatToFixed(91.756363), SkFloatToFixed(91.756363), paint);
56#endif
57}
58
59static bool HitTestPath(const SkPath& path, SkScalar x, SkScalar y) {
60 SkRegion rgn, clip;
61
62 int ix = SkScalarFloor(x);
63 int iy = SkScalarFloor(y);
64
65 clip.setRect(ix, iy, ix + 1, iy + 1);
66
67 bool contains = rgn.setPath(path, clip);
68 return contains;
69}
70
71static void TestOverflowHitTest() {
72 SkPath path;
73
74#ifdef SK_SCALAR_IS_FLOATx
75 path.addCircle(0, 0, 70000, SkPath::kCCW_Direction);
76 SkASSERT(HitTestPath(path, 40000, 40000));
77#endif
78}
79
reed@google.com81e3d7f2011-06-01 12:42:36 +000080class OverflowView : public SampleView {
reed@android.com8a1c16f2008-12-17 15:59:43 +000081public:
82 OverflowView() {}
83
84protected:
85 // overrides from SkEventSink
86 virtual bool onQuery(SkEvent* evt) {
87 if (SampleCode::TitleQ(*evt)) {
88 SampleCode::TitleR(evt, "Circles");
89 return true;
90 }
91 return this->INHERITED::onQuery(evt);
92 }
93
reed@google.com81e3d7f2011-06-01 12:42:36 +000094 virtual void onDrawContent(SkCanvas* canvas) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000095 DrawRoundRect();
96 TestOverflowHitTest();
97 }
98
99private:
reed@google.com81e3d7f2011-06-01 12:42:36 +0000100 typedef SampleView INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000101};
102
103//////////////////////////////////////////////////////////////////////////////
104
105static SkView* MyFactory() { return new OverflowView; }
106static SkViewRegister reg(MyFactory);
107