Obtient le rectangle qui délimite un objet GraphicsPath
#include <GDIPlus.au3>
_GDIPlus_PathGetWorldBounds ( $hPath [, $hMatrix = 0 [, $hPen = 0]] )
$hPath | Handle de l'objet GraphicsPath |
$hMatrix | [optionnel] Handle de l'objet Matrix qui spécifie une transformation à appliquer à ce GraphicsPath avant que le rectangle de délimitation soit calculé. Le chemin ne se transforme pas en permanence |
$hPen | [optionnel] Handle de l'objet Pen qui influe sur la taille du rectangle de délimitation. Les limites du rectangle délimitant seront suffisamment grandes pour englober le GraphicsPath quand il sera dessiné avec le crayon spécifié. |
Succès: | Retourne un tableau contenant les coordonnées du rectangle et ses dimensions: [0] - Coordonnée X du rectangle [1] - Coordonnée Y du rectangle [2] - Largeur du rectangle [3] - Hauteur du rectangle |
Échec: | Définit @error <> 0, @extended contient le code erreur GPSTATUS ($GPID_ERR*). |
Consultez GdipGetPathWorldBounds dans la Librairie MSDN.
#include <GDIPlus.au3> #include <GUIConstantsEx.au3> Example() Func Example() Local $iW, $iH, $hGUI, $hGraphic, $hBrush, $hPen, $hPath, $hFamily, $tLayout, $hMatrix, $aBounds ; Crée une GUI $iW = 640 $iH = 220 $hGUI = GUICreate("GDI+", $iW, $iH) GUISetState(@SW_SHOW) ; Dessine une chaîne en utilisant un Path _GDIPlus_Startup() $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) ; Crée un objet graphique à partir du handle de la fenêtre _GDIPlus_GraphicsSetSmoothingMode($hGraphic, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ; Définit pour l'objet graphique la qualité de rendu antialiasing _GDIPlus_GraphicsClear($hGraphic, 0xFF000000) $hBrush = _GDIPlus_BrushCreateSolid(0xFFDD2200) $hPen = _GDIPlus_PenCreate(0xFFFFBB00, 2) $hPath = _GDIPlus_PathCreate() ; Crée un objet path $hFamily = _GDIPlus_FontFamilyCreate("Arial") ; Crée un objet FontFamily $tLayout = _GDIPlus_RectFCreate() ; Crée une chaîne encadrée par un rectangle de position X=0, Y=0 _GDIPlus_PathAddString($hPath, "Fit to Window", $tLayout, $hFamily) ; Ajoute le contour de la chaîne au Path ; Transforme le Path pour l'adapter à la fenêtre $aBounds = _GDIPlus_PathGetWorldBounds($hPath) ; Obtient le rectangle de délimitation du Path $hMatrix = _GDIPlus_MatrixCreate() _GDIPlus_MatrixTranslate($hMatrix, -$aBounds[0], -$aBounds[1]) ; Matrice de translation pour l'offset du rectangle de délimitation _GDIPlus_MatrixScale($hMatrix, $iW / $aBounds[2], $iH / $aBounds[3], True) ; Matrice de mise à l'échelle _GDIPlus_PathTransform($hPath, $hMatrix) ; Translate et met à l'échelle le Path _GDIPlus_GraphicsFillPath($hGraphic, $hPath, $hBrush) ; Dessine le Path avec le handle Graphic (GUI) _GDIPlus_GraphicsDrawPath($hGraphic, $hPath, $hPen) ; Dessine le Path avec le handle Graphic (GUI) ; Transforme le tracé pour le centrer _GDIPlus_PathReset($hPath) ; Réinitialise le Path (supprime chaîne précédente) _GDIPlus_PathAddString($hPath, "Center", $tLayout, $hFamily, 0, 100, 0) ; Ajoute le contour de la chaîne au Path $aBounds = _GDIPlus_PathGetWorldBounds($hPath) _GDIPlus_MatrixSetElements($hMatrix, 1, 0, 0, 1, 0, 0) ; Réinitialise la matrice _GDIPlus_MatrixTranslate($hMatrix, ($iW / 2) - $aBounds[0] - ($aBounds[2] / 2), ($iH / 2) - $aBounds[1] - ($aBounds[3] / 2)) _GDIPlus_PathTransform($hPath, $hMatrix) ; Translate (offset) le Path _GDIPlus_BrushSetSolidColor($hBrush, 0x7F004488) _GDIPlus_PenSetColor($hPen, 0xFF00AAFF) _GDIPlus_GraphicsFillPath($hGraphic, $hPath, $hBrush) ; Dessine le Path avec le handle Graphic (GUI) _GDIPlus_GraphicsDrawPath($hGraphic, $hPath, $hPen) ; Dessine le Path avec le handle Graphic (GUI) ; Boucle jusqu'à ce que l'utilisateur quitte. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE ; Nettoie les ressources _GDIPlus_MatrixDispose($hMatrix) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_PathDispose($hPath) _GDIPlus_PenDispose($hPen) _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() EndFunc ;==>Example