aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Ghigonis <laurent@p1sec.com>2012-11-30 15:42:30 +0100
committerLaurent Ghigonis <laurent@p1sec.com>2012-11-30 15:42:30 +0100
commit0468049ba9c7701fcc4f0999fda4511ba2eaa8da (patch)
tree0d03a5e8db1858fc7d354d1662fd549e4416e0b2
parentadd conditionnal glouglou support :) (diff)
downloadglouglou-0468049ba9c7701fcc4f0999fda4511ba2eaa8da.tar.xz
glouglou-0468049ba9c7701fcc4f0999fda4511ba2eaa8da.zip
display different fixed colors based on glouglou event.
for now only handle process events
-rw-r--r--src/elife_evas_smart.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c
index bde26ff..b732294 100644
--- a/src/elife_evas_smart.c
+++ b/src/elife_evas_smart.c
@@ -72,6 +72,7 @@ enum lifemode {
struct cell {
int age, newage;
+ u_int32_t forced_color;
int x, y;
int r, g, b;
};
@@ -96,7 +97,7 @@ static struct grid *grid_new(Evas_Object *container,
int w, int h, enum lifemode mode);
static void grid_del(struct grid *grid);
static int grid_evolution(struct grid *grid);
-static void grid_inject_pattern(struct grid *grid);
+static void grid_inject_pattern(struct grid *grid, u_int32_t color);
static int grid_redraw(struct grid *grid, int w, int h);
static int cell_neighbours_count(struct cell *cell, struct grid *grid);
static void cell_redraw(struct cell *c, struct grid *g);
@@ -153,9 +154,16 @@ int
gg_packet(struct gg_client *cli, struct gg_packet *pkt)
{
struct grid *grid;
+ u_int32_t color;
grid = cli->usrdata;
- grid_inject_pattern(grid);
+ switch(pkt->type) {
+ case PACKET_FORK: color=0xff0000; break;
+ case PACKET_EXEC: color=0x00ff00; break;
+ case PACKET_EXIT: color=0x0000ff; break;
+ default: color=0x0f00f0; break;
+ }
+ grid_inject_pattern(grid, color);
return 0;
}
@@ -196,6 +204,7 @@ grid_new(Evas_Object *container, int w, int h, enum lifemode mode)
cell->r = 0;
cell->g = 0;
cell->b = 0;
+ cell->forced_color = 0x000000;
cell->age = !(rand() % INITCELL_PROBA);
}
}
@@ -264,6 +273,8 @@ grid_evolution(struct grid *grid)
cell->newage = 0;
break;
}
+ if (cell->newage == 0 && cell->forced_color)
+ cell->forced_color = 0;
if (DEBUG)
printf("evolution: %d %d n %d age %d newage %d\n", i, j,
neighbours, cell->age, cell->newage);
@@ -274,7 +285,7 @@ grid_evolution(struct grid *grid)
event_base_loop(grid->ev_base, EVLOOP_NONBLOCK);
#else
if (rand() % INJECT_PROBA == 0)
- grid_inject_pattern(grid);
+ grid_inject_pattern(grid, 0);
#endif
for (j=0; j<grid->h; j++) {
@@ -290,7 +301,7 @@ grid_evolution(struct grid *grid)
}
static void
-grid_inject_pattern(struct grid *grid)
+grid_inject_pattern(struct grid *grid, u_int32_t color)
{
struct cell *cell;
enum lifepattern_t npat;
@@ -312,6 +323,7 @@ grid_inject_pattern(struct grid *grid)
continue;
cell = CELL_GET(grid, cx, cy);
cell->newage = (pat->pat[pat->w*j + i] - '0') * 27;
+ cell->forced_color = color;
cell->age = cell->newage;
// cell_redraw(cell, grid);
}
@@ -378,12 +390,16 @@ cell_neighbours_count(struct cell *cell, struct grid *grid)
static void
cell_redraw(struct cell *c, struct grid *grid)
{
- int r, g, b, a;
+ u_int8_t r, g, b, a;
int x, y, w, h;
int i, j;
int color;
- if (c->age < 100) {
+ if (c->forced_color && c->age > 0) {
+ r = (c->forced_color & 0xff0000) >> 16;
+ g = (c->forced_color & 0xff00) >> 8;
+ b = (c->forced_color & 0xff);
+ } else if (c->age < 100) {
r = (c->age > 0) ? 128 : 0;
g = (c->age > 0) ? (33 + c->age * 7) : 0;
b = 0;
@@ -426,7 +442,7 @@ grid_mouse_down(void *data,
struct grid *grid;
grid = data;
- grid_inject_pattern(grid);
+ grid_inject_pattern(grid, 0);
}
Evas_Object *