Alex1986 Posted June 22, 2018 Share Posted June 22, 2018 (edited) Hi this simple code , but it is rectangular, I want inside the circle _GDIPlus_GraphicsFillEllipse _GDIPlus_GraphicsDrawEllipse Thank You expandcollapse popup#include <GDIPlus.au3> Opt("GUIOnEventMode", 1) Global $gW = 300 , $gH = 300 , $nW = 50 $Form1 = GUICreate("selected circle", $gW, $gH, 192, 124) GUISetOnEvent(-3 , "_Exit") GUISetState(@SW_SHOW) _GDIPlus_Startup() $Graph = _GDIPlus_GraphicsCreateFromHWND($Form1) _GDIPlus_GraphicsDrawRect( $Graph , $gW/2 - $nW/2 ,$gH/2 - $nW/2 , $nW ,$nW ) $coloGUI = "0xFFFFFFFF" While 1 sleep(40) $mPos = GUIGetCursorInfo("") if ($mPos[0] > $gW/2 - $nW/2 AND $mPos[1] > $gH/2 - $nW/2) AND ($mPos[0] < $gW/2 + $nW/2 AND $mPos[1] < $gH/2 + $nW/2) Then _GDIPlus_GraphicsClear($Graph , $coloGUI) _GDIPlus_GraphicsFillRect( $Graph , $gW/2 - $nW/2, $gH/2 - $nW/2 , $nW , $nW ) Else _GDIPlus_GraphicsClear($Graph , $coloGUI) _GDIPlus_GraphicsDrawRect( $Graph , $gW/2 - $nW/2 , $gH/2 - $nW/2 , $nW , $nW ) EndIf WEnd Func _Exit() _GDIPlus_GraphicsDispose($Graph) _GDIPlus_Shutdown() Exit EndFunc Edited June 22, 2018 by Alex1986 Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted June 22, 2018 Moderators Share Posted June 22, 2018 @Alex1986 so what have you tried on your own? This forum is dedicated to helping people with their own scripts; it is not a place where you put in a request and someone barfs up code for you. You say it is simple code, and you show the functions you know you need, so what problems are you running into? "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Alex1986 Posted June 22, 2018 Author Share Posted June 22, 2018 I have a problem with mouse coordinates . When the cursor mouse enters the circle color changes, I can apply it to the rectangle, but the circle i can't *the simple code that apply to the rectangle Link to comment Share on other sites More sharing options...
Malkey Posted June 22, 2018 Share Posted June 22, 2018 See the function _PointInEllipse() from here. Instead of clearing the entire graphics each time, I would refill the shape with a different coloured brush. Then you can keep multiple shapes on the one graphics object. expandcollapse popup#include <GDIPlus.au3> Opt("GUIOnEventMode", 1) Global $gW = 300, $gH = 300, $nW = 50 $Form1 = GUICreate("selected circle", $gW, $gH, 192, 124) GUISetOnEvent(-3, "_Exit") GUISetState(@SW_SHOW) _GDIPlus_Startup() $Graph = _GDIPlus_GraphicsCreateFromHWND($Form1) _GDIPlus_GraphicsClear($Graph, 0xFFFFFFFF) Local $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF) Local $hBrush2 = _GDIPlus_BrushCreateSolid(0xFFFF0000) Local $hBrush3 = _GDIPlus_BrushCreateSolid(0xFF0000FF) While 1 Sleep(40) $mPos = GUIGetCursorInfo("") If _PointInEllipse($mPos[0], $mPos[1], $gW / 4 - $nW / 4, $gH / 4 - $nW / 4, $nW, $nW) Then _GDIPlus_GraphicsFillEllipse($Graph, $gW / 4 - $nW / 4, $gH / 4 - $nW / 4, $nW, $nW, $hBrush2) Else _GDIPlus_GraphicsFillEllipse($Graph, $gW / 4 - $nW / 4, $gH / 4 - $nW / 4, $nW, $nW, $hBrush) _GDIPlus_GraphicsDrawEllipse($Graph, $gW / 4 - $nW / 4, $gH / 4 - $nW / 4, $nW, $nW) EndIf If ($mPos[0] > $gW / 2 - $nW / 2 And $mPos[1] > $gH / 2 - $nW / 2) And ($mPos[0] < $gW / 2 + $nW / 2 And $mPos[1] < $gH / 2 + $nW / 2) Then _GDIPlus_GraphicsFillRect($Graph, $gW / 2 - $nW / 2, $gH / 2 - $nW / 2, 50, 50, $hBrush3) Else _GDIPlus_GraphicsFillRect($Graph, $gW / 2 - $nW / 2, $gH / 2 - $nW / 2, 50, 50, $hBrush) _GDIPlus_GraphicsDrawRect($Graph, $gW / 2 - $nW / 2, $gH / 2 - $nW / 2, 50, 50) EndIf WEnd ; From http://www.autoitscript.com/forum/index.php?showtopic=89034&view=findpost&p=639786 ; ($xPt, $yPt) - x, y position of the point to check ; $xTL, $yTL, Top left x Pos, top left Y position of the rectangle encompassing the ellipse. ; $w, $h - The width an height of ellipse ; Method: The distance from the 1st focal point to a point on the perimeter plus the distance from ; the second focal point to the same point on the perimeter is a constant and equals the width of ; the ellipse, the major axis. So, if the sum of the two distances form the point to check to the ; two foci is greater than the major axis, then the point is outside the ellipse. Func _PointInEllipse($xPt, $yPt, $xTL, $yTL, $w, $h) Local $bInside = False, $a = $w / 2, $b = $h / 2 Local $c1X, $c2X, $dist, $xc = $xTL + $a, $yc = $yTL + $b $c1X = $xc - ($a ^ 2 - $b ^ 2) ^ (1 / 2) ; 1st focal point x position $c2X = $xc + ($a ^ 2 - $b ^ 2) ^ (1 / 2) ; 2nd focal point x position $dist = (($xPt - $c1X) ^ 2 + ($yPt - $yc) ^ 2) ^ 0.5 + (($xPt - $c2X) ^ 2 + ($yPt - $yc) ^ 2) ^ 0.5 If $dist <= $w Then $bInside = Not $bInside Return $bInside EndFunc ;==>_PointInEllipse Func _Exit() _GDIPlus_BrushDispose($hBrush) _GDIPlus_BrushDispose($hBrush2) _GDIPlus_BrushDispose($hBrush3) _GDIPlus_GraphicsDispose($Graph) _GDIPlus_Shutdown() Exit EndFunc ;==>_Exit Link to comment Share on other sites More sharing options...
Alex1986 Posted June 22, 2018 Author Share Posted June 22, 2018 @Malkey thank you very much 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