SampleStrokeRect.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright 2011 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "include/core/SkCanvas.h"
  8. #include "include/core/SkPaint.h"
  9. #include "samplecode/Sample.h"
  10. class StrokeRectSample : public Sample {
  11. public:
  12. StrokeRectSample() {}
  13. protected:
  14. virtual SkString name() { return SkString("Stroke Rects"); }
  15. virtual void onDrawContent(SkCanvas* canvas) {
  16. SkPaint paint;
  17. paint.setAntiAlias(true);
  18. paint.setStyle(SkPaint::kStroke_Style);
  19. paint.setStrokeWidth(SkIntToScalar(20));
  20. SkPaint hair;
  21. hair.setStyle(SkPaint::kStroke_Style);
  22. hair.setColor(SK_ColorRED);
  23. static const SkISize gSize[] = {
  24. { 100, 50 },
  25. { 100, 0 },
  26. { 0, 50 },
  27. { 0, 0 }
  28. };
  29. static const SkPaint::Join gJoin[] = {
  30. SkPaint::kMiter_Join,
  31. SkPaint::kRound_Join,
  32. SkPaint::kBevel_Join
  33. };
  34. canvas->translate(paint.getStrokeWidth(), paint.getStrokeWidth());
  35. for (size_t i = 0; i < SK_ARRAY_COUNT(gJoin); ++i) {
  36. paint.setStrokeJoin(gJoin[i]);
  37. canvas->save();
  38. for (size_t j = 0; j < SK_ARRAY_COUNT(gSize); ++j) {
  39. SkRect r = SkRect::MakeWH(SkIntToScalar(gSize[j].fWidth),
  40. SkIntToScalar(gSize[j].fHeight));
  41. canvas->drawRect(r, paint);
  42. canvas->drawRect(r, hair);
  43. canvas->translate(0, SkIntToScalar(100));
  44. }
  45. canvas->restore();
  46. canvas->translate(SkIntToScalar(150), 0);
  47. }
  48. }
  49. private:
  50. typedef Sample INHERITED;
  51. };
  52. ///////////////////////////////////////////////////////////////////////////////
  53. DEF_SAMPLE( return new StrokeRectSample(); )