Home | History | Annotate | Download | only in samplecode
      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 
      8 #include "DecodeFile.h"
      9 #include "SampleCode.h"
     10 #include "SkView.h"
     11 #include "SkCanvas.h"
     12 #include "SkCornerPathEffect.h"
     13 #include "SkGradientShader.h"
     14 #include "SkGraphics.h"
     15 #include "SkPath.h"
     16 #include "SkRandom.h"
     17 #include "SkRegion.h"
     18 #include "SkShader.h"
     19 #include "SkUtils.h"
     20 #include "SkColorPriv.h"
     21 #include "SkColorFilter.h"
     22 #include "SkTime.h"
     23 #include "SkTypeface.h"
     24 #include "SkStream.h"
     25 #include "SkColorPriv.h"
     26 
     27 class LinesView : public SampleView {
     28 public:
     29     LinesView() {}
     30 
     31 protected:
     32     // overrides from SkEventSink
     33     bool onQuery(SkEvent* evt) override {
     34         if (SampleCode::TitleQ(*evt)) {
     35             SampleCode::TitleR(evt, "Lines");
     36             return true;
     37         }
     38         return this->INHERITED::onQuery(evt);
     39     }
     40 
     41     /*
     42      0x1F * x + 0x1F * (32 - x)
     43      */
     44     void drawRings(SkCanvas* canvas) {
     45         canvas->scale(SkIntToScalar(1)/2, SkIntToScalar(1)/2);
     46 
     47         SkRect  r;
     48         SkScalar x = SkIntToScalar(10);
     49         SkScalar y = SkIntToScalar(10);
     50         r.set(x, y, x + SkIntToScalar(100), y + SkIntToScalar(100));
     51 
     52         SkPaint paint;
     53      //   paint.setAntiAlias(true);
     54         paint.setStyle(SkPaint::kStroke_Style);
     55         paint.setStrokeWidth(SkScalarHalf(SkIntToScalar(3)));
     56         paint.setColor(0xFFFF8800);
     57      //   paint.setColor(0xFFFFFFFF);
     58         canvas->drawRect(r, paint);
     59     }
     60 
     61     void onDrawContent(SkCanvas* canvas) override {
     62         SkBitmap bm;
     63         decode_file("/kill.gif", &bm);
     64         canvas->drawBitmap(bm, 0, 0, nullptr);
     65 
     66         this->drawRings(canvas);
     67         return;
     68 
     69         SkPaint paint;
     70 
     71       //  fAlpha = 0x80;
     72         paint.setColor(SK_ColorWHITE);
     73         paint.setAlpha(fAlpha & 0xFF);
     74         SkRect r;
     75 
     76         SkScalar x = SkIntToScalar(10);
     77         SkScalar y = SkIntToScalar(10);
     78         r.set(x, y, x + SkIntToScalar(100), y + SkIntToScalar(100));
     79         canvas->drawRect(r, paint);
     80         return;
     81 
     82         paint.setColor(0xffffff00);            // yellow
     83         paint.setStyle(SkPaint::kStroke_Style);
     84         paint.setStrokeWidth(SkIntToScalar(2));
     85 
     86 //        y += SK_Scalar1/2;
     87 
     88         canvas->drawLine(x, y, x + SkIntToScalar(90), y + SkIntToScalar(90), paint);
     89 
     90         paint.setAntiAlias(true);              // with anti-aliasing
     91         y += SkIntToScalar(10);
     92         canvas->drawLine(x, y, x + SkIntToScalar(90), y + SkIntToScalar(90), paint);
     93     }
     94 
     95     SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned) override {
     96         fAlpha = SkScalarRoundToInt(y);
     97         this->inval(nullptr);
     98         return nullptr;
     99     }
    100 private:
    101 
    102     int fAlpha;
    103     typedef SampleView INHERITED;
    104 };
    105 
    106 //////////////////////////////////////////////////////////////////////////////
    107 
    108 static SkView* MyFactory() { return new LinesView; }
    109 static SkViewRegister reg(MyFactory);
    110