2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2014-01-13 14:53:55 +00:00
|
|
|
|
2016-03-18 22:48:49 +00:00
|
|
|
#include "DecodeFile.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SampleCode.h"
|
|
|
|
#include "SkView.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkCornerPathEffect.h"
|
|
|
|
#include "SkGradientShader.h"
|
|
|
|
#include "SkGraphics.h"
|
|
|
|
#include "SkPath.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkRegion.h"
|
|
|
|
#include "SkShader.h"
|
|
|
|
#include "SkUtils.h"
|
|
|
|
#include "SkColorPriv.h"
|
|
|
|
#include "SkColorFilter.h"
|
|
|
|
#include "SkTime.h"
|
|
|
|
#include "SkTypeface.h"
|
|
|
|
#include "SkStream.h"
|
|
|
|
#include "SkColorPriv.h"
|
|
|
|
|
2011-05-05 14:03:48 +00:00
|
|
|
class LinesView : public SampleView {
|
2008-12-17 15:59:43 +00:00
|
|
|
public:
|
2012-08-23 18:19:56 +00:00
|
|
|
LinesView() {}
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
protected:
|
|
|
|
// overrides from SkEventSink
|
2015-07-13 13:18:39 +00:00
|
|
|
bool onQuery(SkEvent* evt) override {
|
2011-05-05 14:03:48 +00:00
|
|
|
if (SampleCode::TitleQ(*evt)) {
|
2008-12-17 15:59:43 +00:00
|
|
|
SampleCode::TitleR(evt, "Lines");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onQuery(evt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
0x1F * x + 0x1F * (32 - x)
|
|
|
|
*/
|
2011-05-05 14:03:48 +00:00
|
|
|
void drawRings(SkCanvas* canvas) {
|
2008-12-17 15:59:43 +00:00
|
|
|
canvas->scale(SkIntToScalar(1)/2, SkIntToScalar(1)/2);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
|
|
|
SkRect r;
|
2008-12-17 15:59:43 +00:00
|
|
|
SkScalar x = SkIntToScalar(10);
|
|
|
|
SkScalar y = SkIntToScalar(10);
|
|
|
|
r.set(x, y, x + SkIntToScalar(100), y + SkIntToScalar(100));
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
SkPaint paint;
|
2010-12-20 18:26:13 +00:00
|
|
|
// paint.setAntiAlias(true);
|
2008-12-17 15:59:43 +00:00
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(SkScalarHalf(SkIntToScalar(3)));
|
|
|
|
paint.setColor(0xFFFF8800);
|
2010-12-20 18:26:13 +00:00
|
|
|
// paint.setColor(0xFFFFFFFF);
|
2008-12-17 15:59:43 +00:00
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2015-07-13 13:18:39 +00:00
|
|
|
void onDrawContent(SkCanvas* canvas) override {
|
2008-12-17 15:59:43 +00:00
|
|
|
SkBitmap bm;
|
2016-03-18 22:48:49 +00:00
|
|
|
decode_file("/kill.gif", &bm);
|
2015-08-27 14:41:13 +00:00
|
|
|
canvas->drawBitmap(bm, 0, 0, nullptr);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
this->drawRings(canvas);
|
|
|
|
return;
|
|
|
|
|
|
|
|
SkPaint paint;
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
// fAlpha = 0x80;
|
|
|
|
paint.setColor(SK_ColorWHITE);
|
|
|
|
paint.setAlpha(fAlpha & 0xFF);
|
|
|
|
SkRect r;
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
SkScalar x = SkIntToScalar(10);
|
|
|
|
SkScalar y = SkIntToScalar(10);
|
|
|
|
r.set(x, y, x + SkIntToScalar(100), y + SkIntToScalar(100));
|
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
return;
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
paint.setColor(0xffffff00); // yellow
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(SkIntToScalar(2));
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
// y += SK_Scalar1/2;
|
|
|
|
|
|
|
|
canvas->drawLine(x, y, x + SkIntToScalar(90), y + SkIntToScalar(90), paint);
|
|
|
|
|
|
|
|
paint.setAntiAlias(true); // with anti-aliasing
|
|
|
|
y += SkIntToScalar(10);
|
|
|
|
canvas->drawLine(x, y, x + SkIntToScalar(90), y + SkIntToScalar(90), paint);
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned) override {
|
2013-12-17 19:22:07 +00:00
|
|
|
fAlpha = SkScalarRoundToInt(y);
|
2015-08-27 14:41:13 +00:00
|
|
|
return nullptr;
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
|
|
|
|
int fAlpha;
|
2011-05-05 14:03:48 +00:00
|
|
|
typedef SampleView INHERITED;
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static SkView* MyFactory() { return new LinesView; }
|
|
|
|
static SkViewRegister reg(MyFactory);
|