Jump to content

Variable not declared BUT ITS GLOBAL VARIABLE


burners
 Share

Recommended Posts

I have been having issues lately with Global Variables which are in the main top section of my script outside of any functions.

It appears any functions throw an error telling me the variables are not declared when they are GLOBAL variables.

I dont understand how a global variable isnt declared.

Any ideas?

Thanks

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

Link to comment
Share on other sites

OK

I am playing around with the Autoit Clock script and modifying it to run as a Gauge that will eventually read data from the serial.

For now I am using a text file while I am testing and modifying the code, I am currently working on the piece that will only update the gauge needle when a change is detected.

This is done with

$LastXXP = $XXP

$LastYYP = $YYP

On line 165

If I try to run the script it tells me $XXP is not declared but they are on line 52

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

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

#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
; ===============================================================================================================================


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

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


;################################################################################################################################
;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
  $LastXXP = $XXP
  $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

Got that fixed but one thing that puzzles me is why when I update my text file the gauge will draw a new needle without erasing the old and I dont recall removing anything that would cause this.

If you wanna look check it out, You need a text file @

C:\test.txt

With a value of something like 200

Then open the file and change the value to see the first needle register

#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

Dammit I now see I declared after the function call

DUH!!!!!

that's a problem I have a lot too >.< Try to declare all your variables at the very top, even if they aren't used until the bottom of your script. That helps me prevent doing stuff like this. Plus I think it makes the script look cleaner anyway, which is always a positive!

00101101011110000101000001101100011011110110100101110100

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