Flutter Engine
The Flutter Engine
third_party
skia
docs
examples
SkPath_cubicTo_example.cpp
Go to the documentation of this file.
1
// Copyright 2020 Google LLC.
2
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3
#include "
tools/fiddle/examples.h
"
4
REG_FIDDLE
(SkPath_cubicTo_example, 512, 512,
false
, 0) {
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
*/
19
void
draw
(
SkCanvas
* canvas) {
20
canvas->
clear
(
SkColorSetARGB
(255, 255, 255, 255));
21
SkFont
font
(
fontMgr
->
matchFamilyStyle
(
nullptr
, {}), 32);
22
23
SkPaint
paint
;
24
paint
.setAntiAlias(
true
);
25
paint
.setStyle(
SkPaint::kStroke_Style
);
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
SkColorSetARGB
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition:
SkColor.h:49
REG_FIDDLE
REG_FIDDLE(SkPath_cubicTo_example, 512, 512, false, 0)
Definition:
SkPath_cubicTo_example.cpp:4
draw
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition:
aaclip.cpp:27
SkCanvas
Definition:
SkCanvas.h:106
SkCanvas::clear
void clear(SkColor color)
Definition:
SkCanvas.h:1199
SkCanvas::drawPath
void drawPath(const SkPath &path, const SkPaint &paint)
Definition:
SkCanvas.cpp:1747
SkCanvas::drawString
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition:
SkCanvas.h:1803
SkFontMgr::matchFamilyStyle
sk_sp< SkTypeface > matchFamilyStyle(const char familyName[], const SkFontStyle &) const
Definition:
SkFontMgr.cpp:109
SkFont
Definition:
SkFont.h:35
SkPaint
Definition:
SkPaint.h:44
SkPaint::setColor
void setColor(SkColor color)
Definition:
SkPaint.cpp:119
SkPaint::setAntiAlias
void setAntiAlias(bool aa)
Definition:
SkPaint.h:170
SkPaint::kStroke_Style
@ kStroke_Style
set to stroke geometry
Definition:
SkPaint.h:194
SkPath
Definition:
SkPath.h:59
SkPath::moveTo
SkPath & moveTo(SkScalar x, SkScalar y)
Definition:
SkPath.cpp:688
SkPath::lineTo
SkPath & lineTo(SkScalar x, SkScalar y)
Definition:
SkPath.cpp:728
SkPath::cubicTo
SkPath & cubicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar x3, SkScalar y3)
Definition:
SkPath.cpp:799
paint
const Paint & paint
Definition:
color_source.cc:38
d
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition:
main.cc:19
fontMgr
sk_sp< SkFontMgr > fontMgr
Definition:
examples.cpp:32
examples.h
b
static bool b
Definition:
ffi_native_test_module.c:74
a
struct MyStruct a[10]
gen_test_font.font
font
Font Metadata and Metrics.
Definition:
gen_test_font.py:26
MyStruct::x
double x
Definition:
ffi_native_test_module.c:11
MyStruct::y
int16_t y
Definition:
ffi_native_test_module.c:12
SkPoint
Definition:
SkPoint_impl.h:163
Generated on Sun Jun 23 2024 21:55:56 for Flutter Engine by
1.9.4