Flutter Engine
The Flutter Engine
third_party
skia
tools
viewer
SGSlide.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2019 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 "
include/core/SkCanvas.h
"
9
#include "
include/core/SkFont.h
"
10
#include "
include/core/SkFontMetrics.h
"
11
#include "
include/core/SkPath.h
"
12
#include "
include/private/base/SkTDArray.h
"
13
#include "
modules/sksg/include/SkSGDraw.h
"
14
#include "
modules/sksg/include/SkSGGroup.h
"
15
#include "
modules/sksg/include/SkSGPaint.h
"
16
#include "
modules/sksg/include/SkSGRect.h
"
17
#include "
modules/sksg/include/SkSGScene.h
"
18
#include "
tools/viewer/ClickHandlerSlide.h
"
19
20
struct
PerNodeInfo
{
21
// key
22
sksg::Draw
*
fDraw
;
23
24
// value(s)
25
sksg::GeometryNode
*
fGeo
;
26
sksg::PaintNode
*
fPaint
;
27
};
28
29
class
SGSlide
:
public
ClickHandlerSlide
{
30
// TODO(kjlubick) use a vector instead of our private SkTDArray
31
SkTDArray<PerNodeInfo>
fSideCar;
32
sk_sp<sksg::Group>
fGroup;
33
std::unique_ptr<sksg::Scene> fScene;
34
35
PerNodeInfo
* findInfo(
sksg::Draw
*
key
) {
36
for
(
int
i
= 0;
i
< fSideCar.
size
(); ++
i
) {
37
if
(fSideCar[
i
].fDraw ==
key
) {
38
return
&fSideCar[
i
];
39
}
40
}
41
return
nullptr
;
42
}
43
44
void
appendNode(
sk_sp<sksg::Draw>
d
,
sk_sp<sksg::GeometryNode>
g,
sk_sp<sksg::PaintNode>
p
) {
45
fGroup->
addChild
(
d
);
46
auto
sc = fSideCar.
append
();
47
sc->
fDraw
=
d
.get();
48
sc->fGeo = g.
get
();
49
sc->fPaint =
p
.get();
50
}
51
52
public
:
53
SGSlide
() {
54
fGroup =
sksg::Group::Make
();
55
56
fScene =
sksg::Scene::Make
(fGroup);
57
58
auto
r =
sksg::Rect::Make
({20, 20, 400, 300});
59
auto
p
=
sksg::Color::Make
(
SK_ColorRED
);
60
auto
d
=
sksg::Draw::Make
(r,
p
);
61
this->appendNode(
d
, r,
p
);
62
63
r =
sksg::Rect::Make
({60, 70, 300, 400});
64
p
=
sksg::Color::Make
(
SK_ColorBLUE
);
65
d
=
sksg::Draw::Make
(r,
p
);
66
this->appendNode(
d
, r,
p
);
67
fName
=
"SceneGraph"
;
68
}
69
70
void
draw
(
SkCanvas
* canvas)
override
{
71
fScene->render(canvas);
72
}
73
74
protected
:
75
Click
*
onFindClickHandler
(
SkScalar
x
,
SkScalar
y
,
skui::ModifierKey
modi)
override
{
76
if
(
auto
node = fScene->nodeAt({x, y})) {
77
Click
* click =
new
Click
();
78
click->
fMeta
.
setPtr
(
"node"
, (
void
*)node);
79
return
click;
80
}
81
return
nullptr
;
82
}
83
84
bool
onClick
(
Click
* click)
override
{
85
sksg::Draw
* node =
nullptr
;
86
if
(click->
fMeta
.
findPtr
(
"node"
, (
void
**)&node)) {
87
if
(
auto
info
= this->findInfo(node)) {
88
auto
geo =
info
->fGeo;
89
sksg::Rect
* r = (
sksg::Rect
*)geo;
90
SkScalar
dx
= click->
fCurr
.
fX
- click->
fPrev
.
fX
;
91
SkScalar
dy = click->
fCurr
.
fY
- click->
fPrev
.
fY
;
92
r->setL(r->getL() +
dx
);
93
r->setR(r->getR() +
dx
);
94
r->setT(r->getT() + dy);
95
r->setB(r->getB() + dy);
96
}
97
return
true
;
98
}
99
return
false
;
100
}
101
};
102
103
//////////////////////////////////////////////////////////////////////////////
104
105
DEF_SLIDE
(
return
new
SGSlide
(); )
ClickHandlerSlide.h
info
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition:
DM.cpp:213
SkCanvas.h
SK_ColorBLUE
constexpr SkColor SK_ColorBLUE
Definition:
SkColor.h:135
SK_ColorRED
constexpr SkColor SK_ColorRED
Definition:
SkColor.h:126
SkFontMetrics.h
SkFont.h
SkPath.h
SkSGDraw.h
SkSGGroup.h
SkSGPaint.h
SkSGRect.h
SkSGScene.h
SkTDArray.h
DEF_SLIDE
#define DEF_SLIDE(code)
Definition:
Slide.h:25
ClickHandlerSlide::Click
Definition:
ClickHandlerSlide.h:25
ClickHandlerSlide::Click::fMeta
SkMetaData fMeta
Definition:
ClickHandlerSlide.h:38
ClickHandlerSlide::Click::fPrev
SkPoint fPrev
Definition:
ClickHandlerSlide.h:32
ClickHandlerSlide::Click::fCurr
SkPoint fCurr
Definition:
ClickHandlerSlide.h:33
ClickHandlerSlide
Definition:
ClickHandlerSlide.h:22
SGSlide
Definition:
SGSlide.cpp:29
SGSlide::onFindClickHandler
Click * onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey modi) override
Definition:
SGSlide.cpp:75
SGSlide::onClick
bool onClick(Click *click) override
Definition:
SGSlide.cpp:84
SGSlide::SGSlide
SGSlide()
Definition:
SGSlide.cpp:53
SGSlide::draw
void draw(SkCanvas *canvas) override
Definition:
SGSlide.cpp:70
SkCanvas
Definition:
SkCanvas.h:106
SkMetaData::setPtr
void setPtr(const char name[], void *value)
Definition:
SkMetaData.cpp:42
SkMetaData::findPtr
bool findPtr(const char name[], void **value=nullptr) const
Definition:
SkMetaData.cpp:136
SkTDArray< PerNodeInfo >
SkTDArray::size
int size() const
Definition:
SkTDArray.h:138
SkTDArray::append
T * append()
Definition:
SkTDArray.h:191
Slide::fName
SkString fName
Definition:
Slide.h:54
sk_sp< sksg::Group >
sk_sp::get
T * get() const
Definition:
SkRefCnt.h:303
sksg::Color::Make
static sk_sp< Color > Make(SkColor c)
Definition:
SkSGPaint.cpp:44
sksg::Draw
Definition:
SkSGDraw.h:33
sksg::Draw::Make
static sk_sp< Draw > Make(sk_sp< GeometryNode > geo, sk_sp< PaintNode > paint)
Definition:
SkSGDraw.h:35
sksg::GeometryNode
Definition:
SkSGGeometryNode.h:26
sksg::Group::addChild
void addChild(sk_sp< RenderNode >)
Definition:
SkSGGroup.cpp:45
sksg::Group::Make
static sk_sp< Group > Make()
Definition:
SkSGGroup.h:31
sksg::PaintNode
Definition:
SkSGPaint.h:35
sksg::Rect
Definition:
SkSGRect.h:34
sksg::Rect::Make
static sk_sp< Rect > Make()
Definition:
SkSGRect.h:36
sksg::Scene::Make
static std::unique_ptr< Scene > Make(sk_sp< RenderNode > root)
Definition:
SkSGScene.cpp:16
d
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition:
main.cc:19
SkScalar
float SkScalar
Definition:
extension.cpp:12
i
int i
Definition:
fl_socket_accessible.cc:18
key
int key
Definition:
keyboard_key_handler_unittests.cc:114
y
double y
Definition:
mouse-input-test.cc:83
x
double x
Definition:
mouse-input-test.cc:82
SkRecords::dx
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
Definition:
SkRecords.h:208
dart_profiler_symbols.p
p
Definition:
dart_profiler_symbols.py:55
skui::ModifierKey
ModifierKey
Definition:
ModifierKey.h:9
PerNodeInfo
Definition:
SGSlide.cpp:20
PerNodeInfo::fPaint
sksg::PaintNode * fPaint
Definition:
SGSlide.cpp:26
PerNodeInfo::fDraw
sksg::Draw * fDraw
Definition:
SGSlide.cpp:22
PerNodeInfo::fGeo
sksg::GeometryNode * fGeo
Definition:
SGSlide.cpp:25
SkPoint::fX
float fX
x-axis value
Definition:
SkPoint_impl.h:164
SkPoint::fY
float fY
y-axis value
Definition:
SkPoint_impl.h:165
Generated on Sun Jun 23 2024 21:56:52 for Flutter Engine by
1.9.4