gadgets.pas 12 KB

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