It is currently April 26th, 2024, 3:26 am

Change image tint depening on the battery level

Get help with creating, editing & fixing problems with skins
User avatar
100krotka
Posts: 7
Joined: July 30th, 2019, 11:33 am

Change image tint depening on the battery level

Post by 100krotka »

Hi there! I am just discovering rainmeter and it's great.

I was trying to make a widget depening on the battery level.
In my vars.inc file I have the saved colors named RED, ORANGE etc.
Picking the colors from file are working, I tested out that with mouseover function

Code: Select all

MouseOverAction=[!SetOption DOTS1 imagetint #RED#]
But...

An image has to appear when it is on the battery and disappear when plugged in (That's working).
What's more I need it to change the color when the battery level is below some level e.g. 50% (That's not working)

Image
Horizontal 5 dots
The battery percentage and plugged in status are calculated correctly imo as shown in the picture.


There's my code:

Code: Select all

[Rainmeter]
Update=1000

[Variables]
@Include1=#ROOTCONFIGPATH#\Resources\vars.inc

[MeasurePercent]
Measure=Plugin
PlugIn=PowerPlugin
PowerState=PERCENT

[MeasureACLine]
Measure=Plugin
PlugIn=PowerPlugin
PowerState=ACLINE
Substitute="0","1"

IfCondition= (#CURRENTSECTION#=1)
IfTrueAction=[!HideMeter DOTS1]
IfFalseAction=[!ShowMeter DOTS1]

[DOTS1]
Meter=image
x=100
y=0
imagename=#currentpath#\resources\images\1BatteryON.png

IfCondition=(MeasurePercent>50)
IfTrueAction=[!SetOption DOTS1 imagetint #YELLOW#]
IfFalseAction=[!SetOption DOTS1 imagetint #RED#]

I tried this way and stucked :uhuh:
I am looking forward to your answers :)
Last edited by 100krotka on July 30th, 2019, 12:18 pm, edited 1 time in total.
User avatar
jsmorley
Developer
Posts: 22630
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Change image tint depening on the battery level

Post by jsmorley »

You can't put an IfCondition on a meter, it must be on a measure. If you move the IfCondition and the matching actions up to [MeasurePercent], I think you will get what you want.

Code: Select all

[Rainmeter]
Update=1000

[Variables]
@Include1=#ROOTCONFIGPATH#\Resources\vars.inc

[MeasurePercent]
Measure=Plugin
PlugIn=PowerPlugin
PowerState=PERCENT
IfCondition=MeasurePercent>50
IfTrueAction=[!SetOption DOTS1 ImageTint #YELLOW#][!UpdateMeter DOTS1][!Redraw]
IfFalseAction=[!SetOption DOTS1 ImageTint #RED#][!UpdateMeter DOTS1][!Redraw]

[MeasureACLine]
Measure=Plugin
PlugIn=PowerPlugin
PowerState=ACLINE
Substitute="0","1"
IfCondition=#CURRENTSECTION#=1
IfTrueAction=[!HideMeter DOTS1]
IfFalseAction=[!ShowMeter DOTS1]

[DOTS1]
Meter=Image
X=100
Y=0
ImageName=#CURRENTPATH#\resources\images\1BatteryON.png
User avatar
100krotka
Posts: 7
Joined: July 30th, 2019, 11:33 am

Re: Change image tint depening on the battery level

Post by 100krotka »

Oh!
That's working, I put that IF in the incorrect measure.

Thank you so much C:
User avatar
jsmorley
Developer
Posts: 22630
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Change image tint depening on the battery level

Post by jsmorley »

100krotka wrote: July 30th, 2019, 12:25 pm Oh!
That's working, I put that IF in the incorrect measure.

Thank you so much C:
Glad to help.
User avatar
jsmorley
Developer
Posts: 22630
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Change image tint depening on the battery level

Post by jsmorley »

One side-note I might mention...

I think you will find that if you use the built-in @Resources approach to this, you will find it of some value.

You have a folder called "Resources" under the root config of your skin. Then you are variously accessing it with #ROOTCONFIGPATH#\Resources\vars.inc and also #CURRENTPATH#\resources\images\1BatteryON.png.

If you instead created a folder called "@Resources" under the root config of your skin, you can more easily, and more consistently access it with #@#vars.inc and #@#Images\1BatteryON.png.

https://docs.rainmeter.net/manual/skins/resources-folder/
User avatar
100krotka
Posts: 7
Joined: July 30th, 2019, 11:33 am

Re: Change image tint depening on the battery level

Post by 100krotka »

You're right, that's a simple way.

I have one more question.
In your code above there are only 2 states (above 50% and below).
What's the fastest way to add more states. (In c++ I am using elseif)

I see that there's a way of using many Ifconditions e.g. IfCondition, IfCondition2 ...
Is it the only way?
User avatar
jsmorley
Developer
Posts: 22630
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Change image tint depening on the battery level

Post by jsmorley »

100krotka wrote: July 30th, 2019, 12:51 pm You're right, that's a simple way.

I have one more question.
In your code above there are only 2 states (above 50% and below).
What's the fastest way to add more states. (In c++ I am using elseif)

The really isn't any if/then/elseif/then/else procedural construct in Rainmeter, but you can do something like:

Code: Select all

[MeasurePercent]
Measure=Plugin
PlugIn=PowerPlugin
PowerState=PERCENT
IfCondition=MeasurePercent < 25
IfTrueAction=[!SetOption DOTS1 ImageTint #RED#][!UpdateMeter DOTS1][!Redraw]
IfCondition2=(MeasurePercent >= 25) && (MeasurePercent < 50)
IfTrueAction2=[!SetOption DOTS1 ImageTint #YELLOW#][!UpdateMeter DOTS1][!Redraw]
IfCondition3=(MeasurePercent >= 50) && (MeasurePercent < 75)
IfTrueAction3=[!SetOption DOTS1 ImageTint #BLUE#][!UpdateMeter DOTS1][!Redraw]
IfCondition4=MeasurePercent >= 75
IfTrueAction4=[!SetOption DOTS1 ImageTint #GREEN#][!UpdateMeter DOTS1][!Redraw]
So in effect you have the IfCondition/Action pairs "fall though" as they succeed or fail. Unlike an if/then/else/then construct in C++, there is no concept of a "break". All the IfCondition(N) statements will be evaluated, and you must ensure that only one of them can be true, or that the possible true conditions are in the correct order so that the "last" true one is the one you want. All true actions will be fired...

I don't have any IfFalseAction(s), as at least (and at most) one of these must succeed...

The same things is true of IfFalseAction(s), any action that is false will be fired...

Code: Select all

[MeasurePercent]
Measure=Plugin
PlugIn=PowerPlugin
PowerState=PERCENT
IfCondition=MeasurePercent < 25
IfTrueAction=[!SetOption DOTS1 ImageTint #RED#][!UpdateMeter DOTS1][!Redraw]
IfFalseAction=[!Log "I'm NOT less than 25"]
IfCondition2=(MeasurePercent >= 25) && (MeasurePercent < 50)
IfTrueAction2=[!SetOption DOTS1 ImageTint #YELLOW#][!UpdateMeter DOTS1][!Redraw]
IfFalseAction2=[!Log "I'm NOT greater than or equal to 25 and less than 50"]
IfCondition3=(MeasurePercent >= 50) && (MeasurePercent < 75)
IfTrueAction3=[!SetOption DOTS1 ImageTint #BLUE#][!UpdateMeter DOTS1][!Redraw]
IfFalseAction3=[!Log "I'm NOT greater than or equal to 50 and less than 75"]
IfCondition4=MeasurePercent >= 75
IfTrueAction4=[!SetOption DOTS1 ImageTint #GREEN#][!UpdateMeter DOTS1][!Redraw]
IfFalseAction4=[!Log "I'm NOT greater than 75"]
In this case, only one of the "true" actions WILL be fired, and only one of the "false" actions will NOT be fired.
User avatar
100krotka
Posts: 7
Joined: July 30th, 2019, 11:33 am

Re: Change image tint depening on the battery level

Post by 100krotka »

jsmorley wrote: July 30th, 2019, 12:56 pm So in effect you have the IfCondition/Action pairs "fall though" as they succeed or fail. Unlike an if/then/else/then construct in C++, there is no concept of a "break". All the IfCondition(N) statements will be evaluated, and you must ensure that only one of them can be true, or that the possible true conditions are in the correct order so that the "last" true one is the one you want. All true actions will be fired...
That's what I thought :)


I am also thinking of a state when the battery is fully charged and a charger still plugged in

Code: Select all

[MeasurePercent]
(...)
IfCondition=(MeasurePercent=100) && (MeasureACLine=1)
IfTrueAction (...)
I tried pasting this, but I know I did something wrong.
How do I get that info is it plugged in and use it with a battery percentage?
User avatar
jsmorley
Developer
Posts: 22630
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Change image tint depening on the battery level

Post by jsmorley »

100krotka wrote: July 30th, 2019, 1:27 pm That's what I thought :)


I am also thinking of a state when the battery is fully charged and a charger still plugged in

Code: Select all

[MeasurePercent]
(...)
IfCondition=(MeasurePercent=100) && (MeasureACLine=1)
IfTrueAction (...)
I tried pasting this, but I know I did something wrong.
How do I get that info is it plugged in and use it with a battery percentage?
Not sure. That looks ok to me.
User avatar
jsmorley
Developer
Posts: 22630
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Change image tint depening on the battery level

Post by jsmorley »

100krotka wrote: July 30th, 2019, 1:27 pm That's what I thought :)


I am also thinking of a state when the battery is fully charged and a charger still plugged in

Code: Select all

[MeasurePercent]
(...)
IfCondition=(MeasurePercent=100) && (MeasureACLine=1)
IfTrueAction (...)
I tried pasting this, but I know I did something wrong.
How do I get that info is it plugged in and use it with a battery percentage?
Ah, I see. You are evaluating the numeric value of MeasureACLine, but are assuming that the Substitute you have on it will impact that. It won't. Substitute only changes the string value of a measure. You might try:

Code: Select all

[MeasurePercent]
(...)
IfCondition=(MeasurePercent=100) && ([MeasureACLine]=1)
IfTrueAction (...)
DynamicVariables=1
Using the section variable [MeasureACLine] will use the string value of the measure, and as long as the string is numeric in nature, the IfCondition will be fine with that. You need DynamicVariables=1 on the measure to use [SectionVariables] in it.

Sorry that I'm on a desktop, and can't fully test with PowerPlugin.