Jump to content

Making a gauge


Recommended Posts

So I saw the clock example and it flew right over my head with the drawing and what not but I want to know how to say take the clock hand and make it display a value like 270 degrees will be zero and 90 degrees would be 100. I could either do this or do a movie clip with a slider and I'd like to avoid that but either way a slider is what's going to control the gauge if not then two input boxes and a button. Can someone help me with this?

Link to comment
Share on other sites

So I saw the clock example and it flew right over my head with the drawing and what not but I want to know how to say take the clock hand and make it display a value like 270 degrees will be zero and 90 degrees would be 100. I could either do this or do a movie clip with a slider and I'd like to avoid that but either way a slider is what's going to control the gauge if not then two input boxes and a button. Can someone help me with this?

Something like this?

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

_Main()

Func _Main()
    Local $hGUI, $hGraphic, $hPen
    $x = 200
    $y = 150
    $radius = 150
    $hGUI = GUICreate("Gadge", $x * 2, $y * 2)
    $Slider1 = GUICtrlCreateSlider(1, 1, 350, 15)
    GUICtrlSetLimit(-1, 270, 90)
    $Label1 = GUICtrlCreateLabel("Degree", 360, 1, 50, 20)
    GUISetState()
    _GDIPlus_Startup()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($x * 2, $y * 2, $hGraphic)
    $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2)
    $hPen = _GDIPlus_PenCreate(0xFF000000, 5)
    $deg = 0
    $deg2 = 0

    Do
        $deg = GUICtrlRead($Slider1)
        GUICtrlSetData($Label1, $deg & "°")
        If $deg2 <> $deg Then
            $deg2 = $deg
            _WinAPI_RedrawWindow($hGUI)
            _GDIPlus_GraphicsClear($hBackbuffer, 0xFFFFFFFF)
            $radian = ($deg / 180) * 3.14159265358979
            $xz = $x + Cos($radian) * $radius
            $yz = $y + Sin($radian) * $radius
            _GDIPlus_GraphicsDrawLine($hGraphic, $x, $y, $xz, $yz, $hPen)

        EndIf
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
EndFunc   ;==>_Main

Smoother

Edited by JoHanatCent
Link to comment
Share on other sites

Thanks man! Just wondering would it be possible t remove the gui and only have the drawn line, maybe put the slider in a seperate window?

Something to play with:

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
_GDIPlus_Startup()
$hGUI = GUICreate("", @DesktopWidth, @DesktopHeight - 100, 400, 100, $WS_POPUP, $WS_EX_LAYERED)
GUISetBkColor(0xABCDEF)
GUISetOnEvent(-3, "_Exit")
OnAutoItExitRegister("_Exit")
_WinAPI_SetLayeredWindowAttributes($hGUI, 0xABCDEF, 0x60)
GUISetState()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics(400, 400, $hGraphic)
$hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2)
$hPen = _GDIPlus_PenCreate(0xFF000000, 5)
$deg = 0
$deg2 = 0
$x = 200
$y = 150
$radius = 150
$gGUI = GUICreate("Gauge", 400, 30, @DesktopWidth/2-200, 1, $WS_POPUP)
GUISetOnEvent(-3, "_Exit")
OnAutoItExitRegister("_Exit")
GUICtrlSetDefColor(0xFF0000)
GUISetBkColor(0xE0FFFF)
$Slider1 = GUICtrlCreateSlider(1, 1, 350, 15)
GUICtrlSetLimit(-1, 270, 90)
$Label1 = GUICtrlCreateLabel("Degree", 360, 1, 50, 20)
GUISetState()
Do
    $deg = GUICtrlRead($Slider1)
    If $deg2 <> $deg Then
        $deg2 = $deg
        _WinAPI_RedrawWindow($hGUI)
        _GDIPlus_GraphicsClear($hBackbuffer, 0xFFFFFFFF)
        $radian = ($deg / 180) * 3.14159265358979
        $xz = $x + Cos($radian) * $radius
        $yz = $y + Sin($radian) * $radius
        _GDIPlus_GraphicsDrawLine($hGraphic, $x, $y, $xz, $yz, $hPen)
        GUICtrlSetData($Label1, $deg & "°")
    EndIf
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Func _Exit()
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
    Exit
EndFunc   ;==>_Exit

Note: Did not remove the GUI.

Without the Gui refreshing the Gauge will become an issue!

Edited by JoHanatCent
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...