Jump to content
wakillon

Shape2Polygon

Recommended Posts

UEZ

Great work again wakillon. :thumbsup:

 

A small example how to use the generated array data would be great!

 

Example modified from the help file:

#include <Array.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>

Example()

Func Example()
    Local $hGUI, $hGraphic, $hBrush, $hPen, $hPath, $hMatrix

    ; Code Generated by Shape2Polygon, Polygon Size=512x246 (reduction level=8) from C:\...\Shape2Polygon\Sample Shapes\Shape_08.png
    Local $aPoints = [[215,0],[1,126],[1,128],[0,135],[1,142],[2,149],[3,156],[5,163],[8,170],[11,177],[15,184],[20,191],[25,198],[32,205],[39,212],[46,218],[53,223],[60,227],[67,231],[74,234],[81,237],[88,240],[95,241],[101,240],[97,233],[94,226],[91,219],[89,212],[89,201],[92,194],[99,187],[106,184],[122,184],[129,185],[136,187],[143,189],[150,192],[157,197],[164,204],[167,203],[173,196],[180,190],[187,186],[201,186],[208,188],[215,192],[222,197],[229,204],[235,211],[240,218],[245,225],[249,232],[252,239],[256,245],[260,238],[263,231],[267,224],[271,217],[277,210],[284,203],[291,196],[298,191],[305,188],[312,185],[320,185],[327,186],[334,191],[341,198],[345,205],[349,204],[356,198],[363,193],[370,189],[377,186],[384,184],[396,184],[403,185],[410,187],[417,192],[422,199],[422,213],[420,220],[418,227],[414,234],[409,241],[410,244],[417,242],[424,240],[431,238],[438,234],[445,231],[452,227],[459,222],[466,217],[473,210],[480,203],[486,196],[492,189],[496,182],[501,175],[504,168],[507,161],[509,154],[510,147],[511,140],[510,133],[510,120],[508,113],[506,106],[503,99],[499,92],[494,85],[488,78],[481,71],[474,65],[467,59],[460,54],[453,49],[446,45],[439,41],[432,37],[425,33],[418,30],[411,26],[404,23],[397,21],[390,18],[383,16],[376,13],[370,16],[374,23],[377,30],[379,37],[379,55],[377,62],[374,69],[369,76],[362,83],[355,88],[348,91],[341,93],[333,93],[326,91],[319,88],[312,82],[305,75],[301,68],[297,61],[295,54],[292,47],[291,40],[289,33],[288,26],[287,19],[287,7],[286,0],[281,7],[277,14],[273,21],[271,28],[259,28],[252,29],[245,28],[238,21],[235,14],[231,7],[224,0],[224,17],[223,24],[223,33],[222,40],[220,47],[218,54],[216,61],[213,68],[208,75],[201,82],[194,87],[187,90],[180,92],[171,92],[164,91],[157,89],[150,85],[143,78],[138,71],[134,64],[132,57],[132,40],[134,33],[136,26],[139,19],[137,13],[130,15],[123,18],[116,20],[109,23],[102,26],[95,29],[88,32],[81,35],[74,39],[67,43],[60,47],[53,52],[46,57],[39,63],[32,70],[26,77],[20,84],[15,91],[11,98],[8,105],[5,112],[3,119],[1,126]]

    ; Create GUI
    $hGUI = GUICreate("GDI+ Example for Shape2Polygon by UEZ", _ArrayMax($aPoints) + 100, _ArrayMax($aPoints, 0, -1, -1, 1) + 100)
    GUISetState(@SW_SHOW)

    _GDIPlus_Startup()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;Create a graphics object from a window handle
    _GDIPlus_GraphicsSetSmoothingMode($hGraphic, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;Sets the graphics object rendering quality (antialiasing)
    _GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)

    $hBrush = _GDIPlus_HatchBrushCreate(35, 0xFF606060, 0xFF000000)
    $hPen = _GDIPlus_PenCreate(0xFF202020, 3)
    _GDIPlus_PenSetMiterLimit($hPen, 32)
    _GDIPlus_PenSetDashCap($hPen,  $GDIP_DASHCAPROUND)

    $hMatrix = _GDIPlus_MatrixCreate()

    $hPath = _GDIPlus_PathCreate() ;Create new path object

;~     _GDIPlus_PathAddPolygon($hPath, $aPoints)
    _GDIPlus_PathAddClosedCurve2($hPath, $aPoints, 7.5)

    ; move coordinates 50 pixels on x/y axis
    _GDIPlus_MatrixTranslate($hMatrix, 50, 50)
    _GDIPlus_PathTransform($hPath, $hMatrix)

    _GDIPlus_GraphicsFillPath($hGraphic, $hPath, $hBrush) ;Fill path to graphics handle (GUI)
    _GDIPlus_GraphicsDrawPath($hGraphic, $hPath, $hPen) ;Draw path to graphics handle (GUI)

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ; Clean up resources
    _GDIPlus_PathDispose($hPath)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_MatrixDispose($hMatrix)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
EndFunc   ;==>Example

 

Edited by UEZ
Small update to the drawing style ;-)
  • Like 2

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
wakillon

Thanks  

You are right, here is one who was used for Trump campaign ! :D

#Region    ;************ Includes ************
#Include <Array.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#EndRegion ;************ Includes ************

_GDIPlus_Startup()

Opt ( 'GUIOnEventMode', 1 )

Global $hGUI, $hGraphic, $hBmp_Buffer, $hGfx_Buffer, $aDim, $aPosCenter, $x, $y

; Code Generated by Shape2Polygon, Polygon Size=328x309 (reduction level=4) from D:\Shape2Polygon\Shapes\Hypnosis-spiral-800px.png
Local $aPoints = [[717,0],[164,307],[168,308],[172,308],[190,308],[193,308],[197,307],[202,307],[206,306],[210,305],[214,304],[218,303],[222,302],[226,301],[229,300],[232,298],[236,297],[239,295],[243,294],[246,291],[250,290],[254,288],[258,285],[262,283],[265,281],[269,277],[273,274],[277,271],[281,267],[285,263],[289,259],[292,256],[295,252],[298,248],[300,244],[303,241],[305,237],[308,233],[310,229],[312,225],[313,221],[315,217],[316,214],[318,210],[320,206],[321,202],[322,198],[322,194],[323,190],[324,187],[325,183],[325,179],[325,174],[326,171],[327,168],[327,155],[326,151],[326,147],[325,145],[325,138],[325,135],[324,131],[323,127],[322,124],[322,120],[321,117],[320,113],[318,109],[316,105],[316,101],[313,97],[312,93],[310,90],[308,86],[306,82],[304,79],[301,75],[299,71],[296,67],[293,64],[291,60],[287,56],[284,52],[280,48],[276,44],[272,41],[269,38],[265,34],[261,32],[257,29],[253,26],[249,23],[245,21],[241,19],[237,17],[234,15],[231,14],[227,12],[224,11],[221,9],[217,8],[213,7],[209,6],[205,5],[201,4],[198,3],[195,2],[191,2],[187,1],[182,1],[178,0],[174,0],[171,0],[168,0],[162,0],[159,0],[153,0],[150,0],[146,0],[142,1],[138,2],[135,2],[132,2],[128,3],[125,4],[121,6],[117,6],[114,7],[110,8],[106,10],[102,11],[99,12],[96,14],[92,15],[88,18],[84,19],[82,21],[78,23],[74,25],[71,28],[67,30],[63,32],[59,36],[55,39],[51,42],[47,45],[43,49],[40,53],[36,57],[33,61],[30,65],[27,69],[23,73],[20,77],[18,81],[15,84],[13,88],[12,92],[10,95],[8,99],[6,102],[4,106],[3,110],[2,113],[0,117],[0,120],[0,124],[2,128],[4,131],[8,135],[12,136],[16,136],[20,136],[24,134],[28,130],[29,126],[31,122],[33,118],[34,115],[36,111],[38,108],[40,104],[42,100],[44,97],[47,93],[50,89],[54,85],[56,81],[59,77],[63,73],[66,70],[70,67],[74,64],[78,61],[82,58],[85,56],[88,54],[91,51],[95,49],[99,47],[102,45],[106,43],[110,42],[113,41],[117,39],[121,38],[125,37],[129,36],[133,34],[137,33],[141,33],[145,33],[148,32],[152,31],[161,31],[165,30],[167,31],[179,31],[183,32],[187,33],[191,33],[195,34],[196,34],[200,35],[204,37],[207,38],[211,39],[214,40],[217,42],[221,43],[225,45],[228,48],[232,50],[236,51],[239,54],[243,57],[247,59],[250,63],[254,66],[258,70],[262,74],[266,78],[268,82],[272,86],[274,90],[276,93],[279,96],[281,100],[282,104],[284,108],[285,111],[287,115],[289,119],[289,122],[290,126],[291,129],[292,133],[293,137],[294,140],[295,144],[295,147],[295,151],[295,167],[295,171],[295,174],[294,178],[294,182],[293,185],[292,189],[291,192],[290,196],[289,200],[288,203],[286,207],[284,210],[283,212],[281,215],[280,219],[277,223],[275,227],[272,231],[270,235],[266,239],[262,243],[258,246],[254,249],[251,252],[247,255],[243,258],[239,260],[235,263],[231,265],[227,267],[223,268],[219,270],[216,271],[213,272],[209,273],[205,274],[201,275],[198,275],[195,276],[191,277],[182,277],[179,277],[175,277],[165,277],[162,276],[159,275],[155,275],[152,274],[150,273],[146,272],[143,271],[139,269],[135,268],[132,266],[128,263],[124,261],[121,259],[117,256],[114,254],[110,251],[106,247],[103,243],[100,240],[97,236],[94,232],[92,228],[90,225],[88,222],[86,218],[84,215],[82,212],[81,208],[80,204],[79,200],[78,196],[78,192],[77,189],[76,186],[76,165],[77,162],[77,158],[78,154],[79,151],[80,147],[82,144],[82,140],[84,136],[87,132],[88,128],[92,124],[94,120],[97,117],[100,113],[104,110],[108,106],[111,103],[115,101],[118,98],[122,96],[126,95],[129,92],[133,91],[137,90],[141,88],[145,88],[149,86],[153,86],[158,86],[162,84],[166,84],[169,86],[173,86],[177,86],[180,87],[184,88],[187,88],[191,90],[195,91],[198,93],[202,95],[206,97],[210,100],[214,103],[218,106],[221,110],[224,114],[227,118],[230,122],[232,126],[234,129],[236,133],[237,137],[238,140],[239,144],[240,147],[241,151],[241,167],[240,171],[239,174],[239,178],[237,182],[236,185],[235,189],[232,192],[230,196],[226,200],[223,204],[219,207],[217,210],[213,213],[209,215],[205,217],[201,218],[198,220],[195,221],[191,222],[188,222],[184,223],[178,223],[174,222],[171,222],[168,222],[164,221],[161,219],[157,217],[153,216],[150,213], _
[147,211],[143,207],[140,203],[137,200],[135,196],[134,192],[132,189],[132,185],[130,181],[130,170],[131,166],[132,162],[134,158],[136,154],[140,150],[144,147],[147,143],[151,141],[155,141],[159,139],[166,139],[170,140],[174,141],[178,144],[181,146],[183,149],[186,153],[186,156],[186,160],[183,156],[179,154],[175,152],[167,152],[163,153],[160,155],[156,158],[154,162],[152,165],[150,169],[150,176],[151,180],[152,183],[154,187],[156,191],[160,194],[164,196],[167,198],[171,200],[174,201],[175,201],[184,201],[187,200],[191,199],[195,198],[199,196],[203,192],[207,189],[210,185],[213,182],[214,178],[216,174],[217,171],[218,167],[219,164],[219,154],[218,151],[217,147],[217,144],[215,140],[213,136],[210,133],[208,129],[204,125],[200,121],[197,118],[193,115],[189,114],[186,112],[182,110],[178,110],[174,109],[171,108],[168,108],[160,108],[156,108],[154,109],[150,109],[146,110],[143,111],[139,113],[135,114],[132,117],[128,119],[124,122],[120,126],[117,129],[114,133],[111,137],[108,141],[106,145],[104,149],[103,153],[101,156],[101,160],[100,164],[99,168],[99,185],[100,189],[101,192],[101,196],[103,199],[104,203],[105,207],[108,210],[110,213],[112,217],[114,221],[117,225],[120,228],[123,231],[127,234],[130,237],[133,240],[137,242],[141,244],[145,246],[147,248],[151,249],[155,250],[158,251],[162,253],[166,253],[167,253],[171,254],[188,254],[192,253],[196,253],[200,253],[204,251],[208,250],[211,249],[214,247],[218,246],[220,245],[224,243],[228,240],[231,238],[235,236],[239,232],[243,229],[246,225],[249,222],[252,219],[255,215],[258,211],[260,207],[262,203],[264,200],[265,196],[267,192],[268,188],[270,184],[270,180],[271,176],[272,173],[272,169],[272,165],[272,153],[272,150],[272,145],[271,142],[270,138],[270,134],[268,130],[267,126],[266,123],[264,119],[262,115],[261,111],[259,108],[257,105],[254,101],[251,97],[249,93],[246,90],[242,86],[238,82],[235,79],[231,76],[227,74],[224,72],[221,69],[217,67],[213,65],[210,63],[206,63],[202,60],[198,59],[195,59],[191,57],[188,56],[184,55],[180,55],[177,55],[174,54],[155,54],[152,55],[147,55],[144,55],[141,56],[137,57],[133,57],[129,59],[126,60],[123,61],[119,63],[115,65],[111,67],[108,69],[104,72],[100,74],[96,76],[92,78],[89,81],[85,84],[81,88],[78,91],[74,95],[72,99],[69,102],[66,106],[64,110],[61,114],[59,118],[57,122],[55,126],[54,129],[52,133],[51,137],[50,140],[49,144],[48,147],[47,150],[46,154],[46,158],[46,162],[45,165],[45,185],[46,189],[46,192],[46,196],[47,200],[48,203],[48,207],[50,210],[51,214],[51,218],[53,221],[55,224],[56,228],[57,230],[59,234],[60,237],[63,241],[65,245],[67,248],[69,250],[72,253],[73,255],[74,258],[78,262],[80,264],[84,268],[84,270],[88,272],[92,276],[96,279],[100,282],[103,285],[107,287],[111,290],[114,291],[118,293],[121,295],[125,297],[129,298],[146,304],[159,307]]

; Set Position.
$x = 20
$y = 20
$aDim = _PolygonGetSize ( $aPoints )
$hGUI = GUICreate ( 'Vote for Trump !', $aDim[0] +$x*2, $aDim[1] +$y*2 )
GUISetOnEvent ( $GUI_EVENT_CLOSE, '_Exit' )
GUISetState()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND ( $hGUI )
$hBmp_Buffer = _GDIPlus_BitmapCreateFromGraphics ( $aDim[0] +$x*2, $aDim[1] +$y*2, $hGraphic )
$hGfx_Buffer = _GDIPlus_ImageGetGraphicsContext ( $hBmp_Buffer )
$aPoints = _PolygonSetPos ( $aPoints, $x, $y )
Dim $aPosCenter[2][2] = [[1]]
$aPosCenter[1][0] = $aDim[0]/2 +$x
$aPosCenter[1][1] = $aDim[1]/2 +$y

While 1
    _GDIPlus_GraphicsClear ( $hGfx_Buffer, 0xFFFFFFFF )
    _GDIPlus_GraphicsFillPolygon ( $hGfx_Buffer, $aPoints )
    _GDIPlus_GraphicsTransformPoints ( $hGfx_Buffer, $aPosCenter )
    _GDIPlus_GraphicsTranslateTransform ( $hGfx_Buffer, $aPosCenter[1][0], $aPosCenter[1][1] )
    _GDIPlus_GraphicsRotateTransform ( $hGfx_Buffer, 5 )
    _GDIPlus_GraphicsTranslateTransform ( $hGfx_Buffer, -$aPosCenter[1][0], -$aPosCenter[1][1] )
    _GDIPlus_GraphicsDrawImage ( $hGraphic, $hBmp_Buffer, 0, 0 )
    Sleep ( 10 )
WEnd

_GDIPlus_GraphicsDispose ( $hGfx_Buffer )
_GDIPlus_BitmapDispose ( $hBmp_Buffer )
_GDIPlus_GraphicsDispose ( $hGraphic )
_GDIPlus_Shutdown()
Exit

Func _PolygonGetSize ( $aPoints )
    If UBound ( $aPoints, 2 ) <> 2 Then Return SetError ( 1, 0, '' )
    Local $aRet[2]
    Local $iXMin = _ArrayMin ( $aPoints, 1, 1, -1, 0 )
    Local $iYMin = _ArrayMin ( $aPoints, 1, 1, -1, 1 )
    Local $iXMax = _ArrayMax ( $aPoints, 1, 1, -1, 0 )
    Local $iYMax = _ArrayMax ( $aPoints, 1, 1, -1, 1 )
    $aRet[0] = $iXMax - $iXMin +1 ; width
    $aRet[1] = $iYMax - $iYMin +1 ; height
    $aPoints = 0
    Return $aRet
EndFunc ;==> _PolygonGetSize()

Func _PolygonSetPos ( $aPoints, $x=0, $y=0 )
    If UBound ( $aPoints, 2 ) <> 2 Then Return SetError ( 1, 0, '' )
    Local $iXMin = _ArrayMin ( $aPoints, 1, 1, -1, 0 )
    Local $iYMin = _ArrayMin ( $aPoints, 1, 1, -1, 1 )
    For $i = 1 To UBound ( $aPoints ) -1
        $aPoints[$i][0] = $x + $aPoints[$i][0] - $iXMin
        $aPoints[$i][1] = $y + $aPoints[$i][1] - $iYMin
    Next
    Return $aPoints
EndFunc ;==> _PolygonSetPos()

Func _Exit()
    Exit
EndFunc ;==> _Exit()

Edited cause $aPoints Coordinates disapear when posting with AutoIt format.

Edited by wakillon
  • Like 2

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites
Synapsee

a pinch of Shape2Polygon + a pinch of UEZ + a pinch of that post = :D

#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <WinAPIGdi.au3>
#include <Array.au3>

Local $aPoints = [[215,0],[1,126],[1,128],[0,135],[1,142],[2,149],[3,156],[5,163],[8,170],[11,177],[15,184],[20,191],[25,198],[32,205],[39,212],[46,218],[53,223],[60,227],[67,231],[74,234],[81,237],[88,240],[95,241],[101,240],[97,233],[94,226],[91,219],[89,212],[89,201],[92,194],[99,187],[106,184],[122,184],[129,185],[136,187],[143,189],[150,192],[157,197],[164,204],[167,203],[173,196],[180,190],[187,186],[201,186],[208,188],[215,192],[222,197],[229,204],[235,211],[240,218],[245,225],[249,232],[252,239],[256,245],[260,238],[263,231],[267,224],[271,217],[277,210],[284,203],[291,196],[298,191],[305,188],[312,185],[320,185],[327,186],[334,191],[341,198],[345,205],[349,204],[356,198],[363,193],[370,189],[377,186],[384,184],[396,184],[403,185],[410,187],[417,192],[422,199],[422,213],[420,220],[418,227],[414,234],[409,241],[410,244],[417,242],[424,240],[431,238],[438,234],[445,231],[452,227],[459,222],[466,217],[473,210],[480,203],[486,196],[492,189],[496,182],[501,175],[504,168],[507,161],[509,154],[510,147],[511,140],[510,133],[510,120],[508,113],[506,106],[503,99],[499,92],[494,85],[488,78],[481,71],[474,65],[467,59],[460,54],[453,49],[446,45],[439,41],[432,37],[425,33],[418,30],[411,26],[404,23],[397,21],[390,18],[383,16],[376,13],[370,16],[374,23],[377,30],[379,37],[379,55],[377,62],[374,69],[369,76],[362,83],[355,88],[348,91],[341,93],[333,93],[326,91],[319,88],[312,82],[305,75],[301,68],[297,61],[295,54],[292,47],[291,40],[289,33],[288,26],[287,19],[287,7],[286,0],[281,7],[277,14],[273,21],[271,28],[259,28],[252,29],[245,28],[238,21],[235,14],[231,7],[224,0],[224,17],[223,24],[223,33],[222,40],[220,47],[218,54],[216,61],[213,68],[208,75],[201,82],[194,87],[187,90],[180,92],[171,92],[164,91],[157,89],[150,85],[143,78],[138,71],[134,64],[132,57],[132,40],[134,33],[136,26],[139,19],[137,13],[130,15],[123,18],[116,20],[109,23],[102,26],[95,29],[88,32],[81,35],[74,39],[67,43],[60,47],[53,52],[46,57],[39,63],[32,70],[26,77],[20,84],[15,91],[11,98],[8,105],[5,112],[3,119],[1,126]]

Global $hGraphic, $hBrush, $hBrushFont, $hFont, $hFormat, $hFamily, $hGUI, $tRect_Coords[4] ;would be used in two functions therefore declared as global.
Global $iTheme = 0

Local $hPen, $hPath

$Version = 1; 1 or 2

Example()

$Version = 2; 1 or 2

Example()

Func Example()

    ; Create GUI
    $hGUI = GUICreate("GDI+", _ArrayMax($aPoints) + 100, _ArrayMax($aPoints, 0, -1, -1, 1) + 100)

    ; Fill a rectangle
    _GDIPlus_Startup()
    $tRect_Coords[0] = 0
    $tRect_Coords[1] = 0
    $tRect_Coords[2] = _ArrayMax($aPoints) + 100
    $tRect_Coords[3] = _ArrayMax($aPoints, 0, -1, -1, 1) + 100

    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;Create a graphics object from a window handle
    _GDIPlus_GraphicsSetSmoothingMode($hGraphic, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;Sets the graphics object rendering quality (antialiasing)
    _GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)

    $hBrush = _GDIPlus_HatchBrushCreate(35, 0xFF606060, 0xFF000000)
    $hPen = _GDIPlus_PenCreate(0xFF202020, 3)
    _GDIPlus_PenSetMiterLimit($hPen, 32)
    _GDIPlus_PenSetDashCap($hPen,  $GDIP_DASHCAPROUND)

    $hMatrix = _GDIPlus_MatrixCreate()

    $hPath = _GDIPlus_PathCreate() ;Create new path object

    _GDIPlus_PathAddClosedCurve2($hPath, $aPoints, 7.5)

    ; move coordinates 50 pixels on x/y axis
    _GDIPlus_MatrixTranslate($hMatrix, 50, 50)
    _GDIPlus_PathTransform($hPath, $hMatrix)

    _GDIPlus_GraphicsFillPath($hGraphic, $hPath, $hBrush) ;Fill path to graphics handle (GUI)
    _GDIPlus_GraphicsDrawPath($hGraphic, $hPath, $hPen) ;Draw path to graphics handle (GUI)

    ;Register for painting
    GUIRegisterMsg($WM_PAINT, "WM_PAINT") ;$WM_PAINT

    GUISetState()

    ; Loop until the user exits.

    If $Version = 1 Then

        Do
            Switch GUIGetMsg()
                Case $GUI_EVENT_CLOSE
                    ExitLoop

                Case $GUI_EVENT_PRIMARYDOWN
                    If CheckPointer($tRect_Coords) Then SetThemev1(1)

                Case $GUI_EVENT_PRIMARYUP

                    If CheckPointer($tRect_Coords) Then
                        SetThemev1(2)
                    Else
                        SetThemev1(0)
                    EndIf



                Case $GUI_EVENT_MOUSEMOVE

                    If GetTheme() = 1 Then ContinueLoop

                    If CheckPointer($tRect_Coords) Then
                        SetThemev1(2)
                    Else
                        SetThemev1(0)
                    EndIf

            EndSwitch

        Until 0

    Else

        Do
            Switch GUIGetMsg()
                Case $GUI_EVENT_CLOSE
                    ExitLoop

                Case $GUI_EVENT_PRIMARYDOWN
                    If CheckPointer($tRect_Coords) Then SetThemev2(1)

                Case $GUI_EVENT_PRIMARYUP

                    If CheckPointer($tRect_Coords) Then
                        SetThemev2(2)
                    Else
                        SetThemev2(0)
                    EndIf



                Case $GUI_EVENT_MOUSEMOVE

                    If GetTheme() = 1 Then ContinueLoop

                    If CheckPointer($tRect_Coords) Then
                        SetThemev2(2)
                    Else
                        SetThemev2(0)
                    EndIf

            EndSwitch

        Until 0

    EndIf

    ; Clean up resources
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_BrushDispose($hBrushFont)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
EndFunc   ;==>Example

Func WM_PAINT($hGUI, $iMsg, $wParam, $lParam)

    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW)

    ;Your Code must lie below
    ;Paint the string

    _GDIPlus_GraphicsClear($hGraphic, 0xFFF0F0F0)
    _GDIPlus_GraphicsFillPath($hGraphic, $hPath, $hBrush) ;Fill path to graphics handle (GUI)
    _GDIPlus_GraphicsDrawPath($hGraphic, $hPath, $hPen) ;Draw path to graphics handle (GUI)

    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_VALIDATE)

    Return 0;'GUI_RUNDEFMSG'
EndFunc   ;==>WM_PAINT

Func CheckPointer(ByRef $aiCoords_ClientRel)
    Return _WinAPI_PtInRectEx(_WinAPI_GetMousePosX(True, $hGUI), _WinAPI_GetMousePosY(True, $hGUI), $aiCoords_ClientRel[0], $aiCoords_ClientRel[1], $aiCoords_ClientRel[2] + $aiCoords_ClientRel[0], $aiCoords_ClientRel[3] + $aiCoords_ClientRel[1])
EndFunc   ;==>CheckPointer

Func GetTheme()
    Return $iTheme
EndFunc   ;==>GetTheme

Func SetThemev1($Theme, $f_Redraw = true)

    If GetTheme() = $Theme Then Return 1

    If $Theme = 0 Then ;Idle

   $hBrush = _GDIPlus_HatchBrushCreate(35, 0xFF606060, 0xFF000000)
    $hPen = _GDIPlus_PenCreate(0xFF202020, 3)
    _GDIPlus_PenSetMiterLimit($hPen, 32)
    _GDIPlus_PenSetDashCap($hPen,  $GDIP_DASHCAPROUND)

    $hMatrix = _GDIPlus_MatrixCreate()

    $hPath = _GDIPlus_PathCreate() ;Create new path object

    _GDIPlus_PathAddClosedCurve2($hPath, $aPoints, 7.5)

    ; move coordinates 50 pixels on x/y axis
    _GDIPlus_MatrixTranslate($hMatrix, 50, 50)
    _GDIPlus_PathTransform($hPath, $hMatrix)

    _GDIPlus_GraphicsFillPath($hGraphic, $hPath, $hBrush) ;Fill path to graphics handle (GUI)
    _GDIPlus_GraphicsDrawPath($hGraphic, $hPath, $hPen) ;Draw path to graphics handle (GUI)

    ElseIf $Theme = 1 Then ;MouseDown

        $hBrush = _GDIPlus_HatchBrushCreate(35, 0xFFFF6060, 0xFF000000)
        $hPen = _GDIPlus_PenCreate(0xFF202020, 3)
        _GDIPlus_PenSetMiterLimit($hPen, 32)
        _GDIPlus_PenSetDashCap($hPen,  $GDIP_DASHCAPROUND)

        $hMatrix = _GDIPlus_MatrixCreate()

        $hPath = _GDIPlus_PathCreate() ;Create new path object

        _GDIPlus_PathAddClosedCurve2($hPath, $aPoints, 7.5)

        ; move coordinates 50 pixels on x/y axis
        _GDIPlus_MatrixTranslate($hMatrix, 50, 50)
        _GDIPlus_PathTransform($hPath, $hMatrix)

        _GDIPlus_GraphicsFillPath($hGraphic, $hPath, $hBrush) ;Fill path to graphics handle (GUI)
        _GDIPlus_GraphicsDrawPath($hGraphic, $hPath, $hPen) ;Draw path to graphics handle (GUI)

;~      msgbox(0,"","pressed")

    ElseIf $Theme = 2 Then ;MouseOver

        $hBrush = _GDIPlus_HatchBrushCreate(35, 0xFFFFFF60, 0xFF000000)
        $hPen = _GDIPlus_PenCreate(0xFF202020, 3)
        _GDIPlus_PenSetMiterLimit($hPen, 32)
        _GDIPlus_PenSetDashCap($hPen,  $GDIP_DASHCAPROUND)

        $hMatrix = _GDIPlus_MatrixCreate()

        $hPath = _GDIPlus_PathCreate() ;Create new path object

        _GDIPlus_PathAddClosedCurve2($hPath, $aPoints, 7.5)

        ; move coordinates 50 pixels on x/y axis
        _GDIPlus_MatrixTranslate($hMatrix, 50, 50)
        _GDIPlus_PathTransform($hPath, $hMatrix)

        _GDIPlus_GraphicsFillPath($hGraphic, $hPath, $hBrush) ;Fill path to graphics handle (GUI)
        _GDIPlus_GraphicsDrawPath($hGraphic, $hPath, $hPen) ;Draw path to graphics handle (GUI)

    Else
        Return SetError(1, 0, 0)
    EndIf

    $iTheme = $Theme

    ConsoleWrite("CurTheme: " & $iTheme & @CRLF)
    If $f_Redraw Then _WinAPI_RedrawWindow($hGUI, 0, 0, BitOR($RDW_INTERNALPAINT, $RDW_ERASE))

endfunc   ;==>SetTheme

Func SetThemev2($Theme, $f_Redraw = true)

    If GetTheme() = $Theme Then Return 1

    If $Theme = 0 Then ;Idle

   $hBrush = _GDIPlus_HatchBrushCreate(35, 0xFF606060, 0xFF000000)
    $hPen = _GDIPlus_PenCreate(0xFF202020, 3)
    _GDIPlus_PenSetMiterLimit($hPen, 32)
    _GDIPlus_PenSetDashCap($hPen,  $GDIP_DASHCAPROUND)

    $hMatrix = _GDIPlus_MatrixCreate()

    $hPath = _GDIPlus_PathCreate() ;Create new path object

    _GDIPlus_PathAddClosedCurve2($hPath, $aPoints, 7.5)

    ; move coordinates 50 pixels on x/y axis
    _GDIPlus_MatrixTranslate($hMatrix, 50, 50)
    _GDIPlus_PathTransform($hPath, $hMatrix)

    _GDIPlus_GraphicsFillPath($hGraphic, $hPath, $hBrush) ;Fill path to graphics handle (GUI)
    _GDIPlus_GraphicsDrawPath($hGraphic, $hPath, $hPen) ;Draw path to graphics handle (GUI)

    ElseIf $Theme = 1 Then ;MouseDown

        $hBrush = _GDIPlus_HatchBrushCreate(35, 0xFFFF6060, 0xFFFF6060)
        $hPen = _GDIPlus_PenCreate(0xFFFF6060, 3)
        _GDIPlus_PenSetMiterLimit($hPen, 32)
        _GDIPlus_PenSetDashCap($hPen,  $GDIP_DASHCAPROUND)

        $hMatrix = _GDIPlus_MatrixCreate()

        $hPath = _GDIPlus_PathCreate() ;Create new path object

        _GDIPlus_PathAddClosedCurve2($hPath, $aPoints, 7.5)

        ; move coordinates 50 pixels on x/y axis
        _GDIPlus_MatrixTranslate($hMatrix, 50, 50)
        _GDIPlus_PathTransform($hPath, $hMatrix)

        _GDIPlus_GraphicsFillPath($hGraphic, $hPath, $hBrush) ;Fill path to graphics handle (GUI)
        _GDIPlus_GraphicsDrawPath($hGraphic, $hPath, $hPen) ;Draw path to graphics handle (GUI)

;~      msgbox(0,"","pressed")

    ElseIf $Theme = 2 Then ;MouseOver

        $hBrush = _GDIPlus_HatchBrushCreate(35, 0xFFFFFF60, 0xFFFFFF60)
        $hPen = _GDIPlus_PenCreate(0xFFFFFF60, 3)
        _GDIPlus_PenSetMiterLimit($hPen, 32)
        _GDIPlus_PenSetDashCap($hPen,  $GDIP_DASHCAPROUND)

        $hMatrix = _GDIPlus_MatrixCreate()

        $hPath = _GDIPlus_PathCreate() ;Create new path object

        _GDIPlus_PathAddClosedCurve2($hPath, $aPoints, 7.5)

        ; move coordinates 50 pixels on x/y axis
        _GDIPlus_MatrixTranslate($hMatrix, 50, 50)
        _GDIPlus_PathTransform($hPath, $hMatrix)

        _GDIPlus_GraphicsFillPath($hGraphic, $hPath, $hBrush) ;Fill path to graphics handle (GUI)
        _GDIPlus_GraphicsDrawPath($hGraphic, $hPath, $hPen) ;Draw path to graphics handle (GUI)

    Else
        Return SetError(1, 0, 0)
    EndIf

    $iTheme = $Theme

    ConsoleWrite("CurTheme: " & $iTheme & @CRLF)
    If $f_Redraw Then _WinAPI_RedrawWindow($hGUI, 0, 0, BitOR($RDW_INTERNALPAINT, $RDW_ERASE))

endfunc   ;==>SetTheme

any people who improve that have my eternal gratitude ^^

Edited by Synapsee
code update
  • Like 1

Share this post


Link to post
Share on other sites
wakillon

Don't know if it's what you want...

#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <WinAPIGdi.au3>
#include <Array.au3>

Local $aPoints = [[215,0],[1,126],[1,128],[0,135],[1,142],[2,149],[3,156],[5,163],[8,170],[11,177],[15,184],[20,191],[25,198],[32,205],[39,212],[46,218],[53,223],[60,227],[67,231],[74,234],[81,237],[88,240],[95,241],[101,240],[97,233],[94,226],[91,219],[89,212],[89,201],[92,194],[99,187],[106,184],[122,184],[129,185],[136,187],[143,189],[150,192],[157,197],[164,204],[167,203],[173,196],[180,190],[187,186],[201,186],[208,188],[215,192],[222,197],[229,204],[235,211],[240,218],[245,225],[249,232],[252,239],[256,245],[260,238],[263,231],[267,224],[271,217],[277,210],[284,203],[291,196],[298,191],[305,188],[312,185],[320,185],[327,186],[334,191],[341,198],[345,205],[349,204],[356,198],[363,193],[370,189],[377,186],[384,184],[396,184],[403,185],[410,187],[417,192],[422,199],[422,213],[420,220],[418,227],[414,234],[409,241],[410,244],[417,242],[424,240],[431,238],[438,234],[445,231],[452,227],[459,222],[466,217],[473,210],[480,203],[486,196],[492,189],[496,182],[501,175],[504,168],[507,161],[509,154],[510,147],[511,140],[510,133],[510,120],[508,113],[506,106],[503,99],[499,92],[494,85],[488,78],[481,71],[474,65],[467,59],[460,54],[453,49],[446,45],[439,41],[432,37],[425,33],[418,30],[411,26],[404,23],[397,21],[390,18],[383,16],[376,13],[370,16],[374,23],[377,30],[379,37],[379,55],[377,62],[374,69],[369,76],[362,83],[355,88],[348,91],[341,93],[333,93],[326,91],[319,88],[312,82],[305,75],[301,68],[297,61],[295,54],[292,47],[291,40],[289,33],[288,26],[287,19],[287,7],[286,0],[281,7],[277,14],[273,21],[271,28],[259,28],[252,29],[245,28],[238,21],[235,14],[231,7],[224,0],[224,17],[223,24],[223,33],[222,40],[220,47],[218,54],[216,61],[213,68],[208,75],[201,82],[194,87],[187,90],[180,92],[171,92],[164,91],[157,89],[150,85],[143,78],[138,71],[134,64],[132,57],[132,40],[134,33],[136,26],[139,19],[137,13],[130,15],[123,18],[116,20],[109,23],[102,26],[95,29],[88,32],[81,35],[74,39],[67,43],[60,47],[53,52],[46,57],[39,63],[32,70],[26,77],[20,84],[15,91],[11,98],[8,105],[5,112],[3,119],[1,126]]

Global $hGraphic, $hBrush, $hBrushFont, $hFont, $hFormat, $hFamily, $hGUI, $tRect_Coords[4] ;would be used in two functions therefore declared as global.
Global $iTheme = 0

Local $hPen, $hPath
$Version = 1; 1 or 2
Example()
$Version = 2; 1 or 2
Example()

Func Example()
    ; Create GUI
    $hGUI = GUICreate("GDI+", _ArrayMax($aPoints) + 100, _ArrayMax($aPoints, 0, -1, -1, 1) + 100)
    ; Fill a rectangle
    _GDIPlus_Startup()
    $tRect_Coords[0] = 0
    $tRect_Coords[1] = 0
    $tRect_Coords[2] = _ArrayMax($aPoints) + 100
    $tRect_Coords[3] = _ArrayMax($aPoints, 0, -1, -1, 1) + 100
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;Create a graphics object from a window handle
    _GDIPlus_GraphicsSetSmoothingMode($hGraphic, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;Sets the graphics object rendering quality (antialiasing)
    _GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)
    $hBrush = _GDIPlus_HatchBrushCreate(35, 0xFF606060, 0xFF000000)
    $hPen = _GDIPlus_PenCreate(0xFF202020, 3)
    ;_GDIPlus_PenSetMiterLimit($hPen, 10)
    _GDIPlus_PenSetDashCap($hPen,  $GDIP_DASHCAPROUND)
    $hMatrix = _GDIPlus_MatrixCreate()
    $hPath = _GDIPlus_PathCreate() ;Create new path object
;~     _GDIPlus_PathAddClosedCurve2($hPath, $aPoints, 7.5)
    _GDIPlus_PathAddPolygon ( $hPath, $aPoints )
    ; move coordinates 50 pixels on x/y axis
    _GDIPlus_MatrixTranslate($hMatrix, 50, 50)
    _GDIPlus_PathTransform($hPath, $hMatrix)
    _GDIPlus_GraphicsFillPath($hGraphic, $hPath, $hBrush) ;Fill path to graphics handle (GUI)
    _GDIPlus_GraphicsDrawPath($hGraphic, $hPath, $hPen) ;Draw path to graphics handle (GUI)
    ;Register for painting
    GUIRegisterMsg($WM_PAINT, "WM_PAINT") ;$WM_PAINT
    GUISetState()
    ; Loop until the user exits.
    If $Version = 1 Then
        Do
            Switch GUIGetMsg()
                Case $GUI_EVENT_CLOSE
                    ExitLoop
                Case $GUI_EVENT_PRIMARYDOWN
                    If CheckPointer($tRect_Coords) Then SetThemev1(1)
                Case $GUI_EVENT_PRIMARYUP
                    If CheckPointer($tRect_Coords) Then
                        SetThemev1(2)
                    Else
                        SetThemev1(0)
                    EndIf
                Case $GUI_EVENT_MOUSEMOVE
                    If GetTheme() = 1 Then ContinueLoop
                    If CheckPointer($tRect_Coords) Then
                        SetThemev1(2)
                    Else
                        SetThemev1(0)
                    EndIf
            EndSwitch
        Until 0
    Else
        Do
            Switch GUIGetMsg()
                Case $GUI_EVENT_CLOSE
                    ExitLoop
                Case $GUI_EVENT_PRIMARYDOWN
                    If CheckPointer($tRect_Coords) Then SetThemev2(1)
                Case $GUI_EVENT_PRIMARYUP
                    If CheckPointer($tRect_Coords) Then
                        SetThemev2(2)
                    Else
                        SetThemev2(0)
                    EndIf
                Case $GUI_EVENT_MOUSEMOVE
                    If GetTheme() = 1 Then ContinueLoop
                    If CheckPointer($tRect_Coords) Then
                        SetThemev2(2)
                    Else
                        SetThemev2(0)
                    EndIf
            EndSwitch
        Until 0
    EndIf
    ; Clean up resources
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_BrushDispose($hBrushFont)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
EndFunc   ;==>Example

Func WM_PAINT($hGUI, $iMsg, $wParam, $lParam)
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW)
    ;Your Code must lie below
    ;Paint the string
    _GDIPlus_GraphicsClear($hGraphic, 0xFFF0F0F0)
    _GDIPlus_GraphicsFillPath($hGraphic, $hPath, $hBrush) ;Fill path to graphics handle (GUI)
    _GDIPlus_GraphicsDrawPath($hGraphic, $hPath, $hPen) ;Draw path to graphics handle (GUI)
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_VALIDATE)
    Return 0;'GUI_RUNDEFMSG'
EndFunc   ;==>WM_PAINT

Func CheckPointer(ByRef $aiCoords_ClientRel)
    Return _WinAPI_PtInRectEx(_WinAPI_GetMousePosX(True, $hGUI), _WinAPI_GetMousePosY(True, $hGUI), $aiCoords_ClientRel[0], $aiCoords_ClientRel[1], $aiCoords_ClientRel[2] + $aiCoords_ClientRel[0], $aiCoords_ClientRel[3] + $aiCoords_ClientRel[1])
EndFunc   ;==>CheckPointer

Func GetTheme()
    Return $iTheme
EndFunc   ;==>GetTheme

Func SetThemev1($Theme, $f_Redraw = true)
    If GetTheme() = $Theme Then Return 1
    If $Theme = 0 Then ;Idle
        $hBrush = _GDIPlus_HatchBrushCreate(35, 0xFF606060, 0xFF000000)
        $hPen = _GDIPlus_PenCreate(0xFF202020, 3)
        ;_GDIPlus_PenSetMiterLimit($hPen, 10)
        _GDIPlus_PenSetDashCap($hPen,  $GDIP_DASHCAPROUND)
        $hMatrix = _GDIPlus_MatrixCreate()
        $hPath = _GDIPlus_PathCreate() ;Create new path object
;~         _GDIPlus_PathAddClosedCurve2($hPath, $aPoints, 7.5)
        _GDIPlus_PathAddPolygon ( $hPath, $aPoints )
        ; move coordinates 50 pixels on x/y axis
        _GDIPlus_MatrixTranslate($hMatrix, 50, 50)
        _GDIPlus_PathTransform($hPath, $hMatrix)
        _GDIPlus_GraphicsFillPath($hGraphic, $hPath, $hBrush) ;Fill path to graphics handle (GUI)
        _GDIPlus_GraphicsDrawPath($hGraphic, $hPath, $hPen) ;Draw path to graphics handle (GUI)
    ElseIf $Theme = 1 Then ;MouseDown
        $hBrush = _GDIPlus_HatchBrushCreate(35, 0xFFFF6060, 0xFF000000)
        $hPen = _GDIPlus_PenCreate(0xFF202020, 3)
        ;_GDIPlus_PenSetMiterLimit($hPen, 10)
        _GDIPlus_PenSetDashCap($hPen,  $GDIP_DASHCAPROUND)
        $hMatrix = _GDIPlus_MatrixCreate()
        $hPath = _GDIPlus_PathCreate() ;Create new path object
;~         _GDIPlus_PathAddClosedCurve2($hPath, $aPoints, 7.5)
        _GDIPlus_PathAddPolygon ( $hPath, $aPoints )
        ; move coordinates 50 pixels on x/y axis
        _GDIPlus_MatrixTranslate($hMatrix, 50, 50)
        _GDIPlus_PathTransform($hPath, $hMatrix)
        _GDIPlus_GraphicsFillPath($hGraphic, $hPath, $hBrush) ;Fill path to graphics handle (GUI)
        _GDIPlus_GraphicsDrawPath($hGraphic, $hPath, $hPen) ;Draw path to graphics handle (GUI)
;~      msgbox(0,"","pressed")
    ElseIf $Theme = 2 Then ;MouseOver
        $hBrush = _GDIPlus_HatchBrushCreate(35, 0xFFFFFF60, 0xFF000000)
        $hPen = _GDIPlus_PenCreate(0xFF202020, 3 )
        ;_GDIPlus_PenSetMiterLimit($hPen, 10)
        _GDIPlus_PenSetDashCap($hPen,  $GDIP_DASHCAPROUND)
        $hMatrix = _GDIPlus_MatrixCreate()
        $hPath = _GDIPlus_PathCreate() ;Create new path object
;~         _GDIPlus_PathAddClosedCurve2($hPath, $aPoints, 7.5)
        _GDIPlus_PathAddPolygon ( $hPath, $aPoints )
        ; move coordinates 50 pixels on x/y axis
        _GDIPlus_MatrixTranslate($hMatrix, 50, 50)
        _GDIPlus_PathTransform($hPath, $hMatrix)
        _GDIPlus_GraphicsFillPath($hGraphic, $hPath, $hBrush) ;Fill path to graphics handle (GUI)
        _GDIPlus_GraphicsDrawPath($hGraphic, $hPath, $hPen) ;Draw path to graphics handle (GUI)
    Else
        Return SetError(1, 0, 0)
    EndIf
    $iTheme = $Theme
    ConsoleWrite("CurTheme: " & $iTheme & @CRLF)
    If $f_Redraw Then _WinAPI_RedrawWindow($hGUI, 0, 0, BitOR($RDW_INTERNALPAINT, $RDW_ERASE))
endfunc   ;==>SetTheme

Func SetThemev2($Theme, $f_Redraw = true)
    If GetTheme() = $Theme Then Return 1
    If $Theme = 0 Then ;Idle
        $hBrush = _GDIPlus_HatchBrushCreate(35, 0xFF606060, 0xFF000000)
        $hPen = _GDIPlus_PenCreate(0xFF202020, 3)
        ;_GDIPlus_PenSetMiterLimit($hPen, 10)
        _GDIPlus_PenSetDashCap($hPen,  $GDIP_DASHCAPROUND)
        $hMatrix = _GDIPlus_MatrixCreate()
        $hPath = _GDIPlus_PathCreate() ;Create new path object
;~         _GDIPlus_PathAddClosedCurve2($hPath, $aPoints, 7.5)
        _GDIPlus_PathAddPolygon ( $hPath, $aPoints )
        ; move coordinates 50 pixels on x/y axis
        _GDIPlus_MatrixTranslate($hMatrix, 50, 50)
        _GDIPlus_PathTransform($hPath, $hMatrix)
        _GDIPlus_GraphicsFillPath($hGraphic, $hPath, $hBrush) ;Fill path to graphics handle (GUI)
        _GDIPlus_GraphicsDrawPath($hGraphic, $hPath, $hPen) ;Draw path to graphics handle (GUI)
    ElseIf $Theme = 1 Then ;MouseDown
        $hBrush = _GDIPlus_HatchBrushCreate(35, 0xFFFF6060, 0xFFFF6060)
        $hPen = _GDIPlus_PenCreate(0xFFFF6060, 3)
        ;_GDIPlus_PenSetMiterLimit($hPen, 10)
        _GDIPlus_PenSetDashCap($hPen,  $GDIP_DASHCAPROUND)
        $hMatrix = _GDIPlus_MatrixCreate()
        $hPath = _GDIPlus_PathCreate() ;Create new path object
;~         _GDIPlus_PathAddClosedCurve2($hPath, $aPoints, 7.5)
        _GDIPlus_PathAddPolygon ( $hPath, $aPoints )
        ; move coordinates 50 pixels on x/y axis
        _GDIPlus_MatrixTranslate($hMatrix, 50, 50)
        _GDIPlus_PathTransform($hPath, $hMatrix)
        _GDIPlus_GraphicsFillPath($hGraphic, $hPath, $hBrush) ;Fill path to graphics handle (GUI)
        _GDIPlus_GraphicsDrawPath($hGraphic, $hPath, $hPen) ;Draw path to graphics handle (GUI)
;~      msgbox(0,"","pressed")
    ElseIf $Theme = 2 Then ;MouseOver
        $hBrush = _GDIPlus_HatchBrushCreate(35, 0xFFFFFF60, 0xFFFFFF60)
        $hPen = _GDIPlus_PenCreate(0xFFFFFF60, 3)
        ;_GDIPlus_PenSetMiterLimit($hPen, 10)
        _GDIPlus_PenSetDashCap($hPen,  $GDIP_DASHCAPROUND)
        $hMatrix = _GDIPlus_MatrixCreate()
        $hPath = _GDIPlus_PathCreate() ;Create new path object
;~         _GDIPlus_PathAddClosedCurve2($hPath, $aPoints, 7.5)
        _GDIPlus_PathAddPolygon ( $hPath, $aPoints )
        ; move coordinates 50 pixels on x/y axis
        _GDIPlus_MatrixTranslate($hMatrix, 50, 50)
        _GDIPlus_PathTransform($hPath, $hMatrix)
        _GDIPlus_GraphicsFillPath($hGraphic, $hPath, $hBrush) ;Fill path to graphics handle (GUI)
        _GDIPlus_GraphicsDrawPath($hGraphic, $hPath, $hPen) ;Draw path to graphics handle (GUI)
    Else
        Return SetError(1, 0, 0)
    EndIf
    $iTheme = $Theme
    ConsoleWrite("CurTheme: " & $iTheme & @CRLF)
    If $f_Redraw Then _WinAPI_RedrawWindow($hGUI, 0, 0, BitOR($RDW_INTERNALPAINT, $RDW_ERASE))
endfunc   ;==>SetTheme

 

  • Like 1

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

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

  • Similar Content

    • bhns
      By bhns
      try it for make flyers old games xml + Gdi, i belive many sources had lost 
      AIT-ADRLIST.au3

    • mdepot
      By mdepot
      I have a situation where I am repeatedly capturing a region of the screen and feeding it into Tesseract OCR.  Since the OCR is a relatively slow operation, I would like to create an in memory cache of the ocr results.  An ideal hash key for this cache would be a checksum of the captured image.  With this I could capture the region, checksum it, and then only if I don't get a cache hit I would write the image out to disk for external OCR.
      Now I know I can do this by saving the captured image out to disk, and then summing the disk file with _Crypt_HashFile().  But that's still slower than I would like, and it shouldn't be necessary.  Ideally, it should be possible to checksum the image data directly in memory so I don't have to go to disk at all.  In order to do that, I need a way to dump a representation of the image into a string  (or some equivalent).  Then I could use the _Crypt_HashData() function against that string to create my cache hash key.
      Googling around I found an article here that shows a way to convert an image object to a byte array using System.Drawing.  This was the closest thing I found to what I'm trying to do.  I don't know if that method could be used from within AutoIT, or if perhaps there may be a better way I don't know about.  If someone could give me a shove in the right direction it would be a big help.  Thanks!
    • UEZ
      By UEZ
      Here some graphical examples written completely in FreeBasic just for fun.  
      3D Starfield Rotating Flight 3D Starfield Scrolling v1 Booster 3D Starfield Scrolling v3 Booster CreateWindowEx (hGUI) Example FB File2Bas Code Generator (AutoIt script) FB GFX Examples Fire Particles FMOD Examples GDI - GDI+ 3D Sinus Wave GDI - GDI+ Animated Pythagoras Tree GDI - GDI+ Particles - Repulsive Force Sim v2.0 GDI - GDI+ Plasma v5 Booster GDI - GDI+ Random Pattern GDI - GDI+ Space Flight GDI - GDI+ Tunnel Flight - WipeOut Style GDI Classic Raytraced Tunnel GDI Elastic Twister Effect GDI Exploding Pixels GDI Infinite Image Zoom Flight GDI Liquid Pixels GDI Particle Repulsion Grid GDI Particles Mouse Attraction GDI Starfield GDI The Nautilus Raymarcher GDI Worm Tunnel Flight GDI+ Impossible Possible GDI+ Kaleidoscope GDI+ Performance Test - Au3 vs FB GDI+ Polar Clock GDI+ Rotating Earth GDI+ Star Wars Scroller GDI+ Streamer GDI+ Swiss Railway Clock Ini Read - Write Mandelbrot Plasma Puristic Clock Rutt_Etra_Izer_Booster Tunnel Flight uFMOD _WinAPI_SetWindowTitleIcon  
      Download: FreeBasic Examples build 2018-07-10.rar
       
      I will add new examples from time to time.
       
      FreeBasic source codes are also included.
       
    • Bilgus
      By Bilgus
      Draw Path Points allows you to make line paths for drawing with gdi
      You can even load an image and trace the outline
      Save and load functionality undo and redo zoom and scale; Don't Forget Rotate!
      ;Draw Path Points BILGUS 2018 ;Includes #include <File.au3> #include <GDIPlus.au3> #include <GUIConstants.au3> #include <GuiEdit.au3> #include <GuiListView.au3> #include <GuiTab.au3> #include <Misc.au3> If OnAutoItExitRegister("_Exit") <> 0 Then _GDIPlus_Startup() ;initialize GDI+ ConsoleWrite("GDI+ Started" & @CRLF) EndIf Opt("MouseCoordMode", 2) ;Relative coords to the client area of the active window Opt("PixelCoordMode", 2) ;Relative coords to the client area of the active window Global $g_iXScale = 8 Global $g_iYScale = $g_iXScale Global $g_sFileSave = @ScriptDir & "\DrawPath.txt" ;Default Global $g_bClosePath = False Global $g_bShowImage = False Global $g_sImagefile = "" Global $g_iUndo_Max = 50 Global $g_asUndo_Files[1] = [""] Global $g_asRedo_Files[1] = [""] Global $g_aPath_Points[1][2] = [[0, 0]] Global $g_aPath_Rot_Points Global $g_hForm1 = GUICreate("Draw Path Points", 615, 437, 192, 124) Global $g_hSelSquare = GUICtrlCreateLabel("", 0, 0, 0, 0, $SS_BLACKFRAME, $WS_EX_TOPMOST) GUICtrlSetState(-1, $GUI_HIDE) ;------------------------------------------------------------------------------- Global Enum $eC1_delete, $eC1_del_all, $eC1_update, $eC1_shift_dn, $eC1_shift_up, _ $eC1_closepath, $eC1_showimg, $eC1_lock, $eC1_undo, $eC1_redo, $aCtl1_LAST Global $g_ahCtl1[$aCtl1_LAST] Control_Create_Group1() ;------------------------------------------------------------------------------- Global Enum $eC2_zin, $eC2_zout, $eC2_dgroup, $eC2_decx, $eC2_incx, $eC2_decy, _ $eC2_incy, $eC2_edit_rot, $eC2_rot, $eC2_ud_rot, $eC2_rev, $eC2_toall, $aCtl2_LAST Global $g_ahCtl2[$aCtl2_LAST] Control_Create_Group2() ;------------------------------------------------------------------------------- Global $g_hBtn_load = GUICtrlCreateButton("Load", 5, 1, 35, 20) Global $g_hBtn_save = GUICtrlCreateButton("Save", 40, 1, 35, 20) Global $g_hBtn_arr_disp = GUICtrlCreateButton("Array", 75, 1, 35, 20) Global $g_hEdit_encoded = GUICtrlCreateEdit("", 115, 2, 50, 18, $ES_READONLY + $ES_AUTOHSCROLL, $WS_EX_STATICEDGE + $WS_EX_TRANSPARENT) Global $g_hList1 = GUICtrlCreateListView("#|x|y", 5, 24, 161, 201, $LVS_SHOWSELALWAYS Or $LVS_SINGLESEL) Global $g_hList1_LVN = GUICtrlCreateDummy() ;listview notifications Global $g_hImage1 = GUICtrlCreatePic("", 200, 16, 400, 400, -1, $WS_EX_LAYERED) Global $g_hTab1 = GUICtrlCreateTab(1, 225, 20, 500, $TCS_VERTICAL) GUICtrlCreateTabItem(" ") GUICtrlSetState(-1, $GUI_SHOW) ; will be display first GUICtrlCreateTabItem(" ") GUICtrlCreateTabItem("") ; end tabitem definition For $i = 0 To UBound($g_ahCtl2) - 1 GUICtrlSetState($g_ahCtl2[$i], $GUI_HIDE) Next GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") List_Update() List_Index() GUISetState(@SW_SHOW) State_Save($g_aPath_Points) Points_Update($g_aPath_Points) Global $g_nMsg = 0 While 1 $g_nMsg = GUIGetMsg() If $g_nMsg > 0 And $g_nMsg <> $g_ahCtl2[$eC2_ud_rot] And $g_nMsg <> $g_ahCtl2[$eC2_edit_rot] And GUICtrlRead($g_ahCtl2[$eC2_edit_rot]) <> 0 Then ;ConsoleWrite("Cancel_Rotate? " & $g_nMsg & @CRLF) If MsgBox($MB_ICONQUESTION + $MB_OKCANCEL + $MB_DEFBUTTON2, "Save?", "Save Rotated Points?", 10) == $IDOK Then _GUICtrlEdit_SetText($g_ahCtl2[$eC2_edit_rot], "0") $g_aPath_Points = $g_aPath_Rot_Points State_Save($g_aPath_Points) List_Update(List_Index()) Else _GUICtrlEdit_SetText($g_ahCtl2[$eC2_edit_rot], "0") Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage, List_Index()) ;, True) EndIf EndIf Switch $g_nMsg Case $GUI_EVENT_CLOSE Exit Case $g_hTab1 Tab1_Select() Case $g_hSelSquare ;ConsoleWrite("SelSquare" & @CRLF) SelSquare_Drag() Case $g_hList1 ;ConsoleWrite("List1 " & $g_nMsg & @CRLF) Local $iIndex = List_Index() If $iIndex <> -1 Then Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage, $iIndex) _GUICtrlListView_SetItemSelected($g_hList1, $iIndex, True, True) EndIf Case $g_hList1_LVN Point_Selected($g_aPath_Points, $g_hImage1, List_Index()) Case $g_hList1_LVN Case $g_hImage1 Image1_Clicked() Case $g_hBtn_save Btn_save_Clicked() Case $g_hBtn_load Btn_load_Clicked() Case $g_hBtn_arr_disp _ArrayDisplay($g_aPath_Points) ;------------------------------------------------------------------- Case $g_ahCtl1[$eC1_shift_up] $iIndex = List_Index() Point_Swap($iIndex, -1) Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage) Case $g_ahCtl1[$eC1_shift_dn] $iIndex = List_Index() Point_Swap($iIndex, 1) Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage) Case $g_ahCtl1[$eC1_del_all] $g_aPath_Points = 0 Global $g_aPath_Points[1][2] = [[0, 0]] List_Update() Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage) Case $g_ahCtl1[$eC1_delete] $iIndex = List_Index() Point_Delete($iIndex) _GUICtrlListView_ClickItem($g_hList1, $iIndex) Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage) Case $g_ahCtl1[$eC1_redo] $g_aPath_Points = State_Restore($g_aPath_Points, False) List_Update() Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage) Case $g_ahCtl1[$eC1_undo] $g_aPath_Points = State_Restore($g_aPath_Points, True) List_Update() Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage) Case $g_ahCtl1[$eC1_update] List_Update(List_Index()) Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage) Ascii_Points($g_aPath_Points) _GUICtrlEdit_SetSel($g_hEdit_encoded, 0, -1) Case $g_ahCtl1[$eC1_closepath] $g_bClosePath = Control_IsChecked($g_ahCtl1[$eC1_closepath]) List_Update(List_Index()) Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage) If $g_bClosePath Then GUICtrlSetState($g_ahCtl2[$eC2_rev], $GUI_DISABLE) Else GUICtrlSetState($g_ahCtl2[$eC2_rev], $GUI_ENABLE) EndIf Case $g_ahCtl1[$eC1_showimg] If Not $g_bShowImage Then $g_sImagefile = FileOpenDialog("Select an image", SplitDir($g_sImagefile), "All Files(*.*)", 0, SplitFileName($g_sImagefile), $g_hForm1) EndIf $g_bShowImage = Control_IsChecked($g_ahCtl1[$eC1_showimg]) List_Update(List_Index()) Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage) ;------------------------------------------------------------------- Case $g_ahCtl2[$eC2_zin] If Control_IsChecked($g_ahCtl2[$eC2_toall]) Then Points_Scale(1, 1) Else $g_iXScale += 1 $g_iYScale += 1 Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage) EndIf _GUICtrlListView_ClickItem($g_hList1, List_Index()) Case $g_ahCtl2[$eC2_zout] If Control_IsChecked($g_ahCtl2[$eC2_toall]) Then Points_Scale(-1, -1) Else $g_iXScale -= 1 $g_iYScale -= 1 Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage) EndIf _GUICtrlListView_ClickItem($g_hList1, List_Index()) Case $g_ahCtl2[$eC2_rev] $iIndex = List_Index() $g_aPath_Points = Points_Reverse($g_aPath_Points) Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage, $iIndex) ;, True) List_Update($iIndex) Case $g_ahCtl2[$eC2_edit_rot] ;ConsoleWrite("Rotate" & @CRLF) $iIndex = List_Index() Local $iDegrees = GUICtrlRead($g_ahCtl2[$eC2_edit_rot]) $g_aPath_Rot_Points = Points_Rotate($g_aPath_Points, $iDegrees) Points_Update($g_aPath_Rot_Points, $g_bClosePath, $g_bShowImage, $iIndex) ;, True) Case $g_ahCtl2[$eC2_incx] Point_Adjust(1, 0, Control_IsChecked($g_ahCtl2[$eC2_toall])) Case $g_ahCtl2[$eC2_decx] Point_Adjust(-1, 0, Control_IsChecked($g_ahCtl2[$eC2_toall])) Case $g_ahCtl2[$eC2_incy] Point_Adjust(0, 1, Control_IsChecked($g_ahCtl2[$eC2_toall])) Case $g_ahCtl2[$eC2_decy] Point_Adjust(0, -1, Control_IsChecked($g_ahCtl2[$eC2_toall])) EndSwitch WEnd ;---------------------------------------------------------------------------------------------------- Func _Exit() _GDIPlus_Shutdown() ConsoleWrite("GDI+ Stopped" & @CRLF) State_Destroy() EndFunc ;==>_Exit Func Ascii_Points($aPts) ;encodes points into an ascii string Local Const $iChrOffset = 33 Local Const $iMaxOffset = 126 - $iChrOffset If Not IsArray($aPts) Then Return Local $sAscEnc = StringFormat("%03i%05i", $iChrOffset, UBound($aPts) * 2 + 8) If _ArrayMin($aPts) >= 0 And (_ArrayMax($aPts) - _ArrayMin($aPts)) <= $iMaxOffset Then For $i = 0 To UBound($aPts) - 1 $sAscEnc = $sAscEnc & Chr($aPts[$i][0] + $iChrOffset) & Chr($aPts[$i][1] + $iChrOffset) Next EndIf _GUICtrlEdit_SetText($g_hEdit_encoded, $sAscEnc) EndFunc ;==>Ascii_Points Func Btn_load_Clicked() ConsoleWrite("Load: " & SplitDir($g_sFileSave) & @CRLF) $g_sFileSave = FileOpenDialog("Select a save file", SplitDir($g_sFileSave), "All Files(*.*)", 0, SplitFileName($g_sFileSave), $g_hForm1) _FileReadToArray($g_sFileSave, $g_aPath_Points, 0, ",") If @error Then Dim $g_aPath_Points[1][2] = [[0, 0]] Else State_Destroy() State_Save($g_aPath_Points) EndIf List_Update() Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage) EndFunc ;==>Btn_load_Clicked Func Btn_save_Clicked() List_Update(List_Index()) $g_sFileSave = FileOpenDialog("Select a save file", SplitDir($g_sFileSave), "All Files(*.*)", 0, SplitFileName($g_sFileSave), $g_hForm1) _FileWriteFromArray($g_sFileSave, $g_aPath_Points, 0, Default, ",") EndFunc ;==>Btn_save_Clicked Func Control_Create_Group1() Local $iX = 30 Local $iY = 225 $g_ahCtl1[$eC1_delete] = GUICtrlCreateButton("Delete", $iX + 0, $iY + 0, 50, 20) $g_ahCtl1[$eC1_shift_dn] = GUICtrlCreateButton("+", $iX + 70, $iY + 0, 20, 20) $g_ahCtl1[$eC1_shift_up] = GUICtrlCreateButton("-", $iX + 95, $iY + 0, 20, 20) $g_ahCtl1[$eC1_del_all] = GUICtrlCreateButton("Delete All", $iX + 0, $iY + 25, 50, 20) $g_ahCtl1[$eC1_update] = GUICtrlCreateButton("Update", $iX + 70, $iY + 25, 50, 20) $g_ahCtl1[$eC1_undo] = GUICtrlCreateButton("Undo", $iX + 0, $iY + 50, 50, 20) $g_ahCtl1[$eC1_redo] = GUICtrlCreateButton("Redo", $iX + 70, $iY + 50, 50, 20) GUICtrlSetState($g_ahCtl1[$eC1_undo], $GUI_DISABLE) GUICtrlSetState($g_ahCtl1[$eC1_redo], $GUI_DISABLE) $g_ahCtl1[$eC1_closepath] = GUICtrlCreateCheckbox("Complete", $iX + 0, $iY + 70, 65, 25) $g_ahCtl1[$eC1_showimg] = GUICtrlCreateCheckbox("Image", $iX + 0, $iY + 90, 65, 25) $g_ahCtl1[$eC1_lock] = GUICtrlCreateCheckbox("Locked", $iX + 0, $iY + 110, 65, 25) EndFunc ;==>Control_Create_Group1 Func Control_Create_Group2() Local $iX = 30 Local $iY = 225 $g_ahCtl2[$eC2_rev] = GUICtrlCreateButton("Reverse", $iX + 0, $iY + 0, 50, 20) $g_ahCtl2[$eC2_edit_rot] = GUICtrlCreateInput("0", $iX + 0, $iY + 25, 40, 20) $g_ahCtl2[$eC2_ud_rot] = GUICtrlCreateUpdown(-1) GUICtrlSetLimit($eC2_ud_rot, 360, -360) $g_ahCtl2[$eC2_rot] = GUICtrlCreateButton("", $iX + 40, $iY + 25, 10, 20) $g_ahCtl2[$eC2_dgroup] = GUICtrlCreateGroup("Coords", 5 + $iX + 70, $iY + 0, 55, 70) $g_ahCtl2[$eC2_decy] = GUICtrlCreateButton("-", 24 + $iX + 70, 16 + $iY + 0, 17, 17) $g_ahCtl2[$eC2_incy] = GUICtrlCreateButton("+", 24 + $iX + 70, 48 + $iY + 0, 17, 17) $g_ahCtl2[$eC2_decx] = GUICtrlCreateButton("-", 8 + $iX + 70, 32 + $iY + 0, 17, 17) $g_ahCtl2[$eC2_incx] = GUICtrlCreateButton("+", 40 + $iX + 70, 32 + $iY + 0, 17, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) $g_ahCtl2[$eC2_zout] = GUICtrlCreateButton("Zoom -", $iX + 0, $iY + 75, 50, 20) $g_ahCtl2[$eC2_zin] = GUICtrlCreateButton("Zoom +", $iX + 75, $iY + 75, 50, 20) $g_ahCtl2[$eC2_toall] = GUICtrlCreateCheckbox("Apply to all", $iX + 0, $iY + 100, 80, 25) EndFunc ;==>Control_Create_Group2 Func Control_IsChecked($IdCtrl) Return (BitAND(GUICtrlRead($IdCtrl), $GUI_CHECKED) = $GUI_CHECKED) EndFunc ;==>Control_IsChecked Func GDI_Draw_ArrayPoints(ByRef $aPts, $hImage, $g_bClosePath, $iX, $iY, $sFileName, $iSelected = -1) Local $hWnd = GUICtrlGetHandle($hImage) If UBound($aPts) > 1 Then Local $aPoints = GDI_Points($aPts, $iX, $iY) Else Local $aPoints[1][2] = [[0, 0]] EndIf Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hWnd) ;create a graphics object from a window handle _GDIPlus_GraphicsClear($hGraphics, 0xFFFFFFFF) If FileExists($sFileName) Then Local $hBitmap = _GDIPlus_BitmapCreateFromFile($sFileName) Local Const $iWidth = ScaleX(_GDIPlus_ImageGetWidth($hBitmap)) Local Const $iHeight = ScaleY(_GDIPlus_ImageGetHeight($hBitmap)) Local $hBitmap_Scaled = _GDIPlus_ImageResize($hBitmap, $iWidth, $iHeight) ;resize image _GDIPlus_BitmapDispose($hBitmap) ;Done with initial bitmap _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap_Scaled, 0, 0) _GDIPlus_BitmapDispose($hBitmap_Scaled) EndIf Local $hPen = _GDIPlus_PenCreate(0xFFFF0000, ScaleX(1)) Local $hEndCap = _GDIPlus_ArrowCapCreate(1, 1) _GDIPlus_PenSetCustomEndCap($hPen, $hEndCap) If $g_bClosePath Then _GDIPlus_GraphicsDrawPolygon($hGraphics, $aPoints, $hPen) Local $iX0, $iY0, $iX1, $iY1 For $i = 1 To $aPoints[0][0] If Not $g_bClosePath And $i < $aPoints[0][0] Then $iX0 = $aPoints[$i][0] $iY0 = $aPoints[$i][1] $iX1 = $aPoints[$i + 1][0] $iY1 = $aPoints[$i + 1][1] _GDIPlus_GraphicsDrawLine($hGraphics, $iX0, $iY0, $iX1, $iY1, $hPen) EndIf Next _GDIPlus_ArrowCapDispose($hEndCap) _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphics) Point_Selected($aPts, $hImage, $iSelected) EndFunc ;==>GDI_Draw_ArrayPoints Func GDI_Line_hPath_From_Points($aPts, $iXorig, $iYorig) ;Returns hpath object be sure to delete it when finished Local $hPath = _GDIPlus_PathCreate() ;Create new path object Local $aPoints = GDI_Points($aPts, $iXorig, $iYorig) Local $iX0, $iY0, $iX1, $iY1 If IsArray($aPoints) Then For $i = 1 To $aPoints[0][0] - 1 $iX0 = $aPoints[$i][0] $iY0 = $aPoints[$i][1] $iX1 = $aPoints[$i + 1][0] $iY1 = $aPoints[$i + 1][1] _GDIPlus_PathAddLine($hPath, $iX0, $iY0, $iX1, $iY1) Next EndIf Return $hPath ;_GDIPlus_PathDispose($hPath) EndFunc ;==>GDI_Line_hPath_From_Points Func GDI_Points($aPts, $iXo, $iYO) Local $aGDIPts If IsArray($aPts) And UBound($aPts) > 1 Then Local $aGDIPts[UBound($aPts) + 1][2] $aGDIPts[0][0] = UBound($aPts) For $i = 1 To $aGDIPts[0][0] ;Build points list $aGDIPts[$i][0] = ScaleX($aPts[$i - 1][0]) + $iXo $aGDIPts[$i][1] = ScaleY($aPts[$i - 1][1]) + $iYO Next Else Local $aGDIPts[1][2] = [[0, 0]] EndIf Return $aGDIPts EndFunc ;==>GDI_Points Func Image1_Clicked() If Not Control_IsChecked($g_ahCtl1[$eC1_lock]) Then Local $aCPos = ControlGetPos(GUICtrlGetHandle($g_hImage1), "", 0) Local $aPos = MouseGetPos() If IsArray($aPos) And IsArray($aCPos) Then Local $iXn = Int(($aPos[0] - $aCPos[0] + ScaleX(1) / 2) / ScaleX(1)) Local $iYn = Int(($aPos[1] - $aCPos[1] + ScaleY(1) / 2) / ScaleY(1)) Point_Add(List_Index(), $iXn, $iYn) EndIf Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage) Else ToolTip("Locked") Sleep(500) ToolTip("") EndIf EndFunc ;==>Image1_Clicked Func List_Index() Static Local $hWndList1 = GUICtrlGetHandle($g_hList1) Local $iIndex = _GUICtrlListView_GetSelectionMark($hWndList1) If _GUICtrlListView_GetItemSelected($g_hList1, $iIndex) Then Return $iIndex Return -1 EndFunc ;==>List_Index Func List_Update($iIndex = -1) Static $hWnd_List1 = GUICtrlGetHandle($g_hList1) _GUICtrlListView_BeginUpdate($g_hList1) _GUICtrlListView_DeleteAllItems($hWnd_List1) For $i = 0 To UBound($g_aPath_Points) - 1 GUICtrlCreateListViewItem($i & "|" & $g_aPath_Points[$i][0] & "|" & $g_aPath_Points[$i][1], $g_hList1) Next If $iIndex > -1 Then _GUICtrlListView_ClickItem($g_hList1, $iIndex) _GUICtrlListView_EnsureVisible($g_hList1, $iIndex) EndIf _GUICtrlListView_EndUpdate($g_hList1) EndFunc ;==>List_Update Func Point_Add($iIndex, $iX, $iY) If $iIndex <> -1 Then _ArrayInsert($g_aPath_Points, $iIndex, $iX & "|" & $iY, 0) _GUICtrlListView_InsertItem($g_hList1, $iIndex, $iIndex) _GUICtrlListView_SetItemText($g_hList1, $iIndex, $iX, 1) _GUICtrlListView_SetItemText($g_hList1, $iIndex, $iY, 2) _GUICtrlListView_EnsureVisible($g_hList1, $iIndex) Else _ArrayAdd($g_aPath_Points, $iX & "|" & $iY, 0) GUICtrlCreateListViewItem(UBound($g_aPath_Points) - 1 & "|" & $iX & "|" & $iY, $g_hList1) _GUICtrlListView_EnsureVisible($g_hList1, UBound($g_aPath_Points) - 1) EndIf State_Save($g_aPath_Points) EndFunc ;==>Point_Add Func Point_Adjust($iX, $iY, $bToAll) If Not $bToAll Then Local $iIndex = List_Index() If $iIndex == -1 And IsArray($g_aPath_Points) Then $iIndex = UBound($g_aPath_Points) - 1 If $iIndex == -1 Then Return $g_aPath_Points[$iIndex][0] += $iX $g_aPath_Points[$iIndex][1] += $iY _GUICtrlListView_SetItemText($g_hList1, $iIndex, $g_aPath_Points[$iIndex][0], 1) _GUICtrlListView_SetItemText($g_hList1, $iIndex, $g_aPath_Points[$iIndex][1], 2) If $iIndex <> UBound($g_aPath_Points) - 1 Then _GUICtrlListView_ClickItem($g_hList1, $iIndex) Else For $i = 0 To UBound($g_aPath_Points) - 1 $g_aPath_Points[$i][0] += $iX $g_aPath_Points[$i][1] += $iY Next List_Update(List_Index()) EndIf State_Save($g_aPath_Points) Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage) EndFunc ;==>Point_Adjust Func Point_Delete($iIndex) If $iIndex <> -1 Then _ArrayDelete($g_aPath_Points, $iIndex) _GUICtrlListView_DeleteItem($g_hList1, $iIndex) State_Save($g_aPath_Points) ;List_Update($iIndex) EndIf EndFunc ;==>Point_Delete Func Point_Modify($iIndex, $iX, $iY) If $iIndex <> -1 Then $g_aPath_Points[$iIndex][0] = $iX $g_aPath_Points[$iIndex][1] = $iY _GUICtrlListView_SetItemText($g_hList1, $iIndex, $iX, 1) _GUICtrlListView_SetItemText($g_hList1, $iIndex, $iY, 2) _GUICtrlListView_EnsureVisible($g_hList1, $iIndex) State_Save($g_aPath_Points) EndIf EndFunc ;==>Point_Modify Func Point_Selected($aPts, $hImage, $iIndex) If $iIndex > -1 Then GUICtrlSetState($g_hSelSquare, $GUI_HIDE) Local $hWnd = GUICtrlGetHandle($hImage) Local $aPos = ControlGetPos($hWnd, "", 0) If IsArray($aPos) And IsArray($aPts) Then _WinAPI_RedrawWindow($hWnd, Default, Default, $RDW_ERASENOW) Local $iXs = ScaleX($aPts[$iIndex][0]) + $aPos[0] - ScaleX(1) / 2 Local $iYs = ScaleY($aPts[$iIndex][1]) + $aPos[1] - ScaleY(1) / 2 WinMove(GUICtrlGetHandle($g_hSelSquare), "", $iXs, $iYs, ScaleX(1), ScaleY(1)) GUICtrlSetState($g_hSelSquare, $GUI_SHOW) ;ConsoleWrite("Point_Selected" & @CRLF) Else ConsoleWriteError("Error: Point_Selected" & @CRLF) EndIf EndIf EndFunc ;==>Point_Selected Func Point_Swap($iIndex1, $iNext) _GUICtrlListView_BeginUpdate($g_hList1) Local $iIndex2 = 0 Local $aTmp = 0 If $iIndex1 <> -1 Then $iIndex2 = $iIndex1 + $iNext If $iIndex2 > UBound($g_aPath_Points) - 1 Then $iIndex2 = 0 ElseIf $iIndex2 < 0 Then $iIndex2 = UBound($g_aPath_Points) - 1 EndIf _ArraySwap($g_aPath_Points, $iIndex1, $iIndex2) Local $iX1 = _GUICtrlListView_GetItemText($g_hList1, $iIndex1, 2) Local $iY1 = _GUICtrlListView_GetItemText($g_hList1, $iIndex1, 2) Local $iX2 = _GUICtrlListView_GetItemText($g_hList1, $iIndex2, 2) Local $iY2 = _GUICtrlListView_GetItemText($g_hList1, $iIndex2, 2) _GUICtrlListView_SetItemText($g_hList1, $iIndex1, $iX2, 1) _GUICtrlListView_SetItemText($g_hList1, $iIndex1, $iY2, 2) _GUICtrlListView_SetItemText($g_hList1, $iIndex2, $iX1, 1) _GUICtrlListView_SetItemText($g_hList1, $iIndex2, $iY1, 2) _GUICtrlListView_ClickItem($g_hList1, $iIndex2) _GUICtrlListView_EnsureVisible($g_hList1, $iIndex2) Else ;ConsoleWrite("Array Shift" & @CRLF) If $iNext > 0 Then ;ARRAY SHIFT -- Melba23 Local $iUBound = UBound($g_aPath_Points) ; Get size of array $aTmp = _ArrayExtract($g_aPath_Points, 0, $iUBound - 2) ; Extract all but last _ArrayInsert($aTmp, 0, _ArrayExtract($g_aPath_Points, $iUBound - 1, Default)) ; Insert last at top $g_aPath_Points = $aTmp Else $aTmp = _ArrayExtract($g_aPath_Points, 1, Default) ; Extract all but top row _ArrayAdd($aTmp, _ArrayExtract($g_aPath_Points, 0, 0)) ; Add top row at bottom $g_aPath_Points = $aTmp EndIf List_Update(List_Index()) Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage) EndIf State_Save($g_aPath_Points) _GUICtrlListView_EndUpdate($g_hList1) EndFunc ;==>Point_Swap Func Points_Reverse($aPts) Local $hPath = GDI_Line_hPath_From_Points($aPts, 0, 0) ;_GDIPlus_PathFlatten($hPath) _GDIPlus_PathReverse($hPath) Local $aPoints = _GDIPlus_PathGetPoints($hPath) _GDIPlus_PathDispose($hPath) If IsArray($aPoints) Then ;ConsoleWrite("Flipped_Points" & @CRLF) Global $aPts_Rev[$aPoints[0][0]][2] For $i = 1 To $aPoints[0][0] $aPts_Rev[$i - 1][0] = Int($aPoints[$i][0] / ScaleX(1)) $aPts_Rev[$i - 1][1] = Int($aPoints[$i][1] / ScaleY(1)) Next Return $aPts_Rev Else Return $aPts EndIf EndFunc ;==>Points_Reverse Func Points_Rotate($aPts, $iDegrees) Local $hPath = GDI_Line_hPath_From_Points($aPts, 0, 0) ;_GDIPlus_PathFlatten($hPath) Local $hPen = _GDIPlus_PenCreate(0x0, ScaleX(1)) Local $aBounds = _GDIPlus_PathGetWorldBounds($hPath, 0, $hPen) _GDIPlus_PenDispose($hPen) If IsArray($aBounds) Then Local $hMatrix = _GDIPlus_MatrixCreate() _GDIPlus_MatrixTranslate($hMatrix, $aBounds[0] + $aBounds[2] / 2, $aBounds[1] + $aBounds[3] / 2) _GDIPlus_MatrixRotate($hMatrix, $iDegrees) _GDIPlus_MatrixTranslate($hMatrix, -($aBounds[0] + $aBounds[2] / 2), -($aBounds[1] + $aBounds[3] / 2)) _GDIPlus_PathTransform($hPath, $hMatrix) _GDIPlus_MatrixDispose($hMatrix) EndIf Local $aPoints = _GDIPlus_PathGetPoints($hPath) _GDIPlus_PathDispose($hPath) If IsArray($aPoints) Then ;ConsoleWrite("Rotate_Points" & @CRLF) Dim $aPts_Rev[$aPoints[0][0]][2] For $i = 1 To $aPoints[0][0] $aPts_Rev[$i - 1][0] = Int($aPoints[$i][0] / ScaleX(1)) $aPts_Rev[$i - 1][1] = Int($aPoints[$i][1] / ScaleY(1)) Next Return $aPts_Rev Else Return $aPts EndIf EndFunc ;==>Points_Rotate Func Points_Scale($iScaleX, $iScaleY) For $i = 0 To UBound($g_aPath_Points) - 1 If $iScaleX > 0 Then $g_aPath_Points[$i][0] *= 2 Else $g_aPath_Points[$i][0] /= 2 EndIf If $iScaleY > 0 Then $g_aPath_Points[$i][1] *= 2 Else $g_aPath_Points[$i][1] /= 2 EndIf Next State_Save($g_aPath_Points) List_Update(List_Index()) Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage) EndFunc ;==>Points_Scale Func Points_Update($aPts, $g_bClosePath = False, $b_Show_Image = True, $iSelected = -1) Local $_Image_File = $g_sImagefile If Not $b_Show_Image Then $_Image_File = "" GDI_Draw_ArrayPoints($aPts, $g_hImage1, $g_bClosePath, 0, 0, $_Image_File, $iSelected) EndFunc ;==>Points_Update Func ScaleX($iX) Local $iXs = $g_iXScale If $iXs == 0 Then $iXs = -1 If $iXs > 0 Then $iX = $iX * $iXs Else $iX = $iX / Abs($iXs) EndIf Return $iX EndFunc ;==>ScaleX Func ScaleY($iY) Local $iYs = $g_iYScale If $iYs == 0 Then $iYs = -1 If $iYs > 0 Then $iY = $iY * $iYs Else $iY = $iY / Abs($iYs) EndIf Return $iY EndFunc ;==>ScaleY Func SelSquare_Drag() Local $iIndex = List_Index() If $iIndex <> -1 Then Local $cInfo = GUIGetCursorInfo($g_hForm1) Local $aPosSelOrig = ControlGetPos($g_hForm1, "", $g_hSelSquare) If IsArray($aPosSelOrig) Then Local $iSubtractX = $cInfo[0] - $aPosSelOrig[0] Local $iSubtractY = $cInfo[1] - $aPosSelOrig[1] EndIf If IsArray($cInfo) Then Do $cInfo = GUIGetCursorInfo($g_hForm1) ControlMove($g_hForm1, "", $g_hSelSquare, $cInfo[0] - $iSubtractX, $cInfo[1] - $iSubtractY) Until Not $cInfo[2] EndIf Local $aPosSelNew = ControlGetPos($g_hForm1, "", $g_hSelSquare) If IsArray($aPosSelNew) And IsArray($aPosSelOrig) Then Local $iXm = $g_aPath_Points[$iIndex][0] + Int(($aPosSelNew[0] - $aPosSelOrig[0]) / ScaleX(1)) Local $iYm = $g_aPath_Points[$iIndex][1] + Int(($aPosSelNew[1] - $aPosSelOrig[1]) / ScaleY(1)) Point_Modify($iIndex, $iXm, $iYm) Points_Update($g_aPath_Points, $g_bClosePath, $g_bShowImage, $iIndex) EndIf EndIf EndFunc ;==>SelSquare_Drag Func SplitDir($FullPath) Local $sDrive, $sDir, $sDummy _PathSplit($FullPath, $sDrive, $sDir, $sDummy, $sDummy) Return $sDrive & $sDir EndFunc ;==>SplitDir Func SplitFileName($FullPath) Local $sDummy, $sFileName, $sExt _PathSplit($FullPath, $sDummy, $sDummy, $sFileName, $sExt) Return $sFileName & "" & $sExt EndFunc ;==>SplitFileName Func State_Cleanup(ByRef $a1) If (UBound($a1) > $g_iUndo_Max + 2) Then Local $a1Rem = _ArrayExtract($a1, 1, Default) $a1Rem[0] = $a1[0] Local $sTmp = $a1[1] If $sTmp <> "" And FileExists($sTmp) Then FileDelete($sTmp) ;ConsoleWrite("Cleanup Delete (UnD) " & $sTmp & @CRLF) EndIf $a1 = $a1Rem EndIf EndFunc ;==>State_Cleanup Func State_Destroy($bRedo_Only = False) Local $sTmp While (UBound($g_asRedo_Files) > 1) $sTmp = _ArrayPop($g_asRedo_Files) If $sTmp <> "" And FileExists($sTmp) Then FileDelete($sTmp) ;ConsoleWrite(", Delete (ReD) " & $sTmp) If @error Then ConsoleWriteError("Failed to Delete " & $sTmp) EndIf WEnd GUICtrlSetState($g_ahCtl1[$eC1_redo], $GUI_DISABLE) If $bRedo_Only Then Return While (UBound($g_asUndo_Files) > 1) $sTmp = _ArrayPop($g_asUndo_Files) If $sTmp <> "" And FileExists($sTmp) Then FileDelete($sTmp) ;ConsoleWrite(", Delete (UnD)" & $sTmp) If @error Then ConsoleWriteError("Failed to Delete " & $sTmp) EndIf WEnd GUICtrlSetState($g_ahCtl1[$eC1_undo], $GUI_DISABLE) EndFunc ;==>State_Destroy Func State_Is_Diff(ByRef $a1, ByRef $a2) Local $bIsDiff = True If UBound($a1) = UBound($a2) Then $bIsDiff = False For $i = UBound($a1) - 1 To 0 Step -1 If $a1[$i][0] == $a2[$i][0] And $a1[$i][1] == $a2[$i][1] Then ContinueLoop Else ;ConsoleWrite("Diff " & $i & @CRLF) $bIsDiff = True ExitLoop EndIf Next Else ;ConsoleWrite("Diff " & @CRLF) EndIf Return $bIsDiff EndFunc ;==>State_Is_Diff Func State_Restore(ByRef $aPts, $bUndo) Local $sTmp = "" Local $aRes If $bUndo Then $sTmp = _ArrayPop($g_asUndo_Files) ;ConsoleWrite(", Restore (UnD)" & $sTmp) If $sTmp <> "" And FileExists($sTmp) Then _ArrayAdd($g_asRedo_Files, $sTmp) _FileReadToArray($sTmp, $aRes, 0, ",") If UBound($g_asUndo_Files) < 2 Then GUICtrlSetState($g_ahCtl1[$eC1_undo], $GUI_DISABLE) If UBound($g_asRedo_Files) > 2 Then GUICtrlSetState($g_ahCtl1[$eC1_redo], $GUI_ENABLE) If UBound($g_asUndo_Files) > 1 And Not State_Is_Diff($aPts, $aRes) Then Return State_Restore($aPts, $bUndo) If Not @error Then Return $aRes Else ConsoleWriteError("Failed to Restore " & $sTmp) EndIf Else $sTmp = _ArrayPop($g_asRedo_Files) ;ConsoleWrite(", Restore (ReD) " & $sTmp) If $sTmp <> "" And FileExists($sTmp) Then _ArrayAdd($g_asUndo_Files, $sTmp) _FileReadToArray($sTmp, $aRes, 0, ",") If UBound($g_asRedo_Files) < 2 Then GUICtrlSetState($g_ahCtl1[$eC1_redo], $GUI_DISABLE) If UBound($g_asUndo_Files) > 2 Then GUICtrlSetState($g_ahCtl1[$eC1_undo], $GUI_ENABLE) If UBound($g_asRedo_Files) > 1 And Not State_Is_Diff($aPts, $aRes) Then Return State_Restore($aPts, $bUndo) If Not @error Then Return $aRes Else ConsoleWriteError("Failed to Restore " & $sTmp) EndIf EndIf Return $aPts EndFunc ;==>State_Restore Func State_Save($aPts) If $g_iUndo_Max < 1 Then Return Local $sTmp = _TempFile(@TempDir, "DPP_") If UBound($g_asRedo_Files) > 2 Then _ArrayAdd($g_asUndo_Files, _ArrayPop($g_asRedo_Files)) _ArrayAdd($g_asUndo_Files, $sTmp) _FileWriteFromArray($sTmp, $aPts, 0, Default, ",") If UBound($g_asRedo_Files) > 2 Then State_Destroy(True) State_Cleanup($g_asUndo_Files) ;ConsoleWrite("Save State " & UBound($g_asUndo_Files) & " " & $sTmp & @CRLF) If UBound($g_asUndo_Files) > 2 Then GUICtrlSetState($g_ahCtl1[$eC1_undo], $GUI_ENABLE) If @error Then MsgBox(0, @ScriptName & " Error", "Unable to create undo file " & $sTmp) GUICtrlSetState($g_ahCtl1[$eC1_undo], $GUI_DISABLE) GUICtrlSetState($g_ahCtl1[$eC1_redo], $GUI_DISABLE) $g_iUndo_Max = 0 EndIf EndFunc ;==>State_Save Func Tab1_Select() Local $iStateCtl1, $iStateCtl2 Local $tabindex = GUICtrlRead($g_hTab1) ;ConsoleWrite("tab" & $tabindex + 1 & "_selected" & @CRLF) Select Case $tabindex = 0 $iStateCtl1 = $GUI_SHOW $iStateCtl2 = $GUI_HIDE Case $tabindex = 1 $iStateCtl1 = $GUI_HIDE $iStateCtl2 = $GUI_SHOW Case Else _GUICtrlTab_ActivateTab($g_hTab1, 0) Return EndSelect For $i = 0 To UBound($g_ahCtl1) - 1 GUICtrlSetState($g_ahCtl1[$i], $iStateCtl1) Next For $i = 0 To UBound($g_ahCtl2) - 1 GUICtrlSetState($g_ahCtl2[$i], $iStateCtl2) Next EndFunc ;==>Tab1_Select Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) Static Local $hWndList1 = GUICtrlGetHandle($g_hList1) If Not IsHWnd($hWndList1) Then $hWndList1 = GUICtrlGetHandle($g_hList1) If @error Then Return $GUI_RUNDEFMSG If $wParam = $g_hList1 Then Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) Switch DllStructGetData($tNMHDR, "Code") Case $LVN_KEYDOWN, $NM_CLICK GUICtrlSendToDummy($g_hList1_LVN, $lParam) EndSwitch EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY  


      DrawPathPoints.au3
    • fenhanxue
      By fenhanxue
      i want to copy a picture file to clipboard, so that i can paste the picture through ctrl+V
      this is my code ,but it dosen't work :
      #AutoIt3Wrapper_UseX64 = n #Include <Clipboard.au3> #include <GDIPlus.au3> _GDIPlus_Startup() $hClipboard_Bitmap = _GDIPlus_BitmapCreateFromFile('C:\1.jpg') _ClipBoard_Open(0) _ClipBoard_SetDataEx($hClipboard_Bitmap,$CF_BITMAP) _ClipBoard_Close() _GDIPlus_Shutdown() can you help me
×