aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--samplecode/SampleEffects.cpp113
-rw-r--r--xcode/sampleapp/SampleApp.xcodeproj/project.pbxproj8
2 files changed, 119 insertions, 2 deletions
diff --git a/samplecode/SampleEffects.cpp b/samplecode/SampleEffects.cpp
new file mode 100644
index 0000000000..507f727228
--- /dev/null
+++ b/samplecode/SampleEffects.cpp
@@ -0,0 +1,113 @@
+#include "SampleCode.h"
+#include "SkCanvas.h"
+#include "SkPaint.h"
+#include "SkPorterDuff.h"
+#include "SkView.h"
+
+#include "SkBlurMaskFilter.h"
+#include "SkColorMatrixFilter.h"
+#include "SkDiscretePathEffect.h"
+#include "SkGradientShader.h"
+
+//#define COLOR 0xFFFF8844
+#define COLOR 0xFF888888
+
+static void paint_proc0(SkPaint* paint) {
+}
+
+static void paint_proc1(SkPaint* paint) {
+ paint->setMaskFilter(SkBlurMaskFilter::Create(2,
+ SkBlurMaskFilter::kNormal_BlurStyle))->unref();
+}
+
+static void paint_proc2(SkPaint* paint) {
+ SkScalar dir[3] = { 1, 1, 1};
+ paint->setMaskFilter(
+ SkBlurMaskFilter::CreateEmboss(dir, 0.1, 0.05, 1))->unref();
+}
+
+static void paint_proc3(SkPaint* paint) {
+ SkColor colors[] = { SK_ColorRED, COLOR, SK_ColorBLUE };
+ SkPoint pts[] = { 3, 0, 7, 5 };
+ paint->setShader(SkGradientShader::CreateLinear(pts, colors, NULL, SK_ARRAY_COUNT(colors),
+ SkShader::kMirror_TileMode))->unref();
+}
+
+static void paint_proc5(SkPaint* paint) {
+ paint_proc3(paint);
+ paint_proc2(paint);
+}
+
+typedef void (*PaintProc)(SkPaint*);
+const PaintProc gPaintProcs[] = {
+ paint_proc0,
+ paint_proc1,
+ paint_proc2,
+ paint_proc3,
+ paint_proc5,
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+class EffectsView : public SkView {
+public:
+ SkPath fPath;
+ SkPaint fPaint[SK_ARRAY_COUNT(gPaintProcs)];
+
+ EffectsView() {
+ size_t i;
+ const float pts[] = {
+ 0, 0,
+ 10, 0,
+ 10, 5,
+ 20, -5,
+ 10, -15,
+ 10, -10,
+ 0, -10
+ };
+ fPath.moveTo(pts[0], pts[1]);
+ for (i = 2; i < SK_ARRAY_COUNT(pts); i += 2) {
+ fPath.lineTo(pts[i], pts[i+1]);
+ }
+
+ for (i = 0; i < SK_ARRAY_COUNT(gPaintProcs); i++) {
+ fPaint[i].setAntiAlias(true);
+ fPaint[i].setColor(COLOR);
+ gPaintProcs[i](&fPaint[i]);
+ }
+ }
+
+protected:
+ // overrides from SkEventSink
+ virtual bool onQuery(SkEvent* evt) {
+ if (SampleCode::TitleQ(*evt)) {
+ SampleCode::TitleR(evt, "Effects");
+ return true;
+ }
+ return this->INHERITED::onQuery(evt);
+ }
+
+ void drawBG(SkCanvas* canvas) {
+ canvas->drawColor(0xFFDDDDDD);
+ }
+
+ virtual void onDraw(SkCanvas* canvas) {
+ this->drawBG(canvas);
+
+ canvas->scale(3, 3);
+ canvas->translate(10, 30);
+ for (size_t i = 0; i < SK_ARRAY_COUNT(fPaint); i++) {
+ canvas->drawPath(fPath, fPaint[i]);
+ canvas->translate(32, 0);
+ }
+ }
+
+private:
+ typedef SkView INHERITED;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+static SkView* MyFactory() { return new EffectsView; }
+static SkViewRegister reg(MyFactory);
+
diff --git a/xcode/sampleapp/SampleApp.xcodeproj/project.pbxproj b/xcode/sampleapp/SampleApp.xcodeproj/project.pbxproj
index 70732da691..218a039492 100644
--- a/xcode/sampleapp/SampleApp.xcodeproj/project.pbxproj
+++ b/xcode/sampleapp/SampleApp.xcodeproj/project.pbxproj
@@ -73,6 +73,7 @@
009490320FB0A5B90063C792 /* SampleLayerMask.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 009490310FB0A5B90063C792 /* SampleLayerMask.cpp */; };
009CC9190F65918A002185BE /* SampleFontScalerTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 009CC9180F65918A002185BE /* SampleFontScalerTest.cpp */; };
00A41E4B0EFC312F00C9CBEB /* SampleArc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 00A41E4A0EFC312F00C9CBEB /* SampleArc.cpp */; };
+ 00A8A3EE0FC25993006ED638 /* SampleEffects.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 00A8A3ED0FC25993006ED638 /* SampleEffects.cpp */; };
00C55DA10F8552DC000CAC09 /* SampleGradients.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 00C55DA00F8552DC000CAC09 /* SampleGradients.cpp */; };
0156F80407C56A3000C6122B /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0156F80307C56A3000C6122B /* Foundation.framework */; };
01FC44D507BD3BB800D228F4 /* Quartz.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 01FC44D407BD3BB800D228F4 /* Quartz.framework */; };
@@ -197,6 +198,7 @@
009490310FB0A5B90063C792 /* SampleLayerMask.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SampleLayerMask.cpp; path = ../../samplecode/SampleLayerMask.cpp; sourceTree = SOURCE_ROOT; };
009CC9180F65918A002185BE /* SampleFontScalerTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SampleFontScalerTest.cpp; path = ../../samplecode/SampleFontScalerTest.cpp; sourceTree = SOURCE_ROOT; };
00A41E4A0EFC312F00C9CBEB /* SampleArc.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SampleArc.cpp; path = ../../samplecode/SampleArc.cpp; sourceTree = SOURCE_ROOT; };
+ 00A8A3ED0FC25993006ED638 /* SampleEffects.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SampleEffects.cpp; path = ../../samplecode/SampleEffects.cpp; sourceTree = SOURCE_ROOT; };
00C55DA00F8552DC000CAC09 /* SampleGradients.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SampleGradients.cpp; path = ../../samplecode/SampleGradients.cpp; sourceTree = SOURCE_ROOT; };
00D6B5CB0F72DC4300C466B9 /* SampleFuzz.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SampleFuzz.cpp; path = ../../samplecode/SampleFuzz.cpp; sourceTree = SOURCE_ROOT; };
0156F80307C56A3000C6122B /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
@@ -235,6 +237,7 @@
00D6B5CB0F72DC4300C466B9 /* SampleFuzz.cpp */,
00C55DA00F8552DC000CAC09 /* SampleGradients.cpp */,
009490310FB0A5B90063C792 /* SampleLayerMask.cpp */,
+ 00A8A3ED0FC25993006ED638 /* SampleEffects.cpp */,
003145310FB9B48F00B10956 /* SampleShapes.cpp */,
009CC9180F65918A002185BE /* SampleFontScalerTest.cpp */,
007A7CA50F01658C00A2D6EE /* SamplePoints.cpp */,
@@ -487,7 +490,6 @@
files = (
00003C660EFC22A8000FF73A /* SampleApp.cpp in Sources */,
00003C680EFC22A8000FF73A /* SamplePath.cpp in Sources */,
- 00003C690EFC22A8000FF73A /* SamplePathEffects.cpp in Sources */,
00003C740EFC22CE000FF73A /* SkEvent.cpp in Sources */,
00003C750EFC22CE000FF73A /* SkEventSink.cpp in Sources */,
00003C760EFC22CE000FF73A /* SkMetaData.cpp in Sources */,
@@ -530,7 +532,6 @@
007A7CB80F01658C00A2D6EE /* SampleStrokeText.cpp in Sources */,
007A7CBA0F01658C00A2D6EE /* SampleText.cpp in Sources */,
007A7CBB0F01658C00A2D6EE /* SampleTextAlpha.cpp in Sources */,
- 007A7CBC0F01658C00A2D6EE /* SampleTextEffects.cpp in Sources */,
007A7CBD0F01658C00A2D6EE /* SampleTextOnPath.cpp in Sources */,
007A7CBE0F01658C00A2D6EE /* SampleTiling.cpp in Sources */,
007A7CBF0F01658C00A2D6EE /* SampleTypeface.cpp in Sources */,
@@ -549,6 +550,9 @@
003145200FB99CCE00B10956 /* SkRectShape.cpp in Sources */,
003145320FB9B48F00B10956 /* SampleShapes.cpp in Sources */,
003145370FB9BA4000B10956 /* SkGroupShape.cpp in Sources */,
+ 007A7CBC0F01658C00A2D6EE /* SampleTextEffects.cpp in Sources */,
+ 00003C690EFC22A8000FF73A /* SamplePathEffects.cpp in Sources */,
+ 00A8A3EE0FC25993006ED638 /* SampleEffects.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};