Home | History | Annotate | Download | only in samplecode
      1 
      2 /*
      3  * Copyright 2011 Google Inc.
      4  *
      5  * Use of this source code is governed by a BSD-style license that can be
      6  * found in the LICENSE file.
      7  */
      8 #include "SampleCode.h"
      9 #include "SkView.h"
     10 #include "SkCanvas.h"
     11 #include "SkDevice.h"
     12 #include "SkPaint.h"
     13 
     14 class StrokeRectSample : public SampleView {
     15 public:
     16     StrokeRectSample() {}
     17 
     18 protected:
     19     // overrides from SkEventSink
     20     virtual bool onQuery(SkEvent* evt) {
     21         if (SampleCode::TitleQ(*evt)) {
     22             SampleCode::TitleR(evt, "Stroke Rects");
     23             return true;
     24         }
     25         return this->INHERITED::onQuery(evt);
     26     }
     27 
     28     virtual void onDrawContent(SkCanvas* canvas) {
     29         SkPaint paint;
     30         paint.setAntiAlias(true);
     31         paint.setStyle(SkPaint::kStroke_Style);
     32         paint.setStrokeWidth(SkIntToScalar(20));
     33 
     34         SkPaint hair;
     35         hair.setStyle(SkPaint::kStroke_Style);
     36         hair.setColor(SK_ColorRED);
     37 
     38         static const SkISize gSize[] = {
     39             {   100,   50 },
     40             {   100,    0 },
     41             {     0,   50 },
     42             {     0,    0 }
     43         };
     44 
     45         static const SkPaint::Join gJoin[] = {
     46             SkPaint::kMiter_Join,
     47             SkPaint::kRound_Join,
     48             SkPaint::kBevel_Join
     49         };
     50 
     51         canvas->translate(paint.getStrokeWidth(), paint.getStrokeWidth());
     52         for (size_t i = 0; i < SK_ARRAY_COUNT(gJoin); ++i) {
     53             paint.setStrokeJoin(gJoin[i]);
     54 
     55             canvas->save();
     56             for (size_t j = 0; j < SK_ARRAY_COUNT(gSize); ++j) {
     57                 SkRect r = SkRect::MakeWH(SkIntToScalar(gSize[j].fWidth),
     58                                           SkIntToScalar(gSize[j].fHeight));
     59                 canvas->drawRect(r, paint);
     60                 canvas->drawRect(r, hair);
     61                 canvas->translate(0, SkIntToScalar(100));
     62             }
     63             canvas->restore();
     64             canvas->translate(SkIntToScalar(150), 0);
     65         }
     66     }
     67 
     68 private:
     69     typedef SampleView INHERITED;
     70 };
     71 
     72 ///////////////////////////////////////////////////////////////////////////////
     73 
     74 static SkView* MyFactory() { return new StrokeRectSample; }
     75 static SkViewRegister reg(MyFactory);
     76