1

I have a program which does some things using previously set coordinates. I want to make my program more user-friendly. How to get relative coordinates if a screen dimension or another setting is changed? How to take into account these changes?

Example:

I have 1920x1080 screen with set coordinates x=1400, y=800. I need to get the same point on 1600x900 screen e.g. And how to take into consideration other screen settings (dpi, nvidia panel settings etc)?

What ways is there to do it?

I think about using percents to calculate coordinates

1 Answer 1

0

If you have a point of known coordinates, then you can work out where it is as a proportion of screen size:

x_percentage = desired_x_coordinate / x_pixel_count
y_percentage = desired_y_coordinate / y_pixel_count

If you make a function to work out those proportions for whatever position you want, then you can just multiply by the resolution of the other screen to get the pixel co-ordinates for that monitor.

etc. with your example:

def calc_proportion(desired_coordinate, 1D_resolution):
    return desired_coordinate / 1D_resolution

x_percentage = calc_proportion(1400, 1080)
y_percentage = calc_proportion(800, 1920)

new_x_coord = x_percentage * 900
new_y_coord = y_percentage * 1600

Which should give the coordinates: x = 1167 and y = 667, for your other monitor in the example.

This function is of course easily generalisable to work in 2D and do more calculations for you for whatever language you are using.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.