It is currently March 28th, 2024, 12:13 pm

Sliding image

Get help with creating, editing & fixing problems with skins
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Sliding image

Post by kyriakos876 »

xenium wrote:Hi
In the example below, the temperature is displayed in green, yellow or red, depending on the three temperature intervals.
I would like that when the temperature value is green and click on it, slide the green image (meter1);
when the value is yellow and click on it, slide the yellow image (meter2);
when the value is red and click on it, slide the red image (meter3)
How can I do this?

thanks

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
SkinWidth=210



[Variables]
UpdateRateSeconds=600
FontFace=arial

;green
URL=https://www.foreca.com/Canada/Nunavut/Coral_Harbour

;yellow
;URL=https://www.foreca.com/Finland/Helsinki

;red
;URL=https://www.foreca.com/Singapore/Singapore


TempColor1=0,255,0
TempColor2=255,255,0
TempColor3=255,0,0


OffSet1=210
OffSet2=210
OffSet3=210
State1=1
State2=3
State3=5
U1=[!UpdateMeasure MeasureSlider][!UpdateMeter "Meter1"][!Redraw]
U2=[!UpdateMeasure MeasureSlider][!UpdateMeter "Meter2"][!Redraw]
U3=[!UpdateMeasure MeasureSlider][!UpdateMeter "Meter3"][!Redraw]

[MeasureSlider]
Measure=Plugin
Plugin=ActionTimer
ActionList1=Repeat SlideLeft1, 2, 22 | ChangeToState2
SlideLeft1=[!SetVariable OffSet1 "(Clamp(#OffSet1#-10,0,210))"]#U1#
ChangeToState2=[!SetVariable State1 2]
ActionList2=Repeat SlideRight1, 2, 22 | ChangeToState1
SlideRight1=[!SetVariable OffSet1 "(Clamp(#OffSet1#+10,0,210))"]#U1#
ChangeToState1=[!SetVariable State1 1]

ActionList3=Repeat SlideLeft2, 2, 22 | ChangeToState4
SlideLeft2=[!SetVariable OffSet2 "(Clamp(#OffSet2#-10,0,210))"]#U2#
ChangeToState4=[!SetVariable State2 4]
ActionList4=Repeat SlideRight2, 2, 22 | ChangeToState3
SlideRight2=[!SetVariable OffSet2 "(Clamp(#OffSet2#+10,0,210))"]#U2#
ChangeToState3=[!SetVariable State2 3]

ActionList5=Repeat SlideLeft3, 2, 22 | ChangeToState6
SlideLeft3=[!SetVariable OffSet3 "(Clamp(#OffSet3#-10,0,210))"]#U3#
ChangeToState6=[!SetVariable State3 6]
ActionList6=Repeat SlideRight3, 2, 22 | ChangeToState5
SlideRight3=[!SetVariable OffSet3 "(Clamp(#OffSet3#+10,0,210))"]#U3#
ChangeToState5=[!SetVariable State3 5]

DynamicVariables=1



[MeasureTemp]
Measure=WebParser
Url=#URL#
RegExp="(?siU)<span class=".* txt-xxlarge"><strong>(.*)</strong>.*"
UpdateRate=#UpdateRateSeconds#
StringIndex=1

[MeasureColor]
Measure=Calc
Formula=(((MeasureTemp >= -15) && (MeasureTemp < 0)) ? 1 : (((MeasureTemp >= 0) && (MeasureTemp <= 15)) ? 2 : 3))

========================================

[BG]
Meter=Image
SolidColor=0,0,0,100
X=0
Y=0
W=210
H=260

[Meter1]
Meter=Image
SolidColor=0,255,0
X=#OffSet1#
Y=20
W=203
H=240
DynamicVariables=1

[Meter2]
Meter=Image
SolidColor=255,255,0
X=#OffSet2#
Y=20
W=203
H=240
DynamicVariables=1

[Meter3]
Meter=Image
SolidColor=255,0,0
X=#OffSet3#
Y=20
W=203
H=240
DynamicVariables=1

[MeterTemp]
Meter=String
MeasureName=MeasureTemp
X=70
Y=185
W=100
H=100
FontColor=[#TempColor[&MeasureColor]]
StringStyle=bold
StringEffect=SHADOW
FontFace=arial
StringAlign=Left
FontEffectColor=0,0,0,80
AntiAlias=1
ClipString=1
FontSize=15
Postfix="°C"
DynamicVariables=1
LeftMouseUpAction=[!CommandMeasure MeasureSlider "Execute [#state[&MeasureColor]]"]
Basically all I did was rename StateA, StateB, StateC to State1, State2, state3 respectively and change the mouse action from
LeftMouseUpAction=[!CommandMeasure MeasureSlider "Execute #StateA#"]
to
LeftMouseUpAction=[!CommandMeasure MeasureSlider "Execute [#state[&MeasureColor]]"]

(Don't forget to change them on the [MeasureSlider] as well.)

By the way, unless you WANT to have 3 meters for each color, you can always have 1 meter with the color set as a variable.

Also consider adding a [!Stop ....] command in your mouse action for instant response when clicking fast.

Something like:

LeftMouseUpAction=[!CommandMeasure MeasureSlider "Stop 1"][!CommandMeasure MeasureSlider "Execute 2"]
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5380
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA
Contact:

Re: Sliding image

Post by eclectic-tech »

A different solution could be to add IfConditions to your [MeasureColor] to change the click action.

Code: Select all

[MeasureColor]
Measure=Calc
Formula=(((MeasureTemp >= -15) && (MeasureTemp < 0)) ? 1 : (((MeasureTemp >= 0) && (MeasureTemp <= 15)) ? 2 : 3))

; Change click action based on temp value
IfCondition=((MeasureTemp >= -15) && (MeasureTemp < 0))
IfTrueAction=[!SetOption MeterTemp LeftMouseUpAction """[!CommandMeasure MeasureSlider "Execute #*StateA*#"]"""]
IfCondition2=((MeasureTemp >= 0) && (MeasureTemp <= 15))
IfTrueAction2=[!SetOption MeterTemp LeftMouseUpAction """[!CommandMeasure MeasureSlider "Execute #*StateB*#"]"""]
IfCondition3=(MeasureTemp > 15)
IfTrueAction3=[!SetOption MeterTemp LeftMouseUpAction """[!CommandMeasure MeasureSlider "Execute #*StateC*#"]"""]


kyriakos876's suggestion to add a stop action is valid if you want additional clicks to override current actions.
It depends on how you want the slide actions to work; you may end up with a partially slid meter...

The change of renaming the StateA/B/C variables may have some adverse effects on your other commands to slide meters.

Try either this, or kyriakos876's suggestion and see what works best for your desired result. :???:
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Sliding image

Post by balala »

xenium wrote:In the example below, the temperature is displayed in green, yellow or red, depending on the three temperature intervals.
I would like that when the temperature value is green and click on it, slide the green image (meter1);
when the value is yellow and click on it, slide the yellow image (meter2);
when the value is red and click on it, slide the red image (meter3)
How can I do this?
But there are really needed three different meters ([Meter1], [Meter2] and [Meter3])? Because instead I probably would use one single image and would change its color, according to the temperature (same way as you're changing the color of the [MeterTemp] String meter). Wouldn't be this a much simpler solution?
User avatar
xenium
Posts: 841
Joined: January 4th, 2018, 9:52 pm

Re: Sliding image

Post by xenium »

kyriakos876, eclectic-tech
thank you very much, both solutions work, it remains to see that I will use.
balala wrote:But there are really needed three different meters ([Meter1], [Meter2] and [Meter3])? Because instead I probably would use one single image and would change its color, according to the temperature (same way as you're changing the color of the [MeterTemp] String meter). Wouldn't be this a much simpler solution?
You are perfectly right, but I used colorful images just for this example,the skin will have different images for each color temperature.
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Sliding image

Post by balala »

xenium wrote:You are perfectly right, but I used colorful images just for this example,the skin will have different images for each color temperature.
Which also can be set dynamically, depending on the temperature. You just need to add more IfConditions.
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Sliding image

Post by kyriakos876 »

balala wrote:...You just need to add more IfConditions.
Not necessarily, this can be also done by playing around with the variables and the names of the images if you want to avoid IfConditions.
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Sliding image

Post by balala »

kyriakos876 wrote:Not necessarily, this can be also done by playing around with the variables and the names of the images if you want to avoid IfConditions.
Yeah, probably you're right and playing around with the variables is another possibility. However I'm not sure why to avoid the IfConditions. What's wrong with them?
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Sliding image

Post by kyriakos876 »

Well it comes down to personal reference at this point, as both solutions work the same, but I just like my code as few lines as possible. :)
Post Reply