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

Side by Side Diff: samplecode/SampleCircle.cpp

Issue 2142033002: Factor code to rotate a canvas about a point. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Move to canvas. Created 4 years, 5 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
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SampleCode.h" 8 #include "SampleCode.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkPaint.h" 10 #include "SkPaint.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 SkScalar step = SK_ScalarPI * 2 / n; 80 SkScalar step = SK_ScalarPI * 2 / n;
81 SkScalar angle = 0; 81 SkScalar angle = 0;
82 for (int i = 1; i < n; i++) { 82 for (int i = 1; i < n; i++) {
83 angle += step; 83 angle += step;
84 SkScalar c, s = SkScalarSinCos(angle, &c); 84 SkScalar c, s = SkScalarSinCos(angle, &c);
85 path->lineTo(c, s); 85 path->lineTo(c, s);
86 } 86 }
87 path->close(); 87 path->close();
88 } 88 }
89 89
90 static void rotate(SkCanvas* canvas, SkScalar angle, SkScalar px, SkScalar p y) {
91 canvas->translate(-px, -py);
92 canvas->rotate(angle);
93 canvas->translate(px, py);
94 }
95
96 virtual void onDrawContent(SkCanvas* canvas) { 90 virtual void onDrawContent(SkCanvas* canvas) {
97 SkPaint paint; 91 SkPaint paint;
98 paint.setAntiAlias(true); 92 paint.setAntiAlias(true);
99 paint.setStyle(SkPaint::kStroke_Style); 93 paint.setStyle(SkPaint::kStroke_Style);
100 // canvas->drawCircle(250, 250, 220, paint);
101 SkMatrix matrix; 94 SkMatrix matrix;
102 matrix.setScale(SkIntToScalar(100), SkIntToScalar(100)); 95 matrix.setScale(SkIntToScalar(100), SkIntToScalar(100));
103 matrix.postTranslate(SkIntToScalar(200), SkIntToScalar(200)); 96 matrix.postTranslate(SkIntToScalar(200), SkIntToScalar(200));
104 canvas->concat(matrix); 97 canvas->concat(matrix);
105 for (int n = 3; n < 20; n++) { 98 for (int n = 3; n < 20; n++) {
106 SkPath path; 99 SkPath path;
107 make_poly(&path, n); 100 make_poly(&path, n);
108 SkAutoCanvasRestore acr(canvas, true); 101 SkAutoCanvasRestore acr(canvas, true);
109 canvas->rotate(SkIntToScalar(10) * (n - 3)); 102 canvas->rotate(SkIntToScalar(10) * (n - 3));
110 canvas->translate(-SK_Scalar1, 0); 103 canvas->translate(-SK_Scalar1, 0);
111 canvas->drawPath(path, paint); 104 canvas->drawPath(path, paint);
112 } 105 }
113 } 106 }
114 107
115 private: 108 private:
116 int fN; 109 int fN;
117 typedef SampleView INHERITED; 110 typedef SampleView INHERITED;
118 }; 111 };
119 112
120 const SkScalar CircleView::ANIM_DX(SK_Scalar1 / 67); 113 const SkScalar CircleView::ANIM_DX(SK_Scalar1 / 67);
121 const SkScalar CircleView::ANIM_DY(SK_Scalar1 / 29); 114 const SkScalar CircleView::ANIM_DY(SK_Scalar1 / 29);
122 const SkScalar CircleView::ANIM_RAD(SK_Scalar1 / 19); 115 const SkScalar CircleView::ANIM_RAD(SK_Scalar1 / 19);
123 116
124 ////////////////////////////////////////////////////////////////////////////// 117 //////////////////////////////////////////////////////////////////////////////
125 118
126 static SkView* MyFactory() { return new CircleView; } 119 static SkView* MyFactory() { return new CircleView; }
127 static SkViewRegister reg(MyFactory); 120 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « samplecode/SampleApp.cpp ('k') | samplecode/SampleDither.cpp » ('j') | src/core/SkCanvas.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698