diff options
-rw-r--r-- | gm/rrect.cpp | 88 | ||||
-rw-r--r-- | include/core/SkRRect.h | 2 | ||||
-rw-r--r-- | src/core/SkRRect.cpp | 4 |
3 files changed, 63 insertions, 31 deletions
diff --git a/gm/rrect.cpp b/gm/rrect.cpp index 62ca533453..4cbf5030c2 100644 --- a/gm/rrect.cpp +++ b/gm/rrect.cpp @@ -10,44 +10,67 @@ #include "SkRRect.h" #include "SkPath.h" +typedef void (*InsetProc)(const SkRRect&, SkScalar dx, SkScalar dy, SkRRect*); + +static void inset0(const SkRRect& src, SkScalar dx, SkScalar dy, SkRRect* dst) { + SkRect r = src.rect(); + + r.inset(dx, dy); + if (r.isEmpty()) { + dst->setEmpty(); + return; + } + + SkVector radii[4]; + for (int i = 0; i < 4; ++i) { + radii[i] = src.radii((SkRRect::Corner)i); + } + for (int i = 0; i < 4; ++i) { + radii[i].fX -= dx; + radii[i].fY -= dy; + } + dst->setRectRadii(r, radii); +} + +static void inset1(const SkRRect& src, SkScalar dx, SkScalar dy, SkRRect* dst) { + SkRect r = src.rect(); + + r.inset(dx, dy); + if (r.isEmpty()) { + dst->setEmpty(); + return; + } + + SkVector radii[4]; + for (int i = 0; i < 4; ++i) { + radii[i] = src.radii((SkRRect::Corner)i); + } + dst->setRectRadii(r, radii); +} + static void draw_rrect_color(SkCanvas* canvas, const SkRRect& rrect) { SkPaint paint; paint.setAntiAlias(true); - + paint.setStyle(SkPaint::kStroke_Style); + if (rrect.isRect()) { paint.setColor(SK_ColorRED); } else if (rrect.isOval()) { - paint.setColor(SK_ColorGREEN); + paint.setColor(0xFF008800); } else if (rrect.isSimple()) { paint.setColor(SK_ColorBLUE); } else { - paint.setColor(SK_ColorGRAY); + paint.setColor(SK_ColorBLACK); } canvas->drawRRect(rrect, paint); } -static void drawrr(SkCanvas* canvas, const SkRRect& rrect) { - SkRRect inner, outer, inner2; - - SkScalar dx = 30; - SkScalar dy = 30; - - rrect.outset(dx, dy, &outer); - rrect.inset(dx/2, dy/2, &inner); - rrect.inset(dx, dy, &inner2); - - draw_rrect_color(canvas, outer); - draw_rrect_color(canvas, rrect); - draw_rrect_color(canvas, inner); - draw_rrect_color(canvas, inner2); - - SkPaint paint; - paint.setAntiAlias(true); - paint.setStyle(SkPaint::kStroke_Style); - paint.setColor(SK_ColorDKGRAY); - canvas->drawRRect(rrect, paint); - canvas->drawRRect(inner, paint); - canvas->drawRRect(inner2, paint); +static void drawrr(SkCanvas* canvas, const SkRRect& rrect, InsetProc proc) { + SkRRect rr; + for (SkScalar d = -30; d <= 30; d += 10) { + proc(rrect, d, d, &rr); + draw_rrect_color(canvas, rr); + } } class RRectGM : public skiagm::GM { @@ -64,8 +87,10 @@ protected: } virtual void onDraw(SkCanvas* canvas) { + static const InsetProc insetProcs[] = { inset0, inset1 }; + SkRRect rrect[4]; - SkRect r = { 0, 0, 120, 240 }; + SkRect r = { 0, 0, 120, 160 }; SkVector radii[4] = { { 0, 0 }, { 20, 20 }, { 10, 40 }, { 40, 40 } }; @@ -76,9 +101,14 @@ protected: rrect[3].setRectRadii(r, radii); canvas->translate(50, 50); - for (size_t i = 0; i < SK_ARRAY_COUNT(rrect); ++i) { - drawrr(canvas, rrect[i]); - canvas->translate(rrect[i].width() * 2, 0); + for (size_t j = 0; j < SK_ARRAY_COUNT(insetProcs); ++j) { + canvas->save(); + for (size_t i = 0; i < SK_ARRAY_COUNT(rrect); ++i) { + drawrr(canvas, rrect[i], insetProcs[j]); + canvas->translate(rrect[i].width() * 5 / 3, 0); + } + canvas->restore(); + canvas->translate(0, rrect[0].height() * 5 / 3); } } diff --git a/include/core/SkRRect.h b/include/core/SkRRect.h index ac2b7a2810..b09d27ac20 100644 --- a/include/core/SkRRect.h +++ b/include/core/SkRRect.h @@ -220,6 +220,7 @@ public: */ bool contains(SkScalar x, SkScalar y) const; +#if 0 void inset(SkScalar dx, SkScalar dy, SkRRect* dst) const; void inset(SkScalar dx, SkScalar dy) { this->inset(dx, dy, this); @@ -230,6 +231,7 @@ public: void outset(SkScalar dx, SkScalar dy) { this->inset(-dx, -dy, this); } +#endif SkDEBUGCODE(void validate() const;) diff --git a/src/core/SkRRect.cpp b/src/core/SkRRect.cpp index 1623984fc6..0d137ec953 100644 --- a/src/core/SkRRect.cpp +++ b/src/core/SkRRect.cpp @@ -228,7 +228,7 @@ void SkRRect::computeType() const { } /////////////////////////////////////////////////////////////////////////////// - +#if 0 void SkRRect::inset(SkScalar dx, SkScalar dy, SkRRect* dst) const { SkRect r = fRect; @@ -244,7 +244,7 @@ void SkRRect::inset(SkScalar dx, SkScalar dy, SkRRect* dst) const { } dst->setRectRadii(r, radii); } - +#endif /////////////////////////////////////////////////////////////////////////////// uint32_t SkRRect::writeToMemory(void* buffer) const { |