Re: cyclometric circle
Posted: Fri Dec 02, 2022 11:12 am
I tried to improve the class because the object is not centered now the circle is inside the object
practically creating the circumference I halved the measures as you can see in this picture
But now I have problems with the small circles and the numbers because they are attached and I don't understand why
numbers must be 1 to 90 and the number 1 must be located in the top center, the number 45 in the bottom center
even the circles are not all attached and instead should be drawn one behind the other, the position is bad
is there someone can help me please ?
the test with new class
with circles and numbers together
practically creating the circumference I halved the measures as you can see in this picture
But now I have problems with the small circles and the numbers because they are attached and I don't understand why
numbers must be 1 to 90 and the number 1 must be located in the top center, the number 45 in the bottom center
even the circles are not all attached and instead should be drawn one behind the other, the position is bad
is there someone can help me please ?
the test with new class
Code: Select all | Expand
#include "fivewin.ch"
#include "constant.ch"
Function Test()
local oDlg,oFont,oBold
local oBtnClose
local nBottom := 24
local nRight := 55
local nWidth := Max( nRight * DLG_CHARPIX_W, 180 )
local nHeight := nBottom * DLG_CHARPIX_H
local oCicloMetric
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-10
DEFINE FONT oBold NAME "TAHOMA" SIZE 0,-12 BOLD
DEFINE DIALOG oDlg SIZE nWidth, nHeight ;
PIXEL TRUEPIXEL FONT oFont ; //RESIZABLE
TiTle "Manage Ciclometric"
oCicloMetric:= TCyclometric():New( 1, 1, oDlg, 400, 300, CLR_HGRAY)
@ 100,10 BUTTON oBtnClose PROMPT "Close" of oDlg SIZE 80,22 ACTION oDlg:End()
oDlg:bResized := <||
local oRect := oDlg:GetCliRect()
oBtnClose:nLeft := oRect:nRight - 100
oBtnClose:nTop := oRect:nBottom - 45
RETURN NIL
>
ACTIVATE DIALOG oDlg CENTERED;
ON INIT ( Eval(oDlg:bResized))
RELEASE FONT oFont, oBold
Return nil
//------------------------------------------------------------------//
#define darkgray nRgb(169,169,169)
#define darkorange nRgb(255,140,0)
#define darkred nRgb(139,0,0)
#define lightblue nRgb(173,216,230)
#define TA_CENTER 6
#define COLOR_BTNFACE 15
#define PS_SOLID 0
Class TCyclometric From Tcontrol
CLASSDATA lRegistered AS LOGICAL
DATA nColorCirc
DATA nColorText
DATA oFont
DATA lShowSmallCircles
DATA lDrawBorder
DATA nMedWidth,nMedHeight,nMedSide
DATA nTopCir,nLeftCir
DATA nRadiusExt
DATA nRadiusInt
METHOD New( nRow, nCol, oWnd, nWidth, nHeight) CONSTRUCTOR
METHOD Paint()
METHOD Display() INLINE ::BeginPaint(), ::Paint(), ::EndPaint(), 0
METHOD PaintCircle()
METHOD PaintNumbers()
ENDCLASS
//-----------------------------------------------------------------------//
METHOD New( nRow, nCol, oWnd, nWidth, nHeight, nColorCirc,oFont,nColorText,;
lPixel, lDesign,lShowSMallCircles,lDrawBorder) Class TCyclometric
DEFAULT nRow := 0, nCol := 0, oWnd := GetWndDefault()
DEFAULT lPixel := .f.
DEFAULT nColorCirc := CLR_HGRAY
DEFAULT nWidth := 50, nHeight := 50,;
lDesign := .f.
DEFAULT lShowSMallCircles := .t.
DEFAULT lDrawBorder := .t. //test
::nTop = If( lPixel, nRow, nRow * MTR_CHARPIX_H ) //14
::nLeft = If( lPixel, nCol, nCol * MTR_CHARPIX_W ) //8
::nBottom = ::nTop + nHeight
::nRight = ::nLeft + nWidth
::oWnd = oWnd
::lDrawBorder = lDrawBorder
::nId = ::GetNewId()
::nColorCirc = nColorCirc
::lShowSMallCircles := lShowSMallCircles
::lDrag = lDesign
::lCaptured = .f.
::ltransparent =.t.
if oFont == nil
DEFINE FONT ::oFont NAME "Verdana" SIZE 0, -10 BOLD
else
::SetFont( oFont )
endif
::nColorText = nColorText
::nStyle = nOr( WS_CHILD, WS_VISIBLE, WS_CLIPCHILDREN, WS_TABSTOP,;
if( lDrawBorder, WS_BORDER, 0 ) )
::Register()
if ! Empty( ::oWnd:hWnd )
::Create()
::Default()
::oWnd:AddControl( Self )
if ::oWnd:oBrush != nil
::SetBrush( ::oWnd:oBrush )
endif
else
::oWnd:DefControl( Self )
endif
if lDesign
::CheckDots()
endif
return Self
//------------------------------------------------------------//
METHOD Paint() Class TCyclometric
local aInfo, aRect
aInfo := ::DispBegin()
if ::lTransparent .or. ::nOpacity < 255
aRect := GetClientRect( ::hWnd )
SetBrushOrgEx( ::hDC, -::nLeft, -::nTop )
FillRect( ::hDC, aRect, ::oWnd:oBrush:hBrush )
if ! ::lTransparent
FillRectEx( ::hDC, aRect, nARGB( ::nOpacity, ::nClrPane ) )
endif
else
::PaintBack( ::hDC )
endif
::PaintCircle() //draw the main circle
::PaintNumbers() //draw the numbers and small circles
if ValType( ::bPainted ) == "B"
Eval( ::bPainted, ::hDC, ::cPS, Self )
endif
::DispEnd( aInfo )
return nil
//------------------------------------------------------------------------//
METHOD PaintCircle() Class TCyclometric
local aRect := GetClientRect( ::hWnd )
local oPen := CREATEPEN( PS_SOLID, 2, darkgray )
::nTopCir := ::nHeight / 2
::nLeftCir := ::nWidth / 2
::nMedWidth := aRect[4]/2
::nMedHeight := aRect[3]/2
::nMedSide := min( ::nMedWidth, ::nMedHeight ) - 10
ellipse( ::hDC, ::nLeftCir - ::nMedSide,;
::nTopCir - ::nMedSide,;
::nLeftCir + ::nMedSide,;
::nTopCir + ::nMedSide,oPen )
return 0
//------------------------------------------------------------------------//
METHOD PaintNumbers() Class TCyclometric
local nI
local oPen := CREATEPEN( PS_SOLID, 1, CLR_BLUE )
local nTotalNumbers := 90
local step_fi := PI() / 4.5 / 10
local aRect := GetClientRect( ::hWnd )
local nYOffset := ::oFont:nHeight / 2
local nXOffset := ::oFont:nWidth / 2
local nDeltaR := ::oFont:nHeight
local nColor
::nRadiusExt := int( ::nMedSide ) * 0.98
::nRadiusInt := ::nRadiusExt * 0.98
//draw numbers and circles
FOR nI = 1 TO nTotalNumbers
nTop := ::nTopCir - ( ::nRadiusInt * Cos( nI ) )
nLeft := ::nLeftCir + ( ::nRadiusInt * Sin( nI ) )
Ellipse(::hDC, nLeft - 5, nTop - 5, nLeft+ 5, nTop + 5 )
::Say( nTop , nLeft , hb_ntoc( nI,0 ),CLR_RED , , ::oFont, .t.,.t., TA_CENTER )
NEXT
return 0
//------------------------------------------------------------------------//