asciitab.pas 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. { $Id$ }
  2. {********[ SOURCE FILE OF GRAPHICAL FREE VISION ]**********}
  3. { }
  4. { System independent GRAPHICAL clone of ASCIITAB.PAS }
  5. { }
  6. { Interface Copyright (c) 1992 Borland International }
  7. { }
  8. { Copyright (c) 2002 by Pierre Muller }
  9. { [email protected] }
  10. {****************[ THIS CODE IS FREEWARE ]*****************}
  11. { }
  12. { This sourcecode is released for the purpose to }
  13. { promote the pascal language on all platforms. You may }
  14. { redistribute it and/or modify with the following }
  15. { DISCLAIMER. }
  16. { }
  17. { This SOURCE CODE is distributed "AS IS" WITHOUT }
  18. { WARRANTIES AS TO PERFORMANCE OF MERCHANTABILITY OR }
  19. { ANY OTHER WARRANTIES WHETHER EXPRESSED OR IMPLIED. }
  20. { }
  21. {*****************[ SUPPORTED PLATFORMS ]******************}
  22. { 16 and 32 Bit compilers }
  23. { DPMI - FPC 0.9912+ (GO32V2) (32 Bit) }
  24. { WIN95/NT - FPC 0.9912+ (32 Bit) }
  25. { }
  26. UNIT AsciiTab;
  27. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  28. INTERFACE
  29. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  30. {====Include file to sort compiler platform out =====================}
  31. {$I Platform.inc}
  32. {====================================================================}
  33. {==== Compiler directives ===========================================}
  34. {$IFNDEF PPC_FPC}{ FPC doesn't support these switches }
  35. {$F-} { Near calls are okay }
  36. {$A+} { Word Align Data }
  37. {$B-} { Allow short circuit boolean evaluations }
  38. {$O+} { This unit may be overlaid }
  39. {$G+} { 286 Code optimization - if you're on an 8088 get a real computer }
  40. {$P-} { Normal string variables }
  41. {$N-} { No 80x87 code generation }
  42. {$E+} { Emulation is on }
  43. {$ENDIF}
  44. {$X+} { Extended syntax is ok }
  45. {$R-} { Disable range checking }
  46. {$S-} { Disable Stack Checking }
  47. {$I-} { Disable IO Checking }
  48. {$Q-} { Disable Overflow Checking }
  49. {$V-} { Turn off strict VAR strings }
  50. {====================================================================}
  51. USES FVConsts, Objects, Drivers, Views, App; { Standard GFV units }
  52. {***************************************************************************}
  53. { PUBLIC OBJECT DEFINITIONS }
  54. {***************************************************************************}
  55. {---------------------------------------------------------------------------}
  56. { TTABLE OBJECT - 32x32 matrix of all chars }
  57. {---------------------------------------------------------------------------}
  58. type
  59. PTable = ^TTable;
  60. TTable = object(TView)
  61. procedure DrawBackground; virtual;
  62. procedure HandleEvent(var Event:TEvent); virtual;
  63. private
  64. procedure DrawCurPos(enable : boolean);
  65. end;
  66. {---------------------------------------------------------------------------}
  67. { TREPORT OBJECT - View with details of current char }
  68. {---------------------------------------------------------------------------}
  69. PReport = ^TReport;
  70. TReport = object(TView)
  71. ASCIIChar: LongInt;
  72. constructor Load(var S: TStream);
  73. procedure Draw; virtual;
  74. procedure HandleEvent(var Event:TEvent); virtual;
  75. procedure Store(var S: TStream);
  76. end;
  77. {---------------------------------------------------------------------------}
  78. { TASCIIChart OBJECT - the complete AsciiChar window }
  79. {---------------------------------------------------------------------------}
  80. PASCIIChart = ^TASCIIChart;
  81. TASCIIChart = object(TWindow)
  82. Report: PReport;
  83. Table: PTable;
  84. constructor Init;
  85. constructor Load(var S: TStream);
  86. procedure Store(var S: TStream);
  87. procedure HandleEvent(var Event:TEvent); virtual;
  88. end;
  89. {---------------------------------------------------------------------------}
  90. { AsciiTableCommandBase }
  91. {---------------------------------------------------------------------------}
  92. const
  93. AsciiTableCommandBase: Word = 910;
  94. {---------------------------------------------------------------------------}
  95. { Registrations records }
  96. {---------------------------------------------------------------------------}
  97. RTable: TStreamRec = (
  98. ObjType: 10030;
  99. VmtLink: Ofs(TypeOf(TTable)^);
  100. Load: @TTable.Load;
  101. Store: @TTable.Store
  102. );
  103. RReport: TStreamRec = (
  104. ObjType: 10031;
  105. VmtLink: Ofs(TypeOf(TReport)^);
  106. Load: @TReport.Load;
  107. Store: @TReport.Store
  108. );
  109. RASCIIChart: TStreamRec = (
  110. ObjType: 10032;
  111. VmtLink: Ofs(TypeOf(TASCIIChart)^);
  112. Load: @TASCIIChart.Load;
  113. Store: @TASCIIChart.Store
  114. );
  115. {---------------------------------------------------------------------------}
  116. { Registration procedure }
  117. {---------------------------------------------------------------------------}
  118. procedure RegisterASCIITab;
  119. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  120. IMPLEMENTATION
  121. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  122. {***************************************************************************}
  123. { OBJECT METHODS }
  124. {***************************************************************************}
  125. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  126. { TTable OBJECT METHODS }
  127. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  128. procedure TTable.DrawBackground;
  129. var
  130. NormColor : byte;
  131. B : TDrawBuffer;
  132. x,y : sw_integer;
  133. begin
  134. NormColor:=GetColor(1);
  135. For y:=0 to size.Y-1 do
  136. For x:=0 to size.X-1 do
  137. begin
  138. B[x]:=(NormColor shl 8) or ((y*Size.X+x) and $ff);
  139. WriteLine(0,Y,Size.X,1,B);
  140. end;
  141. DrawCurPos(true);
  142. end;
  143. procedure TTable.DrawCurPos(enable : boolean);
  144. var
  145. Color : byte;
  146. B : word;
  147. begin
  148. Color:=GetColor(1);
  149. { add blinking if enable }
  150. If Enable then
  151. Color:=((Color and $F) shl 4) or (Color shr 4);
  152. B:=(Color shl 8) or ((Cursor.Y*Size.X+Cursor.X) and $ff);
  153. WriteLine(Cursor.X,Cursor.Y,1,1,B);
  154. end;
  155. procedure TTable.HandleEvent(var Event:TEvent);
  156. var
  157. xpos,ypos : sw_integer;
  158. Handled : boolean;
  159. procedure SetTo(xpos, ypos : sw_integer);
  160. var
  161. newchar : longint;
  162. begin
  163. newchar:=(ypos*size.X+xpos) and $ff;
  164. DrawCurPos(false);
  165. SetCursor(xpos,ypos);
  166. Message(Owner,evCommand,AsciiTableCommandBase,
  167. pointer(newchar));
  168. DrawCurPos(true);
  169. ClearEvent(Event);
  170. end;
  171. begin
  172. case Event.What of
  173. evMouseDown :
  174. begin
  175. If MouseInView(Event.Where) then
  176. begin
  177. xpos:=(Event.Where.X -RawOrigin.X) div SysFontWidth;
  178. ypos:=(Event.Where.Y -RawOrigin.Y) div SysFontHeight;
  179. SetTo(xpos, ypos);
  180. exit;
  181. end;
  182. end;
  183. evKeyDown :
  184. begin
  185. Handled:=true;
  186. case Event.Keycode of
  187. kbUp : if Cursor.Y>0 then
  188. SetTo(Cursor.X,Cursor.Y-1);
  189. kbDown : if Cursor.Y<Size.Y-1 then
  190. SetTo(Cursor.X,Cursor.Y+1);
  191. kbLeft : if Cursor.X>0 then
  192. SetTo(Cursor.X-1,Cursor.Y);
  193. kbRight: if Cursor.X<Size.X-1 then
  194. SetTo(Cursor.X+1,Cursor.Y);
  195. kbHome : SetTo(0,0);
  196. kbEnd : SetTo(Size.X-1,Size.Y-1);
  197. else
  198. Handled:=false;
  199. end;
  200. if Handled then
  201. exit;
  202. end;
  203. end;
  204. inherited HandleEvent(Event);
  205. end;
  206. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  207. { TReport OBJECT METHODS }
  208. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  209. constructor TReport.Load(var S: TStream);
  210. begin
  211. Inherited Load(S);
  212. S.Read(AsciiChar,Sizeof(AsciiChar));
  213. end;
  214. procedure TReport.Draw;
  215. var
  216. stHex,stDec : string[3];
  217. s : string;
  218. begin
  219. Str(AsciiChar,StDec);
  220. while length(stDec)<3 do
  221. stDec:=' '+stDec;
  222. stHex:=hexstr(AsciiChar,2);
  223. s:='Char "'+chr(AsciiChar)+'" Decimal: '+
  224. StDec+' Hex: $'+StHex;
  225. WriteStr(0,0,S,1);
  226. end;
  227. procedure TReport.HandleEvent(var Event:TEvent);
  228. begin
  229. if (Event.what=evCommand) and
  230. (Event.Command = AsciiTableCommandBase) then
  231. begin
  232. AsciiChar:=Event.InfoLong;
  233. Draw;
  234. ClearEvent(Event);
  235. end
  236. else inherited HandleEvent(Event);
  237. end;
  238. procedure TReport.Store(var S: TStream);
  239. begin
  240. Inherited Store(S);
  241. S.Write(AsciiChar,Sizeof(AsciiChar));
  242. end;
  243. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  244. { TAsciiChart OBJECT METHODS }
  245. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  246. constructor TASCIIChart.Init;
  247. var
  248. R : Trect;
  249. begin
  250. R.Assign(0,0,34,12);
  251. Inherited Init(R,'Ascii table',wnNoNumber);
  252. Flags:=Flags and not (wfGrow or wfZoom);
  253. Palette:=wpGrayWindow;
  254. R.Assign(1,10,33,11);
  255. New(Report,Init(R));
  256. Report^.Options:=Report^.Options or ofFramed;
  257. Insert(Report);
  258. R.Assign(1,1,33,9);
  259. New(Table,Init(R));
  260. Table^.Options:=Table^.Options or (ofSelectable+ofTopSelect);
  261. Insert(Table);
  262. Table^.Select;
  263. end;
  264. constructor TASCIIChart.Load(var S: TStream);
  265. begin
  266. Inherited Load(S);
  267. GetSubViewPtr(S,Table);
  268. GetSubViewPtr(S,Report);
  269. end;
  270. procedure TASCIIChart.Store(var S: TStream);
  271. begin
  272. Inherited Store(S);
  273. PutSubViewPtr(S,Table);
  274. PutSubViewPtr(S,Report);
  275. end;
  276. procedure TASCIIChart.HandleEvent(var Event:TEvent);
  277. begin
  278. if (Event.what=evCommand) and
  279. (Event.Command = AsciiTableCommandBase) then
  280. begin
  281. Report^.HandleEvent(Event);
  282. end
  283. else inherited HandleEvent(Event);
  284. end;
  285. {---------------------------------------------------------------------------}
  286. { Registration procedure }
  287. {---------------------------------------------------------------------------}
  288. procedure RegisterASCIITab;
  289. begin
  290. RegisterType(RTable);
  291. RegisterType(RReport);
  292. RegisterType(RAsciiChart);
  293. end;
  294. END.
  295. {
  296. $Log$
  297. Revision 1.3 2002-05-30 22:23:15 pierre
  298. * current char color changed
  299. Revision 1.2 2002/05/30 14:52:53 pierre
  300. * some more fixes
  301. Revision 1.1 2002/05/29 22:14:53 pierre
  302. Newfile
  303. }