embryo_timer.edc

- Main Page
- Related Pages
- Modules
- Data Structures
- Files
- Examples

embryo_timer.edc

This example shows the usage of timers in embryo.

This example shows the usage of timers in embryo.

collections {
group { name: "main";
script {
public timer_cb(val) {
new x, y, w, h;
new buf[32];
/* set labels with object info */
get_geometry(PART:"red_rect", x, y, w, h);
snprintf(buf, sizeof(buf), "Timer called %d times.", val);
set_text(PART:"label1", buf)
snprintf(buf, sizeof(buf), "Object x: %d w: %d", x, w);
set_text(PART:"label2", buf)
/* renew the timer */
timer(1 / 30, "timer_cb", val + 1);
}
}
parts {
part { name: "bg";
type: RECT;
description { state: "default" 0.0;
color: 255 255 255 255;
}
}
part { name: "label1";
type: TEXT;
description { state: "default" 0.0;
color: 0 0 0 255;
text {
text: "";
font: "Sans";
size: 12;
align: 0.0 0.7;
}
}
}
part { name: "label2";
type: TEXT;
description { state: "default" 0.0;
color: 0 0 0 255;
text {
font: "Sans";
size: 12;
align: 0.0 0.8;
}
}
}
part { name: "red_rect";
type: RECT;
description { state: "default" 0.0;
color: 255 0 0 255;
max: 30 30;
align: 0.1 0.2;
}
description { state: "default" 1.0;
inherit: "default" 0.0;
color: 0 0 255 255;
max: 50 30;
align: 0.9 0.2;
}
}
}
programs {
/* move the red rect back an forth in a loop */
program { name: "init";
signal: "load";
source: "";
action: STATE_SET "default" 1.0;
transition: SINUSOIDAL 1.0;
target: "red_rect";
after: "loop";
}
program { name: "loop";
action: STATE_SET "default" 0.0;
transition: SINUSOIDAL 1.0;
target: "red_rect";
after: "init";
}
/* run the timer_cb for the first time */
program { name: "init2";
signal: "load";
source: "";
script {
timer_cb(0);
}
}
}
}
}