Jump to content

Calculate New position and size of a Rect


Recommended Posts

I trying calculate the new position and size of a rect in diferent gui sizes. Here`s my function

$aRect = _Convert(10,10,20,20,800,600,1024,768)

MsgBox(0,"","Left: " & $aRect[0] & @CRLF & "Top: " & $aRect[1] & @CRLF & "Widht: " & $aRect[2] & @CRLF & "Height: " & $aRect[3])

Func _Convert($iLeft,$iTop,$iWidht,$iHeight,$iSResWidht,$iSResHeight,$iDResWidht,$iDResHeight)

Local $aRect[4]

$iPercentX = $iDResWidht / $iSResWidht
$iPercentY = $iDResHeight / $iSResHeight

$aRect[0] = $iLeft * $iPercentX
$aRect[1] = $iTop * $iPercentY
$aRect[2] = $iWidht * $iPercentX
$aRect[3] = $iHeight * $iPercentY

Return $aRect

EndFunc;_Convert

Someone can tell me if it returning exactly. Thanks in advance

Link to comment
Share on other sites

How should the result look like when the ratio of the destination dimension is different, e.g. 1920x1080?

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Looks working. See

$aRect = _Convert(10,10,20,20,102.4,80,192,108)

;MsgBox(0,"","Left: " & $aRect[0] & @CRLF & "Top: " & $aRect[1] & @CRLF & "Widht: " & $aRect[2] & @CRLF & "Height: " & $aRect[3])

Func _Convert($iLeft,$iTop,$iWidht,$iHeight,$iSResWidht,$iSResHeight,$iDResWidht,$iDResHeight)

Local $aRect[4]

$iPercentX = $iDResWidht / $iSResWidht
$iPercentY = $iDResHeight / $iSResHeight

$aRect[0] = $iLeft * $iPercentX
$aRect[1] = $iTop * $iPercentY
$aRect[2] = $iWidht * $iPercentX
$aRect[3] = $iHeight * $iPercentY

Return $aRect

EndFunc;_Convert

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 900,450,-1,-1)
GUISetState(@SW_SHOW)

GUICtrlCreateGraphic(1,1,102.4,80)
GUICtrlSetBkColor(-1,0x0000FF)
GUICtrlSetState(-1,$GUI_DISABLE)

GUICtrlCreateGraphic(10,10,20,20)
GUICtrlSetBkColor(-1,0xFF0000)

GUICtrlCreateGraphic(450,1,192,108)
GUICtrlSetBkColor(-1,0x0000FF)
GUICtrlSetState(-1,$GUI_DISABLE)

GUICtrlCreateGraphic(450+$aRect[0],$aRect[1],$aRect[2],$aRect[3])
GUICtrlSetBkColor(-1,0xFF0000)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd
Link to comment
Share on other sites

If this is the result you are expecting then it is ok.

I thought the ration of the red square should be the same after resize.

 

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...