It is currently May 5th, 2024, 7:32 pm

Shape Meter - Scaling not centered/offset correctly for combined shapes.

Get help with creating, editing & fixing problems with skins
User avatar
Yincognito
Rainmeter Sage
Posts: 7199
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Shape Meter - Scaling not centered/offset correctly for combined shapes.

Post by Yincognito »

JHB101101 wrote: June 25th, 2021, 10:43 am(this is not pseudo code but I did type it up in here only, so it may need some inspection)
Yeah, it needs a bit more than an "inspection", Jayson. Section names don't match or options are missing, and all that. Anyway, I see what you mean, by eventually figuring out a working version of the code:

Code: Select all

[Variables]
Topmenu_Title_Text="AAA"

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
BackgroundMode=2
SolidColor=47,47,47,255

---Measures---

[Font.A.Glyph]
	Measure=String
	String="0,16|ArcTo 16,0,16|LineTo 26,0|ArcTo 42,16,16|LineTo 42,100|LineTo 26,100|LineTo 26,58|LineTo 16,58|LineTo 16,42|LineTo 26,42|LineTo 26,21|ArcTo 16,21,5,*,*,1|LineTo 16,100|LineTo 0,100|ClosePath 1"
[Font.A.Advance]
	Measure=String
	String=47

[Title.Characters]
	Measure=String
	DynamicVariables=1
	RegExpSubstitute=1
	String=[#Topmenu_Title_Text]
	Substitute="[^ a-zA-Z0-9]":""
	OnUpdateAction=[!UpdateMeasure Title.Character1][!UpdateMeasure Title.Character2][!UpdateMeasure Title.Character3][!UpdateMeter TopmenuFrame][!Redraw]

[Title.Character1]
	Measure=String
	DynamicVariables=1
	RegExpSubstitute=1
	IfMatchMode=1
	String=[&Title.Characters]
	Substitute="^(.).*$":"\1"," ":"Space","":"None"

[Title.Character2]
	Measure=String
	Group=TitleCharacters
	DynamicVariables=1
	RegExpSubstitute=1
	IfMatchMode=1
	String=[&Title.Characters]
	Substitute="^.{1}(.).*$":"\1","[&Title.Characters]":""," ":"Space","":"None"

[Title.Character3]
	Measure=String
	DynamicVariables=1
	RegExpSubstitute=1
	IfMatchMode=1
	String=[&Title.Characters]
	Substitute="^.{2}(.).*$":"\1","[&Title.Characters]":""," ":"Space","":"None"

---Styles---

[Topmenu.Frame]
	DynamicVariables=1
	SharedModifiers=StrokeWidth 0|Fill Color 0,0,0

	Shape=Path Font.[&Title.Character1].Glyph|Offset ([&[#CURRENTSECTION]:W]-100-([&Font.[&Title.Character1].Advance]+[&Font.[&Title.Character2].Advance]+[&Font.[&Title.Character3].Advance])),0|Extend SharedModifiers
	Shape2=Path Font.[&Title.Character2].Glyph|Offset ([&[#CURRENTSECTION]:W]-100-([&Font.[&Title.Character2].Advance]+[&Font.[&Title.Character3].Advance])),0|Extend SharedModifiers
	Shape3=Path Font.[&Title.Character3].Glyph|Offset ([&[#CURRENTSECTION]:W]-100-([&Font.[&Title.Character3].Advance])),0|Extend SharedModifiers

  Font.A.Glyph=[&Font.A.Glyph]
  ; Shape4=Combine Shape | Union Shape2 | Union Shape3 | Scale 0.2,0.2

---Meters---

[TopmenuFrame]
	Meter=Shape
	MeterStyle=Topmenu.Frame
	DynamicVariables=1
	X=0
	Y=0
	W=[#WORKAREAWIDTH]
	H=[#WORKAREAHEIGHT]
Commenting out the Shape4 line does indeed move the scaled shape to the left. This has certainly to do with how you compute the offsets, because for hardcoded offsets it works and centers things without issues.

This code should do roughly what you want though - I'll let you figure out the differences:

Code: Select all

[Variables]
Topmenu_Title_Text="AAA"

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
BackgroundMode=2
SolidColor=47,47,47,255

---Measures---

[Font.A.Glyph]
	Measure=String
	String="0,16|ArcTo 16,0,16|LineTo 26,0|ArcTo 42,16,16|LineTo 42,100|LineTo 26,100|LineTo 26,58|LineTo 16,58|LineTo 16,42|LineTo 26,42|LineTo 26,21|ArcTo 16,21,5,*,*,1|LineTo 16,100|LineTo 0,100|ClosePath 1"
[Font.A.Advance]
	Measure=String
	String=47

[Title.Characters]
	Measure=String
	DynamicVariables=1
	RegExpSubstitute=1
	String=[#Topmenu_Title_Text]
	Substitute="[^ a-zA-Z0-9]":""
	OnUpdateAction=[!UpdateMeasure Title.Character1][!UpdateMeasure Title.Character2][!UpdateMeasure Title.Character3][!UpdateMeter TopmenuFrame][!Redraw]

[Title.Character1]
	Measure=String
	DynamicVariables=1
	RegExpSubstitute=1
	IfMatchMode=1
	String=[&Title.Characters]
	Substitute="^(.).*$":"\1"," ":"Space","":"None"

[Title.Character2]
	Measure=String
	Group=TitleCharacters
	DynamicVariables=1
	RegExpSubstitute=1
	IfMatchMode=1
	String=[&Title.Characters]
	Substitute="^.{1}(.).*$":"\1","[&Title.Characters]":""," ":"Space","":"None"

[Title.Character3]
	Measure=String
	DynamicVariables=1
	RegExpSubstitute=1
	IfMatchMode=1
	String=[&Title.Characters]
	Substitute="^.{2}(.).*$":"\1","[&Title.Characters]":""," ":"Space","":"None"

---Styles---

[Topmenu.Frame]
	DynamicVariables=1
	SharedModifiers=StrokeWidth 0|Fill Color 0,0,0

	Shape=Path Font.[&Title.Character1].Glyph|Offset ([&Font.[&Title.Character1].Advance]+[&Font.[&Title.Character2].Advance]+[&Font.[&Title.Character3].Advance]),0|Extend SharedModifiers
	Shape2=Path Font.[&Title.Character2].Glyph|Offset ([&Font.[&Title.Character2].Advance]+[&Font.[&Title.Character3].Advance]),0|Extend SharedModifiers
	Shape3=Path Font.[&Title.Character3].Glyph|Offset ([&Font.[&Title.Character3].Advance]),0|Extend SharedModifiers

  Font.A.Glyph=[&Font.A.Glyph]
  ; Shape4=Combine Shape | Union Shape2 | Union Shape3 | Scale 0.2,0.2

---Meters---

[TopmenuFrame]
	Meter=Shape
	MeterStyle=Topmenu.Frame
	DynamicVariables=1
	X=([#WORKAREAWIDTH]-100-[TopmenuFrame:W])
	Y=0
Comment out the Shape4 line to see the result. It was more or less about moving the overall "offset" to the X coordinates of the shape. Feel free to adapt it to your preference.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
JHB101101
Posts: 10
Joined: June 24th, 2021, 8:58 am

Re: Shape Meter - Scaling not centered/offset correctly for combined shapes.

Post by JHB101101 »

Hi

@Yincognito

I see what you did, and yes I did leave out a few things. My bad and thanks for the extra effort. I cannot test your code for another few days. Changing the X value of TopmenuFrame is not a solution, since it needs to be full-screen. I have 27 other shapes that are drawn into it. Then I might as well do the math to bring just the title back from the scale, but that will imply a work-around for a bug.

Kind Regards

Jayson
User avatar
Yincognito
Rainmeter Sage
Posts: 7199
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Shape Meter - Scaling not centered/offset correctly for combined shapes.

Post by Yincognito »

JHB101101 wrote: June 25th, 2021, 1:57 pmChanging the X value of TopmenuFrame is not a solution, since it needs to be full-screen. I have 27 other shapes that are drawn into it.
It's not a bug. When you scale shapes, ALL of those shape parameters are automatically "scaled" as well ... including the result of your W (idth) formula that make up the letter offsets - that's why you don't need to bother with the offsets there in the first place, since they are taken care of automatically when scaling. But since you don't want to change the X value of TopmenuFrame (though I can't understand why, after all you can draw shapes on shapes, e.g. those letter shapes on a full screen shape background, but then, you know best what you can or will do), you can Offset the combined shape instead, according to the total length of the shaped letter text:

Code: Select all

[Variables]
Topmenu_Title_Text="AAA"

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
BackgroundMode=2
SolidColor=47,47,47,255

---Measures---

[Font.A.Glyph]
	Measure=String
	String="0,16|ArcTo 16,0,16|LineTo 26,0|ArcTo 42,16,16|LineTo 42,100|LineTo 26,100|LineTo 26,58|LineTo 16,58|LineTo 16,42|LineTo 26,42|LineTo 26,21|ArcTo 16,21,5,*,*,1|LineTo 16,100|LineTo 0,100|ClosePath 1"
[Font.A.Advance]
	Measure=String
	String=47

[Title.Characters]
	Measure=String
	DynamicVariables=1
	RegExpSubstitute=1
	String=[#Topmenu_Title_Text]
	Substitute="[^ a-zA-Z0-9]":""
	OnUpdateAction=[!UpdateMeasure Title.Character1][!UpdateMeasure Title.Character2][!UpdateMeasure Title.Character3][!UpdateMeter TopmenuFrame][!Redraw]

[Title.Character1]
	Measure=String
	DynamicVariables=1
	RegExpSubstitute=1
	IfMatchMode=1
	String=[&Title.Characters]
	Substitute="^(.).*$":"\1"," ":"Space","":"None"

[Title.Character2]
	Measure=String
	Group=TitleCharacters
	DynamicVariables=1
	RegExpSubstitute=1
	IfMatchMode=1
	String=[&Title.Characters]
	Substitute="^.{1}(.).*$":"\1","[&Title.Characters]":""," ":"Space","":"None"

[Title.Character3]
	Measure=String
	DynamicVariables=1
	RegExpSubstitute=1
	IfMatchMode=1
	String=[&Title.Characters]
	Substitute="^.{2}(.).*$":"\1","[&Title.Characters]":""," ":"Space","":"None"

---Styles---

[Topmenu.Frame]
	DynamicVariables=1
	SharedModifiers=StrokeWidth 0|Fill Color 0,0,0

	Shape=Path Font.[&Title.Character1].Glyph|Offset ([&Font.[&Title.Character1].Advance]+[&Font.[&Title.Character2].Advance]+[&Font.[&Title.Character3].Advance]),0|Extend SharedModifiers
	Shape2=Path Font.[&Title.Character2].Glyph|Offset ([&Font.[&Title.Character2].Advance]+[&Font.[&Title.Character3].Advance]),0|Extend SharedModifiers
	Shape3=Path Font.[&Title.Character3].Glyph|Offset ([&Font.[&Title.Character3].Advance]),0|Extend SharedModifiers

  Font.A.Glyph=[&Font.A.Glyph]
  Shape4=Combine Shape | Union Shape2 | Union Shape3 | Offset ([&[#CURRENTSECTION]:W]-100-([&Font.[&Title.Character1].Advance]+[&Font.[&Title.Character2].Advance]+[&Font.[&Title.Character3].Advance])),0 | Scale 0.2,0.2

---Meters---

[TopmenuFrame]
	Meter=Shape
	MeterStyle=Topmenu.Frame
	DynamicVariables=1
	X=0
	Y=0
	W=[#WORKAREAWIDTH]
	H=[#WORKAREAHEIGHT]
Now if you don't like this either, I don't know what to say...

P.S. You can even specify the order of transformations, if you really really want to control that aspect as well, see here.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
JHB101101
Posts: 10
Joined: June 24th, 2021, 8:58 am

Re: Shape Meter - Scaling not centered/offset correctly for combined shapes.

Post by JHB101101 »

Hi
It's not a bug. When you scale shapes, ALL of those shape parameters are automatically "scaled" as well ... including the result of your W (idth) formula that make up the letter offsets - that's why you don't need to bother with the offsets there in the first place, since they are taken care of automatically when scaling.
Help Documentation: The scaling is done either from the center of the shape (default), or optional X,Y anchor points in pixels relative to the top left of the shape.
I understand what you are saying, and will find a way around it. Thank you for all the help. This unfortunately is a bug, since it is only 3 of 27 shapes in the meter. Why change the meter's X or have to add an offset to the shapes. It should simply center where it is like your first example. The fact that I am calculating an offset from the back should not be any different than what you did. It is simply an valid offset.

Kind Regards

Jayson
User avatar
Yincognito
Rainmeter Sage
Posts: 7199
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Shape Meter - Scaling not centered/offset correctly for combined shapes.

Post by Yincognito »

JHB101101 wrote: June 25th, 2021, 5:22 pmI understand what you are saying, and will find a way around it. Thank you for all the help. This unfortunately is a bug, since it is only 3 of 27 shapes in the meter. Why change the meter's X or have to add an offset to the shapes. It should simply center where it is like your first example. The fact that I am calculating an offset from the back should not be any different than what you did. It is simply an valid offset.
Good luck in finding a way around it that you like. I already found not one but 2 such ways, but if you're unwilling to use either, it's your choice. :confused: If you think it's a bug, feel free to post it in the Bugs & Feature Suggestions section of the forum - I'd be interested to see how the devs see this, although I kind of know what the answer will be, see below.

Now as far as the technical part is concerned: you said perfectly well that the manual says that "the scaling is done either from the center of the shape" in this case, since you didn't specify more than the 2 basic parameters, aka the horizontal and the vertical scale factors. However, the center of the shape is NOT the center of those 3 letters you drew, it's half the W (idth) you set yourself, aka W=[#WORKAREAWIDTH], minus the 100 pixels you subtract from it in the shapes, and minus the 5 px "margin" in your letters (i.e. 47 - 42 = 5) which are transparent, because you go from 0, i.e. the X, to the last opaque pixel of the shape(s), which is at ([#WORKAREAWIDTH]-100-5), because of this. The H (eight) is just 100 px, because of the same linked reason, i.e. from X to the last opaque / solid pixel of the shape, vertically. That is precisely the reason why the 0.2,0.2 scaling moves the letters to the left, because Rainmeter will scale things in reference to ([#WORKAREAWIDTH]-100-5), (100/2), which is the actual center of your shape. It has nothing to do with the center of the letters, and it explains why things were properly centered in my initial attempt, where I didn't touch the W and H of the meter (I never do for shapes, unless I want to set some "room" for a rotation and such).

So, again, this is not a bug, it's the expected behavior. If you want to have stuff all over your screen, draw a background meter first, and then put the other shapes on top of it.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
JHB101101
Posts: 10
Joined: June 24th, 2021, 8:58 am

Re: Shape Meter - Scaling not centered/offset correctly for combined shapes.

Post by JHB101101 »

Hi Yincognito

WOW!

I do not claim to understand all you have written, but I do understand this:

An inline Scale command only affects the shape. If I set it on a single letter it does it correctly no matter how I set the Offset. When I Combine a few shapes together the same should happen. It does not! I mean the shapes did not move after the combine. The X,Y,W,H of the original meter did not change.

I do not understand your aggression in this matter.

Kind Regards

Jayson
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm

Re: Shape Meter - Scaling not centered/offset correctly for combined shapes.

Post by death.crafter »

JHB101101 wrote: June 25th, 2021, 8:05 pm I do not understand your aggression in this matter.
Please do not misunderstand him. He is a rather helpful guy.

And he is correct at what he says. Somethings can't be helped due to the way they work. So you can go for Yico's solution or find one that suites you.

And post the solution if you find one if your schedule allows you to.

Regards,
death.crafter
from the Realm of Death
User avatar
Yincognito
Rainmeter Sage
Posts: 7199
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Shape Meter - Scaling not centered/offset correctly for combined shapes.

Post by Yincognito »

JHB101101 wrote: June 25th, 2021, 8:05 pmI do not understand your aggression in this matter.
Ok, I said things as they were, as always, I admit (not a fan of lying, you know) - but where was I "aggressive" though? From my side, it felt strange that you chose to dismiss every solution I proposed just because... well, you didn't want to modify some specific parameters, although I presented ways to avoid the shortcommings you mentioned. That's all. Anyway, I fully understand you, I've been in the same situation as you a couple of times on other occasions, so I probably should have refrained from answering in the first place. My bad.
JHB101101 wrote: June 25th, 2021, 8:05 pmIf I set it on a single letter it does it correctly no matter how I set the Offset. When I Combine a few shapes together the same should happen. It does not!
Ah, I see now - you're right. Didn't try for a single letter/shape yet, as I worked with what you provided, so I didn't know. The only explanation I can think of is that an uncombined shape is just that, a shape on its own, which is bounded by the extent of its opaque pixels, hence the "right" centering. When shapes are combined, some operations like automatically closing shapes (and probably others) are performed and things are replaced by the new combined shape, which inherits all kinds of modifiers from the "parent" shape in the new combined structure. Maybe this is one of those differences, but all I know is that my explanation regarding the width and height of the combined shape is correct, and it's why you noticed the "jump to the left" of the scaled letters. Whether that should happen or not, that's a different story, and opinions will abound on it. Like I said, if you think this is a bug, post it in the appropriate section. Don't be shy, just look at the last bug report there (opinions are divided on it as well) ... it's from none other than me. We're in the same boat. :D
JHB101101 wrote: June 25th, 2021, 8:05 pmThe X,Y,W,H of the original meter did not change.
Hmm.. I don't know about that, I have some doubts regarding the W. Even if you were right on this, these coordinates bear a bit less relevance than usual for Shape meters, where things basically revolve around opaque vs transparent pixels. Anyway, I'm not 100% sure on this one, so I won't pretend I do.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
JHB101101
Posts: 10
Joined: June 24th, 2021, 8:58 am

Re: Shape Meter - Scaling not centered/offset correctly for combined shapes.

Post by JHB101101 »

Hi
I am sorry, but all the solutions given here are work-arounds for the actual bug. How can I use them?!? If your initial post (Help text) worked fine, then my 'code' should work fine too. Not right?
User avatar
Yincognito
Rainmeter Sage
Posts: 7199
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Shape Meter - Scaling not centered/offset correctly for combined shapes.

Post by Yincognito »

JHB101101 wrote: June 25th, 2021, 9:41 pmI am sorry, but all the solutions given here are work-arounds for the actual bug. How can I use them?!? If your initial post (Help text) worked fine, then my 'code' should work fine too. Not right?
Ok, let's be blunt about this - no "aggression" or any such things intended, LOL. My role here, as far as I understand it, is to help you find solutions that work (which I did). They might be workarounds, if this proves to be a bug (not my place to make such decisions, although I can have opinions about it, like everyone else, you included), but they do the job. If you're looking for "pure solutions" - believe me, I'm a fan of those much more than you are, so I fully agree with the principle - you'd have to take this "higher up on the ladder", so to speak, to the developers. I, and others like me who help here, can only do so much. We can't rewrite the Shape implementation on our own - I mean, we could, for sure, but it won't be the same as being "official" and all that.

I agree that your code should work fine too, not sure if in that form though. From a logical point of view what you say makes sense, but common sense logic is not always the criteria on which something is considered a bug or not. Sometimes, unfortunately, even if the behavior is "strange", modifications are not operated in order not to break backward compatibility (imagine the amount of skins that would be affected by such a change). So, what I'm saying is that it's not always black or white, although personally I would like that.

That being said, maybe someone else will come up with a solution that "fits the bill" - who knows. Me, I tried what I could think of - sorry of not being able to help you in an acceptable way (you know what I mean by this). :confused:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth