1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/*
2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2011 Google Inc.
3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com *
4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be
5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file.
6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com */
7bf0001d0472d727266762c5967ec0d919a6df083reed@google.com
88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SampleCode.h"
9b7061176c7f414616fe2e79e832b3e0abe326af6robertphillips@google.com#include "SkBlurMask.h"
108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkView.h"
118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkCanvas.h"
128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkColorShader.h"
138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkEmbossMaskFilter.h"
148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkGradientShader.h"
158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkGraphics.h"
168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkImageDecoder.h"
178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPath.h"
188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRandom.h"
198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRegion.h"
208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkShader.h"
218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkUtils.h"
228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkColorPriv.h"
238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkColorFilter.h"
248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkTime.h"
258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkTypeface.h"
268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkXfermode.h"
278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
28961ddb04a0a7aba843032d829ab867518e52559ereed@google.comclass EmbossView : public SampleView {
298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkEmbossMaskFilter::Light   fLight;
308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
31ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com    EmbossView() {
328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        fLight.fDirection[0] = SK_Scalar1;
338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        fLight.fDirection[1] = SK_Scalar1;
348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        fLight.fDirection[2] = SK_Scalar1;
358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        fLight.fAmbient = 128;
368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        fLight.fSpecular = 16*2;
378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
38ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com
398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected:
408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // overrides from SkEventSink
41961ddb04a0a7aba843032d829ab867518e52559ereed@google.com    virtual bool onQuery(SkEvent* evt) {
42961ddb04a0a7aba843032d829ab867518e52559ereed@google.com        if (SampleCode::TitleQ(*evt)) {
438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            SampleCode::TitleR(evt, "Emboss");
448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            return true;
458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        }
468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        return this->INHERITED::onQuery(evt);
478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
49961ddb04a0a7aba843032d829ab867518e52559ereed@google.com    virtual void onDrawContent(SkCanvas* canvas) {
508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkPaint paint;
51ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com
528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint.setAntiAlias(true);
538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint.setStyle(SkPaint::kStroke_Style);
548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint.setStrokeWidth(SkIntToScalar(10));
557c9d0f3104408a64d52b84643f116179022d73bdcommit-bot@chromium.org        paint.setMaskFilter(SkEmbossMaskFilter::Create(
56b7061176c7f414616fe2e79e832b3e0abe326af6robertphillips@google.com            SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(4)), fLight))->unref();
578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint.setShader(new SkColorShader(SK_ColorBLUE))->unref();
588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        paint.setDither(true);
59ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com
608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        canvas->drawCircle(SkIntToScalar(50), SkIntToScalar(50),
618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                           SkIntToScalar(30), paint);
628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
63ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com
648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate:
658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
66961ddb04a0a7aba843032d829ab867518e52559ereed@google.com    typedef SampleView INHERITED;
678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com//////////////////////////////////////////////////////////////////////////////
708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic SkView* MyFactory() { return new EmbossView; }
728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstatic SkViewRegister reg(MyFactory);
73