Skip to content

Commit

Permalink
draw 3 moveTos followed by various others [moves, lines, closes]
Browse files Browse the repository at this point in the history
  • Loading branch information
reed-at-google authored and Commit bot committed Sep 4, 2015
1 parent f4a6d30 commit 58e524c
Showing 1 changed file with 77 additions and 2 deletions.
79 changes: 77 additions & 2 deletions gm/emptypath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,85 @@ class EmptyPathGM : public GM {
private:
typedef GM INHERITED;
};
DEF_GM( return new EmptyPathGM; )

//////////////////////////////////////////////////////////////////////////////

static GM* MyFactory(void*) { return new EmptyPathGM; }
static GMRegistry reg(MyFactory);
static void make_path_move(SkPath* path, const SkPoint pts[3]) {
for (int i = 0; i < 3; ++i) {
path->moveTo(pts[i]);
}
}

static void make_path_move_close(SkPath* path, const SkPoint pts[3]) {
for (int i = 0; i < 3; ++i) {
path->moveTo(pts[i]);
path->close();
}
}

static void make_path_move_line(SkPath* path, const SkPoint pts[3]) {
for (int i = 0; i < 3; ++i) {
path->moveTo(pts[i]);
path->lineTo(pts[i]);
}
}

typedef void (*MakePathProc)(SkPath*, const SkPoint pts[3]);

static void make_path_move_mix(SkPath* path, const SkPoint pts[3]) {
path->moveTo(pts[0]);
path->moveTo(pts[1]); path->close();
path->moveTo(pts[2]); path->lineTo(pts[2]);
}

class EmptyStrokeGM : public GM {
SkPoint fPts[3];

public:
EmptyStrokeGM() {
fPts[0].set(40, 40);
fPts[1].set(80, 40);
fPts[2].set(120, 40);
}

protected:
SkString onShortName() {
return SkString("emptystroke");
}

SkISize onISize() override { return SkISize::Make(200, 240); }

void onDraw(SkCanvas* canvas) override {
const MakePathProc procs[] = {
make_path_move, // expect red red red
make_path_move_close, // expect black black black
make_path_move_line, // expect black black black
make_path_move_mix, // expect red black black,
};

SkPaint strokePaint;
strokePaint.setStyle(SkPaint::kStroke_Style);
strokePaint.setStrokeWidth(21);
strokePaint.setStrokeCap(SkPaint::kSquare_Cap);

SkPaint dotPaint;
dotPaint.setColor(SK_ColorRED);
strokePaint.setStyle(SkPaint::kStroke_Style);
dotPaint.setStrokeWidth(7);

for (size_t i = 0; i < SK_ARRAY_COUNT(procs); ++i) {
SkPath path;
procs[i](&path, fPts);
canvas->drawPoints(SkCanvas::kPoints_PointMode, 3, fPts, dotPaint);
canvas->drawPath(path, strokePaint);
canvas->translate(0, 40);
}
}

private:
typedef GM INHERITED;
};
DEF_GM( return new EmptyStrokeGM; )

}

0 comments on commit 58e524c

Please sign in to comment.