Quantcast
Channel: Rainmeter Forums
Viewing all articles
Browse latest Browse all 1836

Help: Rainmeter Skins • Re: Bar that changes color based on variable.

$
0
0
First try: This gave the bar a weird color. It's a color that I never declare or wrote anywhere in the script. Which is CYAN.

Code:

[Variables]MyAccentColorOpaque=131,192,239MyDarkAccentColorOpaque=200,60,77TheirAccentColor=#MyAccentColorOpaque#,255TheirDarkAccentColor=#MyDarkAccentColorOpaque#,255[CsCpuThrottle]Measure=CalcFormula=1[tCpu1]Meter=BARMeasureName=sCpu1X=#MySectionSpacing#RY=#MyMarginTop#W=#MyBarWidth#H=#MyHeight#BarColor=([CsCpuThrottle] == 0 ? #TheirAccentColor# : #TheirDarkAccentColor#)DynamicVariables=1SolidColor=#MyBarBackground#BarOrientation=Vertical
In Rainmeter, unlike in some programming languages, to check if the value of a measure is zero, you don't have to use the double equality (==), jut a simple one (=). Accordingly the [CsCpuThrottle] == 0 part of the Formula used into the BarColor option of the [tCpu1] meter should be [CsCpuThrottle] = 0 (see the one single equality sign).
But even so, the formula can1t work, because (once again) unlike into a programming language, Rainmeter can't work withstrings in formula. Thos formulas (like the one used into the mentioned BarColor option) should be entirely mathematic. However a color code of any type is a string in fact, so a such kind of formula doesn't work in Rainmeter.
the solution is the usage of IfConditions. This way, for instance:

Code:

[CsCpuThrottle]Measure=CalcFormula=1IfCondition=(CsCpuThrottle=0)IfTrueAction=[!SetOption tCpu1 BarColor "#TheirAccentColor#"][!UpdateMeter "tCpu1"][!Redraw]IfFalseAction=[!SetOption tCpu1 BarColor "#TheirDarkAccentColor#"][!UpdateMeter "tCpu1"][!Redraw][tCpu1]...;BarColor=([CsCpuThrottle] == 0 ? #TheirAccentColor# : #TheirDarkAccentColor#);DynamicVariables=1...
See that the BarColor of the [tCpu1] meter is set by the !SetOption bangs used into the IfTrueAction and IfFalseAction options of the [CsCpuThrottle] measure, setting the color properly. I completely commented out the BarColor and the DynamicVariables option of the meter, they don't being needed anymore. BarColor is not needed due to what I described above (it is set by the measures), while DynamicVariables is not needed because !SetOption doesn't require it (!SetVariable does require it, but !SetOption doesn't). Note that the DynamicVariables might be needed if there are some not posted parts of the code, which might contain some operations requiring it.
Then I tried this:

Code:

[CsCpuThrottle]Measure=CalcFormula=0[tCpu1]Meter=BARMeasureName=sCpu1X=#MySectionSpacing#RY=#MyMarginTop#W=#MyBarWidth#H=#MyHeight#BarColor=([CsCpuThrottle] == 0 ? 0,0,0,0 : 1,1,1,1)DynamicVariables=1SolidColor=#MyBarBackground#BarOrientation=Vertical
Same result. Weird CYAN color. Not white or black.
Same applies here as well. Strings are not allowed into mathematical formulas in Rainmeter. But one more: even if it wozuld work, you wouldn't see the result, because even if the BarColor would be set to either 0,0,0,0 or 1,1,1,1, these colors are the same. In fact there is no color: 0,0,0,0 is completely transparent black (the last above red colored part sets the transparency of the color, 0 meaning it is completely transparent), while 1,1,1,1 is practically same way transparent (its transparency is 1 from 255, which still means completely invisible). However the BarColor option can't work, due to what have been described above. You get the bar cyan, because not having a valid option for the BarColor, Rainmeter applies the default color, which is 0,128,0, so cyan.
But I don't want to manually change the value in the script whenever I wanted different accent color.
So I tried with variable:

Code:

[CsCpuThrottle]Measure=CalcFormula=0[CsCpuColor]Measure=CalcFormula=(CsCpuThrottle = 0 ? TheirAccentColor : TheirDarkAccentColor)[tCpu1]Meter=BARMeasureName=sCpu1X=#MySectionSpacing#RY=#MyMarginTop#W=#MyBarWidth#H=#MyHeight#BarColor=[CsCpuColor]DynamicVariables=1SolidColor=#MyBarBackground#BarOrientation=Vertical
Well this didn't work. It's still white. How about if I added ##
No, you didn't try with variables, because neither TheirAccentColor, nor TheirDarkAccentColor is a variable. Variables are #TheirAccentColor# and #TheirDarkAccentColor#, but as described above, you can1t use these in formulas.
But it doesn't work for tCpu2, and is ugly.
Use the IfCondition option, as described above. Did you get it working?

Statistics: Posted by balala — Yesterday, 6:40 pm



Viewing all articles
Browse latest Browse all 1836

Trending Articles