Jump to content

[SOLVED] GDI+ Path Transform rotate


 Share

Recommended Posts

Hello friends,

I'm again with a GDI+ problem,

I want to rotate a Path, but it seems that its connected to the Graphics object,

when the path is at the top left corner if I rotate it by 180degrees it goes to the bottom right corner. I want to rotate it to the bottom left corner.

Second thing I tried is, to retrieve the graphics of the window where the path would be drawn using _Winapi_GetDCEx, thereafter I translated the matrix to the center and rotated the path but the path went out of the client coordinates.

Now I'm not able to go forward, please help

This is the code I have so far

#include <GDIP.au3> ;http://www.autoitscript.com/forum/topic/106021-gdipau3/
#include <WinAPIEx.au3>
#include <GuiConstants.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <APIConstants.au3>
#include <Array.au3>
#include <Misc.au3>

Global $GuiSizeX = 400, $GuiSizeY = 400, $iSlider, $iData

$hGui = GUICreate("Paths", $GuiSizeX, $GuiSizeY)
GUICtrlCreateLabel("Rotate Angle", 10, 300, -1, 15)
$iSlider = GUICtrlCreateSlider(10, 320, 380, 20)
GUICtrlSetLimit(-1, 360, -360)

GUICtrlCreateButton("Set Arc", 320, 300, 60, 20)
GUICtrlCreateButton("Reset", 240, 300, 60, 20)

GUISetState()

_GDIPlus_Startup()

$hGraphicGUI = _GDIPlus_GraphicsCreateFromHWND($hGui)
$hBMPBuff = _GDIPlus_BitmapCreateFromGraphics($GuiSizeX, $GuiSizeY, $hGraphicGUI)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hBMPBuff)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2) ;Anti-Alias

Global $hPath = _GDIPlus_PathCreate()

GUIRegisterMsg($WM_PAINT, "MY_PAINT"); Register PAINT-Event
GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL")

Do
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
Case $iSlider + 2
Erase()
Case $iSlider + 1
MsgBox(0, 0, "0 Radian Arc")
SetArc(5, 15, 20, 0, $hGui)
MsgBox(0, 0, "Pie Radian Arc")
SetArc(5, 15, 20, 180, $hGui) ;<<<<<<< This is not inside the Client area, the path rotation is not just getting done.
EndSwitch
Until 0

Func SetArc($iX = 0, $iY = 0, $iSide = 20, $iRotate = 0, $hWnd = 0)

;* Not required when the path is in order.
_GDIPlus_PathStartFigure($hPath) ;*
_GDIPlus_PathAddLine($hPath, $iX + $iSide, $iY, $iX + $iSide, $iY + $iSide)
_GDIPlus_PathAddLine($hPath, $iX + $iSide, $iY + $iSide, $iX, $iY + $iSide)
_GDIPlus_PathAddLine($hPath, $iX, $iY + $iSide, $iX, $iY)
_GDIPlus_PathAddArc($hPath, $iX, $iY - $iSide / 2, $iSide, $iSide, -180, -180)
_GDIPlus_PathCloseFigure($hPath) ;*

If $iRotate Then
Path_Rotate_Draw($hPath, $hWnd, $iRotate)
Else
_GDIPlus_GraphicsDrawPath($hGraphic, $hPath)
EndIf

_GDIPlus_PathReset($hPath)
_WinAPI_RedrawWindow($hGui, 0, 0, 2)

EndFunc ;==>SetArc

Func Erase()

_GDIPlus_GraphicsClear($hGraphic, 0x00FFFFFF)
_WinAPI_RedrawWindow($hGui, 0, 0, BitOR($RDW_INVALIDATE, $RDW_ERASE))

EndFunc ;==>Erase

;Func to redraw the BMP on PAINT MSG
Func MY_PAINT($hWnd, $Msg, $wParam, $lParam)
; Check, if the GUI with the Graphic should be repainted
_GDIPlus_GraphicsDrawImage($hGraphicGUI, $hBMPBuff, 0, 0)
EndFunc ;==>MY_PAINT

Func WM_HSCROLL()
$iData = GUICtrlRead($iSlider)
ToolTip($iData)
EndFunc ;==>WM_HSCROLL

Func Path_Rotate_Draw(ByRef $hPath, $hWnd, $iAngle)
$aBound = _Gdiplus_PathGetWorldBounds($hPath)
;~ _ArrayDisplay($aBound)
$hRgn = _WinAPI_CreateRectRgn($aBound[0], $aBound[1], $aBound[0] + $aBound[2], $aBound[1] + $aBound[3])
$hDC = _WinAPI_GetDCEx($hWnd, $hRgn, $DCX_INTERSECTRGN)
$hGfx = _GDIPlus_GraphicsCreateFromHDC($hDC)
$hMatrix = _GDIPlus_MatrixCreate()
_GDIPlus_GraphicsClear($hGfx)
;Translate
_GDIPlus_MatrixTranslate($hMatrix, $aBound[2] /2, $aBound[3] / 2)
;Rotate
_GDIPlus_MatrixRotate($hMatrix, $iAngle)

_GDIPlus_PathTransform($hPath, $hMatrix)
$aBound = _Gdiplus_PathGetWorldBounds($hPath)
_ArrayDisplay($aBound, "Path World Bounds") ;Why this is not inside the Client Area ?
_GDIPlus_GraphicsDrawPath($hGfx, $hPath)

;Mem release.
_GDIPlus_MatrixDispose($hMatrix)
_GDIPlus_GraphicsDispose($hGfx)
_WinAPI_ReleaseDC($hWnd, $hDC)
_WinAPI_DeleteObject($hRgn)
EndFunc

Func Clear()
ToolTip("")
AdlibUnRegister("Clear")
EndFunc ;==>Clear

;Mem Release
_GDIPlus_PathDispose($hPath)
_GDIPlus_GraphicsDispose($hGraphicGUI)
_GDIPlus_BitmapDispose($hBMPBuff)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()

Thanks for your time :)

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

I get a lot of error when starting your code! Mostly related to redeclared constants.

Br,

UEZ

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

Selection of finest graphical examples at Codepen.io

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

Link to comment
Share on other sites

Please check this

#include <GDIP.au3>   ;http://www.autoitscript.com/forum/topic/106021-gdipau3/
#include <WinAPIEx.au3>
#include <GuiConstants.au3>
#include <WindowsConstants.au3>

Global $GuiSizeX = 400, $GuiSizeY = 400, $iSlider, $iData

$hGui = GUICreate("Paths", $GuiSizeX, $GuiSizeY)

$iArc = GUICtrlCreateButton("Set Arc", 320, 300, 60, 20)
GUICtrlCreateButton("Reset", 240, 300, 60, 20)

GUISetState()

_GDIPlus_Startup()

$hGraphicGUI = _GDIPlus_GraphicsCreateFromHWND($hGui)
$hBMPBuff = _GDIPlus_BitmapCreateFromGraphics($GuiSizeX, $GuiSizeY, $hGraphicGUI)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hBMPBuff)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2) ;Anti-Alias

Global $hPath = _GDIPlus_PathCreate()

GUIRegisterMsg($WM_PAINT, "MY_PAINT"); Register PAINT-Event

Do
Switch GUIGetMsg()

Case $GUI_EVENT_CLOSE
ExitLoop

Case $iArc
MsgBox(0, 0, "0 Radian Arc")
SetArc(5, 15, 20, 0)
MsgBox(0, 0, "Pie Radian Arc")
SetArc(5, 15, 20, 180) ;<<<<<<<<<<<<<<<< This one is supposed to be just below the first one

Case $iArc + 1
Erase()

EndSwitch
Until 0

Func SetArc($iX = 0, $iY = 0, $iSide = 20, $iRotate = 0)

;* Not required when the path is in order.
_GDIPlus_PathStartFigure($hPath) ;*
_GDIPlus_PathAddLine($hPath, $iX + $iSide, $iY, $iX + $iSide, $iY + $iSide)
_GDIPlus_PathAddLine($hPath, $iX + $iSide, $iY + $iSide, $iX, $iY + $iSide)
_GDIPlus_PathAddLine($hPath, $iX, $iY + $iSide, $iX, $iY)
_GDIPlus_PathAddArc($hPath, $iX, $iY - $iSide / 2, $iSide, $iSide, -180, -180)
_GDIPlus_PathCloseFigure($hPath) ;*
$aBounds = _GdiPLus_PathGetWorldBounds($hPath)

If $iRotate Then

$hMatrix = _GDIPlus_MatrixCreate()
_GDIPlus_MatrixTranslate($hMatrix, $aBounds[0] + ($aBounds[2] / 2), $GuiSizeY / 2) ;<<<<<<<<<<<<<<<<<< I guess some error here
_GDIPlus_MatrixRotate($hMatrix, $iRotate)
_GDIPlus_PathTransform($hPath, $hMatrix)
_GDIPlus_MatrixDispose($hMatrix)

EndIf
_GDIPlus_GraphicsDrawPath($hGraphic, $hPath)

_GDIPlus_PathReset($hPath)
_WinAPI_RedrawWindow($hGui, 0, 0, 2)

EndFunc   ;==>SetArc

Func Erase()

_GDIPlus_GraphicsClear($hGraphic, 0x00FFFFFF)
_WinAPI_RedrawWindow($hGui, 0, 0, BitOR($RDW_INVALIDATE, $RDW_ERASE))

EndFunc   ;==>Erase

;Func to redraw the BMP on PAINT MSG
Func MY_PAINT($hWnd, $Msg, $wParam, $lParam)
; Check, if the GUI with the Graphic should be repainted
_GDIPlus_GraphicsDrawImage($hGraphicGUI, $hBMPBuff, 0, 0)
EndFunc   ;==>MY_PAINT

;Mem Release
_GDIPlus_PathDispose($hPath)
_GDIPlus_GraphicsDispose($hGraphicGUI)
_GDIPlus_BitmapDispose($hBMPBuff)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

Hmmm, now getting already defined functions erros! Which AutoIt, WinAPIEx version you are using?

Edit: seems to be a problem with GDIP.au3 and WinAPIEx.au3.

Br,

UEZ

Edited by UEZ

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

Selection of finest graphical examples at Codepen.io

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

Link to comment
Share on other sites

Filename: WinAPIEx.au3 Version: 3.8 / 3.3.8.0

I don't know the version of GDIP.au3

The WinapiEx isn't required for the moment,

do you get error with the WinAPI

#include-once
#include <GDIP.au3> ;http://www.autoitscript.com/forum/topic/106021-gdipau3/
#include <WinAPI.au3>
#include <GuiConstants.au3>
#include <WindowsConstants.au3>

Global $GuiSizeX = 400, $GuiSizeY = 400, $iSlider, $iData

$hGui = GUICreate("Paths", $GuiSizeX, $GuiSizeY)

$iArc = GUICtrlCreateButton("Set Arc", 320, 300, 60, 20)
GUICtrlCreateButton("Reset", 240, 300, 60, 20)

GUISetState()

_GDIPlus_Startup()

$hGraphicGUI = _GDIPlus_GraphicsCreateFromHWND($hGui)
$hBMPBuff = _GDIPlus_BitmapCreateFromGraphics($GuiSizeX, $GuiSizeY, $hGraphicGUI)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hBMPBuff)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2) ;Anti-Alias

Global $hPath = _GDIPlus_PathCreate()

GUIRegisterMsg($WM_PAINT, "MY_PAINT"); Register PAINT-Event

Do
Switch GUIGetMsg()

Case $GUI_EVENT_CLOSE
ExitLoop

Case $iArc
MsgBox(0, 0, "0 Radian Arc")
SetArc(5, 15, 20, 0)
MsgBox(0, 0, "Pie Radian Arc")
SetArc(5, 15, 20, 180) ;<<<<<<<<<<<<<<<< This one is supposed to be just below the first one

Case $iArc + 1
Erase()

EndSwitch
Until 0

Func SetArc($iX = 0, $iY = 0, $iSide = 20, $iRotate = 0)

;* Not required when the path is in order.
_GDIPlus_PathStartFigure($hPath) ;*
_GDIPlus_PathAddLine($hPath, $iX + $iSide, $iY, $iX + $iSide, $iY + $iSide)
_GDIPlus_PathAddLine($hPath, $iX + $iSide, $iY + $iSide, $iX, $iY + $iSide)
_GDIPlus_PathAddLine($hPath, $iX, $iY + $iSide, $iX, $iY)
_GDIPlus_PathAddArc($hPath, $iX, $iY - $iSide / 2, $iSide, $iSide, -180, -180)
_GDIPlus_PathCloseFigure($hPath) ;*
$aBounds = _GdiPLus_PathGetWorldBounds($hPath)

If $iRotate Then

$hMatrix = _GDIPlus_MatrixCreate()
_GDIPlus_MatrixTranslate($hMatrix, $aBounds[0] + ($aBounds[2] / 2), $GuiSizeY / 2) ;<<<<<<<<<<<<<<<<<< I guess some error here
_GDIPlus_MatrixRotate($hMatrix, $iRotate)
_GDIPlus_PathTransform($hPath, $hMatrix)
_GDIPlus_MatrixDispose($hMatrix)

EndIf
_GDIPlus_GraphicsDrawPath($hGraphic, $hPath)

_GDIPlus_PathReset($hPath)
_WinAPI_RedrawWindow($hGui, 0, 0, 2)

EndFunc ;==>SetArc

Func Erase()

_GDIPlus_GraphicsClear($hGraphic, 0x00FFFFFF)
_WinAPI_RedrawWindow($hGui, 0, 0, BitOR($RDW_INVALIDATE, $RDW_ERASE))

EndFunc ;==>Erase

;Func to redraw the BMP on PAINT MSG
Func MY_PAINT($hWnd, $Msg, $wParam, $lParam)
; Check, if the GUI with the Graphic should be repainted
_GDIPlus_GraphicsDrawImage($hGraphicGUI, $hBMPBuff, 0, 0)
EndFunc ;==>MY_PAINT

;Mem Release
_GDIPlus_PathDispose($hPath)
_GDIPlus_GraphicsDispose($hGraphicGUI)
_GDIPlus_BitmapDispose($hBMPBuff)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

Now it's running without any em. I will have a closer look when I find some time - latest on next Tuesday.

Br,

UEZ

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

Selection of finest graphical examples at Codepen.io

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

Link to comment
Share on other sites

thanks :)

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

I found some minutes so try this here:

#include-once
#include <GDIP.au3> ;http://www.autoitscript.com/forum/topic/106021-gdipau3/
#include <WinAPI.au3>
#include <GuiConstants.au3>
#include <WindowsConstants.au3>

Global $GuiSizeX = 400, $GuiSizeY = 400, $iSlider, $iData

$hGui = GUICreate("Paths", $GuiSizeX, $GuiSizeY)
GUISetBkColor(0xFFFFFF)
$iArc = GUICtrlCreateButton("Set Arc", 320, 300, 60, 20)
GUICtrlCreateButton("Reset", 240, 300, 60, 20)

GUISetState()

_GDIPlus_Startup()

$hGraphicGUI = _GDIPlus_GraphicsCreateFromHWND($hGui)
$hBMPBuff = _GDIPlus_BitmapCreateFromGraphics($GuiSizeX, $GuiSizeY - 150, $hGraphicGUI)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hBMPBuff)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2) ;Anti-Alias
GUIRegisterMsg($WM_PAINT, "MY_PAINT"); Register PAINT-Event

Do
    Switch GUIGetMsg()

        Case $GUI_EVENT_CLOSE
            ExitLoop

        Case $iArc
            _GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)
;~          MsgBox(0, 0, "0 Radian Arc")
            SetArc(250, 15, 20, 0)
;~          MsgBox(0, 0, "Pie Radian Arc")
            SetArc(250, 50, 20, 180) ;<<<<<<<<<<<<<<<< This one is supposed to be just below the first one
            SetArc(220, 32, 20, -90)
            SetArc(280, 32, 20, 90)
Case $iArc + 1
            Erase()

    EndSwitch
Until 0

Func SetArc($iX = 0, $iY = 0, $iSide = 20, $iRotate = 0)

    Local $hPath = _GDIPlus_PathCreate()
    ;* Not required when the path is in order.
    _GDIPlus_PathStartFigure($hPath) ;*
    _GDIPlus_PathAddLine($hPath, $iX + $iSide, $iY, $iX + $iSide, $iY + $iSide)
    _GDIPlus_PathAddLine($hPath, $iX + $iSide, $iY + $iSide, $iX, $iY + $iSide)
    _GDIPlus_PathAddLine($hPath, $iX, $iY + $iSide, $iX, $iY)
    _GDIPlus_PathAddArc($hPath, $iX, $iY - $iSide / 2, $iSide, $iSide, -180, -180)
    _GDIPlus_PathCloseFigure($hPath) ;*
    $aBounds = _GdiPLus_PathGetWorldBounds($hPath)

    If $iRotate Then
        $hMatrix = _GDIPlus_MatrixCreate()
        _GDIPlus_MatrixTranslate($hMatrix, $aBounds[0] + $aBounds[2] / 2, $aBounds[1] + $aBounds[3] / 2)
        _GDIPlus_MatrixRotate($hMatrix, $iRotate)
        _GDIPlus_MatrixTranslate($hMatrix, -($aBounds[0] + $aBounds[2] / 2), -($aBounds[1] + $aBounds[3] / 2))
        _GDIPlus_PathTransform($hPath, $hMatrix)
        _GDIPlus_MatrixDispose($hMatrix)
    EndIf
    _GDIPlus_GraphicsDrawPath($hGraphic, $hPath)

    _GDIPlus_PathDispose($hPath)
    _WinAPI_RedrawWindow($hGui, 0, 0, 2)

EndFunc   ;==>SetArc

Func Erase()

    _GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)
    _WinAPI_RedrawWindow($hGui, 0, 0, BitOR($RDW_INVALIDATE, $RDW_ERASE))

EndFunc   ;==>Erase

;Func to redraw the BMP on PAINT MSG
Func MY_PAINT($hWnd, $Msg, $wParam, $lParam)
    ; Check, if the GUI with the Graphic should be repainted
    _GDIPlus_GraphicsDrawImage($hGraphicGUI, $hBMPBuff, 0, 0)
EndFunc   ;==>MY_PAINT

;Mem Release
_GDIPlus_GraphicsDispose($hGraphicGUI)
_GDIPlus_BitmapDispose($hBMPBuff)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()

Br,

UEZ

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

Selection of finest graphical examples at Codepen.io

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

Link to comment
Share on other sites

Thanks.

I get it I missed the Resetting the translation after rotation

Thank you so much :)

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

Create an account or sign in to comment

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

Create an account

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

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

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