Well, this program animates a message on the screen, its pump being a timer.
We can only count on one Timer, it is called OBJ_500MSEC. How long do you think
it elapses before the timer notifies us? 500 milliseconds? The power of labels!!!
If you need finer intervals, well now you need to use PollEvents(). It doesn't
give you timers out of nothing, but it's not blocking and you can manage the
delay in the event-loop (Use LibWait). It's not an elegant solution but...
I couldn't find this label in the SDK header files, so i defined it here
#define IW_EXT500M 0x0001
We just define the message we want to animate and a label to remember the
#define MESSAGE "Pocket-Viewer"
#define SCREEN_W 160
If we want to be notified on the timer event we must put it in the touch table
just like we did with the touch events. The timer is called OBJ_500MSEC, its
action ACT_500MSEC. No coordinates, we assign them "the" dummy value.
TCHTBL TchList =
/* Timer */
0, 0, 0, 0,
/* End */
0, 0, 0, 0,
Here we make some noise, everytime the timer calls out!! Try it ;)
static int pos;
int msg_x, msg_w;
if (pos > strlen(MESSAGE))
pos = 0;
strncpy(msg_text, MESSAGE, pos);
msg_text[pos] = 0;
msg_w = LibGetProStrSize(IB_PFONT3, msg_text);
msg_x = (SCREEN_W - msg_w) / 2;
LibGdsBox(msg_x - 2, 76 - 2, msg_x + msg_w + 2, 84 + 4);
LibPutProStr(IB_PFONT3, msg_x, 76, msg_text, msg_w);
Right! Just how you guessed, our usual events manager, BUT...
bool bExit = FALSE;
for (;bExit == FALSE;)
...that's how we listen to the timer event. This time we don't test the
"obj" field. That's because the timer event may happen the same moment a
touch event happens, in this case we have to test "ext" for the timer and
"obj" for the other object. But we don't know if this is the case, so we
always test "ext" for the timer, it is set anyway.
if (tsts.ext == IW_EXT500M)
if (tsts.obj == OBJ_HIC_ESC)
bExit = TRUE;