It is currently April 18th, 2024, 4:49 am

Automatic Color Change.

Get help with creating, editing & fixing problems with skins
bill98
Posts: 445
Joined: March 17th, 2011, 4:54 am

Automatic Color Change.

Post by bill98 »

I think I already know the answer to this, but I am still wishing for a good one. I have text on top of a colored object. The objects color can change as the data changes. When the object color is dark, is there a way to automatically change the text to a light color and vice versa?
User avatar
balala
Rainmeter Sage
Posts: 16143
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Automatic Color Change.

Post by balala »

Depends on how the color of the colored object is determined. Eg for an image meter with a solid color, you could determine the sum of the three colors (red, green and blue) and use a dark text if the sum is above 382 ((255+255+255)/2) and a light one if the sum is below 382.
This code works this way:

Code: Select all

[Rainmeter]
Update=1000

[MeasureRed]
Measure=Calc
Formula=Random
LowBound=0
HighBound=255
UpdateRandom=1

[MeasureGreen]
Measure=Calc
Formula=Random
LowBound=0
HighBound=255
UpdateRandom=1

[MeasureBlue]
Measure=Calc
Formula=Random
LowBound=0
HighBound=255
UpdateRandom=1

[MeasureColor]
Measure=Calc
Formula=( MeasureRed + MeasureGreen + MeasureBlue )
IfCondition=(MeasureColor>382)
IfTrueAction=[!SetOption MeterColor FontColor "25,25,25"][!SetOption MeterColor FontEffectColor "200,200,200"]
IfFalseAction=[!SetOption MeterColor FontColor "200,200,200"][!SetOption MeterColor FontEffectColor "25,25,25"]

[MeterBackground]
Meter=Image
X=0
Y=0
W=100
H=100
SolidColor=[MeasureRed],[MeasureGreen],[MeasureBlue]
DynamicVariables=1
LeftMouseUpAction=[!TogglePauseMeasure MeasureRed][!TogglePauseMeasure MeasureGreen][!TogglePauseMeasure MeasureBlue]

[MeterColor]
Meter=STRING
MeasureName=MeasureRed
MeasureName2=MeasureGreen
MeasureName3=MeasureBlue
MeasureName4=MeasureColor
X=50
Y=50
StringEffect=Shadow
FontSize=10
FontFace=Segoe UI
StringStyle=BOLD
StringAlign=CENTERCENTER
AntiAlias=1
Text=%1, %2, %3#CRLF#%4
But I think there's no possibility to do something similar if you're using images, because you can't determine how dark or light the image is.
bill98
Posts: 445
Joined: March 17th, 2011, 4:54 am

Re: Automatic Color Change.

Post by bill98 »

Interesting, I never thought of anything like that. Assuming I have a color like 200,0,155,255, how do I go about breaking it down to individual parts and summing them up?
User avatar
balala
Rainmeter Sage
Posts: 16143
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Automatic Color Change.

Post by balala »

bill98 wrote:Interesting, I never thought of anything like that. Assuming I have a color like 200,0,155,255, how do I go about breaking it down to individual parts and summing them up?
If you're using a SolidColor=200,0,155,255 on any meter, I think, you can't, but instead of using it this way, in the above example code, you could add a Color variable:

Code: Select all

[Variables]
Color=200,0,155,255
then use this color code on the meters you need it (SolidColor=#Color#).
Now you can use RegExpSubstitute to get the parts of the color code:

Code: Select all

[MeasureRed]
Measure=String
String=#Color#
RegExpSubstitute=1
Substitute="^(.*),(.*),(.*),(.*)$":"\1"

[MeasureGreen]
Measure=String
String=#Color#
RegExpSubstitute=1
Substitute="^(.*),(.*),(.*),(.*)$":"\2"

[MeasureBlue]
Measure=String
String=#Color#
RegExpSubstitute=1
Substitute="^(.*),(.*),(.*),(.*)$":"\3"
If you're using these substitutions, you have to modify the Formula on your [MeasureColor] measure to: Formula=( [MeasureRed] + [MeasureGreen] + [MeasureBlue] ) and also add to the same section the DynamicVariables=1 option.
User avatar
balala
Rainmeter Sage
Posts: 16143
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Automatic Color Change.

Post by balala »

Or, instead of the substitutions I posted above, you could try these:
Substitute="^(\d*),(\d*),(\d*)(,\d*)?$":"\1" on [MeasureRed], Substitute="^(\d*),(\d*),(\d*)(,\d*)?$":"\2" on [MeasureGreen] and Substitute="^(\d*),(\d*),(\d*)(,\d*)?$":"\3" on [MeasureBlue]. This ensures you that both types of color codes (with and without transparency or alpha value) will work.
bill98
Posts: 445
Joined: March 17th, 2011, 4:54 am

Re: Automatic Color Change.

Post by bill98 »

Ok, I am trying to use this with JSMoreley's RainRGB4 color change program and make the text light for dark Coors and vice versa. Rather than include all this code for each of 60 some colors, is there a way to make a "subroutine" type of skin that can be called to work with each color? Thanks for your patience!
User avatar
balala
Rainmeter Sage
Posts: 16143
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Automatic Color Change.

Post by balala »

bill98 wrote:Ok, I am trying to use this with JSMoreley's RainRGB4 color change program and make the text light for dark Coors and vice versa. Rather than include all this code for each of 60 some colors, is there a way to make a "subroutine" type of skin that can be called to work with each color? Thanks for your patience!
As far as I know, you can't have subroutines in Rainmeter. You can move the measures into an .inc file, but that's not a subroutine and you have to write all those measures, just you don't place them in your skin's .ini file.
bill98
Posts: 445
Joined: March 17th, 2011, 4:54 am

Re: Automatic Color Change.

Post by bill98 »

Having a problem with implementation. Here is the meter that stores the background color, Refreshes the RGBTLD to change the FontColor, and calls RainRGB4.

[MeterChangeBackgroundColor]
Meter=String
X=r
Y=45R
W=200
H=20
FontSize=12
FontColor=#TFC#
StringStyle=Italic
SolidColor=#TitleBG2#
Padding=3,3,0,0
AntiAlias=1
Text=CHG BG #TitleBG2#
LeftMouseUpAction=[!WriteKeyValue Variables BGC #TitleBG2# #@#VariablesM2.inc][!ReFresh RGBLD\RGBTLD.ini]["#@#Addons\RainRGB\RainRGB4.exe" "VarName=TitleBG2" "FileName=#@#Scheme#CSNO#.inc" "RefreshConfig=#CURRENTCONFIG#"]

The background color BGC stores ok, but the RGBLD\RGBTLD.ini skin does not seem to execute. Here is the RGBLD\RGBTLD.ini skin:


[Rainmeter]
Update=1000


;Formula=( [MeasureRed] + [MeasureGreen] + [MeasureBlue] )
DynamicVariables=1

[Variables]
@Include=#@#VariablesM2.inc
@Include2=#@#Scheme#CSNO#.inc



[MeasureRed]
Measure=String
String=#BGC#
RegExpSubstitute="^(.*),(.*),(.*),(.*)$":"\1"

[MeasureGreen]
Measure=String
String=#BGC#
RegExpSubstitute="^(.*),(.*),(.*),(.*)$":"\2"

[MeasureBlue]
Measure=String
String=#BGC#
RegExpSubstitute="^(.*),(.*),(.*),(.*)$":"\3 "


[MeasureColor]
Measure=Calc
Formula=( MeasureRed + MeasureGreen + MeasureBlue )
IfCondition=(MeasureColor>382)
IfTrueAction=[!WriteKeyValue Variables TFC "20,20,20" #@#ICONS\VariablesM2.inc]
IfFalseAction=[!WriteKeyValue Variables TFC "255,255,255" #@#ICONS\VariablesM2.inc]

The skin directory structure is attached.
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 16143
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Automatic Color Change.

Post by balala »

Try to change the [MeasureColor] section to this:

Code: Select all

[MeasureColor]
Measure=Calc
Formula=( [MeasureRed] + [MeasureGreen] + [MeasureBlue] )
DynamicVariables=1
IfCondition=(MeasureColor>382)
IfTrueAction=[!WriteKeyValue Variables TFC "20,20,20" #@#ICONS\VariablesM2.inc]
IfFalseAction=[!WriteKeyValue Variables TFC "255,255,255" #@#ICONS\VariablesM2.inc]
See the difference between your formula and this one. Also added DynamicVariables=1.
On [MeasureColor] section you're using twice the !WriteKeyValue bang. This will modify the TFC variable, but it won't have effect until a refresh. To determine this, you'll have to use the !SetVariable bang, too. Also, in the !WriteKeyValue bang include the file path and name into quote marks.

Code: Select all

IfTrueAction=[!WriteKeyValue Variables TFC "20,20,20" "#@#ICONS\VariablesM2.inc"][!SetVariable TFC "20,20,20"]
IfFalseAction=[!WriteKeyValue Variables TFC "255,255,255" "#@#ICONS\VariablesM2.inc"][!SetVariable TFC "255,255,255"]
I also sugested another substitution.
Another minor thing about your code: you can't use DynamicVariables=1 into the [Rainmeter] section.
bill98
Posts: 445
Joined: March 17th, 2011, 4:54 am

Re: Automatic Color Change.

Post by bill98 »

I updated per your suggestions and even added SetVariable and more Refreshes, but it still will not change TFC. Have I misinterpreted something or what? I have also refreshed the skin manually. Here is a copy of the new RGBTLD file.


[Rainmeter]
Update=1000

[Variables]
@Include=#@#VariablesM2.inc
@Include2=#@#Scheme#CSNO#.inc

[MeasureRed]
Measure=String
String=#BGC#
RegExpSubstitute="^(\d*),(\d*),(\d*)(,\d*)?$":"\1"

[MeasureGreen]
Measure=String
String=#BGC#
RegExpSubstitute="^(\d*),(\d*),(\d*)(,\d*)?$":"\2"

[MeasureBlue]
Measure=String
String=#BGC#
RegExpSubstitute="^(\d*),(\d*),(\d*)(,\d*)?$":"\3"

[MeasureColor]
Measure=Calc
Formula=( [MeasureRed] + [MeasureGreen] + [MeasureBlue] )
DynamicVariables=1
IfCondition=(MeasureColor>382)
IfTrueAction=[!WriteKeyValue Variables TFC "0,0,0" "#@#ICONS\VariablesM2.inc"][!SetVariable TFC "0,0,0"][!ReFresh]
IfFalseAction=[!WriteKeyValue Variables TFC "255,255,255" #@#ICONS\VariablesM2.inc"][!SetVariable TFC "255,255,255"][!ReFresh]

[ShowTFC]
Meter=String
FontColor=0,0,0,255
FontSize=16
x=1
y=1
Text=BGC=#BGC#, TFC=#TFC#,#CRLF#
DynamicVariables=1