• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
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  */
8 #include "SampleCode.h"
9 #include "SkView.h"
10 #include "SkCanvas.h"
11 #include "SkDevice.h"
12 #include "SkPaint.h"
13 
DrawRoundRect()14 static 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 
HitTestPath(const SkPath & path,SkScalar x,SkScalar y)59 static 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 
TestOverflowHitTest()71 static 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 
80 class OverflowView : public SampleView {
81 public:
OverflowView()82 	OverflowView() {}
83 
84 protected:
85     // overrides from SkEventSink
onQuery(SkEvent * evt)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 
onDrawContent(SkCanvas * canvas)94     virtual void onDrawContent(SkCanvas* canvas) {
95         DrawRoundRect();
96         TestOverflowHitTest();
97     }
98 
99 private:
100     typedef SampleView INHERITED;
101 };
102 
103 //////////////////////////////////////////////////////////////////////////////
104 
MyFactory()105 static SkView* MyFactory() { return new OverflowView; }
106 static SkViewRegister reg(MyFactory);
107 
108