Sign in to follow this  
Followers 0
monoscout999

GDI+ Roatating image Button

5 posts in this topic

#1 ·  Posted (edited)

I finish a script that demonstrates how to click a moving GDI+ image, still don´t understand it at 100% but i think that is a start, comments will be apreciated.

#include <GDIP.au3>
#include <winapi.au3>
#include <Misc.au3>
Opt("MouseCoordMode", 2)
 
_GDIPlus_Startup()
 
$hGui = GUICreate("GDI+ Evento by monoscout999", 300, 300)
$iPic = GUICtrlCreatePic("", 0, 0, 300, 300)
 
GUISetState()
 
Global $hDll = DllOpen("user32.dll")
global $RotAng = 1
Global $status
Global $aColors[4] = [3, 0xFFFF0000, 0xFF550000, 0xFF220000]
Global $aPoints[4][2] = [[3],[63, 200],[237, 200],[150, 50]]
Global $aPathPoints[4][2] = [[3],[-87, 50],[87, 50],[0, -100]] ; All elements - 150
 
$hGraphics = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($iPic))
_GDIPlus_GraphicsClear($hGraphics, 0xFF123456)
_GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2)
 
$hBrush = _GDIPlus_PathBrushCreate($aPoints)
_GDIPlus_PathBrushSetCenterColor($hBrush, 0xFF222200)
_GDIPlus_PathBrushSetSurroundColorsWithCount($hBrush, $aColors)
 
$hGBitmap = _GDIPlus_BitmapCreateFromGraphics(300, 300, $hGraphics)
$hGBackbuffer = _GDIPlus_ImageGetGraphicsContext($hGBitmap)
 
$hPath = _GDIPlus_PathCreate()
 
$hMatrix = _GDIPlus_MatrixCreate()
_GDIPlus_MatrixTranslate($hMatrix, 150, 150)
 
AdlibRegister("Rotate", 20)
 
While True
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case -3
            Exit
 
    EndSwitch
    $status = _GDIPlus_PathIsVisiblePoint($hPath, MouseGetPos(0), MouseGetPos(1), $hGraphics)
    If $status = True Then
        GUISetCursor(14, 1, $hGui)
        $MousePos = MouseGetPos(0)
        While _IsPressed(0x01,$hDll)
        $RotAng = (MouseGetPos(0) - $MousePos) / 50
        Opt("MouseCoordMode", 1)
        ToolTip($RotAng, MouseGetPos(0)+20, MouseGetPos(1)+20,"Rotation Speed")
        Opt("MouseCoordMode", 2)
        WEnd
        ToolTip("")
    Else
        GUISetCursor(-1, 1, $hGui)
    EndIf
WEnd
 
 
AdlibUnRegister("Rotate")
_GDIPlus_MatrixDispose($hMatrix)
_GDIPlus_PathDispose($hPath)
_GDIPlus_GraphicsDispose($hGBackbuffer)
_GDIPlus_BitmapDispose($hGBitmap)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()
DllClose($hDll)
 
Func Rotate()
    _GDIPlus_GraphicsClear($hGBackbuffer, 0xFF123456)
    _GDIPlus_MatrixRotate($hMatrix, $RotAng)
    _GDIPlus_GraphicsSetTransform($hGraphics, $hMatrix)
    $aPathPoints2 = _GDIPlus_MatrixTransformPoints($hMatrix, $aPathPoints)
    _GDIPlus_PathReset($hPath)
    _GDIPlus_PathAddPolygon($hPath, $aPathPoints2)
    _GDIPlus_GraphicsFillPolygon($hGBackbuffer, $aPoints, $hBrush)
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hGBitmap, -150, -150, 300, 300)
EndFunc   ;==>Rotate

EDIT You can adjust the rotation speed by draging over the shape.

Edited by monoscout999

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I was trying to play with some color algorythm to calculate how to change the color while the object is rotating and simulate a white light from the top of the GUI.. i have failed, but this random effect come up :mellow:

#include <GDIP.au3>
#include <winapi.au3>
#include <Misc.au3>
#include <array.au3>

Opt("MouseCoordMode", 2)

_GDIPlus_Startup()

$hGui = GUICreate("GDI+ Evento by monoscout999", 300, 300)

GUISetState()

Global $hDll = DllOpen("user32.dll")
Global $RotAng = 1
Global $status
Global $aColors[4] = [3, 0xFF550000, 0xFF550000, 0xFFAA0000]
Global $aPoints[4][2] = [[3],[63, 200],[237, 200],[150, 50]]
Global $aPathPoints[4][2] = [[3],[-87, 50],[87, 50],[0, -100]] ; All elements - 150

$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
_GDIPlus_GraphicsClear($hGraphics, 0xFF123456)
_GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2)

$hBrush = _GDIPlus_PathBrushCreate($aPoints)
_GDIPlus_PathBrushSetCenterColor($hBrush, 0xFFFFFFFF)
_GDIPlus_PathBrushSetSurroundColorsWithCount($hBrush, $aColors)

$hGBitmap = _GDIPlus_BitmapCreateFromGraphics(300, 300, $hGraphics)
$hGBackbuffer = _GDIPlus_ImageGetGraphicsContext($hGBitmap)

$hPath = _GDIPlus_PathCreate()

$hMatrix = _GDIPlus_MatrixCreate()
_GDIPlus_MatrixTranslate($hMatrix, 150, 150)

AdlibRegister("Rotate", 20)

While True
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case -3
            Exit

    EndSwitch
    $status = _GDIPlus_PathIsVisiblePoint($hPath, MouseGetPos(0), MouseGetPos(1), $hGraphics)
    If $status = True Then
        GUISetCursor(14, 1, $hGui)
        $MousePos = MouseGetPos(0)
        While _IsPressed(0x01, $hDll)
            $RotAng = Int((MouseGetPos(0) - $MousePos) / 50)
            Opt("MouseCoordMode", 1)
            ToolTip($RotAng, MouseGetPos(0) + 20, MouseGetPos(1) + 20, "Rotation Speed")
            Opt("MouseCoordMode", 2)
        WEnd
        ToolTip("")
    Else
        GUISetCursor(-1, 1, $hGui)
    EndIf
WEnd


AdlibUnRegister("Rotate")
_GDIPlus_MatrixDispose($hMatrix)
_GDIPlus_PathDispose($hPath)
_GDIPlus_GraphicsDispose($hGBackbuffer)
_GDIPlus_BitmapDispose($hGBitmap)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()
DllClose($hDll)

Func Rotate()
    _GDIPlus_GraphicsClear($hGBackbuffer, 0xFF123456)
    _GDIPlus_MatrixRotate($hMatrix, $RotAng)
    _GDIPlus_GraphicsSetTransform($hGraphics, $hMatrix)
    $aPathPoints2 = _GDIPlus_MatrixTransformPoints($hMatrix, $aPathPoints)
    $aNewColors = _ChangeArrayColors($aColors, $aPathPoints2)
    _GDIPlus_PathBrushSetSurroundColorsWithCount($hBrush, $aNewColors)
    _GDIPlus_PathReset($hPath)
    _GDIPlus_PathAddPolygon($hPath, $aPathPoints2)
    _GDIPlus_GraphicsFillPolygon($hGBackbuffer, $aPoints, $hBrush)
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hGBitmap, -150, -150, 300, 300)
EndFunc   ;==>Rotate

Func _ChangeArrayColors($Colors, $Points)
    Local $y
    Local $dif
    Local $ColorDif
    Local $NewColor
    For $i = 1 To $Points[0][0]
        $y = $Points[$i][1]
        $dif = $y - 150
        $ColorDif = $dif * 255 / 100 ; Carppy too
        $NewColor = ($ColorDif) * -1
        If $NewColor > 255 Then
            $NewColor = 255 ; A Crapy correction
        EndIf
        If $NewColor < 0 Then
            $NewColor = 0
        EndIf
        $Colors[$i] = "0xFF"&Hex($NewColor, 2)&"5555"
    Next
    Return $Colors
EndFunc   ;==>_ChangeArrayColors
Edited by monoscout999

Share this post


Link to post
Share on other sites

I have some errors with autoit 3.3.3.1 (GDIP.au3 not found !)

Do you have a solution please ?

Share this post


Link to post
Share on other sites

Download from the link in my signature... is an extension of the GDIPlus library.

Share this post


Link to post
Share on other sites

I am glad to see that others are playing with GDI+, too. :mellow:

Nice work!

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

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