gui.screen_to_local doesn’t take into account node’s scale
Hi! I decided to add a checkbox (“Large interface”) that sets the scale of all windows to 1.75. But when scaling the window, the slider works incorrectly
The slider’s code uses gui.screen_to_local(slider, vmath.vector3(action.screen_x, action.screen_y, 0)) to convert the screen position to the local position
I think the slider works incorrectly because gui.screen_to_local doesn’t take into account node’s scale. Yes, i can divide the position by the node’s scale manually but i want gui.screen_to_local to do it on its own
What’s the rest of the code that the slider uses to determine 0% from 100%?
I think screen_to_local uses the current GUI scene or the parent node as the “local”, so if the scene is the same size and position as the screen there won’t be any difference between action.x and action.screen_x (or screen_to_local) for a parent-less node. But if the parent scales, you need to scale the reference too.
Here’s a quick example that I hope shows what I mean: as you scale the parent, the boundaries tend towards 0 and screen_size, but screen_to_local always == screen_x (unless you change the size of the window).
But if you track the child, 0,0,0 remains constant and the boundaries tend towards -infinity and infinity. So for a slider, you would also need to scale the maximum and minimum x (at least in center pivot)
I fixed this problem by dividing screen position by recursive node size
Fixed code: pathed.zip (3.2 KB)
To get code with the bug, delete lines 14 - 16 in scale.lua
From what I can see, you never seem to apply the current scale to the slider node. Specifically, you don’t scale self.data.offset_x or self.data.offset_y - which is why the slider stays at the old size.
During init() you set them with this code (lines 108 - 114):
self.data.size=gui.get_size(self.data.nodes._)
if pivot>=2 and pivot<=4 then self.data.offset_x=-self.data.size.x
elseif pivot==1 or pivot==0 or pivot==5 then self.data.offset_x=-self.data.size.x/2
end
if pivot==8 or pivot==1 or pivot==2 then self.data.offset_y=-self.data.size.y
elseif pivot==7 or pivot==0 or pivot==3 then self.data.offset_y=-self.data.size.y/2
end
Which is also not accounting for scale if you reinitialize, because nodes stay a constant size when scaled.
Also keep in mind that a child node’s scale property is its relative size to the parent node. So offset_x = offset_x * gui.get_scale(slider) will almost certainly shrink your slider, and if it has a parent its scale is relative to its parent… so you’ll still need get_scale_recursively() But at least it won’t be on every input!