Player: add the pause feature

When pressing F2, the scenario will be paused/played. It can help to
understand complex scenarios.
This commit is contained in:
Daniel Zaoui 2018-12-05 13:43:37 +02:00
parent 3b05bf5786
commit 8206e75fb9
1 changed files with 35 additions and 3 deletions

View File

@ -32,6 +32,7 @@
#define PATH_ 1024 #define PATH_ 1024
#define IMAGE_FILENAME_EXT ".png" #define IMAGE_FILENAME_EXT ".png"
#define PAUSE_KEY_STR "F2"
typedef struct typedef struct
{ {
@ -146,6 +147,8 @@ static Eina_Bool _stabilization_timer_cb(void *);
static double _speed = 1.0; static double _speed = 1.0;
static Eina_Bool _exit_required = EINA_FALSE; static Eina_Bool _exit_required = EINA_FALSE;
static Eina_Bool _pause_request = EINA_FALSE;
static Eina_Bool _playing_status = EINA_FALSE;
static void static void
_printf(int verbose, const char *fmt, ...) _printf(int verbose, const char *fmt, ...)
@ -580,6 +583,7 @@ wdg_found:
act, prev_act); act, prev_act);
} }
else fprintf(stderr, "Failed finding %s.\n", t->wdg_name); else fprintf(stderr, "Failed finding %s.\n", t->wdg_name);
break;
} }
case EXACTNESS_ACTION_STABILIZE: case EXACTNESS_ACTION_STABILIZE:
{ {
@ -596,6 +600,7 @@ wdg_found:
static Eina_Bool static Eina_Bool
_feed_event_timer_cb(void *data EINA_UNUSED) _feed_event_timer_cb(void *data EINA_UNUSED)
{ {
if (_pause_request) return ECORE_CALLBACK_CANCEL;
Exactness_Action *act = eina_list_data_get(_cur_event_list); Exactness_Action *act = eina_list_data_get(_cur_event_list);
if (act) _feed_event(act->type, act->n_evas, act->data); if (act) _feed_event(act->type, act->n_evas, act->data);
@ -644,7 +649,8 @@ _stabilization_timer_cb(void *data EINA_UNUSED)
} }
if (!need_more) if (!need_more)
{ {
if (_src_type != FTYPE_REMOTE) _playing_status = EINA_FALSE;
if (_src_type != FTYPE_REMOTE && !_pause_request)
{ {
Exactness_Action *act = eina_list_data_get(_cur_event_list); Exactness_Action *act = eina_list_data_get(_cur_event_list);
_printf(2, " %s timer_time=<%f>\n", __func__, act->delay_ms / 1000.0); _printf(2, " %s timer_time=<%f>\n", __func__, act->delay_ms / 1000.0);
@ -1039,6 +1045,33 @@ _evas_del_cb(void *data EINA_UNUSED, const Efl_Event *event)
eina_list_data_set(p, NULL); eina_list_data_set(p, NULL);
} }
static void
_event_key_cb(void *data EINA_UNUSED, const Efl_Event *event)
{
Efl_Input_Key *evk = event->info;
if (!evk) return;
const char *key = efl_input_key_name_get(evk);
if (!strcmp(key, PAUSE_KEY_STR) && efl_input_key_pressed_get(evk))
{
_pause_request = !_pause_request;
if (_pause_request) _printf(1, "Pausing scenario\n");
else
{
_printf(1, "Playing scenario\n");
if (!_playing_status)
_feed_event_timer_cb(NULL);
}
}
}
EFL_CALLBACKS_ARRAY_DEFINE(_evas_callbacks,
{ EFL_EVENT_DEL, _evas_del_cb },
{ EFL_CANVAS_SCENE_EVENT_RENDER_POST, _evas_render_post_cb },
{ EFL_EVENT_KEY_DOWN, _event_key_cb },
{ EFL_EVENT_KEY_UP, _event_key_cb }
)
static Evas * static Evas *
_my_evas_new(int w EINA_UNUSED, int h EINA_UNUSED) _my_evas_new(int w EINA_UNUSED, int h EINA_UNUSED)
{ {
@ -1049,8 +1082,7 @@ _my_evas_new(int w EINA_UNUSED, int h EINA_UNUSED)
{ {
_printf(1, "New Evas\n"); _printf(1, "New Evas\n");
_evas_list = eina_list_append(_evas_list, e); _evas_list = eina_list_append(_evas_list, e);
efl_event_callback_add(e, EFL_EVENT_DEL, _evas_del_cb, NULL); efl_event_callback_array_add(e, _evas_callbacks(), NULL);
efl_event_callback_add(e, EFL_CANVAS_SCENE_EVENT_RENDER_POST, _evas_render_post_cb, NULL);
} }
return e; return e;
} }