2 #include <Elementary.h>
3 #include <rive_tizen.hpp>
5 #include "animation/linear_animation_instance.hpp"
6 #include "artboard.hpp"
8 #include "thorvg_renderer.hpp"
15 static unique_ptr<tvg::SwCanvas> canvas;
16 static rive::File* currentFile = nullptr;
17 static rive::Artboard* artboard = nullptr;
18 static rive::LinearAnimationInstance* animationInstance = nullptr;
20 static void deleteWindow(void *data, Evas_Object *obj, void *ev)
25 static void drawToCanvas(void* data, Eo* obj)
27 if (canvas->draw() == tvg::Result::Success)
33 static void runExample(uint32_t* buffer)
36 canvas = tvg::SwCanvas::gen();
37 canvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
40 char *filename = "../../example/shapes.riv";
41 FILE* fp = fopen(filename, "r");
43 fseek(fp, 0, SEEK_END);
44 auto length = ftell(fp);
45 fseek(fp, 0, SEEK_SET);
47 uint8_t* bytes = new uint8_t[length];
48 if (fread(bytes, 1, length, fp) != length)
51 fprintf(stderr, "failed to read all of %s\n", filename);
55 auto reader = rive::BinaryReader(bytes, length);
56 rive::File* file = nullptr;
57 auto result = rive::File::import(reader, &file);
58 if (result != rive::ImportResult::success)
61 fprintf(stderr, "failed to import %s\n", filename);
65 artboard = file->artboard();
67 delete animationInstance;
69 auto animation = artboard->firstAnimation<rive::LinearAnimation>();
70 if (animation != nullptr)
72 animationInstance = new rive::LinearAnimationInstance(animation);
73 animationInstance->advance(0);
77 animationInstance = nullptr;
80 rive::ThorvgRenderer renderer(canvas.get());
84 artboard->draw(&renderer);
92 static void cleanExample()
94 delete animationInstance;
98 static void setupScreen(uint32_t* buffer)
100 Eo* win = elm_win_util_standard_add(NULL, "Rive Viewer");
101 evas_object_smart_callback_add(win, "delete,request", deleteWindow, 0);
103 Eo* view = evas_object_image_filled_add(evas_object_evas_get(win));
104 evas_object_image_size_set(view, WIDTH, HEIGHT);
105 evas_object_image_data_set(view, buffer);
106 evas_object_image_pixels_get_callback_set(view, drawToCanvas, nullptr);
107 evas_object_image_pixels_dirty_set(view, EINA_TRUE);
108 evas_object_image_data_update_add(view, 0, 0, WIDTH, HEIGHT);
109 evas_object_size_hint_weight_set(view, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
110 evas_object_show(view);
112 elm_win_resize_object_add(win, view);
113 evas_object_resize(win, WIDTH, HEIGHT);
114 evas_object_show(win);
117 int main(int argc, char **argv)
119 static uint32_t buffer[WIDTH * HEIGHT];
121 tvg::Initializer::init(tvg::CanvasEngine::Sw, thread::hardware_concurrency());
123 elm_init(argc, argv);
135 tvg::Initializer::term(tvg::CanvasEngine::Sw);