blob: 35adbf35099aa7bff345eef3d4d76e2adda485ae [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;
reed@android.com8a1c16f2008-12-17 15:59:43 +000019 SkMatrix matrix;
20 matrix.reset();
rmistry@google.comae933ce2012-08-23 18:19:56 +000021
reed@android.com8a1c16f2008-12-17 15:59:43 +000022 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1370, 812);
23 bitmap.allocPixels();
mike@reedtribe.org3bd21732012-09-26 02:45:10 +000024
25 SkCanvas canvas(bitmap);
rmistry@google.comae933ce2012-08-23 18:19:56 +000026
reed@android.com8a1c16f2008-12-17 15:59:43 +000027 // set up clipper
28 SkRect skclip;
29 skclip.set(SkIntToFixed(284), SkIntToFixed(40), SkIntToFixed(1370), SkIntToFixed(708));
rmistry@google.comae933ce2012-08-23 18:19:56 +000030
reed@android.com8a1c16f2008-12-17 15:59:43 +000031 ret = canvas.clipRect(skclip);
32 SkASSERT(ret);
rmistry@google.comae933ce2012-08-23 18:19:56 +000033
reed@android.com8a1c16f2008-12-17 15:59:43 +000034 matrix.set(SkMatrix::kMTransX, SkFloatToFixed(-1153.28));
35 matrix.set(SkMatrix::kMTransY, SkFloatToFixed(1180.50));
rmistry@google.comae933ce2012-08-23 18:19:56 +000036
reed@android.com8a1c16f2008-12-17 15:59:43 +000037 matrix.set(SkMatrix::kMScaleX, SkFloatToFixed(0.177171));
38 matrix.set(SkMatrix::kMScaleY, SkFloatToFixed(0.177043));
rmistry@google.comae933ce2012-08-23 18:19:56 +000039
reed@android.com8a1c16f2008-12-17 15:59:43 +000040 matrix.set(SkMatrix::kMSkewX, SkFloatToFixed(0.126968));
41 matrix.set(SkMatrix::kMSkewY, SkFloatToFixed(-0.126876));
rmistry@google.comae933ce2012-08-23 18:19:56 +000042
reed@android.com8a1c16f2008-12-17 15:59:43 +000043 matrix.set(SkMatrix::kMPersp0, SkFloatToFixed(0.0));
44 matrix.set(SkMatrix::kMPersp1, SkFloatToFixed(0.0));
rmistry@google.comae933ce2012-08-23 18:19:56 +000045
reed@android.com8a1c16f2008-12-17 15:59:43 +000046 ret = canvas.concat(matrix);
rmistry@google.comae933ce2012-08-23 18:19:56 +000047
reed@android.com8a1c16f2008-12-17 15:59:43 +000048 paint.setAntiAlias(true);
49 paint.setColor(0xb2202020);
50 paint.setStyle(SkPaint::kStroke_Style);
51 paint.setStrokeWidth(SkFloatToFixed(68.13));
rmistry@google.comae933ce2012-08-23 18:19:56 +000052
reed@android.com8a1c16f2008-12-17 15:59:43 +000053 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.com02939ce2012-06-06 12:09:51 +000059#ifdef SK_SCALAR_IS_FLOATx // FIXME: unclear when if ever this can be enabled
reed@android.com8a1c16f2008-12-17 15:59:43 +000060static bool HitTestPath(const SkPath& path, SkScalar x, SkScalar y) {
61 SkRegion rgn, clip;
rmistry@google.comae933ce2012-08-23 18:19:56 +000062
reed@android.com8a1c16f2008-12-17 15:59:43 +000063 int ix = SkScalarFloor(x);
64 int iy = SkScalarFloor(y);
65
66 clip.setRect(ix, iy, ix + 1, iy + 1);
rmistry@google.comae933ce2012-08-23 18:19:56 +000067
reed@android.com8a1c16f2008-12-17 15:59:43 +000068 bool contains = rgn.setPath(path, clip);
69 return contains;
70}
caryclark@google.com02939ce2012-06-06 12:09:51 +000071#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +000072
73static void TestOverflowHitTest() {
74 SkPath path;
rmistry@google.comae933ce2012-08-23 18:19:56 +000075
caryclark@google.com02939ce2012-06-06 12:09:51 +000076#ifdef SK_SCALAR_IS_FLOATx // FIXME: unclear when if ever this can be enabled
reed@android.com8a1c16f2008-12-17 15:59:43 +000077 path.addCircle(0, 0, 70000, SkPath::kCCW_Direction);
78 SkASSERT(HitTestPath(path, 40000, 40000));
79#endif
80}
81
reed@google.com81e3d7f2011-06-01 12:42:36 +000082class OverflowView : public SampleView {
reed@android.com8a1c16f2008-12-17 15:59:43 +000083public:
rmistry@google.comae933ce2012-08-23 18:19:56 +000084 OverflowView() {}
reed@android.com8a1c16f2008-12-17 15:59:43 +000085
86protected:
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.comae933ce2012-08-23 18:19:56 +000095
reed@google.com81e3d7f2011-06-01 12:42:36 +000096 virtual void onDrawContent(SkCanvas* canvas) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000097 DrawRoundRect();
98 TestOverflowHitTest();
99 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000100
reed@android.com8a1c16f2008-12-17 15:59:43 +0000101private:
reed@google.com81e3d7f2011-06-01 12:42:36 +0000102 typedef SampleView INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000103};
104
105//////////////////////////////////////////////////////////////////////////////
106
107static SkView* MyFactory() { return new OverflowView; }
108static SkViewRegister reg(MyFactory);