Re: Clocks & Backgrounds

Scott Raney ((no email))
Thu, 10 Mar 94 9:41:30 MST

>
> >I have been tasked to mock-up a desktop interface using MetaCard. The
> >cognitive people's design calls for a clock to be displayed. Does any one
> >know how I can have a running clock update itself in a background field?
> >Since it is just a demo, I can always just put a random time value into a
> >field as text, but a running clock would really knock their socks off.
> >
> Create a field called "Time_Field", and put the following handler in your
> card or stack script. If this eats a lot of cpu cycles (don't know if it
> would or not), you might want to look at changing the idleRate.
>
> on idle
> put the long time into field "Time_Field"
> end idle

Note that getting and setting field contents takes twice as long as
getting and setting a variable (setting takes 4 times as long if the
screen isn't locked due to the X calls and the redraws), so you could
optimize this by storing the time into a variable and comparing with
it first:

local curtime
on idle
if curtime is not the long time then
put the long time into curtime
put curtime into field "Time_Field"
end if
end idle

You could also set the idleRate to a bigger number, but neither of
these are really necessary. Most workstations are fast enough that
even doing something really CPU intensive like shell("date") will work
OK in an idle handler. This will slow down any weather forcasting you
happen to be doing in the background, however ;-)

If you want to get fancy, make an analog clock. You can use a polygon
style graphic for the hands, and set the points property in the idle
handler. Other than a little math (you'll need to use sin() and cos()
to get the length and orientation right) the process is
straightforward. You could either use another graphic for the clock
face, or cheat and take a snapshot of xclock and then erase the hands
and the background (use the bucket tool with mouse button 2). Sounds
like a good stack contest project to me (hint, hint).
Scott

-- 
***********************************************************************
* Scott Raney  303-447-3936            Remember: the better you look, *
* raney@metacard.com                   the more you'll see -- Lidia   *
***********************************************************************