Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
cbfa4e54
Unverified
Commit
cbfa4e54
authored
Apr 27, 2019
by
Shi-Hao Hong
Committed by
GitHub
Apr 27, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve canvas example in sample dart ui app (#31634)
parent
7c4ccb34
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
5 deletions
+35
-5
canvas.dart
examples/layers/raw/canvas.dart
+35
-5
No files found.
examples/layers/raw/canvas.dart
View file @
cbfa4e54
...
@@ -32,21 +32,41 @@ ui.Picture paint(ui.Rect paintBounds) {
...
@@ -32,21 +32,41 @@ ui.Picture paint(ui.Rect paintBounds) {
final
double
devicePixelRatio
=
ui
.
window
.
devicePixelRatio
;
final
double
devicePixelRatio
=
ui
.
window
.
devicePixelRatio
;
final
ui
.
Size
logicalSize
=
ui
.
window
.
physicalSize
/
devicePixelRatio
;
final
ui
.
Size
logicalSize
=
ui
.
window
.
physicalSize
/
devicePixelRatio
;
// Saves a copy of current transform onto the save stack
canvas
.
save
();
canvas
.
save
();
// Note that transforms that occur after this point apply only to the
// yellow-bluish rectangle
// This line will cause the transform to shift entirely outside the paint
// boundaries, which will cause the canvas interface to discard its
// commands. Comment it out to see it on screen.
canvas
.
translate
(-
mid
.
dx
/
2.0
,
logicalSize
.
height
*
2.0
);
canvas
.
translate
(-
mid
.
dx
/
2.0
,
logicalSize
.
height
*
2.0
);
canvas
.
clipRect
(
ui
.
Rect
.
fromLTRB
(
0.0
,
-
logicalSize
.
height
,
logicalSize
.
width
,
radius
));
// Clips the current transform
canvas
.
clipRect
(
ui
.
Rect
.
fromLTRB
(
0
,
radius
+
50
,
logicalSize
.
width
,
logicalSize
.
height
),
clipOp:
ui
.
ClipOp
.
difference
);
// Shifts the coordinate space of and rotates the current transform
canvas
.
translate
(
mid
.
dx
,
mid
.
dy
);
canvas
.
translate
(
mid
.
dx
,
mid
.
dy
);
paint
.
color
=
const
ui
.
Color
.
fromARGB
(
128
,
255
,
0
,
255
);
canvas
.
rotate
(
math
.
pi
/
4
);
canvas
.
rotate
(
math
.
pi
/
4.0
);
final
ui
.
Gradient
yellowBlue
=
ui
.
Gradient
.
linear
(
final
ui
.
Gradient
yellowBlue
=
ui
.
Gradient
.
linear
(
ui
.
Offset
(-
radius
,
-
radius
),
ui
.
Offset
(-
radius
,
-
radius
),
const
ui
.
Offset
(
0.0
,
0.0
),
const
ui
.
Offset
(
0.0
,
0.0
),
<
ui
.
Color
>[
const
ui
.
Color
(
0xFFFFFF00
),
const
ui
.
Color
(
0xFF0000FF
)],
<
ui
.
Color
>[
const
ui
.
Color
(
0xFFFFFF00
),
const
ui
.
Color
(
0xFF0000FF
)],
);
);
canvas
.
drawRect
(
ui
.
Rect
.
fromLTRB
(-
radius
,
-
radius
,
radius
,
radius
),
ui
.
Paint
()..
shader
=
yellowBlue
);
// Draws a yellow-bluish rectangle
canvas
.
drawRect
(
ui
.
Rect
.
fromLTRB
(-
radius
,
-
radius
,
radius
,
radius
),
ui
.
Paint
()..
shader
=
yellowBlue
,
);
// Note that transforms that occur after this point apply only to the
// yellow circle
// Scale x and y by 0.5.
// Scale x and y by 0.5.
final
Float64List
scaleMatrix
=
Float64List
.
fromList
(<
double
>[
final
Float64List
scaleMatrix
=
Float64List
.
fromList
(<
double
>[
...
@@ -56,11 +76,21 @@ ui.Picture paint(ui.Rect paintBounds) {
...
@@ -56,11 +76,21 @@ ui.Picture paint(ui.Rect paintBounds) {
0.0
,
0.0
,
0.0
,
1.0
,
0.0
,
0.0
,
0.0
,
1.0
,
]);
]);
canvas
.
transform
(
scaleMatrix
);
canvas
.
transform
(
scaleMatrix
);
// Sets paint to transparent yellow
paint
.
color
=
const
ui
.
Color
.
fromARGB
(
128
,
0
,
255
,
0
);
paint
.
color
=
const
ui
.
Color
.
fromARGB
(
128
,
0
,
255
,
0
);
// Draws a transparent yellow circle
canvas
.
drawCircle
(
ui
.
Offset
.
zero
,
radius
,
paint
);
canvas
.
drawCircle
(
ui
.
Offset
.
zero
,
radius
,
paint
);
// Restores the transform from before `save` was called
canvas
.
restore
();
canvas
.
restore
();
// Sets paint to transparent red
paint
.
color
=
const
ui
.
Color
.
fromARGB
(
128
,
255
,
0
,
0
);
paint
.
color
=
const
ui
.
Color
.
fromARGB
(
128
,
255
,
0
,
0
);
// Note that this circle is drawn on top of the previous layer that contains
// the rectangle and smaller circle
canvas
.
drawCircle
(
const
ui
.
Offset
(
150.0
,
300.0
),
radius
,
paint
);
canvas
.
drawCircle
(
const
ui
.
Offset
(
150.0
,
300.0
),
radius
,
paint
);
// When we're done issuing painting commands, we end the recording an receive
// When we're done issuing painting commands, we end the recording an receive
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment