Jump to content

Recommended Posts

Posted (edited)

I made a test script that gets the mouse's position and draws a little dot in it's place. Snippet:

While 1
   $aPos = MouseGetPos()
   _GDIPlus_GraphicsDrawLine($hGraphic, $aPos[0], $aPos[1], $aPos[0] + 2.5, $aPos[1] + 2.5, $hPen)
WEnd

There is no Sleep function called in the while loop, so it should execute as frequent as possible.

I am afraid AutoIt isn't the right tool to make what you are trying to do. Here is the result:

afbeelding.png.9ccfb4530ac01ce7aeb4be6e0a5e6e10.png

Edited by Leendert-Jan
Posted

The tail should disappear ) This is not a drawing. In theory, for example, you need to draw 10 elements as a line from the coordinates of the mouse and then change their transparency.

Posted (edited)

My point was that it is not going to work with AutoIt. There might be a way to make the line more transparent over time, creating the effect that you want, but if drawing a line in the first place does not work, why bother trying to make the line transparent?

First we need a working script that follows the mouse and draws a SOLID line, after that we can start worrying about making the effects possible. But as shown in my post, simply drawing  a line isn't possible in the first place.

Edited by Leendert-Jan
Spelling
Posted (edited)
#include <WinAPISys.au3>
#include <WinAPIsysinfoConstants.au3>

_WinAPI_SystemParametersInfo($SPI_SETMOUSETRAILS, 15, 0, NULL)

Change the "15" to 1 or 0 to turn it off

Though this is globally, but i'm sure UEZ could come up with a solution in gdiplus.

Edited by Werty

Some guy's script + some other guy's script = my script!

Posted (edited)

Maybe this :

#include <GDIPlus.au3>
#include <GUIConstants.au3>

Global Const $SIZE = 600

Example()

Func Example()
  Local $hGUI = GUICreate("", $SIZE, $SIZE, 0, 0, $WS_POPUP, $WS_EX_TOPMOST)

  _GDIPlus_Startup()
  Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
  Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($SIZE, $SIZE, $hGraphic)
  Global $hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
  _GDIPlus_GraphicsSetSmoothingMode($hGfxCtxt, 2)

  GUISetState(@SW_SHOW)

  Local $Xprev = MouseGetPos(0), $Yprev = MouseGetPos(1), $X, $Y, $iPointer = 0
  Global $aDraw[400][3] = [[$Xprev, $Yprev, 0xFF]]

  AdlibRegister(_Fade, 70)

  While True
    If GUIGetMsg() = $GUI_EVENT_CLOSE Then ExitLoop
    $X = MouseGetPos(0)
    $Y = MouseGetPos(1)
    If $X = $Xprev And $Yprev = $Y Then ContinueLoop

    $iPointer += 1
    If $iPointer = UBound($aDraw) Then $iPointer = 0

    $aDraw[$iPointer][0] = $X
    $aDraw[$iPointer][1] = $Y
    $aDraw[$iPointer][2] = 0xFF
    $Xprev = $X
    $Yprev = $Y
  WEnd

  _GDIPlus_GraphicsDispose($hGfxCtxt)
  _GDIPlus_BitmapDispose($hBitmap)
  _GDIPlus_GraphicsDispose($hGraphic)
  _GDIPlus_Shutdown()
EndFunc   ;==>Example

Func _Fade()
  Local $hPen
  _GDIPlus_GraphicsClear($hGfxCtxt, 0xFFFFFFFF)

  For $i = 0 to UBound($aDraw) - 1
    If $aDraw[$i][2] And $aDraw[Mod($i+1,UBound($aDraw))][2] Then
      $aDraw[$i][2] -= 51
      $hPen = _GDIPlus_PenCreate(Dec(Hex($aDraw[$i][2], 2) & "FF0000", $NUMBER_32BIT), 2)
      _GDIPlus_GraphicsDrawLine($hGfxCtxt, $aDraw[$i][0], $aDraw[$i][1], $aDraw[Mod($i+1,UBound($aDraw))][0], $aDraw[Mod($i+1,UBound($aDraw))][1], $hPen)
      _GDIPlus_PenDispose($hPen)
    EndIf
  Next
  _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $SIZE, $SIZE)
EndFunc

 

Edited by Nine
Posted

Nice script @nine :)
... allow me just little modification on your listing:

#include <GDIPlus.au3>
#include <GUIConstants.au3>
#include <WINAPI.au3>

Global Const $SIZEx = @DesktopWidth, $SIZEy = @DesktopHeight, $AlphaKey = 0xFFFFFFFF
Global $hGraphic, $hBitmap, $hGfxCtxt, $aDraw[400][3]
Example()

Func Example()
    ; Local $hGUI = GUICreate("", $SIZE, $SIZE, 0, 0, $WS_POPUP, $WS_EX_TOPMOST)
    Local $hBackground = GUICreate("", $SIZEx, $SIZEy, 0, 0, $WS_POPUPWINDOW, $WS_EX_LAYERED + $WS_EX_TOPMOST)
    GUISetBkColor($AlphaKey, $hBackground)
    _WinAPI_SetLayeredWindowAttributes($hBackground, $AlphaKey, 0, $LWA_COLORKEY)
    GUISetState(@SW_SHOW, $hBackground)

    _GDIPlus_Startup()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hBackground)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($SIZEx, $SIZEy, $hGraphic)
    $hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)

    _GDIPlus_GraphicsSetSmoothingMode($hGfxCtxt, 2)

    Local $Xprev = MouseGetPos(0), $Yprev = MouseGetPos(1), $X, $Y, $iPointer = 0
    ; $aDraw[400][3] = [[$Xprev, $Yprev, 0xFF]]
    $aDraw[0][0] = $Xprev
    $aDraw[0][1] = $Yprev
    $aDraw[0][2] = 0xFF

    AdlibRegister(_Fade, 70)

    While True
        If GUIGetMsg() = $GUI_EVENT_CLOSE Then ExitLoop
        $X = MouseGetPos(0)
        $Y = MouseGetPos(1)
        If $X = $Xprev And $Yprev = $Y Then ContinueLoop

        $iPointer += 1
        If $iPointer = UBound($aDraw) Then $iPointer = 0

        $aDraw[$iPointer][0] = $X
        $aDraw[$iPointer][1] = $Y
        $aDraw[$iPointer][2] = 0xFF
        $Xprev = $X
        $Yprev = $Y
    WEnd

    _GDIPlus_GraphicsDispose($hGfxCtxt)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
EndFunc   ;==>Example

Func _Fade()
    Local $hPen
    _GDIPlus_GraphicsClear($hGfxCtxt, 0xFFFFFFFF)

    For $i = 1 To UBound($aDraw) - 1
        If $aDraw[$i][2] And $aDraw[Mod($i + 1, UBound($aDraw))][2] Then
            $aDraw[$i][2] -= 51
            $hPen = _GDIPlus_PenCreate(Dec(Hex($aDraw[$i][2], 2) & "FF0000", $NUMBER_32BIT), 2)
            _GDIPlus_GraphicsDrawLine($hGfxCtxt, $aDraw[$i][0], $aDraw[$i][1], $aDraw[Mod($i + 1, UBound($aDraw))][0], $aDraw[Mod($i + 1, UBound($aDraw))][1], $hPen)
            _GDIPlus_PenDispose($hPen)
        EndIf
    Next
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $SIZEx, $SIZEy)
EndFunc   ;==>_Fade

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Posted

@Chimp Thanks for your suggestions.

I just found a small bug (it would sometimes shortly draw a line from nowhere).  So I needed to change the _Fade function to this :

Func _Fade()
  Local Static $iFirst
  Local $hPen, $n
  _GDIPlus_GraphicsClear($hGfxCtxt, 0xFFFFFFFF)

  For $i = 0 to UBound($aDraw) - 1
    If $aDraw[$iFirst][2] Then ExitLoop
    $iFirst = Mod($iFirst + 1, UBound($aDraw))
  Next

  $n = $iFirst
  For $i = 0 To UBound($aDraw) - 1
    If Not $aDraw[Mod($n+1,UBound($aDraw))][2] Then ExitLoop
    $aDraw[$n][2] -= 51
    $hPen = _GDIPlus_PenCreate(Dec(Hex($aDraw[$n][2], 2) & "FF0000", $NUMBER_32BIT), 2)
    _GDIPlus_GraphicsDrawLine($hGfxCtxt, $aDraw[$n][0], $aDraw[$n][1], $aDraw[Mod($n+1,UBound($aDraw))][0], $aDraw[Mod($n+1,UBound($aDraw))][1], $hPen)
    _GDIPlus_PenDispose($hPen)
    $n = Mod($n+1, UBound($aDraw))
  Next
  _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $SIZE, $SIZE)
EndFunc

 

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
  • Recently Browsing   0 members

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