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

Side by Side Diff: experimental/SkV8Example/Path.cpp

Issue 132413002: Just use one version of the scripts in both the browser and in SkV8. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: merge Created 6 years, 11 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
« no previous file with comments | « experimental/SkV8Example/Path.h ('k') | experimental/SkV8Example/SkV8Example.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 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
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 */ 8 */
9 9
10 #include "Path.h" 10 #include "Path.h"
(...skipping 25 matching lines...) Expand all
36 36
37 Handle<Context> context = gGlobal->getContext(); 37 Handle<Context> context = gGlobal->getContext();
38 38
39 // Enter the scope so all operations take place in the scope. 39 // Enter the scope so all operations take place in the scope.
40 Context::Scope contextScope(context); 40 Context::Scope contextScope(context);
41 41
42 Local<FunctionTemplate> constructor = FunctionTemplate::New( 42 Local<FunctionTemplate> constructor = FunctionTemplate::New(
43 gGlobal->getIsolate(), Path::ConstructPath); 43 gGlobal->getIsolate(), Path::ConstructPath);
44 constructor->InstanceTemplate()->SetInternalFieldCount(1); 44 constructor->InstanceTemplate()->SetInternalFieldCount(1);
45 45
46 ADD_METHOD("close", ClosePath); 46 ADD_METHOD("closePath", ClosePath);
47 ADD_METHOD("moveTo", MoveTo); 47 ADD_METHOD("moveTo", MoveTo);
48 ADD_METHOD("lineTo", LineTo); 48 ADD_METHOD("lineTo", LineTo);
49 ADD_METHOD("quadraticCurveTo", QuadraticCurveTo); 49 ADD_METHOD("quadraticCurveTo", QuadraticCurveTo);
50 ADD_METHOD("bezierCurveTo", BezierCurveTo); 50 ADD_METHOD("bezierCurveTo", BezierCurveTo);
51 ADD_METHOD("arc", Arc); 51 ADD_METHOD("arc", Arc);
52 ADD_METHOD("rect", Rect); 52 ADD_METHOD("rect", Rect);
53 ADD_METHOD("oval", Oval);
53 54
54 context->Global()->Set(String::NewFromUtf8( 55 context->Global()->Set(String::NewFromUtf8(
55 gGlobal->getIsolate(), "Path"), constructor->GetFunction()); 56 gGlobal->getIsolate(), "Path"), constructor->GetFunction());
56 } 57 }
57 58
58 Path* Path::Unwrap(const v8::FunctionCallbackInfo<Value>& args) { 59 Path* Path::Unwrap(const v8::FunctionCallbackInfo<Value>& args) {
59 Handle<External> field = Handle<External>::Cast( 60 Handle<External> field = Handle<External>::Cast(
60 args.This()->GetInternalField(0)); 61 args.This()->GetInternalField(0));
61 void* ptr = field->Value(); 62 void* ptr = field->Value();
62 return static_cast<Path*>(ptr); 63 return static_cast<Path*>(ptr);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 185
185 SkRect rect = { 186 SkRect rect = {
186 SkDoubleToScalar(x), 187 SkDoubleToScalar(x),
187 SkDoubleToScalar(y), 188 SkDoubleToScalar(y),
188 SkDoubleToScalar(x) + SkDoubleToScalar(w), 189 SkDoubleToScalar(x) + SkDoubleToScalar(w),
189 SkDoubleToScalar(y) + SkDoubleToScalar(h) 190 SkDoubleToScalar(y) + SkDoubleToScalar(h)
190 }; 191 };
191 Path* path = Unwrap(args); 192 Path* path = Unwrap(args);
192 path->fSkPath.addRect(rect); 193 path->fSkPath.addRect(rect);
193 } 194 }
195
196 void Path::Oval(const v8::FunctionCallbackInfo<Value>& args) {
197 if (args.Length() != 4 && args.Length() != 5) {
198 args.GetIsolate()->ThrowException(
199 v8::String::NewFromUtf8(
200 args.GetIsolate(), "Error: 4 or 5 args required."));
201 return;
202 }
203 double x = args[0]->NumberValue();
204 double y = args[1]->NumberValue();
205 double radiusX = args[2]->NumberValue();
206 double radiusY = args[3]->NumberValue();
207 SkPath::Direction dir = SkPath::kCW_Direction;
208 if (args.Length() == 5 && !args[4]->BooleanValue()) {
209 dir = SkPath::kCCW_Direction;
210 }
211 Path* path = Unwrap(args);
212 SkRect rect = {
213 SkDoubleToScalar(x-radiusX),
214 SkDoubleToScalar(y-radiusX),
215 SkDoubleToScalar(x+radiusY),
216 SkDoubleToScalar(y+radiusY)
217 };
218
219 path->fSkPath.addOval(rect, dir);
220 }
OLDNEW
« no previous file with comments | « experimental/SkV8Example/Path.h ('k') | experimental/SkV8Example/SkV8Example.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698