diff --git a/engine/core/core.gni b/engine/core/core.gni index b1541a13276..924d43d7255 100644 --- a/engine/core/core.gni +++ b/engine/core/core.gni @@ -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 diff --git a/engine/core/painting/Point.cpp b/engine/core/painting/Point.cpp new file mode 100644 index 00000000000..aff2fdcb7b9 --- /dev/null +++ b/engine/core/painting/Point.cpp @@ -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::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 diff --git a/engine/core/painting/Point.dart b/engine/core/painting/Point.dart new file mode 100644 index 00000000000..9fc7082e707 --- /dev/null +++ b/engine/core/painting/Point.dart @@ -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); +} + diff --git a/engine/core/painting/Point.h b/engine/core/painting/Point.h new file mode 100644 index 00000000000..90d4dbd1aeb --- /dev/null +++ b/engine/core/painting/Point.h @@ -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 { + static Point FromArgumentsWithNullCheck(Dart_NativeArguments args, + int index, + Dart_Handle& exception); +}; + +} // namespace blink + +#endif // SKY_ENGINE_CORE_PAINTING_POINT_H_ diff --git a/examples/raw/painting.sky b/examples/raw/painting.sky index bd960e6efb8..2b5597c923b 100644 --- a/examples/raw/painting.sky +++ b/examples/raw/painting.sky @@ -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);