common scene: design load()/save() interfaces

these interfaces will perform for vector resources such as svg/tvg/etc ...

see testSvg examples

Change-Id: Icec0a4682301a13646868bd7c3bfc1771ae7db2c
This commit is contained in:
Hermet Park 2020-06-16 15:28:43 +09:00
parent f627679882
commit c235b7b81d
7 changed files with 171 additions and 0 deletions

2
.gitignore vendored
View file

@ -17,3 +17,5 @@ testStrokeLine
testLinearGradient testLinearGradient
testRadialGradient testRadialGradient
testGradientTransform testGradientTransform
testSvg
testSvg2

View file

@ -71,6 +71,7 @@ enum class TVG_EXPORT StrokeJoin { Bevel = 0, Round, Miter };
enum class TVG_EXPORT FillSpread { Pad = 0, Reflect, Repeat }; enum class TVG_EXPORT FillSpread { Pad = 0, Reflect, Repeat };
enum class TVG_EXPORT CanvasEngine { Sw = 0, Gl }; enum class TVG_EXPORT CanvasEngine { Sw = 0, Gl };
struct Point struct Point
{ {
float x, y; float x, y;
@ -282,6 +283,9 @@ public:
Result push(std::unique_ptr<Paint> paint) noexcept; Result push(std::unique_ptr<Paint> paint) noexcept;
Result reserve(uint32_t size) noexcept; Result reserve(uint32_t size) noexcept;
Result load(const std::string& path, float w, float h, bool lazy = false) noexcept;
Result save(const std::string& path) noexcept;
Result rotate(float degree) noexcept override; Result rotate(float degree) noexcept override;
Result scale(float factor) noexcept override; Result scale(float factor) noexcept override;
Result translate(float x, float y) noexcept override; Result translate(float x, float y) noexcept override;

View file

@ -107,4 +107,27 @@ Result Scene::bounds(float* x, float* y, float* w, float* h) const noexcept
return Result::Success; return Result::Success;
} }
Result Scene::load(const std::string& path, float w, float h, bool lazy) noexcept
{
if (path.empty()) return Result::InvalidArguments;
auto impl = pImpl.get();
if (!impl) return Result::MemoryCorruption;
return impl->load(path, w, h, lazy);
}
Result Scene::save(const std::string& path) noexcept
{
if (path.empty()) return Result::InvalidArguments;
auto impl = pImpl.get();
if (!impl) return Result::MemoryCorruption;
return impl->save(path);
}
#endif /* _TVG_SCENE_CPP_ */ #endif /* _TVG_SCENE_CPP_ */

View file

@ -191,6 +191,16 @@ struct Scene::Impl
return true; return true;
} }
Result load(const string& path, float w, float h, bool lazy)
{
return Result::Success;
}
Result save(const string& path)
{
return Result::Success;
}
}; };
#endif //_TVG_SCENE_IMPL_H_ #endif //_TVG_SCENE_IMPL_H_

View file

@ -15,3 +15,5 @@ all:
gcc -o testLinearGradient testLinearGradient.cpp -g -lstdc++ `pkg-config --cflags --libs elementary tizenvg` gcc -o testLinearGradient testLinearGradient.cpp -g -lstdc++ `pkg-config --cflags --libs elementary tizenvg`
gcc -o testRadialGradient testRadialGradient.cpp -g -lstdc++ `pkg-config --cflags --libs elementary tizenvg` gcc -o testRadialGradient testRadialGradient.cpp -g -lstdc++ `pkg-config --cflags --libs elementary tizenvg`
gcc -o testGradientTransform testGradientTransform.cpp -g -lstdc++ `pkg-config --cflags --libs elementary tizenvg` gcc -o testGradientTransform testGradientTransform.cpp -g -lstdc++ `pkg-config --cflags --libs elementary tizenvg`
gcc -o testSvg testSvg.cpp -g -lstdc++ `pkg-config --cflags --libs elementary tizenvg`
gcc -o testSvg2 testSvg2.cpp -g -lstdc++ `pkg-config --cflags --libs elementary tizenvg`

63
test/testSvg.cpp Normal file
View file

@ -0,0 +1,63 @@
#include <tizenvg.h>
#include <Elementary.h>
using namespace std;
#define WIDTH 800
#define HEIGHT 800
static uint32_t buffer[WIDTH * HEIGHT];
void tvgtest()
{
//Initialize TizenVG Engine
tvg::Initializer::init(tvg::CanvasEngine::Sw);
//Create a Canvas
auto canvas = tvg::SwCanvas::gen();
canvas->target(buffer, WIDTH, WIDTH, HEIGHT);
/* Create a SVG scene, keep original size,
You can pass 0 x 0 size for lazying loading in this case.
scene->load("sample.svg", 0, 0, true); */
auto scene = tvg::Scene::gen();
scene->load("sample.svg");
canvas->push(move(scene));
canvas->draw();
canvas->sync();
//Terminate TizenVG Engine
tvg::Initializer::term(tvg::CanvasEngine::Sw);
}
void
win_del(void *data, Evas_Object *o, void *ev)
{
elm_exit();
}
int main(int argc, char **argv)
{
tvgtest();
//Show the result using EFL...
elm_init(argc, argv);
Eo* win = elm_win_util_standard_add(NULL, "TizenVG Test");
evas_object_smart_callback_add(win, "delete,request", win_del, 0);
Eo* img = evas_object_image_filled_add(evas_object_evas_get(win));
evas_object_image_size_set(img, WIDTH, HEIGHT);
evas_object_image_data_set(img, buffer);
evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_show(img);
elm_win_resize_object_add(win, img);
evas_object_geometry_set(win, 0, 0, WIDTH, HEIGHT);
evas_object_show(win);
elm_run();
elm_shutdown();
}

67
test/testSvg2.cpp Normal file
View file

@ -0,0 +1,67 @@
#include <tizenvg.h>
#include <Elementary.h>
using namespace std;
#define WIDTH 800
#define HEIGHT 800
static uint32_t buffer[WIDTH * HEIGHT];
void tvgtest()
{
//Initialize TizenVG Engine
tvg::Initializer::init(tvg::CanvasEngine::Sw);
//Create a Canvas
auto canvas = tvg::SwCanvas::gen();
canvas->target(buffer, WIDTH, WIDTH, HEIGHT);
//Create a SVG scene, keep aspect ratio to width/2 with lazy loading
auto scene = tvg::Scene::gen();
scene->load("sample.svg", WIDTH/2, 0, true);
canvas->push(move(scene));
//Create a SVG scene, keep aspect ratio to height/2 with lazy loading
auto scene2 = tvg::Scene::gen();
scene2->load("sample.svg", 0, HEIGHT/2, true);
scene2->translate(WIDTH/2, HEIGHT/2);
canvas->push(move(scene2));
canvas->draw();
canvas->sync();
//Terminate TizenVG Engine
tvg::Initializer::term(tvg::CanvasEngine::Sw);
}
void
win_del(void *data, Evas_Object *o, void *ev)
{
elm_exit();
}
int main(int argc, char **argv)
{
tvgtest();
//Show the result using EFL...
elm_init(argc, argv);
Eo* win = elm_win_util_standard_add(NULL, "TizenVG Test");
evas_object_smart_callback_add(win, "delete,request", win_del, 0);
Eo* img = evas_object_image_filled_add(evas_object_evas_get(win));
evas_object_image_size_set(img, WIDTH, HEIGHT);
evas_object_image_data_set(img, buffer);
evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_show(img);
elm_win_resize_object_add(win, img);
evas_object_geometry_set(win, 0, 0, WIDTH, HEIGHT);
evas_object_show(win);
elm_run();
elm_shutdown();
}