Page 1 of 1

Changing color with a substitute

Posted: June 1st, 2010, 2:53 am
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.

Re: Changing color with a substitute

Posted: June 1st, 2010, 3:03 am
by jsmorley
Good tip. Also, the same can be accomplished with image meters by using ImageTint in place of FontColor.

Re: Changing color with a substitute

Posted: June 1st, 2010, 3:04 am
by smurfier
That's actually what I did with my example skin.

Re: Changing color with a substitute

Posted: August 1st, 2010, 12:19 am
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"

Re: Changing color with a substitute

Posted: August 2nd, 2010, 6:38 pm
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"

Re: Changing color with a substitute

Posted: August 18th, 2010, 11:28 pm
by burnwell88
Thx man .... good work :)