It is currently May 19th, 2024, 12:24 pm

Lua Scripting - How to TransformMatrix

Discuss the use of Lua in Script measures.
User avatar
Kurou
Posts: 42
Joined: January 24th, 2022, 2:54 pm
Location: World Wide Web

Re: Lua Scripting - How to TransformMatrix

Post by Kurou »

Yincognito wrote: June 25th, 2023, 3:05 pm I'm not familiar with how the actual code looks like, but I don't think there's a need to multiply the skin height by the scale variable, since the TM already does that and you'll end up having the same issue. There is no problem if your skin doesn't have a static value in relation to its contents, the TM scaling works the same regardless. The key is to not have the meter positioning based on an already scaled value.

So, when I said "static" I meant "not scaled". This means that you can use a dynamic dimension (like the one based on the contents), as long as it's not dynamic because of scaling (like the one you get by using already scaled [Background:WH] as factors in positioning). To produce the correct results, the TM expects the values it works with to be unscaled (or original), irrespective if they are dynamic due to some other reason besides scaling.
My problem is that when the skin gets scaled the width is correct, positioning too but the height of the entire skin is the same. This height is not declared by default but build up from meters.

(Meters are shown via lua code)

Rainmeter Code:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
DynamicVariables=1
Group=ashuramaru

;   Backgrounds
Background=#@#\images\backgrounds\#background#_blank.png
BackgroundMode=3
BackgroundMargins=0,34,0,14

;   Actions
OnRefreshAction=[!CommandMeasure "Script" "Statistics_Handler('network') ; Statistics_Handler('processor') ; Statistics_Handler('graphics') ; Statistics_Handler('system') ; Statistics_Handler('drives')"]
OnUpdateAction=[!CommandMeasure "Script" "Temperature_CPU() ; Temperature_GPU()"]
RightMouseDownAction=[!CommandMeasure "Script" "ConfigActive_Toggle('#ROOTCONFIG#\\control\\context', 'context_menu.ini', '-1')"]

[MetaData]
Name=Statistics - Connected
Information=Skin which is displaying all usage information from the pc sensors in connected style.
Author=Kurou

[Variables]

;###################
;   Imports
;###################

;   Variables
@Include_Variables_Customization=#@#\variables\customization.inc
@Include_Variables_Settings=#@#\variables\settings.inc

;   Styles
@Include_Style_String=#@#\styles\strings.inc
@Include_Style_Graphs=#@#\styles\graphs.inc

;   Measures
@Include_Measures_Network=#@#\addons\statistics\measures\network.inc
@Include_Measures_Processor=#@#\addons\statistics\measures\#import_sensor_app#\processor.inc
@Include_Measures_Graphics=#@#\addons\statistics\measures\#import_sensor_app#\graphics.inc
@Include_Measures_System=#@#\addons\statistics\measures\#import_sensor_app#\system.inc
@Include_Measures_Drives=#@#\addons\statistics\measures\drives.inc

;###################
;   Measures
;###################

[Script]
Measure=Script
ScriptFile=#@#\lua\statistics.lua

[Measure_TranslucentRM]
Measure=Plugin
Plugin=TranslucentRM
Type=#background_effect#
Border=#background_border#
Taskbar=0
Corner=#background_corner#

[Measure_ConfigActive]
Measure=Plugin
Plugin=ConfigActive

;###################
;   Meters
;###################

[Background]
Meter=Shape
Shape=Rectangle 0, 0, 200, 1 | Fill Color 0, 0, 0 | StrokeWidth 0 | Stroke Color 0,0,0
X=0
Y=0

;   Network

@Include_Network=#import_first#

[Seperator_1]
Meter=Image
Y=20r

;   Processor

@Include_Processor=#import_second#

[Seperator_2]
Meter=Image
Y=20r

;   Graphics

@Include_Graphics=#import_third#

[Seperator_3]
Meter=Image
Y=20r

;   System

@Include_System=#import_fourth#

[Seperator_4]
Meter=Image
Y=20r

;   Drives

@Include_Drives=#import_fifth#

[Loading]
Meter=String
MeterStyle=Statistics_Header
FontSize=20
Text=Loading...
X=(200 / 2)
Y=15r
One of the imports (meters):

Code: Select all

[Network_Header]
Meter=Image
ImageName=#@#\images\backgrounds\#background#_header.png
W=200
X=0r
Y=0r
Hidden=1

[Network_Title]
Meter=String
MeterStyle=Statistics_Header
Text=Network
X=(200 / 2)
Y=7r
Hidden=1

[Network_Header_Spacer]
Meter=Image
Y=5r

;   Ping
[Network_Ping_Label]
Meter=String
MeterStyle=Statistics_Left
Text=Latency
X=5
Hidden=1

[Network_Ping_Value]
Meter=String
MeasureName=Measure_Ping
MeterStyle=Statistics_Right
Text=%1
Postfix=" ms"
X=(200 - 2)
Y=0r
Hidden=1

[Network_Ping_Bar]
Meter=Bar
MeasureName=Measure_Ping
MeterStyle=Statistics_Bar
W=(200 - 10)
H=#bar_height#
X=5
Hidden=1

[Network_Ping_Graph_Background]
Meter=Shape
Shape=Rectangle 0, 0, (200 - 10), 40 | Fill Color 20, 20, 20, 150 | StrokeWidth 0.2 | Stroke Color 250, 250, 250, 150
X=0r
Hidden=1

[Network_Ping_Graph]
Meter=Line
MeterStyle=Statistics_Line
MeasureName=Measure_Ping
AutoScale=0
Hidden=1

[Network_Ping_Graph2]
Meter=Histogram
MeterStyle=Statistics_Histogram
MeasureName=Measure_Ping
AutoScale=0
Hidden=1

[Network_Ping_Graph_Spacer]
Meter=Image
Hidden=1

;   Upload
[Network_Upload_Label]
Meter=String
MeterStyle=Statistics_Left
Text=Upload
X=5
Hidden=1

[Network_Upload_Value]
Meter=String
MeasureName=Measure_Upload
MeterStyle=Statistics_Right
Text=%1
Postfix="B/s"
NumOfDecimals=1
AutoScale=1k
X=(200 - 2)
Y=0r
Hidden=1

[Network_Upload_Bar]
Meter=Bar
MeasureName=Measure_Upload
MeterStyle=Statistics_Bar
W=(200 - 10)
H=#bar_height#
X=5
Hidden=1

[Network_Upload_Graph_Background]
Meter=Shape
Shape=Rectangle 0, 0, (200 - 10), 40 | Fill Color 20, 20, 20, 150 | StrokeWidth 0.2 | Stroke Color 250, 250, 250, 150
X=0r
Hidden=1

[Network_Upload_Graph]
Meter=Line
MeterStyle=Statistics_Line
MeasureName=Measure_Upload
AutoScale=0
Hidden=1

[Network_Upload_Graph2]
Meter=Histogram
MeterStyle=Statistics_Histogram
MeasureName=Measure_Upload
AutoScale=0
Hidden=1

[Network_Upload_Graph_Spacer]
Meter=Image
Hidden=1

;   Download
[Network_Download_Label]
Meter=String
MeterStyle=Statistics_Left
Text=Download
X=5
Hidden=1

[Network_Download_Value]
Meter=String
MeasureName=Measure_Download
MeterStyle=Statistics_Right
Text=%1
Postfix="B/s"
NumOfDecimals=1
AutoScale=1k
X=(200 - 2)
Y=0r
Hidden=1

[Network_Download_Bar]
Meter=Bar
MeasureName=Measure_Download
MeterStyle=Statistics_Bar
W=(200 - 10)
H=#bar_height#
X=5
Hidden=1

[Network_Download_Graph_Background]
Meter=Shape
Shape=Rectangle 0, 0, (200 - 10), 40 | Fill Color 20, 20, 20, 150 | StrokeWidth 0.2 | Stroke Color 250, 250, 250, 150
X=0r
Hidden=1

[Network_Download_Graph]
Meter=Line
MeterStyle=Statistics_Line
MeasureName=Measure_Download
AutoScale=0
Hidden=1

[Network_Download_Graph2]
Meter=Histogram
MeterStyle=Statistics_Histogram
MeasureName=Measure_Download
AutoScale=0
Hidden=1

[Network_Download_Graph_Spacer]
Meter=Image
Hidden=1

;   Traffic
[Network_Traffic_Label]
Meter=String
MeterStyle=Statistics_Left
Text=Traffic
X=5
Hidden=1

[Network_Traffic_Value]
Meter=String
MeasureName=Measure_Traffic
MeterStyle=Statistics_Right
Text=%1
Postfix="B"
NumOfDecimals=1
AutoScale=1k
X=(200 - 2)
Y=0r
Hidden=1

[Network_Traffic_Bar]
Meter=Bar
MeasureName=Measure_Traffic
MeterStyle=Statistics_Bar
W=(200 - 10)
H=#bar_height#
X=5
Hidden=1

[Network_Traffic_Graph_Background]
Meter=Shape
Shape=Rectangle 0, 0, (200 - 10), 40 | Fill Color 20, 20, 20, 150 | StrokeWidth 0.2 | Stroke Color 250, 250, 250, 150
X=0r
Hidden=1

[Network_Traffic_Graph]
Meter=Line
MeterStyle=Statistics_Line
MeasureName=Measure_Traffic
AutoScale=
Hidden=1

[Network_Traffic_Graph2]
Meter=Histogram
MeterStyle=Statistics_Histogram
MeasureName=Measure_Traffic
AutoScale=0
Hidden=1

[Network_Traffic_Graph_Spacer]
Meter=Image
Hidden=1
Last edited by Kurou on June 26th, 2023, 10:21 am, edited 2 times in total.
Brought to you by: https://kurou.dev/
User avatar
Yincognito
Rainmeter Sage
Posts: 7286
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Lua Scripting - How to TransformMatrix

Post by Yincognito »

Kurou wrote: June 25th, 2023, 3:31 pm My problem is that when the skin gets scaled the width is correct, positioning too but the height of the entire skin is the same. This height is not declared by default but build up from meters.
Well, I told you that TM comes with that drawback and you have to understand how it works, and you just experienced it (if you thought the drawback was only about mouse detection, think again)... :confused:

First, let me point out that the said behavior is considered normal. The reason is related to the fact that TM only acts on meters (and not on the skin itself), and only acts on the visual side of them (and not on their properties). This means that every property of the said meters stays the same after the TM scaling, including their position, size, and so on (hence the mouse detection bit from the manual). You can clearly see that by watching the log when holding middle click on the first meter from the following skin in order to scale stuff:

Code: Select all

[Variables]
Style=0
Scale=1.0
W=419
H=135

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

---Styles---

[Scale]
TransformationMatrix=#Scale#;0;0;#Scale#;0;0

[Texts]
X=0r
Y=0R
FontFace=Consolas
SolidColor=0,0,0,255
FontColor=255,255,255,255
Padding=10,10,10,10
FontSize=16
AntiAlias=1
Text=Scaling Using TransformationMatrix
DynamicVariables=1

---Meters---

[Background]
Meter=Image
SolidColor=255,0,0,255
W=(#W#*#Scale#)
H=45
; W=(#W#*#Scale#)
; H=(#H#*#Scale#)
MiddleMouseDownAction=[!SetVariable Scale 2.75][!UpdateMeter *][!Redraw][!Log "Meter Size = [1stMeter:W],[1stMeter:H]"]
MiddleMouseUpAction=[!SetVariable Scale 1.0][!UpdateMeter *][!Redraw][!Log "Meter Size = [1stMeter:W],[1stMeter:H]"]
DynamicVariables=1

[1stMeter]
Meter=String
MeterStyle=Texts|Scale
X=0r
Y=0r

[2ndMeter]
Meter=String
MeterStyle=Texts|Scale

[3rdMeter]
Meter=String
MeterStyle=Texts|Scale
The effect is that, since the positions and size of the meters have the same values, the skin size is the same too, thus the height in your skin (and the above one too) staying the same as well, since it's not "declared" or better said scaled individually (via a formula like in the commented lines from the code).

The solution is obvious, "scaling" the values that give the skin size (in your case, the background meter) independently, without using TM, just like in the commented lines from the above code. I know that this doesn't suit the content based height in your scenario since you have to somehow estimate the unscaled height based on what you hide and show, but then, if TM was the perfect solution, everybody would use it in their skins, right?
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Kurou
Posts: 42
Joined: January 24th, 2022, 2:54 pm
Location: World Wide Web

Re: Lua Scripting - How to TransformMatrix

Post by Kurou »

Yincognito wrote: June 25th, 2023, 6:05 pm Well, I told you that TM comes with that drawback and you have to understand how it works, and you just experienced it (if you thought the drawback was only about mouse detection, think again)... :confused:

First, let me point out that the said behavior is considered normal. The reason is related to the fact that TM only acts on meters (and not on the skin itself), and only acts on the visual side of them (and not on their properties). This means that every property of the said meters stays the same after the TM scaling, including their position, size, and so on (hence the mouse detection bit from the manual). You can clearly see that by watching the log when holding middle click on the first meter from the following skin in order to scale stuff:

The effect is that, since the positions and size of the meters have the same values, the skin size is the same too, thus the height in your skin (and the above one too) staying the same as well, since it's not "declared" or better said scaled individually (via a formula like in the commented lines from the code).

The solution is obvious, "scaling" the values that give the skin size (in your case, the background meter) independently, without using TM, just like in the commented lines from the above code. I know that this doesn't suit the content based height in your scenario since you have to somehow estimate the unscaled height based on what you hide and show, but then, if TM was the perfect solution, everybody would use it in their skins, right?
I got it, thanks for help :)
Brought to you by: https://kurou.dev/
User avatar
Yincognito
Rainmeter Sage
Posts: 7286
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Lua Scripting - How to TransformMatrix

Post by Yincognito »

Kurou wrote: June 26th, 2023, 10:20 am I got it, thanks for help :)
You're welcome. ;-)
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Kurou
Posts: 42
Joined: January 24th, 2022, 2:54 pm
Location: World Wide Web

Re: Lua Scripting - How to TransformMatrix

Post by Kurou »

Yincognito wrote: June 26th, 2023, 11:50 am You're welcome. ;-)
At the end i've used TransformMatrix for other skins from the suite and the main skin statistics is based on the calculation (width/height * #scale#) formula. TransformMatrix doesnt work with dynamic skin height and thats very sad thing :'(.
Brought to you by: https://kurou.dev/
User avatar
Yincognito
Rainmeter Sage
Posts: 7286
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Lua Scripting - How to TransformMatrix

Post by Yincognito »

Kurou wrote: June 27th, 2023, 2:06 pmTransformMatrix doesnt work with dynamic skin height and thats very sad thing :'(.
It doesn't work with ANY dynamic skin dimension, not just the height, and you would have noticed this if you changed the background meter width to an arbitrary value like 45 in the code I posted earlier (I only did it for the height since it was your scenario, but that doesn't mean that the dynamic skin width works with TM).



Like I said, TM does NOT work with skins - it only works with meters, since it's a meter option. This means that in order to "scale a skin", you have to scale a background meter (since that meter will determine the skin size, assuming DynamicWindowSize=1 is set in the [Rainmeter] section of the skin).

In addition to that, the said background meter must NOT be scaled using TM, since, like I've shown above, TM does NOT change the properties of a meter (like position, size, etc.) and therefore not the skin's, it's a purely visual transformation. Basically, you have to scale the background meter independently from TM, using a formula, and scale the rest using TM.

Following this logic, the said background meter must be aware of the ORIGINAL skin size, so it can multiply that with the #Scale# variable to get the desired result. The thing is here, a skin will only be able to provide its size to the skin designer once all meters are updated and redrawn, which obviously happens at the end of the meter section. So, if we set the size variables ONCE in a dummy meter at the end, problem solved:

Code: Select all

[Variables]
Action=Make
MakeSize=[!SetVariable SW [#CURRENTCONFIGWIDTH]][!SetVariable SH [#CURRENTCONFIGHEIGHT]][!UpdateMeter Background][!Redraw]
SkipSize=[]
Scale=1.00
Notch=0.05
SW=0
SH=0

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

---Styles---

[Scale]
TransformationMatrix=#Scale#;0;0;#Scale#;0;0

[Texts]
X=0r
Y=0R
FontFace=Consolas
FontColor=255,255,255,255
Padding=10,10,10,10
FontSize=16
AntiAlias=1
Text=Scaling Using TransformationMatrix
DynamicVariables=1

---Meters---

[Background]
Meter=Image
SolidColor=0,0,0,255
W=(#SW#*#Scale#)
H=(#SH#*#Scale#)
MouseScrollUpAction=[!SetVariable Scale (Clamp(#Scale#+#Notch#,#Notch#,Min(#WORKAREAWIDTH#/#SW#,#WORKAREAHEIGHT#/#SH#)))][!UpdateMeter *][!Redraw]
MouseScrollDownAction=[!SetVariable Scale (Clamp(#Scale#-#Notch#,#Notch#,Min(#WORKAREAWIDTH#/#SW#,#WORKAREAHEIGHT#/#SH#)))][!UpdateMeter *][!Redraw]
LeftMouseDoubleClickAction=[!SetVariable Scale 1.00][!UpdateMeter *][!Redraw]
MiddleMouseUpAction=[!WriteKeyValue Variables Scale #Scale#]
DynamicVariables=1

[1stMeter]
Meter=String
MeterStyle=Texts|Scale
X=0r
Y=0r

[2ndMeter]
Meter=String
MeterStyle=Texts|Scale

[3rdMeter]
Meter=String
MeterStyle=Texts|Scale

[SkinSize]
Meter=Image
OnUpdateAction=[#[#Action]Size][!SetVariable Action "Skip"]
DynamicVariables=1
Scroll to scale, left double click to reset scale to 1, middle click to save current scale to the file. It's a bit of a hack, but it works. Adapting this to your cases it's up to you - if you're fine with the approach, that is.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Kurou
Posts: 42
Joined: January 24th, 2022, 2:54 pm
Location: World Wide Web

Re: Lua Scripting - How to TransformMatrix

Post by Kurou »

Yincognito wrote: June 27th, 2023, 5:03 pm It doesn't work with ANY dynamic skin dimension, not just the height, and you would have noticed this if you changed the background meter width to an arbitrary value like 45 in the code I posted earlier (I only did it for the height since it was your scenario, but that doesn't mean that the dynamic skin width works with TM).



Like I said, TM does NOT work with skins - it only works with meters, since it's a meter option. This means that in order to "scale a skin", you have to scale a background meter (since that meter will determine the skin size, assuming DynamicWindowSize=1 is set in the [Rainmeter] section of the skin).

In addition to that, the said background meter must NOT be scaled using TM, since, like I've shown above, TM does NOT change the properties of a meter (like position, size, etc.) and therefore not the skin's, it's a purely visual transformation. Basically, you have to scale the background meter independently from TM, using a formula, and scale the rest using TM.

Following this logic, the said background meter must be aware of the ORIGINAL skin size, so it can multiply that with the #Scale# variable to get the desired result. The thing is here, a skin will only be able to provide its size to the skin designer once all meters are updated and redrawn, which obviously happens at the end of the meter section. So, if we set the size variables ONCE in a dummy meter at the end, problem solved:

Code: Select all

[Variables]
Action=Make
MakeSize=[!SetVariable SW [#CURRENTCONFIGWIDTH]][!SetVariable SH [#CURRENTCONFIGHEIGHT]][!UpdateMeter Background][!Redraw]
SkipSize=[]
Scale=1.00
Notch=0.05
SW=0
SH=0

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

---Styles---

[Scale]
TransformationMatrix=#Scale#;0;0;#Scale#;0;0

[Texts]
X=0r
Y=0R
FontFace=Consolas
FontColor=255,255,255,255
Padding=10,10,10,10
FontSize=16
AntiAlias=1
Text=Scaling Using TransformationMatrix
DynamicVariables=1

---Meters---

[Background]
Meter=Image
SolidColor=0,0,0,255
W=(#SW#*#Scale#)
H=(#SH#*#Scale#)
MouseScrollUpAction=[!SetVariable Scale (Clamp(#Scale#+#Notch#,#Notch#,Min(#WORKAREAWIDTH#/#SW#,#WORKAREAHEIGHT#/#SH#)))][!UpdateMeter *][!Redraw]
MouseScrollDownAction=[!SetVariable Scale (Clamp(#Scale#-#Notch#,#Notch#,Min(#WORKAREAWIDTH#/#SW#,#WORKAREAHEIGHT#/#SH#)))][!UpdateMeter *][!Redraw]
LeftMouseDoubleClickAction=[!SetVariable Scale 1.00][!UpdateMeter *][!Redraw]
MiddleMouseUpAction=[!WriteKeyValue Variables Scale #Scale#]
DynamicVariables=1

[1stMeter]
Meter=String
MeterStyle=Texts|Scale
X=0r
Y=0r

[2ndMeter]
Meter=String
MeterStyle=Texts|Scale

[3rdMeter]
Meter=String
MeterStyle=Texts|Scale

[SkinSize]
Meter=Image
OnUpdateAction=[#[#Action]Size][!SetVariable Action "Skip"]
DynamicVariables=1
Scroll to scale, left double click to reset scale to 1, middle click to save current scale to the file. It's a bit of a hack, but it works. Adapting this to your cases it's up to you - if you're fine with the approach, that is.
I could do that. But so the scale function was created so the thread will be closed. Thanks for the support :)
Brought to you by: https://kurou.dev/