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.
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SampleCode.h"
|
|
|
|
#include "SkView.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "Sk64.h"
|
|
|
|
#include "SkCornerPathEffect.h"
|
|
|
|
#include "SkGradientShader.h"
|
|
|
|
#include "SkGraphics.h"
|
|
|
|
#include "SkImageDecoder.h"
|
|
|
|
#include "SkKernel33MaskFilter.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 "SkXfermode.h"
|
|
|
|
|
|
|
|
#include "SkStream.h"
|
|
|
|
#include "SkXMLParser.h"
|
|
|
|
#include "SkColorPriv.h"
|
|
|
|
#include "SkImageDecoder.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
|
2011-05-05 14:03:48 +00:00
|
|
|
virtual bool onQuery(SkEvent* evt) {
|
|
|
|
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
|
|
|
|
2011-05-05 14:03:48 +00:00
|
|
|
virtual void onDrawContent(SkCanvas* canvas) {
|
2008-12-17 15:59:43 +00:00
|
|
|
SkBitmap bm;
|
|
|
|
SkImageDecoder::DecodeFile("/kill.gif", &bm);
|
|
|
|
canvas->drawBitmap(bm, 0, 0, NULL);
|
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);
|
|
|
|
}
|
|
|
|
|
2011-05-05 14:03:48 +00:00
|
|
|
virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) {
|
2008-12-17 15:59:43 +00:00
|
|
|
fAlpha = SkScalarRound(y);
|
|
|
|
this->inval(NULL);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
|