How it works: (this will be a biiiiiig post

)
| Code: |
--
-- This is the initialization function. It gets called every time Rainlendar
-- is started or refreshed. The initialization function must be defined in the
-- skin file.
--
function Timeloid3D_Initialize(skin, window)
-- Create a timer which updates the data once per second
Rainlendar_CreateTimer(1000, Timeloid3D_OnTimer, skin .. "|" .. window)
-- Run the timer callback so the data is updated immediately
Timeloid3D_OnTimer(skin .. "|" .. window)
end
--
-- A callback function for the timer. This gets called every time the timer triggers.
-- Returns true so the timer will go on forever (false would stop the timer).
--
function Timeloid3D_OnTimer(userData)
-- Split the user data
_, _, skin, window = userData:find("(.*)|(.*)")
time = os.date("%I:%M:%S")
_, _, tHour, tMin, tSec = time:find("(%d+):(%d+):(%d+)")
tHour = tonumber(tHour)
tMin = tonumber(tMin)
tSec = tonumber(tSec)
Rainlendar_SetItemValue(window, "Timeloid3D.hour", "element", "bitmap.h" .. tHour)
Rainlendar_SetItemValue(window, "Timeloid3D.tens", "element", "bitmap.m" .. math.floor(tMin / 10))
Rainlendar_SetItemValue(window, "Timeloid3D.minute", "element", "bitmap.mm" .. tMin % 10)
Rainlendar_SetItemValue(window, "Timeloid3D.second", "element", "bitmap.s" .. tSec)
Rainlendar_Redraw(0, window)
return True
end
|
This is the timeloid.lua file, a LUA script. The first function (Timeloid3D_Initialize) is launched when the window appears (see next, timeloid.xml). It creates a timer which launchs the second function (Timeloid3D_OnTimer) every 1000 ms (like in the meter.ini). The OnTimer reads the current time (os.date) and using Regular Expressions (not too dificult but kind of), it takes the hour, the minute and the second and convert each string (a text) into a number.
Another way is to read the hour, minute and second separately with os.date("%I"), os.date("%M") and os.date("%S"), but you can have something like 1:59:58 -> 1:59:59 -> 1:00:00 -> 2:00:01 if they're not taken at the same time. (you take the hour just a moment before the change to 2).
The ".." concatenates strings. And with the SetItemValue (you can find more info in the Rainlendar Help) it changes the value of e.g. "element" of the item called "Timeloid3D.hour". And then, redraws the window (every second a new picture).
The values for the element tag are stored in xml/elements.xml
| Code: |
<?xml version="1.0" encoding="UTF-8" ?>
<skin version="1.0">
<elements>
<bitmap id="bitmap.h0" file="images/h0.png" />
...
<bitmap id="bitmap.h12" file="images/h12.png" />
<bitmap id="bitmap.mm0" file="images/mm0.png" />
...
<bitmap id="bitmap.mm12" file="images/mm12.png" />
<bitmap id="bitmap.m0" file="images/m0.png" />
...
<bitmap id="bitmap.m12" file="images/m12.png" />
<bitmap id="bitmap.s0" file="images/s0.png" />
...
<bitmap id="bitmap.s59" file="images/s59.png" />
<bitmap id="bitmap.secsshadow" file="images/secsshadow.png" />
<bitmap id="bitmap.shadow" file="images/shadow.png" />
</elements>
</skin>
|
Each image must have an identifier. Because of the pattern, I can change the values of the element tag.
Now comes the window, timeloid.xml:
| Code: |
<?xml version="1.0" encoding="UTF-8" ?>
<skin version="1.0">
<window id="Timeloid 3D" w="442" h="785" threshold="48" default="0" oncreate="Timeloid3D_Initialize('#SKIN#', '#ID#')">
<image id="Timeloid3D.shadow" x="0" y="590" element="bitmap.shadow" />
<image id="Timeloid3D.hour" x="20" y="0" element="bitmap.h0" />
<image id="Timeloid3D.tens" x="40" y="189" element="bitmap.m0" />
<image id="Timeloid3D.minute" x="0" y="365" element="bitmap.mm0" />
<image id="Timeloid3D.secsshadow" x="235" y="394" element="bitmap.secsshadow" />
<image id="Timeloid3D.second" x="246" y="455" element="bitmap.s0" />
</window>
</skin>
|
When the window is created (oncreate) it launchs the first function of this post.
Then, one by one, each image that composes the window. (I use .h0, .m0, .mm0 and .s0 by default)
The order matters, that's way I put the secsshadow before the second but after the minute.
You can find these files renaming the extension from .r2skin to .zip and opening it with any app.
If you want to port any other skin, you will need to check every skin (start with Shadow4.r2skin). When I start to use Rainlendar2, I didn't know anything about LUA or XML (a little of XML). But you will need a little experience on C language (from LUA comes).
There is a "better" way, with less lines, but you need to put all the hours in 1 file, one next the other. You will have a image with e.g. 12 frames (1 -> 12), and with the <time> item, you can "do" something automatic.