Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile Exe
#Dim All
%Unicode = 1
#Include "Win32API.inc"
Enum Equates Singular
IDC_Graphic
End Enum
Global hDlg As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Click Anywhere!",1300,300,300,220, %WS_OverlappedWindow To hDlg
Control Add Graphic, hDlg, %IDC_Graphic,"", 0,0,300,220, %SS_Notify
Graphic Attach hDlg, %IDC_Graphic
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local pt As Point, xCenter, yCenter, iResult As Single
Static rc As Rect
Select Case Cb.Msg
Case %WM_InitDialog
rc.Left = 23 : rc.Right = 270
rc.Top = 40 : rc.Bottom = 180
Graphic Ellipse (rc.Left,rc.Top)-(rc.Right,rc.Bottom),%Black
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Graphic
GetCursorPos(pt)
ScreenToClient(hDlg,pt)
Graphic Clear
iResult = PtInEllipse(rc,pt)
Dialog Set Text hDlg, IIf$(iResult > -1, "In ","Out ") + Format$(Abs(iResult), "##0.00") + " radians " + Format$(Abs(iResult*57.296) ,"##0.00") + " degrees"
xCenter = rc.nLeft + (rc.Right - rc.nLeft ) / 2
yCenter = rc.nTop + (rc.nBottom - rc.nTop ) / 2
Graphic Ellipse (rc.Left,rc.Top)-(rc.Right,rc.Bottom),%Black 'ellipse
Graphic Ellipse (xCenter-2,yCenter-2)-(xCenter+2,yCenter+2),%Red 'center of ellipse
Graphic Line (xCenter, yCenter)-(pt.x,pt.y), %Blue 'line to point clicked
End Select
End Select
End Function
Function PtInEllipse(rc As Rect, pt As Point) As Single 'angle 0-2pi radians. if point outside ellipse, angle is negative
Local xCenter, yCenter, radiusX,radiusY As Long, radians,iResult As Single
radiusX = (rc.Right - rc.nLeft ) / 2 : xCenter = rc.nLeft + radiusX
radiusY = (rc.nBottom - rc.nTop ) / 2 : yCenter = rc.nTop + radiusY
radians = Atn( (pt.y-yCenter) / (pt.x-xCenter) )
iResult = 6.28318 - (radians + Switch(pt.x < xCenter, 3.14159, pt.y < yCenter, 6.28318))
If ((pt.x - xCenter) ^ 2) / (radiusX^2) + ((pt.y - yCenter) ^2 ) / (radiusY^2) >= 1 Then Function = -iResult Else Function = iResult
End Function
http://www.garybeene.com/sw/gbsnippets.htm