It is currently March 28th, 2024, 3:34 pm

Rainmeter Rotation Generator

Tips and Tricks from the Rainmeter Community
Post Reply
Maximilian Braun
Posts: 2
Joined: November 5th, 2020, 12:15 am

Rainmeter Rotation Generator

Post by Maximilian Braun »

As i was trying to Rotate a widget/plugin that i installed i noticed that it is extremely hard to rotate a widget.
It's not actually hard but you have to calculate the values for every single change if you for example want to test it with different values.
I didn't find an actual generator on the Internet so i created one myself.
I thought also other people could use it to calculate their values.
So here i am at 2 o'clock in the morning making this post 😂.

Anyway here is the tool: https://codepen.io/How_to_Code/full/mdEjrja

The reference i used: https://docs.rainmeter.net/tips/transformation-matrix-guide/

Hope you like this generator. This is my first project that i post to others so that it is public available.
Have fun :welcome:
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Rainmeter Rotation Generator

Post by balala »

Maximilian Braun wrote: November 5th, 2020, 12:23 am Anyway here is the tool: https://codepen.io/How_to_Code/full/mdEjrja
Hi and welcome to Rainmeter.
I definitely am a great fan of TransformationMatrix, which I believe is an extremely powerful option. So when I saw your post I immediately gave it a try. It is a good tool, congratulations for it. But I have two comments:
  • You can't rotate a whole skin (you named it widget, but Rainmeter doesn't work with widgets, but with skins), much less a plugin (measure, for instance). What can you rotate, are the meters. You have to apply the calculated TransformationMatrix to such a meter (just to calrify a little bit the terminology).
  • The last two parameters of such a TransformationMatrix option (named tx and ty in TransformationMatrix Guide), are used to move horizontally, respectivelly vertically the rotated meter. These are needed because if the rotated meter isn't moved, it goes outside of the skin, due to the fact that when rotating a meter, it is rotated around the origin of the skin. These two parameters are moving the rotated meter in a way to look like it has been rotated around another point (which one depends on the values of the tx and ty parameters). So I'm not sure how have you calculated these last two parameters, but they can't be used in all situation. Your tool should take into account the center of rotation. If interested, I can help you to modify the code of your tool, to make it to take into account this center.
However congratulation for this tool. It's a great instrument.
Maximilian Braun
Posts: 2
Joined: November 5th, 2020, 12:15 am

Re: Rainmeter Rotation Generator

Post by Maximilian Braun »

balala wrote: November 5th, 2020, 7:49 am Hi and welcome to Rainmeter.
I definitely am a great fan of TransformationMatrix, which I believe is an extremely powerful option. So when I saw your post I immediately gave it a try. It is a good tool, congratulations for it. But I have two comments:
  • You can't rotate a whole skin (you named it widget, but Rainmeter doesn't work with widgets, but with skins), much less a plugin (measure, for instance). What can you rotate, are the meters. You have to apply the calculated TransformationMatrix to such a meter (just to calrify a little bit the terminology).
  • The last two parameters of such a TransformationMatrix option (named tx and ty in TransformationMatrix Guide), are used to move horizontally, respectivelly vertically the rotated meter. These are needed because if the rotated meter isn't moved, it goes outside of the skin, due to the fact that when rotating a meter, it is rotated around the origin of the skin. These two parameters are moving the rotated meter in a way to look like it has been rotated around another point (which one depends on the values of the tx and ty parameters). So I'm not sure how have you calculated these last two parameters, but they can't be used in all situation. Your tool should take into account the center of rotation. If interested, I can help you to modify the code of your tool, to make it to take into account this center.
However congratulation for this tool. It's a great instrument.

Thanks for youre reply.
1. I know you cant rotate an plugin/widget directly. Sorry. I meant the right thing but wrote the wrong. My Bad.
2. I would appreciate it if you could show me how to improve my code. I calculated the last two values like in the reference link that i posted under the editor link.
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Rainmeter Rotation Generator

Post by balala »

Maximilian Braun wrote: November 5th, 2020, 3:09 pm 1. I know you cant rotate an plugin/widget directly. Sorry. I meant the right thing but wrote the wrong. My Bad.
Alright, no problem. Just take care widgets still don't exist in Rainmeter. They are skins, according to Rainmeter's terminology.
Maximilian Braun wrote: November 5th, 2020, 3:09 pm 2. I would appreciate it if you could show me how to improve my code. I calculated the last two values like in the reference link that i posted under the editor link.
Ok, here is an example Rainmeter code:

Code: Select all

[Rainmeter]
Update=-1

[Variables]
Rot=0
RotationCenterX=([ImageMeter:X]+[ImageMeter:W]/2)
RotationCenterY=([ImageMeter:Y]+[ImageMeter:H]/2)
RotationAngle=30
Angle=0

[MeasureRot]
Measure=Calc
Formula=#Rot#
IfCondition=(#CURRENTSECTION#=0)
IfTrueAction=[!SetVariable Angle "0"][!SetOption MeterRotate Text "Not rotated#CRLF#Click here to rotate."][!UpdateMeter "ImageMeter"][!UpdateMeter "MeterRotate"][!Redraw]
IfFalseAction=[!SetVariable Angle "#RotationAngle#"][!SetOption MeterRotate Text "Rotated with #RotationAngle# degrees#CRLF#Click here to unrotate."][!UpdateMeter "ImageMeter"][!UpdateMeter "MeterRotate"][!Redraw]
DynamicVariables=1

[ImageMeter]
Meter=Image
SolidColor=255,240,0
AntiAlias=1
X=40
Y=75
W=200
H=150
DynamicVariables=1
TransformationMatrix=(Cos(Rad(#Angle#)));(-Sin(Rad(#Angle#)));(Sin(Rad(#Angle#)));(Cos(Rad(#Angle#)));(#RotationCenterX#-#RotationCenterX#*Cos(Rad(#Angle#))-#RotationCenterY#*Sin(Rad(#Angle#)));(#RotationCenterY#+#RotationCenterX#*Sin(Rad(#Angle#))-#RotationCenterY#*Cos(Rad(#Angle#)))

[MeterRotationCenter]
Meter=Image
SolidColor=255,0,0
X=(#RotationCenterX#-1)
Y=(#RotationCenterY#-1)
W=3
H=3
DynamicVariables=1

[MeterRotate]
Meter=STRING
Y=0
Padding=15,5,15,5
FontColor=220,220,220
FontEffectColor=0,0,0
StringEffect=Shadow
SolidColor=0,0,0,150
FontSize=8
FontFace=Segoe UI
StringStyle=BOLD
StringAlign=LEFT
AntiAlias=1
DynamicVariables=1
LeftMouseUpAction=[!SetVariable Rot "(1-#Rot#)"][!UpdateMeasure "MeasureRot"][!UpdateMeter "MeterRotate"][!Redraw]
Hidden=0
See that here you have a yellow rectangle. When you load / refresh the skin, the rectangle is unrotated. A string in the upper left corner shows the status. If you click this string, you get the rectangle rotated with a number of degrees set on the RotateAngle variable (into the [Variables] section). Into the same [Variables] section you can modify the RotationCenterX and RotationCenterY variables, which are the coordinates of the rotation center. In the above code these are set to RotationCenterX=([ImageMeter:X]+[ImageMeter:W]/2) and RotationCenterY=([ImageMeter:Y]+[ImageMeter:H]/2), which represint the center of the image (of the yellow rectangle), no matter where do you place it.
Now in the code of your tool what should you modify in my opinion, is to add two other fields beside the rotation angle, where the user should have to add the coordinates of the rotation center. Then in the calculation of the returned TransformationMatrix option you should use these coordinates. Into the TransformationMatrix option of the above code, these are the #RotationCenterX# and #RotationCenterY# variables, these should be replaced by the values added to the fields of the coordinates of the rotation center (the two fields I talked about above).
I don't know in which language have you wrote the code of your tool, but probably doesn't even matter too much, because I anyway don't know any of those languages used to write such tools. But if you try to modify the code of your tool, I hope you'll be able to take into account what have I described above.
If any question arrises, please come back and post it here. If I can I'm gonna answer them.
Great work, congratulations for it again. :great:
Post Reply