gadgets.pas 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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 Common, 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. THeapView = OBJECT (TView)
  99. OldMem: LongInt; { Last memory count }
  100. PROCEDURE Update;
  101. PROCEDURE DrawBackGround; Virtual;
  102. END;
  103. PHeapView = ^THeapView; { Heapview pointer }
  104. {---------------------------------------------------------------------------}
  105. { TClockView OBJECT - ANCESTOR VIEW OBJECT }
  106. {---------------------------------------------------------------------------}
  107. TYPE
  108. TClockView = OBJECT (TView)
  109. Refresh : Byte; { Refresh rate }
  110. LastTime: Longint; { Last time displayed }
  111. TimeStr : String[10]; { Time string }
  112. CONSTRUCTOR Init (Var Bounds: TRect);
  113. FUNCTION FormatTimeStr (H, M, S: Word): String; Virtual;
  114. PROCEDURE Update; Virtual;
  115. PROCEDURE DrawBackGround; Virtual;
  116. END;
  117. PClockView = ^TClockView; { Clockview ptr }
  118. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  119. IMPLEMENTATION
  120. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  121. {***************************************************************************}
  122. { OBJECT METHODS }
  123. {***************************************************************************}
  124. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  125. { THeapView OBJECT METHODS }
  126. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  127. {--THeapView----------------------------------------------------------------}
  128. { Update -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Nov99 LdB }
  129. {---------------------------------------------------------------------------}
  130. PROCEDURE THeapView.Update;
  131. BEGIN
  132. If (OldMem <> MemAvail) Then Begin { Memory differs }
  133. OldMem := MemAvail; { Hold memory avail }
  134. SetDrawMask(vdBackGnd OR vdInner); { Set draw masks }
  135. DrawView; { Now redraw }
  136. End;
  137. END;
  138. {--THeapView----------------------------------------------------------------}
  139. { DrawBackGround -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Nov99 LdB }
  140. {---------------------------------------------------------------------------}
  141. PROCEDURE THeapView.DrawBackGround;
  142. VAR HOfs: Integer; S: String;
  143. BEGIN
  144. Str(OldMem, S); { Convert to string }
  145. HOfs := ColourOfs; { Hold any offset }
  146. ColourOfs := 2; { Set colour offset }
  147. Inherited DrawBackGround; { Clear the backgound }
  148. ColourOfs := HOfs; { Reset any offset }
  149. WriteStr(-(RawSize.X-TextWidth(S)+1), 0, S, 2); { Write the string }
  150. END;
  151. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  152. { TClockView OBJECT METHODS }
  153. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  154. {--TClockView---------------------------------------------------------------}
  155. { Init -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Nov99 LdB }
  156. {---------------------------------------------------------------------------}
  157. CONSTRUCTOR TClockView.Init (Var Bounds: TRect);
  158. BEGIN
  159. Inherited Init(Bounds); { Call ancestor }
  160. FillChar(LastTime, SizeOf(LastTime), #$FF); { Fill last time }
  161. TimeStr := ''; { Empty time string }
  162. Refresh := 1; { Refresh per second }
  163. END;
  164. {--TClockView---------------------------------------------------------------}
  165. { FormatStr -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Nov99 LdB }
  166. {---------------------------------------------------------------------------}
  167. FUNCTION TClockView.FormatTimeStr (H, M, S: Word): String;
  168. VAR Hs, Ms, Ss: String;
  169. BEGIN
  170. Str(H, Hs); { Convert hour string }
  171. While (Length(Hs) < 2) Do Hs := '0' + Hs; { Add lead zero's }
  172. Str(M, Ms); { Convert min string }
  173. While (Length(Ms) < 2) Do Ms := '0' + Ms; { Add lead zero's }
  174. Str(S, Ss); { Convert sec string }
  175. While (Length(Ss) < 2) Do Ss := '0' + Ss; { Add lead zero's }
  176. FormatTimeStr := Hs + ':'+ Ms + ':' + Ss; { Return string }
  177. END;
  178. {--TClockView---------------------------------------------------------------}
  179. { Update -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Nov99 LdB }
  180. {---------------------------------------------------------------------------}
  181. PROCEDURE TClockView.Update;
  182. VAR Hour, Min, Sec, Sec100: Word;
  183. BEGIN
  184. GetTime(Hour, Min, Sec, Sec100); { Get current time }
  185. If (Abs(Sec - LastTime) >= Refresh) Then Begin { Refresh time elapsed }
  186. LastTime := Sec; { Hold second }
  187. TimeStr := FormatTimeStr(Hour, Min, Sec); { Create time string }
  188. SetDrawMask(vdBackGnd OR vdInner); { Set draw masks }
  189. DrawView; { Now redraw }
  190. End;
  191. END;
  192. {--TClockView---------------------------------------------------------------}
  193. { DrawBackGround -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Nov99 LdB }
  194. {---------------------------------------------------------------------------}
  195. PROCEDURE TClockView.DrawBackGround;
  196. VAR HOfs: Integer;
  197. BEGIN
  198. HOfs := ColourOfs; { Hold any offset }
  199. ColourOfs := 2; { Set colour offset }
  200. Inherited DrawBackGround; { Clear the backgound }
  201. ColourOfs := HOfs; { Reset any offset }
  202. WriteStr(0, 0, TimeStr, 2); { Write the string }
  203. END;
  204. END.