Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(370)

Side by Side Diff: samplecode/SampleBlur.cpp

Issue 253833002: move common blur types into central header (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « samplecode/SampleBigBlur.cpp ('k') | samplecode/SampleEffects.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "SampleCode.h" 8 #include "SampleCode.h"
9 #include "SkBlurMask.h" 9 #include "SkBlurMask.h"
10 #include "SkBlurMaskFilter.h" 10 #include "SkBlurMaskFilter.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 return this->INHERITED::onQuery(evt); 69 return this->INHERITED::onQuery(evt);
70 } 70 }
71 71
72 void drawBG(SkCanvas* canvas) { 72 void drawBG(SkCanvas* canvas) {
73 canvas->drawColor(0xFFDDDDDD); 73 canvas->drawColor(0xFFDDDDDD);
74 } 74 }
75 75
76 virtual void onDrawContent(SkCanvas* canvas) { 76 virtual void onDrawContent(SkCanvas* canvas) {
77 drawBG(canvas); 77 drawBG(canvas);
78 78
79 SkBlurMaskFilter::BlurStyle NONE = SkBlurMaskFilter::BlurStyle(-999); 79 SkBlurStyle NONE = SkBlurStyle(-999);
80 static const struct { 80 static const struct {
81 SkBlurMaskFilter::BlurStyle fStyle; 81 SkBlurStyle fStyle;
82 int fCx, fCy; 82 int fCx, fCy;
83 } gRecs[] = { 83 } gRecs[] = {
84 { NONE, 0, 0 }, 84 { NONE, 0, 0 },
85 { SkBlurMaskFilter::kInner_BlurStyle, -1, 0 }, 85 { kInner_SkBlurStyle, -1, 0 },
86 { SkBlurMaskFilter::kNormal_BlurStyle, 0, 1 }, 86 { kNormal_SkBlurStyle, 0, 1 },
87 { SkBlurMaskFilter::kSolid_BlurStyle, 0, -1 }, 87 { kSolid_SkBlurStyle, 0, -1 },
88 { SkBlurMaskFilter::kOuter_BlurStyle, 1, 0 }, 88 { kOuter_SkBlurStyle, 1, 0 },
89 }; 89 };
90 90
91 SkPaint paint; 91 SkPaint paint;
92 paint.setAntiAlias(true); 92 paint.setAntiAlias(true);
93 paint.setTextSize(25); 93 paint.setTextSize(25);
94 canvas->translate(-40, 0); 94 canvas->translate(-40, 0);
95 95
96 SkBlurMaskFilter::BlurFlags flags = SkBlurMaskFilter::kNone_BlurFlag; 96 SkBlurMaskFilter::BlurFlags flags = SkBlurMaskFilter::kNone_BlurFlag;
97 for (int j = 0; j < 2; j++) { 97 for (int j = 0; j < 2; j++) {
98 canvas->save(); 98 canvas->save();
99 paint.setColor(SK_ColorBLUE); 99 paint.setColor(SK_ColorBLUE);
100 for (size_t i = 0; i < SK_ARRAY_COUNT(gRecs); i++) { 100 for (size_t i = 0; i < SK_ARRAY_COUNT(gRecs); i++) {
101 if (gRecs[i].fStyle != NONE) { 101 if (gRecs[i].fStyle != NONE) {
102 SkMaskFilter* mf = SkBlurMaskFilter::Create(gRecs[i].fStyle, 102 SkMaskFilter* mf = SkBlurMaskFilter::Create(gRecs[i].fStyle,
103 SkBlurMask::ConvertRadiusToSigma(SkIntToSc alar(20)), 103 SkBlurMask::ConvertRadiusToSigma(SkIntToSc alar(20)),
104 flags); 104 flags);
105 paint.setMaskFilter(mf)->unref(); 105 paint.setMaskFilter(mf)->unref();
106 } else { 106 } else {
107 paint.setMaskFilter(NULL); 107 paint.setMaskFilter(NULL);
108 } 108 }
109 canvas->drawCircle(200 + gRecs[i].fCx*100.f, 109 canvas->drawCircle(200 + gRecs[i].fCx*100.f,
110 200 + gRecs[i].fCy*100.f, 50, paint); 110 200 + gRecs[i].fCy*100.f, 50, paint);
111 } 111 }
112 // draw text 112 // draw text
113 { 113 {
114 SkMaskFilter* mf = SkBlurMaskFilter::Create(SkBlurMaskFilter::kN ormal_BlurStyle, 114 SkMaskFilter* mf = SkBlurMaskFilter::Create(kNormal_SkBlurStyle,
115 SkBlurMask::ConvertRadiusToSigma(SkIntToSc alar(4)), 115 SkBlurMask::ConvertRadiusToSigma(SkIntToSc alar(4)),
116 flags); 116 flags);
117 paint.setMaskFilter(mf)->unref(); 117 paint.setMaskFilter(mf)->unref();
118 SkScalar x = SkIntToScalar(70); 118 SkScalar x = SkIntToScalar(70);
119 SkScalar y = SkIntToScalar(400); 119 SkScalar y = SkIntToScalar(400);
120 paint.setColor(SK_ColorBLACK); 120 paint.setColor(SK_ColorBLACK);
121 canvas->drawText("Hamburgefons Style", 18, x, y, paint); 121 canvas->drawText("Hamburgefons Style", 18, x, y, paint);
122 canvas->drawText("Hamburgefons Style", 18, x, y + SkIntToScalar( 50), paint); 122 canvas->drawText("Hamburgefons Style", 18, x, y + SkIntToScalar( 50), paint);
123 paint.setMaskFilter(NULL); 123 paint.setMaskFilter(NULL);
124 paint.setColor(SK_ColorWHITE); 124 paint.setColor(SK_ColorWHITE);
125 x -= SkIntToScalar(2); 125 x -= SkIntToScalar(2);
126 y -= SkIntToScalar(2); 126 y -= SkIntToScalar(2);
127 canvas->drawText("Hamburgefons Style", 18, x, y, paint); 127 canvas->drawText("Hamburgefons Style", 18, x, y, paint);
128 } 128 }
129 canvas->restore(); 129 canvas->restore();
130 flags = SkBlurMaskFilter::kHighQuality_BlurFlag; 130 flags = SkBlurMaskFilter::kHighQuality_BlurFlag;
131 canvas->translate(350, 0); 131 canvas->translate(350, 0);
132 } 132 }
133 } 133 }
134 134
135 private: 135 private:
136 typedef SkView INHERITED; 136 typedef SkView INHERITED;
137 }; 137 };
138 138
139 ////////////////////////////////////////////////////////////////////////////// 139 //////////////////////////////////////////////////////////////////////////////
140 140
141 static SkView* MyFactory() { return new BlurView; } 141 static SkView* MyFactory() { return new BlurView; }
142 static SkViewRegister reg(MyFactory); 142 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « samplecode/SampleBigBlur.cpp ('k') | samplecode/SampleEffects.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698