It is currently April 27th, 2024, 10:16 am

Change meter position(area)

Get help with creating, editing & fixing problems with skins
BorisLFC
Posts: 6
Joined: March 15th, 2024, 9:31 am

Change meter position(area)

Post by BorisLFC »

Hi. I need some help. I have this code
[MeasureX]
Measure=Calc
Formula=Random
LowBound=0
HighBound=(#SCREENAREAWIDTH#-#CURRENTCONFIGWIDTH#)
UpdateRandom=1
UpdateDivider=-1
DynamicVariables=1
Group=Position

[MeasureY]
Measure=Calc
Formula=Random
LowBound=0
HighBound=(#SCREENAREAHEIGHT#-#CURRENTCONFIGHEIGHT#)
UpdateRandom=1
UpdateDivider=-1
DynamicVariables=1
Group=Position

[MeasureTimer]
Measure=Calc
Formula=( COUNTER % 10 )
IfCondition=(#CURRENTSECTION#=0)
IfTrueAction=[!UpdateMeasureGroup "Position"][!Move "[MeasureX]" "[MeasureY]"]
It randomly moves a meter wherever on desktop. What i want to achieve is my centered skin only moves in an area, not the whole desktop, for example a 300px area, centrally. Can this be done? Im at a loss.
User avatar
SilverAzide
Rainmeter Sage
Posts: 2611
Joined: March 23rd, 2015, 5:26 pm

Re: Change meter position(area)

Post by SilverAzide »

BorisLFC wrote: March 15th, 2024, 9:39 am Hi. I need some help. I have this code

It randomly moves a meter wherever on desktop. What i want to achieve is my centered skin only moves in an area, not the whole desktop, for example a 300px area, centrally. Can this be done? Im at a loss.
Have you tried changing the LowBound and HighBound options to the range you want?
Gadgets Wiki GitHub More Gadgets...
BorisLFC
Posts: 6
Joined: March 15th, 2024, 9:31 am

Re: Change meter position(area)

Post by BorisLFC »

Hi. Thx for the reply. I tried that and skin was moving in the top left area of the screen. I'll give it another go when i get home. I dont want to ditch rainmeter because of oled monitor, but dont want to risk it with static positions either.
User avatar
balala
Rainmeter Sage
Posts: 16176
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Change meter position(area)

Post by balala »

BorisLFC wrote: March 15th, 2024, 9:39 am It randomly moves a meter wherever on desktop. What i want to achieve is my centered skin only moves in an area, not the whole desktop, for example a 300px area, centrally. Can this be done?
Definitely possible, but we need the whole code. I'd like to see what and how are you moving. So post the whole code please.
BorisLFC wrote: March 15th, 2024, 1:55 pm I dont want to ditch rainmeter because of oled monitor, but dont want to risk it with static positions either.
You're not risking anything, new monitors (the OLED monitors for instance, but not just) have no such problems. However what you ask can be done. But as said above, I'd like to see the code for first.
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5407
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Change meter position(area)

Post by eclectic-tech »

To restrict the skin to a central position and limit how far off center it moves from that point, look at this example.

It uses mostly your original code with a few variables added to set positions and limits, an OnRefreshAction to initially position the skin, clamps on the Lowbounds and Highbounds to prevent going off your screen, and a dummy shape meter as the skin content.

It repositions the skin every 10 seconds around the center point and displays the current upper left skin corner coordinates in the shape center.

Code: Select all

[Rainmeter]
OnRefreshAction=[!Move "[MeasureX]" "[MeasureY]"]

[Variables]
StepRate=10
XCenterPosition=(#SCREENAREAWIDTH#*0.5)
YCenterPosition=(#SCREENAREAHEIGHT#*0.5)
OffCenterMax=300

[MeasureX]
Measure=Calc
Formula=Random
LowBound=(Clamp(#XCenterPosition#-#OffCenterMax#,0,#XCenterPosition#))
HighBound=(Clamp(#XCenterPosition#+#OffCenterMax#-#CURRENTCONFIGWIDTH#,#XCenterPosition#,#SCREENAREAWIDTH#-#CURRENTCONFIGWIDTH#))
UpdateRandom=1
UpdateDivider=-1
DynamicVariables=1
Group=Position

[MeasureY]
Measure=Calc
Formula=Random
LowBound=(Clamp(#YCenterPosition#-#OffCenterMax#,0,#YCenterPosition#))
HighBound=(Clamp(#YCenterPosition#+#OffCenterMax#-#CURRENTCONFIGHEIGHT#,#YCenterPosition#,#SCREENAREAHEIGHT#-#CURRENTCONFIGHEIGHT#))
UpdateRandom=1
UpdateDivider=-1
DynamicVariables=1
Group=Position

[MeasureTimer]
Measure=Calc
Formula=( COUNTER % #StepRate# )
IfCondition=(#CURRENTSECTION#=0)
IfTrueAction=[!UpdateMeasureGroup "Position"][!Move "[MeasureX]" "[MeasureY]"]

[MeterImage]
Meter=Shape
X=2
Y=2
Shape=Rectangle 1,1,200,200,4 | StrokeWidth 2 | Fill Color 244,220,100
DynamicVariables=1

[Location]
Meter=String
MeasureName=MeasureX
MeasureName2=MeasureY
StringAlign=CenterCenter
StringStyle=Bold
X=100
Y=100
Text=X=%1#CRLF#Y=%2

Hope this gives you some help.
User avatar
balala
Rainmeter Sage
Posts: 16176
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Change meter position(area)

Post by balala »

eclectic-tech wrote: March 15th, 2024, 5:10 pm To restrict the skin to a central position and limit how far off center it moves from that point, look at this example.
Good approach, however I think there is a way to simplify even more the code. For this you should have to use the newer !SetWindowPosition bang, instead of !Move. For instance:

Code: Select all

[Rainmeter]
OnRefreshAction=[!SetWindowPosition "(50+[MeasureX])%" "(50+[MeasureY])%" "50%" "50%"]

[Variables]
StepRate=10
OffCenterMaxPercent=25

[MeasureX]
Measure=Calc
Formula=Random
LowBound=-#OffCenterMaxPercent#
HighBound=#OffCenterMaxPercent#
UpdateRandom=1
UpdateDivider=-1
Group=Position

[MeasureY]
Measure=Calc
Formula=Random
LowBound=-#OffCenterMaxPercent#
HighBound=#OffCenterMaxPercent#
UpdateRandom=1
UpdateDivider=-1
DynamicVariables=1
Group=Position

[MeasureTimer]
Measure=Calc
OnUpdateAction=[!UpdateMeasureGroup "Position"][!SetWindowPosition "(50+[MeasureX])%" "(50+[MeasureY])%" "50%" "50%"]
UpdateDivider=#StepRate#
DynamicVariables=1

[MeterImage]
Meter=Shape
X=2
Y=2
Shape=Rectangle 1,1,200,200,4 | StrokeWidth 2 | Fill Color 244,220,100
DynamicVariables=1

[Location]
Meter=String
MeasureName=MeasureX
MeasureName2=MeasureY
StringAlign=CenterCenter
StringStyle=Bold
X=100
Y=100
Text=X=%1#CRLF#Y=%2
These are the things got updated:
  • I replaced the !Move bangs with !SetWindowPosition (both of them, in the OnRefreshAction option of the [Rainmeter] section and on the [MeasureTime] measure, however I rewrote this measure as well - see below). The advantage of this bang against !Move is that you easily can set the anchor point of the skin, by the last two parameters, no need to calculate the position of the skin to get it centered. I set both of them to 50%, this way getting the skin centered around the appropriate point.
  • I replaced both, the LowBound and HighBound options of the [MeasureX] and [MeasureY] measures by LowBound=-#OffCenterMaxPercent# and HighBound=#OffCenterMaxPercent#. OffCenterMaxPercent is a variable defined into the [Variables] section and it represents the percentage with which the skin can move away by the center of the screen. The generated random numbers are kept between -#OffCenterMaxPercent# and #OffCenterMaxPercent#, ensuring a move of the skin around the center of the screen (which is set by the 50% used in the formulas of first two parameters of the !SetWindowPosition bangs).
  • I removed the Formula option of the [MeasureTimer] measure (not needed in this approach), added an UpdateDivider=#StepRate# option to get it updated on each #StepRate# seconds. A DynamicVariables=1 was required as well, so I added this one as well.
  • I removed the DynamicVariables=1 options from the [MeasureX] and [MeasureY] options. By simplifying these measures, the DynamicVariables option became useless.
  • I removed the not needed anymore XCenterPosition and YCenterPosition variables from the [Variables] section.
  • I kept unchanged both meters.
Hope these changes make sense and you're not offended by them (I'm sure you are not).
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5407
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Change meter position(area)

Post by eclectic-tech »

No offense taken here ;-)

It's always good to have options to examine. I went with the OP's method of choice (!Move), but your approach is better suited when moving entire skins. :thumbup:
User avatar
balala
Rainmeter Sage
Posts: 16176
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Change meter position(area)

Post by balala »

eclectic-tech wrote: March 15th, 2024, 7:48 pm but your approach is better suited when moving entire skins. :thumbup:
Not sure if it's better suited, however the !Move bang moves the entire skin as well. !SetWindowPosition seems much better in my opinion, due to its described properties (it's a much more modern and new bang). I assume since we have this bang, !Move is kept only for backward compatibility reasons (this is again only my opinion).
BorisLFC
Posts: 6
Joined: March 15th, 2024, 9:31 am

Re: Change meter position(area)

Post by BorisLFC »

Thanks for all the help, guys. I was totally wrong with my code, need to delve in rainmeter documentation more. Not ashamed to admit, but AI couldnt help me there. But you.. you know your stuff. Balala, as for the rest of the code, nothing much, its just a skin with a weekday, date and clock. As for the code by eclectic-tech, it does what i wanted, and i can modify it for other areas of the screen too. Will try this latest revised one. Anyway, really appreciate your help guys.
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5407
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Change meter position(area)

Post by eclectic-tech »

Happy to help.