Support and General Use > Theming and Appearance Customization
Tutorial - Creating a Clock with an Image Strip
DrewVosburg:
It has been done before, but this guide will help you create a clock using an image strip.
The idea here is to only have ten numbers in the strip, so that one might change the font
easily. This isn't something that may come up often, but it's useful to know if you want
to make a multicolored font for a clock.
Let's suppose we have a 6px wide image strip of numbers, 0-9 from top to bottom:
--- Code: ---%xl(N,numbers.bmp,0,0,10)
--- End code ---
We can use these numbers to fill in each digit for the clock. The trickiest part about this
procedure is positioning the clock. This clock will be 31 px wide, each digit being 6px, and
a colon in the center that is 3px wide. Placement for this tutorial will be in the upper left
corner (0,0), but you can move the clock by adding to the X and Y of each viewport.
We will start with the hours. I am using a 12 hour clock. The same principles apply with
a 24 hour clock, although a 12 hour clock begins at 1, while a 24 hour clock begins at 0.
Remember that subimage "a" is the number zero, and "b" is one. The first nine will be
nothing, and the last three will be a one.
--- Code: ---#HOURS - Tens place
%V(0,0,6,-,-)
%?cl<|||||||||%xd(Nb)|%xd(Nb)|%xd(Nb)>
--- End code ---
The ones place is a bit more complex:
--- Code: ---#HOURS - Ones place
%V(6,0,6,-,-)
%?cl<%xd(Nb)|%xd(Nc)|%xd(Nd)|%xd(Ne)|%xd(Nf)|%xd(Ng)|%xd(Nh)|%xd(Ni)|%xd(Nj)|%xd(Na)|%xd(Nb)|%xd(Nc)>
--- End code ---
This conditional has twelve values, one for each of the twelve hours. The important thing
to remember with a 12 hour clock is that it begins counting at 1, not 0. Thus, the first
entry is subimage "b", for 1. Subimages "a", "b", and "c" round out the last three values
for 10, 11, and 12.
Let's add in a blinking colon to divide hours from minutes. First, preload the image:
--- Code: ---%xl(c,colon.bmp,0,0)
--- End code ---
Now let's give it a viewport:
--- Code: ---%V(12,0,3,-,-)
--- End code ---
I'm going to use a %t tag to make it blink in half second intervals.
--- Code: ---%t(0.5)%xd(c);%t(0.5);
--- End code ---
The tens place for minutes is basically the same as the tens place for the hours, but
continued. Because there are sixty values for minutes and the tens digit changes
every ten values, we must make 6 sets of 10 values. The numbers 0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nf)|%xd(Nf)|%xd(Nf)|%xd(Nf)|%xd(Na)>
#MINUTES - Ones place
%V(21,0,6,-,-)
%?cM<%xd(Na)|%xd(Nb)|%xd(Nc)|%xd(Nd)|%xd(Ne)|%xd(Nf)|%xd(Ng)|%xd(Nh)|%xd(Ni)|%xd(Na)|%xd(Na)|%xd(Nb)|%xd(Nc)|%xd(Nd)|%xd(Ne)|%xd(Nf)|%xd(Ng)|%xd(Nh)|%xd(Ni)|%xd(Na)|%xd(Na)|%xd(Nb)|%xd(Nc)|%xd(Nd)|%xd(Ne)|%xd(Nf)|%xd(Ng)|%xd(Nh)|%xd(Ni)|%xd(Na)|%xd(Na)|%xd(Nb)|%xd(Nc)|%xd(Nd)|%xd(Ne)|%xd(Nf)|%xd(Ng)|%xd(Nh)|%xd(Ni)|%xd(Na)|%xd(Na)|%xd(Nb)|%xd(Nc)|%xd(Nd)|%xd(Ne)|%xd(Nf)|%xd(Ng)|%xd(Nh)|%xd(Ni)|%xd(Na)|%xd(Na)|%xd(Nb)|%xd(Nc)|%xd(Nd)|%xd(Ne)|%xd(Nf)|%xd(Ng)|%xd(Nh)|%xd(Ni)|%xd(Nj)>
--- End code ---
Hope you found this useful! I am planning on adding it to a theme I made in order
to avoid having to make a custom .fnt, although it will have to happen eventually...
Post Merge: January 12, 2011, 01:14:52 PMIf you want the files i used to play with:
http://dl.dropbox.com/u/2255413/clock.zip
Giova:
This is great, but it also reveal a limit of the wps language: these long sequences of values.
Working on something similar a while ago but with volume (-73 to 6), I was thinking on something like 'to', for instance <%xd(Na)|---|%xd(Nz)> instead of the whole sequence.
Just an idea...
Anyway, good job!
JdGordon:
Nice, except this can be alot simpler.
use %?if(), %xd(label, subimage_number) and %xd(label, other_tag)..
http://www.rockbox.org/wiki/Main/CustomWPS#A_37if_40_41_logical_comparison_tag
http://www.rockbox.org/wiki/CustomWPS#xd_45_Display_a_preloaded_40sub_41image
I could also add a tag so either allow simple maths, or simply to split up another tags number... eg %?xx(%cl, 1)<0|1|2> <- that says "get the first digit" and use that for the conditional... although I'm not entirely sure how to make that sensible.
DrewVosburg:
I would KILL to be able to get certain digits of numbers. I've transitioned to using ifs for the tens digits and keeping the ones the way they are.
With volume, my Fuze has a minimum value of -81dB, but the simulator has a minimum value of -73. I had to use ifs for the ones digit, which then resulted in a series of if statements which hung the device on theme loading. I got it to work, but it's ugly as sin. ANY kind of math would be greatly appreciated!
Llorean:
If the simulator reports different values for the volume than the same build revision, for the same target, that's a bug and should be reported on flyspray.
Navigation
[0] Message Index
[#] Next page
Go to full version