SampleEmboss.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. #include "include/core/SkCanvas.h"
  8. #include "include/core/SkColorFilter.h"
  9. #include "include/core/SkColorPriv.h"
  10. #include "include/core/SkGraphics.h"
  11. #include "include/core/SkPath.h"
  12. #include "include/core/SkRegion.h"
  13. #include "include/core/SkShader.h"
  14. #include "include/core/SkTime.h"
  15. #include "include/core/SkTypeface.h"
  16. #include "include/effects/SkGradientShader.h"
  17. #include "include/utils/SkRandom.h"
  18. #include "samplecode/Sample.h"
  19. #include "src/core/SkBlurMask.h"
  20. #include "src/effects/SkEmbossMaskFilter.h"
  21. #include "src/utils/SkUTF.h"
  22. class EmbossView : public Sample {
  23. SkEmbossMaskFilter::Light fLight;
  24. public:
  25. EmbossView() {
  26. fLight.fDirection[0] = SK_Scalar1;
  27. fLight.fDirection[1] = SK_Scalar1;
  28. fLight.fDirection[2] = SK_Scalar1;
  29. fLight.fAmbient = 128;
  30. fLight.fSpecular = 16*2;
  31. }
  32. protected:
  33. virtual SkString name() { return SkString("Emboss"); }
  34. virtual void onDrawContent(SkCanvas* canvas) {
  35. SkPaint paint;
  36. paint.setAntiAlias(true);
  37. paint.setStyle(SkPaint::kStroke_Style);
  38. paint.setStrokeWidth(SkIntToScalar(10));
  39. paint.setMaskFilter(SkEmbossMaskFilter::Make(SkBlurMask::ConvertRadiusToSigma(4), fLight));
  40. paint.setShader(SkShaders::Color(SK_ColorBLUE));
  41. paint.setDither(true);
  42. canvas->drawCircle(SkIntToScalar(50), SkIntToScalar(50),
  43. SkIntToScalar(30), paint);
  44. }
  45. private:
  46. typedef Sample INHERITED;
  47. };
  48. //////////////////////////////////////////////////////////////////////////////
  49. DEF_SAMPLE( return new EmbossView(); )