Home | History | Annotate | Download | only in samplecode
      1 #include "SampleCode.h"
      2 #include "SkView.h"
      3 #include "SkCanvas.h"
      4 #include "SkDevice.h"
      5 #include "SkPaint.h"
      6 
      7 static void DrawRoundRect() {
      8 #ifdef SK_SCALAR_IS_FIXED
      9     bool ret = false;
     10     SkPaint  paint;
     11     SkBitmap bitmap;
     12     SkCanvas canvas;
     13     SkMatrix matrix;
     14     matrix.reset();
     15 
     16     bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1370, 812);
     17     bitmap.allocPixels();
     18     canvas.setBitmapDevice(bitmap);
     19 
     20     // set up clipper
     21     SkRect skclip;
     22     skclip.set(SkIntToFixed(284), SkIntToFixed(40), SkIntToFixed(1370), SkIntToFixed(708));
     23 
     24     ret = canvas.clipRect(skclip);
     25     SkASSERT(ret);
     26 
     27     matrix.set(SkMatrix::kMTransX, SkFloatToFixed(-1153.28));
     28     matrix.set(SkMatrix::kMTransY, SkFloatToFixed(1180.50));
     29 
     30     matrix.set(SkMatrix::kMScaleX, SkFloatToFixed(0.177171));
     31     matrix.set(SkMatrix::kMScaleY, SkFloatToFixed(0.177043));
     32 
     33     matrix.set(SkMatrix::kMSkewX, SkFloatToFixed(0.126968));
     34     matrix.set(SkMatrix::kMSkewY, SkFloatToFixed(-0.126876));
     35 
     36     matrix.set(SkMatrix::kMPersp0, SkFloatToFixed(0.0));
     37     matrix.set(SkMatrix::kMPersp1, SkFloatToFixed(0.0));
     38 
     39     ret = canvas.concat(matrix);
     40 
     41     paint.setAntiAlias(true);
     42     paint.setColor(0xb2202020);
     43     paint.setStyle(SkPaint::kStroke_Style);
     44     paint.setStrokeWidth(SkFloatToFixed(68.13));
     45 
     46     SkRect r;
     47     r.set(SkFloatToFixed(-313.714417), SkFloatToFixed(-4.826389), SkFloatToFixed(18014.447266), SkFloatToFixed(1858.154541));
     48     canvas.drawRoundRect(r, SkFloatToFixed(91.756363), SkFloatToFixed(91.756363), paint);
     49 #endif
     50 }
     51 
     52 static bool HitTestPath(const SkPath& path, SkScalar x, SkScalar y) {
     53     SkRegion    rgn, clip;
     54 
     55     int ix = SkScalarFloor(x);
     56     int iy = SkScalarFloor(y);
     57 
     58     clip.setRect(ix, iy, ix + 1, iy + 1);
     59 
     60     bool contains = rgn.setPath(path, clip);
     61     return contains;
     62 }
     63 
     64 static void TestOverflowHitTest() {
     65     SkPath path;
     66 
     67 #ifdef SK_SCALAR_IS_FLOATx
     68     path.addCircle(0, 0, 70000, SkPath::kCCW_Direction);
     69     SkASSERT(HitTestPath(path, 40000, 40000));
     70 #endif
     71 }
     72 
     73 class OverflowView : public SampleView {
     74 public:
     75 	OverflowView() {}
     76 
     77 protected:
     78     // overrides from SkEventSink
     79     virtual bool onQuery(SkEvent* evt) {
     80         if (SampleCode::TitleQ(*evt)) {
     81             SampleCode::TitleR(evt, "Circles");
     82             return true;
     83         }
     84         return this->INHERITED::onQuery(evt);
     85     }
     86 
     87     virtual void onDrawContent(SkCanvas* canvas) {
     88         DrawRoundRect();
     89         TestOverflowHitTest();
     90     }
     91 
     92 private:
     93     typedef SampleView INHERITED;
     94 };
     95 
     96 //////////////////////////////////////////////////////////////////////////////
     97 
     98 static SkView* MyFactory() { return new OverflowView; }
     99 static SkViewRegister reg(MyFactory);
    100 
    101