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
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SampleCode.h"
|
2013-09-06 14:16:12 +00:00
|
|
|
#include "SkBlurMask.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SkView.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkEmbossMaskFilter.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"
|
|
|
|
|
2011-05-05 14:03:48 +00:00
|
|
|
class EmbossView : public SampleView {
|
2008-12-17 15:59:43 +00:00
|
|
|
SkEmbossMaskFilter::Light fLight;
|
|
|
|
public:
|
2012-08-23 18:19:56 +00:00
|
|
|
EmbossView() {
|
2008-12-17 15:59:43 +00:00
|
|
|
fLight.fDirection[0] = SK_Scalar1;
|
|
|
|
fLight.fDirection[1] = SK_Scalar1;
|
|
|
|
fLight.fDirection[2] = SK_Scalar1;
|
|
|
|
fLight.fAmbient = 128;
|
|
|
|
fLight.fSpecular = 16*2;
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
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, "Emboss");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onQuery(evt);
|
|
|
|
}
|
|
|
|
|
2011-05-05 14:03:48 +00:00
|
|
|
virtual void onDrawContent(SkCanvas* canvas) {
|
2008-12-17 15:59:43 +00:00
|
|
|
SkPaint paint;
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(SkIntToScalar(10));
|
2016-04-04 17:02:58 +00:00
|
|
|
paint.setMaskFilter(SkEmbossMaskFilter::Make(SkBlurMask::ConvertRadiusToSigma(4), fLight));
|
2016-03-25 16:08:00 +00:00
|
|
|
paint.setShader(SkShader::MakeColorShader(SK_ColorBLUE));
|
2008-12-17 15:59:43 +00:00
|
|
|
paint.setDither(true);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
canvas->drawCircle(SkIntToScalar(50), SkIntToScalar(50),
|
|
|
|
SkIntToScalar(30), paint);
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
private:
|
|
|
|
|
2011-05-05 14:03:48 +00:00
|
|
|
typedef SampleView INHERITED;
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static SkView* MyFactory() { return new EmbossView; }
|
|
|
|
static SkViewRegister reg(MyFactory);
|