epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 8 | #include "SampleCode.h" |
| 9 | #include "SkView.h" |
| 10 | #include "SkCanvas.h" |
| 11 | #include "SkDevice.h" |
| 12 | #include "SkPaint.h" |
| 13 | |
| 14 | static void DrawRoundRect() { |
| 15 | #ifdef SK_SCALAR_IS_FIXED |
| 16 | bool ret = false; |
| 17 | SkPaint paint; |
| 18 | SkBitmap bitmap; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 19 | SkMatrix matrix; |
| 20 | matrix.reset(); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 21 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 22 | bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1370, 812); |
| 23 | bitmap.allocPixels(); |
mike@reedtribe.org | 3bd2173 | 2012-09-26 02:45:10 +0000 | [diff] [blame] | 24 | |
| 25 | SkCanvas canvas(bitmap); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 26 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 27 | // set up clipper |
| 28 | SkRect skclip; |
| 29 | skclip.set(SkIntToFixed(284), SkIntToFixed(40), SkIntToFixed(1370), SkIntToFixed(708)); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 30 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 31 | ret = canvas.clipRect(skclip); |
| 32 | SkASSERT(ret); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 33 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 34 | matrix.set(SkMatrix::kMTransX, SkFloatToFixed(-1153.28)); |
| 35 | matrix.set(SkMatrix::kMTransY, SkFloatToFixed(1180.50)); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 36 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 37 | matrix.set(SkMatrix::kMScaleX, SkFloatToFixed(0.177171)); |
| 38 | matrix.set(SkMatrix::kMScaleY, SkFloatToFixed(0.177043)); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 39 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 40 | matrix.set(SkMatrix::kMSkewX, SkFloatToFixed(0.126968)); |
| 41 | matrix.set(SkMatrix::kMSkewY, SkFloatToFixed(-0.126876)); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 42 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 43 | matrix.set(SkMatrix::kMPersp0, SkFloatToFixed(0.0)); |
| 44 | matrix.set(SkMatrix::kMPersp1, SkFloatToFixed(0.0)); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 45 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 46 | ret = canvas.concat(matrix); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 47 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 48 | paint.setAntiAlias(true); |
| 49 | paint.setColor(0xb2202020); |
| 50 | paint.setStyle(SkPaint::kStroke_Style); |
| 51 | paint.setStrokeWidth(SkFloatToFixed(68.13)); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 52 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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 | |
caryclark@google.com | 02939ce | 2012-06-06 12:09:51 +0000 | [diff] [blame] | 59 | #ifdef SK_SCALAR_IS_FLOATx // FIXME: unclear when if ever this can be enabled |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 60 | static bool HitTestPath(const SkPath& path, SkScalar x, SkScalar y) { |
| 61 | SkRegion rgn, clip; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 62 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 63 | int ix = SkScalarFloor(x); |
| 64 | int iy = SkScalarFloor(y); |
| 65 | |
| 66 | clip.setRect(ix, iy, ix + 1, iy + 1); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 67 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 68 | bool contains = rgn.setPath(path, clip); |
| 69 | return contains; |
| 70 | } |
caryclark@google.com | 02939ce | 2012-06-06 12:09:51 +0000 | [diff] [blame] | 71 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 72 | |
| 73 | static void TestOverflowHitTest() { |
| 74 | SkPath path; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 75 | |
caryclark@google.com | 02939ce | 2012-06-06 12:09:51 +0000 | [diff] [blame] | 76 | #ifdef SK_SCALAR_IS_FLOATx // FIXME: unclear when if ever this can be enabled |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 77 | path.addCircle(0, 0, 70000, SkPath::kCCW_Direction); |
| 78 | SkASSERT(HitTestPath(path, 40000, 40000)); |
| 79 | #endif |
| 80 | } |
| 81 | |
reed@google.com | 81e3d7f | 2011-06-01 12:42:36 +0000 | [diff] [blame] | 82 | class OverflowView : public SampleView { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 83 | public: |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 84 | OverflowView() {} |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 85 | |
| 86 | protected: |
| 87 | // overrides from SkEventSink |
| 88 | virtual bool onQuery(SkEvent* evt) { |
| 89 | if (SampleCode::TitleQ(*evt)) { |
| 90 | SampleCode::TitleR(evt, "Circles"); |
| 91 | return true; |
| 92 | } |
| 93 | return this->INHERITED::onQuery(evt); |
| 94 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 95 | |
reed@google.com | 81e3d7f | 2011-06-01 12:42:36 +0000 | [diff] [blame] | 96 | virtual void onDrawContent(SkCanvas* canvas) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 97 | DrawRoundRect(); |
| 98 | TestOverflowHitTest(); |
| 99 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 100 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 101 | private: |
reed@google.com | 81e3d7f | 2011-06-01 12:42:36 +0000 | [diff] [blame] | 102 | typedef SampleView INHERITED; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | ////////////////////////////////////////////////////////////////////////////// |
| 106 | |
| 107 | static SkView* MyFactory() { return new OverflowView; } |
| 108 | static SkViewRegister reg(MyFactory); |