diff --git a/examples/DirectUpdate.cpp b/examples/DirectUpdate.cpp index 8d373202..ed60464f 100644 --- a/examples/DirectUpdate.cpp +++ b/examples/DirectUpdate.cpp @@ -29,10 +29,28 @@ struct UserExample : tvgexam::Example { tvg::Shape* solid = nullptr; - tvg::Shape* gradient = nullptr; - uint32_t w, h; + void bbox(tvg::Canvas* canvas, tvg::Paint* paint) + { + //aabb + { + float x, y, w, h; + paint->bounds(&x, &y, &w, &h); + + auto bound = tvg::Shape::gen(); + bound->moveTo(x, y); + bound->lineTo(x + w, y); + bound->lineTo(x + w, y + h); + bound->lineTo(x, y + h); + bound->close(); + bound->strokeWidth(2.0f); + bound->strokeFill(255, 0, 0, 255); + + canvas->push(bound); + } + } + bool content(tvg::Canvas* canvas, uint32_t w, uint32_t h) override { //Shape (for BG) @@ -41,66 +59,25 @@ struct UserExample : tvgexam::Example bg->fill(255, 255, 255); canvas->push(bg); - //Solid Shape - { - solid = tvg::Shape::gen(); - solid->appendRect(-100, -100, 200, 200); + solid = tvg::Shape::gen(); + solid->moveTo(100, 100); + solid->lineTo(120, 100); + solid->lineTo(120, 120); + solid->close(); + solid->fill(0, 0, 0, 255); + solid->strokeFill(0, 255, 255, 125); + solid->strokeWidth(5); + tvg::Matrix m = {3, 0, 450, 0, 3, 100, 0, 0, 1}; + solid->transform(m); + canvas->push(solid); - //fill property will be retained - solid->fill(127, 255, 255); - solid->strokeFill(0, 0, 255); - solid->strokeWidth(1); - - canvas->push(solid); - } - - //Gradient Shape - { - gradient = tvg::Shape::gen(); - gradient->appendRect(w - 200, 0, 200, 200); - - //LinearGradient - auto fill = tvg::LinearGradient::gen(); - fill->linear(w - 200, 0, w - 200 + 285, 300); - - //Gradient Color Stops - tvg::Fill::ColorStop colorStops[3]; - colorStops[0] = {0, 255, 0, 0, 127}; - colorStops[1] = {0.5, 255, 255, 0, 127}; - colorStops[2] = {1, 255, 255, 255, 127}; - - fill->colorStops(colorStops, 3); - gradient->fill(fill); - - canvas->push(gradient); - } + bbox(canvas, solid); this->w = w; this->h = h; return true; } - - bool update(tvg::Canvas* canvas, uint32_t elapsed) override - { - auto progress = tvgexam::progress(elapsed, 2.0f, true); //play time 2 sec. - - //Reset Shape - if (tvgexam::verify(solid->reset())) { - //Solid Shape - solid->appendRect(-100 + (w * progress), -100 + (h * progress), 200, 200, (100 * progress), (100 * progress)); - solid->strokeWidth(30 * progress); - - //Gradient Shape - gradient->translate(-(w * progress), (h * progress)); - - canvas->update(); - - return true; - } - - return false; - } };