E1M1 Posted March 2, 2011 Share Posted March 2, 2011 I am trying tom make clock control. How do I dynamically put all 12 hour label to right place on clock? I don't want to use _GDIPlus_GraphicsDrawString ($hGraphic, "Hello world", 140, 110) with fixed coordinates, but I can't think how to make function that would place these dynamically. 3'o clock should be placed at 0 degrees, 12 o'clock should be at 90 degrees 9 => 180 deg and 6 => 270 deg. How can I write function that would take $x,$y,$r1,$r2,$deg as args and then calculate x,y so that when I put label on x,y it would be on right place at clock? #include <GuiConstantsEx.au3> #include <GDIPlus.au3> Opt('MustDeclareVars', 1) _Main() Func _Main() Local $hGUI, $hGraphic ; Create GUI $hGUI = GUICreate("GDI+", 400, 300) GUISetState() ; Draw an ellipse _GDIPlus_Startup () GUiCtrlClockCreate($hGUI,30,30,200,200) ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE ; Clean up resources _GDIPlus_GraphicsDispose ($hGraphic) _GDIPlus_Shutdown () EndFunc ;==>_Main Func GUICtrlClockCreate($hwnd,$x,$y,$r1,$r2,$hGraphic = False) If $hGraphic = false Then $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hwnd) _GDIPlus_GraphicsDrawEllipse ($hGraphic, $x,$y,$r1,$r2) _GDIPlus_GraphicsDrawEllipse ($hGraphic, $x + ($r1/2 -1),$y + ($r2/2 -1),3,3) ;_GDIPlus_GraphicsDrawString ($hGraphic, "Hello world", 140, 110) EndFunc edited Link to comment Share on other sites More sharing options...
UEZ Posted March 2, 2011 Share Posted March 2, 2011 (edited) You mean something like this:expandcollapse popup#include <GuiConstantsEx.au3> #include <GDIPlus.au3> Opt('MustDeclareVars', 1) _Main() Func _Main() Local $hGUI, $hGraphic ; Create GUI $hGUI = GUICreate("GDI+", 400, 300) GUISetState() ; Draw an ellipse _GDIPlus_Startup () GUiCtrlClockCreate($hGUI,30,30,200,200) ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE ; Clean up resources _GDIPlus_GraphicsDispose ($hGraphic) _GDIPlus_Shutdown () EndFunc ;==>_Main Func GUICtrlClockCreate($hwnd,$x,$y,$r1,$r2,$hGraphic = False) Local $i, $cR3 = 90, $fs = 8, $deg = ACos(-1) / 180 If $hGraphic = false Then $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hwnd) _GDIPlus_GraphicsDrawEllipse ($hGraphic, $x,$y,$r1,$r2) _GDIPlus_GraphicsDrawEllipse ($hGraphic, $x + ($r1/2 -1),$y + ($r2/2 -1),3,3) For $i = 1 To 12 _GDIPlus_GraphicsDrawString($hGraphic, $i, -$fs / 2 + $x + ($r1/2 -1) + Cos(-45 + ($i - 1) * 29.7 * $deg) * $cR3, -$fs * 0.75 + $y + ($r2/2 -1) + Sin(-45 + ($i - 1) * 29.7 * $deg) * $cR3, "Arial", $fs) Next ;_GDIPlus_GraphicsDrawString ($hGraphic, "Hello world", 140, 110) EndFuncI wrote last year a Maybe it is useful for you! Br,UEZ Edited April 23, 2011 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
E1M1 Posted March 2, 2011 Author Share Posted March 2, 2011 (edited) Thanks a lot. I am looking for something like your clock but how to make clock pointers user dragable? Lets say that user click on X,Y on client area. How to detect if that x,y is somewhere on clock pointer? expandcollapse popup#include <GuiConstantsEx.au3> #include <GDIPlus.au3> Opt('MustDeclareVars', 1) _Main() Func _Main() Local $hGUI, $hGraphic ; Create GUI $hGUI = GUICreate("GDI+", 400, 300) GUISetState() ; Draw an ellipse _GDIPlus_Startup () GUiCtrlClockCreate($hGUI,30,30,200,200) ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE ; Clean up resources _GDIPlus_GraphicsDispose ($hGraphic) _GDIPlus_Shutdown () EndFunc ;==>_Main Func GUICtrlClockCreate($hwnd,$x,$y,$r1,$r2,$hGraphic = False) Local $i, $cR3 = 90, $fs = 8, $deg = ACos(-1) / 180 If $hGraphic = false Then $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hwnd) _GDIPlus_GraphicsDrawEllipse ($hGraphic, $x,$y,$r1,$r2) _GDIPlus_GraphicsDrawEllipse ($hGraphic, $x + ($r1/2 -1),$y + ($r2/2 -1),3,3) For $i = 1 To 12 _GDIPlus_GraphicsDrawString($hGraphic, $i, -$fs / 2 + $x + ($r1/2 -1) + Cos(-45 + ($i - 1) * 29.7 * $deg) * $cR3, -$fs * 0.75 + $y + ($r2/2 -1) + Sin(-45 + ($i - 1) * 29.7 * $deg) * $cR3, "Arial", $fs) Next $i = 1 _GDIPlus_GraphicsDrawLine($hGraphic, $x + ($r1/2 -1), $y + ($r2/2 -1), -$fs / 2 + $x + ($r1/2 -1) + Cos(-45 + ($i - 1) * 29.7 * $deg) * $cR3, -$fs * 0.75 + $y + ($r2/2 -1) + Sin(-45 + ($i - 1) * 29.7 * $deg) * $cR3) $i = 3 _GDIPlus_GraphicsDrawLine($hGraphic, $x + ($r1/2 -1), $y + ($r2/2 -1), -$fs / 2 + $x + ($r1/2 -1) + Cos(-45 + ($i - 1) * 29.7 * $deg) * $cR3, -$fs * 0.75 + $y + ($r2/2 -1) + Sin(-45 + ($i - 1) * 29.7 * $deg) * $cR3) ;_GDIPlus_GraphicsDrawString ($hGraphic, "Hello world", 140, 110) EndFunc Edited March 2, 2011 by E1M1 edited Link to comment Share on other sites More sharing options...
Malkey Posted March 3, 2011 Share Posted March 3, 2011 .... how to make clock pointers user dragable?....Dragable clock hands reminded me of the example Don't forget to right click either clock's center black dot. Link to comment Share on other sites More sharing options...
E1M1 Posted March 3, 2011 Author Share Posted March 3, 2011 nice example edited Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now