# Converting Coordinates To Different Aspect Ratios

## Recommended Posts

Hi,

I'm currently developing a program that uses a 16:9 aspect ratio and I'm wondering there is an easier way than hand jamming new coordinates for 4:3 aspect ratio. I've been searching the forums and googling all over and can't seem to find a good solution. I found this example below but its not working as intended. Thanks in advance...

```Func CoordSwitch(\$coordx0, \$coordy0)
;16:9
Call("DesktopResolution")
If \$Resolution = "1920x1080" Or \$Resolution = "1600x900" Or \$Resolution = "1366x768" Or \$Resolution = "1360x768" Or \$Resolution = "1280x720" Then
\$OriginalXCoord = \$coordx0
\$OriginalYCoord = \$coordy0
\$ResolutionXorY = StringSplit(\$Resolution, "x")
\$AdjustedXCoord = (\$ResolutionXorY / 1920) * \$OriginalXCoord
\$AdjustedYCoord = (\$ResolutionXorY / 1080) * \$OriginalYCoord

EndIf
; 16:10
If \$Resolution = "1680x1050" Or \$Resolution = "1440x900" Or \$Resolution = "1280x800" Then
\$OriginalXCoord = \$coordx0
\$OriginalYCoord = \$coordy0
\$ResolutionXorY = StringSplit(\$Resolution, "x")
\$AdjustedXCoord = (\$ResolutionXorY / 1680) * \$OriginalXCoord
\$AdjustedYCoord = (\$ResolutionXorY / 1050) * \$OriginalYCoord
EndIf
; 4:3 Resoltions
If \$Resolution = "1400x1050" Or \$Resolution = "1360x1024" Or \$Resolution = "1280x960" Or \$Resolution = "1152x864" Or \$Resolution = "1024x768" Or \$Resolution = "800x600" Then
\$OriginalXCoord = \$coordx0
\$OriginalYCoord = \$coordy0
\$ResolutionXorY = StringSplit(\$Resolution, "x")
\$AdjustedXCoord = (\$ResolutionXorY / 1400) * \$OriginalXCoord
\$AdjustedYCoord = (\$ResolutionXorY / 1050) * \$OriginalYCoord
EndIf
EndFunc

Func DesktopResolution()
Switch \$resolution = ""
Case @DesktopWidth = 800 And @DesktopHeight = 600
\$resolution = "800x600"
Case @DesktopWidth = 1024 And @DesktopHeight = 768
\$resolution = "1024x768"
Case @DesktopWidth = 1152 And @DesktopHeight = 864
\$resolution = "1152x864"
Case @DesktopWidth = 1280 And @DesktopHeight = 720
\$resolution = "1280x720"
Case @DesktopWidth = 1280 And @DesktopHeight = 800
\$resolution = "1280x800"
Case @DesktopWidth = 1280 And @DesktopHeight = 960
\$resolution = "1280x960"
Case @DesktopWidth = 1360 And @DesktopHeight = 768
\$resolution = "1360x768"
Case @DesktopWidth = 1366 And @DesktopHeight = 768
\$resolution = "1366x768"
Case @DesktopWidth = 1440 And @DesktopHeight = 900
\$resolution = "1440x900"
Case @DesktopWidth = 1400 And @DesktopHeight = 1050
\$resolution = "1440x900"
Case @DesktopWidth = 1600 And @DesktopHeight = 900
\$resolution = "1600x900"
Case @DesktopWidth = 1920 And @DesktopHeight = 1080
\$resolution = "1920x1080"
Case Else
Return SetError(1, 0, \$resolution)
EndSwitch
Return \$resolution
EndFunc```
##### Share on other sites

```CoordSwitch(\$coordx0, \$coordy0)

Func CoordSwitch(\$OriginalXCoord, \$OriginalYCoord)

\$DW = @DesktopWidth
\$DH = @DesktopHeight

Switch \$DW & 'x' & \$DH
Case "1920x1080", "1600x900", "1366x768", "1360x768", "1280x720" ;16:9
\$AdjustedXCoord = (\$DW / 1920) * \$OriginalXCoord
\$AdjustedYCoord = (\$DH / 1080) * \$OriginalYCoord
Case "1680x1050", "1440x900", "1280x800" ; 16:10
\$AdjustedXCoord = (\$DW / 1680) * \$OriginalXCoord
\$AdjustedYCoord = (\$DH / 1050) * \$OriginalYCoord
Case "1400x1050", "1360x1024", "1280x960", "1152x864", "1024x768", "800x600" ; 4:3
\$AdjustedXCoord = (\$DW / 1400) * \$OriginalXCoord
\$AdjustedYCoord = (\$DH / 1050) * \$OriginalYCoord
Case Else
MsgBox(0, '???', \$DW & 'x' & \$DH)
EndSwitch
EndFunc```
##### Share on other sites

I tried editing my post to take that other function out, didn't realize it was in there when I posted. Other than that this will operate the exact same way as the one I posted..Thanks for the cleanup though.

##### Share on other sites

```CoordSwitch(100, 100, 1280, 800)

Func CoordSwitch(\$X, \$Y, \$W, \$H) ;  \$W, \$H - Original

; MouseClick("Left", @DesktopWidth / \$W * \$X, @DesktopHeight / \$H * \$Y, 1)

MsgBox(0, 'Coord', 'x = '&@DesktopWidth / \$W * \$X &@CRLF& 'y = '&@DesktopHeight / \$H * \$Y)

EndFunc```

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...