summaryrefslogtreecommitdiff
path: root/src/lib/elementary/efl_ui_mi_controller.c
blob: 690babeee172df08cd62ae6498e48674f0e83741 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif

#define EFL_ACCESS_OBJECT_PROTECTED
#define EFL_PART_PROTECTED

#include <Elementary.h>

#include "elm_priv.h"
#include "efl_ui_mi_state.eo.h"
#include "efl_ui_mi_controller_private.h"
//#include "efl_ui_mi_controller_part.eo.h"
//#include "elm_part_helper.h"

#define MY_CLASS EFL_UI_MI_CONTROLLER_CLASS

#define MY_CLASS_NAME "Efl_Ui_Mi_Controller"

static const char SIG_FOCUSED[] = "focused";
static const char SIG_UNFOCUSED[] = "unfocused";

/* smart callbacks coming from efl_ui_mi_controller objects: */
static const Evas_Smart_Cb_Description _smart_callbacks[] = {
   {SIG_FOCUSED, ""},
   {SIG_UNFOCUSED, ""},
   {SIG_WIDGET_LANG_CHANGED, ""}, /**< handled by elm_widget */
   {NULL, NULL}
};

EOLIAN static void
_efl_ui_mi_controller_repeat_mode_set(Eo *obj EINA_UNUSED, Efl_Ui_Mi_Controller_Data *pd, Efl_Ui_Mi_Controller_Repeat_Mode mode)
{
}

EOLIAN static Efl_Ui_Mi_Controller_Repeat_Mode
_efl_ui_mi_controller_repeat_mode_get(const Eo *obj EINA_UNUSED, Efl_Ui_Mi_Controller_Data *pd)
{
   return 0;
}

Eina_Bool
_efl_ui_mi_controller_trigger(Eo *obj, Efl_Ui_Mi_Controller_Data *pd, const char *start, Eina_Bool animation)
{

   Efl_Ui_Mi_State *state;
   Eina_Array_Iterator iter;
   unsigned int i;
   const char *_start;
   const char *_end;

   EINA_ARRAY_ITER_NEXT(pd->states, i, state, iter)
    {
        efl_ui_mi_state_sector_get(state, &_start, NULL);
        if (_start && !strcmp(start, _start))
          break;
    }

   pd->cur_state_idx = i;
   efl_ui_mi_state_sector_get(state, &_start, &_end);
   if (_start)
     {
        efl_event_callback_call(state, EFL_UI_MI_STATE_EVENT_TRIGGER, NULL);
        efl_ui_vg_animation_playing_sector(pd->anim, _start, _end);
     }
   else
     ERR("No start point");

   return EINA_FALSE;
}

Eina_Bool
_efl_ui_mi_controller_trigger_next(Eo *obj, Efl_Ui_Mi_Controller_Data *pd, Eina_Bool animation)
{
   if (!pd->states) return EINA_FALSE;

   int states = eina_array_count_get (pd->states);
   int cur_idx = 0;
   if (states < pd->cur_state_idx)
     cur_idx = pd->cur_state_idx;
   else
     cur_idx = pd->cur_state_idx + 1;


   Efl_Ui_Mi_State *cur_state = eina_array_data_get (pd->states, cur_idx);
   if (!cur_state) return EINA_FALSE;

   const char *_start;
   const char *_end;
   efl_ui_mi_state_sector_get(cur_state, &_start, &_end);

   if (_start)
     {
        efl_event_callback_call(cur_state, EFL_UI_MI_STATE_EVENT_TRIGGER, NULL);
        efl_ui_vg_animation_playing_sector(pd->anim, _start, _end);
     }
   else
     ERR("No start point");

   pd->cur_state_idx++;
   return EINA_TRUE;
}

Eina_Bool
_efl_ui_mi_controller_trigger_prev(Eo *obj, Efl_Ui_Mi_Controller_Data *pd, Eina_Bool animation)
{
   //change state and play
   return EINA_FALSE;
}

EOLIAN static Eo*
_efl_ui_mi_controller_state_get(const Eo *eo_obj, Efl_Ui_Mi_Controller_Data *pd,
                                const char *state_name)
{
   Efl_Ui_Mi_State *state;
   Eina_Array_Iterator iter;
   unsigned int i;
   const char *_name;

   EINA_ARRAY_ITER_NEXT(pd->states, i, state, iter)
    {
        efl_ui_mi_state_sector_get(state, &_name, NULL);
        if (_name && !strcmp(state_name, _name))
          return state;
    }

   return NULL;
}

Eina_Bool
_efl_ui_mi_controller_state_add(Eo *obj, Efl_Ui_Mi_Controller_Data *pd, Efl_Ui_Mi_State *state)
{

   if (!state) return EINA_FALSE;
   if (!pd->states)
     {
         pd->states = eina_array_new(sizeof(Efl_Ui_Mi_State*));
     }

   eina_array_push(pd->states, state);
   return EINA_FALSE;
}


static void
_sizing_eval(Eo *obj, void *data)
{
   Efl_Ui_Mi_Controller_Data *pd = data;
   if (!efl_file_loaded_get(pd->anim)) return;

   double hw,hh;
   efl_gfx_hint_weight_get(obj, &hw, &hh);

   Eina_Size2D size = efl_ui_vg_animation_default_view_size_get(pd->anim);

   Eina_Size2D min = {-1, -1};
   if (hw == 0) min.w = size.w;
   if (hh == 0) min.h = size.h;
   efl_gfx_hint_size_min_set(obj, min);
}

EOLIAN static Eina_Error
_efl_ui_mi_controller_efl_file_load(Eo *obj, Efl_Ui_Mi_Controller_Data *pd)
{
   Eina_Error err;
   Eina_Bool ret;
   const char *file;
   const char *key;

   if (efl_file_loaded_get(obj)) return 0;

   err = efl_file_load(efl_super(obj, MY_CLASS));
   if (err) return err;

   file = efl_file_get(obj);
   key = efl_file_key_get(obj);
   ret = efl_file_simple_load(pd->anim, file, key);
   if (!ret)
     {
        ERR("Efl.Ui.Mi_Controller File load fail : %s\n", file);
        efl_file_unload(obj);
        return eina_error_get();
     }
   _sizing_eval(obj, pd);

   //temporary
   Eo *vg = efl_key_data_get(pd->anim, "vg_obj");
   Eina_List *sector_list = efl_gfx_frame_controller_sector_list_get(vg);

   if (sector_list)
     {
        Eina_List *l;
        Efl_Gfx_Frame_Sector_Data *sector;
        Eo *state = NULL;
        const char *start_sector = NULL, *end_sector = NULL;

        EINA_LIST_FOREACH(sector_list, l, sector)
          {
             start_sector = end_sector;
             end_sector = sector->name;
             if (start_sector && end_sector)
               {
                  state = efl_add(EFL_UI_MI_STATE_CLASS, obj);
                  efl_key_data_set(state, "controller", obj);
                  efl_ui_mi_state_sector_set(state, start_sector, end_sector);
                  efl_ui_mi_controller_state_add(obj, state);
               }
          }
        state = efl_add(EFL_UI_MI_STATE_CLASS, obj);
        efl_key_data_set(state, "controller", obj);
        efl_ui_mi_state_sector_set(state, "*", NULL);
        efl_ui_mi_controller_state_add(obj, state);

        EINA_LIST_FOREACH(sector_list, l, sector)
          {
             free((char*)sector->name);
             free(sector);
          }
        eina_list_free(sector_list);
     }
   return 0;
}

EOLIAN static void
_efl_ui_mi_controller_efl_gfx_view_view_size_set(Eo *obj EINA_UNUSED,
                                                  Efl_Ui_Mi_Controller_Data *pd,
                                                  Eina_Size2D size)
{
   efl_gfx_view_size_set(pd->anim, size);
}

EOLIAN Eina_Size2D
_efl_ui_mi_controller_efl_gfx_view_view_size_get(const Eo *obj EINA_UNUSED,
                                                  Efl_Ui_Mi_Controller_Data *pd)
{
   Eina_Size2D view_size = efl_gfx_view_size_get(pd->anim);

   return view_size;
}
static void
_size_hint_event_cb(void *data, const Efl_Event *event)
{
   _sizing_eval(event->object, data);
}

static void
_animation_playback_progress_changed_cb(void *data, const Efl_Event *event)
{
   Eo* obj = data;
   Efl_Ui_Mi_Controller_Data *pd = efl_data_scope_safe_get(obj, MY_CLASS);
   if (!pd) return NULL;

   Efl_Ui_Mi_State *cur_state = eina_array_data_get (pd->states, pd->cur_state_idx);
   efl_event_callback_call(cur_state, EFL_UI_MI_STATE_EVENT_FEEDBACK, (double*)event->info);
}

EOLIAN static void
_efl_ui_mi_controller_efl_canvas_group_group_add(Eo *obj, Efl_Ui_Mi_Controller_Data *pd)
{
   efl_canvas_group_add(efl_super(obj, MY_CLASS));
   elm_widget_sub_object_parent_add(obj);

   pd->anim = efl_add(EFL_UI_VG_ANIMATION_CLASS, obj);
   elm_widget_resize_object_set(obj, pd->anim);

   efl_event_callback_add(pd->anim, EFL_PLAYER_EVENT_PLAYBACK_PROGRESS_CHANGED, _animation_playback_progress_changed_cb, obj);
   efl_key_data_set(obj, "anim", pd->anim);

   efl_event_callback_add(obj, EFL_GFX_ENTITY_EVENT_HINTS_CHANGED, _size_hint_event_cb, pd);
}

EOLIAN static void
_efl_ui_mi_controller_efl_canvas_group_group_del(Eo *obj, Efl_Ui_Mi_Controller_Data *pd EINA_UNUSED)
{
   efl_canvas_group_del(efl_super(obj, MY_CLASS));

   if (pd->states) eina_array_free(pd->states);
}

EOLIAN static void
_efl_ui_mi_controller_efl_object_destructor(Eo *obj,
                                          Efl_Ui_Mi_Controller_Data *pd EINA_UNUSED)
{
   efl_destructor(efl_super(obj, MY_CLASS));
}

EOLIAN static Eo *
_efl_ui_mi_controller_efl_object_constructor(Eo *obj,
                                           Efl_Ui_Mi_Controller_Data *pd EINA_UNUSED)
{
   obj = efl_constructor(efl_super(obj, MY_CLASS));
   evas_object_smart_callbacks_descriptions_set(obj, _smart_callbacks);

   return obj;
}

/* Efl.Part begin */
/*ELM_PART_OVERRIDE_CONTENT_SET(efl_ui_mi_controller, EFL_UI_MI_CONTROLLER, Efl_Ui_Mi_Controller_Data)
ELM_PART_OVERRIDE_CONTENT_GET(efl_ui_mi_controller, EFL_UI_MI_CONTROLLER, Efl_Ui_Mi_Controller_Data)
ELM_PART_OVERRIDE_CONTENT_UNSET(efl_ui_mi_controller, EFL_UI_MI_CONTROLLER, Efl_Ui_Mi_Controller_Data)
#include "efl_ui_mi_controller_part.eo.c"*/
/* Efl.Part end */

/* Internal EO APIs and hidden overrides */


#define EFL_UI_MI_CONTROLLER_EXTRA_OPS \
   EFL_CANVAS_GROUP_ADD_DEL_OPS(efl_ui_mi_controller)

#include "efl_ui_mi_controller.eo.c"