mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-13 19:44:28 +00:00
examples stacking: ++ scene stacking.
This commit is contained in:
parent
13009657cd
commit
85587bbe79
1 changed files with 46 additions and 16 deletions
|
@ -26,14 +26,14 @@
|
|||
/* Drawing Commands */
|
||||
/************************************************************************/
|
||||
|
||||
static tvg::Shape* paints[3];
|
||||
static tvg::Paint* paints[4];
|
||||
static int order = 0;
|
||||
|
||||
void tvgDrawCmds(tvg::Canvas* canvas)
|
||||
{
|
||||
if (!canvas) return;
|
||||
|
||||
canvas->reserve(3); //reserve 3 shape nodes (optional)
|
||||
canvas->reserve(4); //reserve 3 shape nodes (optional)
|
||||
|
||||
//Prepare Round Rectangle
|
||||
auto shape1 = tvg::Shape::gen();
|
||||
|
@ -42,19 +42,39 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
shape1->fill(0, 255, 0, 255); //r, g, b, a
|
||||
if (canvas->push(move(shape1)) != tvg::Result::Success) return;
|
||||
|
||||
//Prepare Circle
|
||||
//Prepare Round Rectangle2
|
||||
auto shape2 = tvg::Shape::gen();
|
||||
paints[1] = shape2.get();
|
||||
shape2->appendRect(100, 100, 400, 400, 50, 50); //x, y, w, h, rx, ry
|
||||
shape2->fill(255, 255, 0, 255); //r, g, b, a
|
||||
if (canvas->push(move(shape2)) != tvg::Result::Success) return;
|
||||
|
||||
//Prepare Ellipse
|
||||
//Prepare Round Rectangle3
|
||||
auto shape3 = tvg::Shape::gen();
|
||||
paints[2] = shape3.get();
|
||||
shape3->appendRect(200, 200, 400, 400, 50, 50); //x, y, w, h, rx, ry
|
||||
shape3->fill(0, 255, 255, 255); //r, g, b, a
|
||||
if (canvas->push(move(shape3)) != tvg::Result::Success) return;
|
||||
|
||||
//Prepare Scene
|
||||
auto scene = tvg::Scene::gen();
|
||||
paints[3] = scene.get();
|
||||
|
||||
auto shape4 = tvg::Shape::gen();
|
||||
shape4->appendCircle(400, 400, 100, 100);
|
||||
shape4->fill(255, 0, 0, 255);
|
||||
shape4->stroke(5);
|
||||
shape4->stroke(255, 255, 255, 255);
|
||||
scene->push(move(shape4));
|
||||
|
||||
auto shape5 = tvg::Shape::gen();
|
||||
shape5->appendCircle(550, 550, 150, 150);
|
||||
shape5->fill(255, 0, 255, 255);
|
||||
shape5->stroke(5);
|
||||
shape5->stroke(255, 255, 255, 255);
|
||||
scene->push(move(shape5));
|
||||
|
||||
if (canvas->push(move(scene)) != tvg::Result::Success) return;
|
||||
}
|
||||
|
||||
|
||||
|
@ -67,25 +87,35 @@ void tvgUpdateCmds(tvg::Canvas* canvas)
|
|||
|
||||
switch (order) {
|
||||
case 0:
|
||||
canvas->push(unique_ptr<tvg::Shape>(paints[0]));
|
||||
canvas->push(unique_ptr<tvg::Shape>(paints[1]));
|
||||
canvas->push(unique_ptr<tvg::Shape>(paints[2]));
|
||||
canvas->push(unique_ptr<tvg::Shape>((tvg::Shape*)paints[0]));
|
||||
canvas->push(unique_ptr<tvg::Shape>((tvg::Shape*)paints[1]));
|
||||
canvas->push(unique_ptr<tvg::Shape>((tvg::Shape*)paints[2]));
|
||||
canvas->push(unique_ptr<tvg::Scene>((tvg::Scene*)paints[3]));
|
||||
break;
|
||||
case 1:
|
||||
canvas->push(unique_ptr<tvg::Shape>(paints[1]));
|
||||
canvas->push(unique_ptr<tvg::Shape>(paints[2]));
|
||||
canvas->push(unique_ptr<tvg::Shape>(paints[0]));
|
||||
canvas->push(unique_ptr<tvg::Shape>((tvg::Shape*)paints[1]));
|
||||
canvas->push(unique_ptr<tvg::Shape>((tvg::Shape*)paints[2]));
|
||||
canvas->push(unique_ptr<tvg::Scene>((tvg::Scene*)paints[3]));
|
||||
canvas->push(unique_ptr<tvg::Shape>((tvg::Shape*)paints[0]));
|
||||
break;
|
||||
case 2:
|
||||
canvas->push(unique_ptr<tvg::Shape>(paints[2]));
|
||||
canvas->push(unique_ptr<tvg::Shape>(paints[0]));
|
||||
canvas->push(unique_ptr<tvg::Shape>(paints[1]));
|
||||
canvas->push(unique_ptr<tvg::Shape>((tvg::Shape*)paints[2]));
|
||||
canvas->push(unique_ptr<tvg::Scene>((tvg::Scene*)paints[3]));
|
||||
canvas->push(unique_ptr<tvg::Shape>((tvg::Shape*)paints[0]));
|
||||
canvas->push(unique_ptr<tvg::Shape>((tvg::Shape*)paints[1]));
|
||||
break;
|
||||
case 3:
|
||||
canvas->push(unique_ptr<tvg::Scene>((tvg::Scene*)paints[3]));
|
||||
canvas->push(unique_ptr<tvg::Shape>((tvg::Shape*)paints[0]));
|
||||
canvas->push(unique_ptr<tvg::Shape>((tvg::Shape*)paints[1]));
|
||||
canvas->push(unique_ptr<tvg::Shape>((tvg::Shape*)paints[2]));
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
++order;
|
||||
|
||||
if (order > 2) order = 0;
|
||||
if (order > 3) order = 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -199,10 +229,10 @@ int main(int argc, char **argv)
|
|||
|
||||
if (tvgEngine == tvg::CanvasEngine::Sw) {
|
||||
auto view = createSwView();
|
||||
ecore_timer_add(0.5, timerSwCb, view);
|
||||
ecore_timer_add(0.33, timerSwCb, view);
|
||||
} else {
|
||||
auto view = createGlView();
|
||||
ecore_timer_add(0.5, timerGlCb, view);
|
||||
ecore_timer_add(0.33, timerGlCb, view);
|
||||
}
|
||||
|
||||
elm_run();
|
||||
|
|
Loading…
Add table
Reference in a new issue