OLD | NEW |
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 24 matching lines...) Expand all Loading... |
35 | 35 |
36 Handle<Context> context = gGlobal->getContext(); | 36 Handle<Context> context = gGlobal->getContext(); |
37 | 37 |
38 // Enter the scope so all operations take place in the scope. | 38 // Enter the scope so all operations take place in the scope. |
39 Context::Scope contextScope(context); | 39 Context::Scope contextScope(context); |
40 | 40 |
41 Local<FunctionTemplate> constructor = FunctionTemplate::New( | 41 Local<FunctionTemplate> constructor = FunctionTemplate::New( |
42 Path::ConstructPath); | 42 Path::ConstructPath); |
43 constructor->InstanceTemplate()->SetInternalFieldCount(1); | 43 constructor->InstanceTemplate()->SetInternalFieldCount(1); |
44 | 44 |
45 ADD_METHOD("close", ClosePath); | 45 ADD_METHOD("closePath", ClosePath); |
46 ADD_METHOD("moveTo", MoveTo); | 46 ADD_METHOD("moveTo", MoveTo); |
47 ADD_METHOD("lineTo", LineTo); | 47 ADD_METHOD("lineTo", LineTo); |
48 ADD_METHOD("quadraticCurveTo", QuadraticCurveTo); | 48 ADD_METHOD("quadraticCurveTo", QuadraticCurveTo); |
49 ADD_METHOD("bezierCurveTo", BezierCurveTo); | 49 ADD_METHOD("bezierCurveTo", BezierCurveTo); |
50 ADD_METHOD("arc", Arc); | 50 ADD_METHOD("arc", Arc); |
51 ADD_METHOD("rect", Rect); | 51 ADD_METHOD("rect", Rect); |
| 52 ADD_METHOD("oval", Oval); |
52 | 53 |
53 context->Global()->Set(String::New("Path"), constructor->GetFunction()); | 54 context->Global()->Set(String::New("Path"), constructor->GetFunction()); |
54 } | 55 } |
55 | 56 |
56 Path* Path::Unwrap(const v8::FunctionCallbackInfo<Value>& args) { | 57 Path* Path::Unwrap(const v8::FunctionCallbackInfo<Value>& args) { |
57 Handle<External> field = Handle<External>::Cast( | 58 Handle<External> field = Handle<External>::Cast( |
58 args.This()->GetInternalField(0)); | 59 args.This()->GetInternalField(0)); |
59 void* ptr = field->Value(); | 60 void* ptr = field->Value(); |
60 return static_cast<Path*>(ptr); | 61 return static_cast<Path*>(ptr); |
61 } | 62 } |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 | 183 |
183 SkRect rect = { | 184 SkRect rect = { |
184 SkDoubleToScalar(x), | 185 SkDoubleToScalar(x), |
185 SkDoubleToScalar(y), | 186 SkDoubleToScalar(y), |
186 SkDoubleToScalar(x) + SkDoubleToScalar(w), | 187 SkDoubleToScalar(x) + SkDoubleToScalar(w), |
187 SkDoubleToScalar(y) + SkDoubleToScalar(h) | 188 SkDoubleToScalar(y) + SkDoubleToScalar(h) |
188 }; | 189 }; |
189 Path* path = Unwrap(args); | 190 Path* path = Unwrap(args); |
190 path->fSkPath.addRect(rect); | 191 path->fSkPath.addRect(rect); |
191 } | 192 } |
| 193 |
| 194 void Path::Oval(const v8::FunctionCallbackInfo<Value>& args) { |
| 195 if (args.Length() != 4 && args.Length() != 5) { |
| 196 args.GetIsolate()->ThrowException( |
| 197 v8::String::NewFromUtf8( |
| 198 args.GetIsolate(), "Error: 4 or 5 args required.")); |
| 199 return; |
| 200 } |
| 201 double x = args[0]->NumberValue(); |
| 202 double y = args[1]->NumberValue(); |
| 203 double radiusX = args[2]->NumberValue(); |
| 204 double radiusY = args[3]->NumberValue(); |
| 205 SkPath::Direction dir = SkPath::kCW_Direction; |
| 206 if (args.Length() == 5 && !args[4]->BooleanValue()) { |
| 207 dir = SkPath::kCCW_Direction; |
| 208 } |
| 209 Path* path = Unwrap(args); |
| 210 SkRect rect = { |
| 211 SkDoubleToScalar(x-radiusX), |
| 212 SkDoubleToScalar(y-radiusX), |
| 213 SkDoubleToScalar(x+radiusY), |
| 214 SkDoubleToScalar(y+radiusY) |
| 215 }; |
| 216 |
| 217 path->fSkPath.addOval(rect, dir); |
| 218 } |
OLD | NEW |