[phpBB Debug] PHP Warning: in file [ROOT]/viewtopic.php on line 1745: Undefined array key 0
[phpBB Debug] PHP Warning: in file [ROOT]/viewtopic.php on line 1745: Undefined array key 1
[phpBB Debug] PHP Warning: in file [ROOT]/viewtopic.php on line 1745: Undefined array key 2
[phpBB Debug] PHP Warning: in file [ROOT]/viewtopic.php on line 1745: Undefined array key 3
[phpBB Debug] PHP Warning: in file [ROOT]/viewtopic.php on line 1745: Undefined array key 4
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4191: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3076)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4191: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3076)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4191: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3076)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4191: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3076)
FiveTech Software tech support forums • cyclometric circle - Page 3
Page 3 of 4

Re: cyclometric circle

Posted: Fri Dec 02, 2022 11:12 am
by Silvio.Falconi
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


Image


But now I have problems with the small circles and the numbers because they are attached and I don't understand why

Image

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

Image


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
//------------------------------------------------------------------------//







 
with circles and numbers together

Image

Re: cyclometric circle

Posted: Fri Dec 02, 2022 11:37 am
by Silvio.Falconi
Now I correct the position of numbers but there is also some errors


Image

Code: Select all | Expand

METHOD PaintNumbers() Class TCyclometric
   local nI
   local  oPen := CREATEPEN( PS_SOLID, 1, CLR_BLUE )
   local  nTotalNumbers := 90


  local  nYOffset := ::oFont:nHeight / 2
  local  nXOffset := ::oFont:nWidth / 2
  local  nDeltaR  := ::oFont:nHeight

  local nColor
  local nAngolo


    ::nRadiusExt := int( ::nMedSide ) * 0.98
    ::nRadiusInt := ::nRadiusExt      * 0.98

     //draw numbers and circles
    FOR nI = 1 TO  nTotalNumbers
          nAngolo := 2* PI() / nTotalNumbers * ( nI - 1 )
          nTop  := ::nTopCir  -  ( ::nRadiusInt * Cos( nAngolo  ) )
          nLeft := ::nLeftCir +  ( ::nRadiusInt * Sin( nAngolo  ) )


         * 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
//------------------------------------------------------------------------//
the numbers must be outside the circumference


While the small circles seems run ok and right position

Image

Re: cyclometric circle

Posted: Fri Dec 02, 2022 12:10 pm
by Silvio.Falconi
Perhaps I resolve but there is a small error


Image


Now the small circles are right and in their place and also the numbers only in the lower part touch the edge of the object
the numbers seem crooked to me i.e. there is no axis 90-> 45 the numbers are slightly off , How I can resolve ?

New code

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()
METHOD PaintSmallCircles()
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  nColorText   := CLR_BLUE

    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 "TAHOMA" SIZE 0, -10
   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
   ::PaintSmallCircles()  //small circles
   ::PaintNumbers()  //draw the numbers

   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 PaintSmallCircles() Class TCyclometric
   local nI
   local  oPen := CREATEPEN( PS_SOLID, 1, CLR_BLUE )
   local  nTotalNumbers := 90


  local  nYOffset := ::oFont:nHeight / 2
  local  nXOffset := ::oFont:nWidth / 2
  local  nDeltaR  := ::oFont:nHeight


  local nAngolo


    ::nRadiusExt := int( ::nMedSide ) * 0.98
    ::nRadiusInt := ::nRadiusExt      * 0.98

     //draw circles
    FOR nI = 1 TO  nTotalNumbers
          nAngolo := 2* PI() / nTotalNumbers * ( nI - 1 )
          nTop  := ::nTopCir  -  ( ::nRadiusInt * Cos( nAngolo  ) )
          nLeft := ::nLeftCir +  ( ::nRadiusInt * Sin( nAngolo  ) )


          Ellipse(::hDC, nLeft - 5, nTop  - 5, nLeft+ 5, nTop  + 5    )


       NEXT
 return 0
//------------------------------------------------------------------------//

 METHOD PaintNumbers() Class TCyclometric
   local nI
   local  oPen := CREATEPEN( PS_SOLID, 1, CLR_BLUE )
   local  nTotalNumbers := 90


  local  nYOffset := ::oFont:nHeight / 2
  local  nXOffset := ::oFont:nWidth / 2
  local  nDeltaR  := ::oFont:nHeight

  local nColor
  local nAngolo
  local nMedSidetxt   := min( ::nMedWidth, ::nMedHeight )
  
    ::nRadiusExt := int( nMedSidetxt ) * 0.98


     //draw numbers and circles
    FOR nI = 1 TO  nTotalNumbers
          nAngolo := 2* PI() / nTotalNumbers * ( nI - 1 )
           nTop  := ::nTopCir  -  ( ::nRadiusExt * Cos( nAngolo  ) )
           nLeft := ::nLeftCir +  ( ::nRadiusExt * Sin( nAngolo  ) )

        ::Say( ntop - nYOffset  , nLeft  , hb_ntoc( nI,0 ),::nColorText , , ::oFont, .t.,.t., TA_CENTER )

       NEXT
 return 0
//------------------------------------------------------------------------//

 


as you can see here

Image

the number 90 is not in the center and consequently the number 45 is displaced

i don't know how to solve

Re: cyclometric circle

Posted: Fri Dec 02, 2022 1:11 pm
by Silvio.Falconi
* correct the numbers text on the bottom

* when drawing the geometric shape corresponding to the xbrowse line, the lines are wrong because they don't point to the real xbrowse values

Image


New code

Code: Select all | Expand

#include "fivewin.ch"
#include "constant.ch"


Function Test()

      local oDlg,oFont,oBold
      local oBtnClose
      local nBottom   := 38
      local nRight    := 99
      local nWidth    := Max( nRight * DLG_CHARPIX_W, 180 )
      local nHeight   := nBottom * DLG_CHARPIX_H
      local cUrl:="http://www.televideo.rai.it/televideo/pub/solotesto.jsp?pagina=786"
      local adata:=TestUrl( cUrl )
      local oBrw
      local oCicloMetric

      local aColors:= {CLR_BLUE,;
                      CLR_GREEN,;
                      CLR_RED,;
                      CLR_MAGENTA,;
                      CLR_BROWN,;
                      CLR_HGRAY,;
                      CLR_LIGHTGRAY,;
                      CLR_HBLUE,;
                      CLR_HMAGENTA,;
                      METRO_VIOLET ,;
                      METRO_BROWN}

   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( 8, 1, oDlg,  500, 500, CLR_HGRAY)


       @ 200,600 XBROWSE oBrw OF oDlg SIZE 300,250 PIXEL NOBORDER;
      COLS 1,2,3,4,5,6;
      HEADERS "Ruota", "E1", "E2", "E3", "E4", "E5" ;
      SIZES  80,30,30,30,30,30  ;
      ARRAY adata ;
      CELL LINES

    WITH OBJECT oBrw
      :nRowHeight    := 20
      :nClrBorder := CLR_GRAY
      :lDrawBorder := .t.
      :nColorBox := CLR_HRED

      :lHeader             := .f.
      :lHscroll            := .f.
      :lvscroll            := .f.
      :l2007               := .F.
      :l2015               := .t.

      :nStretchCol         := STRETCHCOL_WIDEST
      :lAllowRowSizing     := .F.
      :lAllowColSwapping   := .F.
      :lAllowColHiding     := .F.
      :lRecordSelector     := .F.
      :nColDividerStyle    := LINESTYLE_LIGHTGRAY
      :nRowDividerStyle    := LINESTYLE_LIGHTGRAY
      :bClrStd := { || { CLR_BLACK, If( oBrw:KeyNo % 2 == 0, nRgb(173,216,230) , CLR_WHITE ) } }

      :bChange  := { ||Showform(oBrw:nArrayAt,oCicloMetric,aColors,oBrw) }

      :CreateFromCode()
   End




     @ 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
//----------------------------------------------------------------------//

 Function TestUrl( cUrl )
        local cRet:=""
        local cData:=""
        local cFile := "test.txt"
        local cBuff
        local nHndl
        local aShow:={}
        local nI

        IF IsInternet()
               cRet := WebPageContents( cUrl )
               cData := WebPageContents( cUrl )
        if Empty( cRet )
          ? "Invalid URL"
       else
            //per la data estrazione
            cData := subStr( cData, at( "ALMANACCO",  cData )+9 )
            cData := allTrim( subStr( cData, 1, at("BARI",  cData ) -1 ) )

            // per il blocco Bari - Nazionale
            cRet := subStr( cRet, at( "BARI", cRet ) )
            cRet := allTrim( subStr( cRet, 1, at( "Controlla", cRet ) - 1 ) )

            nHndl := fCreate( cFile )
            fWrite( nHndl, cRet )
            fClose( nHndl )
            IF ( nHndl := fOpen( cFile ) ) < 1
                msgStop( "UNABLE TO OPEN: " + cFile  )
            ELSE
                aShow := {}
                WHILE hb_fReadLine( nHndl, @cBuff, chr( 10 ) ) == 0
                    cBuff := allTrim( cBuff )
                    IF ! empty( cBuff )
                        aAdd( aShow, {} )
                        aAdd( aTail( aShow ), subStr( cBuff, 1, 11 ) )
                        FOR nI := 12 TO 28 STEP 4
                            aAdd( aTail( aShow ), subStr( cBuff, nI, 2 ) )
                        NEXT
                    ENDIF
                ENDDO
                * xBrowse( aShow )
                ferase(cfile)
                return aShow
            ENDIF
         endif
      else
         MsgAlert("Controlla la connessione su internet!","EasyLotto")
          endif
          return nil
//----------------------------------------------------------------------//

 Function Showform(nRecord,oCiclo,aColors,oBrw)
   local aNumeri:= {}
   local atemp:= {}
   local cText
   local num1,num2,num3,num4,num5


   nColor:=aColors[ nRecord ]

   AAdd(atemp,oBrw:aArrayData[ nRecord ] )

   cText:=atemp[1][1]  //text
   num1 :=atemp[1][2]
   num2 :=atemp[1][3]
   num3 :=atemp[1][4]
   num4 :=atemp[1][5]
   num5 :=atemp[1][6]

    aNumeri := {num1,num2,num3,num4,num5}

   ASort( aNumeri, nil, nil, { |x,y| x < y } )

   num1 :=aNumeri[1]
   num2 :=aNumeri[2]
   num3 :=aNumeri[3]
   num4 :=aNumeri[4]
   num5 :=aNumeri[5]

 *  oCiclo:Paint()
   oCiclo:Distance_Multiple(val(num1),val(num2),val(num3),val(num4),val(num5),nColor,oCiclo:aposition)

   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

    DATA aPosition


METHOD New( nRow, nCol, oWnd,  nWidth, nHeight) CONSTRUCTOR
METHOD Paint()
METHOD Display() INLINE ::BeginPaint(), ::Paint(), ::EndPaint(), 0
METHOD PaintCircle()
METHOD PaintNumbers()
METHOD PaintSmallCircles()
METHOD Distance_Multiple(num1,num2,num3,num4,num5,nColor)
METHOD Say_distance(num1,num2)
METHOD Line( nTop, nLeft, nBottom, nRight, nColor, nDim )
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  nColorText   := CLR_BLUE

    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.
   ::aPosition := {}


    if oFont == nil
      DEFINE FONT ::oFont NAME "TAHOMA" SIZE 0, -10
   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
   ::PaintSmallCircles()  //small circles
   ::PaintNumbers()  //draw the numbers

   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-5) ) - 10

      ellipse( ::hDC, ::nLeftCir - ::nMedSide,;
                      ::nTopCir  - ::nMedSide,;
                      ::nLeftCir + ::nMedSide,;
                      ::nTopCir  + ::nMedSide,oPen )


return 0
//------------------------------------------------------------------------//
METHOD PaintSmallCircles() Class TCyclometric
   local nI
   local  oPen := CREATEPEN( PS_SOLID, 1, CLR_BLUE )
   local  nTotalNumbers := 90


  local  nYOffset := ::oFont:nHeight / 2
  local  nXOffset := ::oFont:nWidth / 2
  local  nDeltaR  := ::oFont:nHeight


  local nAngolo


    ::nRadiusExt := int( ::nMedSide ) * 0.99
    ::nRadiusInt := ::nRadiusExt      * 0.99

     //draw circles
  /*  FOR nI = 1 TO  nTotalNumbers
          nAngolo := 2* PI() / nTotalNumbers * ( nI - 1 )
          nTop  := ::nTopCir  -  ( ::nRadiusInt * Cos( nAngolo  ) )
          nLeft := ::nLeftCir +  ( ::nRadiusInt * Sin( nAngolo  ) )

          Ellipse(::hDC, nLeft - 5, nTop  - 5, nLeft+ 5, nTop  + 5    )

          //positions
          AaDd(::aPosition,{nI,nLeft,nTop} )

       NEXT
     */

    FOR nI = 1 TO  nTotalNumbers
          nAngolo := 2* PI() / nTotalNumbers * ( nI - 1 )
          nTop  := ::nTopCir  -  ( ::nRadiusExt * Cos( nAngolo  ) )
          nLeft := ::nLeftCir +  ( ::nRadiusExt * Sin( nAngolo  ) )

          Ellipse(::hDC, nLeft-2  , nTop-2  , nLeft+2, nTop+2      )

          //positions
          AaDd(::aPosition,{nI,nLeft,nTop} )

       NEXT

 return 0
//------------------------------------------------------------------------//

 METHOD PaintNumbers() Class TCyclometric
   local nI
   local  oPen := CREATEPEN( PS_SOLID, 1, CLR_BLUE )
   local  nTotalNumbers := 90


  local  nYOffset := ::oFont:nHeight / 2
  local  nXOffset := ::oFont:nWidth / 2
  local  nDeltaR  := ::oFont:nHeight

  local nColor
  local nAngolo
  local nMedSidetxt   := min( ::nMedWidth, ::nMedHeight ) -5

    ::nRadiusExt := int( nMedSidetxt ) * 0.98


     //draw numbers
    FOR nI = 1 TO  nTotalNumbers
          nAngolo := 2* PI() / nTotalNumbers * ( nI - 1 )
           nTop  := ::nTopCir  -  ( ::nRadiusExt * Cos( nAngolo  ) )
           nLeft := ::nLeftCir +  ( ::nRadiusExt * Sin( nAngolo  ) )

        ::Say( ntop - nYOffset  , nLeft  , hb_ntoc( nI,0 ),::nColorText , , ::oFont, .t.,.t., TA_CENTER )

       NEXT
 return 0
//------------------------------------------------------------------------//

METHOD Distance_Multiple(num1,num2,num3,num4,num5,nColor)  CLASS  TCyclometric
   local  aNumpos := ::aposition
   local nAt1,nAt2,nAt3,nAt4,nAt5
   local oPen,hOldPen




   local aPoints   := array(5)
   local hBrush1,hOld1
   local nDimPenLine:=1



   nAt1:= AScan( aNumpos, { | a | a[1] = num1 } )
   nAt2:= AScan( aNumpos, { | a | a[1] = num2 } )
   nAt3:= AScan( aNumpos, { | a | a[1] = num3 } )
   nAt4:= AScan( aNumpos, { | a | a[1] = num4 } )
   nAt5:= AScan( aNumpos, { | a | a[1] = num5 } )


     aPoints [5]  := {aNumpos[nAt5][2], aNumpos[nAt5][3]}
     aPoints [4]  := {aNumpos[nAt4][2], aNumpos[nAt4][3]}
     aPoints [3]  := {aNumpos[nAt3][2], aNumpos[nAt3][3]}
     aPoints [2]  := {aNumpos[nAt2][2], aNumpos[nAt2][3]}
     aPoints [1]  := {aNumpos[nAt1][2], aNumpos[nAt1][3]}



     //Intern distance
     ::line( aPoints [1][1],aPoints [1][2],aPoints [2][1],aPoints [2][2], nColor,nDimPenLine)
     ::line( aPoints [2][1],aPoints [2][2],aPoints [3][1],aPoints [3][2], nColor,nDimPenLine)
     ::line( aPoints [3][1],aPoints [3][2],aPoints [4][1],aPoints [4][2], nColor,nDimPenLine)
     ::line( aPoints [4][1],aPoints [4][2],aPoints [5][1],aPoints [5][2], nColor,nDimPenLine)
     ::line( aPoints [5][1],aPoints [5][2],aPoints [1][1],aPoints [1][2], nColor,nDimPenLine)




     //Intern distance

    *   IF ::lShowDistance
         ::Say_distance(num1,num2)
         ::Say_distance(num2,num3)
         ::Say_distance(num3,num4)
         ::Say_distance(num4,num5)
         ::Say_distance(num5,num1)
     *  Endif




     return nil

//----------------------------------------------------------------------------//
     METHOD Line( nTop, nLeft, nBottom, nRight, nColor, nDim ) CLASS  TCyclometric

 *  local hPen := if( oPen = nil, 0, oPen:hPen )

 local  oPen := CreatePen(PS_SOLID, nDim, nColor  )

  *local  oPen := CreatePen(PS_DOT, nDim, nColor  )
 local   hOldPen

   ::GetDC()
   hOldPen := SelectObject( ::hDC, oPen )
   MoveTo( ::hDC, nLeft, nTop )
   LineTo( ::hDC, nRight, nBottom, oPen )
   SelectObject( ::hDC, hOldPen )
   ::ReleaseDC()

   return nil

//------------------------------------------------------------------------------//
    METHOD Say_distance(num1,num2) CLASS  TCyclometric
  local nDistanza:= 0
   local nAt1,nAt2
   local  aNumpos := ::aposition
   local aRect:= {}
   local nYOffset,nXOffset, nY,nX

   //calc the distance
    IF num2>num1
             nDistanza:= num2-num1
          else
             nDistanza:= num1-num2
          Endif
          If nDistanza > 45
            nDistanza:= 90-nDistanza
         Endif

  // Print the distance
       nYOffset = ::oFont:nHeight / 2
       nXOffset = ::oFont:nWidth / 2


   nAt1:= AScan( aNumpos, { | a | a[1] = num1 } )
   nAt2:= AScan( aNumpos, { | a | a[1] = num2 } )



   IF aNumpos[nAt1][3] > aNumpos[nAt2][3]
      nX := aNumpos[nAt2][3] + ( aNumpos[nAt1][3] - aNumpos[nAt2][3] ) /2
   ELSE
      nX := aNumpos[nAt1][3] + ( aNumpos[nAt2][3] - aNumpos[nAt1][3] ) /2
   ENDIF

   IF aNumpos[nAt1][2] > aNumpos[nAt2][2]
      nY := aNumpos[nAt2][2] + ( aNumpos[nAt1][2] - aNumpos[nAt2][2] ) /2
   ELSE
      nY := aNumpos[nAt1][2] + ( aNumpos[nAt2][2] - aNumpos[nAt1][2] ) /2
   ENDIF

   ::Say( nY - nYOffset, nX - 0, LTRIM( STRzero( nDistanza,2 ) ),CLR_BLACK , , ::oFont, .t.,.t., nil )

return Nil

 //------------------------------------------------------------------------//








 

Re: cyclometric circle

Posted: Sat Dec 03, 2022 3:59 pm
by Silvio.Falconi
Antonio,
I tried also with

::bPainted := { |hDC|FillRectEx( ::hDC, aPoints, aGrad) }

or

::bPainted := { |hDC|FloodFill( ::hDC, aPoints [1][1], aPoints [5][1], nil, nColor ) }

or

local hBru := CreateSolidBrush( nColor )
local hOld := SelectObject( ::hDC, hBru )
local hpen:=CreatePen(0,8,nColor)

FillRect( ::hDC, { aPoints [1][1],aPoints [1][2],aPoints [2][1],aPoints [2][2] }, hBru )

SelectObject( ::hDC, hOld )
DeleteObject( hBru )


Not Happen nothing