This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository elimine.

View the commit online.

commit ef87230eaee2cabdd487023f60caf8361c0f65ad
Author: Vincent Torri <vto...@outlook.fr>
AuthorDate: Wed Jul 9 10:46:06 2025 +0200

    replace elm_table with elm_grid
---
 src/bin/elimine.c | 171 ++++++++++++++++++++++++++++++++++--------------------
 src/bin/icon.c    |  82 ++++++++++++++++----------
 src/bin/icon.h    |   2 +-
 3 files changed, 162 insertions(+), 93 deletions(-)

diff --git a/src/bin/elimine.c b/src/bin/elimine.c
index 453f895..70a2739 100644
--- a/src/bin/elimine.c
+++ b/src/bin/elimine.c
@@ -11,6 +11,8 @@
 
 #include "icon.h"
 
+#define lookup(l, c) (l) * ctx->nc + (c)
+
 /*
  * Boards (width x height x mines):
  * - 9x9x10
@@ -28,21 +30,21 @@ typedef enum
 
 typedef struct
 {
-    Evas_Object *win;
-    Evas_Object *tbl;
+    Evas *evas;
+    Evas_Object *grd;
+    Evas_Object *smiley;
+    Eina_List *tiles;
 
     int *state;
     int *known;
     int nl; /* number of lines of the board */
     int nc; /* number of columns of the board */
     int nm; /* number of mines in the board */
-    int tile_sz; /* size in pixels of a tile */
+    int pixel_sz; /* size in pixels of a tile */
 
     Eina_Bool finished;
 } Ctx;
 
-#define lookup(l, c) (l) * ctx->nc + (c)
-
 static inline int in_board(Ctx *ctx, int l, int c)
 {
     return  (l >= 0) && (c >= 0) && (l < ctx->nl) && (c < ctx->nc);
@@ -65,18 +67,20 @@ void display_board(Ctx *ctx)
     }
 }
 
-Ctx *ctx_new(Evas_Object *win, Difficulty d, int tile_sz)
+Ctx *ctx_new(Difficulty d, int pixel_sz)
 {
     Ctx *ctx;
     int count;
     int l;
 
+    if (!icon_init(pixel_sz))
+        return NULL;
+
     ctx = (Ctx *)calloc(1, sizeof(Ctx));
     if (!ctx)
         return NULL;
 
-    ctx->win = win;
-    ctx->tile_sz = tile_sz;
+    ctx->pixel_sz = pixel_sz;
 
     switch (d)
     {
@@ -171,6 +175,8 @@ Ctx *ctx_new(Evas_Object *win, Difficulty d, int tile_sz)
         }
     }
 
+    ctx->tiles = elm_grid_children_get(ctx->grd);
+
     return ctx;
 }
 
@@ -187,38 +193,11 @@ void ctx_del(Ctx *ctx)
 
 #define TILE(t, l, c) \
 do { \
-    Evas_Object*o;                                              \
-    int icon_w;                                                 \
-    int icon_h;                                                 \
-    tile_size_get(&icon_w, &icon_h);                            \
-    icon_w *= ctx->tile_sz;                                     \
-    icon_h *= ctx->tile_sz;                                     \
-    o = evas_object_image_add(evas_object_evas_get(ctx->win));  \
-    evas_object_image_size_set(o, icon_w, icon_h);              \
-    evas_object_image_fill_set(o, 0, 0, icon_w, icon_h);        \
-    evas_object_image_data_set(o, tile_bmp_get(t));             \
-    evas_object_resize(o, icon_w, icon_h);                      \
-    evas_object_size_hint_min_set(o, icon_w, icon_h);           \
-    evas_object_size_hint_max_set(o, icon_w, icon_h);           \
-    elm_table_pack(ctx->tbl, o, c, l, 1, 1);                    \
-    evas_object_show(o);                                        \
+    Evas_Object *o = eina_list_nth(ctx->tiles, l * ctx->nc + c);    \
+    evas_object_image_data_set(o, tile_bmp_get(t));                 \
+    evas_object_image_pixels_dirty_set(o, EINA_TRUE);               \
 } while (0)
 
-void ctx_draw(Ctx *ctx)
-{
-    int l;
-
-    for (l = 0; l < ctx->nl; l++)
-    {
-        int c;
-
-        for (c = 0; c < ctx->nc; c++)
-        {
-            TILE(ctx->known[lookup(l, c)], l, c);
-        }
-    }
-}
-
 static inline int in_bounds(Ctx *ctx, int l, int c)
 {
     return (l >= 0) && (c >= 0) && (l < ctx->nl) && (c < ctx->nc);
@@ -270,8 +249,8 @@ _cb_mouse_up(void *ctx_, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_UNUSED, v
         return;
 
     ev = (Evas_Event_Mouse_Up *)event_info;
-    c = ev->output.x / (16 * ctx->tile_sz);
-    l = (ev->output.y - 32 * ctx->tile_sz) / (16 * ctx->tile_sz);
+    c = ev->output.x / (16 * ctx->pixel_sz);
+    l = (ev->output.y - 32 * ctx->pixel_sz) / (16 * ctx->pixel_sz);
 
     if ((ev->button == 3) ||
         ((ev->button == 1) &&
@@ -328,31 +307,59 @@ _cb_mouse_up(void *ctx_, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_UNUSED, v
             }
 
             ctx->finished = EINA_TRUE;
+            evas_object_image_data_set(ctx->smiley, smiley_bmp_get(SMILEY_LOST));
+            evas_object_image_pixels_dirty_set(ctx->smiley, EINA_TRUE);
         }
         else if (ctx->state[lookup(l, c)] == TILE_NOTHING)
         {
             uncover(ctx, l, c);
+            evas_object_image_data_set(ctx->smiley, smiley_bmp_get(SMILEY_NORMAL));
+            evas_object_image_pixels_dirty_set(ctx->smiley, EINA_TRUE);
         }
         else
         {
             ctx->known[lookup(l, c)] = ctx->state[lookup(l, c)];
             TILE(ctx->state[lookup(l, c)], l, c);
+            evas_object_image_data_set(ctx->smiley, smiley_bmp_get(SMILEY_NORMAL));
+            evas_object_image_pixels_dirty_set(ctx->smiley, EINA_TRUE);
         }
     }
 }
 
+static void
+_cb_mouse_down(void *ctx_, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
+{
+    Ctx *ctx;
+    Evas_Event_Mouse_Down *ev;
+    int l;
+    int c;
+
+    ctx = (Ctx *)ctx_;
+
+    ev = (Evas_Event_Mouse_Down *)event_info;
+    c = ev->output.x / (16 * ctx->pixel_sz);
+    l = (ev->output.y - 32 * ctx->pixel_sz) / (16 * ctx->pixel_sz);
+    TILE(TILE_NOTHING, l, c);
+    evas_object_image_data_set(ctx->smiley, smiley_bmp_get(SMILEY_CLICKED));
+    evas_object_image_pixels_dirty_set(ctx->smiley, EINA_TRUE);
+}
+
 EAPI_MAIN int
 elm_main(int argc, char **argv)
 {
     Ctx *ctx;
 
     Evas_Object *win;
-    Evas_Object *tbl;
     Evas_Object *vbox;
     Evas_Object *hbox;
     Evas_Object *o;
     int win_w;
     int win_h;
+    int l;
+
+    ctx = ctx_new(INTERMEDIATE, 3);
+    if (!ctx)
+        return 1;
 
     elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
     elm_app_name_set("elimine");
@@ -361,9 +368,6 @@ elm_main(int argc, char **argv)
     elm_win_title_set(win, "Elimine");
     elm_win_autodel_set(win, EINA_TRUE);
 
-    ctx = ctx_new(win, INTERMEDIATE, 3);
-
-    icon_init(win, ctx->tile_sz);
 
     /* background */
     o = elm_bg_add(win);
@@ -389,14 +393,13 @@ elm_main(int argc, char **argv)
     evas_object_show(o);
     hbox = o;
 
-    o = evas_object_image_add(evas_object_evas_get(win));
+    o = evas_object_image_filled_add(evas_object_evas_get(win));
     int icon_w;
     int icon_h;
     cipher_size_get(&icon_w, &icon_h);
-    icon_w *= ctx->tile_sz;
-    icon_h *= ctx->tile_sz;
+    icon_w *= ctx->pixel_sz;
+    icon_h *= ctx->pixel_sz;
     evas_object_image_size_set(o, icon_w, icon_h);
-    evas_object_image_fill_set(o, 0, 0, icon_w, icon_h);
     evas_object_image_data_set(o, cipher_bmp_get(CIPHER_ZERO));
     evas_object_resize(o, icon_w, icon_h);
     evas_object_size_hint_min_set(o, icon_w, icon_h);
@@ -404,27 +407,70 @@ elm_main(int argc, char **argv)
     elm_box_pack_end(hbox, o);
     evas_object_show(o);
 
-    o = evas_object_image_add(evas_object_evas_get(win));
+    o = evas_object_image_filled_add(evas_object_evas_get(win));
     smiley_size_get(&icon_w, &icon_h);
-    icon_w *= ctx->tile_sz;
-    icon_h *= ctx->tile_sz;
+    icon_w *= ctx->pixel_sz;
+    icon_h *= ctx->pixel_sz;
     evas_object_image_size_set(o, icon_w, icon_h);
-    evas_object_image_fill_set(o, 0, 0, icon_w, icon_h);
-    evas_object_image_data_set(o, smiley_bmp_get(SMILEY_WIN));
+    evas_object_image_data_set(o, smiley_bmp_get(SMILEY_NORMAL));
+    evas_object_resize(o, icon_w, icon_h);
+    evas_object_size_hint_min_set(o, icon_w, icon_h);
+    evas_object_size_hint_max_set(o, icon_w, icon_h);
+    elm_box_pack_end(hbox, o);
+    evas_object_show(o);
+    ctx->smiley = o;
+
+    o = evas_object_image_filled_add(evas_object_evas_get(win));
+    tile_size_get(&icon_w, &icon_h);
+    icon_w *= ctx->pixel_sz;
+    icon_h *= ctx->pixel_sz;
+    evas_object_image_size_set(o, icon_w, icon_h);
+    evas_object_image_data_set(o, tile_bmp_get(TILE_BOMB_EXPLODED));
     evas_object_resize(o, icon_w, icon_h);
     evas_object_size_hint_min_set(o, icon_w, icon_h);
     evas_object_size_hint_max_set(o, icon_w, icon_h);
     elm_box_pack_end(hbox, o);
     evas_object_show(o);
 
-    /* table */
-    o = elm_table_add(win);
-    elm_table_homogeneous_set(o, EINA_TRUE);
+    /* grid */
+    o = elm_grid_add(win);
+    elm_grid_size_set(o, ctx->nc, ctx->nl);
     evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
     evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
     elm_box_pack_end(vbox, o);
     evas_object_show(o);
-    tbl = o;
+    ctx->grd = o;
+
+    /* tiles in grid */
+    /* int icon_w; */
+    /* int icon_h; */
+
+    tile_size_get(&icon_w, &icon_h);
+    icon_w *= ctx->pixel_sz;
+    icon_h *= ctx->pixel_sz;
+    evas_object_size_hint_min_set(o, icon_w * ctx->nc, icon_h * ctx->nl);
+    evas_object_size_hint_max_set(o, icon_w * ctx->nc, icon_h * ctx->nl);
+
+    for (l = 0; l < ctx->nl; l++)
+    {
+        int c;
+
+        for (c = 0; c < ctx->nc; c++)
+        {
+            Evas_Object*o;
+
+            o = evas_object_image_filled_add(evas_object_evas_get(win));
+            evas_object_image_size_set(o, icon_w, icon_h);
+            evas_object_image_data_set(o, tile_bmp_get(ctx->known[lookup(l, c)]));
+            evas_object_resize(o, icon_w, icon_h);
+            evas_object_size_hint_min_set(o, icon_w, icon_h);
+            evas_object_size_hint_max_set(o, icon_w, icon_h);
+            elm_grid_pack(ctx->grd, o, c, l, 1, 1);
+            evas_object_show(o);
+        }
+    }
+
+    ctx->tiles = elm_grid_children_get(ctx->grd);
 
     o = evas_object_rectangle_add(win);
     evas_object_color_set(o, 0, 0, 0, 0);
@@ -433,18 +479,19 @@ elm_main(int argc, char **argv)
     elm_win_resize_object_add(win, o);
     evas_object_repeat_events_set(o, EINA_TRUE);
     evas_object_show(o);
-    evas_object_event_callback_add(tbl, EVAS_CALLBACK_MOUSE_UP,
+    evas_object_event_callback_add(ctx->grd, EVAS_CALLBACK_MOUSE_UP,
                                    _cb_mouse_up, ctx);
+    evas_object_event_callback_add(ctx->grd, EVAS_CALLBACK_MOUSE_DOWN,
+                                   _cb_mouse_down, ctx);
 
-    ctx->tbl = tbl;
     ctx->finished = EINA_FALSE;
 
     display_board(ctx);
 
-    ctx_draw(ctx);
+    //ctx_draw(ctx);
 
-    win_w = ctx->nc * ctx->tile_sz;
-    win_h = ctx->nl * ctx->tile_sz;
+    win_w = ctx->nc * ctx->pixel_sz;
+    win_h = ctx->nl * ctx->pixel_sz;
     evas_object_resize(win,
                        win_w * elm_config_scale_get(),
                        win_h * elm_config_scale_get());
diff --git a/src/bin/icon.c b/src/bin/icon.c
index 80f9581..ef538c2 100644
--- a/src/bin/icon.c
+++ b/src/bin/icon.c
@@ -5,8 +5,7 @@
 
 #include <stdlib.h>
 
-#include <Eina.h>
-#include <Evas.h>
+#include <Elementary.h>
 
 #include "config.h"
 #include "icon.h"
@@ -76,16 +75,16 @@ struct Icon
 {
     Eina_Strbuf *buf;
     Offset *offset;
-    unsigned int **data;
     int w;
     int h;
     int nbr;
-    int tile_sz;
+    int pixel_sz;
 };
 
-unsigned int ** icon_create(Evas_Object *win, const Icon *ic)
+static unsigned int **
+icon_create(Evas_Object *win, const Icon *ic)
 {
-    Evas_Object *o;
+    Evas_Object *img;
     unsigned int *m;
     unsigned int **data;
     int img_w;
@@ -93,9 +92,9 @@ unsigned int ** icon_create(Evas_Object *win, const Icon *ic)
     int idx;
     Evas_Load_Error err;
 
-    o = evas_object_image_filled_add(evas_object_evas_get(win));
-    evas_object_image_file_set(o, eina_strbuf_string_get(ic->buf), NULL);
-    err = evas_object_image_load_error_get(o);
+    img = evas_object_image_filled_add(evas_object_evas_get(win));
+    evas_object_image_file_set(img, eina_strbuf_string_get(ic->buf), NULL);
+    err = evas_object_image_load_error_get(img);
     if (err != EVAS_LOAD_ERROR_NONE)
     {
         fprintf(stderr, "could not load image '%s'. error string is \"%s\"\n",
@@ -103,9 +102,13 @@ unsigned int ** icon_create(Evas_Object *win, const Icon *ic)
         return NULL;
     }
 
-    evas_object_image_size_get(o, &img_w, &img_h);
-    evas_object_image_size_set(o, img_w, img_h);
-    m = evas_object_image_data_get(o, EINA_TRUE);
+    evas_object_image_size_get(img, &img_w, &img_h);
+    evas_object_image_size_set(img, img_w, img_h);
+    evas_object_resize(img, img_w, img_h);
+    evas_object_resize(win, img_w, img_h);
+    elm_win_render(win);
+
+    m = evas_object_image_data_get(img, EINA_TRUE);
 
     data = "" sizeof(unsigned int *));
     if (!data)
@@ -115,7 +118,7 @@ unsigned int ** icon_create(Evas_Object *win, const Icon *ic)
     {
         unsigned int *bmp;
 
-        data[idx] = calloc(ic->w * ic->h * ic->tile_sz * ic->tile_sz, sizeof(unsigned int));
+        data[idx] = calloc(ic->w * ic->h * ic->pixel_sz * ic->pixel_sz, sizeof(unsigned int));
         if (!data[idx])
         {
             goto del_data;
@@ -129,17 +132,19 @@ unsigned int ** icon_create(Evas_Object *win, const Icon *ic)
             {
                 unsigned int col = bmp[l * img_w + c];
 
-                for (int j = 0; j < ic->tile_sz; j++)
+                for (int j = 0; j < ic->pixel_sz; j++)
                 {
-                    for (int i = 0; i < ic->tile_sz; i++)
+                    for (int i = 0; i < ic->pixel_sz; i++)
                     {
-                        data[idx][(ic->tile_sz * l + j) * ic->w * ic->tile_sz + ic->tile_sz * c + i] = col;
+                        data[idx][(ic->pixel_sz * l + j) * ic->w * ic->pixel_sz + ic->pixel_sz * c + i] = col;
                     }
                 }
             }
         }
     }
 
+    evas_object_del(img);
+
     return data;
 
   del_data:
@@ -147,16 +152,27 @@ unsigned int ** icon_create(Evas_Object *win, const Icon *ic)
         free(data[idx]);
     free(data);
   del_o:
-    evas_object_del(o);
+    evas_object_del(img);
     return NULL;
 }
 
-Eina_Bool icon_init(Evas_Object *win, int tile_sz)
+Eina_Bool
+icon_init(int pixel_sz)
 {
+    const char *old_engine;
+    Evas_Object *win;
     Eina_Strbuf *buf;
     Icon ic;
     Eina_Bool ret = EINA_FALSE;
 
+    old_engine = elm_config_preferred_engine_get();
+
+    elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
+    elm_config_preferred_engine_set("buffer");
+    win = elm_win_add(NULL, "icon", ELM_WIN_BASIC);
+    evas_object_show(win);
+    elm_win_norender_push(win);
+
     buf = eina_strbuf_new();
     if (!buf)
         return ret;
@@ -166,11 +182,10 @@ Eina_Bool icon_init(Evas_Object *win, int tile_sz)
 
     ic.buf = buf;
     ic.offset = cipher_offset;
-    ic.data = ""
     ic.w = cipher_size[0];
     ic.h = cipher_size[1];
     ic.nbr = CIPHER_COUNT;
-    ic.tile_sz = tile_sz;
+    ic.pixel_sz = pixel_sz;
 
     cipher_bmp = icon_create(win, &ic);
 
@@ -180,11 +195,10 @@ Eina_Bool icon_init(Evas_Object *win, int tile_sz)
 
     ic.buf = buf;
     ic.offset = tile_offset;
-    ic.data = ""
     ic.w = tile_size[0];
     ic.h = tile_size[1];
     ic.nbr = TILE_COUNT;
-    ic.tile_sz = tile_sz;
+    ic.pixel_sz = pixel_sz;
 
     tile_bmp = icon_create(win, &ic);
 
@@ -194,14 +208,16 @@ Eina_Bool icon_init(Evas_Object *win, int tile_sz)
 
     ic.buf = buf;
     ic.offset = smiley_offset;
-    ic.data = ""
     ic.w = smiley_size[0];
     ic.h = smiley_size[1];
     ic.nbr = SMILEY_COUNT;
-    ic.tile_sz = tile_sz;
+    ic.pixel_sz = pixel_sz;
 
     smiley_bmp = icon_create(win, &ic);
 
+    evas_object_del(win);
+    elm_config_preferred_engine_set(old_engine);
+
     ret = EINA_TRUE;
 
   free_buf:
@@ -209,35 +225,41 @@ Eina_Bool icon_init(Evas_Object *win, int tile_sz)
     return ret;
 }
 
-void cipher_size_get(int *w, int *h)
+void
+cipher_size_get(int *w, int *h)
 {
     if (w) *w = cipher_size[0];
     if (h) *h = cipher_size[1];
 }
 
-unsigned int *cipher_bmp_get(Cipher_Type t)
+unsigned int *
+cipher_bmp_get(Cipher_Type t)
 {
     return cipher_bmp[t];
 }
 
-void tile_size_get(int *w, int *h)
+void
+tile_size_get(int *w, int *h)
 {
     if (w) *w = tile_size[0];
     if (h) *h = tile_size[1];
 }
 
-unsigned int *tile_bmp_get(Tile_Type t)
+unsigned int *
+tile_bmp_get(Tile_Type t)
 {
     return tile_bmp[t];
 }
 
-void smiley_size_get(int *w, int *h)
+void
+smiley_size_get(int *w, int *h)
 {
     if (w) *w = smiley_size[0];
     if (h) *h = smiley_size[1];
 }
 
-unsigned int *smiley_bmp_get(Smiley_Type t)
+unsigned int *
+smiley_bmp_get(Smiley_Type t)
 {
     return smiley_bmp[t];
 }
diff --git a/src/bin/icon.h b/src/bin/icon.h
index c6e0c04..271d3ad 100644
--- a/src/bin/icon.h
+++ b/src/bin/icon.h
@@ -50,7 +50,7 @@ typedef enum
     SMILEY_COUNT
 } Smiley_Type;
 
-Eina_Bool icon_init(Evas_Object *win, int tile_sz);
+Eina_Bool icon_init(int tile_sz);
 
 void cipher_size_get(int *w, int *h);
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to