gadgets.pas 12 KB

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