Flutter Engine
The Flutter Engine
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
11#include "include/core/SkPath.h"
19
21 // key
23
24 // value(s)
27};
28
29class SGSlide : public ClickHandlerSlide {
30 // TODO(kjlubick) use a vector instead of our private SkTDArray
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
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
52public:
54 fGroup = sksg::Group::Make();
55
56 fScene = sksg::Scene::Make(fGroup);
57
58 auto r = sksg::Rect::Make({20, 20, 400, 300});
60 auto d = sksg::Draw::Make(r, p);
61 this->appendNode(d, r, p);
62
63 r = sksg::Rect::Make({60, 70, 300, 400});
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
74protected:
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
105DEF_SLIDE( return new SGSlide(); )
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
#define DEF_SLIDE(code)
Definition: Slide.h:25
Click * onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey modi) override
Definition: SGSlide.cpp:75
bool onClick(Click *click) override
Definition: SGSlide.cpp:84
SGSlide()
Definition: SGSlide.cpp:53
void draw(SkCanvas *canvas) override
Definition: SGSlide.cpp:70
void setPtr(const char name[], void *value)
Definition: SkMetaData.cpp:42
bool findPtr(const char name[], void **value=nullptr) const
Definition: SkMetaData.cpp:136
int size() const
Definition: SkTDArray.h:138
T * append()
Definition: SkTDArray.h:191
SkString fName
Definition: Slide.h:54
T * get() const
Definition: SkRefCnt.h:303
static sk_sp< Color > Make(SkColor c)
Definition: SkSGPaint.cpp:44
static sk_sp< Draw > Make(sk_sp< GeometryNode > geo, sk_sp< PaintNode > paint)
Definition: SkSGDraw.h:35
void addChild(sk_sp< RenderNode >)
Definition: SkSGGroup.cpp:45
static sk_sp< Group > Make()
Definition: SkSGGroup.h:31
static sk_sp< Rect > Make()
Definition: SkSGRect.h:36
static std::unique_ptr< Scene > Make(sk_sp< RenderNode > root)
Definition: SkSGScene.cpp:16
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition: main.cc:19
float SkScalar
Definition: extension.cpp:12
double y
double x
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
Definition: SkRecords.h:208
ModifierKey
Definition: ModifierKey.h:9
sksg::PaintNode * fPaint
Definition: SGSlide.cpp:26
sksg::Draw * fDraw
Definition: SGSlide.cpp:22
sksg::GeometryNode * fGeo
Definition: SGSlide.cpp:25
float fX
x-axis value
Definition: SkPoint_impl.h:164
float fY
y-axis value
Definition: SkPoint_impl.h:165