examples stacking: ++ scene stacking.

This commit is contained in:
Hermet Park 2021-06-09 21:07:13 +09:00
parent 13009657cd
commit 85587bbe79

View file

@ -26,14 +26,14 @@
/* Drawing Commands */ /* Drawing Commands */
/************************************************************************/ /************************************************************************/
static tvg::Shape* paints[3]; static tvg::Paint* paints[4];
static int order = 0; static int order = 0;
void tvgDrawCmds(tvg::Canvas* canvas) void tvgDrawCmds(tvg::Canvas* canvas)
{ {
if (!canvas) return; if (!canvas) return;
canvas->reserve(3); //reserve 3 shape nodes (optional) canvas->reserve(4); //reserve 3 shape nodes (optional)
//Prepare Round Rectangle //Prepare Round Rectangle
auto shape1 = tvg::Shape::gen(); auto shape1 = tvg::Shape::gen();
@ -42,19 +42,39 @@ void tvgDrawCmds(tvg::Canvas* canvas)
shape1->fill(0, 255, 0, 255); //r, g, b, a shape1->fill(0, 255, 0, 255); //r, g, b, a
if (canvas->push(move(shape1)) != tvg::Result::Success) return; if (canvas->push(move(shape1)) != tvg::Result::Success) return;
//Prepare Circle //Prepare Round Rectangle2
auto shape2 = tvg::Shape::gen(); auto shape2 = tvg::Shape::gen();
paints[1] = shape2.get(); paints[1] = shape2.get();
shape2->appendRect(100, 100, 400, 400, 50, 50); //x, y, w, h, rx, ry shape2->appendRect(100, 100, 400, 400, 50, 50); //x, y, w, h, rx, ry
shape2->fill(255, 255, 0, 255); //r, g, b, a shape2->fill(255, 255, 0, 255); //r, g, b, a
if (canvas->push(move(shape2)) != tvg::Result::Success) return; if (canvas->push(move(shape2)) != tvg::Result::Success) return;
//Prepare Ellipse //Prepare Round Rectangle3
auto shape3 = tvg::Shape::gen(); auto shape3 = tvg::Shape::gen();
paints[2] = shape3.get(); paints[2] = shape3.get();
shape3->appendRect(200, 200, 400, 400, 50, 50); //x, y, w, h, rx, ry shape3->appendRect(200, 200, 400, 400, 50, 50); //x, y, w, h, rx, ry
shape3->fill(0, 255, 255, 255); //r, g, b, a shape3->fill(0, 255, 255, 255); //r, g, b, a
if (canvas->push(move(shape3)) != tvg::Result::Success) return; 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) { switch (order) {
case 0: case 0:
canvas->push(unique_ptr<tvg::Shape>(paints[0])); canvas->push(unique_ptr<tvg::Shape>((tvg::Shape*)paints[0]));
canvas->push(unique_ptr<tvg::Shape>(paints[1])); canvas->push(unique_ptr<tvg::Shape>((tvg::Shape*)paints[1]));
canvas->push(unique_ptr<tvg::Shape>(paints[2])); canvas->push(unique_ptr<tvg::Shape>((tvg::Shape*)paints[2]));
canvas->push(unique_ptr<tvg::Scene>((tvg::Scene*)paints[3]));
break; break;
case 1: case 1:
canvas->push(unique_ptr<tvg::Shape>(paints[1])); canvas->push(unique_ptr<tvg::Shape>((tvg::Shape*)paints[1]));
canvas->push(unique_ptr<tvg::Shape>(paints[2])); canvas->push(unique_ptr<tvg::Shape>((tvg::Shape*)paints[2]));
canvas->push(unique_ptr<tvg::Shape>(paints[0])); canvas->push(unique_ptr<tvg::Scene>((tvg::Scene*)paints[3]));
canvas->push(unique_ptr<tvg::Shape>((tvg::Shape*)paints[0]));
break; break;
case 2: case 2:
canvas->push(unique_ptr<tvg::Shape>(paints[2])); canvas->push(unique_ptr<tvg::Shape>((tvg::Shape*)paints[2]));
canvas->push(unique_ptr<tvg::Shape>(paints[0])); canvas->push(unique_ptr<tvg::Scene>((tvg::Scene*)paints[3]));
canvas->push(unique_ptr<tvg::Shape>(paints[1])); canvas->push(unique_ptr<tvg::Shape>((tvg::Shape*)paints[0]));
canvas->push(unique_ptr<tvg::Shape>((tvg::Shape*)paints[1]));
break; 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; ++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) { if (tvgEngine == tvg::CanvasEngine::Sw) {
auto view = createSwView(); auto view = createSwView();
ecore_timer_add(0.5, timerSwCb, view); ecore_timer_add(0.33, timerSwCb, view);
} else { } else {
auto view = createGlView(); auto view = createGlView();
ecore_timer_add(0.5, timerGlCb, view); ecore_timer_add(0.33, timerGlCb, view);
} }
elm_run(); elm_run();