OLD | NEW |
| (Empty) |
1 // | |
2 // Copyright 2014 Google Inc. All rights reserved. | |
3 // | |
4 // Use of this source code is governed by a BSD-style | |
5 // license that can be found in the LICENSE file or at | |
6 // https://developers.google.com/open-source/licenses/bsd | |
7 // | |
8 | |
9 part of charted.svg.shapes; | |
10 | |
11 /// Draw a rectangle at [x], [y] which is [width] pixels wide and | |
12 /// [height] pixels height. [topLeft], [topRight], [bottomRight] and | |
13 /// [bottomLeft] are the corner radius at each of the four corners. | |
14 String roundedRect(int x, int y, int width, int height, | |
15 int topLeft, int topRight, int bottomRight, int bottomLeft) => | |
16 'M${x+topLeft},${y} ' | |
17 'L${x+width-topRight},${y} ' | |
18 'Q${x+width},${y} ${x+width},${y+topRight}' | |
19 'L${x+width},${y+height-bottomRight} ' | |
20 'Q${x+width},${y+height} ${x+width-bottomRight},${y+height}' | |
21 'L${x+bottomLeft},${y+height} ' | |
22 'Q${x},${y+height} ${x},${y+height-bottomLeft}' | |
23 'L${x},${y+topLeft} ' | |
24 'Q${x},${y} ${x+topLeft},${y} Z'; | |
25 | |
26 /// Draw a rectangle with rounded corners on both corners on the right. | |
27 String rightRoundedRect(int x, int y, int width, int height, int radius) { | |
28 if (width < radius) radius = width; | |
29 if (height < radius * 2) radius = height ~/ 2; | |
30 return roundedRect(x, y, width, height, 0, radius, radius, 0); | |
31 } | |
32 | |
33 /// Draw a rectangle with rounded corners on both corners on the top. | |
34 String topRoundedRect(int x, int y, int width, int height, int radius) { | |
35 if (height < radius) radius = height; | |
36 if (width < radius * 2) radius = width ~/ 2; | |
37 return roundedRect(x, y, width, height, radius, radius, 0, 0); | |
38 } | |
39 | |
40 /// Draw a rectangle with rounded corners on both corners on the right. | |
41 String leftRoundedRect(int x, int y, int width, int height, int radius) { | |
42 if (width < radius) radius = width; | |
43 if (height < radius * 2) radius = height ~/ 2; | |
44 return roundedRect(x, y, width, height, radius, 0, 0, radius); | |
45 } | |
46 | |
47 /// Draw a rectangle with rounded corners on both corners on the top. | |
48 String bottomRoundedRect(int x, int y, int width, int height, int radius) { | |
49 if (height < radius) radius = height; | |
50 if (width < radius * 2) radius = width ~/ 2; | |
51 return roundedRect(x, y, width, height, 0, 0, radius, radius); | |
52 } | |
OLD | NEW |