hermet pushed a commit to branch master.

http://git.enlightenment.org/games/etypers.git/commit/?id=7ae3274511ac991097d5844769e0fc83d1e4ffa2

commit 7ae3274511ac991097d5844769e0fc83d1e4ffa2
Author: Hermet Park <her...@hermet.pe.kr>
Date:   Fri Feb 12 23:27:54 2016 +0900

    code refactoring.
    
    clean and neat!
---
 src/bin/etypers.c | 466 ++++++++++++++++++++++++------------------------------
 1 file changed, 209 insertions(+), 257 deletions(-)

diff --git a/src/bin/etypers.c b/src/bin/etypers.c
index f0b48b2..4c16de1 100644
--- a/src/bin/etypers.c
+++ b/src/bin/etypers.c
@@ -9,26 +9,17 @@
 #define WALL_COLOR 100, 100, 100, 170
 #define MINUS_SCORE 25
 
-typedef struct _Enemy Enemy;
-typedef struct _AppData AppData;
-typedef enum _GameState GameState;
-
-static void _pause(AppData *appdata);
-static void _resume(AppData *appdata);
-static void _popup(AppData *appdata);
-static void _reset_defense_wall(AppData *appdata);
-
-enum _GameState
+typedef enum _GameState
 {
    Ready = 0,
    Playing,
    Paused,
-   SubPopup,
-   SubPopup2,
+   ReadyPopup,
+   PausedPopup,
    GameOver
-};
+} GameState;
 
-struct _AppData
+typedef struct _AppData
 {
    Eina_Inlist *enemies;
    Eina_Array *words_array;
@@ -51,9 +42,9 @@ struct _AppData
    Evas_Object *popup;
    GameState state;
    Ecore_Animator *animator;
-};
+} AppData;
 
-struct _Enemy
+typedef struct _Enemy
 {
    EINA_INLIST;
    Evas_Object *entry;
@@ -61,22 +52,24 @@ struct _Enemy
    float y;
    float w;
    float h;
-};
+} Enemy;
+
+static void reset_defense_wall(AppData *appdata);
 
 static double
-level_handicap_for_enemy_add(double level)
+level_handicap_forenemy_add(double level)
 {
    return ((double) (rand() % (int) (level * 100000))) * 0.000014;
 }
 
 static unsigned long
-_enemy_score_get(Enemy* enemy)
+enemy_score_get(Enemy* enemy)
 {
    return strlen(elm_object_text_get(enemy->entry));
 }
 
 static void
-_remove_all_enemies(AppData *appdata)
+remove_all_enemies(AppData *appdata)
 {
    while (appdata->enemies)
      {
@@ -89,7 +82,7 @@ _remove_all_enemies(AppData *appdata)
 }
 
 static Enemy *
-_enemy_new(Evas_Object *parent, const char *str, Evas_Coord x, Evas_Coord y,
+enemy_new(Evas_Object *parent, const char *str, Evas_Coord x, Evas_Coord y,
            Evas_Coord max_w, Evas_Coord max_h)
 {
    Enemy *enemy = calloc(1, sizeof(Enemy));
@@ -128,28 +121,28 @@ _enemy_new(Evas_Object *parent, const char *str, 
Evas_Coord x, Evas_Coord y,
 }
 
 static void
-_enemy_add(AppData *appdata)
+enemy_add(AppData *appdata)
 {
    unsigned int words_cnt = eina_array_count(appdata->words_array);
    char *word = eina_array_data_get(appdata->words_array,(rand() % words_cnt));
-   Enemy *enemy = _enemy_new(appdata->bx, word,
-                             (rand() % appdata->bound_w), 0, appdata->bound_w,
-                             appdata->bound_h);
+   Enemy *enemy = enemy_new(appdata->bx, word,
+                            (rand() % appdata->bound_w), 0, appdata->bound_w,
+                            appdata->bound_h);
    appdata->enemies = eina_inlist_append(appdata->enemies,
                                          (Eina_Inlist *) enemy);
    appdata->interval_time = appdata->last_frame_time;
 }
 
 static void
-_obj_del(void *data, Elm_Transit *transit)
+enemy_kill_transit_del_cb(void *data, Elm_Transit *transit)
 {
    evas_object_del(data);
 }
 
 static void
-_enemy_kill(AppData *appdata, Enemy *enemy)
+enemy_kill(AppData *appdata, Enemy *enemy)
 {
-   appdata->score += _enemy_score_get(enemy);
+   appdata->score += enemy_score_get(enemy);
 
    Evas_Object *entry = enemy->entry;
    appdata->enemies = eina_inlist_remove(appdata->enemies,
@@ -165,14 +158,14 @@ _enemy_kill(AppData *appdata, Enemy *enemy)
    elm_transit_effect_translation_add(transit, 0, 0, ELM_SCALE_SIZE(15),
                                       ELM_SCALE_SIZE(-20));
    elm_transit_effect_color_add(transit, 255, 255, 255, 255, 0, 0, 0, 0);
-   elm_transit_del_cb_set(transit, _obj_del, entry);
+   elm_transit_del_cb_set(transit, enemy_kill_transit_del_cb, entry);
    elm_transit_go(transit);
 }
 
 static void
-_enemy_explose(AppData *appdata, Enemy *enemy)
+enemy_collide(AppData *appdata, Enemy *enemy)
 {
-   appdata->score += _enemy_score_get(enemy);
+   appdata->score += enemy_score_get(enemy);
    evas_object_del(enemy->entry);
    appdata->enemies = eina_inlist_remove(appdata->enemies,
                                          EINA_INLIST_GET(enemy));
@@ -180,7 +173,7 @@ _enemy_explose(AppData *appdata, Enemy *enemy)
 }
 
 static void
-_update_gui(AppData *appdata)
+update_gui(AppData *appdata)
 {
    static char buf[64];
 
@@ -194,15 +187,15 @@ _update_gui(AppData *appdata)
 }
 
 static void
-_game_reset(AppData *appdata)
+game_reset(AppData *appdata)
 {
    elm_object_text_set(appdata->entry, "");
    elm_object_part_text_set(appdata->ly, "level_value", "1");
    elm_object_part_text_set(appdata->ly, "score_value", "0");
    elm_object_part_text_set(appdata->ly, "correct_value", "100%");
 
-   _remove_all_enemies(appdata);
-   _reset_defense_wall(appdata);
+   remove_all_enemies(appdata);
+   reset_defense_wall(appdata);
    elm_object_signal_emit(appdata->ly, "elm,state,gamereset", "etypers");
 
    appdata->score = 0;
@@ -213,19 +206,19 @@ _game_reset(AppData *appdata)
 }
 
 static void
-_game_over(AppData *appdata)
+game_over(AppData *appdata)
 {
    ecore_animator_freeze(appdata->animator);
    elm_object_signal_emit(appdata->ly, "elm,state,gameover", "etypers");
    appdata->state = GameOver;
 }
 
-void _wall_hide(void *data, Elm_Transit *transit)
+void remove_wall_transit_del_cb(void *data, Elm_Transit *transit)
 {
    evas_object_hide(data);
 }
 
-void _remove_wall(Evas_Object *wall)
+void remove_wall(Evas_Object *wall)
 {
    Elm_Transit *transit = elm_transit_add();
    if (!transit)
@@ -236,12 +229,12 @@ void _remove_wall(Evas_Object *wall)
 
    elm_transit_object_add(transit, wall);
    elm_transit_effect_color_add(transit, WALL_COLOR, 0, 0, 0, 0);
-   elm_transit_del_cb_set(transit, _wall_hide, wall);
+   elm_transit_del_cb_set(transit, remove_wall_transit_del_cb, wall);
    elm_transit_duration_set(transit, 0.5);
    elm_transit_go(transit);
 }
 
-Eina_Bool _collision(AppData *appdata, Enemy *enemy)
+Eina_Bool collision_check(AppData *appdata, Enemy *enemy)
 {
    if (appdata->defense_rect.y > (Evas_Coord) (enemy->y + enemy->h))
      return EINA_FALSE;
@@ -261,7 +254,7 @@ Eina_Bool _collision(AppData *appdata, Enemy *enemy)
           {
              appdata->defense_wall =
                 eina_list_remove_list(appdata->defense_wall, l);
-             _remove_wall(wall);
+             remove_wall(wall);
              collide = EINA_TRUE;
           }
      }
@@ -272,7 +265,7 @@ Eina_Bool _collision(AppData *appdata, Enemy *enemy)
 static Eina_Bool
 _animator_cb(void *data)
 {
-//FIXME: Sometimes this func is called abnormally. Need to check.
+   //FIXME: Sometimes this func is called abnormally. Need to check.
    AppData *appdata = data;
    double current_time = ecore_time_get();
    double elapsed_time = current_time - appdata->interval_time;
@@ -290,14 +283,14 @@ _animator_cb(void *data)
         //Reached to the bottom... Boom!
         if (enemy->y > appdata->bound_h)
           {
-             _game_over(appdata);
+             game_over(appdata);
              return ECORE_CALLBACK_RENEW;
           }
 
         //Collide with defense wall
-        if (_collision(appdata, enemy))
+        if (collision_check(appdata, enemy))
           {
-             _enemy_explose(appdata, enemy);
+             enemy_collide(appdata, enemy);
              continue;
           }
 
@@ -310,21 +303,21 @@ _animator_cb(void *data)
    appdata->last_frame_time = current_time;
 
    //Add Enemy?
-   if ((elapsed_time + level_handicap_for_enemy_add(appdata->level)) >
+   if ((elapsed_time + level_handicap_forenemy_add(appdata->level)) >
        (NEW_ENEMY_DURATION_SEC + appdata->level))
-     _enemy_add(appdata);
+     enemy_add(appdata);
 
-   _update_gui(appdata);
+   update_gui(appdata);
 
    return ECORE_CALLBACK_RENEW;
 }
 
 static void
-_app_release(AppData *appdata)
+app_release(AppData *appdata)
 {
    ecore_animator_del(appdata->animator);
 
-   _remove_all_enemies(appdata);
+   remove_all_enemies(appdata);
 
    //Remove all words allocated
    while (eina_array_count(appdata->words_array))
@@ -338,41 +331,15 @@ _app_release(AppData *appdata)
 }
 
 static void
-_win_del(void *data, Evas_Object *obj, void *event_info)
-{
-   _app_release(data);
-}
-
-static Evas_Object *
-_layout_create(Evas_Object *win)
-{
-   Evas_Object *ly = elm_layout_add(win);
-
-   char buf[PATH_MAX];
-   snprintf(buf, sizeof(buf), "%s/theme/etypers.edj", PACKAGE_DATA_DIR);
-
-   elm_layout_file_set(ly, buf, "gui");
-   evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
-   elm_win_resize_object_add(win, ly);
-   evas_object_show(ly);
-
-   return ly;
-}
-
-static Evas_Object *
-_box_create(Evas_Object *ly, const char *part)
+win_delete_request_cb(void *data, Evas_Object *obj, void *event_info)
 {
-   Evas_Object *bx = elm_box_add(ly);
-   evas_object_show(bx);
-   elm_object_part_content_set(ly, part, bx);
-
-   return bx;
+   app_release(data);
 }
 
 static void
-_combo(AppData *appdata, Enemy *enemy, int combo)
+combo(AppData *appdata, Enemy *enemy, int combo)
 {
-   appdata->score += _enemy_score_get(enemy) * combo;
+   appdata->score += enemy_score_get(enemy) * combo;
 
    Evas *e = evas_object_evas_get(appdata->win);
    Evas_Object *text = evas_object_text_add(e);
@@ -403,20 +370,13 @@ _combo(AppData *appdata, Enemy *enemy, int combo)
    elm_transit_object_add(transit, text);
    elm_transit_effect_zoom_add(transit, 1, 1.25);
    elm_transit_effect_color_add(transit, 255, 255, 0, 255, 0, 0, 0, 0);
-   elm_transit_del_cb_set(transit, _obj_del, text);
+   elm_transit_del_cb_set(transit, enemy_kill_transit_del_cb, text);
    elm_transit_duration_set(transit, 1);
    elm_transit_go(transit);
 }
 
-static void _minus_score(AppData *appdata)
-{
-   appdata->score -= MINUS_SCORE;
-   if (appdata->score < 0)
-     appdata->score = 0;
-}
-
 static void
-_update_correctness(AppData *appdata, Eina_Bool hit)
+update_correctness(AppData *appdata, Eina_Bool hit)
 {
    appdata->hit_try_cnt += 1.0f;
    if (hit) appdata->hit_cnt += 1.0f;
@@ -428,7 +388,7 @@ _update_correctness(AppData *appdata, Eina_Bool hit)
 }
 
 static void
-_enemies_kill(AppData *appdata, Evas_Object *obj, const char *input_text,
+enemies_kill(AppData *appdata, Evas_Object *obj, const char *input_text,
               Eina_Bool space)
 {
    //Compare the enemies and clear them.
@@ -455,26 +415,28 @@ _enemies_kill(AppData *appdata, Evas_Object *obj, const 
char *input_text,
              hit = EINA_TRUE;
              appdata->combo++;
              if (appdata->combo > 1)
-               _combo(appdata, enemy, appdata->combo);
-             _enemy_kill(appdata, enemy);
+               combo(appdata, enemy, appdata->combo);
+             enemy_kill(appdata, enemy);
           }
      }
 
    //Minus score if it doesn't any hits
    if (!hit)
      {
-        _minus_score(appdata);
+        appdata->score -= MINUS_SCORE;
+        if (appdata->score < 0) appdata->score = 0;
         appdata->combo = 0;
      }
 
-   _update_correctness(appdata, hit);
+   update_correctness(appdata, hit);
 
    elm_object_text_set(obj, NULL);
 
 }
 
 static void
-_changed_user_cb(void *data, Evas_Object *obj, void *event_info)
+entry_changed_user_cb(void *data, Evas_Object *obj,
+                      void *event_info EINA_UNUSED)
 {
    const char *input_text = elm_object_text_get(obj);
    if (!input_text) return;
@@ -482,31 +444,116 @@ _changed_user_cb(void *data, Evas_Object *obj, void 
*event_info)
    //try to kill the enemies when user press the "space" key
    if (input_text[strlen(input_text) -1] != ' ') return;
 
-   _enemies_kill(data, obj, input_text, EINA_TRUE);
+   enemies_kill(data, obj, input_text, EINA_TRUE);
+}
+
+static void
+table_resize_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj,
+                void *event_info EINA_UNUSED)
+{
+   Evas_Coord x, y, w, h;
+   evas_object_geometry_get(obj, &x, &y, &w, &h);
+
+   AppData *appdata = data;
+   appdata->defense_rect.x = x;
+   appdata->defense_rect.y = y;
+   appdata->defense_rect.w = w;
+   appdata->defense_rect.h = h;
+}
+
+static void
+table_create(AppData *appdata)
+{
+   Evas_Object *table = elm_table_add(appdata->ly);
+   if (!table) return;
+   elm_table_homogeneous_set(table, EINA_TRUE);
+   elm_table_padding_set(table, ELM_SCALE_SIZE(1), ELM_SCALE_SIZE(1));
+   elm_object_part_content_set(appdata->ly, "defense_wall", table);
+   evas_object_show(table);
+   evas_object_event_callback_add(table, EVAS_CALLBACK_RESIZE, table_resize_cb,
+                                  appdata);
+   appdata->table = table;
+}
+
+static void
+base_gui_create(AppData *appdata)
+{
+   //Create a window
+   Evas_Object *win = elm_win_add(NULL, "EFL Typers", ELM_WIN_DIALOG_BASIC);
+   elm_win_title_set(win, "EFL Typers v1.0");
+   elm_win_autodel_set(win, EINA_TRUE);
+   elm_win_focus_highlight_enabled_set(win, EINA_FALSE);
+   evas_object_smart_callback_add(win, "delete,request", win_delete_request_cb,
+                                  appdata);
+   //Fix the window size
+   Evas_Object *rect = evas_object_rectangle_add(evas_object_evas_get(win));
+   evas_object_size_hint_min_set(rect, DEFAULT_WIN_W, DEFAULT_WIN_H);
+   elm_win_resize_object_add(win, rect);
+
+   //Layout
+   Evas_Object *ly = elm_layout_add(win);
+
+   char buf[PATH_MAX];
+   snprintf(buf, sizeof(buf), "%s/theme/etypers.edj", PACKAGE_DATA_DIR);
+
+   elm_layout_file_set(ly, buf, "gui");
+   evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+   elm_win_resize_object_add(win, ly);
+   evas_object_show(ly);
+
+   //Box
+   Evas_Object *bx = elm_box_add(ly);
+   evas_object_show(bx);
+   elm_object_part_content_set(ly, "enemies", bx);
+
+   //Entry
+   Evas_Object *entry = elm_entry_add(ly);
+   elm_entry_single_line_set(entry, EINA_TRUE);
+   elm_entry_input_panel_enabled_set(entry, EINA_FALSE);
+   evas_object_show(entry);
+   elm_object_part_content_set(ly, "entry", entry);
+   evas_object_smart_callback_add(entry, "changed,user", entry_changed_user_cb,
+                                  appdata);
+
+   appdata->win = win;
+   appdata->ly = ly;
+   appdata->bx = bx;
+   appdata->entry = entry;
+
+   table_create(appdata);
+}
+
+static void
+game_resume(AppData *appdata)
+{
+   elm_object_disabled_set(appdata->entry, EINA_FALSE);
+   elm_object_focus_set(appdata->entry, EINA_TRUE);
+   appdata->last_frame_time = ecore_time_get();
+   ecore_animator_thaw(appdata->animator);
 }
 
 static void
-_game_level_cb(void *data, Evas_Object *obj, void *event_info)
+game_level_cb(void *data, Evas_Object *obj, void *event_info)
 {
    AppData *appdata = evas_object_data_get(obj, "appdata");
    evas_object_del(appdata->popup);
    appdata->popup = NULL;
    appdata->level = (int)(uintptr_t) data;
 
-   _game_reset(appdata);
+   game_reset(appdata);
    appdata->state = Playing;
-   _resume(appdata);
+   game_resume(appdata);
 }
 
 static void
-_game_start_cb(void *data, Evas_Object *obj, void *event_info)
+game_start_cb(void *data, Evas_Object *obj, void *event_info)
 {
    AppData *appdata = data;
    evas_object_del(appdata->popup);
 
    appdata->popup = NULL;
-   if (appdata->state == Paused) appdata->state = SubPopup2;
-   else appdata->state = SubPopup;
+   if (appdata->state == Paused) appdata->state = PausedPopup;
+   else appdata->state = ReadyPopup;
 
    Evas_Object *notify = elm_notify_add(appdata->win);
    elm_notify_align_set(notify, 0.5, 0.5);
@@ -532,23 +579,23 @@ _game_start_cb(void *data, Evas_Object *obj, void 
*event_info)
    evas_object_data_set(list, "appdata", appdata);
    evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
    evas_object_size_hint_align_set(list, EVAS_HINT_FILL, EVAS_HINT_FILL);
-   elm_list_item_append(list, "Level 1", NULL, NULL, _game_level_cb,
+   elm_list_item_append(list, "Level 1", NULL, NULL, game_level_cb,
                         (void *) 1);
-   elm_list_item_append(list, "Level 2", NULL, NULL, _game_level_cb,
+   elm_list_item_append(list, "Level 2", NULL, NULL, game_level_cb,
                         (void *) 2);
-   elm_list_item_append(list, "Level 3", NULL, NULL, _game_level_cb,
+   elm_list_item_append(list, "Level 3", NULL, NULL, game_level_cb,
                         (void *) 3);
-   elm_list_item_append(list, "Level 4", NULL, NULL, _game_level_cb,
+   elm_list_item_append(list, "Level 4", NULL, NULL, game_level_cb,
                         (void *) 4);
-   elm_list_item_append(list, "Level 5", NULL, NULL, _game_level_cb,
+   elm_list_item_append(list, "Level 5", NULL, NULL, game_level_cb,
                         (void *) 5);
-   elm_list_item_append(list, "Level 6", NULL, NULL, _game_level_cb,
+   elm_list_item_append(list, "Level 6", NULL, NULL, game_level_cb,
                         (void *) 6);
-   elm_list_item_append(list, "Level 7", NULL, NULL, _game_level_cb,
+   elm_list_item_append(list, "Level 7", NULL, NULL, game_level_cb,
                         (void *) 7);
-   elm_list_item_append(list, "Level 8", NULL, NULL, _game_level_cb,
+   elm_list_item_append(list, "Level 8", NULL, NULL, game_level_cb,
                         (void *) 8);
-   elm_list_item_append(list, "Level 9", NULL, NULL, _game_level_cb,
+   elm_list_item_append(list, "Level 9", NULL, NULL, game_level_cb,
                         (void *) 9);
 
    elm_list_go(list);
@@ -562,30 +609,22 @@ _game_start_cb(void *data, Evas_Object *obj, void 
*event_info)
    appdata->popup = notify;
 }
 
-#if 0
-static void
-_top_ranking_cb(void *data, Evas_Object *obj, void *event_info)
-{
-  //TODO: 
-}
-#endif
-
 static void
-_game_exit_cb(void *data, Evas_Object *obj, void *event_info)
+game_exit_cb(void *data, Evas_Object *obj, void *event_info)
 {
-   _app_release(data);
+   app_release(data);
 }
 
 static void
-_about_cb(void *data, Evas_Object *obj, void *event_info)
+about_cb(void *data, Evas_Object *obj, void *event_info)
 {
    AppData *appdata = data;
 
    Evas_Object *popup = elm_popup_add(appdata->win);
    if (!popup) return;
 
-   if (appdata->state == Ready) appdata->state = SubPopup;
-   else appdata->state = SubPopup2;
+   if (appdata->state == Ready) appdata->state = ReadyPopup;
+   else appdata->state = PausedPopup;
 
    elm_object_part_text_set(popup, "title,text", "EFL Typers v1.0");
    elm_object_text_set(popup, "Copyright © 2016 Hermet Park<br> and various 
contributors (see AUTHORS)");
@@ -597,16 +636,8 @@ _about_cb(void *data, Evas_Object *obj, void *event_info)
    appdata->popup = popup;
 }
 
-#if 0
-static void
-_option_cb(void *data, Evas_Object *obj, void *event_info)
-{
-   //TODO:
-}
-#endif
-
 static Evas_Object *
-_popup_create(Evas_Object *parent, AppData *appdata)
+popup_create(Evas_Object *parent, AppData *appdata)
 {
    Evas_Object *notify = elm_notify_add(parent);
    elm_notify_align_set(notify, 0.5, 0.5);
@@ -630,11 +661,11 @@ _popup_create(Evas_Object *parent, AppData *appdata)
                            ELM_SCROLLER_POLICY_OFF);
    evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
    evas_object_size_hint_align_set(list, EVAS_HINT_FILL, EVAS_HINT_FILL);
-   elm_list_item_append(list, "Start", NULL, NULL, _game_start_cb,
+   elm_list_item_append(list, "Start", NULL, NULL, game_start_cb,
                               appdata);
-   elm_list_item_append(list, "About", NULL, NULL, _about_cb, appdata);
+   elm_list_item_append(list, "About", NULL, NULL, about_cb, appdata);
 
-   elm_list_item_append(list, "Exit", NULL, NULL, _game_exit_cb, appdata);
+   elm_list_item_append(list, "Exit", NULL, NULL, game_exit_cb, appdata);
 
    elm_list_go(list);
    evas_object_show(list);
@@ -649,66 +680,48 @@ _popup_create(Evas_Object *parent, AppData *appdata)
 }
 
 static void
-_popup(AppData *appdata)
-{
-   if (!appdata->popup)
-     {
-        Evas_Object *popup = _popup_create(appdata->win, appdata);
-        appdata->popup = popup;
-     }
-   else
-     {
-        evas_object_del(appdata->popup);
-        appdata->popup = NULL;
-     }
-}
-
-static void
-_pause(AppData *appdata)
+game_pause(AppData *appdata)
 {
    elm_object_disabled_set(appdata->entry, EINA_TRUE);
    ecore_animator_freeze(appdata->animator);
 }
 
 static void
-_resume(AppData *appdata)
-{
-   elm_object_disabled_set(appdata->entry, EINA_FALSE);
-   elm_object_focus_set(appdata->entry, EINA_TRUE);
-   appdata->last_frame_time = ecore_time_get();
-   ecore_animator_thaw(appdata->animator);
-}
-
-static void
-_pause_or_resume(AppData *appdata)
+pause_or_resume(AppData *appdata)
 {
    if (appdata->state == Paused)
      {
         appdata->state = Playing;
-        _resume(appdata);
+        game_resume(appdata);
      }
    else if (appdata->state == Playing)
      {
         appdata->state = Paused;
-        _pause(appdata);
+        game_pause(appdata);
      }
-   else if (appdata->state == SubPopup)
+   else if (appdata->state == ReadyPopup)
      {
         evas_object_del(appdata->popup);
         appdata->popup = NULL;
      }
-   else if (appdata->state == SubPopup2)
+   else if (appdata->state == PausedPopup)
      {
         evas_object_del(appdata->popup);
         appdata->popup = NULL;
         appdata->state = Paused;
      }
 
-   _popup(appdata);
+   if (!appdata->popup)
+     appdata->popup = popup_create(appdata->win, appdata);
+   else
+     {
+        evas_object_del(appdata->popup);
+        appdata->popup = NULL;
+     }
 }
 
 static Eina_Bool
-_key_down_cb(void *data, int type, void *event_info)
+main_key_down_cb(void *data, int type EINA_UNUSED, void *event_info)
 {
    Ecore_Event_Key *event = event_info;
    AppData *appdata = data;
@@ -723,7 +736,7 @@ _key_down_cb(void *data, int type, void *event_info)
           {
              const char *input_text = elm_object_text_get(appdata->entry);
              if (input_text)
-               _enemies_kill(appdata, appdata->entry, input_text, EINA_FALSE);
+               enemies_kill(appdata, appdata->entry, input_text, EINA_FALSE);
 
              return ECORE_CALLBACK_DONE;
           }
@@ -732,52 +745,19 @@ _key_down_cb(void *data, int type, void *event_info)
    else if (!strcmp(event->keyname, "Escape"))
      {
         if (appdata->state == GameOver)
-          {
-             _game_reset(appdata);
-          }
-        _pause_or_resume(appdata);
+          game_reset(appdata);
+        pause_or_resume(appdata);
         return ECORE_CALLBACK_DONE;
      }
 
    return ECORE_CALLBACK_PASS_ON;
 }
 
-static Evas_Object *
-_entry_create(Evas_Object *ly, const char *part, AppData *appdata)
-{
-   Evas_Object *entry = elm_entry_add(ly);
-   elm_entry_single_line_set(entry, EINA_TRUE);
-   elm_entry_input_panel_enabled_set(entry, EINA_FALSE);
-   evas_object_show(entry);
-   elm_object_part_content_set(ly, part, entry);
-   evas_object_smart_callback_add(entry, "changed,user",  _changed_user_cb,
-                                  appdata);
-   return entry;
-}
-
-static Evas_Object *
-_win_create(AppData *appdata)
-{
-   //Create a window
-   Evas_Object *win = elm_win_add(NULL, "EFL Typers", ELM_WIN_DIALOG_BASIC);
-   elm_win_title_set(win, "EFL Typers v1.0");
-   elm_win_autodel_set(win, EINA_TRUE);
-   elm_win_focus_highlight_enabled_set(win, EINA_FALSE);
-   evas_object_smart_callback_add(win, "delete,request", _win_del, appdata);
-
-   //Fix the window size
-   Evas_Object *rect = evas_object_rectangle_add(evas_object_evas_get(win));
-   evas_object_size_hint_min_set(rect, DEFAULT_WIN_W, DEFAULT_WIN_H);
-   elm_win_resize_object_add(win, rect);
-
-   return win;
-}
-
-static Eina_Array *
-_words_create()
+static void
+words_create(AppData *appdata)
 {
    Eina_Array *array = eina_array_new(400);
-   if (!array) return NULL;
+   if (!array) return;
 
    char buf[128];
    char path[PATH_MAX];
@@ -787,46 +767,19 @@ _words_create()
    if (!fp)
      {
         eina_array_free(array);
-        return NULL;
+        return;
      }
 
    while(0 < fscanf(fp, "%s", buf))
      eina_array_push(array, strdup(buf));
 
-   return array;
-}
-
-static void
-_table_resize_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
-{
-   Evas_Coord x, y, w, h;
-   evas_object_geometry_get(obj, &x, &y, &w, &h);
-
-   AppData *appdata = data;
-   appdata->defense_rect.x = x;
-   appdata->defense_rect.y = y;
-   appdata->defense_rect.w = w;
-   appdata->defense_rect.h = h;
-}
-
-static Evas_Object *
-_table_create(Evas_Object *ly, const char *part, AppData *appdata)
-{
-   Evas_Object *table = elm_table_add(ly);
-   if (!table) return NULL;
-   elm_table_homogeneous_set(table, EINA_TRUE);
-   elm_table_padding_set(table, ELM_SCALE_SIZE(1), ELM_SCALE_SIZE(1));
-   elm_object_part_content_set(ly, "defense_wall", table);
-   evas_object_show(table);
-   evas_object_event_callback_add(table, EVAS_CALLBACK_RESIZE, 
_table_resize_cb,
-                                  appdata);
-   return table;
+   appdata->words_array = array;
 }
 
 static Eina_List *
-_defense_wall_set(Evas_Object *table)
+defense_wall_init(AppData *appdata)
 {
-   Evas *evas = evas_object_evas_get(table);
+   Evas *evas = evas_object_evas_get(appdata->table);
    Eina_List *list = NULL;
    int i, j;
 
@@ -842,50 +795,49 @@ _defense_wall_set(Evas_Object *table)
              evas_object_size_hint_weight_set(obj, EVAS_HINT_EXPAND,
                                               EVAS_HINT_EXPAND);
              evas_object_show(obj);
-             elm_table_pack(table, obj, i, j, 1, 1);
+             elm_table_pack(appdata->table, obj, i, j, 1, 1);
 
              list = eina_list_append(list, obj);
           }
      }
-   return list;
+   appdata->defense_wall = list;
 }
 
 static void
-_reset_defense_wall(AppData *appdata)
+reset_defense_wall(AppData *appdata)
 {
    eina_list_free(appdata->defense_wall);
    evas_object_del(appdata->table);
-   appdata->table = _table_create(appdata->ly, "table", appdata);
-   appdata->defense_wall = _defense_wall_set(appdata->table);
+   table_create(appdata);
+   defense_wall_init(appdata);
 }
 
 static void
-_app_init(AppData *appdata)
+app_init(AppData *appdata)
 {
-   ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, _key_down_cb, appdata);
+   ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, main_key_down_cb, appdata);
+
+   words_create(appdata);
+   base_gui_create(appdata);
+   defense_wall_init(appdata);
 
-   appdata->words_array = _words_create();
-   appdata->win = _win_create(appdata);
-   appdata->ly = _layout_create(appdata->win);
-   appdata->bx = _box_create(appdata->ly, "enemies");
-   appdata->entry = _entry_create(appdata->ly, "entry", appdata);
-   appdata->table = _table_create(appdata->ly, "table", appdata);
-   appdata->defense_wall = _defense_wall_set(appdata->table);
    appdata->state = Ready;
    appdata->level = 1;
    appdata->bound_w = DEFAULT_WIN_W;
    appdata->bound_h = DEFAULT_WIN_H;
+
    appdata->animator = ecore_animator_add(_animator_cb, appdata);
 
-   _pause(appdata);
-   _popup(appdata);
+   game_pause(appdata);
+
+   appdata->popup = popup_create(appdata->win, appdata);
 
    evas_object_resize(appdata->win, DEFAULT_WIN_W, DEFAULT_WIN_H);
    evas_object_show(appdata->win);
 }
 
 static void
-_elm_setup(void)
+elm_steup(void)
 {
    elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
    elm_app_compile_bin_dir_set(PACKAGE_BIN_DIR);
@@ -900,9 +852,9 @@ int elm_main(int argc, char **argv)
    AppData *appdata = calloc(1, sizeof(AppData));
    if (!appdata) return 0;
 
-   _elm_setup();
+   elm_steup();
 
-   _app_init(appdata);
+   app_init(appdata);
 
    elm_run();
 

-- 


Reply via email to