Sign in to follow this  
Followers 0
lordofthestrings

Geotriangle on screen

12 posts in this topic

#1 ·  Posted (edited)

Update:

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=Triangle.exe
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <misc.au3>
Global $EndPosMouse
HotKeySet("{LEFT}", "Rotate_Left")
HotKeySet("{RIGHT}", "Rotate_Right")
HotKeySet("{UP}", "Freeze")
HotKeySet("{DOWN}", "clear")
HotKeySet("{ESC}", "Exit_Completely")
 
_GDIPlus_Startup()
 
$hBmp_Triangle = DrawTriangle()
Global $iW = _GDIPlus_ImageGetWidth($hBmp_Triangle)
Global $iH = _GDIPlus_ImageGetHeight($hBmp_Triangle)
;Default, BitOR($WS_EX_LAYERED, $WS_EX_TOOLWINDOW))
;$hGUI = GUICreate("GDI+", 2 * $iW, 2 * $iH, 0, 0, Default, BitOR($WS_EX_LAYERED, $WS_EX_TOOLWINDOW)) ;$WS_MAXIMIZE, BitOR($WS_EX_MDICHILD, $WS_EX_TRANSPARENT, $WS_EX_DLGMODALFRAME)) ; ;,
$hGUI = GUICreate("GDI+", @DesktopWidth, @DesktopHeight, 0, 0, Default, BitOR($WS_EX_LAYERED, $WS_EX_TOOLWINDOW));, $WS_MAXIMIZE, BitOR($WS_EX_MDICHILD, $WS_EX_TRANSPARENT, $WS_EX_DLGMODALFRAME))
 
GUISetState()
Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics( 2 * $iW, 2 * $iH, $hGraphic)
Global $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
Global $hBrush, $hFormat, $hFamily, $hFont, $tLayout
$hPen = _GDIPlus_PenCreate()
$ScreenDc = _WinAPI_GetDC($hGUI)
$GDIBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
$dc = _WinAPI_CreateCompatibleDC($ScreenDc)
_WinAPI_SelectObject($dc, $GDIBitmap)
 
;  _WinAPI_UpdateLayeredWindow parameters
$tSize = DllStructCreate($tagSIZE)
$pSize = DllStructGetPtr($tSize)
DllStructSetData($tSize, "X", 2 * $iW)
DllStructSetData($tSize, "Y", 2 * $iH)
$tSource = DllStructCreate($tagPOINT)
$pSource = DllStructGetPtr($tSource)
$tBlend = DllStructCreate($tagBLENDFUNCTION)
$pBlend = DllStructGetPtr($tBlend)
DllStructSetData($tBlend, "Alpha", 0xFF)
DllStructSetData($tBlend, "Format", 1)
$tPoint = DllStructCreate($tagPOINT)
$pPoint = DllStructGetPtr($tPoint)
DllStructSetData($tPoint, "X", 0)
DllStructSetData($tPoint, "Y", 0)
 
$counter = 0
 
Local $hDLL = DllOpen("user32.dll")
Global $hMatrix = _GDIPlus_MatrixCreate()
Global $hBmp_Rotate = _GDIPlus_BitmapCreateFromScan0(2 * $iW, 2 * $iH)
Global $hGfx_BmpRotate = _GDIPlus_ImageGetGraphicsContext($hBmp_Rotate)
 
While 1
    $mousepos = MouseGetPos()
    clear()
    rotator($counter)
If _IsPressed("51", $hDLL) Then
Sleep(10000)
EndIf
    Sleep(20)
WEnd
 
 
Func Rotate_Left()
    $counter -= 0.5
    rotator($counter)
EndFunc   ;==>Rotate_Left
 
Func Rotate_Right()
    $counter += 0.5
    rotator($counter)
EndFunc   ;==>Rotate_Right
 
Func Freeze()
$iRotation=0
If Not $counter = 0 Then
If $counter>0 Then
For $iRotation = 0.5 To $counter Step 0.5
Send("{LEFT}")
rotator($counter)
Next
Else
For $iRotation = $counter To -0.5 Step 0.5
Send("{RIGHT}")
rotator(-$counter)
Next
EndIf
EndIf
If $counter = 0 Then
; _GDIPlus_BitmapLockBits
EndIf
Return $counter
EndFunc   ;==>Freeze
 
Func clear()
    _GDIPlus_GraphicsClear($hBackbuffer, 0x00F0F0F0)
    _GDIPlus_GraphicsClear($hGfx_BmpRotate, 0x00F0F0F0)
EndFunc   ;==>clear
 
Func DrawCounter($TextToDraw = "Hello World", $LeftTopX=0, $LeftTopY=0)
$hBrush = _GDIPlus_BrushCreateSolid(0x7FFF007F)
$hFormat = _GDIPlus_StringFormatCreate()
$hFamily = _GDIPlus_FontFamilyCreate("Arial")
$hFont = _GDIPlus_FontCreate($hFamily, 18, 2)
$tLayout = _GDIPlus_RectFCreate($LeftTopX+800, $LeftTopY+50, 20, 40)
_GDIPlus_GraphicsDrawStringEx($hGraphic, $TextToDraw, $hFont, $tLayout, $hFormat, $hBrush)
EndFunc
 
Func DrawTriangle($MouseX = 470, $MouseY = 0)
    Local $hBitmap = _GDIPlus_BitmapCreateFromScan0(2 * $MouseX, $MouseX)
    Local $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
    Local $hPen3 = _GDIPlus_PenCreate(0xFFFFFFFF)
    Local $hPen2 = _GDIPlus_PenCreate(0xFF0000F0)
    Local $hPen = _GDIPlus_PenCreate(0xEEAAAAAA)
_GDIPlus_GraphicsDrawArc($hGraphic, $MouseX-150, $MouseY-100, 300, 300, +170, -160,$hPen3) ; arc or Arch
_GDIPlus_GraphicsDrawLine($hGraphic, $MouseX - 470, $MouseY, $MouseX, $MouseY + 470, $hPen) ; triangle
_GDIPlus_GraphicsDrawLine($hGraphic, $MouseX - 470, $MouseY, $MouseX + 470, $MouseY, $hPen) ; triangle
_GDIPlus_GraphicsDrawLine($hGraphic, $MouseX, $MouseY + 470, $MouseX + 470, $MouseY, $hPen) ; triangle
_GDIPlus_GraphicsDrawLine($hGraphic, $MouseX, $MouseY+470, $MouseX, $MouseY, $hPen)  ;90° angle line
; add millimeter + Centimeter lines
$counter = 1
For $i = -470 To 470 Step 5
If $counter >= 1 And $counter <=6 Then
_GDIPlus_GraphicsDrawLine($hGraphic, $MouseX-$i, $MouseY, $MouseX-$i, $MouseY+5, $hPen2)
$counter += 1
EndIf
If $counter = 6 Then
_GDIPlus_GraphicsDrawLine($hGraphic, $MouseX-$i, $MouseY, $MouseX-$i, $MouseY+15, $hPen2)
$counter = 1
EndIf
Next
; add 180 Angle (those on the diagonal sides) + Horizontal lines
$counter = 1
For $a = 5.2 To 470 Step 5.2
If $counter >= 1 And $counter <=6 Then
_GDIPlus_GraphicsDrawLine($hGraphic, $a,$a-1,$a+5,$a-7, $hPen2) ; Left half side millimeter lines
_GDIPlus_GraphicsDrawLine($hGraphic, $a+470,470-$a,470+$a-5,470-$a-7, $hPen2) ; Right "" "" ""
$counter += 1
EndIf
If $counter = 6 Then
_GDIPlus_GraphicsDrawLine($hGraphic, $a,$a-1,$a+12,$a-15, $hPen2) ; Left half side centimeter lines
_GDIPlus_GraphicsDrawLine($hGraphic, $a+470,470-$a,470+$a-12,470-$a-15, $hPen2) ; Right ""  "" "" ""
If $MouseY + $a <400 then _GDIPlus_GraphicsDrawLine($hGraphic, _
($MouseX - 400 + $a), $MouseY + $a, ($MouseX + 400 - $a), $MouseY + $a, $hPen) ; Horizontal lines
$counter = 1
EndIf
Next
; _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX-235, $MouseY, $MouseX+117.5, $MouseY+352.5, $hPen)
; _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX+235, $MouseY, $MouseX-117.5, $MouseY+352.5, $hPen)
_GDIPlus_GraphicsDrawLine($hGraphic, $MouseX, $MouseY, $MouseX+235, $MouseY+235, $hPen)
_GDIPlus_GraphicsDrawLine($hGraphic, $MouseX, $MouseY, $MouseX-235,$MouseY+235, $hPen)
; _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX, $MouseY, $MouseX-470+117.5, $MouseY+117.5, $hPen)
; _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX, $MouseY, $MouseX+470-117.5, $MouseY+117.5, $hPen)
; _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX, $MouseY, $MouseX-117.5, $MouseY+352.5, $hPen)
; _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX, $MouseY, $MouseX+117.5, $MouseY+352.5, $hPen)
; _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX +235, $MouseY, $MouseX +352.5, $MouseY+117.5, $hPen)
; _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX -235, $MouseY, $MouseX -352.5, $MouseY+117.5, $hPen)
 
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_PenDispose($hPen)
    Return $hBitmap
EndFunc   ;==>DrawTriangle
 
Func rotator($Angle)
    ;Rotation Matrix
    _GDIPlus_MatrixTranslate($hMatrix, $iW, $iH)
    _GDIPlus_MatrixRotate($hMatrix, $Angle, False)
    _GDIPlus_MatrixTranslate($hMatrix, -$iW, -$iH)
    _GDIPlus_GraphicsSetTransform($hGfx_BmpRotate, $hMatrix)
    _GDIPlus_GraphicsDrawImageRect($hGfx_BmpRotate, $hBmp_Triangle, $iW / 2, $iH / 2, $iW, $iH)
    _GDIPlus_GraphicsDrawImageRect($hBackbuffer, $hBmp_Rotate, MouseGetPos(0) - $iW, MouseGetPos(1) - $iH, 2 * $iW, 2 * $iH)
    $GDIBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    _WinAPI_SelectObject($dc, $gdibitmap)
    _WinAPI_UpdateLayeredWindow($hGUI, $ScreenDc, 0, $pSize, $dc, $pSource, 0, $pBlend, 1)
    _WinAPI_DeleteObject($GDIBitmap)
EndFunc   ;==>rotator
 
Func Stop_Draw()
Sleep(30000)
EndFunc
 
Func Exit_Completely()
    _WinAPI_DeleteDC($dc)
    _WinAPI_ReleaseDC($hGUI, $ScreenDc)
    _WinAPI_DeleteObject($GDIBitmap)
    _GDIPlus_MatrixDispose($hMatrix)
    _GDIPlus_BitmapDispose($hBmp_Triangle)
    _GDIPlus_BitmapDispose($hBmp_Rotate)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($hGfx_BmpRotate)
; Clean up resources
_GDIPlus_FontDispose($hFont)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
DllClose($hDLL)
GUIDelete($hGUI)
    Exit
EndFunc   ;==>exit_script
 
Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iPixelFormat = $GDIP_PXF32ARGB, $iStride = 0, $pScan0 = 0)
    Local $aResult = DllCall($ghGDIPDll, "int", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "handle*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    If $aResult[0] Then Return SetError(10, $aResult[0], 0)
    Return $aResult[6]
EndFunc   ;==>_GDIPlus_BitmapCreateFromScan0

 

Hi guys, I have been playing my first time with scripts that draw something, before I always wrote scripts that  manage something like a service, or a workstation or whatever, never drawing lines, and I'm trying. But I'm a little stuck with 2 problems:
1) draw only one triangle and follow the mouse arround

2) arrow left and right rotate the triangle but it rotates in a wrong way, I would like to counter the downward rotation and have it rotate arround the center of the diagonal of the triangle.

If someone with a little more expertise on this topic can have a look at it and point me in the right direction?

that would be really appreciated :)

Kind regards,

Dimitri

 

below is the code I came up with (for reference purposes I leave it here too):

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=Triangle.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
Global $hGraphic, $EndPosMouse
$hGUI = GUICreate("GDI+", @DesktopWidth, @DesktopHeight, 0, 0,$WS_MAXIMIZE, BitOR($WS_EX_MDICHILD,$WS_EX_TRANSPARENT, $WS_EX_DLGMODALFRAME))
GUISetState()
HotKeySet("{LEFT}","Rotate_Left")
HotKeySet("{RIGHT}","Rotate_Right")
HotKeySet("{UP}","Freeze")
HotKeySet("{DOWN}","clear")
HotKeySet("{ESC}","exit_script")
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hPen = _GDIPlus_PenCreate()
 
$counter = 0
While 1
$mousepos = MouseGetPos()
DrawTriangle($mousepos[0], $mousepos[1])
Sleep(1000)
WEnd
_GDIPlus_PenDispose($hPen)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
GUIDelete($hGUI)
 
Func Rotate_Left()
$counter-=5
rotator($counter)
EndFunc
 
Func Rotate_Right()
$counter+=5
rotator($counter)
EndFunc
 
Func Freeze()
EndFunc
 
Func clear()
EndFunc
 
Func DrawTriangle($MouseX, $MouseY)
$mm = 5.875*8
For $i = $mm To 940 Step $mm
If $i < 470 Then
_GDIPlus_GraphicsDrawLine($hGraphic, $MouseX - 470 + $i, $MouseY, $MouseX - 470 + $i, $MouseY + $i, $hPen)
Else
_GDIPlus_GraphicsDrawLine($hGraphic, $MouseX + 470 + 470 - $i, $MouseY, $MouseX + 470 + 470 - $i, $MouseY - 470 + $i, $hPen)
EndIf
Next
For $x = 5.2 To 470 Step 5.2*8
_GDIPlus_GraphicsDrawLine($hGraphic, $MouseX - 470 + $x, $MouseY + $x, $MouseX + 470 - $x, $MouseY + $x, $hPen)
Next
_GDIPlus_GraphicsDrawLine($hGraphic, $MouseX - 470, $MouseY, $MouseX + 470, $MouseY, $hPen)
_GDIPlus_GraphicsDrawLine($hGraphic, $MouseX - 470, $MouseY, $MouseX, $MouseY + 470, $hPen)
_GDIPlus_GraphicsDrawLine($hGraphic, $MouseX, $MouseY + 470, $MouseX + 470, $MouseY, $hPen)
_GDIPlus_GraphicsDrawLine($hGraphic, $MouseX, $MouseY + 470, $MouseX, $MouseY, $hPen)
_GDIPlus_GraphicsDrawLine($hGraphic, $MouseX - 235, $MouseY, $MouseX + 117.5, $MouseY + 352.5, $hPen)
_GDIPlus_GraphicsDrawLine($hGraphic, $MouseX + 235, $MouseY, $MouseX - 117.5, $MouseY + 352.5, $hPen)
_GDIPlus_GraphicsDrawLine($hGraphic, $MouseX, $MouseY, $MouseX + 235, $MouseY + 235, $hPen)
_GDIPlus_GraphicsDrawLine($hGraphic, $MouseX, $MouseY, $MouseX - 235, $MouseY + 235, $hPen)
_GDIPlus_GraphicsDrawLine($hGraphic, $MouseX, $MouseY, $MouseX - 470 + 117.5, $MouseY + 117.5, $hPen)
_GDIPlus_GraphicsDrawLine($hGraphic, $MouseX, $MouseY, $MouseX + 470 - 117.5, $MouseY + 117.5, $hPen)
_GDIPlus_GraphicsDrawLine($hGraphic, $MouseX, $MouseY, $MouseX - 117.5, $MouseY + 352.5, $hPen)
_GDIPlus_GraphicsDrawLine($hGraphic, $MouseX, $MouseY, $MouseX + 117.5, $MouseY + 352.5, $hPen)
_GDIPlus_GraphicsDrawLine($hGraphic, $MouseX + 235, $MouseY, $MouseX + 352.5, $MouseY + 117.5, $hPen)
_GDIPlus_GraphicsDrawLine($hGraphic, $MouseX - 235, $MouseY, $MouseX - 352.5, $MouseY + 117.5, $hPen)
EndFunc
Func rotator($Angle)
    ;Rotation Matrix
    $hMatrix = _GDIPlus_MatrixCreate()
    _GDIPlus_MatrixRotate($hMatrix, $Angle, False)
    _GDIPlus_GraphicsSetTransform($hGraphic, $hMatrix)
    ; Clean up resources
    _GDIPlus_MatrixDispose($hMatrix)
; $Angle=0
EndFunc
Func exit_script()
Exit
EndFunc
 
Edited by lordofthestrings

Share this post


Link to post
Share on other sites



Why not ask in the Help Forum ?


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

because I already have in my opinion a big part working of the script, I just like to finalize it :) if a mod agrees, feel free to move this thread otherwise I have to recreate it myself..
Kind regards,


Share this post


Link to post
Share on other sites

lordofthestrings,

And lo, it has been moved! :sorcerer:

Next time, if there is one, please use the "Report" button to ask us to move things - that way it will not depend on my dropping into the thread by chance. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

ok great thanks Melba! :)


Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Here a really fast hack:

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=Triangle.exe
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
Global $EndPosMouse

_GDIPlus_Startup()

$hBmp_Triangle = DrawTriangle()
$iW = _GDIPlus_ImageGetWidth($hBmp_Triangle)
$iH = _GDIPlus_ImageGetHeight($hBmp_Triangle)

$hGUI = GUICreate("GDI+", @DesktopWidth, @DesktopHeight, 0, 0, Default, BitOR($WS_EX_LAYERED, $WS_EX_TOOLWINDOW));, $WS_MAXIMIZE, BitOR($WS_EX_MDICHILD, $WS_EX_TRANSPARENT, $WS_EX_DLGMODALFRAME))
GUISetState()
HotKeySet("{LEFT}", "Rotate_Left")
HotKeySet("{RIGHT}", "Rotate_Right")
HotKeySet("{UP}", "Freeze")
HotKeySet("{DOWN}", "clear")
HotKeySet("{ESC}", "exit_script")

Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics(@DesktopWidth, @DesktopHeight, $hGraphic)
Global $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
$hPen = _GDIPlus_PenCreate()

$ScreenDc = _WinAPI_GetDC($hGUI)
$GDIBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
$dc = _WinAPI_CreateCompatibleDC($ScreenDc)
_WinAPI_SelectObject($dc, $GDIBitmap)
; _WinAPI_UpdateLayeredWindow parameters
$tSize = DllStructCreate($tagSIZE)
$pSize = DllStructGetPtr($tSize)
DllStructSetData($tSize, "X", @DesktopWidth)
DllStructSetData($tSize, "Y", @DesktopHeight)
$tSource = DllStructCreate($tagPOINT)
$pSource = DllStructGetPtr($tSource)
$tBlend = DllStructCreate($tagBLENDFUNCTION)
$pBlend = DllStructGetPtr($tBlend)
DllStructSetData($tBlend, "Alpha", 0xFF)
DllStructSetData($tBlend, "Format", 1)
$tPoint = DllStructCreate($tagPOINT)
$pPoint = DllStructGetPtr($tPoint)
DllStructSetData($tPoint, "X", 0)
DllStructSetData($tPoint, "Y", 0)

$counter = 0

Global $hMatrix = _GDIPlus_MatrixCreate()

Global $hBmp_Rotate = _GDIPlus_BitmapCreateFromScan0(2 * $iW, 2 * $iH)
Global $hGfx_BmpRotate = _GDIPlus_ImageGetGraphicsContext($hBmp_Rotate)

While 1
    $mousepos = MouseGetPos()
    clear()
    rotator($counter)
    Sleep(50)
WEnd

Func Rotate_Left()
    $counter -= 0.5
    rotator($counter)
EndFunc   ;==>Rotate_Left

Func Rotate_Right()
    $counter += 0.5
    rotator($counter)
EndFunc   ;==>Rotate_Right

Func Freeze()
EndFunc   ;==>Freeze

Func clear()
    _GDIPlus_GraphicsClear($hBackbuffer, 0x00F0F0F0)
    _GDIPlus_GraphicsClear($hGfx_BmpRotate, 0x00F0F0F0)
EndFunc   ;==>clear

Func DrawTriangle($MouseX = 470, $MouseY = 0)
    Local $hBitmap = _GDIPlus_BitmapCreateFromScan0(2 * $MouseX, $MouseX)
    Local $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
    Local $hPen = _GDIPlus_PenCreate(0xFFFF0000)
    Local $mm = 5.875 * 8, $i, $x
    For $i = $mm To 940 Step $mm
        If $i < 470 Then
            _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX - 470 + $i, $MouseY, $MouseX - 470 + $i, $MouseY + $i, $hPen)
        Else
            _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX + 470 + 470 - $i, $MouseY, $MouseX + 470 + 470 - $i, $MouseY - 470 + $i, $hPen)
        EndIf
    Next
    For $x = 5.2 To 470 Step 5.2 * 8
        _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX - 470 + $x, $MouseY + $x, $MouseX + 470 - $x, $MouseY + $x, $hPen)
    Next
    _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX - 470, $MouseY, $MouseX + 470, $MouseY, $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX - 470, $MouseY, $MouseX, $MouseY + 470, $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX, $MouseY + 470, $MouseX + 470, $MouseY, $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX, $MouseY + 470, $MouseX, $MouseY, $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX - 235, $MouseY, $MouseX + 117.5, $MouseY + 352.5, $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX + 235, $MouseY, $MouseX - 117.5, $MouseY + 352.5, $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX, $MouseY, $MouseX + 235, $MouseY + 235, $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX, $MouseY, $MouseX - 235, $MouseY + 235, $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX, $MouseY, $MouseX - 470 + 117.5, $MouseY + 117.5, $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX, $MouseY, $MouseX + 470 - 117.5, $MouseY + 117.5, $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX, $MouseY, $MouseX - 117.5, $MouseY + 352.5, $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX, $MouseY, $MouseX + 117.5, $MouseY + 352.5, $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX + 235, $MouseY, $MouseX + 352.5, $MouseY + 117.5, $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX - 235, $MouseY, $MouseX - 352.5, $MouseY + 117.5, $hPen)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_PenDispose($hPen)
    Return $hBitmap
EndFunc   ;==>DrawTriangle

Func rotator($Angle)
    ;Rotation Matrix
    _GDIPlus_MatrixTranslate($hMatrix, $iW, $iH)
    _GDIPlus_MatrixRotate($hMatrix, $Angle, False)
    _GDIPlus_MatrixTranslate($hMatrix, -$iW, -$iH)
    _GDIPlus_GraphicsSetTransform($hGfx_BmpRotate, $hMatrix)
    _GDIPlus_GraphicsDrawImageRect($hGfx_BmpRotate, $hBmp_Triangle, $iW / 2, $iH / 2, $iW, $iH)
    _GDIPlus_GraphicsDrawImageRect($hBackbuffer, $hBmp_Rotate, MouseGetPos(0) - $iW, MouseGetPos(1) - $iH, 2 * $iW, 2 * $iH)
    $GDIBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    _WinAPI_SelectObject($dc, $gdibitmap)
    _WinAPI_UpdateLayeredWindow($hGUI, $ScreenDc, 0, $pSize, $dc, $pSource, 0, $pBlend, 1)
    _WinAPI_DeleteObject($GDIBitmap)
EndFunc   ;==>rotator

Func exit_script()
    _WinAPI_DeleteDC($dc)
    _WinAPI_ReleaseDC($hGUI, $ScreenDc)
    _WinAPI_DeleteObject($GDIBitmap)
    _GDIPlus_MatrixDispose($hMatrix)
    _GDIPlus_BitmapDispose($hBmp_Triangle)
    _GDIPlus_BitmapDispose($hBmp_Rotate)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($hGfx_BmpRotate)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
    Exit
EndFunc   ;==>exit_script


Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iPixelFormat = $GDIP_PXF32ARGB, $iStride = 0, $pScan0 = 0)
    Local $aResult = DllCall($ghGDIPDll, "int", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "handle*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    If $aResult[0] Then Return SetError(10, $aResult[0], 0)
    Return $aResult[6]
EndFunc   ;==>_GDIPlus_BitmapCreateFromScan0

Func _GDIPlus_GraphicsSetInterpolationMode($hGraphics, $iInterpolationMode)
    Local $aResult = DllCall($ghGDIPDll, "int", "GdipSetInterpolationMode", "handle", $hGraphics, "int", $iInterpolationMode)
    If @error Then Return SetError(@error, @extended, 0)
    If $aResult[0] Then Return SetError(10, $aResult[0], 0)
    Return True
EndFunc   ;==>_GDIPlus_GraphicsSetInterpolationMode

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

Share this post


Link to post
Share on other sites

Howly shit that's exactly what I wanted :D really beautifull work UEZ!  :thumbsup:


Share this post


Link to post
Share on other sites

Your are welcome.

I forgot to extent the transparent GUI to desktop width / height. See post#6 again.

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

Share this post


Link to post
Share on other sites

Hi, it's getting there, I now want to see a few other changes, but at the moment I'm beginning to feel a bit stupid cause I can 't get it to work.

1) add the numbers on the gui, like the centimeters, the angle digits.. stuff like that

2) when I freeze it, it should stay on the position that the mouse currently is, and "release the mouse back to you" but I don't even know where to begin,

I checked the _GDIPlus_Lockbits but what bits to lock? --> clueless.. if someone wants to have a go at it, it would be nice to finalize this.

 

Here's the code I have so far:

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=Triangle.exe
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
Global $EndPosMouse
HotKeySet("{LEFT}", "Rotate_Left")
HotKeySet("{RIGHT}", "Rotate_Right")
HotKeySet("{UP}", "Freeze")
HotKeySet("{DOWN}", "clear")
HotKeySet("{ESC}", "exit_script")


_GDIPlus_Startup()

$hBmp_Triangle = DrawTriangle()
Global $iW = _GDIPlus_ImageGetWidth($hBmp_Triangle)
Global $iH = _GDIPlus_ImageGetHeight($hBmp_Triangle)
;Default, BitOR($WS_EX_LAYERED, $WS_EX_TOOLWINDOW))
;$hGUI = GUICreate("GDI+", 2 * $iW, 2 * $iH, 0, 0, Default, BitOR($WS_EX_LAYERED, $WS_EX_TOOLWINDOW)) ;$WS_MAXIMIZE, BitOR($WS_EX_MDICHILD, $WS_EX_TRANSPARENT, $WS_EX_DLGMODALFRAME)) ; ;,
$hGUI = GUICreate("GDI+", @DesktopWidth, @DesktopHeight, 0, 0, Default, BitOR($WS_EX_LAYERED, $WS_EX_TOOLWINDOW));, $WS_MAXIMIZE, BitOR($WS_EX_MDICHILD, $WS_EX_TRANSPARENT, $WS_EX_DLGMODALFRAME))

GUISetState()
Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics( 2 * $iW, 2 * $iH, $hGraphic)
Global $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
Global $hBrush, $hFormat, $hFamily, $hFont, $tLayout
$hPen = _GDIPlus_PenCreate()
$ScreenDc = _WinAPI_GetDC($hGUI)
$GDIBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
$dc = _WinAPI_CreateCompatibleDC($ScreenDc)
_WinAPI_SelectObject($dc, $GDIBitmap)

;  _WinAPI_UpdateLayeredWindow parameters
$tSize = DllStructCreate($tagSIZE)
$pSize = DllStructGetPtr($tSize)
DllStructSetData($tSize, "X", 2 * $iW)
DllStructSetData($tSize, "Y", 2 * $iH)
$tSource = DllStructCreate($tagPOINT)
$pSource = DllStructGetPtr($tSource)
$tBlend = DllStructCreate($tagBLENDFUNCTION)
$pBlend = DllStructGetPtr($tBlend)
DllStructSetData($tBlend, "Alpha", 0xFF)
DllStructSetData($tBlend, "Format", 1)
$tPoint = DllStructCreate($tagPOINT)
$pPoint = DllStructGetPtr($tPoint)
DllStructSetData($tPoint, "X", 0)
DllStructSetData($tPoint, "Y", 0)

$counter = 0

Global $hMatrix = _GDIPlus_MatrixCreate()
Global $hBmp_Rotate = _GDIPlus_BitmapCreateFromScan0(2 * $iW, 2 * $iH)
Global $hGfx_BmpRotate = _GDIPlus_ImageGetGraphicsContext($hBmp_Rotate)

While 1
    $mousepos = MouseGetPos()
    clear()
    rotator($counter)
    Sleep(20)
WEnd






Func Rotate_Left()
    $counter -= 0.5
    rotator($counter)
EndFunc   ;==>Rotate_Left

Func Rotate_Right()
    $counter += 0.5
    rotator($counter)
EndFunc   ;==>Rotate_Right

Func Freeze()
$iRotation=0
    If Not $counter = 0 Then
        If $counter>0 Then
            For $iRotation = 0.5 To $counter Step 0.5
                Send("{LEFT}")
                rotator($counter)
            Next
        Else
            For $iRotation = $counter To -0.5 Step 0.5
                Send("{RIGHT}")
                rotator(-$counter)
            Next
        EndIf
    EndIf
    If $counter = 0 Then
;       _GDIPlus_BitmapLockBits
    EndIf
    Return $counter
EndFunc   ;==>Freeze

Func clear()
    _GDIPlus_GraphicsClear($hBackbuffer, 0x00F0F0F0)
    _GDIPlus_GraphicsClear($hGfx_BmpRotate, 0x00F0F0F0)
EndFunc   ;==>clear

Func DrawCounter($TextToDraw = "Hello World", $LeftTopX=0, $LeftTopY=0)
    $hBrush = _GDIPlus_BrushCreateSolid(0x7FFF007F)
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    $hFont = _GDIPlus_FontCreate($hFamily, 18, 2)
    $tLayout = _GDIPlus_RectFCreate($LeftTopX+800, $LeftTopY+50, 20, 40)
    _GDIPlus_GraphicsDrawStringEx($hGraphic, $TextToDraw, $hFont, $tLayout, $hFormat, $hBrush)

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

EndFunc

Func DrawTriangle($MouseX = 470, $MouseY = 0)
    Local $hBitmap = _GDIPlus_BitmapCreateFromScan0(2 * $MouseX, $MouseX)
    Local $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
    Local $hPen3 = _GDIPlus_PenCreate(0xFFFFFFFF)
    Local $hPen2 = _GDIPlus_PenCreate(0xFF0000F0)
    Local $hPen = _GDIPlus_PenCreate(0xEEAAAAAA)
    _GDIPlus_GraphicsDrawArc($hGraphic, $MouseX-470, $MouseY-100, 300, 300, +170, -160,$hPen3)
    _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX - 470, $MouseY, $MouseX, $MouseY + 470, $hPen)     ; triangle
    _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX - 470, $MouseY, $MouseX + 470, $MouseY, $hPen)     ; triangle
    _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX, $MouseY + 470, $MouseX + 470, $MouseY, $hPen)     ; triangle
    _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX, $MouseY+470, $MouseX, $MouseY, $hPen)             ;90° angle line
; add 90 Angle + Horizontal lines
$counter = 1
For $i = -470 To 470 Step 5
    If $counter >= 1 And $counter <=6 Then
        _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX-$i, $MouseY, $MouseX-$i, $MouseY+5, $hPen2)
        $counter += 1
    EndIf
    If $counter = 6 Then
        _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX-$i, $MouseY, $MouseX-$i, $MouseY+15, $hPen2)
;           $hGraphic2 = _GDIPlus_GraphicsCreateFromHWND($hGUI)
;           DrawCounter(5, $MouseX-940-$i+60, $MouseY-$i+120)
        $counter = 1
    EndIf
Next
$counter = 1
For $a = 5.2 To 470 Step 5.2
    If $counter >= 1 And $counter <=6 Then
        _GDIPlus_GraphicsDrawLine($hGraphic, $a,$a-1,$a+5,$a-7, $hPen2)
        _GDIPlus_GraphicsDrawLine($hGraphic, $a+470,470-$a,470+$a-5,470-$a-7, $hPen2)
    $counter += 1
    EndIf
    If $counter = 6 Then
        _GDIPlus_GraphicsDrawLine($hGraphic, $a,$a-1,$a+12,$a-15, $hPen2)
        _GDIPlus_GraphicsDrawLine($hGraphic, $a+470,470-$a,470+$a-12,470-$a-15, $hPen2)
        If $MouseY + $a <400 then _GDIPlus_GraphicsDrawLine($hGraphic, ($MouseX - 400 + $a), $MouseY + $a, ($MouseX + 400 - $a), $MouseY + $a, $hPen)
        $counter = 1
    EndIf
Next
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_PenDispose($hPen)
    Return $hBitmap
EndFunc   ;==>DrawTriangle

Func rotator($Angle)
    ;Rotation Matrix
    _GDIPlus_MatrixTranslate($hMatrix, $iW, $iH)
    _GDIPlus_MatrixRotate($hMatrix, $Angle, False)
    _GDIPlus_MatrixTranslate($hMatrix, -$iW, -$iH)
    _GDIPlus_GraphicsSetTransform($hGfx_BmpRotate, $hMatrix)
    _GDIPlus_GraphicsDrawImageRect($hGfx_BmpRotate, $hBmp_Triangle, $iW / 2, $iH / 2, $iW, $iH)
    _GDIPlus_GraphicsDrawImageRect($hBackbuffer, $hBmp_Rotate, MouseGetPos(0) - $iW, MouseGetPos(1) - $iH +$iH/3, 2 * $iW, 2 * $iH)
    $GDIBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    _WinAPI_SelectObject($dc, $gdibitmap)
    _WinAPI_UpdateLayeredWindow($hGUI, $ScreenDc, 0, $pSize, $dc, $pSource, 0, $pBlend, 1)
    _WinAPI_DeleteObject($GDIBitmap)
EndFunc   ;==>rotator

Func exit_script()
    _WinAPI_DeleteDC($dc)
    _WinAPI_ReleaseDC($hGUI, $ScreenDc)
    _WinAPI_DeleteObject($GDIBitmap)
    _GDIPlus_MatrixDispose($hMatrix)
    _GDIPlus_BitmapDispose($hBmp_Triangle)
    _GDIPlus_BitmapDispose($hBmp_Rotate)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($hGfx_BmpRotate)
    ; Clean up resources
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()

    GUIDelete($hGUI)
    Exit
EndFunc   ;==>exit_script

Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iPixelFormat = $GDIP_PXF32ARGB, $iStride = 0, $pScan0 = 0)
    Local $aResult = DllCall($ghGDIPDll, "int", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "handle*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    If $aResult[0] Then Return SetError(10, $aResult[0], 0)
    Return $aResult[6]
EndFunc   ;==>_GDIPlus_BitmapCreateFromScan0

Share this post


Link to post
Share on other sites

solved: freeze

todo: numbers in the GUI

update : See post #1


Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

You have to update on each rotation the triangle!

Something like this here:

 

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=Triangle.exe
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <misc.au3>
Global $EndPosMouse
HotKeySet("{LEFT}", "Rotate_Left")
HotKeySet("{RIGHT}", "Rotate_Right")
HotKeySet("{UP}", "Freeze")
HotKeySet("{DOWN}", "clear")
HotKeySet("{ESC}", "Exit_Completely")

_GDIPlus_Startup()

$hBmp_Triangle = DrawTriangle()
Global $iW = _GDIPlus_ImageGetWidth($hBmp_Triangle)
Global $iH = _GDIPlus_ImageGetHeight($hBmp_Triangle)
;Default, BitOR($WS_EX_LAYERED, $WS_EX_TOOLWINDOW))
;$hGUI = GUICreate("GDI+", 2 * $iW, 2 * $iH, 0, 0, Default, BitOR($WS_EX_LAYERED, $WS_EX_TOOLWINDOW)) ;$WS_MAXIMIZE, BitOR($WS_EX_MDICHILD, $WS_EX_TRANSPARENT, $WS_EX_DLGMODALFRAME)) ; ;,
$hGUI = GUICreate("GDI+", @DesktopWidth, @DesktopHeight, 0, 0, Default, BitOR($WS_EX_LAYERED, $WS_EX_TOOLWINDOW));, $WS_MAXIMIZE, BitOR($WS_EX_MDICHILD, $WS_EX_TRANSPARENT, $WS_EX_DLGMODALFRAME))

GUISetState()
Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics(@DesktopWidth, @DesktopHeight, $hGraphic)
Global $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
Global $hBrush, $hFormat, $hFamily, $hFont, $tLayout
$hPen = _GDIPlus_PenCreate()
$ScreenDc = _WinAPI_GetDC($hGUI)
$GDIBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
$dc = _WinAPI_CreateCompatibleDC($ScreenDc)
_WinAPI_SelectObject($dc, $GDIBitmap)

;  _WinAPI_UpdateLayeredWindow parameters
$tSize = DllStructCreate($tagSIZE)
$pSize = DllStructGetPtr($tSize)
DllStructSetData($tSize, "X", @DesktopWidth)
DllStructSetData($tSize, "Y", @DesktopHeight)
$tSource = DllStructCreate($tagPOINT)
$pSource = DllStructGetPtr($tSource)
$tBlend = DllStructCreate($tagBLENDFUNCTION)
$pBlend = DllStructGetPtr($tBlend)
DllStructSetData($tBlend, "Alpha", 0xFF)
DllStructSetData($tBlend, "Format", 1)
$tPoint = DllStructCreate($tagPOINT)
$pPoint = DllStructGetPtr($tPoint)
DllStructSetData($tPoint, "X", 0)
DllStructSetData($tPoint, "Y", 0)

$counter = 0

Local $hDLL = DllOpen("user32.dll")
Global $hMatrix = _GDIPlus_MatrixCreate()
Global $hBmp_Rotate = _GDIPlus_BitmapCreateFromScan0(2 * $iW, 2 * $iH)
Global $hGfx_BmpRotate = _GDIPlus_ImageGetGraphicsContext($hBmp_Rotate)

While 1
    $mousepos = MouseGetPos()
    clear()
    rotator($counter)
    If _IsPressed("51", $hDLL) Then
        Sleep(10000)
    EndIf
    Sleep(20)
WEnd


Func Rotate_Left()
    $counter -= 0.5
    rotator($counter)
EndFunc   ;==>Rotate_Left

Func Rotate_Right()
    $counter += 0.5
    rotator($counter)
EndFunc   ;==>Rotate_Right

Func Freeze()
    $iRotation = 0
    If Not $counter = 0 Then
        If $counter > 0 Then
            For $iRotation = 0.5 To $counter Step 0.5
                Send("{LEFT}")
                rotator($counter)
            Next
        Else
            For $iRotation = $counter To -0.5 Step 0.5
                Send("{RIGHT}")
                rotator(-$counter)
            Next
        EndIf
    EndIf
    If $counter = 0 Then
        ; _GDIPlus_BitmapLockBits
    EndIf
    Return $counter
EndFunc   ;==>Freeze

Func clear()
    _GDIPlus_GraphicsClear($hBackbuffer, 0x00F0F0F0)
    _GDIPlus_GraphicsClear($hGfx_BmpRotate, 0x00F0F0F0)
EndFunc   ;==>clear

Func DrawCounter($hGraphic, $TextToDraw = "Hello World", $LeftTopX = 470, $LeftTopY = 235)
    Local $hBrush = _GDIPlus_BrushCreateSolid(0x7FFF007F)
    Local $hFormat = _GDIPlus_StringFormatCreate()
    Local $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    Local $hFont = _GDIPlus_FontCreate($hFamily, 18, 2)
    Local $tLayout = _GDIPlus_RectFCreate($LeftTopX, $LeftTopY, 0, 0)
    _GDIPlus_StringFormatSetAlign($hFormat, 1)
    _GDIPlus_GraphicsDrawStringEx($hGraphic, $TextToDraw, $hFont, $tLayout, $hFormat, $hBrush)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
EndFunc   ;==>DrawCounter

Func DrawTriangle($MouseX = 470, $MouseY = 0)
    Local $hBitmap = _GDIPlus_BitmapCreateFromScan0(2 * $MouseX, $MouseX)
    Local $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
    Local $hPen3 = _GDIPlus_PenCreate(0xFFFFFFFF)
    Local $hPen2 = _GDIPlus_PenCreate(0xFF0000F0)
    Local $hPen = _GDIPlus_PenCreate(0xEEAAAAAA)
    _GDIPlus_GraphicsDrawArc($hGraphic, $MouseX - 150, $MouseY - 100, 300, 300, +170, -160, $hPen3) ; arc or Arch
    _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX - 470, $MouseY, $MouseX, $MouseY + 470, $hPen) ; triangle
    _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX - 470, $MouseY, $MouseX + 470, $MouseY, $hPen) ; triangle
    _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX, $MouseY + 470, $MouseX + 470, $MouseY, $hPen) ; triangle
    _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX, $MouseY + 470, $MouseX, $MouseY, $hPen) ;90° angle line
    ; add millimeter + Centimeter lines
    Local $counter = 1
    For $i = -470 To 470 Step 5
        If $counter >= 1 And $counter <= 6 Then
            _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX - $i, $MouseY, $MouseX - $i, $MouseY + 5, $hPen2)
            $counter += 1
        EndIf
        If $counter = 6 Then
            _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX - $i, $MouseY, $MouseX - $i, $MouseY + 15, $hPen2)
            $counter = 1
        EndIf
    Next
    ; add 180 Angle (those on the diagonal sides) + Horizontal lines
    $counter = 1
    For $a = 5.2 To 470 Step 5.2
        If $counter >= 1 And $counter <= 6 Then
            _GDIPlus_GraphicsDrawLine($hGraphic, $a, $a - 1, $a + 5, $a - 7, $hPen2) ; Left half side millimeter lines
            _GDIPlus_GraphicsDrawLine($hGraphic, $a + 470, 470 - $a, 470 + $a - 5, 470 - $a - 7, $hPen2) ; Right "" "" ""
            $counter += 1
        EndIf
        If $counter = 6 Then
            _GDIPlus_GraphicsDrawLine($hGraphic, $a, $a - 1, $a + 12, $a - 15, $hPen2) ; Left half side centimeter lines
            _GDIPlus_GraphicsDrawLine($hGraphic, $a + 470, 470 - $a, 470 + $a - 12, 470 - $a - 15, $hPen2) ; Right ""  "" "" ""
            If $MouseY + $a < 400 Then _GDIPlus_GraphicsDrawLine($hGraphic, _
                    ($MouseX - 400 + $a), $MouseY + $a, ($MouseX + 400 - $a), $MouseY + $a, $hPen) ; Horizontal lines
            $counter = 1
        EndIf
    Next
    ; _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX-235, $MouseY, $MouseX+117.5, $MouseY+352.5, $hPen)
    ; _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX+235, $MouseY, $MouseX-117.5, $MouseY+352.5, $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX, $MouseY, $MouseX + 235, $MouseY + 235, $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX, $MouseY, $MouseX - 235, $MouseY + 235, $hPen)
    ; _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX, $MouseY, $MouseX-470+117.5, $MouseY+117.5, $hPen)
    ; _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX, $MouseY, $MouseX+470-117.5, $MouseY+117.5, $hPen)
    ; _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX, $MouseY, $MouseX-117.5, $MouseY+352.5, $hPen)
    ; _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX, $MouseY, $MouseX+117.5, $MouseY+352.5, $hPen)
    ; _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX +235, $MouseY, $MouseX +352.5, $MouseY+117.5, $hPen)
    ; _GDIPlus_GraphicsDrawLine($hGraphic, $MouseX -235, $MouseY, $MouseX -352.5, $MouseY+117.5, $hPen)

    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_PenDispose($hPen)
    Return $hBitmap
EndFunc   ;==>DrawTriangle

Func rotator($Angle)
    Local $hBmp_Triangle = DrawTriangle()
    Local $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBmp_Triangle)
    DrawCounter($hCtxt, "Rotation Step: " & $counter & "°")

    ;Rotation Matrix
    _GDIPlus_MatrixTranslate($hMatrix, $iW, $iH)
    _GDIPlus_MatrixRotate($hMatrix, $Angle, False)
    _GDIPlus_MatrixTranslate($hMatrix, -$iW, -$iH)
    _GDIPlus_GraphicsSetTransform($hGfx_BmpRotate, $hMatrix)
    _GDIPlus_GraphicsDrawImageRect($hGfx_BmpRotate, $hBmp_Triangle, $iW / 2, $iH / 2, $iW, $iH)
    _GDIPlus_GraphicsDrawImageRect($hBackbuffer, $hBmp_Rotate, MouseGetPos(0) - $iW, MouseGetPos(1) - $iH, 2 * $iW, 2 * $iH)
    $GDIBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    _WinAPI_SelectObject($dc, $GDIBitmap)
    _WinAPI_UpdateLayeredWindow($hGUI, $ScreenDc, 0, $pSize, $dc, $pSource, 0, $pBlend, 1)
    _WinAPI_DeleteObject($GDIBitmap)

    _GDIPlus_GraphicsDispose($hCtxt)
    _GDIPlus_BitmapDispose($hBmp_Triangle)
EndFunc   ;==>rotator

Func Stop_Draw()
    Sleep(30000)
EndFunc   ;==>Stop_Draw

Func Exit_Completely()
    _WinAPI_DeleteDC($dc)
    _WinAPI_ReleaseDC($hGUI, $ScreenDc)
    _WinAPI_DeleteObject($GDIBitmap)
    _GDIPlus_MatrixDispose($hMatrix)
    _GDIPlus_BitmapDispose($hBmp_Triangle)
    _GDIPlus_BitmapDispose($hBmp_Rotate)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($hGfx_BmpRotate)
    ; Clean up resources
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    DllClose($hDLL)
    GUIDelete($hGUI)
    Exit
EndFunc   ;==>Exit_Completely

Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iPixelFormat = $GDIP_PXF32ARGB, $iStride = 0, $pScan0 = 0)
    Local $aResult = DllCall($ghGDIPDll, "int", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "handle*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    If $aResult[0] Then Return SetError(10, $aResult[0], 0)
    Return $aResult[6]
EndFunc   ;==>_GDIPlus_BitmapCreateFromScan0

Be careful when creating gfx handles -> don't forget to dispose it otherwise memory leaks will occur!

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

Share this post


Link to post
Share on other sites

damn you're a GDI superstar. It would have taken me forever to do learn this myself..  :cheer:  :dance:  :guitar:


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