gfvgraph.pas 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  1. { $Id$ }
  2. {********[ SOURCE FILE OF GRAPHICAL FREE VISION ]**********}
  3. { }
  4. { System independent GFV GRAPHICS UNIT }
  5. { }
  6. { Copyright (c) 1999, 2000 by Leon de Boer }
  7. { [email protected] - primary e-mail address }
  8. { [email protected] - backup e-mail address }
  9. { }
  10. { This unit provides the interlink between the graphics }
  11. { used in GFV and the graphics API for the different }
  12. { operating systems. }
  13. { }
  14. {****************[ THIS CODE IS FREEWARE ]*****************}
  15. { }
  16. { This sourcecode is released for the purpose to }
  17. { promote the pascal language on all platforms. You may }
  18. { redistribute it and/or modify with the following }
  19. { DISCLAIMER. }
  20. { }
  21. { This SOURCE CODE is distributed "AS IS" WITHOUT }
  22. { WARRANTIES AS TO PERFORMANCE OF MERCHANTABILITY OR }
  23. { ANY OTHER WARRANTIES WHETHER EXPRESSED OR IMPLIED. }
  24. { }
  25. {*****************[ SUPPORTED PLATFORMS ]******************}
  26. { 16 and 32 Bit compilers }
  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. { - Speed Pascal 1.0+ (32 Bit) }
  35. { }
  36. {*****************[ REVISION HISTORY ]*********************}
  37. { Version Date Fix }
  38. { ------- --------- ---------------------------------- }
  39. { 1.00 26 Nov 99 Unit started from relocated code }
  40. { originally from views.pas }
  41. { 1.01 21 May 00 GetMaxX and GetMaxY added. }
  42. { 1.02 05 Dec 00 Fixed DOS/DPMI implementation. }
  43. {**********************************************************}
  44. UNIT GFVGraph;
  45. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  46. INTERFACE
  47. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  48. {====Include file to sort compiler platform out =====================}
  49. {$I Platform.inc}
  50. {====================================================================}
  51. {==== Compiler directives ===========================================}
  52. {$IFNDEF PPC_FPC} { FPC doesn't support these switches }
  53. {$F-} { Near far calls are okay }
  54. {$A+} { Word Align Data }
  55. {$B-} { Allow short circuit boolean evaluations }
  56. {$O+} { This unit may be overlaid }
  57. {$G+} { 286 Code optimization - if you're on an 8088 get a real computer }
  58. {$E+} { Emulation is on }
  59. {$N-} { No 80x87 code generation }
  60. {$ENDIF}
  61. {$X+} { Extended syntax is ok }
  62. {$R-} { Disable range checking }
  63. {$S-} { Disable Stack Checking }
  64. {$I-} { Disable IO Checking }
  65. {$Q-} { Disable Overflow Checking }
  66. {$V-} { Turn off strict VAR strings }
  67. {====================================================================}
  68. {$IFDEF GRAPH_API} { GRAPH CODE }
  69. USES Graph; { Standard unit }
  70. {$ENDIF}
  71. {***************************************************************************}
  72. { PUBLIC CONSTANTS }
  73. {***************************************************************************}
  74. {---------------------------------------------------------------------------}
  75. { STANDARD COLOUR CONSTANTS }
  76. {---------------------------------------------------------------------------}
  77. CONST
  78. Black = 0; { Black }
  79. Blue = 1; { Blue }
  80. Green = 2; { Green }
  81. Cyan = 3; { Cyan }
  82. Red = 4; { Red }
  83. Magenta = 5; { Magenta }
  84. Brown = 6; { Brown }
  85. LightGray = 7; { Light grey }
  86. DarkGray = 8; { Dark grey }
  87. LightBlue = 9; { Light blue }
  88. LightGreen = 10; { Light green }
  89. LightCyan = 11; { Light cyan }
  90. LightRed = 12; { Light red }
  91. LightMagenta = 13; { Light magenta }
  92. Yellow = 14; { Yellow }
  93. White = 15; { White }
  94. {---------------------------------------------------------------------------}
  95. { WRITE MODE CONSTANTS }
  96. {---------------------------------------------------------------------------}
  97. CONST
  98. NormalPut = 0; { Normal overwrite }
  99. CopyPut = 0; { Normal put image }
  100. AndPut = 1; { AND colour write }
  101. OrPut = 2; { OR colour write }
  102. XorPut = 3; { XOR colour write }
  103. NotPut = 4; { NOT colour write }
  104. {---------------------------------------------------------------------------}
  105. { CLIP CONTROL CONSTANTS }
  106. {---------------------------------------------------------------------------}
  107. CONST
  108. ClipOn = True; { Clipping on }
  109. ClipOff = False; { Clipping off }
  110. {---------------------------------------------------------------------------}
  111. { VIDEO CARD DETECTION CONSTANTS }
  112. {---------------------------------------------------------------------------}
  113. CONST
  114. Detect = 0; { Detect video }
  115. {$IFDEF GRAPH_API} { DOS CODE ONLY }
  116. {---------------------------------------------------------------------------}
  117. { DOS GRAPHICS SOLID FILL BAR AREA CONSTANT }
  118. {---------------------------------------------------------------------------}
  119. CONST
  120. SolidFill = Graph.SolidFill;
  121. LowAscii : boolean = true;
  122. type
  123. textrainfo = array[0..0] of word;
  124. pextrainfo = ^textrainfo;
  125. TSpVideoBuf = array [0..0] of pextrainfo;
  126. PSpVideoBuf = ^TSpVideoBuf;
  127. const
  128. SpVideoBuf : PSpVideoBuf = nil;
  129. {$ELSE not GRAPH_API }
  130. CONST
  131. SolidFill = 0;
  132. {$ENDIF not GRAPH_API}
  133. {***************************************************************************}
  134. { PUBLIC TYPE DEFINITIONS }
  135. {***************************************************************************}
  136. {---------------------------------------------------------------------------}
  137. { ViewPortType RECORD DEFINITION }
  138. {---------------------------------------------------------------------------}
  139. TYPE
  140. ViewPortType = PACKED RECORD
  141. X1, Y1, X2, Y2: Integer; { Corners of viewport }
  142. Clip : Boolean; { Clip status }
  143. END;
  144. {***************************************************************************}
  145. { INTERFACE ROUTINES }
  146. {***************************************************************************}
  147. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  148. { GRAPHICS MODE CONTROL ROUTINES }
  149. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  150. {-SetWriteMode-------------------------------------------------------
  151. Sets the current write mode constant all subsequent draws etc. are
  152. then via the set mode.
  153. 26Nov99 LdB
  154. ---------------------------------------------------------------------}
  155. PROCEDURE SetWriteMode (Mode: Byte; TextMode: Boolean);
  156. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  157. { VIEWPORT CONTROL ROUTINES }
  158. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  159. {-GetViewSettings----------------------------------------------------
  160. Returns the current viewport and clip parameters in the variable.
  161. 26Nov99 LdB
  162. ---------------------------------------------------------------------}
  163. PROCEDURE GetViewSettings (Var CurrentViewPort: ViewPortType; TextMode: Boolean);
  164. {-SetViewPort--------------------------------------------------------
  165. Set the current viewport and clip parameters to that requested.
  166. 26Nov99 LdB
  167. ---------------------------------------------------------------------}
  168. PROCEDURE SetViewPort (X1, Y1, X2, Y2: Integer; Clip, TextMode: Boolean);
  169. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  170. { GRAPHICS DEVICE CAPACITY ROUTINES }
  171. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  172. {-GetMaxX------------------------------------------------------------
  173. Returns X coordinate of maximum value that can be entered in any
  174. graphics routine, that is the actual screen width in pixels - 1.
  175. 21May2000 LdB
  176. ---------------------------------------------------------------------}
  177. FUNCTION GetMaxX (TextMode: Boolean): Integer;
  178. {-GetMaxY------------------------------------------------------------
  179. Returns Y coordinate of maximum value that can be entered in any
  180. graphics routine, that is the actual screen height in pixels - 1.
  181. 21May2000 LdB
  182. ---------------------------------------------------------------------}
  183. FUNCTION GetMaxY (TextMode: Boolean): Integer;
  184. PROCEDURE SetColor(Color: Word);
  185. PROCEDURE SetFillStyle (Pattern: Word; Color: Word);
  186. PROCEDURE Bar (X1, Y1, X2, Y2: Integer);
  187. PROCEDURE Line(X1, Y1, X2, Y2: Integer);
  188. PROCEDURE Rectangle(X1, Y1, X2, Y2: Integer);
  189. PROCEDURE OutTextXY(X,Y: Integer; TextString: String);
  190. {$IFDEF GRAPH_API}
  191. procedure GraphUpdateScreen(Force: Boolean);
  192. procedure SetExtraInfo(x,y,xi,yi : longint; color : word);
  193. procedure SetupExtraInfo;
  194. procedure FreeExtraInfo;
  195. Const
  196. { Possible cursor types for video interface }
  197. crHidden = 0;
  198. crUnderLine = 1;
  199. crBlock = 2;
  200. crHalfBlock = 3;
  201. EmptyVideoBufCell : pextrainfo = nil;
  202. { from video unit }
  203. procedure SetCursorPos(NewCursorX, NewCursorY: Word);
  204. { Position the cursor to the given position }
  205. function GetCursorType: Word;
  206. { Return the cursor type: Hidden, UnderLine or Block }
  207. procedure SetCursorType(NewType: Word);
  208. { Set the cursor to the given type }
  209. {$ENDIF GRAPH_API}
  210. {***************************************************************************}
  211. { INITIALIZED PUBLIC VARIABLES }
  212. {***************************************************************************}
  213. {---------------------------------------------------------------------------}
  214. { INITIALIZED DOS/DPMI/WIN/NT/OS2 VARIABLES }
  215. {---------------------------------------------------------------------------}
  216. CONST
  217. WriteMode : Byte = 0; { Current write mode }
  218. SysScreenWidth : Integer = 640; { Default screen width }
  219. SysScreenHeight: Integer = 480; { Default screen height}
  220. {$ifdef USE_VIDEO_API}
  221. SysFontWidth : Integer = 8; { System font width }
  222. SysFontHeight : Integer = 16; { System font height }
  223. TextScreenWidth : Integer = 80;
  224. TextScreenHeight : Integer = 25;
  225. {$endif USE_VIDEO_API}
  226. {$ifdef DEBUG}
  227. const
  228. WriteDebugInfo : boolean = false;
  229. {$endif DEBUG}
  230. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  231. IMPLEMENTATION
  232. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  233. {$ifdef USE_VIDEO_API}
  234. USES video; { Standard unit }
  235. {$ENDIF}
  236. {***************************************************************************}
  237. { PRIVATE INITIALIZED VARIABLES }
  238. {***************************************************************************}
  239. {---------------------------------------------------------------------------}
  240. { DOS/DPMI/WIN/NT/OS2 INITIALIZED VARIABLES }
  241. {---------------------------------------------------------------------------}
  242. CONST
  243. FillCol : Integer = 0;
  244. Cxp : Integer = 0; { Current x position }
  245. Cyp : Integer = 0; { Current y position }
  246. ViewPort: ViewPortType = (X1:0; Y1:0; X2: 639;
  247. Y2: 479; Clip: True); { Default viewport }
  248. {***************************************************************************}
  249. { INTERFACE ROUTINES }
  250. {***************************************************************************}
  251. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  252. { GRAPHICS MODE CONTROL ROUTINES }
  253. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  254. {---------------------------------------------------------------------------}
  255. { SetWriteMode -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 05Dec2000 LdB }
  256. {---------------------------------------------------------------------------}
  257. PROCEDURE SetWriteMode (Mode: Byte; TextMode: Boolean);
  258. BEGIN
  259. {$IFDEF GRAPH_API} { GRAPH CODE }
  260. If TextMode Then
  261. WriteMode := Mode { Hold write mode }
  262. Else Graph.SetWriteMode(Mode); { Call graph proc }
  263. {$ELSE not GRAPH_API}
  264. WriteMode := Mode; { Hold write mode }
  265. {$ENDIF not GRAPH_API}
  266. END;
  267. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  268. { VIEW PORT CONTROL ROUTINES }
  269. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  270. {---------------------------------------------------------------------------}
  271. { GetViewSettings -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 05Dec2000 LdB }
  272. {---------------------------------------------------------------------------}
  273. PROCEDURE GetViewSettings (Var CurrentViewPort: ViewPortType; TextMode: Boolean);
  274. {$IFDEF GRAPH_API}
  275. VAR Ts: Graph.ViewPortType;
  276. {$ENDIF GRAPH_API}
  277. BEGIN
  278. {$IFNDEF GRAPH_API}
  279. CurrentViewPort := ViewPort; { Textmode viewport }
  280. {$ELSE GRAPH_API}
  281. If TextMode Then CurrentViewPort := ViewPort { Textmode viewport }
  282. Else Begin
  283. Graph.GetViewSettings(Ts); { Get graph settings }
  284. CurrentViewPort.X1 := Ts.X1; { Transfer X1 }
  285. CurrentViewPort.Y1 := Ts.Y1; { Transfer Y1 }
  286. CurrentViewPort.X2 := Ts.X2; { Transfer X2 }
  287. CurrentViewPort.Y2 := Ts.Y2; { Transfer Y2 }
  288. CurrentViewPort.Clip := Ts.Clip; { Transfer clip mask }
  289. End;
  290. {$ENDIF GRAPH_API}
  291. END;
  292. {---------------------------------------------------------------------------}
  293. { SetViewPort -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 05Dec2000 LdB }
  294. {---------------------------------------------------------------------------}
  295. PROCEDURE SetViewPort (X1, Y1, X2, Y2: Integer; Clip, TextMode: Boolean);
  296. BEGIN
  297. {$IFDEF GRAPH_API}
  298. If TextMode Then Begin { TEXT MODE GFV }
  299. {$ENDIF GRAPH_API}
  300. If (X1 < 0) Then X1 := 0; { X1 negative fix }
  301. If (X1 >SysScreenWidth) Then
  302. X1 := SysScreenWidth; { X1 off screen fix }
  303. If (Y1 < 0) Then Y1 := 0; { Y1 negative fix }
  304. If (Y1 > SysScreenHeight) Then
  305. Y1 := SysScreenHeight; { Y1 off screen fix }
  306. If (X2 < 0) Then X2 := 0; { X2 negative fix }
  307. If (X2 > SysScreenWidth) Then
  308. X2 := SysScreenWidth; { X2 off screen fix }
  309. If (Y2 < 0) Then Y2 := 0; { Y2 negative fix }
  310. If (Y2 > SysScreenHeight) Then
  311. Y2 := SysScreenHeight; { Y2 off screen fix }
  312. ViewPort.X1 := X1; { Set X1 port value }
  313. ViewPort.Y1 := Y1; { Set Y1 port value }
  314. ViewPort.X2 := X2; { Set X2 port value }
  315. ViewPort.Y2 := Y2; { Set Y2 port value }
  316. ViewPort.Clip := Clip; { Set port clip value }
  317. {$ifdef DEBUG}
  318. If WriteDebugInfo then
  319. Writeln(stderr,'New ViewPort(',X1,',',Y1,',',X2,',',Y2,')');
  320. {$endif DEBUG}
  321. Cxp := X1; { Set current x pos }
  322. Cyp := Y1; { Set current y pos }
  323. {$IFDEF GRAPH_API}
  324. End Else Begin { GRAPHICS MODE GFV }
  325. Graph.SetViewPort(X1, Y1, X2, Y2, Clip); { Call graph proc }
  326. X1:=X1 div SysFontWidth;
  327. X2:=X2 div SysFontWidth;
  328. Y1:=Y1 div SysFontHeight;
  329. Y2:=Y2 div SysFontHeight;
  330. If (X1 < 0) Then X1 := 0; { X1 negative fix }
  331. If (X1 >SysScreenWidth) Then
  332. X1 := SysScreenWidth; { X1 off screen fix }
  333. If (Y1 < 0) Then Y1 := 0; { Y1 negative fix }
  334. If (Y1 > SysScreenHeight) Then
  335. Y1 := SysScreenHeight; { Y1 off screen fix }
  336. If (X2 < 0) Then X2 := 0; { X2 negative fix }
  337. If (X2 > SysScreenWidth) Then
  338. X2 := SysScreenWidth; { X2 off screen fix }
  339. If (Y2 < 0) Then Y2 := 0; { Y2 negative fix }
  340. If (Y2 > SysScreenHeight) Then
  341. Y2 := SysScreenHeight; { Y2 off screen fix }
  342. ViewPort.X1 := X1; { Set X1 port value }
  343. ViewPort.Y1 := Y1; { Set Y1 port value }
  344. ViewPort.X2 := X2; { Set X2 port value }
  345. ViewPort.Y2 := Y2; { Set Y2 port value }
  346. ViewPort.Clip := Clip; { Set port clip value }
  347. Cxp := X1; { Set current x pos }
  348. Cyp := Y1; { Set current y pos }
  349. End;
  350. {$ENDIF GRAPH_API}
  351. END;
  352. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  353. { GRAPHICS DEVICE CAPACITY ROUTINES }
  354. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  355. {---------------------------------------------------------------------------}
  356. { GetMaxX - Platforms DOS/DPMI/WIN/NT/OS2 - Updated 05Dec2000 LdB }
  357. {---------------------------------------------------------------------------}
  358. FUNCTION GetMaxX (TextMode: Boolean): Integer;
  359. BEGIN
  360. {$IFDEF GRAPH_API}
  361. If TextMode Then
  362. {$ENDIF GRAPH_API}
  363. GetMaxX := SysScreenWidth-1 { Screen width }
  364. {$IFDEF GRAPH_API}
  365. Else GetMaxX := Graph.GetMaxX; { Call graph func }
  366. {$ENDIF GRAPH_API}
  367. END;
  368. {---------------------------------------------------------------------------}
  369. { GetMaxY - Platforms DOS/DPMI/WIN/NT/OS2 - Updated 05Dec2000 LdB }
  370. {---------------------------------------------------------------------------}
  371. FUNCTION GetMaxY (TextMode: Boolean): Integer;
  372. BEGIN
  373. {$IFDEF GRAPH_API}
  374. If TextMode Then
  375. {$ENDIF GRAPH_API}
  376. GetMaxY := SysScreenHeight-1 { Screen height }
  377. {$IFDEF GRAPH_API}
  378. Else GetMaxY := Graph.GetMaxY; { Call graph func }
  379. {$ENDIF GRAPH_API}
  380. END;
  381. PROCEDURE SetColor(Color: Word);
  382. BEGIN
  383. {$IFDEF GRAPH_API}
  384. Graph.SetColor(Color); { Call graph proc }
  385. {$ENDIF GRAPH_API}
  386. END;
  387. PROCEDURE SetFillStyle (Pattern: Word; Color: Word);
  388. BEGIN
  389. {$IFDEF GRAPH_API}
  390. Graph.SetFillStyle(Pattern, Color); { Call graph proc }
  391. {$ENDIF GRAPH_API}
  392. END;
  393. PROCEDURE Bar (X1, Y1, X2, Y2: Integer);
  394. BEGIN
  395. {$IFDEF GRAPH_API}
  396. Graph.Bar(X1, Y1, X2, Y2); { Call graph proc }
  397. {$ENDIF GRAPH_API}
  398. END;
  399. PROCEDURE Line(X1, Y1, X2, Y2: Integer);
  400. BEGIN
  401. {$IFDEF GRAPH_API}
  402. Graph.Line(X1, Y1, X2, Y2); { Call graph proc }
  403. {$ENDIF GRAPH_API}
  404. END;
  405. PROCEDURE Rectangle(X1, Y1, X2, Y2: Integer);
  406. BEGIN
  407. {$IFDEF GRAPH_API}
  408. Graph.Rectangle(X1, Y1, X2, Y2); { Call graph proc }
  409. {$ENDIF GRAPH_API}
  410. END;
  411. PROCEDURE OutTextXY(X,Y: Integer; TextString: string);
  412. {$IFDEF GRAPH_API}
  413. var
  414. i,j,xi,yj,xs,ys : longint;
  415. Ts: Graph.ViewPortType;
  416. Txs : TextSettingsType;
  417. tw, th : integer;
  418. color : word;
  419. {$ENDIF GRAPH_API}
  420. BEGIN
  421. {$IFDEF GRAPH_API}
  422. Graph.OutTextXY(X, Y, TextString); { Call graph proc }
  423. if true then
  424. begin
  425. Graph.GetViewSettings(Ts);
  426. Graph.GetTextSettings(Txs);
  427. tw:=TextWidth(TextString);
  428. th:=TextHeight(TextString);
  429. case Txs.Horiz of
  430. centertext : Xs:=(tw shr 1);
  431. lefttext : Xs:=0;
  432. righttext : Xs:=tw;
  433. end;
  434. case txs.vert of
  435. centertext : Ys:=-(th shr 1);
  436. bottomtext : Ys:=-th;
  437. toptext : Ys:=0;
  438. end;
  439. x:=x-xs;
  440. y:=y+ys;
  441. For j:=0 to tw-1 do
  442. For i:=0 to th-1 do
  443. begin
  444. xi:=x+i+Ts.x1;
  445. yj:=y+j+Ts.y1;
  446. Color:=GetPixel(xi,yj);
  447. SetExtraInfo(xi div SysFontWidth,yj div SysFontHeight,
  448. xi mod SysFontWidth,yj mod SysFontHeight, Color);
  449. end;
  450. end;
  451. {$ENDIF GRAPH_API}
  452. END;
  453. {$IFDEF GRAPH_API}
  454. { from video unit }
  455. Const
  456. CursorX : longint = -1;
  457. CursorY : longint = -1;
  458. CursorType : byte = crHidden;
  459. CursorIsVisible : boolean = false;
  460. LineReversed = true;
  461. LineNormal = false;
  462. TYPE
  463. TCursorInfo = array[0..7] of boolean;
  464. CONST
  465. DefaultCursors: Array[crUnderline..crHalfBlock] of TCursorInfo =
  466. (
  467. (LineNormal, LineNormal, LineNormal, LineNormal, LineNormal, LineNormal, LineNormal, LineReversed),
  468. (LineReversed, LineReversed, LineReversed, LineReversed, LineReversed, LineReversed, LineReversed, LineReversed),
  469. (LineNormal, LineNormal, LineNormal, LineNormal, LineReversed, LineReversed, LineReversed, LineReversed)
  470. );
  471. Procedure XorPutCursor;
  472. var
  473. j,YSCale : longint;
  474. Ts: Graph.ViewPortType;
  475. StoreColor : longint;
  476. begin
  477. if CursorType=crHidden then
  478. exit;
  479. Yscale:=(SysFontHeight+1) div 8;
  480. Graph.GetViewSettings(Ts);
  481. graph.SetWriteMode(graph.XORPut);
  482. StoreColor:=Graph.GetColor;
  483. Graph.SetColor(White);
  484. if (CursorX*SysFontWidth>=Ts.X1) and (CursorX*SysFontWidth<Ts.X2) and
  485. (CursorY*SysFontHeight>=Ts.Y1) and (CursorY*SysFontHeight<Ts.Y2) then
  486. for j:=0 to SysFontHeight-1 do
  487. begin
  488. if DefaultCursors[CursorType][(j*8) div SysFontHeight] then
  489. begin
  490. Graph.MoveTo(CursorX*SysFontWidth-Ts.X1,CursorY*SysFontHeight+j-Ts.Y1);
  491. Graph.LineRel(SysFontWidth-1,0);
  492. end;
  493. end;
  494. Graph.SetColor(StoreColor);
  495. graph.SetWriteMode(graph.CopyPut);
  496. end;
  497. Procedure HideCursor;
  498. begin
  499. If CursorIsVisible then
  500. begin
  501. XorPutCursor;
  502. CursorIsVisible:=false;
  503. end;
  504. end;
  505. Procedure ShowCursor;
  506. begin
  507. If not CursorIsVisible then
  508. begin
  509. XorPutCursor;
  510. CursorIsVisible:=true;
  511. end;
  512. end;
  513. { Position the cursor to the given position }
  514. procedure SetCursorPos(NewCursorX, NewCursorY: Word);
  515. begin
  516. HideCursor;
  517. CursorX:=NewCursorX;
  518. CursorY:=NewCursorY;
  519. ShowCursor;
  520. end;
  521. { Return the cursor type: Hidden, UnderLine or Block }
  522. function GetCursorType: Word;
  523. begin
  524. GetCursorType:=CursorType;
  525. end;
  526. { Set the cursor to the given type }
  527. procedure SetCursorType(NewType: Word);
  528. begin
  529. HideCursor;
  530. CursorType:=NewType;
  531. ShowCursor;
  532. end;
  533. const
  534. SetExtraInfoCalled : boolean = false;
  535. procedure SetExtraInfo(x,y,xi,yi : longint; color : word);
  536. var
  537. i,k,l : longint;
  538. extrainfo : pextrainfo;
  539. begin
  540. i:=y*TextScreenWidth+x;
  541. if not assigned(SpVideoBuf^[i]) or (SpVideoBuf^[i]=EmptyVideoBufCell) then
  542. begin
  543. GetMem(SpVideoBuf^[i],SysFontHeight*SysFontWidth*Sizeof(word));
  544. FillChar(SpVideoBuf^[i]^,SysFontHeight*SysFontWidth*Sizeof(word),#255);
  545. end;
  546. extrainfo:=SpVideoBuf^[i];
  547. l:=yi*SysFontWidth + xi;
  548. if l>=SysFontHeight*SysFontWidth then
  549. RunError(219);
  550. extrainfo^[l]:=color;
  551. SetExtraInfoCalled:=true;
  552. end;
  553. procedure SetupExtraInfo;
  554. begin
  555. if not assigned(EmptyVideoBufCell) then
  556. begin
  557. GetMem(EmptyVideoBufCell,SysFontHeight*SysFontWidth*Sizeof(word));
  558. FillChar(EmptyVideoBufCell^,SysFontHeight*SysFontWidth*Sizeof(word),#255);
  559. end;
  560. end;
  561. procedure FreeExtraInfo;
  562. var
  563. i : longint;
  564. begin
  565. HideCursor;
  566. if assigned(SpVideoBuf) then
  567. begin
  568. for i:=0 to (TextScreenWidth+1)*(TextScreenHeight+1) - 1 do
  569. if assigned(SpVideoBuf^[i]) and (SpVideoBuf^[i]<>EmptyVideoBufCell) then
  570. FreeMem(SpVideoBuf^[i],SysFontHeight*SysFontWidth*Sizeof(word));
  571. if assigned(EmptyVideoBufCell) then
  572. FreeMem(EmptyVideoBufCell,SysFontHeight*SysFontWidth*Sizeof(word));
  573. FreeMem(SpVideoBuf,sizeof(pextrainfo)*(TextScreenWidth+1)*(TextScreenHeight+1));
  574. SpVideoBuf:=nil;
  575. end;
  576. end;
  577. {define Use_ONLY_COLOR}
  578. procedure GraphUpdateScreen(Force: Boolean);
  579. var
  580. smallforce : boolean;
  581. i,x,y : longint;
  582. xi,yi,k,l : longint;
  583. ch : char;
  584. attr : byte;
  585. color : word;
  586. SavedColor : longint;
  587. {$ifndef Use_ONLY_COLOR}
  588. SavedBkColor,CurBkColor : longint;
  589. {$endif not Use_ONLY_COLOR}
  590. CurColor : longint;
  591. NextColor,NextBkColor : longint;
  592. StoreFillSettings: FillSettingsType;
  593. Ts: Graph.ViewPortType;
  594. {$ifdef debug}
  595. ChangedCount, SpecialCount : longint;
  596. {$endif debug}
  597. begin
  598. {$ifdef USE_VIDEO_API}
  599. if force or SetExtraInfoCalled then
  600. smallforce:=true
  601. else
  602. begin
  603. asm
  604. movl VideoBuf,%esi
  605. movl OldVideoBuf,%edi
  606. movl VideoBufSize,%ecx
  607. shrl $2,%ecx
  608. repe
  609. cmpsl
  610. orl %ecx,%ecx
  611. jz .Lno_update
  612. movb $1,smallforce
  613. .Lno_update:
  614. end;
  615. end;
  616. if SmallForce then
  617. begin
  618. {$ifdef debug}
  619. SpecialCount:=0;
  620. ChangedCount:=0;
  621. {$endif debug}
  622. SetExtraInfoCalled:=false;
  623. SavedColor:=Graph.GetColor;
  624. {$ifndef Use_ONLY_COLOR}
  625. SavedBkColor:=Graph.GetBkColor;
  626. CurBkColor:=SavedBkColor;
  627. {$endif not Use_ONLY_COLOR}
  628. CurColor:=SavedColor;
  629. Graph.GetViewSettings(Ts);
  630. Graph.SetViewPort(0,0,Graph.GetMaxX,Graph.GetMaxY,false);
  631. Graph.GetFillSettings(StoreFillSettings);
  632. {$ifdef Use_ONLY_COLOR}
  633. Graph.SetFillStyle(SolidFill,0);
  634. {$else not Use_ONLY_COLOR}
  635. Graph.SetFillStyle(EmptyFill,0);
  636. {$endif not Use_ONLY_COLOR}
  637. Graph.SetWriteMode(CopyPut);
  638. Graph.SetTextJustify(LeftText,TopText);
  639. for y := 0 to TextScreenHeight - 1 do
  640. begin
  641. for x := 0 to TextScreenWidth - 1 do
  642. begin
  643. i:=y*TextScreenWidth+x;
  644. if (OldVideoBuf^[i]<>VideoBuf^[i]) or
  645. (assigned(SpVideoBuf^[i]) and (SpVideoBuf^[i]<>EmptyVideoBufCell)) then
  646. begin
  647. ch:=chr(VideoBuf^[i] and $ff);
  648. if ch<>#0 then
  649. begin
  650. {$ifdef debug}
  651. Inc(ChangedCount);
  652. {$endif debug}
  653. if (SpVideoBuf^[i]=EmptyVideoBufCell) then
  654. SpVideoBuf^[i]:=nil;
  655. Attr:=VideoBuf^[i] shr 8;
  656. NextColor:=Attr and $f;
  657. NextBkColor:=(Attr and $70) shr 4;
  658. {$ifndef Use_ONLY_COLOR}
  659. if NextBkColor<>CurBkColor then
  660. begin
  661. Graph.SetBkColor(NextBkColor);
  662. CurBkColor:=NextBkColor;
  663. end;
  664. {$else Use_ONLY_COLOR}
  665. if NextBkColor<>CurColor then
  666. begin
  667. Graph.SetColor(NextBkColor);
  668. CurColor:=NextBkColor;
  669. end;
  670. {$endif Use_ONLY_COLOR}
  671. if (x=CursorX) and (y=CursorY) then
  672. HideCursor;
  673. Graph.Bar(x*SysFontWidth,y*SysFontHeight,(x+1)*SysFontWidth-1,(y+1)*SysFontHeight-1);
  674. if assigned(SpVideoBuf^[i]) then
  675. begin
  676. {$ifdef debug}
  677. Inc(SpecialCount);
  678. {$endif debug}
  679. For yi:=0 to SysFontHeight-1 do
  680. For xi:=0 to SysFontWidth-1 do
  681. begin
  682. l:=yi*SysFontWidth + xi;
  683. color:=SpVideoBuf^[i]^[l];
  684. if color<>$ffff then
  685. Graph.PutPixel(x*SysfontWidth+xi,y*SysFontHeight+yi,color);
  686. end;
  687. end;
  688. if NextColor<>CurColor then
  689. begin
  690. Graph.SetColor(NextColor);
  691. CurColor:=NextColor;
  692. end;
  693. { SetBkColor does change the palette index 0 entry...
  694. which leads to troubles if we want to write in dark }
  695. (* if (CurColor=0) and (ch<>' ') and assigned(SpVideoBuf^[i]) then
  696. begin
  697. Graph.SetBkColor(0);
  698. CurBkColor:=0;
  699. end; *)
  700. if ch<>' ' then
  701. Graph.OutTextXY(x*SysFontWidth,y*SysFontHeight+2,ch);
  702. if (x=CursorX) and (y=CursorY) then
  703. ShowCursor;
  704. end;
  705. OldVideoBuf^[i]:=VideoBuf^[i];
  706. if assigned(SpVideoBuf^[i]) then
  707. begin
  708. if (SpVideoBuf^[i]=EmptyVideoBufCell) then
  709. SpVideoBuf^[i]:=nil
  710. else
  711. begin
  712. FreeMem(SpVideoBuf^[i],SysFontHeight*SysFontWidth*sizeof(word));
  713. SpVideoBuf^[i]:=EmptyVideoBufCell;
  714. end;
  715. end;
  716. end;
  717. end;
  718. end;
  719. Graph.SetFillStyle(StoreFillSettings.pattern,StoreFillSettings.color);
  720. Graph.SetColor(SavedColor);
  721. {$ifndef Use_ONLY_COLOR}
  722. Graph.SetBkColor(SavedBkColor);
  723. {$endif not Use_ONLY_COLOR}
  724. Graph.SetViewPort(TS.X1,Ts.Y1,ts.X2,ts.Y2,ts.Clip);
  725. end;
  726. {$else not USE_VIDEO_API}
  727. RunError(219);
  728. {$endif USE_VIDEO_API}
  729. end;
  730. {$ENDIF GRAPH_API}
  731. END.
  732. {
  733. $Log$
  734. Revision 1.18 2002-09-07 15:06:36 peter
  735. * old logs removed and tabs fixed
  736. Revision 1.17 2002/08/22 13:40:49 pierre
  737. * several graphic mode improovements
  738. Revision 1.16 2002/06/06 06:41:14 pierre
  739. + Cursor functions for UseFixedFont case
  740. Revision 1.15 2002/05/31 12:37:47 pierre
  741. * try to enhance graph mode
  742. Revision 1.14 2002/05/29 22:15:57 pierre
  743. * fix build failure in non graph mode
  744. Revision 1.13 2002/05/29 19:35:31 pierre
  745. * fix GraphUpdateScreen procedure
  746. Revision 1.12 2002/05/28 19:42:32 pierre
  747. * fix non graphic mode compilation
  748. Revision 1.11 2002/05/28 19:13:44 pierre
  749. + GraphUpdateScreen function
  750. }