Hi,
I'm back with a new problem/error.
I've just reworked my menu system so that it scales with the resolution/window size. But it no longer works properly with small resolutions (e.g. 640x480). Since I don't know whether the problem is with me or with the ASFML, I'll explain my strange solution for a menu system.
The graphics task:
First it is checked if the area of the view is smaller than the current resolution and if so the area is set to the current resolution. The initial value of the area is (5.00, 5.00) and the later values depend on the text calculations that come later. Then I set the view to the calculated area and the center to half of the axes accordingly. Then the various properties for the text are set, followed by the text position. When positioning the text, all lines that should be selectable are then written into an array using Sf.Graphics.Text.getGlobalBounds. The text positioning function then returns the height and width, which is then used to calculate the new area of the view on the next run.
The logic task:
It reads the written value from the array and checks whether the current mouse position is in it. If so, you can select the option and the text will be colored green.
The whole thing works without errors at high resolutions (eg 1600x1000). Scaling up is also not a problem. When scaling down, however, it only works correctly up to a certain resolution, the resolution up to which it works depends on the text width and number of lines. Below this resolution, the text will still display/scale correctly, but the position for selection will start to shift to the right, down, or right down, depending on how you scale. Picture 1 shows how it is correct at high resolutions, pictures 2 and 3 then the shift at low resolutions.
I've been looking for the error for some time now and I noticed that the local bounds and global bounds never match the set position, unless the string to be set is empty. So if I set a text to position (0.00, 0.00), then the text position is (0.00, 0.00), but value of top and left are always slightly larger than 0.00, regardless of whether I get the values with getLocalBounds or getGlobalBounds. This discrepancy looks like a mistake to me. Which is why I'm now wondering if the text positioning and bounds queries are wrong or if my system is just crap.
Hope you understand halfway what I mean, even if the explanation is probably unnecessarily long.
Pictures



Hi,
I'm back with a new problem/error.
I've just reworked my menu system so that it scales with the resolution/window size. But it no longer works properly with small resolutions (e.g. 640x480). Since I don't know whether the problem is with me or with the ASFML, I'll explain my strange solution for a menu system.
The graphics task:
First it is checked if the area of the view is smaller than the current resolution and if so the area is set to the current resolution. The initial value of the area is (5.00, 5.00) and the later values depend on the text calculations that come later. Then I set the view to the calculated area and the center to half of the axes accordingly. Then the various properties for the text are set, followed by the text position. When positioning the text, all lines that should be selectable are then written into an array using Sf.Graphics.Text.getGlobalBounds. The text positioning function then returns the height and width, which is then used to calculate the new area of the view on the next run.
The logic task:
It reads the written value from the array and checks whether the current mouse position is in it. If so, you can select the option and the text will be colored green.
The whole thing works without errors at high resolutions (eg 1600x1000). Scaling up is also not a problem. When scaling down, however, it only works correctly up to a certain resolution, the resolution up to which it works depends on the text width and number of lines. Below this resolution, the text will still display/scale correctly, but the position for selection will start to shift to the right, down, or right down, depending on how you scale. Picture 1 shows how it is correct at high resolutions, pictures 2 and 3 then the shift at low resolutions.
I've been looking for the error for some time now and I noticed that the local bounds and global bounds never match the set position, unless the string to be set is empty. So if I set a text to position (0.00, 0.00), then the text position is (0.00, 0.00), but value of top and left are always slightly larger than 0.00, regardless of whether I get the values with getLocalBounds or getGlobalBounds. This discrepancy looks like a mistake to me. Which is why I'm now wondering if the text positioning and bounds queries are wrong or if my system is just crap.
Hope you understand halfway what I mean, even if the explanation is probably unnecessarily long.
Pictures