Calcule les coordonnées des transformés des points d'une liste par une rotation de centre et d'angle spécifiés
#include <WinAPIGdi.au3>
_WinAPI_RotatePoints ( ByRef $aPoint, $iXC, $iYC, $fAngle [, $iStart = 0 [, $iEnd = -1]] )
$aPoint | Le tableau 2D ([x1, y1,...], [x2, y2,...],..., [xN, yN,...]). Chacune des premières paires d'éléments de ce tableau contient un point à pivoter. Les autres éléments du tableau (s'il y en a) restent inchangés. |
$iXC | La coordonnée x du centre de la rotation, en unités logiques. |
$iYC | La coordonnée y du centre de la rotation, en unités logiques. |
$fAngle | L'angle de la rotation, en degrés. |
$iStart | [optionnel] L'index du tableau où commencer la rotation des points. |
$iEnd | [optionnel] L'index du tableau où arrêter la rotation des points. |
Succès: | Retourne 1. |
Échec: | Retourne 0 et définit @error <> 0. |
Cette fonction n'arrondit pas les valeurs des coordonnées après transformation, elles peuvent être du type float.
#include <GUIConstantsEx.au3> #include <SendMessage.au3> #include <SliderConstants.au3> #include <StaticConstants.au3> #include <WinAPIGdi.au3> #include <WinAPIGdiDC.au3> #include <WinAPIHObj.au3> #include <WinAPIMisc.au3> #include <WinAPIRes.au3> #include <WinAPISysWin.au3> #include <WindowsConstants.au3> Opt('TrayAutoPause', 0) ; Charger l'image Global $g_hBitmap = _WinAPI_LoadImage(0, @ScriptDir & '\Extras\Compass.bmp', $IMAGE_BITMAP, 0, 0, $LR_LOADFROMFILE) Local $tSIZE = _WinAPI_GetBitmapDimension($g_hBitmap) Local $W = DllStructGetData($tSIZE, 'X') Local $H = DllStructGetData($tSIZE, 'Y') ; Créer GUI Global $g_hForm = GUICreate('Test '& StringReplace(@ScriptName, '.au3', '()'), $W, $H + 26) Global $g_idPic = GUICtrlCreatePic('', 0, 0, $W, $H) GUICtrlCreateGraphic(0, $H, $W, 1) GUICtrlSetBkColor(-1, 0xDFDFDF) Global $g_idSlider = GUICtrlCreateSlider(0, $H + 1, $W, 25, BitOR($TBS_BOTH, $TBS_NOTICKS)) Global $g_hSlider = GUICtrlGetHandle(-1) GUICtrlSetLimit(-1, 360, 0) GUICtrlSetData(-1, 0) ; Définir bitmap à contrôler avec rotation _SetBitmapRotate($g_idPic, $g_hBitmap, 0) ; Créer WM_HSCROLL un message pour un défilement en direct et spectacle GUI GUIRegisterMsg($WM_HSCROLL, 'WM_HSCROLL') GUISetState(@SW_SHOW) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func _SetBitmapRotate($hWnd, $hBitmap, $iAngle) If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) If Not $hWnd Then Return 0 EndIf EndIf Local $aW[2], $aH[2] Local $aPoint[3][2] Local $tRECT = _WinAPI_GetClientRect($hWnd) $aW[0] = DllStructGetData($tRECT, 3) - DllStructGetData($tRECT, 1) $aH[0] = DllStructGetData($tRECT, 4) - DllStructGetData($tRECT, 2) Local $tSIZE = _WinAPI_GetBitmapDimension($g_hBitmap) $aW[1] = DllStructGetData($tSIZE, 1) $aH[1] = DllStructGetData($tSIZE, 2) $aPoint[0][0] = ($aW[0] - $aW[1]) / 2 $aPoint[0][1] = ($aH[0] - $aH[1]) / 2 $aPoint[1][0] = $aPoint[0][0] + $aW[1] $aPoint[1][1] = $aPoint[0][1] $aPoint[2][0] = $aPoint[0][0] $aPoint[2][1] = $aPoint[0][1] + $aH[1] Local $hDC = _WinAPI_GetDC($hWnd) Local $hDestDC = _WinAPI_CreateCompatibleDC($hDC) Local $hMask = _WinAPI_CreateBitmap($aW[0], $aH[0], 1, 1) Local $hDestSv = _WinAPI_SelectObject($hDestDC, $hMask) Local $hBrush = _WinAPI_SelectObject($hDestDC, _WinAPI_GetStockObject($DC_BRUSH)) Local $hPen = _WinAPI_SelectObject($hDestDC, _WinAPI_GetStockObject($DC_PEN)) _WinAPI_SetDCBrushColor($hDestDC, 0xFFFFFF) _WinAPI_SetDCPenColor($hDestDC, 0xFFFFFF) _WinAPI_Ellipse($hDestDC, _WinAPI_CreateRectEx($aPoint[0][0] + 43, $aPoint[0][1] + 43, $aPoint[1][0] - 86, $aPoint[2][1] - 86)) Local $hBmp = _WinAPI_CreateCompatibleBitmapEx($hDC, $aW[0], $aH[0], 0xFFFFFF) _WinAPI_SelectObject($hDestDC, $hBrush) _WinAPI_SelectObject($hDestDC, $hPen) _WinAPI_SelectObject($hDestDC, $hBmp) Local $hSrcDC = _WinAPI_CreateCompatibleDC($hDC) Local $hSrcSv = _WinAPI_SelectObject($hSrcDC, $hBitmap) _WinAPI_RotatePoints($aPoint, $aW[0] / 2, $aH[0] / 2, $iAngle) _WinAPI_PlgBlt($hDestDC, $aPoint, $hSrcDC, 0, 0, $aW[1], $aH[1]) _WinAPI_RotatePoints($aPoint, $aW[0] / 2, $aH[0] / 2, -2 * $iAngle) _WinAPI_PlgBlt($hDestDC, $aPoint, $hSrcDC, 0, 0, $aW[1], $aH[1], $hMask) _WinAPI_SelectObject($hDestDC, $hDestSv) _WinAPI_DeleteDC($hDestDC) _WinAPI_SelectObject($hSrcDC, $hSrcSv) _WinAPI_DeleteDC($hSrcDC) _WinAPI_DeleteObject($hMask) _WinAPI_ReleaseDC($hWnd, $hDC) Local $hObj = _SendMessage($hWnd, $STM_SETIMAGE, $IMAGE_BITMAP, $hBmp) If $hObj Then _WinAPI_DeleteObject($hObj) EndIf $hObj = _SendMessage($hWnd, $STM_GETIMAGE) If $hObj <> $hBmp Then _WinAPI_DeleteObject($hBmp) EndIf Return 1 EndFunc ;==>_SetBitmapRotate Func WM_HSCROLL($hWnd, $iMsg, $wParam, $lParam) #forceref $iMsg, $wParam, $lParam If $hWnd = $g_hForm Then If $lParam = $g_hSlider Then _SetBitmapRotate($g_idPic, $g_hBitmap, GUICtrlRead($g_idSlider)) EndIf EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_HSCROLL