Sign in to follow this  
Followers 0
Malkey

Polygon & Closed Curve GDI+ Graphics

8 posts in this topic

#1 ·  Posted (edited)

Using _GDIPlus_GraphicsFillClosedCurve ( ) and _GDIPlus_GraphicsDrawClosedCurve ( ) functions, this graphics display is adjustiable by clicking on a red dot. When the red dot turns green, that point is drabbable.

A right click on the graphics area displays a context menu with the options:-

- Show hide points (Checked show / Unchecked hide),

- Write current points to console (Can be copied, and replace the existing points array in script)

- Toggles Show Closed Curve / Show Polygon

- Show both Closed Curve and Polygon (Checked show both / Unchecked reverts back to above option)

- exit

Enjoy.

#include <GDIPlus.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <misc.au3>
#include <GuiMenu.au3>
#include <WinAPI.au3>

Global Const $iOpacity = 255
;lobal Const $ULW_ALPHA = 2
Global $hGui, $hGraphic, $hBitmap, $hBrush, $hBrush, $SBoth, $GrnPt, $ShowBoth = 0
Global $iFlagSave = 0, $iBkGndColor = 0xFFffff80, $iMinBorder = 25, $bStatFlag = False
Global $dll = DllOpen("user32.dll")
Global $GuiSizeX = @DesktopWidth*3 / 4, $GuiSizeY = @DesktopWidth*3 / 4   ; 200 ;
Global Const $WM_LBUTTONDOWN = 0x0201  ; Drag Window 1 of 3 addin
Global $msg, $exit, $moveAll, $viewpoints, $pointsVisible = 1, $showPolC = 0, $togPolyCurve
;Global $aPoints[20][2] = [[19,0], [323,0],[323,69],[181,69],[256,173],[319,173],[319,225], _
;                          [173,225],[173,173],[230,173],[147,69],[89,152],[120,152],[120,204], _
;                          [11,204],[11,152],[64,152],[120,69],[0,69],[0,0]]
Global $aPoints[20][2] = [[19,0], [309,19],[309,69],[181,69],[256,173],[319,173],[319,225], _
                          [173,225],[173,173],[230,173],[147,69],[89,152],[120,152],[120,204], _
                          [11,204],[11,152],[64,152],[120,69],[38,69],[38,19]]                        

;Global $aPoints[8][2] = [[7,0],[447,422],[164,202],[431,428],[70,233],[327,151],[461,415],[251,176]]   ; 3down
;Global $aPoints[8][2] = [[7,0],[365,403],[432,403],[530,262],[530,213],[357,213],[358,260],[469,260]]  ;seven

Opt("MouseCoordMode", 0)
Opt("GUIOnEventMode", 1)

ClosedCurveOrPolygon()

Func ClosedCurveOrPolygon()
    Local $0nPoint, $mouseDiffX, $mouseDiffY, $MouseStartPos, $pos
    $hGui = GUICreate("GDI+", $GuiSizeX, $GuiSizeY, -1, -1, 0, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
    
    GUIRegisterMsg($WM_LBUTTONDOWN, "_WinMove")    ; Drag Window 2 of 3 addin
    $ContextMenu = GUICtrlCreateContextMenu()
    $viewpoints = GUICtrlCreateMenuItem("Show points", $ContextMenu, 1)
    GUICtrlSetState($viewpoints, $GUI_CHECKED)
    GUICtrlSetOnEvent($viewpoints, "ShowaPoints")
    $SelColor = GUICtrlCreateMenuItem("Change Background Colour", $ContextMenu)
    GUICtrlSetOnEvent($SelColor, "SelectColor")
    $separator1 = GUICtrlCreateMenuItem("", $ContextMenu) ; create a separator line
    $addpoint = GUICtrlCreateMenuItem("Add a point numbered after selected point number", $ContextMenu)
    GUICtrlSetOnEvent($addpoint, "AddPoint")
    $substractpoint = GUICtrlCreateMenuItem("Delete the selected (green) point ", $ContextMenu)
    GUICtrlSetOnEvent($substractpoint, "SubstractPoint")
    $separator1 = GUICtrlCreateMenuItem("", $ContextMenu) ; create a separator line
    $Currentpoints = GUICtrlCreateMenuItem("Write current points to Console", $ContextMenu)
    GUICtrlSetOnEvent($Currentpoints, "CurrentPoints2Console")
    $SaveBitmap = GUICtrlCreateMenuItem("Save as PNG File ", $ContextMenu)
    GUICtrlSetOnEvent($SaveBitmap, "SaveBitmap")
    $Border = GUICtrlCreateMenuItem("Set Space Size around Polygon in Saved Image", $ContextMenu)
    GUICtrlSetOnEvent($Border, "Border")
    $separator1 = GUICtrlCreateMenuItem("", $ContextMenu) ; create a separator line
    $togPolyCurve = GUICtrlCreateMenuItem("Show Closed Curve", $ContextMenu)
    GUICtrlSetOnEvent($togPolyCurve, "TogPol_Curv")
    $SBoth = GUICtrlCreateMenuItem("Show Closed Curve and Polygon", $ContextMenu)
    GUICtrlSetState($SBoth, $GUI_UNCHECKED)
    GUICtrlSetOnEvent($SBoth, "ShowBoth")
    $separator1 = GUICtrlCreateMenuItem("", $ContextMenu) ; create a separator line
    $MenuItemExit = GUICtrlCreateMenuItem("Exit", $ContextMenu)
    GUICtrlSetOnEvent($MenuItemExit, "quitclk") 
    
    GUISetState()
    Draw(0)
    
    Do
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Or $exit = 1 Then ExitLoop
        If _IsPressed("01", $dll) Then  ; Virtual-Key Code (0x01) Left mouse button
            $MouseStartPos = MouseGetPos()
            $0nPoint = CheckOverPoint($MouseStartPos[0], $MouseStartPos[1])  
            $mouseDiffX = 0
            If $0nPoint > 0 Then                
                ToolTip("Point:  " & $0nPoint & @CRLF & "X: " & $aPoints[$0nPoint][0] & _
                    "  Y: " & $aPoints[$0nPoint][1], _ClientToScreen($hGui,$aPoints,$0nPoint,0) - 30, _
                                                    _ClientToScreen($hGui,$aPoints,$0nPoint,1) + 20)
                $moveAll = 1
                Draw($0nPoint)
                $GrnPt = $0nPoint
                While _IsPressed("01", $dll)    ; Virtual-Key Code (0x01) Left mouse button
                    $pos = MouseGetPos()
                    $mouseDiffX = Int(($pos[0] - $MouseStartPos[0]))
                    $mouseDiffY = Int(($pos[1] - $MouseStartPos[1]))
                    If Abs($mouseDiffX) > 0 Or Abs($mouseDiffY) > 0 Then
                        $aPoints[$0nPoint][0] = $pos[0]
                        $aPoints[$0nPoint][1] = $pos[1]
                        Draw($0nPoint)
                        ToolTip("Point:  " & $0nPoint & @CRLF & "X: " & $aPoints[$0nPoint][0] & _
                        "  Y: " & $aPoints[$0nPoint][1], _ClientToScreen($hGui,$aPoints,$0nPoint,0) - 30, _
                                                        _ClientToScreen($hGui,$aPoints,$0nPoint,1) + 20)
                        Sleep(200)
                    EndIf
                    Sleep(20)
                WEnd
                ToolTip("")
            Else
                $moveAll = 0
                Draw(0)
                
            EndIf
        EndIf ; mouse BTN 1 pressed??
        Sleep(20)
    Until _IsPressed("1B")  ; ESC key
    DllClose($dll)
EndFunc   ;==>ClosedCurveOrPolygon

;Check if mouse pointer is over a red/green spot
Func CheckOverPoint($MouseX, $MouseY)
    Local $x, $retValue = 0
    For $x = 1 To $aPoints[0][0]
        If $MouseX < $aPoints[$x][0] + 5 And $MouseX > $aPoints[$x][0] - 5 And _
                $MouseY < $aPoints[$x][1] + 5 And $MouseY > $aPoints[$x][1] - 5 Then
            $retValue = $x
        EndIf
    Next
    Return $retValue
EndFunc   ;==>CheckOverPoint

Func Draw($pt)
    Local $hWnd, $hDC, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend, $hBrushRed, $hBrushGreen,$hPen
    $GrnPt = $pt
    _GDIPlus_Startup ()
    $hWnd = _WinAPI_GetDC (0)
    $hDC = _WinAPI_CreateCompatibleDC ($hWnd)
    $hBitmap = _WinAPI_CreateCompatibleBitmap ($hWnd, $GuiSizeX, $GuiSizeY)
    _WinAPI_SelectObject ($hDC, $hBitmap)
    $hGraphic = _GDIPlus_GraphicsCreateFromHDC ($hDC)
    $hPen = _GDIPlus_PenCreate(0xFF010101,1)
    $hBrush = _GDIPlus_BrushCreateSolid ($iBkGndColor)  ; Random(0xff000000, 0xffffff00, 1))
    $hBrushRed = _GDIPlus_BrushCreateSolid (0x8fff0000)     ;red
    $hBrushGreen = _GDIPlus_BrushCreateSolid (0x8f00ff00)   ;Green
    _GDIPlus_GraphicsClear ($hGraphic)
    If $ShowBoth = 1 Then
        _GDIPlus_GraphicsFillClosedCurve ($hGraphic, $aPoints, $hBrush)
        _GDIPlus_GraphicsDrawClosedCurve ($hGraphic, $aPoints, $hPen)
        _GDIPlus_GraphicsFillPolygon($hGraphic, $aPoints, $hBrush)
        _GDIPlus_GraphicsDrawPolygon ($hGraphic, $aPoints,$hPen)
    Else
        If $showPolC = 1 Then
            _GDIPlus_GraphicsFillClosedCurve ($hGraphic, $aPoints, $hBrush)
            _GDIPlus_GraphicsDrawClosedCurve ($hGraphic, $aPoints,$hPen)
        Else
            _GDIPlus_GraphicsFillPolygon($hGraphic, $aPoints, $hBrush)
            _GDIPlus_GraphicsDrawPolygon ($hGraphic, $aPoints,$hPen)
        EndIf
    EndIf
    If $pointsVisible = 1 Then
        For $x = 1 To $aPoints[0][0]
            If $x = $pt Then
                _GDIPlus_GraphicsFillEllipse ($hGraphic, $aPoints[$x][0] - 5, $aPoints[$x][1] - 5, 10, 10, $hBrushGreen)
            Else
                _GDIPlus_GraphicsFillEllipse ($hGraphic, $aPoints[$x][0] - 5, $aPoints[$x][1] - 5, 10, 10, $hBrushRed)  
            EndIf
            _GDIPlus_GraphicsDrawEllipse ($hGraphic, $aPoints[$x][0] - 5, $aPoints[$x][1] - 5, 10, 10)
        Next
    EndIf
    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", $GuiSizeX)
    DllStructSetData($tSize, "Y", $GuiSizeY)
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", $iOpacity)
    DllStructSetData($tBlend, "Format", 1)
    _WinAPI_UpdateLayeredWindow ($hGui, $hWnd, 0, $pSize, $hDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    _GDIPlus_PenDispose($hPen) 
    _GDIPlus_BrushDispose ($hBrush)
    _GDIPlus_BrushDispose ($hBrushRed)
    _GDIPlus_BrushDispose ($hBrushGreen)
    _GDIPlus_GraphicsDispose ($hGraphic)
    If $iFlagSave = 0 Then  
        _WinAPI_DeleteObject ($hBitmap)
        _GDIPlus_Shutdown()
    EndIf
    _WinAPI_ReleaseDC (0, $hWnd)
    
    _WinAPI_DeleteDC ($hDC)
    $Exit = GUICtrlCreateButton("Exit", 40, 25, 40, 30)
    Return
EndFunc   ;==>Draw

;Called from context menu check / uncheck Show Points
Func ShowaPoints()
    If $pointsVisible = 1 Then
        GUICtrlSetState($viewpoints, $GUI_UNCHECKED)
        $pointsVisible = 0
    Else
        GUICtrlSetState($viewpoints, $GUI_CHECKED)
        $pointsVisible = 1
    EndIf
    Draw(0)
    Return
EndFunc   ;==>ShowaPoints

;Called from context menu Write Current points to console
Func CurrentPoints2Console()
    $FromStats = SizeStats()
    $text = "Global $aPoints[" & $aPoints[0][0]+1 & "][2] = [[" & $aPoints[0][0] & ",0], "
    
    For $x = 1 To $aPoints[0][0]
        if mod($x,7)= 0 Then $text &=  StringFormat (" _\n%26s", " ")
        $text &= "[" & $aPoints[$x][0] & "," & $aPoints[$x][1] & "],"
    Next
    $text = StringTrimRight($text, 1) & "]"
    ConsoleWrite($text & @CRLF & @CRLF)
    ConsoleWrite(" Width X Height = " & $FromStats[4] & " X " & $FromStats[5] & _
                "   MiniX, MiniY = " & $FromStats[0] & ", " & $FromStats[1] & _
                "   MaxX, MaxY = " & $FromStats[2] & ", " & $FromStats[3] & _
                "   Border set to " & $iMinBorder & @CRLF & @CRLF)
    Return
EndFunc   ;==>CurrentPoints2Console

; Called from context menu Exit script.
Func quitclk()
    $exit = 1 ; Chr(27) ;
EndFunc   ;==>quitclk

; Called from context menu toggle between Closed Curves and Polygon
Func TogPol_Curv()
    If $showPolC = 0 Then
        GUICtrlSetData($togPolyCurve, "Show Polygon")
        $showPolC = 1
    Else
        GUICtrlSetData($togPolyCurve, "Show Closed Curve")
        $showPolC = 0
    EndIf
    If $ShowBoth = 1 Then ShowBoth()
    Draw(0)
    Return
EndFunc   ;==>TogPol_Curv

;Called from context menu check / uncheck Show Both Polygon and Closed Curve
Func ShowBoth()
    If $ShowBoth = 1 Then
        GUICtrlSetState($SBoth, $GUI_UNCHECKED)
        $ShowBoth = 0
    Else
        GUICtrlSetState($SBoth, $GUI_CHECKED)
        $ShowBoth = 1
    EndIf
    Draw(0)
    Return
EndFunc   ;==>ShowBoth

;Called from context menu. Adds a points. eg. if point3 is selected (green) then a new point 4 is added 
Func AddPoint()
    If $GrnPt = 0 Then
        MsgBox(0,"Add a Point","Select a point. (Click on a red point to turn it green",0,WinGetHandle('Program Manager'))
    Else
        dim $aRET[$aPoints[0][0] +2][2]
        $aRET[0][0] = $aPoints[0][0] +1
        For $r = 1 To $aPoints[0][0]
            if $r = $GrnPt  Then
                $aRET[$r][0] = $aPoints[$r][0] 
                $aRET[$r][1] = $aPoints[$r][1] 
                $aRET[$r+1][0] = $aPoints[$r][0] + 10   
                $aRET[$r+1][1] = $aPoints[$r][1] + 10   
            ElseIf $r > $GrnPt  Then
                $aRET[$r+1][0] = $aPoints[$r][0]    
                $aRET[$r+1][1] = $aPoints[$r][1]
            Else
                $aRET[$r][0] = $aPoints[$r][0]  
                $aRET[$r][1] = $aPoints[$r][1]  
            EndIf
        Next
        $aPoints = $aRET
        $aRET = ""
        Draw(0)         
    EndIf
    Return
EndFunc

; Returns a suitable Width and Height to encompass polygon for use in 
; save as image and write to console. Max & Min points are just for info. 
Func SizeStats()
    Local $iMinX = $aPoints[1][0],$iMaxX = $aPoints[1][0], $x = 0, $y = 0
    Local $iMinY = $aPoints[1][1],$iMaxY = $aPoints[1][1]
    Local $iMinWidth,$iMinHeigth
    
    For $r = 1 To $aPoints[0][0]
        if $aPoints[$r][0] < $iMinX Then $iMinX = $aPoints[$r][0]
        if $aPoints[$r][1] < $iMinY Then $iMinY = $aPoints[$r][1]
        if $aPoints[$r][0] > $iMaxX Then $iMaxX = $aPoints[$r][0]
        if $aPoints[$r][1] > $iMaxY Then $iMaxY = $aPoints[$r][1]
    Next
    
    Local $iMaxBorder = 80
    if Not $bStatFlag then
        If $iMinX < $iMinBorder then $x = $iMinBorder - $iMinX
        If $iMinY < $iMinBorder then $y = $iMinBorder - $iMinY
        If ($iMinX - $iMinBorder) > $iMaxBorder then $x = $x - ($iMinX - $iMinBorder)
        If ($iMinY - $iMinBorder) > $iMaxBorder then $y = $y - ($iMinY - $iMinBorder)
        If $x <> 0 or $y <> 0 then $aPoints = arrayplusScalarPoint($aPoints, $x, $y)
        $bStatFlag = true
        SizeStats()
    EndIf
    $bStatFlag = False
    
    $iMinWidth  = $iMinX + $iMaxX  ; = (2 * $iMinX) + actual width 
    $iMinHeigth = $iMinY + $iMaxY  ; = (2 * $iMinY) + actual height 
    
    Local $aStats[6] = [$iMinX, $iMinY, $iMaxX, $iMaxY, $iMinWidth, $iMinHeigth]
    Draw(0)
    Return $aStats
EndFunc

Func SaveBitmap()
    SizeStats()
    $FromStats = SizeStats()
    CurrentPoints2Console()
    Draw(0)     
    $GuiSizeX = $FromStats[4] 
    $GuiSizeY = $FromStats[5]
    $iFlagSave = 1 ; In Draw() function will not delete $hBitmap
    Draw(0)
    $iFlagSave = 0 ; Next Draw() function call, will delete $hBitmap.
    $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP ($hBitmap)
    
    _GDIPlus_ImageSaveToFile($hImage1, "Poly.png")
    ShellExecute ( "Poly.png")
    
    ; Clean up resources
    _WinAPI_DeleteObject ($hBitmap)
    _GDIPlus_ImageDispose ($hImage1)
    _GDIPlus_Shutdown()
    $GuiSizeX = @DesktopWidth*3 / 4
    $GuiSizeY = @DesktopWidth*3 / 4
    Return
EndFunc 
    
; Called from context menu. Deletes the selected (green) point.
Func SubstractPoint()
    If $GrnPt = 0 Then
        MsgBox(0,"Substract a point","Select a point. (Click on a red point to turn it green")
    Else
        dim $aRET[$aPoints[0][0] ][2]
        $aRET[0][0] = $aPoints[0][0] -1
        For $r = 1 To $aRET[0][0]
            if $r >= $GrnPt  Then
                $aRET[$r][0] = $aPoints[$r+1][0]    
                $aRET[$r][1] = $aPoints[$r+1][1]
            Else
                $aRET[$r][0] = $aPoints[$r][0]  
                $aRET[$r][1] = $aPoints[$r][1]  
            EndIf
        Next
        $aPoints = $aRET
        $aRET = ""
        Draw(0)
    EndIf
    Return  
EndFunc
    
Func SelectColor()
    Local $col
    $col = _ChooseColor(2, 0xffff80, 2)
    If $col <> -1 Then $iBkGndColor = "0xFF" & StringTrimLeft($col,2)
    Draw(0)
    Return
EndFunc

Func Border()
    Local $x = 0, $y = 0
    $Bdr = InputBox ( "Change border space size around the image to be saved", _
    "Current border size is " & $iMinBorder & @CRLF & @CRLF & _
    "Enter new border size, or Cancel" & @CRLF & @CRLF, $iMinBorder,"", 400,150)
    If Not @error and Number($Bdr) > 0  Then $iMinBorder = Number ($Bdr) ; Min border size = 1
    SizeStats()
    Draw(0)
    Return
EndFunc

;Matrix $a plus a Scalar (number) $k 
func arrayplusScalarPoint(ByRef $pts, $x = 0,$y = 0)
    dim $aRET[$pts[0][0] +1][2]
    $aRET[0][0] =$pts[0][0]
    For $r = 1 To $pts[0][0]
        $aRET[$r][0] = $pts[$r][0] + $x 
        $aRET[$r][1] = $pts[$r][1] + $y     
    Next
    Return $aRET
EndFunc

; =================================================================
; Drag Window 3 of 3 addin
; =================================================================
Func _WinMove($hWnd, $Command, $wParam, $lParam)
    If BitAND(WinGetState($hWnd), 32) Then Return $GUI_RUNDEFMSG
    If $moveAll = 0 Then
        ;DllCall("user32.dll", "long", "SendMessage", "hwnd", $HWnd, "int", $WM_SYSCOMMAND, "int", 0xF009, "int", 0)
        DllCall("user32.dll", "int", "SendMessage", "hWnd", $hWnd, "int", $WM_NCLBUTTONDOWN, "int", $HTCAPTION, "int", 0)
    EndIf
    Return
EndFunc   ;==>_WinMove

; #FUNCTION# ==========================================================================
; Name...........: _GDIPlus_GraphicsFillPolygon
; Description ...: Fill a polygon
; Syntax.........: _GDIPlus_GraphicsFillPolygon($hGraphics, $aPoints[, $hBrush = 0])
; Parameters ....: $hGraphics   - Handle to a Graphics object
;                  $aPoints     - Array that specifies the points of the polygon:
;                  |[0][0] - Number of points
;                  |[1][0] - Point 1 X position
;                  |[1][1] - Point 1 Y position
;                  |[2][0] - Point 2 X position
;                  |[2][1] - Point 2 Y position
;                  |[n][0] - Point n X position
;                  |[n][1] - Point n Y position
;                  $hBrush      - Handle to a brush object that is used to fill the Polygon. 
;                                 If 0, a black brush will be used.
; Return values .: Success      - True
;                  Failure      - False
; Remarks .......: In a polygon, the line continues from the last point in the points array and connects  with
;                  the first point in the array. The array of points must contain a minimum of three elements.
; Related .......:
; Link ..........; @@MsdnLink@@ GdipFillPolygon2I
; Example .......; ?
; =========================================================================================
Func _GDIPlus_GraphicsFillPolygon($hGraphics, $aPoints, $hBrush = 0)
    Local $iI, $iCount, $pPoints, $tPoints, $aResult, $tmpError, $tmpExError

    $iCount = $aPoints[0][0]
    $tPoints = DllStructCreate("int[" & $iCount * 2 & "]")
    $pPoints = DllStructGetPtr($tPoints)
    For $iI = 1 To $iCount
        DllStructSetData($tPoints, 1, $aPoints[$iI][0], (($iI - 1) * 2) + 1)
        DllStructSetData($tPoints, 1, $aPoints[$iI][1], (($iI - 1) * 2) + 2)
    Next

    _GDIPlus_BrushDefCreate ($hBrush)
    $aResult = DllCall($ghGDIPDll, "int", "GdipFillPolygon2I", "hwnd", $hGraphics, "hwnd", $hBrush, "ptr", _
                                                                                    $pPoints, "int", $iCount)
    $tmpError = @error
    $tmpExError = @extended
    _GDIPlus_BrushDefDispose ()
    If $tmpError Then Return SetError($tmpError, $tmpExError, False)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc   ;==>_GDIPlus_GraphicsFillPolygon

;_ClientToScreen() Function - Converts client (gui) coordinates to Screen coordinates
;Input - $hwnd   - Handle from GUICreate() function
;        $cPoint - Array of points in $cPoint[n+1][2] = [[n,0],[x1,y1],[x2,y2],...[xn,yn]] format
;                  Where n = Number of points
;        $index  - Index of array e.g for point $cPoint[2][0] and $cPoint[2][1] $index = 2
;        $xy     - if 0 then returns screen coordinate of x
;                - If 1 then returns screen coordinate of y 
;                - if 2 then returns array where return array[0] = x, and array[1] = y value
Func _ClientToScreen($hwnd, ByRef $cPoint,$index, $xy = 2)      
    Local $tpoint = DllStructCreate("int X;int Y")
    local $ret[2]
    DllStructSetData($tpoint, "X", $cPoint[$index][0])
    DllStructSetData($tpoint, "Y", $cPoint[$index][1])
    _WinAPI_ClientToScreen($hwnd, $tpoint)
    $ret[0] = DllStructGetData($tpoint, "X")
    $ret[1] = DllStructGetData($tpoint, "Y")
    If $xy = 0 then Return $ret[0] ; x value
    If $xy = 1 then Return $ret[1] ; y value
    If $xy = 2 then Return $ret    ; array 
EndFunc

Edit: Updated script on 27/06/2008

Added Change background colour to context menu,

Added Add a point to context menu,

Added Delete a point to context menu,

Added Save to file to context menu,

Added Set space around polygon for save file to context menu,.

Added Tooltip on points,

Updated write to console.

Edited by Malkey

Share this post


Link to post
Share on other sites



The graphic is drawn correctly, I cannot manipulate the handles though. Clicking and dragging just moves the entire image. I am running XP Pro SP2.

Share this post


Link to post
Share on other sites

The graphic is drawn correctly, I cannot manipulate the handles though. Clicking and dragging just moves the entire image. I am running XP Pro SP2.

The good news is it worked for me.

I just downloaded the script via Firefox > AutoIT menu > Edit with SciTE. Then F5 in SciTE.

Initally, I had to left click 3 times on the red dot to turn it green. The green dot was then draggable. If you don't click on the green dot the entire image drags.

I then commented out ;Global Const $ULW_ALPHA = 2 and it worked in v3.2.11.10 (beta). I am running XP Pro SP2.

If you can successfully run other scripts with GDIPlus content, I have no idea why it is not working for all.

Share this post


Link to post
Share on other sites

There we go, it works at home :D

You should make it so when you click a line it will add a new draggable point.

I would really like to know why this script didn't work when you were not at home. Is there anything I can do for future scripts that would ensure compatibility?

Add a new draggable point. I'll have a go at that in the next version when/if I get around to it. I did have fun playing with this script and thought of other features that could be added. But, it is a nothing script. A step to something better.

With the Fill Polygon, one could put coloured flat sides to 3D adjustable objects. It would be interesting to see how fill closed curves look in 3D. That is, different Z-axis values for the points. Or GDIPus Paths look like an untouched resource with potential. Limited by the imagination and knowledge.

Thanks for the reply. I was beginning to think only a few unknowns could get it to work, and probably best if I hadn't posted it in the first place.

Share this post


Link to post
Share on other sites

Updated original post.

Inspired by

http://www.autoitscript.com/forum/index.ph...st&p=542801

I thought where might be a use for a better polygon /closed curve maker.

Inspired by

http://www.autoitscript.com/forum/index.ph...st&p=533815

I though it would be useful to be able to save the creation the an image file.

I tried to save the polygon with a transparent background, but failed.

At this stage Gimp2 or Paint Shop Pro can be used to remove background.

Share this post


Link to post
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
Sign in to follow this  
Followers 0