Chromium Code Reviews| Index: gm/canvasstate.cpp |
| diff --git a/gm/internal_links.cpp b/gm/canvasstate.cpp |
| similarity index 14% |
| copy from gm/internal_links.cpp |
| copy to gm/canvasstate.cpp |
| index 3fdbbd51fc721a2a14b31568d7e5b922da2643c9..19c20c95c517ae1d530ab1f3c887429081fb5342 100644 |
| --- a/gm/internal_links.cpp |
| +++ b/gm/canvasstate.cpp |
| @@ -1,77 +1,143 @@ |
| - |
| /* |
| * Copyright 2013 Google Inc. |
| * |
| * Use of this source code is governed by a BSD-style license that can be |
| * found in the LICENSE file. |
| */ |
| + |
| #include "gm.h" |
| +#include "SkCanvas.h" |
| +#include "SkPaint.h" |
| +#include "SkPath.h" |
| +#include "SkRect.h" |
|
robertphillips
2013/08/13 12:12:32
put this in the skiagm namespace?
djsollen
2013/08/13 13:24:45
Done.
|
|
robertphillips
2013/08/13 12:12:32
// This GM exercises the flags to save(). save() a
djsollen
2013/08/13 13:24:45
Done.
|
| -#include "SkAnnotation.h" |
| -#include "SkData.h" |
| +class CanvasStateGM : public skiagm::GM { |
| + SkSize fSize; |
| + enum { |
| + WIDTH = 150, |
| + HEIGHT = 150, |
| + }; |
| + |
| + SkPaint fFillPaint; |
| + SkPaint fStrokePaint; |
| + |
| + SkPath fPath; |
| + |
| + SkRect fInsetRect; |
| + SkRect fFullRect; |
| -namespace skiagm { |
| -/** Draws two rectangles. In output formats that support internal links (PDF), |
| - * clicking the one labeled "Link to A" should take you to the one labeled |
| - * "Target A". Note that you'll need to zoom your PDF viewer in a fair bit in |
| - * order for the scrolling to not be blocked by the edge of the document. |
| - */ |
| -class InternalLinksGM : public GM { |
| public: |
| - InternalLinksGM() { |
| - this->setBGColor(0xFFDDDDDD); |
| + CanvasStateGM() { |
| + fSize.set(SkIntToScalar(WIDTH), SkIntToScalar(HEIGHT)); |
| + |
| + fFillPaint.setColor(SK_ColorRED); |
| + fFillPaint.setStyle(SkPaint::kFill_Style); |
| + |
| + fStrokePaint.setColor(SK_ColorBLUE); |
| + fStrokePaint.setStyle(SkPaint::kStroke_Style); |
| + fStrokePaint.setStrokeWidth(1); |
| + |
| + fPath.moveTo(25, 25); |
| + fPath.lineTo(125, 25); |
| + fPath.lineTo(75, 125); |
| + fPath.close(); |
| + |
| + fInsetRect = SkRect::MakeXYWH(1, 1, WIDTH-2, HEIGHT-2); |
|
robertphillips
2013/08/13 12:12:32
I'm surprised fFullRect isn't 0,0 -> WIDTH,HEIGHT
|
| + fFullRect = SkRect::MakeXYWH(10, 10, WIDTH-20, HEIGHT-20); |
| } |
| protected: |
|
robertphillips
2013/08/13 12:12:32
SK_OVERRIDE?
|
| virtual SkString onShortName() { |
| - return SkString("internal_links"); |
| + return SkString("canvas-state"); |
| } |
|
robertphillips
2013/08/13 12:12:32
SK_OVERRIDE?
|
| virtual SkISize onISize() { |
| - return make_isize(700, 500); |
| + return SkISize::Make(960, 1200); |
| } |
|
robertphillips
2013/08/13 12:12:32
SK_OVERRIDE?
|
| virtual void onDraw(SkCanvas* canvas) { |
| - SkAutoTUnref<SkData> name(SkData::NewWithCString("target-a")); |
| canvas->save(); |
| - canvas->translate(SkIntToScalar(100), SkIntToScalar(100)); |
| - drawLabeledRect(canvas, "Link to A", 0, 0); |
| - SkRect rect = SkRect::MakeXYWH(0, 0, SkIntToScalar(50), SkIntToScalar(20)); |
| - SkAnnotateLinkToDestination(canvas, rect, name.get()); |
| + |
| + // [0,0] -- red triangle |
| + // test that we don't drop the clip since we are not setting the clip bit |
|
robertphillips
2013/08/13 12:12:32
Would it make sense to encapsulate all these in:
|
| + canvas->drawRect(fInsetRect, fStrokePaint); |
| + canvas->save(SkCanvas::kMatrix_SaveFlag); |
| + canvas->clipPath(fPath); |
| canvas->restore(); |
| + canvas->drawRect(fFullRect, fFillPaint); |
| + canvas->restore(); |
| canvas->save(); |
| - canvas->translate(SkIntToScalar(200), SkIntToScalar(200)); |
| - SkPoint point = SkPoint::Make(SkIntToScalar(100), SkIntToScalar(50)); |
| - drawLabeledRect(canvas, "Target A", point.x(), point.y()); |
| - SkAnnotateNamedDestination(canvas, point, name.get()); |
| + canvas->translate(WIDTH, 0); |
| + |
| + // [0,1] -- red box |
| + // test that we drop the clip since we are setting the clip bit |
| + canvas->drawRect(fInsetRect, fStrokePaint); |
| + canvas->save(SkCanvas::kClip_SaveFlag); |
| + canvas->clipPath(fPath); |
| canvas->restore(); |
| - } |
| + canvas->drawRect(fFullRect, fFillPaint); |
| -private: |
| - /** Draw an arbitrary rectangle at a given location and label it with some |
| - * text. */ |
| - void drawLabeledRect(SkCanvas* canvas, const char* text, SkScalar x, SkScalar y) { |
| - SkPaint paint; |
| - paint.setColor(SK_ColorBLUE); |
| - SkRect rect = SkRect::MakeXYWH(x, y, |
| - SkIntToScalar(50), SkIntToScalar(20)); |
| - canvas->drawRect(rect, paint); |
| - |
| - paint.setAntiAlias(true); |
| - paint.setTextSize(SkIntToScalar(25)); |
| - paint.setColor(SK_ColorBLACK); |
| - canvas->drawText(text, strlen(text), x, y, paint); |
| + canvas->restore(); |
| + canvas->save(); |
| + canvas->translate(0, HEIGHT); |
| + |
| + // [1,0] -- red box in uppper left |
| + // test that we don't drop the matrix since we are not setting the matrix bit |
| + canvas->drawRect(fInsetRect, fStrokePaint); |
| + canvas->save(SkCanvas::kClip_SaveFlag); |
| + canvas->scale(0.5, 0.5); |
| + canvas->restore(); |
| + canvas->drawRect(fFullRect, fFillPaint); |
| + |
| + canvas->restore(); |
| + canvas->save(); |
| + canvas->translate(WIDTH, HEIGHT); |
| + |
| + // [1,1] -- red box |
| + // test that we drop the matrix since we are setting the matrix bit |
| + canvas->drawRect(fInsetRect, fStrokePaint); |
| + canvas->save(SkCanvas::kMatrix_SaveFlag); |
| + canvas->scale(0.5, 0.5); |
| + canvas->restore(); |
| + canvas->drawRect(fFullRect, fFillPaint); |
| + |
| + canvas->restore(); |
| + canvas->save(); |
| + canvas->translate(0, 2*HEIGHT); |
| + |
| + // [2,0] -- red box in upper left |
| + // test that we drop the clip but not matrix |
| + canvas->drawRect(fInsetRect, fStrokePaint); |
| + canvas->save(SkCanvas::kClip_SaveFlag); |
| + canvas->clipPath(fPath); |
| + canvas->scale(0.5, 0.5); |
| + canvas->restore(); |
| + canvas->drawRect(fFullRect, fFillPaint); |
| + |
| + canvas->restore(); |
| + canvas->save(); |
| + canvas->translate(WIDTH, 2*HEIGHT); |
| + |
| + // [2,1] -- red triangle |
| + // test that we drop the matrix but not the clip |
| + canvas->drawRect(fInsetRect, fStrokePaint); |
| + canvas->save(SkCanvas::kMatrix_SaveFlag); |
| + canvas->clipPath(fPath); |
| + canvas->scale(0.5, 0.5); |
| + canvas->restore(); |
| + canvas->drawRect(fFullRect, fFillPaint); |
| + |
| + canvas->restore(); |
| } |
| - typedef GM INHERITED; |
| +private: |
| + typedef skiagm::GM INHERITED; |
| }; |
| ////////////////////////////////////////////////////////////////////////////// |
|
robertphillips
2013/08/13 12:12:32
DEF_GM?
|
| -static GM* MyFactory(void*) { return SkNEW(InternalLinksGM); } |
| -static GMRegistry reg(MyFactory); |
| - |
| -} |
| +static skiagm::GM* MyFactory(void*) { return new CanvasStateGM; } |
| +static skiagm::GMRegistry reg(MyFactory); |