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

Unified Diff: experimental/SkV8Example/Path.cpp

Issue 177963005: Rename Path to Path2D (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « experimental/SkV8Example/Path.h ('k') | experimental/SkV8Example/Path2D.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: experimental/SkV8Example/Path.cpp
diff --git a/experimental/SkV8Example/Path.cpp b/experimental/SkV8Example/Path.cpp
deleted file mode 100644
index b2af1f7d44b5b07dcd370971af46bdecd728c98e..0000000000000000000000000000000000000000
--- a/experimental/SkV8Example/Path.cpp
+++ /dev/null
@@ -1,244 +0,0 @@
-/*
- * Copyright 2014 Google Inc.
- *
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- *
- */
-
-#include "Path.h"
-#include "Global.h"
-
-Global* Path::gGlobal = NULL;
-
-void Path::ConstructPath(const v8::FunctionCallbackInfo<Value>& args) {
- HandleScope handleScope(gGlobal->getIsolate());
- Path* path = new Path();
- args.This()->SetInternalField(
- 0, External::New(gGlobal->getIsolate(), path));
-}
-
-#define ADD_METHOD(name, fn) \
- constructor->InstanceTemplate()->Set( \
- String::NewFromUtf8( \
- global->getIsolate(), name, \
- String::kInternalizedString), \
- FunctionTemplate::New(global->getIsolate(), fn))
-
-// Install the constructor in the global scope so Paths can be constructed
-// in JS.
-void Path::AddToGlobal(Global* global) {
- gGlobal = global;
-
- // Create a stack-allocated handle scope.
- HandleScope handleScope(gGlobal->getIsolate());
-
- Handle<Context> context = gGlobal->getContext();
-
- // Enter the scope so all operations take place in the scope.
- Context::Scope contextScope(context);
-
- Local<FunctionTemplate> constructor = FunctionTemplate::New(
- gGlobal->getIsolate(), Path::ConstructPath);
- constructor->InstanceTemplate()->SetInternalFieldCount(1);
-
- ADD_METHOD("closePath", ClosePath);
- ADD_METHOD("moveTo", MoveTo);
- ADD_METHOD("lineTo", LineTo);
- ADD_METHOD("quadraticCurveTo", QuadraticCurveTo);
- ADD_METHOD("bezierCurveTo", BezierCurveTo);
- ADD_METHOD("arc", Arc);
- ADD_METHOD("rect", Rect);
- ADD_METHOD("oval", Oval);
- ADD_METHOD("conicTo", ConicTo);
-
- context->Global()->Set(String::NewFromUtf8(
- gGlobal->getIsolate(), "Path"), constructor->GetFunction());
-}
-
-Path* Path::Unwrap(const v8::FunctionCallbackInfo<Value>& args) {
- Handle<External> field = Handle<External>::Cast(
- args.This()->GetInternalField(0));
- void* ptr = field->Value();
- return static_cast<Path*>(ptr);
-}
-
-void Path::ClosePath(const v8::FunctionCallbackInfo<Value>& args) {
- Path* path = Unwrap(args);
- path->fSkPath.close();
-}
-
-void Path::MoveTo(const v8::FunctionCallbackInfo<Value>& args) {
- if (args.Length() != 2) {
- args.GetIsolate()->ThrowException(
- v8::String::NewFromUtf8(
- args.GetIsolate(), "Error: 2 arguments required."));
- return;
- }
- double x = args[0]->NumberValue();
- double y = args[1]->NumberValue();
- Path* path = Unwrap(args);
- path->fSkPath.moveTo(SkDoubleToScalar(x), SkDoubleToScalar(y));
-}
-
-void Path::LineTo(const v8::FunctionCallbackInfo<Value>& args) {
- if (args.Length() != 2) {
- args.GetIsolate()->ThrowException(
- v8::String::NewFromUtf8(
- args.GetIsolate(), "Error: 2 arguments required."));
- return;
- }
- double x = args[0]->NumberValue();
- double y = args[1]->NumberValue();
- Path* path = Unwrap(args);
- path->fSkPath.lineTo(SkDoubleToScalar(x), SkDoubleToScalar(y));
-}
-
-void Path::QuadraticCurveTo(const v8::FunctionCallbackInfo<Value>& args) {
- if (args.Length() != 4) {
- args.GetIsolate()->ThrowException(
- v8::String::NewFromUtf8(
- args.GetIsolate(), "Error: 4 arguments required."));
- return;
- }
- double cpx = args[0]->NumberValue();
- double cpy = args[1]->NumberValue();
- double x = args[2]->NumberValue();
- double y = args[3]->NumberValue();
- Path* path = Unwrap(args);
- // TODO(jcgregorio) Doesn't handle the empty last path case correctly per
- // the HTML 5 spec.
- path->fSkPath.quadTo(
- SkDoubleToScalar(cpx), SkDoubleToScalar(cpy),
- SkDoubleToScalar(x), SkDoubleToScalar(y));
-}
-
-void Path::BezierCurveTo(const v8::FunctionCallbackInfo<Value>& args) {
- if (args.Length() != 6) {
- args.GetIsolate()->ThrowException(
- v8::String::NewFromUtf8(
- args.GetIsolate(), "Error: 6 arguments required."));
- return;
- }
- double cp1x = args[0]->NumberValue();
- double cp1y = args[1]->NumberValue();
- double cp2x = args[2]->NumberValue();
- double cp2y = args[3]->NumberValue();
- double x = args[4]->NumberValue();
- double y = args[5]->NumberValue();
- Path* path = Unwrap(args);
- // TODO(jcgregorio) Doesn't handle the empty last path case correctly per
- // the HTML 5 spec.
- path->fSkPath.cubicTo(
- SkDoubleToScalar(cp1x), SkDoubleToScalar(cp1y),
- SkDoubleToScalar(cp2x), SkDoubleToScalar(cp2y),
- SkDoubleToScalar(x), SkDoubleToScalar(y));
-}
-
-void Path::Arc(const v8::FunctionCallbackInfo<Value>& args) {
- if (args.Length() != 5 && args.Length() != 6) {
- args.GetIsolate()->ThrowException(
- v8::String::NewFromUtf8(
- args.GetIsolate(), "Error: 5 or 6 args required."));
- return;
- }
- double x = args[0]->NumberValue();
- double y = args[1]->NumberValue();
- double radius = args[2]->NumberValue();
- double startAngle = args[3]->NumberValue();
- double endAngle = args[4]->NumberValue();
- bool antiClockwise = false;
- if (args.Length() == 6) {
- antiClockwise = args[5]->BooleanValue();
- }
- double sweepAngle;
- if (!antiClockwise) {
- sweepAngle = endAngle - startAngle;
- } else {
- sweepAngle = startAngle - endAngle;
- startAngle = endAngle;
- }
-
- Path* path = Unwrap(args);
- SkRect rect = {
- SkDoubleToScalar(x-radius),
- SkDoubleToScalar(y-radius),
- SkDoubleToScalar(x+radius),
- SkDoubleToScalar(y+radius)
- };
-
- path->fSkPath.addArc(rect, SkRadiansToDegrees(startAngle),
- SkRadiansToDegrees(sweepAngle));
-}
-
-void Path::Rect(const v8::FunctionCallbackInfo<Value>& args) {
- if (args.Length() != 4) {
- args.GetIsolate()->ThrowException(
- v8::String::NewFromUtf8(
- args.GetIsolate(), "Error: 4 arguments required."));
- return;
- }
- double x = args[0]->NumberValue();
- double y = args[1]->NumberValue();
- double w = args[2]->NumberValue();
- double h = args[3]->NumberValue();
-
- SkRect rect = {
- SkDoubleToScalar(x),
- SkDoubleToScalar(y),
- SkDoubleToScalar(x) + SkDoubleToScalar(w),
- SkDoubleToScalar(y) + SkDoubleToScalar(h)
- };
- Path* path = Unwrap(args);
- path->fSkPath.addRect(rect);
-}
-
-void Path::Oval(const v8::FunctionCallbackInfo<Value>& args) {
- if (args.Length() != 4 && args.Length() != 5) {
- args.GetIsolate()->ThrowException(
- v8::String::NewFromUtf8(
- args.GetIsolate(), "Error: 4 or 5 args required."));
- return;
- }
- double x = args[0]->NumberValue();
- double y = args[1]->NumberValue();
- double radiusX = args[2]->NumberValue();
- double radiusY = args[3]->NumberValue();
- SkPath::Direction dir = SkPath::kCW_Direction;
- if (args.Length() == 5 && !args[4]->BooleanValue()) {
- dir = SkPath::kCCW_Direction;
- }
- Path* path = Unwrap(args);
- SkRect rect = {
- SkDoubleToScalar(x-radiusX),
- SkDoubleToScalar(y-radiusX),
- SkDoubleToScalar(x+radiusY),
- SkDoubleToScalar(y+radiusY)
- };
-
- path->fSkPath.addOval(rect, dir);
-}
-
-void Path::ConicTo(const v8::FunctionCallbackInfo<Value>& args) {
- if (args.Length() != 5) {
- args.GetIsolate()->ThrowException(
- v8::String::NewFromUtf8(
- args.GetIsolate(), "Error: 5 args required."));
- return;
- }
- double x1 = args[0]->NumberValue();
- double y1 = args[1]->NumberValue();
- double x2 = args[2]->NumberValue();
- double y2 = args[3]->NumberValue();
- double w = args[4]->NumberValue();
- Path* path = Unwrap(args);
-
- path->fSkPath.conicTo(
- SkDoubleToScalar(x1),
- SkDoubleToScalar(y1),
- SkDoubleToScalar(x2),
- SkDoubleToScalar(y2),
- SkDoubleToScalar(w)
- );
-}
« no previous file with comments | « experimental/SkV8Example/Path.h ('k') | experimental/SkV8Example/Path2D.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698