Sky: Add a Point class.

Also, fix the style in Rect.cpp/.h.

R=eseidel@chromium.org

Review URL: https://codereview.chromium.org/1158843002
This commit is contained in:
Matt Perry 2015-05-27 14:40:02 -04:00
parent 922ea790b8
commit 4139325e2c
5 changed files with 88 additions and 3 deletions

View File

@ -1125,7 +1125,11 @@ core_idl_files = get_path_info([
],
"abspath")
core_dart_files = get_path_info([ "painting/Rect.dart" ], "abspath")
core_dart_files = get_path_info([
"painting/Rect.dart",
"painting/Point.dart",
],
"abspath")
# Files for which bindings (.cpp and .h files) will be generated
# 'partial interface', target (right side of) 'implements', and

View File

@ -0,0 +1,38 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/engine/config.h"
#include "sky/engine/core/painting/Point.h"
#include "sky/engine/tonic/dart_error.h"
#include "sky/engine/tonic/dart_state.h"
#include "base/logging.h"
namespace blink {
// Convert dartPoint.x,y ==> SkPoint.
Point DartConverter<Point, void>::FromArgumentsWithNullCheck(
Dart_NativeArguments args,
int index,
Dart_Handle& exception) {
Point result;
result.is_null = true;
Dart_Handle dartPoint = Dart_GetNativeArgument(args, index);
DCHECK(!LogIfError(dartPoint));
Dart_Handle xValue = Dart_GetField(dartPoint, Dart_NewStringFromCString("x"));
Dart_Handle yValue = Dart_GetField(dartPoint, Dart_NewStringFromCString("y"));
double x = 0.0, y = 0.0;
Dart_Handle err = Dart_DoubleValue(xValue, &x);
DCHECK(!LogIfError(err));
err = Dart_DoubleValue(xValue, &y);
DCHECK(!LogIfError(err));
result.sk_point.set(x, y);
result.is_null = false;
return result;
}
} // namespace blink

View File

@ -0,0 +1,13 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
part of dart.sky;
class Point {
double x;
double y;
Point(this.x, this.y);
}

View File

@ -0,0 +1,29 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SKY_ENGINE_CORE_PAINTING_POINT_H_
#define SKY_ENGINE_CORE_PAINTING_POINT_H_
#include "dart/runtime/include/dart_api.h"
#include "sky/engine/tonic/dart_converter.h"
#include "third_party/skia/include/core/SkPoint.h"
namespace blink {
// Very simple wrapper for SkPoint to add a null state.
class Point {
public:
SkPoint sk_point;
bool is_null;
};
template<>
struct DartConverter<Point, void> {
static Point FromArgumentsWithNullCheck(Dart_NativeArguments args,
int index,
Dart_Handle& exception);
};
} // namespace blink
#endif // SKY_ENGINE_CORE_PAINTING_POINT_H_

View File

@ -14,13 +14,14 @@ void main() {
var element = document.getElementById('canvas');
element.requestPaint((PaintingContext context) {
Paint paint = new Paint();
double radius = math.min(context.width, context.height) / 2.0;
Point mid = new Point(context.width / 2.0, context.height / 2.0);
double radius = math.min(mid.x, mid.y);
context.save();
context.clipRect(new Rect()..setLTRB(0.0, 0.0, context.width, radius));
context.translate(context.width / 2.0, context.height / 2.0);
context.translate(mid.x, mid.y);
paint.setARGB(128, 255, 0, 255);
context.rotateDegrees(45.0);