Jump to content

_GDIPlus_GraphicsDrawLine Cant Clear Old Line?


burners
 Share

Recommended Posts

I have created a script from scratch and worked off of the AutoIT clock script which is the one I am working from now and what I am looking to do is create a Gauge that updates with a serial input (Which I am working on in another script). For now though I am having an issue with the GUI side of things.

So in my sample I have a modified clock script which reads a txt file located at

C:\test.txt

The value can be between 0-360 in the text file, you have to change the value at least once to get the first needle to show up. However after that each change will draw an additional needle and I can not figure out how to delete the old. At first I thought it was something I was missing in my original script but now it seems even with the clock script I have the same issue.

I still have the original clock script and I cant find anything thats different other then the things that need to be.

#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

; ===============================================================================================================================
; Global variables
; ===============================================================================================================================

$WidthHeight = 400 ; Width & Height of Window
$iCenter           = $WidthHeight /2 ;Center of Window
$iDotOpacity       = 250
$iOpacity          = 128
$nPI               = 3.1415926535897932384626433832795
$iRadius           = $WidthHeight /2 ;Center of Radius
$iHourRad          = $WidthHeight /2 ;Center of Radius
$iMinRad           = 100
$iTickLen          = 0.02
$AC_SRC_ALPHA      = 1

$deg = ACos(-1) / 180
$radiusM = 200
$radiusP = 360
$R2M = $radiusM * 0.50
$R2P = $radiusP * 0.50


Global Enum $eScrDC=0, $eMemDC, $eBitmap, $eWidth, $eHeight, $eGraphic, $ePen, $eCap, $eBrush, $eFormat, $eFamily, $eFont, $eLayout, $eLast
Global $hDial, $hDigiGauge, $hNeedle, $hPeak, $hSec, $hDot, $aGauge, $aHour, $aMin, $aSec, $aCurr[3][2], $aLast[3][2]

;################################################################################################################################
;000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
;################################################################################################################################

; ===============================================================================================================================
; Main
; ===============================================================================================================================

fakeinput()

Global $XXM = $iCenter + Cos($input1 * $deg) * $R2M
Global $YYM = $iCenter + Sin($input1 * $deg) * $R2M

Global $XXP = $iCenter + Cos($input1 * $deg) * $R2P
Global $YYP = $iCenter + Sin($input1 * $deg) * $R2P

GaugeInit()
DialDraw ()
Draw     ()
DotDraw  ()
GaugeLoop()
GaugeDone()

;################################################################################################################################
;111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
;################################################################################################################################

; ===============================================================================================================================
; Loop until user exits
; ===============================================================================================================================
Func GaugeLoop()
  do
    Draw()
  until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc

;################################################################################################################################
;222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
;################################################################################################################################

; ===============================================================================================================================
; Initialize Gauge
; ===============================================================================================================================
Func GaugeInit()
  Local $iX, $iY

  ; Calculate the dial frame caption size
  $iX = -(_WinAPI_GetSystemMetrics($SM_CXFRAME))
  $iY = -(_WinAPI_GetSystemMetrics($SM_CYCAPTION) + _WinAPI_GetSystemMetrics($SM_CYFRAME))

  ; Allocate the window resources
  $hDial = GUICreate("Gauge", $WidthHeight, $WidthHeight,  -1,  -1, 0, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
  GUISetState()
  $hDigiGauge = GUICreate("DigiGauge" , $WidthHeight, $WidthHeight, $iX, 240, 0, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hDial)
  GUISetState()
  $hNeedle = GUICreate("Needle" , $WidthHeight, $WidthHeight, $iX, $iY, 0, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hDial)
  GUISetState()
  $hPeak  = GUICreate("Peak"  , $WidthHeight, $WidthHeight, $iX, $iY, 0, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hDial)
  GUISetState()
  $hDot  = GUICreate("Dot"  , $WidthHeight, $WidthHeight, $iX, $iY, 0, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hDial)
  GUISetState()

  ; Initialize GDI+ library
  _GDIPlus_Startup()

  ; Initialize GDI+ resources
  DigiGaugeInit()
  HourInit()
  MinInit ()

  ; Hook non client hit test message so we can move the Gauge
  GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
EndFunc

; ===============================================================================================================================
; Initialize resources for the digital Gauge
; ===============================================================================================================================
Func DigiGaugeInit()
  $aGauge = ResourceInit($iRadius * 2, $iRadius * 2)
  $aGauge[$eBrush ] = _GDIPlus_BrushCreateSolid(0xFF008080)
  $aGauge[$eFormat] = _GDIPlus_StringFormatCreate()
  $aGauge[$eFamily] = _GDIPlus_FontFamilyCreate("Arial")
  $aGauge[$eFont  ] = _GDIPlus_FontCreate($aGauge[$eFamily], 24, 1)
  $aGauge[$eLayout] = _GDIPlus_RectFCreate(0, 0, $iRadius * 2, 40)
EndFunc

; ===============================================================================================================================
; Initialize resources for the hour hand
; ===============================================================================================================================
Func HourInit()
  $aHour = ResourceInit($iRadius * 2, $iRadius * 2)
  $aHour[$ePen] = _GDIPlus_PenCreate(0xFFFF0000)
  $aHour[$eCap] = _GDIPlus_ArrowCapCreate($iHourRad / 2, 8)
  _GDIPlus_PenSetCustomEndCap($aHour[$ePen], $aHour[$eCap])
EndFunc

; ===============================================================================================================================
; Initialize resources for the minute hand
; ===============================================================================================================================
Func MinInit()
  $aMin = ResourceInit($iRadius * 2, $iRadius * 2)
  $aMin[$ePen] = _GDIPlus_PenCreate(0xFFFF00FF)
  $aMin[$eCap] = _GDIPlus_ArrowCapCreate($iMinRad / 2, 8)
  _GDIPlus_PenSetCustomEndCap($aMin[$ePen], $aMin[$eCap])
EndFunc

; ===============================================================================================================================
; Initialize bitmap resources
; ===============================================================================================================================
Func ResourceInit($iWidth, $iHeight)
  Local $aInfo[$eLast + 1]

  $aInfo[$eScrDC  ] = _WinAPI_GetDC(0)
  $aInfo[$eMemDC  ] = _WinAPI_CreateCompatibleDC($aInfo[$eScrDC])
  $aInfo[$eBitmap ] = _WinAPI_CreateCompatibleBitmap($aInfo[$eScrDC], $iWidth, $iHeight)
  _WinAPI_SelectObject($aInfo[$eMemDC], $aInfo[$eBitmap])
  $aInfo[$eWidth  ] = $iWidth
  $aInfo[$eHeight ] = $iHeight
  $aInfo[$eGraphic] = _GDIPlus_GraphicsCreateFromHDC($aInfo[$eMemDC])
  _GDIPlus_GraphicsFillRect($aInfo[$eGraphic], 0, 0, $iRadius * 2, $iRadius * 2)
  Return $aInfo
EndFunc

;################################################################################################################################
;333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333
;################################################################################################################################

; ===============================================================================================================================
; Draw the Gauge elements
; ===============================================================================================================================
Func Draw()
  ; Calculate current Gauge element position
  Global $LastXXP = $XXP
  Global $LastYYP = $YYP
  fakeinput()
  Global $XXP = $iCenter + Cos($input1 * $deg) * $R2P
  Global $YYP = $iCenter + Sin($input1 * $deg) * $R2P
  Global $XXP = $iCenter + Cos($input1 * $deg) * $R2P
  Global $YYP = $iCenter + Sin($input1 * $deg) * $R2P

  $aLast = $aCurr
  $aCurr[1][0] = $iCenter + Cos(TimeToRadians("min" )) * $iMinRad
  $aCurr[1][1] = $iCenter - Sin(TimeToRadians("min" )) * $iMinRad
  $aCurr[2][0] = $iCenter + Cos(TimeToRadians("hour")) * $iHourRad
  $aCurr[2][1] = $iCenter - Sin(TimeToRadians("hour")) * $iHourRad

  ; Draw Gauge elements
  DigiGaugeDraw()
  HourDraw()
  MinDraw ()
EndFunc

; ===============================================================================================================================
; Draw the Gauge dial
; ===============================================================================================================================
Func DialDraw()
  Local $aDial, $hPen1, $hPen2, $iI, $iN, $iX1, $iY1, $iX2, $iY2

  $aDial = ResourceInit($iRadius * 2, $iRadius * 2)
  $hPen1 = _GDIPlus_PenCreate()
  $hPen2 = _GDIPlus_PenCreate(0xFF0000FF, 4)
  for $iI = 0 to 2 * $nPI Step $nPI / 30
    $iX1 = $iCenter + Cos($iI) * ($iRadius * (1.00 - $iTickLen))
    $iY1 = $iCenter - Sin($iI) * ($iRadius * (1.00 - $iTickLen))
    $iX2 = $iCenter + Cos($iI) * $iRadius
    $iY2 = $iCenter - Sin($iI) * $iRadius
    if Mod($iN, 5) = 0 then
      _GDIPlus_GraphicsDrawLine($aDial[$eGraphic], $iX1, $iY1, $iX2, $iY2, $hPen2)
    else
      _GDIPlus_GraphicsDrawLine($aDial[$eGraphic], $iX1, $iY1, $iX2, $iY2, $hPen1)
    endif
    $iN += 1
  next
  _GDIPlus_PenDispose($hPen2)
  _GDIPlus_PenDispose($hPen1)

  ResourceSet ($hDial, $aDial)
  ResourceDone($aDial)
EndFunc

; ===============================================================================================================================
; Draw the center dot
; ===============================================================================================================================
Func DotDraw()
  Local $aDot

  $aDot = ResourceInit($iRadius * 2, $iRadius * 2)
  _GDIPlus_GraphicsFillEllipse($aDot[$eGraphic], $iRadius-10, $iRadius-10, 20, 20)
  ResourceSet ($hDot, $aDot, $iDotOpacity)
  ResourceDone($aDot)
EndFunc

; ===============================================================================================================================
; Draw the hour hand
; ===============================================================================================================================
Func HourDraw()
    if ($LastXXP = $XXP) and ($LastYYP = $YYP) then Return
  _GDIPlus_GraphicsDrawLine($aHour[$eGraphic], $iCenter, $iCenter,  $XXP, $YYP, $aHour[$ePen])
  ResourceSet($hNeedle, $aHour)
EndFunc

; ===============================================================================================================================
; Draw the minute hand
; ===============================================================================================================================
Func MinDraw()
      ;if ($aLast[1][0] = $aCurr[1][0]) and ($aLast[1][1] = $aCurr[1][1]) then Return
  ;_GDIPlus_GraphicsFillRect($aMin[$eGraphic], 0, 0, $iRadius * 2, $iRadius * 2)
  ;_GDIPlus_GraphicsDrawLine($aMin[$eGraphic], $iCenter, $iCenter, $XXM, $YYM, $aMin[$ePen])
  ;ResourceSet($hPeak, $aMin)
EndFunc

; ===============================================================================================================================
; Draw the digital Gauge
; ===============================================================================================================================
Func DigiGaugeDraw()
  Local $sString, $aSize
  if ($aLast[0][0] = $aCurr[0][0]) and ($aLast[0][1] = $aCurr[0][1]) then Return
fakeinput()
  $sString = $input0
  $aSize   = _GDIPlus_GraphicsMeasureString($aGauge[$eGraphic], $sString, $aGauge[$eFont], $aGauge[$eLayout], $aGauge[$eFormat])
  DllStructSetData($aGauge[$eLayout], "X", $iRadius - (DllStructGetData($aSize[0], "Width") / 2))
  DllStructSetData($aGauge[$eLayout], "Y", $iRadius / 3)
  _GDIPlus_GraphicsFillRect($aGauge[$eGraphic], 0, 0, $iRadius * 2, $iRadius * 2)
  _GDIPlus_GraphicsDrawStringEx($aGauge[$eGraphic], $sString, $aGauge[$eFont], $aGauge[$eLayout], $aGauge[$eFormat], $aGauge[$eBrush])
  ResourceSet($hDigiGauge, $aGauge)
EndFunc

;################################################################################################################################
;444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444
;################################################################################################################################

; ===============================================================================================================================
; Finalize Gauge
; ===============================================================================================================================
Func GaugeDone()
  ; Finalize GDI+ resources
  DigiGaugeDone()
  HourDone()
  MinDone ()
  SecDone ()

  ; Finalize GDI+ library
  _GDIPlus_Shutdown()
EndFunc

; ===============================================================================================================================
; Finalize resources for the hour hand
; ===============================================================================================================================
Func HourDone()
  _GDIPlus_PenDispose($aHour[$ePen])
  _GDIPlus_ArrowCapDispose($aHour[$eCap])
  ResourceDone($aHour)
EndFunc

; ===============================================================================================================================
; Finalize resources for the minute hand
; ===============================================================================================================================
Func MinDone()
  _GDIPlus_PenDispose($aMin[$ePen])
  _GDIPlus_ArrowCapDispose($aMin[$eCap])
  ResourceDone($aMin)
EndFunc

; ===============================================================================================================================
; Finalize resources for the digital Gauge
; ===============================================================================================================================
Func DigiGaugeDone()
  _GDIPlus_FontDispose        ($aGauge[$eFont  ])
  _GDIPlus_FontFamilyDispose  ($aGauge[$eFamily])
  _GDIPlus_StringFormatDispose($aGauge[$eFormat])
  _GDIPlus_BrushDispose       ($aGauge[$eBrush ])
  ResourceDone($aGauge)
EndFunc

; ===============================================================================================================================
; Finalize drawing resources
; ===============================================================================================================================
Func ResourceDone(ByRef $aInfo)
  _GDIPlus_GraphicsDispose($aInfo[$eGraphic])
  _WinAPI_ReleaseDC   (0, $aInfo[$eScrDC])
  _WinAPI_DeleteObject($aInfo[$eBitmap])
  _WinAPI_DeleteDC    ($aInfo[$eMemDC ])
EndFunc

;################################################################################################################################
;555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555
;################################################################################################################################

; ===============================================================================================================================
; Update layered window with resource information
; ===============================================================================================================================
Func ResourceSet($hGUI, ByRef $aInfo, $iAlpha=-1)
  Local $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend

  if $iAlpha = -1 then $iAlpha = $iOpacity
  $tSize   = DllStructCreate($tagSIZE)
  $pSize   = DllStructGetPtr($tSize  )
  DllStructSetData($tSize, "X", $aInfo[$eWidth ])
  DllStructSetData($tSize, "Y", $aInfo[$eHeight])
  $tSource = DllStructCreate($tagPOINT)
  $pSource = DllStructGetPtr($tSource)
  $tBlend  = DllStructCreate($tagBLENDFUNCTION)
  $pBlend  = DllStructGetPtr($tBlend )
  DllStructSetData($tBlend, "Alpha" , $iAlpha      )
  DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA)
  _WinAPI_UpdateLayeredWindow($hGUI, $aInfo[$eScrDC], 0, $pSize, $aInfo[$eMemDC], $pSource, 0, $pBlend, $ULW_ALPHA)
EndFunc

;################################################################################################################################
;666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666
;################################################################################################################################

Func fakeinput()
$file = FileOpen("c:\test.txt", 0)
$intemp = FileReadLine($file)
FileClose($file)
Global $input00 = $intemp
Global $input0 = Round($input00, 1)
Global $input1 = $input0 + 90
Global $input2 = $input1
EndFunc

; ===============================================================================================================================
; Convert Gauge value to radians
; ===============================================================================================================================
Func TimeToRadians($sGaugeType)
  Switch $sGaugeType
    case "sec"
      Return ($nPI / 2) - (@SEC  * ($nPI / 30))
    case "min"
      Return ($nPI / 2) - (@MIN  * ($nPI / 30)) - (Int(@SEC / 10) * ($nPI / 180))
    case "hour"
      Return ($nPI / 2) - (@HOUR * ($nPI / 6 )) - (@MIN / 12) * ($nPI / 30)
  EndSwitch
EndFunc

; ===============================================================================================================================
; Handle the WM_NCHITTEST message so our window can be dragged
; ===============================================================================================================================
Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
  if $hWnd = $hDial then Return $HTCAPTION
EndFunc

~~--Feel Free to Steal my Sigs --~~FLAT LOOK____________________________________ROUNDED LOOK

Link to comment
Share on other sites

OK I got it working with this but curious if this will cause resource issues once its reading streaming data

#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

; ===============================================================================================================================
; Global variables
; ===============================================================================================================================

$WidthHeight = 400 ; Width & Height of Window
$iCenter           = $WidthHeight /2 ;Center of Window
$iDotOpacity       = 250
$iOpacity          = 128
$nPI               = 3.1415926535897932384626433832795
$iRadius           = $WidthHeight /2 ;Center of Radius
$iHourRad          = $WidthHeight /2 ;Center of Radius
$iMinRad           = 100
$iTickLen          = 0.02
$AC_SRC_ALPHA      = 1

$deg = ACos(-1) / 180
$radiusM = 200
$radiusP = 360
$R2M = $radiusM * 0.50
$R2P = $radiusP * 0.50


Global Enum $eScrDC=0, $eMemDC, $eBitmap, $eWidth, $eHeight, $eGraphic, $ePen, $eCap, $eBrush, $eFormat, $eFamily, $eFont, $eLayout, $eLast
Global $hDial, $hDigiGauge, $hNeedle, $hPeak, $hSec, $hDot, $aGauge, $aHour, $aMin, $aSec, $aCurr[3][2], $aLast[3][2]

;################################################################################################################################
;000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
;################################################################################################################################

; ===============================================================================================================================
; Main
; ===============================================================================================================================

fakeinput()

Global $XXM = $iCenter + Cos($input1 * $deg) * $R2M
Global $YYM = $iCenter + Sin($input1 * $deg) * $R2M

Global $XXP = $iCenter + Cos($input1 * $deg) * $R2P
Global $YYP = $iCenter + Sin($input1 * $deg) * $R2P

GaugeInit()
DialDraw ()
Draw     ()
DotDraw  ()
GaugeLoop()
GaugeDone()

;################################################################################################################################
;111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
;################################################################################################################################

; ===============================================================================================================================
; Loop until user exits
; ===============================================================================================================================
Func GaugeLoop()
  do
    Draw()
  until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc

;################################################################################################################################
;222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
;################################################################################################################################

; ===============================================================================================================================
; Initialize Gauge
; ===============================================================================================================================
Func GaugeInit()
  Local $iX, $iY

  ; Calculate the dial frame caption size
  $iX = -(_WinAPI_GetSystemMetrics($SM_CXFRAME))
  $iY = -(_WinAPI_GetSystemMetrics($SM_CYCAPTION) + _WinAPI_GetSystemMetrics($SM_CYFRAME))

  ; Allocate the window resources
  $hDial = GUICreate("Gauge", $WidthHeight, $WidthHeight,  -1,  -1, 0, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
  GUISetState()
  $hDigiGauge = GUICreate("DigiGauge" , $WidthHeight, $WidthHeight, $iX, 240, 0, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hDial)
  GUISetState()
  $hNeedle = GUICreate("Needle" , $WidthHeight, $WidthHeight, $iX, $iY, 0, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hDial)
  GUISetState()
  $hPeak  = GUICreate("Peak"  , $WidthHeight, $WidthHeight, $iX, $iY, 0, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hDial)
  GUISetState()
  $hDot  = GUICreate("Dot"  , $WidthHeight, $WidthHeight, $iX, $iY, 0, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hDial)
  GUISetState()

  ; Initialize GDI+ library
  _GDIPlus_Startup()

  ; Initialize GDI+ resources
  DigiGaugeInit()
  HourInit()
  MinInit ()

  ; Hook non client hit test message so we can move the Gauge
  GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
EndFunc

; ===============================================================================================================================
; Initialize resources for the digital Gauge
; ===============================================================================================================================
Func DigiGaugeInit()
  $aGauge = ResourceInit($iRadius * 2, $iRadius * 2)
  $aGauge[$eBrush ] = _GDIPlus_BrushCreateSolid(0xFF008080)
  $aGauge[$eFormat] = _GDIPlus_StringFormatCreate()
  $aGauge[$eFamily] = _GDIPlus_FontFamilyCreate("Arial")
  $aGauge[$eFont  ] = _GDIPlus_FontCreate($aGauge[$eFamily], 24, 1)
  $aGauge[$eLayout] = _GDIPlus_RectFCreate(0, 0, $iRadius * 2, 40)
EndFunc

; ===============================================================================================================================
; Initialize resources for the hour hand
; ===============================================================================================================================
Func HourInit()
  $aHour = ResourceInit($iRadius * 2, $iRadius * 2)
  $aHour[$ePen] = _GDIPlus_PenCreate(0xFFFF0000)
  $aHour[$eCap] = _GDIPlus_ArrowCapCreate($iHourRad / 2, 8)
  _GDIPlus_PenSetCustomEndCap($aHour[$ePen], $aHour[$eCap])
EndFunc

; ===============================================================================================================================
; Initialize resources for the minute hand
; ===============================================================================================================================
Func MinInit()
  $aMin = ResourceInit($iRadius * 2, $iRadius * 2)
  $aMin[$ePen] = _GDIPlus_PenCreate(0xFFFF00FF)
  $aMin[$eCap] = _GDIPlus_ArrowCapCreate($iMinRad / 2, 8)
  _GDIPlus_PenSetCustomEndCap($aMin[$ePen], $aMin[$eCap])
EndFunc

; ===============================================================================================================================
; Initialize bitmap resources
; ===============================================================================================================================
Func ResourceInit($iWidth, $iHeight)
  Local $aInfo[$eLast + 1]

  $aInfo[$eScrDC  ] = _WinAPI_GetDC(0)
  $aInfo[$eMemDC  ] = _WinAPI_CreateCompatibleDC($aInfo[$eScrDC])
  $aInfo[$eBitmap ] = _WinAPI_CreateCompatibleBitmap($aInfo[$eScrDC], $iWidth, $iHeight)
  _WinAPI_SelectObject($aInfo[$eMemDC], $aInfo[$eBitmap])
  $aInfo[$eWidth  ] = $iWidth
  $aInfo[$eHeight ] = $iHeight
  $aInfo[$eGraphic] = _GDIPlus_GraphicsCreateFromHDC($aInfo[$eMemDC])
  _GDIPlus_GraphicsFillRect($aInfo[$eGraphic], 0, 0, $iRadius * 2, $iRadius * 2)
  Return $aInfo
EndFunc

;################################################################################################################################
;333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333
;################################################################################################################################

; ===============================================================================================================================
; Draw the Gauge elements
; ===============================================================================================================================
Func Draw()
  ; Calculate current Gauge element position
  Global $LastXXP = $XXP
  Global $LastYYP = $YYP
  fakeinput()
  Global $XXP = $iCenter + Cos($input1 * $deg) * $R2P
  Global $YYP = $iCenter + Sin($input1 * $deg) * $R2P
  Global $XXP = $iCenter + Cos($input1 * $deg) * $R2P
  Global $YYP = $iCenter + Sin($input1 * $deg) * $R2P

  $aLast = $aCurr
  $aCurr[1][0] = $iCenter + Cos(TimeToRadians("min" )) * $iMinRad
  $aCurr[1][1] = $iCenter - Sin(TimeToRadians("min" )) * $iMinRad
  $aCurr[2][0] = $iCenter + Cos(TimeToRadians("hour")) * $iHourRad
  $aCurr[2][1] = $iCenter - Sin(TimeToRadians("hour")) * $iHourRad

  ; Draw Gauge elements
  DigiGaugeDraw()
  HourDraw()
  MinDraw ()
EndFunc

; ===============================================================================================================================
; Draw the Gauge dial
; ===============================================================================================================================
Func DialDraw()
  Local $aDial, $hPen1, $hPen2, $iI, $iN, $iX1, $iY1, $iX2, $iY2

  $aDial = ResourceInit($iRadius * 2, $iRadius * 2)
  $hPen1 = _GDIPlus_PenCreate()
  $hPen2 = _GDIPlus_PenCreate(0xFF0000FF, 4)
  for $iI = 0 to 2 * $nPI Step $nPI / 30
    $iX1 = $iCenter + Cos($iI) * ($iRadius * (1.00 - $iTickLen))
    $iY1 = $iCenter - Sin($iI) * ($iRadius * (1.00 - $iTickLen))
    $iX2 = $iCenter + Cos($iI) * $iRadius
    $iY2 = $iCenter - Sin($iI) * $iRadius
    if Mod($iN, 5) = 0 then
      _GDIPlus_GraphicsDrawLine($aDial[$eGraphic], $iX1, $iY1, $iX2, $iY2, $hPen2)
    else
      _GDIPlus_GraphicsDrawLine($aDial[$eGraphic], $iX1, $iY1, $iX2, $iY2, $hPen1)
    endif
    $iN += 1
  next
  _GDIPlus_PenDispose($hPen2)
  _GDIPlus_PenDispose($hPen1)

  ResourceSet ($hDial, $aDial)
  ResourceDone($aDial)
EndFunc

; ===============================================================================================================================
; Draw the center dot
; ===============================================================================================================================
Func DotDraw()
  Local $aDot

  $aDot = ResourceInit($iRadius * 2, $iRadius * 2)
  _GDIPlus_GraphicsFillEllipse($aDot[$eGraphic], $iRadius-10, $iRadius-10, 20, 20)
  ResourceSet ($hDot, $aDot, $iDotOpacity)
  ResourceDone($aDot)
EndFunc

; ===============================================================================================================================
; Draw the hour hand
; ===============================================================================================================================
Func HourDraw()
    if ($LastXXP = $XXP) and ($LastYYP = $YYP) then Return
    HourDone()
    HourInit()
  _GDIPlus_GraphicsDrawLine($aHour[$eGraphic], $iCenter, $iCenter,  $XXP, $YYP, $aHour[$ePen])
  ResourceSet($hNeedle, $aHour)
EndFunc

; ===============================================================================================================================
; Draw the minute hand
; ===============================================================================================================================
Func MinDraw()
      ;if ($aLast[1][0] = $aCurr[1][0]) and ($aLast[1][1] = $aCurr[1][1]) then Return
  ;_GDIPlus_GraphicsFillRect($aMin[$eGraphic], 0, 0, $iRadius * 2, $iRadius * 2)
  ;_GDIPlus_GraphicsDrawLine($aMin[$eGraphic], $iCenter, $iCenter, $XXM, $YYM, $aMin[$ePen])
  ;ResourceSet($hPeak, $aMin)
EndFunc

; ===============================================================================================================================
; Draw the digital Gauge
; ===============================================================================================================================
Func DigiGaugeDraw()
  Local $sString, $aSize
  if ($aLast[0][0] = $aCurr[0][0]) and ($aLast[0][1] = $aCurr[0][1]) then Return
fakeinput()
  $sString = $input0
  $aSize   = _GDIPlus_GraphicsMeasureString($aGauge[$eGraphic], $sString, $aGauge[$eFont], $aGauge[$eLayout], $aGauge[$eFormat])
  DllStructSetData($aGauge[$eLayout], "X", $iRadius - (DllStructGetData($aSize[0], "Width") / 2))
  DllStructSetData($aGauge[$eLayout], "Y", $iRadius / 3)
  _GDIPlus_GraphicsFillRect($aGauge[$eGraphic], 0, 0, $iRadius * 2, $iRadius * 2)
  _GDIPlus_GraphicsDrawStringEx($aGauge[$eGraphic], $sString, $aGauge[$eFont], $aGauge[$eLayout], $aGauge[$eFormat], $aGauge[$eBrush])
  ResourceSet($hDigiGauge, $aGauge)
EndFunc

;################################################################################################################################
;444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444
;################################################################################################################################

; ===============================================================================================================================
; Finalize Gauge
; ===============================================================================================================================
Func GaugeDone()
  ; Finalize GDI+ resources
  DigiGaugeDone()
  HourDone()
  MinDone ()
  SecDone ()

  ; Finalize GDI+ library
  _GDIPlus_Shutdown()
EndFunc

; ===============================================================================================================================
; Finalize resources for the hour hand
; ===============================================================================================================================
Func HourDone()
  _GDIPlus_PenDispose($aHour[$ePen])
  _GDIPlus_ArrowCapDispose($aHour[$eCap])
  ResourceDone($aHour)
EndFunc

; ===============================================================================================================================
; Finalize resources for the minute hand
; ===============================================================================================================================
Func MinDone()
  _GDIPlus_PenDispose($aMin[$ePen])
  _GDIPlus_ArrowCapDispose($aMin[$eCap])
  ResourceDone($aMin)
EndFunc

; ===============================================================================================================================
; Finalize resources for the digital Gauge
; ===============================================================================================================================
Func DigiGaugeDone()
  _GDIPlus_FontDispose        ($aGauge[$eFont  ])
  _GDIPlus_FontFamilyDispose  ($aGauge[$eFamily])
  _GDIPlus_StringFormatDispose($aGauge[$eFormat])
  _GDIPlus_BrushDispose       ($aGauge[$eBrush ])
  ResourceDone($aGauge)
EndFunc

; ===============================================================================================================================
; Finalize drawing resources
; ===============================================================================================================================
Func ResourceDone(ByRef $aInfo)
  _GDIPlus_GraphicsDispose($aInfo[$eGraphic])
  _WinAPI_ReleaseDC   (0, $aInfo[$eScrDC])
  _WinAPI_DeleteObject($aInfo[$eBitmap])
  _WinAPI_DeleteDC    ($aInfo[$eMemDC ])
EndFunc

;################################################################################################################################
;555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555
;################################################################################################################################

; ===============================================================================================================================
; Update layered window with resource information
; ===============================================================================================================================
Func ResourceSet($hGUI, ByRef $aInfo, $iAlpha=-1)
  Local $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend

  if $iAlpha = -1 then $iAlpha = $iOpacity
  $tSize   = DllStructCreate($tagSIZE)
  $pSize   = DllStructGetPtr($tSize  )
  DllStructSetData($tSize, "X", $aInfo[$eWidth ])
  DllStructSetData($tSize, "Y", $aInfo[$eHeight])
  $tSource = DllStructCreate($tagPOINT)
  $pSource = DllStructGetPtr($tSource)
  $tBlend  = DllStructCreate($tagBLENDFUNCTION)
  $pBlend  = DllStructGetPtr($tBlend )
  DllStructSetData($tBlend, "Alpha" , $iAlpha      )
  DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA)
  _WinAPI_UpdateLayeredWindow($hGUI, $aInfo[$eScrDC], 0, $pSize, $aInfo[$eMemDC], $pSource, 0, $pBlend, $ULW_ALPHA)
EndFunc

;################################################################################################################################
;666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666
;################################################################################################################################

Func fakeinput()
$file = FileOpen("c:\test.txt", 0)
$intemp = FileReadLine($file)
FileClose($file)
Global $input00 = $intemp
Global $input0 = Round($input00, 1)
Global $input1 = $input0 + 90
Global $input2 = $input1
EndFunc

; ===============================================================================================================================
; Convert Gauge value to radians
; ===============================================================================================================================
Func TimeToRadians($sGaugeType)
  Switch $sGaugeType
    case "sec"
      Return ($nPI / 2) - (@SEC  * ($nPI / 30))
    case "min"
      Return ($nPI / 2) - (@MIN  * ($nPI / 30)) - (Int(@SEC / 10) * ($nPI / 180))
    case "hour"
      Return ($nPI / 2) - (@HOUR * ($nPI / 6 )) - (@MIN / 12) * ($nPI / 30)
  EndSwitch
EndFunc

; ===============================================================================================================================
; Handle the WM_NCHITTEST message so our window can be dragged
; ===============================================================================================================================
Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
  if $hWnd = $hDial then Return $HTCAPTION
EndFunc

~~--Feel Free to Steal my Sigs --~~FLAT LOOK____________________________________ROUNDED LOOK

Link to comment
Share on other sites

Hi,

Regardless of your problem you might want to set Global Variable from outside of functions.

As it is I get errors about variable not being declared yet.

(41,38) : WARNING: $input1: possibly used before declaration.
Global $XXM = $iCenter + Cos($input1 *
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

So I step through the first error declare the Global vars from fakeinput() function.

Then try again only to get..

(227,18) : WARNING: $LastXXP: possibly used before declaration.
    if ($LastXXP =
~~~~~~~~~~~~~~~~~^

Soak, lather, rinse repeat and again, down through the list of global vars that should be declared outside functions then onto

(272,12) : ERROR: SecDone(): undefined function.
  SecDone ()
~~~~~~~~~~~^

It sorta makes it hard to try and help when the code is incomplete...lol

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...