Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
SkPath_cubicTo_example.cpp File Reference
#include "tools/fiddle/examples.h"

Go to the source code of this file.

Functions

 REG_FIDDLE (SkPath_cubicTo_example, 512, 512, false, 0)
 

Function Documentation

◆ REG_FIDDLE()

REG_FIDDLE ( SkPath_cubicTo_example  ,
512  ,
512  ,
false  ,
 
)

Definition at line 4 of file SkPath_cubicTo_example.cpp.

4 {
5/*
6 If the starting point is (x0, y0), then this curve is defined as the
7 paramentric curve as `t` goes from 0 to 1:
8 s := 1 - t
9 x := (s * s * s * x0) +
10 (3 * s * s * t * x1) +
11 (3 * s * t * t * x2) +
12 (t * t * t * x3)
13 y := (s * s * s * y0) +
14 (3 * s * s * t * y1) +
15 (3 * s * t * t * y2) +
16 (t * t * t * y3)
17
18*/
19void draw(SkCanvas* canvas) {
20 canvas->clear(SkColorSetARGB(255, 255, 255, 255));
21 SkFont font(fontMgr->matchFamilyStyle(nullptr, {}), 32);
22
24 paint.setAntiAlias(true);
26 paint.setStrokeWidth(5);
27
28 SkPoint a{128, 64};
29 SkPoint b{448, 448};
30 SkPoint c{64, 448};
31 SkPoint d{384, 64};
32
33 SkPath threeSegments;
34 threeSegments.moveTo(a);
35 threeSegments.lineTo(b);
36 threeSegments.lineTo(c);
37 threeSegments.lineTo(d);
38
39 canvas->drawPath(threeSegments, paint);
40
41 paint.setColor(SkColorSetARGB(255, 0, 0, 255));
42 SkPath cubicCurve;
43 cubicCurve.moveTo(a);
44 cubicCurve.cubicTo(b, c, d);
45 canvas->drawPath(cubicCurve, paint);
46
47 SkPaint textPaint;
48 textPaint.setColor(SkColorSetARGB(255, 0, 255, 0));
49 textPaint.setAntiAlias(true);
50 canvas->drawString("a", a.x(), a.y(), font, textPaint);
51 canvas->drawString("b", b.x(), b.y(), font, textPaint);
52 canvas->drawString("c", c.x() - 20, c.y(), font, textPaint);
53 canvas->drawString("d", d.x(), d.y(), font, textPaint);
54}
55} // END FIDDLE
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition SkColor.h:49
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition aaclip.cpp:27
void clear(SkColor color)
Definition SkCanvas.h:1199
void drawPath(const SkPath &path, const SkPaint &paint)
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition SkCanvas.h:1803
sk_sp< SkTypeface > matchFamilyStyle(const char familyName[], const SkFontStyle &) const
void setColor(SkColor color)
Definition SkPaint.cpp:119
void setAntiAlias(bool aa)
Definition SkPaint.h:170
@ kStroke_Style
set to stroke geometry
Definition SkPaint.h:194
SkPath & moveTo(SkScalar x, SkScalar y)
Definition SkPath.cpp:678
SkPath & lineTo(SkScalar x, SkScalar y)
Definition SkPath.cpp:718
SkPath & cubicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar x3, SkScalar y3)
Definition SkPath.cpp:789
const Paint & paint
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition main.cc:19
sk_sp< SkFontMgr > fontMgr
Definition examples.cpp:32
static bool b
struct MyStruct a[10]
font
Font Metadata and Metrics.