It is currently March 28th, 2024, 11:54 pm

Changing color with a substitute

Tips and Tricks from the Rainmeter Community
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Changing color with a substitute

Post by smurfier »

There are many methods to change a meters color and there have been several discussions on which is the best method. All of these discussions have skipped over one of the easier ways. Using a Calc measure and a Substitute one can have 31 color options.

First measure something:

Code: Select all

[msBattery]
Measure=Plugin
Plugin=Plugins/PowerPlugin.dll
PowerState=Percent
Then set up you Calc Measure:

Code: Select all

[msTint]
Measure=Calc
Formula=msBattery>50 ? -1 :((msBattery<51) && (msBattery>25) ? -2 : -3)
Substitute="-1":"111,198,111,255","-2":"215,215,109,255","-3":"190,19,19,255"
It is best to use negative numbers for your values in the formula since they do not occur in color codes. Since you can have up to 30 nested conditional statement, it is possible to have 31 color codes including the last "else" statement.

Code: Select all

[mtBattery]
Meter=String
MeasureName=msBattery
Text="There is %1% remaining."
FontColor=[msTint]
DynamicVariables=1
Note: It is important to leave the value given by the measure as is and not remove the decimal with a substitute. For some reason, removing the ".0" disables the alpha value.
Last edited by smurfier on October 9th, 2011, 5:16 am, edited 3 times in total.
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Changing color with a substitute

Post by jsmorley »

Good tip. Also, the same can be accomplished with image meters by using ImageTint in place of FontColor.
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Changing color with a substitute

Post by smurfier »

That's actually what I did with my example skin.
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
User avatar
Scolex
Posts: 111
Joined: July 31st, 2010, 8:52 am

Re: Changing color with a substitute

Post by Scolex »

I tries using this and was able to get it to work with a line graph but could not figure out how to get it to work with a histogram.
The skin I am trying to modify is the HUD CPU1 meter.
Where am I going wrong, I am a newb so bare with me.
Here is what I have.

Code: Select all

[MeasureCPU1]
Measure=Plugin
Plugin=Plugins\PerfMon.dll
PerfMonObject="Processor"
PerfMonInstance=0
PerfMonCounter="% Processor Time"
PerfMonDifference=1
InvertMeasure=1

[msTint]
Measure=Calc
Formula=MeasureCPU1>80 ? -1 :((MeasureCPU1<81) && (MeasureCPU1>30) ? -2 : -3)
Substitute="-1":"255,0,0,75","-2":"0,255,0,75","-3":"0,0,255,75"

[msTint2]
Measure=Calc
Formula=MeasureCPU1>80 ? -1 :((MeasureCPU1<81) && (MeasureCPU1>30) ? -2 : -3)
Substitute="-1":"255,0,0,37","-2":"0,255,0,37","-3":"0,0,255,37"

[msVarSet]
Measure=Calc
Formula=MeasureCPU1<>(-1)
IfEqualValue=1
IfEqualAction=!RainmeterSetVariable Color msTint

[CPU1Graph1]
Meter=Line
MeasureName=MeasureCPU1
X=0
Y=4
H=43
W=180
LineCount=1
LineColor=[msTint]
DynamicVariables=1
AntiAlias=1

[CPU1Graph2]
Meter=HISTOGRAM
MeasureName=MeasureCPU1
X=0r
Y=0r
H=42
W=180
PrimaryColor=[msTint2]
DynamicVariables=1
AntiAlias=1

[l.str]
Meter=STRING
X=5
Y=43r
StringStyle=NORMAL
StringAlign=LEFT
FontColor=#fontColor.Text#
FontSize=#FontHeight#
FontFace=#FontName#
AntiAlias=1
Text="CPU 1"
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Changing color with a substitute

Post by smurfier »

You forgot about dynamic variables in one of your measures. Also, as with the bar meter, we may not be able to use dynamic variables with a line or histogram meter. This may require some trial and error, but I applaud you for seeing that you can set the color value to a variable using another measure.

Code: Select all

[MeasureCPU1]
Measure=Plugin
Plugin=Plugins\PerfMon.dll
PerfMonObject="Processor"
PerfMonInstance=0
PerfMonCounter="% Processor Time"
PerfMonDifference=1
InvertMeasure=1

[msTint]
Measure=Calc
Formula=MeasureCPU1>80 ? -1 :(MeasureCPU1>30 ? -2 : -3)
;^removed a redundancy
Substitute="-1":"255,0,0,75","-2":"0,255,0,75","-3":"0,0,255,75"

[msTint2]
Measure=Calc
Formula=MeasureCPU1>80 ? -1 :(MeasureCPU1>30 ? -2 : -3)
;^removed the same redundancy
Substitute="-1":"255,0,0,37","-2":"0,255,0,37","-3":"0,0,255,37"

[msVarSet]
Measure=Calc
Formula=MeasureCPU1<>(-1)
IfEqualValue=1
IfEqualAction=!RainmeterSetVariable Color [msTint]
DynamicVariables=1
;^you need to use dynamic variables

[CPU1Graph1]
Meter=Line
MeasureName=MeasureCPU1
X=0
Y=4
H=43
W=180
LineCount=1
LineColor=[msTint]
DynamicVariables=1
AntiAlias=1

[CPU1Graph2]
Meter=HISTOGRAM
MeasureName=MeasureCPU1
X=r
;You don't reed a zero before the r. a number is only necessary if you want to add or subtract from the coordinates of the previous meter.
Y=r
H=42
W=180
PrimaryColor=[msTint2]
DynamicVariables=1
AntiAlias=1

[l.str]
Meter=STRING
X=5
Y=43r
StringStyle=NORMAL
StringAlign=LEFT
FontColor=#fontColor.Text#
FontSize=#FontHeight#
FontFace=#FontName#
AntiAlias=1
Text="CPU 1"
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
burnwell88
Posts: 90
Joined: August 13th, 2009, 8:37 am

Re: Changing color with a substitute

Post by burnwell88 »

Thx man .... good work :)