gadgets.pas 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. { $Id$ }
  2. {********[ SOURCE FILE OF GRAPHICAL FREE VISION ]**********}
  3. { }
  4. { System independent GRAPHICAL clone of GADGETS.PAS }
  5. { }
  6. { Interface Copyright (c) 1992 Borland International }
  7. { }
  8. { Copyright (c) 1999 by Leon de Boer }
  9. { [email protected] - primary e-mail address }
  10. { [email protected] - backup e-mail address }
  11. { }
  12. {****************[ THIS CODE IS FREEWARE ]*****************}
  13. { }
  14. { This sourcecode is released for the purpose to }
  15. { promote the pascal language on all platforms. You may }
  16. { redistribute it and/or modify with the following }
  17. { DISCLAIMER. }
  18. { }
  19. { This SOURCE CODE is distributed "AS IS" WITHOUT }
  20. { WARRANTIES AS TO PERFORMANCE OF MERCHANTABILITY OR }
  21. { ANY OTHER WARRANTIES WHETHER EXPRESSED OR IMPLIED. }
  22. { }
  23. {*****************[ SUPPORTED PLATFORMS ]******************}
  24. { 16 and 32 Bit compilers }
  25. { DOS - Turbo Pascal 7.0 + (16 Bit) }
  26. { DPMI - Turbo Pascal 7.0 + (16 Bit) }
  27. { - FPC 0.9912+ (GO32V2) (32 Bit) }
  28. { WINDOWS - Turbo Pascal 7.0 + (16 Bit) }
  29. { - Delphi 1.0+ (16 Bit) }
  30. { WIN95/NT - Delphi 2.0+ (32 Bit) }
  31. { - Virtual Pascal 2.0+ (32 Bit) }
  32. { - Speedsoft Sybil 2.0+ (32 Bit) }
  33. { - FPC 0.9912+ (32 Bit) }
  34. { OS2 - Virtual Pascal 1.0+ (32 Bit) }
  35. { }
  36. {*******************[ DOCUMENTATION ]**********************}
  37. { }
  38. { This unit had to be for GFV due to some problems with }
  39. { the original Borland International implementation. }
  40. { }
  41. { First it used the DOS unit for it's time calls in the }
  42. { TClockView object. Since this unit can not be compiled }
  43. { under WIN/NT/OS2 we use a new unit TIME.PAS which was }
  44. { created and works under these O/S. }
  45. { }
  46. { Second the HeapView object accessed MemAvail from in }
  47. { the Draw call. As GFV uses heap memory during the Draw }
  48. { call the OldMem value always met the test condition in }
  49. { the update procedure. The consequence was the view }
  50. { would continually redraw. By moving the memavail call }
  51. { the update procedure this eliminates this problem. }
  52. { }
  53. { Finally the original object relied on the font char }
  54. { blocks being square to erase it's entire view area as }
  55. { it used a simple writeline call in the Draw method. }
  56. { Under GFV font blocks are not necessarily square and }
  57. { so both objects had their Draw routines rewritten. As }
  58. { the Draw had to be redone it was done in the GFV split }
  59. { drawing method to accelerate the graphical speed. }
  60. { }
  61. {******************[ REVISION HISTORY ]********************}
  62. { Version Date Fix }
  63. { ------- --------- --------------------------------- }
  64. { 1.00 12 Nov 99 First multi platform release }
  65. {**********************************************************}
  66. UNIT Gadgets;
  67. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  68. INTERFACE
  69. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  70. {====Include file to sort compiler platform out =====================}
  71. {$I Platform.inc}
  72. {====================================================================}
  73. {==== Compiler directives ===========================================}
  74. {$IFNDEF PPC_FPC}{ FPC doesn't support these switches }
  75. {$F-} { Near calls are okay }
  76. {$A+} { Word Align Data }
  77. {$B-} { Allow short circuit boolean evaluations }
  78. {$O+} { This unit may be overlaid }
  79. {$G+} { 286 Code optimization - if you're on an 8088 get a real computer }
  80. {$P-} { Normal string variables }
  81. {$N-} { No 80x87 code generation }
  82. {$E+} { Emulation is on }
  83. {$ENDIF}
  84. {$X+} { Extended syntax is ok }
  85. {$R-} { Disable range checking }
  86. {$S-} { Disable Stack Checking }
  87. {$I-} { Disable IO Checking }
  88. {$Q-} { Disable Overflow Checking }
  89. {$V-} { Turn off strict VAR strings }
  90. {====================================================================}
  91. USES FVConsts, Time, Objects, Drivers, Views, App; { Standard GFV units }
  92. {***************************************************************************}
  93. { PUBLIC OBJECT DEFINITIONS }
  94. {***************************************************************************}
  95. {---------------------------------------------------------------------------}
  96. { THeapView OBJECT - ANCESTOR VIEW OBJECT }
  97. {---------------------------------------------------------------------------}
  98. TYPE
  99. THeapViewMode=(HVNormal,HVComma,HVKb,HVMb);
  100. THeapView = OBJECT (TView)
  101. Mode : THeapViewMode;
  102. OldMem: LongInt; { Last memory count }
  103. constructor Init(var Bounds: TRect);
  104. constructor InitComma(var Bounds: TRect);
  105. constructor InitKb(var Bounds: TRect);
  106. constructor InitMb(var Bounds: TRect);
  107. PROCEDURE Update;
  108. PROCEDURE Draw; Virtual;
  109. Function Comma ( N : LongInt ) : String;
  110. END;
  111. PHeapView = ^THeapView; { Heapview pointer }
  112. {---------------------------------------------------------------------------}
  113. { TClockView OBJECT - ANCESTOR VIEW OBJECT }
  114. {---------------------------------------------------------------------------}
  115. TYPE
  116. TClockView = OBJECT (TView)
  117. am : Char;
  118. Refresh : Byte; { Refresh rate }
  119. LastTime: Longint; { Last time displayed }
  120. TimeStr : String[10]; { Time string }
  121. CONSTRUCTOR Init (Var Bounds: TRect);
  122. FUNCTION FormatTimeStr (H, M, S: Word): String; Virtual;
  123. PROCEDURE Update; Virtual;
  124. PROCEDURE Draw; Virtual;
  125. END;
  126. PClockView = ^TClockView; { Clockview ptr }
  127. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  128. IMPLEMENTATION
  129. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  130. {***************************************************************************}
  131. { OBJECT METHODS }
  132. {***************************************************************************}
  133. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  134. { THeapView OBJECT METHODS }
  135. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  136. constructor THeapView.Init(var Bounds: TRect);
  137. begin
  138. inherited Init(Bounds);
  139. mode:=HVNormal;
  140. OldMem := 0;
  141. end;
  142. constructor THeapView.InitComma(var Bounds: TRect);
  143. begin
  144. inherited Init(Bounds);
  145. mode:=HVComma;
  146. OldMem := 0;
  147. end;
  148. constructor THeapView.InitKb(var Bounds: TRect);
  149. begin
  150. inherited Init(Bounds);
  151. mode:=HVKb;
  152. OldMem := 0;
  153. end;
  154. constructor THeapView.InitMb(var Bounds: TRect);
  155. begin
  156. inherited Init(Bounds);
  157. mode:=HVMb;
  158. OldMem := 0;
  159. end;
  160. {--THeapView----------------------------------------------------------------}
  161. { Update -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Nov99 LdB }
  162. {---------------------------------------------------------------------------}
  163. PROCEDURE THeapView.Update;
  164. {$ifdef HASGETHEAPSTATUS}
  165. var
  166. status : TFPCHeapStatus;
  167. {$endif HASGETHEAPSTATUS}
  168. BEGIN
  169. {$ifdef HASGETHEAPSTATUS}
  170. status:=GetFPCHeapStatus;
  171. If (OldMem <> status.CurrHeapUsed) Then Begin { Memory differs }
  172. OldMem := status.CurrHeapUsed; { Hold memory avail }
  173. DrawView; { Now redraw }
  174. End;
  175. {$else}
  176. If (OldMem <> MemAvail) Then Begin { Memory differs }
  177. OldMem := MemAvail; { Hold memory avail }
  178. DrawView; { Now redraw }
  179. End;
  180. {$endif}
  181. END;
  182. {--THeapView----------------------------------------------------------------}
  183. { Draw -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Nov99 LdB }
  184. {---------------------------------------------------------------------------}
  185. PROCEDURE THeapView.Draw;
  186. VAR
  187. C : Byte;
  188. S : String;
  189. B : TDrawBuffer;
  190. begin
  191. case mode of
  192. HVNormal :
  193. Str(OldMem:Size.X, S);
  194. HVComma :
  195. S:=Comma(OldMem);
  196. HVKb :
  197. begin
  198. Str(OldMem shr 10:Size.X-1, S);
  199. S:=S+'K';
  200. end;
  201. HVMb :
  202. begin
  203. Str(OldMem shr 20:Size.X-1, S);
  204. S:=S+'M';
  205. end;
  206. end;
  207. C:=GetColor(2);
  208. MoveChar(B,' ',C,Size.X);
  209. MoveStr(B,S,C);
  210. WriteLine(0,0,Size.X,1,B);
  211. END;
  212. Function THeapView.Comma ( n : LongInt) : String;
  213. Var
  214. num, loc : Byte;
  215. s : String;
  216. t : String;
  217. Begin
  218. Str (n,s);
  219. Str (n:Size.X,t);
  220. num := length(s) div 3;
  221. if (length(s) mod 3) = 0 then dec (num);
  222. delete (t,1,num);
  223. loc := length(t)-2;
  224. while num > 0 do
  225. Begin
  226. Insert (',',t,loc);
  227. dec (num);
  228. dec (loc,3);
  229. End;
  230. Comma := t;
  231. End;
  232. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  233. { TClockView OBJECT METHODS }
  234. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  235. {--TClockView---------------------------------------------------------------}
  236. { Init -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Nov99 LdB }
  237. {---------------------------------------------------------------------------}
  238. CONSTRUCTOR TClockView.Init (Var Bounds: TRect);
  239. BEGIN
  240. Inherited Init(Bounds); { Call ancestor }
  241. FillChar(LastTime, SizeOf(LastTime), #$FF); { Fill last time }
  242. TimeStr := ''; { Empty time string }
  243. Refresh := 1; { Refresh per second }
  244. END;
  245. {--TClockView---------------------------------------------------------------}
  246. { FormatStr -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Nov99 LdB }
  247. {---------------------------------------------------------------------------}
  248. FUNCTION TClockView.FormatTimeStr (H, M, S: Word): String;
  249. VAR Hs, Ms, Ss: String;
  250. BEGIN
  251. Str(H, Hs); { Convert hour string }
  252. While (Length(Hs) < 2) Do Hs := '0' + Hs; { Add lead zero's }
  253. Str(M, Ms); { Convert min string }
  254. While (Length(Ms) < 2) Do Ms := '0' + Ms; { Add lead zero's }
  255. Str(S, Ss); { Convert sec string }
  256. While (Length(Ss) < 2) Do Ss := '0' + Ss; { Add lead zero's }
  257. FormatTimeStr := Hs + ':'+ Ms + ':' + Ss; { Return string }
  258. END;
  259. {--TClockView---------------------------------------------------------------}
  260. { Update -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Nov99 LdB }
  261. {---------------------------------------------------------------------------}
  262. PROCEDURE TClockView.Update;
  263. VAR Hour, Min, Sec, Sec100: Word;
  264. BEGIN
  265. GetTime(Hour, Min, Sec, Sec100); { Get current time }
  266. If (Abs(Sec - LastTime) >= Refresh) Then Begin { Refresh time elapsed }
  267. LastTime := Sec; { Hold second }
  268. TimeStr := FormatTimeStr(Hour, Min, Sec); { Create time string }
  269. DrawView; { Now redraw }
  270. End;
  271. END;
  272. {--TClockView---------------------------------------------------------------}
  273. { DrawBackGround -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Nov99 LdB }
  274. {---------------------------------------------------------------------------}
  275. PROCEDURE TClockView.Draw;
  276. VAR
  277. C : Byte;
  278. B : TDrawBuffer;
  279. BEGIN
  280. C:=GetColor(2);
  281. MoveChar(B,' ',C,Size.X);
  282. MoveStr(B,TimeStr,C);
  283. WriteLine(0,0,Size.X,1,B);
  284. END;
  285. END.
  286. {
  287. $Log$
  288. Revision 1.11 2005-02-28 15:38:38 marco
  289. * getFPCheapstatus (no, FPC HEAP, not FP CHEAP!)
  290. Revision 1.10 2005/02/14 17:13:18 peter
  291. * truncate log
  292. }