forked from Falconisilvio/TCyclometric
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTCycloMetric.prg
390 lines (280 loc) · 11.3 KB
/
TCycloMetric.prg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
#include "fivewin.ch"
// TCyclometric class for Italian Lottery
#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
/*
Copyright (c) 2022 <Falconi Silvio>
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
CLASS TCyclometric FROM TControl
CLASSDATA lRegistered AS LOGICAL
DATA nDiametro
DATA oFont,oBold
DATA apos AS ARRAY
DATA lShowNumbers AS LOGICAL init .T.
DATA nDimPenCircle,nDimPenLine
METHOD New( nTop, nLeft, nWidth, nHeight, oWnd, nDiametro) CONSTRUCTOR
METHOD Init( hDlg )
METHOD End() INLINE if( ::hWnd == 0, ::Destroy(), Super:End() )
METHOD Destroy()
METHOD Display()
METHOD Paint()
METHOD Line( nTop, nLeft, nBottom, nRight, oPen )
METHOD Say( nRow, nCol, cText, nClrFore, nClrBack, oFont, lPixel,lTransparent, nAlign )
METHOD Distance(num1,num2)
METHOD Distance_Multiple(num1,num2,num3,num4,num5)
METHOD Say_distance(num1,num2)
ENDCLASS
METHOD New( nTop, nLeft, nWidth, nHeight, oWnd, nDiametro,;
lDesign,lShowNumbers,nDimPenCircle,nDimPenLine ) CLASS TCyclometric
DEFAULT nDiametro := 200 ,;
nHeight := 200 ,;
nLeft := 10 ,;
nTop := 10 ,;
nWidth := 200 ,;
lDesign := .f. ,;
lShowNumbers := .t. ,;
nDimPenCircle := 1 ,;
nDimPenLine := 1 ,;
oWnd := GetWndDefault()
::nId := ::GetNewId()
::nTop := nTop
::nLeft := nLeft
::nBottom := nTop + nHeight - 1
::nRight := nLeft + nWidth - 1
::oWnd := oWnd
::lDrag = lDesign
::oBrush := TBrush():New(,GetSysColor(COLOR_BTNFACE) )
::apos := {}
::nDiametro = nDiametro
::oFont = TFont():New( "Tahoma", 0, -10 )
::oBold = TFont():New( "Verdana", 0, -10, , .t. )
::nStyle := nOr( WS_CHILD, WS_VISIBLE, WS_TABSTOP, WS_CLIPSIBLINGS )
::Register( nOr( CS_VREDRAW, CS_HREDRAW ) )
::lShowNumbers := lShowNumbers
::nDimPenCircle := nDimPenCircle
::nDimPenLine := nDimPenLine
if ! Empty( oWnd:hWnd )
::Create()
::Default()
::lVisible = .t.
oWnd:AddControl( Self )
else
oWnd:DefControl( Self )
::lVisible = .f.
endif
if lDesign
::CheckDots()
endif
Return self
//--------------------------------------------------------------------------------------------------------//
METHOD Init( hDlg ) CLASS TCyclometric
Super:Init( hDlg )
return nil
//--------------------------------------------------------------------------------------------------------//
METHOD Destroy() CLASS TCyclometric
if ::hWnd != 0
::Super:Destroy()
endif
return nil
//--------------------------------------------------------//
METHOD Display() CLASS TCyclometric
::BeginPaint()
::Paint()
::EndPaint()
return 0
//--------------------------------------------------------//
METHOD Paint() CLASS TCyclometric
local nI
local nRaggio := (::nDiametro/2)
local xCent := ::nLeft+nRaggio
local yCent := ::nTop+nRaggio
local aTcPen := array(4)
local nTotalNumbers := 90
local step_fi := PI() / 4.5 / 10 // add by Jimmy
local hDc:=::getDc(), nDeltaR
local nRaggioSay,nY2,nX2
aTcPen[1] := CREATEPEN( PS_SOLID, ::nDimPenCircle, darkgray )
aTcPen[2] := CREATEPEN( PS_SOLID, ::nDimPenLine, darkred )
//draw the circle
Ellipse(hDC,::nLeft,::nTop,::nLeft+::nDiametro,::nTop+ ::nDiametro,aTcPen[1])
//draw the numbers
nYOffset = ::oFont:nHeight / 2
nXOffset = ::oFont:nWidth / 2
nDeltaR := ::oFont:nHeight
FOR nI = 1 TO nTotalNumbers
nAngolo := 2* Pgreco() / nTotalNumbers * ( nI - 1 )
nY := INT( nRaggio * SIN(( ni-22.5) * step_fi ) + yCent)
nX := INT( nRaggio * COS(( ni-22.5) * step_fi ) + xCent)
// small circles
Ellipse(hDC, nX,nY ,nX-3,nY+3,aTcPen[2])
// Save the positions of numbers
aadd( ::apos , {nI,nY,nX} )
If ::lShowNumbers
nRaggioSay := (::nDiametro/2) + 10
nY2 := INT( nRaggioSay * SIN(( ni-22.5) * step_fi ) + yCent)
nX2 := INT( nRaggioSay * COS(( ni-22.5) * step_fi ) + xCent)
::Say( nY2 - nYOffset, nX2 - 0, hb_ntoc( nI,0 ),CLR_RED , , ::oFont, .t.,.t., TA_CENTER )
Endif
//Say( nRow, nCol, cText, nClrFore, nClrBack, oFont, lPixel, lTransparent, nAlign )
NEXT
::ReleaseDC()
return nil
//--------------------------------------------------------------//
STAT FUNC Pgreco(); RETURN (3.1415926536)
//--------------------------------------------------------------//
METHOD Line( nTop, nLeft, nBottom, nRight, nColor,nspessore ) CLASS TCyclometric
* local hPen := if( oPen = nil, 0, oPen:hPen )
local oPen := CreatePen(PS_SOLID, nspessore, 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( nRow, nCol, cText, nClrFore, nClrBack, oFont, lPixel,;
lTransparent, nAlign ) CLASS TCyclometric
DEFAULT nClrFore := ::nClrText,;
nClrBack := ::nClrPane,;
oFont := ::oFont,;
lPixel := .f.,;
lTransparent := .f.
if ValType( nClrFore ) == "C" // xBase Color string
nClrBack = nClrFore
nClrFore = nGetForeRGB( nClrFore )
nClrBack = nGetBackRGB( nClrBack )
endif
::GetDC()
DEFAULT nAlign := GetTextAlign( ::hDC )
WSay( ::hWnd, ::hDC, nRow, nCol, cValToChar( cText ), nClrFore, nClrBack,;
If( oFont != nil, oFont:hFont, 0 ), lPixel, lTransparent, nAlign )
::ReleaseDC()
return nil
//--------------------------------------------------------------//
METHOD Distance(num1,num2) CLASS TCyclometric
local aNumpos := ::apos
local nAt1,nAt2
local oPen,hOldPen
local aRect:= {}
local nDistanza,nYOffset,nXOffset, nY,nX
// xbrowser aNumpos
nAt1:= AScan( aNumpos, { | a | a[1] = num1 } )
nAt2:= AScan( aNumpos, { | a | a[1] = num2 } )
aRect:= {aNumpos[nAt1][2],aNumpos[nAt1][3],aNumpos[nAt2][2],aNumpos[nAt2][3]}
::line( aRect[1],aRect[2],aRect[3],aRect[4], CLR_RED)
// draw the distance number
IF num2>num1
nDistanza:= num2-num1
else
nDistanza:= num1-num2
Endif
If nDistanza > 45
nDistanza:= 90-nDistanza
Endif
nYOffset = ::oFont:nHeight / 2
nXOffset = ::oFont:nWidth / 2
nY := aRect[2]
nX := aRect[4]
::Say( nY - nYOffset, nX - nXOffset, LTRIM( STRzero( nDistanza,2 ) ), , , ::oFont, .t.,;
.t., nil )
return nil
//--------------------------------------------------------------//
METHOD Distance_Multiple(num1,num2,num3,num4,num5,nColor) CLASS TCyclometric
local aNumpos := ::apos
local nAt1,nAt2,nAt3,nAt4,nAt5
local oPen,hOldPen
local aRect:= {}
local nDistanza,nYOffset,nXOffset, nY,nX
local nRaggio := (::nDiametro/2)
local xCent := ::nLeft+nRaggio
local yCent := ::nTop+nRaggio
local aPoints := array(5)
local aGrad := { | lInvert | If( lInvert, ;
{ { 1/3, nColor, nColor }, ;
{ 2/3, nColor, nColor } ;
}, ;
{ { 1/2, nColor, nColor }, ;
{ 1/2, nColor, nColor } ;
} ) }
* xbrowser aNumpos
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]}
::line( aPoints [1][1],aPoints [1][2],aPoints [2][1],aPoints [2][2], nColor,::nDimPenLine)
::Say_distance(num1,num2)
::line( aPoints [2][1],aPoints [2][2],aPoints [3][1],aPoints [3][2], nColor,::nDimPenLine)
::Say_distance(num2,num3)
::line( aPoints [3][1],aPoints [3][2],aPoints [4][1],aPoints [4][2], nColor,::nDimPenLine)
::Say_distance(num3,num4)
::line( aPoints [4][1],aPoints [4][2],aPoints [5][1],aPoints [5][2], nColor,::nDimPenLine)
::Say_distance(num4,num5)
::line( aPoints [5][1],aPoints [5][2],aPoints [1][1],aPoints [1][2], nColor,::nDimPenLine)
::Say_distance(num5,num1)
FillRectEx( ::hDC, aPoints, aGrad)
::ReleaseDC()
return nil
//-----------------------------------------------------------------------//
METHOD Say_distance(num1,num2) CLASS TCyclometric
local nDistanza:= 0
local nAt1,nAt2
local aNumpos := ::apos
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 ) ),darkorange , , ::oFont, .t.,.t., nil )
return Nil