Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
skia
gm
thinstrokedrects.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2013 Google Inc.
3
*
4
* Use of this source code is governed by a BSD-style license that can be
5
* found in the LICENSE file.
6
*/
7
8
#include "
gm/gm.h
"
9
#include "
include/core/SkCanvas.h
"
10
#include "
include/core/SkColor.h
"
11
#include "
include/core/SkPaint.h
"
12
#include "
include/core/SkRect.h
"
13
#include "
include/core/SkScalar.h
"
14
#include "
include/core/SkSize.h
"
15
#include "
include/core/SkString.h
"
16
#include "
include/core/SkTypes.h
"
17
18
namespace
skiagm
{
19
20
// Draw rects with various stroke widths at 1/8 pixel increments
21
class
ThinStrokedRectsGM
:
public
GM
{
22
public
:
23
ThinStrokedRectsGM
() {
24
this->
setBGColor
(0xFF000000);
25
}
26
27
protected
:
28
SkString
getName
()
const override
{
return
SkString
(
"thinstrokedrects"
); }
29
30
SkISize
getISize
()
override
{
return
SkISize::Make
(240, 320); }
31
32
void
onDraw
(
SkCanvas
* canvas)
override
{
33
34
SkPaint
paint
;
35
paint
.setColor(
SK_ColorWHITE
);
36
paint
.setStyle(
SkPaint::kStroke_Style
);
37
paint
.setAntiAlias(
true
);
38
39
constexpr
SkRect
rect = { 0, 0, 10, 10 };
40
constexpr
SkRect
rect2 = { 0, 0, 20, 20 };
41
42
constexpr
SkScalar
gStrokeWidths[] = {
43
4, 2, 1, 0.5f, 0.25f, 0.125f, 0
44
};
45
46
canvas->
translate
(5, 5);
47
for
(
int
i = 0; i < 8; ++i) {
48
canvas->
save
();
49
canvas->
translate
(i*0.125f, i*30.0f);
50
for
(
size_t
j = 0; j < std::size(gStrokeWidths); ++j) {
51
paint
.setStrokeWidth(gStrokeWidths[j]);
52
canvas->
drawRect
(rect,
paint
);
53
canvas->
translate
(15, 0);
54
}
55
canvas->
restore
();
56
}
57
58
// Draw a second time in red with a scale
59
paint
.setColor(
SK_ColorRED
);
60
canvas->
translate
(0, 15);
61
for
(
int
i = 0; i < 8; ++i) {
62
canvas->
save
();
63
canvas->
translate
(i*0.125f, i*30.0f);
64
canvas->
scale
(0.5f, 0.5f);
65
for
(
size_t
j = 0; j < std::size(gStrokeWidths); ++j) {
66
paint
.setStrokeWidth(2.0f * gStrokeWidths[j]);
67
canvas->
drawRect
(rect2,
paint
);
68
canvas->
translate
(30, 0);
69
}
70
canvas->
restore
();
71
}
72
}
73
74
private
:
75
using
INHERITED =
GM
;
76
};
77
78
//////////////////////////////////////////////////////////////////////////////
79
80
DEF_GM
(
return
new
ThinStrokedRectsGM;)
81
}
// namespace skiagm
SkCanvas.h
SkColor.h
SK_ColorRED
constexpr SkColor SK_ColorRED
Definition
SkColor.h:126
SK_ColorWHITE
constexpr SkColor SK_ColorWHITE
Definition
SkColor.h:122
SkPaint.h
SkRect.h
SkScalar.h
SkSize.h
SkString.h
SkTypes.h
SkCanvas
Definition
SkCanvas.h:106
SkCanvas::drawRect
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition
SkCanvas.cpp:1997
SkCanvas::restore
void restore()
Definition
SkCanvas.cpp:465
SkCanvas::translate
void translate(SkScalar dx, SkScalar dy)
Definition
SkCanvas.cpp:1602
SkCanvas::save
int save()
Definition
SkCanvas.cpp:451
SkCanvas::scale
void scale(SkScalar sx, SkScalar sy)
Definition
SkCanvas.cpp:1613
SkPaint
Definition
SkPaint.h:44
SkPaint::kStroke_Style
@ kStroke_Style
set to stroke geometry
Definition
SkPaint.h:194
SkString
Definition
SkString.h:118
skiagm::GM
Definition
gm.h:110
skiagm::GM::setBGColor
void setBGColor(SkColor)
Definition
gm.cpp:159
skiagm::ThinStrokedRectsGM
Definition
thinstrokedrects.cpp:21
skiagm::ThinStrokedRectsGM::onDraw
void onDraw(SkCanvas *canvas) override
Definition
thinstrokedrects.cpp:32
skiagm::ThinStrokedRectsGM::ThinStrokedRectsGM
ThinStrokedRectsGM()
Definition
thinstrokedrects.cpp:23
skiagm::ThinStrokedRectsGM::getISize
SkISize getISize() override
Definition
thinstrokedrects.cpp:30
skiagm::ThinStrokedRectsGM::getName
SkString getName() const override
Definition
thinstrokedrects.cpp:28
paint
const Paint & paint
Definition
color_source.cc:38
SkScalar
float SkScalar
Definition
extension.cpp:12
gm.h
DEF_GM
#define DEF_GM(CODE)
Definition
gm.h:40
skiagm
Definition
DMSrcSink.h:27
SkISize
Definition
SkSize.h:16
SkISize::Make
static constexpr SkISize Make(int32_t w, int32_t h)
Definition
SkSize.h:20
SkRect
Definition
extension.cpp:13
Generated on Fri Apr 26 2024 06:16:09 for Flutter Engine by
1.9.8