Anyway, I recently put together (still putting together) a GUI in which I was asked to change the resolution from 1920x1080 to 1280x720.
Now, in some screens I had done a lot of pixel precise work and used integers, which obviously had to be changed for a different resolution.
So, thinking about what to do, I thought I'd just use float values instead.
To simplify things, say I had an image positioned using integers. For example at 100 pixels on the x axis, and 900 pixels on the y axis.
Code: Select all
xpos 100
ypos 900
A simple solution is to use a float value instead, which will be a percentage of the resolution, instead of a fixed number. So, 0.5 for example, is half the resolution. For 1920x1080, 0.5 would be 960 on the x axis, or 540 on the y axis, and yet for 1280x720 its different, being xpos 640, ypos 360.
So to salvage all your work, and convert an integer to float, all you need to do is take your integer and divide it by your resolution.
For example, in the previous example, an image at 100, 900 would become:
xpos= 100/1920
ypos = 900/1080
Code: Select all
xpos 0.0520833333333333
ypos 0.8333333333333333
Code: Select all
xpos 0.052
ypos 0.834
Or you can use it to find pixel precise positioning in an image editor, and input the value as a float.