Added drawArc to Canvas. (flutter/engine#2995)

* Added drawArc to Canvas.

Added a way to call SkCanvas::drawArc from Dart. This method is
optimized for the arc case and should be faster that drawing paths.

* Removed implementation details from docs.

* Added more details to the docs.
This commit is contained in:
Dragoș Tiselice
2016-09-12 13:41:01 -07:00
committed by GitHub
parent 8b925fcbb1
commit ac99851ce8
3 changed files with 52 additions and 0 deletions

View File

@@ -1297,6 +1297,30 @@ class Canvas extends NativeFieldWrapperClass2 {
List<dynamic> paintObjects,
ByteData paintData) native "Canvas_drawCircle";
/// Draw an arc scaled to fit inside the given rectangle. It starts from
/// startAngle radians around the oval up to startAngle + sweepAngle
/// radians around the oval, with zero radians being the point on
/// the right hand side of the oval that crosses the horizontal line
/// that intersects the center of the rectangle and with positive
/// angles going clockwise around the oval. If useCenter is true, the arc is
/// closed back to the center, forming a circle sector. Otherwise, the arc is
/// not closed, forming a circle segment.
///
/// This method is optimized for drawing arcs and should be faster than [Path.arcTo].
void drawArc(Rect rect, double startAngle, double sweepAngle, bool useCenter, Paint paint) {
_drawArc(rect.left, rect.top, rect.right, rect.bottom, startAngle,
sweepAngle, useCenter, paint._objects, paint._data);
}
void _drawArc(double left,
double top,
double right,
double bottom,
double startAngle,
double sweepAngle,
bool useCenter,
List<dynamic> paintObjects,
ByteData paintData) native "Canvas_drawArc";
/// Draws the given [Path] with the given [Paint]. Whether this shape is
/// filled or stroked (or both) is controlled by [Paint.style]. If the path is
/// filled, then subpaths within it are implicitly closed (see [Path.close]).

View File

@@ -46,6 +46,7 @@ IMPLEMENT_WRAPPERTYPEINFO(ui, Canvas);
V(Canvas, drawDRRect) \
V(Canvas, drawOval) \
V(Canvas, drawCircle) \
V(Canvas, drawArc) \
V(Canvas, drawPath) \
V(Canvas, drawImage) \
V(Canvas, drawImageRect) \
@@ -242,6 +243,24 @@ void Canvas::drawCircle(double x,
canvas_->drawCircle(x, y, radius, *paint.paint());
}
void Canvas::drawArc(double left,
double top,
double right,
double bottom,
double startAngle,
double sweepAngle,
bool useCenter,
const Paint& paint,
const PaintData& paint_data) {
if (!canvas_)
return;
canvas_->drawArc(SkRect::MakeLTRB(left, top, right, bottom),
startAngle * 180.0 / M_PI,
sweepAngle* 180.0 / M_PI,
useCenter,
*paint.paint());
}
void Canvas::drawPath(const CanvasPath* path,
const Paint& paint,
const PaintData& paint_data) {

View File

@@ -100,6 +100,15 @@ class Canvas : public ftl::RefCountedThreadSafe<Canvas>,
double radius,
const Paint& paint,
const PaintData& paint_data);
void drawArc(double left,
double top,
double right,
double bottom,
double startAngle,
double sweepAngle,
bool useCenter,
const Paint& paint,
const PaintData& paint_data);
void drawPath(const CanvasPath* path,
const Paint& paint,
const PaintData& paint_data);