J
J
Jay Marlow2018-09-25 22:32:12
Mathematics
Jay Marlow, 2018-09-25 22:32:12

How to adapt coordinates to different window resolutions?

Good day.
The question is most likely very stupid, but my school and university mathematics skills refuse to help in this matter. Maybe I'm just stupid someone will still help in this matter.
Essence:
There is an application window with a size of 1024x768. In it (only for example) in the center there is a button at coordinates 512x384. The fact that it is in the center in this case is for example and convenience, and it can be anywhere, but its coordinates relative to a 1024x768 window are known.
Next, there is a window of the same application, but the size is 1920x1080. It also has the same button in the center, but its coordinates are not known in this case.
Is it possible to find out the position of a button in a window of size 1920x1080, while it is known that this button in a window of size 1024x768 is located at coordinates 512x384?

Window size 1 = 1024x768
Button A = 512x384

Window size 1 = 1920x1080
Button A = ?

I ask for any help and advice.
PS There are no automatic ways to adapt, you need to calculate (if at all possible) by hand.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
Griboks, 2018-09-25
@kolumbou

Use relative coordinates (which are percentages of the window size).

G
GavriKos, 2018-09-26
@GavriKos

The fact that it is in the center in this case is for example and convenience, and it can be anywhere, but its coordinates relative to a 1024x768 window are known.

Relative to what part of the window?
There is an approach using anchor - when, in addition to the coordinate, it is also stored relative to which part of the parent object it is considered.
And then the coordinates of the button in the center of ANY window will be - (0,0).
And then the question of design - where and how you need to nail which elements.

V
vaut, 2018-09-26
@vaut

The simplest proportion:
x1/x2=Xmax1/Xmax2
from there
x2 = x1 * Xmax2/Xmax1
x1=512 old x-coordinate
x2=? new x-coordinate
Xmax1=1024 old window x-size, it is also the maximum coordinate
Xmax2=1920 new window x-size
x2=512*1920/1024=960

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question