It is currently April 24th, 2024, 10:01 am

Typewriter Effect

Get help with creating, editing & fixing problems with skins
User avatar
ZipD
Posts: 37
Joined: September 10th, 2017, 4:31 pm

Typewriter Effect

Post by ZipD »

I need help with creating a typewriter effect where each alphabet of a text appears one after another, like what a typewriter would do. I'm thinking that an ActionTimer would do this but I'm way over my head since I don't know how to get Skin A to send a text to Skin B (I've managed to do this), and then have Skin B do the effect (I need help with this).

Here's the relevant portion of the code from Skin A (Division 2_white.ini):

Code: Select all

[MeterKeyImage]
Meter=Image
MeterStyle=MeterImageStyle
ImageName=Division 2_white.png
MouseOverAction=[!SetOption MeterSpacebarText Text "Tom Clancy's Division 2" "KeyCaps"][!Update KeyCaps]
MouseLeaveAction=[!SetOption MeterSpacebarText Text "" "KeyCaps"][!Update KeyCaps]
And Skin B (Spacebar.ini):

Code: Select all

[MeterSpacebarText]
Meter=String
X=20
Y=(#KeyHeight#-20)/2
W=(#KeyWidth#-35)
FontFace=Courier New Bold
FontSize=16
ClipString=1
Antialias=1
Text=""
Here's also the entire skin:
KeyCaps_1.0.rmskin
You do not have the required permissions to view the files attached to this post.
User avatar
Yincognito
Rainmeter Sage
Posts: 7152
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Typewriter Effect

Post by Yincognito »

ZipD wrote: April 14th, 2020, 1:41 pm I need help with creating a typewriter effect where each alphabet of a text appears one after another, like what a typewriter would do. I'm thinking that an ActionTimer would do this but I'm way over my head since I don't know how to get Skin A to send a text to Skin B (I've managed to do this), and then have Skin B do the effect (I need help with this).

Here's the relevant portion of the code from Skin A (Division 2_white.ini):

Code: Select all

[MeterKeyImage]
Meter=Image
MeterStyle=MeterImageStyle
ImageName=Division 2_white.png
MouseOverAction=[!SetOption MeterSpacebarText Text "Tom Clancy's Division 2" "KeyCaps"][!Update KeyCaps]
MouseLeaveAction=[!SetOption MeterSpacebarText Text "" "KeyCaps"][!Update KeyCaps]
And Skin B (Spacebar.ini):

Code: Select all

[MeterSpacebarText]
Meter=String
X=20
Y=(#KeyHeight#-20)/2
W=(#KeyWidth#-35)
FontFace=Courier New Bold
FontSize=16
ClipString=1
Antialias=1
Text=""
Here's also the entire skin: KeyCaps_1.0.rmskin
I didn't looked yet at your skin, but if the "typewriter effect" is what I think it is, then, in the meantime, you might want to take a look at the posts by me and balala (especially the latter ones) here, where we both implemented an "inverse typewriter effect" (i.e. from end to start). I did it using "classic" methods like a counter and an "eat chars" effect, balala did it using ActionTimer, and it actually worked in the direction you want it to (i.e. from start to end). My guess is that either one of these methods could be adapted to your Skin B (balala's implementation would probably be very close to what you envision, given the already suited direction)...

EDIT: Even more specific, take a look at the screenshots/GIF posted here. Is this close to what you want (the 2nd row in the GIF - bar the scrolling, that is)?
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
balala
Rainmeter Sage
Posts: 16164
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Typewriter Effect

Post by balala »

ZipD wrote: April 14th, 2020, 1:41 pm I need help with creating a typewriter effect where each alphabet of a text appears one after another, like what a typewriter would do. I'm thinking that an ActionTimer would do this but I'm way over my head since I don't know how to get Skin A to send a text to Skin B (I've managed to do this), and then have Skin B do the effect (I need help with this).
As Yincognito wrote, here is my approach, based on what have I wrote on the link he posted. There has been added a lot of modifications to the original code, so, I package the whole config and upload the package. Please download, install and test it, then let me know what do you think about it.
You do not have the required permissions to view the files attached to this post.
User avatar
ZipD
Posts: 37
Joined: September 10th, 2017, 4:31 pm

Re: Typewriter Effect

Post by ZipD »

Wow, just wow! Thank you, that worked perfectly. I want to understand what you did but can you help explain what each of these 4 measures do?

Code: Select all

[MeasureString]
Measure=String
String=#AppName#
RegExpSubstitute=1
Substitute=".":"0","^0(.*)$":"1\1","^$":"0"
IfMatch=^$
IfMatchAction=[!CommandMeasure "MeasureSlide" "Stop 1"][!SetVariable Step "0"][!UpdateMeasure "MeasureSlide"][!UpdateMeasure "MeasureTypeWriter"]
DynamicVariables=1

[MeasureStringLength]
Measure=Calc
Formula=(( [MeasureString] = 0 ) ? 0 : ( Log ( 10 * [MeasureString] )))
DynamicVariables=1

[MeasureSlide]
Measure=Plugin
Plugin=ActionTimer
ActionList1=Repeat In,100,[MeasureStringLength]
In=[!SetVariable Step "(Clamp((#Step#+1),0,100))"]#U#
DynamicVariables=1

[MeasureTypeWriter]
Measure=String
String=#AppName#
RegExpSubstitute=1
Substitute="^(.{#Step#}).*$":"\1","\\1":""
DynamicVariables=1
User avatar
balala
Rainmeter Sage
Posts: 16164
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Typewriter Effect

Post by balala »

ZipD wrote: April 14th, 2020, 4:25 pm I want to understand what you did but can you help explain what each of these 4 measures do?
A very important thing is that when you're hovering the mouse over the skin of the KeyCaps\Division 2 config (whatever that would be), not the Text option of the [MeterSpacebarText] meter (KeyCaps\Spacebar.ini skin) is set, but an AppName variable (I wrote it initially as MyString, but I see you've renamed it). I had to do this, because this variable is used onto more measures of the Spacebar.ini skin.
Now the explanation of the above measures:
  • [MeasureString] is making a substitution of the characters of the AppName variable: each character is replaced by a 0, then finally the first 0 is replaced by an 1. This number will be used to calculate the length of the AppName variable, through the [MeasureStringLength] measure.
  • As said above the [MeasureStringLength] measure returns the length of the AppName variable as a number. It does this applying a logarithm function (Log). But unfortunately I had here to complicate a little bit the function, because if the number returned by the [MeasureString] is zero (which happens when the AppName variable is empty), the logarithm function is not defined. That's why I had to add the condition: if the value of the [MeasureString] is 0, the [MeasureStringLength] returns also 0 (this is the length of an empty string), otherwise it calculates the length of the AppName variable.
  • [MeasureSlide] is the ActionTimer plugin measure, used to increase a variable, from 0 to the length of the AppName variable. This variable is Step. When the [MeasureSlide] measure is ran, it starts to increase the value of the Step variable from 0 to the length of the AppName variable.
  • Finally, the [MeasureTypeWriter] String measure is used to remove the not needed characters of the AppName variable. This is done through the substitution. This substitution gets a number of #Step# characters of the AppName variable and returns these characters. The other variables (following the #Step#th character) are simply removed.
Unfortunately this procedure has a limit: the AppName variable must be shorter then 308 characters. Above this number the [MeasureStringLength] measure doesn't return the length of the variable. In such cases probably a .lua script file could help, but didn't tried this yet. However I hope 308 is an enough large number of characters for most cases.
User avatar
Yincognito
Rainmeter Sage
Posts: 7152
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Typewriter Effect

Post by Yincognito »

ZipD wrote: April 14th, 2020, 4:25 pmI want to understand what you did but can you help explain what each of these 4 measures do?
balala wrote: April 14th, 2020, 6:04 pm
  • [MeasureString] is making a substitution of the characters of the AppName variable: each character is replaced by a 0, then finally the first 0 is replaced by an 1. This number will be used to calculate the length of the AppName variable, through the [MeasureStringLength] measure.
  • As said above the [MeasureStringLength] measure returns the length of the AppName variable as a number. It does this applying a logarithm function (Log). But unfortunately I had here to complicate a little bit the function, because if the number returned by the [MeasureString] is zero (which happens when the AppName variable is empty), the logarithm function is not defined. That's why I had to add the condition: if the value of the [MeasureString] is 0, the [MeasureStringLength] returns also 0 (this is the length of an empty string), otherwise it calculates the length of the AppName variable.
    [...]
    Unfortunately this procedure has a limit: the AppName variable must be shorter then 308 characters. Above this number the [MeasureStringLength] measure doesn't return the length of the variable. In such cases probably a .lua script file could help, but didn't tried this yet. However I hope 308 is an enough large number of characters for most cases.
Setting in [MeasureString]: Substitute=".":"+1", and in [MeasureStringLength]: Formula=( [MeasureString] ) (replacing the entire Substitute and Formula lines) will solve the 308 character limitation - no need to use Lua for every little thing that can be solved in bare Rainmeter code. This applies the advice I gave in the EDIT from the other thread to simplify the process of getting the string length, by using addition instead of logarithm. As much as I like the ingeniuous use of Log() to do this, it's impractical in this case, due to the limitation it causes.

By the way, this modification doesn't count line breaks, because the regex . character class excludes them. I let it this way, as not counting line breaks could, in many cases, be considered a "feature" and not a drawback, but if you want to count them too, all you need to do is replace the substitute with: Substitute="[\s\S]":"+1".
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
balala
Rainmeter Sage
Posts: 16164
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Typewriter Effect

Post by balala »

Yincognito wrote: April 15th, 2020, 2:50 am Setting in [MeasureString]: Substitute=".":"+1", and in [MeasureStringLength]: Formula=( [MeasureString] ) (replacing the entire Substitute and Formula lines) will solve the 308 character limitation - no need to use Lua for every little thing that can be solved in bare Rainmeter code.
Good point! :thumbup:
Didn't figure this out, but yep, it is right, it's working. You've solved this. Thanks for it.
User avatar
Yincognito
Rainmeter Sage
Posts: 7152
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Typewriter Effect

Post by Yincognito »

balala wrote: April 15th, 2020, 6:46 am Good point! :thumbup:
Didn't figure this out, but yep, it is right, it's working. You've solved this. Thanks for it.
Glad I could help. ;-)
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
balala
Rainmeter Sage
Posts: 16164
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Typewriter Effect

Post by balala »

Yincognito wrote: April 15th, 2020, 9:49 am Glad I could help. ;-)
Yep, you definitely did. A very smart solution, congratulation.
User avatar
Yincognito
Rainmeter Sage
Posts: 7152
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Typewriter Effect

Post by Yincognito »

balala wrote: April 15th, 2020, 11:29 am Yep, you definitely did. A very smart solution, congratulation.
Nah, this one is not that smart - it's just a simple addition, after all.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth