Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

[SOLVED] GDI+ 360 Angle Scope

$
0
0
The following is the code
[ autoit ]         
#include-once #include <WinAPI.au3> #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <Misc.au3> _GDIPlus_Startup() Opt("MouseCoordMode", 2) ;User Values Global $i_WindAngle = -60 ;Time Unit is Milli-Secs. Angle in Degrees Global $hGfx_Direction, $hMatrix = _GDIPlus_MatrixCreate() ;The Graphics where Animation and Direction Change will occur Global $hGfx_DirectionBitmap, $hBmp_Direction;The Bitmap and Bitmap Graphic object of the Direction control. ;...-------=============================================== OnAutoItExitRegister("Dispose") ;Create Pen for drawing direction Global $hPen = _GDIPlus_PenCreate(0xFF00FFAB) Global $hArrowCap = _GDIPlus_ArrowCapCreate(5, 3) _GDIPlus_PenSetCustomEndCap($hPen, $hArrowCap) ;...-------=============================================== ;Create the GUI for Animation. Global $hGUI = GUICreate("GDI+ Test", 300, 150) GUICtrlCreateLabel("WindAngle:", 10, 82) Global $iInput = GUICtrlCreateInput($i_WindAngle, 75, 80, 80) Global $iDirection = GUICtrlCreateLabel("", 170, 40, 90, 90, $SS_BITMAP) Global $hDirection = GUICtrlGetHandle(-1) GUICtrlSetCursor(-1, 0) $hGfx_Direction = _GDIPlus_GraphicsCreateFromHWND($hDirection) $hBmp_Direction = _GDIPlus_BitmapCreateFromGraphics(90, 90, $hGfx_Direction) $hGfx_DirectionBitmap = _GDIPlus_ImageGetGraphicsContext($hBmp_Direction) _GDIPlus_MatrixTranslate($hMatrix, 45, 45) _GDIPlus_MatrixRotate($hMatrix, $i_WindAngle) ChangeDirection(1) GUIRegisterMsg($WM_CTLCOLORSTATIC, "WM_CTLCOLORSTATIC") GUISetState() Local $iTimeMsg While $iTimeMsg <> $GUI_EVENT_CLOSE $iTimeMsg = GUIGetMsg() Switch $iTimeMsg Case $iDirection GUICtrlSetState($iDirection, $GUI_DISABLE) ;Change the Pointing Arrow While _IsPressed("01") Sleep(10) WEnd ChangeDirection() GUICtrlSetState($iDirection, $GUI_ENABLE) EndSwitch WEnd ;...-------=============================================== Exit Func ChangeDirection($iDraw = 0) ;If draw is required return immediately If $iDraw Then _GDIPlus_GraphicsSetTransform($hGfx_DirectionBitmap, $hMatrix) _GDIPlus_GraphicsDrawLine($hGfx_DirectionBitmap, 0, 0, 45, 0, $hPen) _WinAPI_RedrawWindow($hDirection) Return 1 EndIf ;Trap the Mouse to the ClientWin Local $tPoint = DllStructCreate($tagPoint) DllStructSetData($tPoint, 1, 0) DllStructSetData($tPoint, 2, 0) _WinAPI_ClientToScreen($hGUI, $tPoint) _MouseTrap( DllStructGetData($tPoint,1), DllStructGetData($tPoint,2), DllStructGetData($tPoint,1) + _WinAPI_GetClientWidth($hGUI), DllStructGetData($tPoint,2) + _WinAPI_GetClientHeight($hGUI)) Local $nAngle = 0, $aDirectionPos = ControlGetPos($hGUI, '', $iDirection) Do ;Clear the Bimap _GDIPlus_GraphicsClear($hGfx_DirectionBitmap, 0xFFF0F0F0) ;Get the Angle suspended with the Mouse $nAngle = Radian2Degree(ATan(Abs(MouseGetPos(1) - $aDirectionPos[1]) / Abs(MouseGetPos(0) - ($aDirectionPos[0] + $aDirectionPos[2] / 2)))) _GDIPlus_MatrixRotate($hMatrix, $nAngle) ;Rotate it _GDIPlus_GraphicsSetTransform($hGfx_DirectionBitmap, $hMatrix) ;Show changes in the Graphics _GDIPlus_GraphicsDrawLine($hGfx_DirectionBitmap, 0, 0, 45, 0, $hPen) ;Draw the Arrow _WinAPI_RedrawWindow($hDirection) ;Show the changes in the Control ;Change the Angle in the Input GUICtrlSetData($iInput, Round($nAngle, 2)) ;Matrix Reset Angles _GDIPlus_MatrixRotate($hMatrix, -$nAngle) ;For Degugging purposes only ToolTip($nAngle) Until _IsPressed("01") ;Exit when clicked again ToolTip("") _MouseTrap() EndFunc ;==>ChangeDirection Func Degree2Radian($iDegree) Return ACos(-1) * $iDegree / 180 EndFunc ;==>Degree2Radian Func Radian2Degree($iRadian) Return 180 * $iRadian / ACos(-1) EndFunc ;==>Radian2Degree Func WM_CTLCOLORSTATIC($hWnd, $iMsg, $wParam, $lParam) If $hDirection = $lParam Then _GDIPlus_GraphicsDrawImage($hGfx_Direction, $hBmp_Direction, 0, 0) Return _WinAPI_GetStockObject($HOLLOW_BRUSH) ;Msg Handled EndIf EndFunc ;==>WM_CTLCOLORSTATIC Func Dispose() GUIDelete($hGUI) ;Memory Release _GDIPlus_PenDispose($hPen) _GDIPlus_ArrowCapDispose($hArrowCap) _GDIPlus_MatrixDispose($hMatrix) _GDIPlus_GraphicsDispose($hGfx_DirectionBitmap) _GDIPlus_ImageDispose($hBmp_Direction) _GDIPlus_GraphicsDispose($hGfx_Direction) _GDIPlus_Shutdown() EndFunc ;==>Dispose
The Problem is
  • The Angle detected seems to be incorrect
  • I don't find a way to receive angles beyond 90 degrees.
There should be a way I'm not aware of, please guide me.
Thanks for you help and time. :)

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>