Support and General Use > Theming and Appearance Customization

Make icon blink?

(1/2) > >>

Elaphe:
I have this code to display different icons depeding if the music is being played, paused, stoped, etc. Can you please modify so that the play icon (b) blinks when active?


--- Code: ---# Play Mode
%V(1,0,11,6,3)
%xl(C,playmode.bmp,0,0,6)
%?mp<%xd(Ca)|%xd(Cb)|%xd(Cc)|%xd(Cd)|%xd(Ce)||||>

--- End code ---

[Saint]:
There's (at least) two ways to do this:

This method requires no additional imagery, but has the (debateable) disadvantage of a lot of needless code duplication and the potential to suffer from drawing issues.
If we don't draw over top of the image we are replacing conditionally, parts of it may remain, causing nasty visual artefacts.

--- Code: ---# Play Mode
%V(1,0,11,6,3)
%xl(C,playmode.bmp,0,0,6)
%t(1.0)%?mp<%xd(Ca)|%xd(Cb)|%xd(Cc)|%xd(Cd)|%xd(Ce)||||>;%t(1.0)%?mp<%xd(Ca)||%xd(Cc)|%xd(Cd)|%xd(Ce)||||>
--- End code ---


The following method requires an additional bitmap to be added to the "C" bitmap strip. This bitmap image should be entirely blank. We'll append it to the very end of the strip, this keeps the addition as minimally invasive as possible. In my example it will be using the sub-image identifier "n".

Remember that this will also require you to adjust the preload (%xl) declaration for the play state icon bitmap strip ("C") to make it aware that it is now handling an additional sub-image

The syntax for bitmap preloads is as follows:

--- Code: ---%xl(IDENTIFIER,bitmap_asset_file_name.bmp,x-pos,x-pos,N)
--- End code ---
Where "N" is the number of subimages contained in the bitmap strip.

Example follows:

--- Code: ---# Play Mode
%V(1,0,11,6,3)
%xl(C,playmode.bmp,0,0,6)
%?mp<%xd(Ca)|%xd(Cb)|%t(1.0)%xd(Cc);%t(1.0)%xd(Cn)|%xd(Cd)|%xd(Ce)||||>
--- End code ---


I would also like to point out that this theme is using the antiquated, virtually impossible to read, sub-image and identifier syntax.
Rockbox has been capable of using descriptive identifiers for a rather long period of time now, but I understand that this is rarely used as most themes seem to be copy-and-paste variants of someone else's (ancient) work.

The current syntax is as follows:

--- Code: ---# Play Mode
%V(1,0,11,6,3)
%xl(PLAY_MODE,playmode.bmp,0,0,6)
%?mp<%xd(PLAY_MODE,1)|%xd(PLAY_MODE,2)|%t(1.0)%xd(PLAY_MODE,3);%t(1.0)%xd(PLAY_MODE,N)|%xd(PLAY_MODE,4)|%xd(PLAY_MODE,5)||||>
--- End code ---
Where "N" is the value of the appended bitmap subimage (your example leads me to believe this value would be 7, as the declaration states playmode.bmp has 6 subimages, yet I only see 5 images being called...).

This can potentially make for longer code, but it makes the code a lot easier to read.

It is somewhat important to explain that in both examples, we are using "alternating sublines" to govern the blinking of our state icon.

This is achieved by first specifying the %t tag, and then dividing the alternating sections with a semicolon. The timeout tag (%t) accepts an optional parameter in tenths of a second to govern the length of time a section is displayed. Alternating sublines will loop back to the first segment after all subline segments have been displayed.

Each alternating subline section can have a unique timeout. If no timeout parameter is given, it will default to 1 second timeout:


--- Code: ---%t(2)displayed for 2 seconds;%t(0.1)displayed for one tenth of a second;(%t)displayed for one second - no timeout parameter given
--- End code ---



[Saint]

Elaphe:
Thanks a lot. It's working! However, I have a problem.

With this code:


--- Code: ---# Play Mode
%V(1,0,11,6,3)
%xl(PLAY_MODE,playmode.bmp,0,0,7)
%?mp<%xd(PLAY_MODE,1)|%xd(PLAY_MODE,2);%t(1.0)%xd(PLAY_MODE,7)|%t(1.0)%xd(PLAY_MODE,3)|%xd(PLAY_MODE,4)|%xd(PLAY_MODE,5)||||>
--- End code ---

I have the play icon blink (1 second on, 1 second off).

However, if I try this, for 0.2 seconds on, and 0.2 seconds off, only the latter works:


--- Code: ---# Play Mode
%V(1,0,11,6,3)
%xl(PLAY_MODE,playmode.bmp,0,0,7)
%?mp<%xd(PLAY_MODE,1)|%xd(PLAY_MODE,2);%t(0.2)%xd(PLAY_MODE,7)|%t(0.2)%xd(PLAY_MODE,3)|%xd(PLAY_MODE,4)|%xd(PLAY_MODE,5)||||>
--- End code ---

So, the icon stays visible for 1 seconds, and invisible for 0.2 seconds.

Any mistake in my code?

This is the image I'm working with:


[Saint]:
Assuming you only want the play state icon to blink, at a rate of .2s, you would want:

--- Code: ---%?mp<%xd(PLAY_MODE,1)|%t(0.2)%xd(PLAY_MODE,2);%t(0.2(PLAY_MODE,7)|%xd(PLAY_MODE,3)|%xd(PLAY_MODE,4)|%xd(PLAY_MODE,5)||||>
--- End code ---


[Saint]

Elaphe:
Sorry, it's not working here. I get the default ugly white status bar in the simulator.

Navigation

[0] Message Index

[#] Next page

Go to full version