create a circle colored in a dialog
Posted: Mon Dec 09, 2024 11:46 am
I wish create a circle colored into a dialog ... why I not see the ellipse ?
Notice
each color is created in the circle as if in triangles
Problem the circle is black
not load colors
Notice
each color is created in the circle as if in triangles
Problem the circle is black
not load colors
Code: Select all | Expand
#include "FiveWin.ch"
#define PI 3.14159265359
FUNCTION Main()
LOCAL oDlg
LOCAL nHeight := 200, nWidth := 200
local oCircle
DEFINE DIALOG oDlg SIZE 400, 400 PIXEL TITLE "Cerchio Colorato"
oCircle:= MyCircle():NEW(1, 1, oDlg, nWidth, nHeight, CLR_BLACK, CLR_BLACK,;
.t., .f.,.t.)
ACTIVATE DIALOG oDlg CENTER
RETURN NIL
Class MyCircle From Tcontrol
CLASSDATA lRegistered AS LOGICAL
DATA nColorCirc
DATA nColorText
DATA lDrawBorder
DATA hPen
DATA nDimPenCircle
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()
ENDCLASS
METHOD New( nRow, nCol, oWnd, nWidth, nHeight, nColorCirc, nColorText,;
lPixel, lDesign,lDrawBorder) CLASS MyCircle
DEFAULT nRow := 0, nCol := 0, oWnd := GetWndDefault()
DEFAULT lPixel := .f.
DEFAULT nColorCirc := CLR_HGRAY
DEFAULT nWidth := 50, nHeight := 50
DEFAULT lDrawBorder := .F.
::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
::hPen = CreatePen( PS_SOLID, 1, nRGB( 128, 128, 128 ) )
::nId = ::GetNewId()
::nColorCirc = nColorCirc
::nColorText = nColorText
::nClrPane = nRGB( 220, 223, 228 )
::nDimPenCircle := 1
::lDrag = lDesign
::lCaptured = .f.
::lTransparent =.t.
::nStyle = nOr( WS_CHILD, WS_VISIBLE, WS_CLIPCHILDREN, WS_TABSTOP,;
if( lDrawBorder, WS_BORDER, 0 ) )
::Register()
if oWnd:lVisible
::Create()
::Default()
::lVisible = .t.
oWnd:AddControl( Self )
else
oWnd:DefControl( Self )
::lVisible = .F.
endif
if lDesign
::CheckDots()
endif
return Self
METHOD Paint() CLASS MyCircle
local aInfo, aRect
local hGrayPen,hOldPen,hWhitePen
Local hBrush, hOldBrush
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()
if ValType( ::bPainted ) == "B"
Eval( ::bPainted, ::hDC, ::cPS, Self )
endif
::DispEnd( aInfo )
return nil
METHOD PaintCircle() CLASS MyCircle
local aRect := GetClientRect( ::hWnd )
local aColors := { CLR_BLACK,CLR_WHITE,CLR_RED,CLR_BLUE,;
CLR_YELLOW,CLR_HGRAY,CLR_HRED,CLR_CYAN,CLR_GREEN,CLR_MAGENTA}
LOCAL nCenterX
LOCAL nCenterY
LOCAL nRadius
LOCAL nStep := 360 / Len(aColors) // Dimensione angolare di ogni spicchio
LOCAL i, nStartAngle := 0
LOCAL oPen, hBrush
::nTopCir := ::nHeight / 2
::nLeftCir := ::nWidth / 2
::nMedWidth := aRect[4]/2
::nMedHeight := aRect[3]/2
::nMedSide := min( ::nMedWidth, (::nMedHeight-5) ) - 10
nCenterX := ::nTopCir
nCenterY := ::nLeftCir
nRadius := ::nMedSide
FOR i := 1 TO Len(aColors)
DrawPie(::hDC, nCenterX, nCenterY, nRadius, nStartAngle, nStartAngle + nStep, aColors[i])
nStartAngle += nStep
DeleteObject(hBrush)
DeleteObject(oPen)
NEXT
return 0
STATIC FUNCTION DrawPie(hDC, nCenterX, nCenterY, nRadius, nStartAngle, nEndAngle, nclr)
LOCAL xStart, yStart, xEnd, yEnd
xStart := nCenterX - nRadius
yStart := nCenterY - nRadius
xEnd := nCenterX + nRadius
yEnd := nCenterY + nRadius
FW_Box( hDC, {xStart,yStart,xEnd, yEnd }, { nClr, 3 }, nClr, , 2 )
RETURN NIL