static Eo* view = nullptr;
static vector<std::string> rivefiles;
static double lastTime;
+static Eo* statePopup = nullptr;
static void deleteWindow(void *data, Evas_Object *obj, void *ev)
{
return !strcmp(dot + 1, "riv");
}
+static void initAnimation(int index)
+{
+ delete animationInstance;
+ animationInstance = nullptr;
+
+ auto animation = artboard->animation(index);
+ if (animation) animationInstance = new rive::LinearAnimationInstance(animation);
+}
+
static void loadRiveFile(const char* filename)
{
lastTime = ecore_time_get(); //Check point
delete animationInstance;
animationInstance = nullptr;
- auto animation = artboard->firstAnimation<rive::LinearAnimation>();
+ auto animation = artboard->firstAnimation();
if (animation) animationInstance = new rive::LinearAnimationInstance(animation);
delete currentFile;
{
Elm_Object_Item *item = elm_list_selected_item_get(obj);
int index = 0;
- for (Elm_Object_Item *iter = item; iter != NULL; iter = elm_list_item_prev(iter))
+ for (Elm_Object_Item *iter = item; iter != nullptr; iter = elm_list_item_prev(iter))
{
index++;
}
if (rivefiles.size() > 0) loadRiveFile(rivefiles[index-1].c_str());
+ if (statePopup) elm_ctxpopup_dismiss(statePopup);
}
static std::vector<std::string> riveFiles(const std::string &dirName)
d = opendir(dirName.c_str());
if (d)
{
- while ((dir = readdir(d)) != NULL)
+ while ((dir = readdir(d)) != nullptr)
{
if (isRiveFile(dir->d_name)) result.push_back(dirName + dir->d_name);
}
Eina_Bool animationLoop(void *data)
{
+ canvas->clear();
+
double currentTime = ecore_time_get();
float elapsed = currentTime - lastTime;
lastTime = currentTime;
delete animationInstance;
}
+static void animPopupItemCb(void *data EINA_UNUSED, Evas_Object *obj, void *event_info)
+{
+ int animationIndex = static_cast<int>(reinterpret_cast<intptr_t>(data));
+ initAnimation(animationIndex);
+ elm_ctxpopup_dismiss(statePopup);
+}
+
+static Elm_Object_Item* animPopupItemNew(Evas_Object *obj, const char *label, int index)
+{
+ Elm_Object_Item *it = nullptr;
+
+ if (!obj) return nullptr;
+
+ return elm_ctxpopup_item_append(obj, label, nullptr, animPopupItemCb, (void*)index);
+}
+
+static void animPopupDismissCb(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
+{
+ evas_object_del(obj);
+ statePopup = nullptr;
+}
+
+static void viewClickedCb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
+{
+ if (!artboard) return;
+ if (statePopup) evas_object_del(statePopup);
+
+ statePopup = elm_ctxpopup_add(obj);
+ evas_object_smart_callback_add(statePopup, "dismissed", animPopupDismissCb, nullptr);
+
+ for (int index = 0; index < artboard->animationCount(); index++)
+ animPopupItemNew(statePopup, artboard->animation(index)->name().c_str(), index);
+
+ int x, y;
+ evas_pointer_canvas_xy_get(evas_object_evas_get(obj), &x, &y);
+ evas_object_move(statePopup, x, y);
+ evas_object_show(statePopup);
+}
+
static void setupScreen(uint32_t* buffer)
{
- Eo* win = elm_win_util_standard_add(NULL, "Rive Viewer");
+ Eo* win = elm_win_util_standard_add(nullptr, "Rive Viewer");
evas_object_smart_callback_add(win, "delete,request", deleteWindow, 0);
Eo* box = elm_box_add(win);
evas_object_show(view);
elm_box_pack_end(box, view);
+ evas_object_event_callback_add(view, EVAS_CALLBACK_MOUSE_UP, viewClickedCb, nullptr);
Eo *fileList = elm_list_add(box);
evas_object_size_hint_weight_set(fileList, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
for (size_t i = 0; i < rivefiles.size(); i++)
{
const char *ptr = strrchr(rivefiles[i].c_str(), '/');
- elm_list_item_append(fileList, ptr + 1, NULL, NULL, fileClickedCb, NULL);
+ elm_list_item_append(fileList, ptr + 1, nullptr, nullptr, fileClickedCb, nullptr);
}
elm_list_go(fileList);