graph.pp 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546
  1. unit Graph;
  2. { *********************************************************************
  3. $Id$
  4. Copyright 1997,1998 Matthias K"oppe <[email protected]>
  5. This library is free software in the sense of the GNU Library GPL;
  6. see `License Conditions' below.
  7. Info:
  8. This unit provides the functions of Borland's Graph unit for linux,
  9. it uses the SVGAlib to do the actual work, so you must have svgalib
  10. on your system
  11. This version requires Free Pascal 0.99.5 or higher.
  12. Large parts have not yet been implemented or tested.
  13. History:
  14. Date Version Who Comments
  15. ---------- -------- ------- -------------------------------------
  16. 25-Sep-97 0.1 mkoeppe Initial multi-target version.
  17. 05-Oct-97 0.1.1 mkoeppe Linux: Added mouse use. Improved clipping.
  18. Added bitmap functions.
  19. ??-Oct-97 0.1.2 mkoeppe Fixed screenbuf functions.
  20. 07-Feb-98 0.1.3 mkoeppe Fixed a clipping bug in DOS target.
  21. 12-Apr-98 0.1.4 mkoeppe Linux: Using Michael's re-worked SVGALIB
  22. interface; prepared for FPC 0.99.5; removed
  23. dependencies.
  24. 15-Apr-98 0.1.5 michael Renamed to graph, inserted needed SVGlib
  25. declarations here so it can be used independently
  26. of the svgalib unit. Removed things that are NOT
  27. part of Borland's Graph from the unit interface.
  28. License Conditions:
  29. This library is free software; you can redistribute it and/or
  30. modify it under the terms of the GNU Library General Public
  31. License as published by the Free Software Foundation; either
  32. version 2 of the License, or (at your option) any later version.
  33. This library is distributed in the hope that it will be useful,
  34. but WITHOUT ANY WARRANTY; without even the implied warranty of
  35. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  36. Library General Public License for more details.
  37. You should have received a copy of the GNU Library General Public
  38. License along with this library; if not, write to the Free
  39. Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  40. *********************************************************************}
  41. {
  42. Functions not currently implemented :
  43. -------------------------------------
  44. SetWriteMode
  45. SetLineStyle
  46. SetFillPattern
  47. SetUserCharSize
  48. SetTextStyle
  49. FillPoly
  50. FloodFill
  51. SetAspectRatio
  52. (please remove what you implement fom this list)
  53. }
  54. interface
  55. { ---------------------------------------------------------------------
  56. Constants
  57. ---------------------------------------------------------------------}
  58. const
  59. NormalPut = 0;
  60. CopyPut = 0;
  61. XORPut = 1;
  62. ORPut = 2;
  63. ANDPut = 3;
  64. NotPut = 4;
  65. BackPut = 8;
  66. Black = 0;
  67. Blue = 1;
  68. Green = 2;
  69. Cyan = 3;
  70. Red = 4;
  71. Magenta = 5;
  72. Brown = 6;
  73. LightGray = 7;
  74. DarkGray = 8;
  75. LightBlue = 9;
  76. LightGreen = 10;
  77. LightCyan = 11;
  78. LightRed = 12;
  79. LightMagenta = 13;
  80. Yellow = 14;
  81. White = 15;
  82. Border = 16;
  83. SolidLn = 0;
  84. DottedLn = 1;
  85. CenterLn = 2;
  86. DashedLn = 3;
  87. UserBitLn = 4;
  88. EmptyFill = 0;
  89. SolidFill = 1;
  90. LineFill = 2;
  91. LtSlashFill = 3;
  92. SlashFill = 4;
  93. BkSlashFill = 5;
  94. LtBkSlashFill = 6;
  95. HatchFill = 7;
  96. XHatchFill = 8;
  97. InterleaveFill = 9;
  98. WideDotFill = 10;
  99. CloseDotFill = 11;
  100. UserFill = 12;
  101. NormWidth = 1;
  102. ThickWidth = 3;
  103. const
  104. LeftText = 0;
  105. CenterText = 1;
  106. RightText = 2;
  107. BottomText = 0;
  108. TopText = 2;
  109. BaseLine = 3;
  110. LeadLine = 4;
  111. { ---------------------------------------------------------------------
  112. Types
  113. ---------------------------------------------------------------------}
  114. Type
  115. FillPatternType = array[1..8] of byte;
  116. ArcCoordsType = record
  117. x,y : integer;
  118. xstart,ystart : integer;
  119. xend,yend : integer;
  120. end;
  121. RGBColor = record
  122. r,g,b,i : byte;
  123. end;
  124. PaletteType = record
  125. Size : integer;
  126. Colors : array[0..767]of Byte;
  127. end;
  128. LineSettingsType = record
  129. linestyle : word;
  130. pattern : word;
  131. thickness : word;
  132. end;
  133. TextSettingsType = record
  134. font : word;
  135. direction : word;
  136. charsize : word;
  137. horiz : word;
  138. vert : word;
  139. end;
  140. FillSettingsType = record
  141. pattern : word;
  142. color : longint;
  143. end;
  144. PointType = record
  145. x,y : integer;
  146. end;
  147. ViewPortType = record
  148. x1,y1,x2,y2 : integer;
  149. Clip : boolean;
  150. end;
  151. const
  152. fillpattern : array[0..12] of FillPatternType = (
  153. ($00,$00,$00,$00,$00,$00,$00,$00), { Hintergrundfarbe }
  154. ($ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff), { Vordergrundfarbe }
  155. ($ff,$ff,$00,$00,$ff,$ff,$00,$00), { === }
  156. ($01,$02,$04,$08,$10,$20,$40,$80), { /// }
  157. ($07,$0e,$1c,$38,$70,$e0,$c1,$83), { /// als dicke Linien }
  158. ($07,$83,$c1,$e0,$70,$38,$1c,$0e), { \\\ als dicke Linien }
  159. ($5a,$2d,$96,$4b,$a5,$d2,$69,$b4), { \ \\ \ }
  160. ($ff,$88,$88,$88,$ff,$88,$88,$88), { K„stchen }
  161. ($18,$24,$42,$81,$81,$42,$24,$18), { Rauten }
  162. ($cc,$33,$cc,$33,$cc,$33,$cc,$33), { "Mauermuster" }
  163. ($80,$00,$08,$00,$80,$00,$08,$00), { weit auseinanderliegende Punkte }
  164. ($88,$00,$22,$00,$88,$00,$22,$00), { dichte Punkte}
  165. (0,0,0,0,0,0,0,0) { benutzerdefiniert }
  166. );
  167. { ---------------------------------------------------------------------
  168. Function Declarations
  169. ---------------------------------------------------------------------}
  170. { Retrieving coordinates }
  171. function GetX: Integer;
  172. function GetY: Integer;
  173. { Pixel-oriented routines }
  174. procedure PutPixel(X, Y: Integer; Pixel: Word);
  175. function GetPixel(X, Y: Integer): Word;
  176. { Line-oriented primitives }
  177. procedure SetWriteMode(WriteMode: Integer);
  178. procedure LineTo(X, Y: Integer);
  179. procedure LineRel(Dx, Dy: Integer);
  180. procedure MoveTo(X, Y: Integer);
  181. procedure MoveRel(Dx, Dy: Integer);
  182. procedure Line(x1, y1, x2, y2: Integer);
  183. procedure SetLineStyle(LineStyle: Word; Pattern: Word; Thickness: Word);
  184. { Linearly bounded primitives }
  185. procedure Rectangle(x1, y1, x2, y2: Integer);
  186. procedure Bar(x1, y1, x2, y2: Integer);
  187. procedure Bar3D(x1, y1, x2, y2: Integer; Depth: Word; Top: Boolean);
  188. procedure DrawPoly(NumPoints: Word; var PolyPoints);
  189. procedure FillPoly(NumPoints: Word; var PolyPoints);
  190. procedure SetFillStyle(Pattern: Word; Color: Word);
  191. procedure SetFillPattern(Pattern: FillPatternType; Color: Word);
  192. procedure FloodFill(X, Y: Integer; Border: Word);
  193. { Nonlinearly bounded primitives }
  194. procedure Arc(X, Y: Integer; StAngle, EndAngle, Radius: Word);
  195. procedure GetArcCoords(var ArcCoords: ArcCoordsType);
  196. procedure Circle(X, Y: Integer; Radius: Word);
  197. procedure Ellipse(X, Y: Integer; StAngle, EndAngle: Word; XRadius, YRadius : Word);
  198. procedure FillEllipse(X, Y: Integer; XRadius, YRadius : Word);
  199. procedure SetAspectRatio(Xasp, Yasp: Word);
  200. procedure PieSlice(X, Y: Integer; StAngle, EndAngle, Radius: Word);
  201. procedure Sector(X, Y: Integer; StAngle, EndAngle, XRadius, YRadius: Word);
  202. { Color routines }
  203. procedure SetBkColor(ColorNum: Word);
  204. procedure SetColor(Color: Word);
  205. { Bitmap utilities }
  206. procedure GetImage(x1, y1, x2, y2: Integer; var BitMap);
  207. procedure PutImage(X, Y: Integer; var BitMap; BitBlt: Word);
  208. function ImageSize(x1, y1, x2, y2: Integer): LongInt;
  209. { Text routines}
  210. procedure OutText(TextString: string);
  211. procedure OutTextXY(X, Y: Integer; TextString: string);
  212. procedure SetTextJustify(Horiz, Vert: Word);
  213. procedure SetTextStyle(Font, Direction: Word; CharSize: Word);
  214. procedure SetUserCharSize(MultX, DivX, MultY, DivY: Word);
  215. { Graph clipping method }
  216. procedure SetViewPort(x1, y1, x2, y2: Integer; Clip: Boolean);
  217. { Init/Done }
  218. procedure InitVideo;
  219. procedure DoneVideo;
  220. { Other }
  221. function GetResX: Integer;
  222. function GetResY: Integer;
  223. function GetAspect: Real;
  224. function GetMaxX : Integer;
  225. function GetMAxY : Integer;
  226. { For compatibility }
  227. Procedure DetectGraph (Var Driver,Mode : Integer);
  228. Procedure InitGraph (Var Driver,Mode : Integer;DriverPath : String);
  229. Procedure CloseGraph;
  230. const
  231. NoGraphics: Boolean = false;
  232. { VGA modes }
  233. GTEXT = 0; { Compatible with VGAlib v1.2 }
  234. G320x200x16 = 1;
  235. G640x200x16 = 2;
  236. G640x350x16 = 3;
  237. G640x480x16 = 4;
  238. G320x200x256 = 5;
  239. G320x240x256 = 6;
  240. G320x400x256 = 7;
  241. G360x480x256 = 8;
  242. G640x480x2 = 9;
  243. G640x480x256 = 10;
  244. G800x600x256 = 11;
  245. G1024x768x256 = 12;
  246. G1280x1024x256 = 13; { Additional modes. }
  247. G320x200x32K = 14;
  248. G320x200x64K = 15;
  249. G320x200x16M = 16;
  250. G640x480x32K = 17;
  251. G640x480x64K = 18;
  252. G640x480x16M = 19;
  253. G800x600x32K = 20;
  254. G800x600x64K = 21;
  255. G800x600x16M = 22;
  256. G1024x768x32K = 23;
  257. G1024x768x64K = 24;
  258. G1024x768x16M = 25;
  259. G1280x1024x32K = 26;
  260. G1280x1024x64K = 27;
  261. G1280x1024x16M = 28;
  262. G800x600x16 = 29;
  263. G1024x768x16 = 30;
  264. G1280x1024x16 = 31;
  265. G720x348x2 = 32; { Hercules emulation mode }
  266. G320x200x16M32 = 33; { 32-bit per pixel modes. }
  267. G640x480x16M32 = 34;
  268. G800x600x16M32 = 35;
  269. G1024x768x16M32 = 36;
  270. G1280x1024x16M32 = 37;
  271. { additional resolutions }
  272. G1152x864x16 = 38;
  273. G1152x864x256 = 39;
  274. G1152x864x32K = 40;
  275. G1152x864x64K = 41;
  276. G1152x864x16M = 42;
  277. G1152x864x16M32 = 43;
  278. G1600x1200x16 = 44;
  279. G1600x1200x256 = 45;
  280. G1600x1200x32K = 46;
  281. G1600x1200x64K = 47;
  282. G1600x1200x16M = 48;
  283. G1600x1200x16M32 = 49;
  284. GLASTMODE = 49;
  285. implementation
  286. uses Objects, Linux;
  287. { ---------------------------------------------------------------------
  288. SVGA bindings.
  289. ---------------------------------------------------------------------}
  290. { Link with VGA, gl and c libraries }
  291. {$linklib vga}
  292. {$linklib vgagl}
  293. {$linklib c}
  294. Const
  295. { Text }
  296. WRITEMODE_OVERWRITE = 0;
  297. WRITEMODE_MASKED = 1;
  298. FONT_EXPANDED = 0;
  299. FONT_COMPRESSED = 2;
  300. { Types }
  301. type
  302. pvga_modeinfo = ^vga_modeinfo;
  303. vga_modeinfo = record
  304. width,
  305. height,
  306. bytesperpixel,
  307. colors,
  308. linewidth, { scanline width in bytes }
  309. maxlogicalwidth, { maximum logical scanline width }
  310. startaddressrange, { changeable bits set }
  311. maxpixels, { video memory / bytesperpixel }
  312. haveblit, { mask of blit functions available }
  313. flags: Longint; { other flags }
  314. { Extended fields: }
  315. chiptype, { Chiptype detected }
  316. memory, { videomemory in KB }
  317. linewidth_unit: Longint; { Use only a multiple of this as parameter for set_displaystart }
  318. linear_aperture: PChar; { points to mmap secondary mem aperture of card }
  319. aperture_size: Longint; { size of aperture in KB if size>=videomemory.}
  320. set_aperture_page: procedure (page: Longint);
  321. { if aperture_size<videomemory select a memory page }
  322. extensions: Pointer; { points to copy of eeprom for mach32 }
  323. { depends from actual driver/chiptype.. etc. }
  324. end;
  325. PGraphicsContext = ^TGraphicsContext;
  326. TGraphicsContext = record
  327. ModeType: Byte;
  328. ModeFlags: Byte;
  329. Dummy: Byte;
  330. FlipPage: Byte;
  331. Width: LongInt;
  332. Height: LongInt;
  333. BytesPerPixel: LongInt;
  334. Colors: LongInt;
  335. BitsPerPixel: LongInt;
  336. ByteWidth: LongInt;
  337. VBuf: pointer;
  338. Clip: LongInt;
  339. ClipX1: LongInt;
  340. ClipY1: LongInt;
  341. ClipX2: LongInt;
  342. ClipY2: LongInt;
  343. ff: pointer;
  344. end;
  345. { vga functions }
  346. Function vga_init: Longint; Cdecl; External;
  347. Function vga_getdefaultmode: Longint; Cdecl; External;
  348. Function vga_hasmode(mode: Longint): Boolean; Cdecl; External;
  349. Function vga_getmodeinfo(mode: Longint): pvga_modeinfo; Cdecl; External;
  350. Function vga_setmode(mode: Longint): Longint; Cdecl; External;
  351. Function vga_getxdim : Longint; cdecl;external;
  352. Function vga_getydim : longint; cdecl;external;
  353. { gl functions }
  354. procedure gl_setpixel(x, y, c: LongInt); Cdecl; External;
  355. function gl_getpixel(x, y: LongInt): LongInt; cdecl; external;
  356. procedure gl_line(x1, y1, x2, y2, c: LongInt); Cdecl; External;
  357. procedure gl_fillbox(x, y, w, h, c: LongInt); Cdecl; External;
  358. procedure gl_circle(x, y, r, c: LongInt ); Cdecl; External;
  359. procedure gl_getbox(x, y, w, h: LongInt; dp: pointer); Cdecl; External;
  360. procedure gl_putbox(x, y, w, h: LongInt; dp: pointer); Cdecl; External;
  361. procedure gl_disableclipping; Cdecl; External;
  362. procedure gl_enableclipping; Cdecl; External;
  363. procedure gl_putboxpart(x, y, w, h, bw, bh: LongInt; b: pointer; xo, yo: LongInt); Cdecl; External;
  364. function gl_rgbcolor(r, g, b: LongInt): LongInt; Cdecl; External;
  365. function gl_setcontextvga(m: LongInt): LongInt; Cdecl; External;
  366. function gl_allocatecontext: PGraphicsContext; Cdecl; External;
  367. procedure gl_getcontext(gc: PGraphicsContext); Cdecl; External;
  368. procedure gl_setrgbpalette; Cdecl; External;
  369. procedure gl_freecontext(gc: PGraphicsContext); Cdecl; External;
  370. procedure gl_setclippingwindow(x1, y1, x2, y2: LongInt); Cdecl; External;
  371. procedure gl_setwritemode(wm: LongInt); Cdecl; External;
  372. procedure gl_setfontcolors(bg, fg: LongInt); Cdecl; External;
  373. procedure gl_writen(x, y, n: LongInt; s: PChar); Cdecl; External;
  374. procedure gl_setfont(fw, fh: LongInt; fdp: pointer); Cdecl; External;
  375. procedure gl_copyboxfromcontext(var gc: TGraphicsContext; x1, y1, w, h, x2, y2: LongInt); Cdecl; External;
  376. procedure gl_setcontext(gc: PGraphicsContext); Cdecl; External;
  377. function gl_setcontextvgavirtual(m: LongInt): LongInt; cdecl; external;
  378. procedure gl_font8x8; Cdecl; External;
  379. { ---------------------------------------------------------------------
  380. Types, constants and variables
  381. ---------------------------------------------------------------------}
  382. var
  383. DrawDelta: TPoint;
  384. CurX, CurY: Integer;
  385. TheColor, TheFillColor: LongInt;
  386. IsVirtual: Boolean;
  387. PhysicalScreen, BackScreen: PGraphicsContext;
  388. ColorTable: array[0..15] of LongInt;
  389. const
  390. BgiColors: array[0..15] of LongInt
  391. = ($000000, $000080, $008000, $008080,
  392. $800000, $800080, $808000, $C0C0C0,
  393. $808080, $0000FF, $00FF00, $00FFFF,
  394. $FF0000, $FF00FF, $FFFF00, $FFFFFF);
  395. const
  396. DoUseMarker: Boolean = true;
  397. TheMarker: Char = '~';
  398. TextColor: LongInt = 15;
  399. MarkColor: LongInt = 15;
  400. BackColor: LongInt = 0;
  401. FontWidth: Integer = 8;
  402. FontHeight: Integer = 8;
  403. var
  404. sHoriz, sVert: Word;
  405. { initialisierte Variablen }
  406. const
  407. SourcePage: Word = 0;
  408. DestPage: Word = 0;
  409. { Retrieves the capabilities for the current mode }
  410. const
  411. vmcImage = 1;
  412. vmcCopy = 2;
  413. vmcSaveRestore = 4;
  414. vmcBuffer = 8;
  415. vmcBackPut = 16;
  416. { ---------------------------------------------------------------------
  417. Graphics Vision Layer
  418. ---------------------------------------------------------------------}
  419. { Types and constants }
  420. var
  421. SizeX, SizeY: Word;
  422. { Draw origin and clipping rectangle }
  423. var
  424. DrawOrigin: TPoint;
  425. ClipRect: TRect;
  426. MetaClipRect: TRect;
  427. MetaOrigin: TPoint;
  428. { Font attributes }
  429. const
  430. ftNormal = 0;
  431. ftBold = 1;
  432. ftThin = 2;
  433. ftItalic = 4;
  434. var
  435. sFont, sColor:Word;
  436. sCharSpace: Integer;
  437. { Not used
  438. sMarker: Char;
  439. sAttr: Word; }
  440. { Windows-style text metric }
  441. type
  442. PTextMetric = ^TTextMetric;
  443. TTextMetric = record
  444. tmHeight: Integer;
  445. tmAscent: Integer;
  446. tmDescent: Integer;
  447. tmInternalLeading: Integer;
  448. tmExternalLeading: Integer;
  449. tmAveCharWidth: Integer;
  450. tmMaxCharWidth: Integer;
  451. tmWeight: Integer;
  452. tmItalic: Byte;
  453. tmUnderlined: Byte;
  454. tmStruckOut: Byte;
  455. tmFirstChar: Byte;
  456. tmLastChar: Byte;
  457. tmDefaultChar: Byte;
  458. tmBreakChar: Byte;
  459. tmPitchAndFamily: Byte;
  460. tmCharSet: Byte;
  461. tmOverhang: Integer;
  462. tmDigitizedAspectX: Integer;
  463. tmDigitizedAspectY: Integer;
  464. end;
  465. { Bitmap utilities }
  466. type
  467. PBitmap = ^TBitmap;
  468. TBitmap = record
  469. Width, Height: Integer;
  470. Data: record end;
  471. end;
  472. { Storing screen regions }
  473. type
  474. TVgaBuf = record
  475. Bounds: TRect;
  476. Mem: Word;
  477. Size: Word;
  478. end;
  479. const
  480. pbNone = 0;
  481. pbCopy = 1;
  482. pbClear = 2;
  483. type
  484. PScreenBuf = ^TScreenBuf;
  485. TScreenBuf = record
  486. Mode: Word;
  487. Rect: TRect;
  488. Size: LongInt;
  489. Info: LongInt
  490. end;
  491. { Procedures and functions }
  492. procedure SetColors;
  493. var
  494. i: Integer;
  495. begin
  496. for i:=0 to 15 do
  497. ColorTable[i] := gl_rgbcolor(BgiColors[i] shr 16,
  498. (BgiColors[i] shr 8) and 255,
  499. BgiColors[i] and 255)
  500. end;
  501. procedure InitVideo;
  502. var
  503. VgaMode: Integer;
  504. ModeInfo: pvga_modeinfo;
  505. begin
  506. if NoGraphics
  507. then begin
  508. SizeX := 640;
  509. SizeY := 480
  510. end
  511. else begin
  512. VgaMode := vga_getdefaultmode;
  513. if (VgaMode = -1) then VgaMode := G320X200X256;
  514. if (not vga_hasmode(VgaMode))
  515. then begin
  516. WriteLn('BGI: Mode not available.');
  517. Halt(1)
  518. end;
  519. ModeInfo := vga_getmodeinfo(VgaMode);
  520. {IsVirtual := (ModeInfo^.colors = 16) or (ModeInfo^.flags and IS_MODEX <> 0);}
  521. IsVirtual := true;
  522. { We always want a back screen (for buffering). }
  523. if IsVirtual
  524. then begin
  525. { Create virtual screen }
  526. gl_setcontextvgavirtual(VgaMode);
  527. BackScreen := gl_allocatecontext;
  528. gl_getcontext(BackScreen)
  529. end;
  530. vga_setmode(VgaMode);
  531. gl_setcontextvga(VgaMode); { Physical screen context. }
  532. PhysicalScreen := gl_allocatecontext;
  533. gl_getcontext(PhysicalScreen);
  534. if (PhysicalScreen^.colors = 256) then gl_setrgbpalette;
  535. SetColors;
  536. SizeX := PhysicalScreen^.Width;
  537. SizeY := PhysicalScreen^.Height
  538. end
  539. end;
  540. procedure DoneVideo;
  541. begin
  542. if not NoGraphics
  543. then begin
  544. if IsVirtual then gl_freecontext(BackScreen);
  545. vga_setmode(GTEXT)
  546. end
  547. end;
  548. procedure SetDelta;
  549. begin
  550. if ClipRect.Empty
  551. then begin
  552. DrawDelta.X := 10000;
  553. DrawDelta.Y := 10000;
  554. end
  555. else begin
  556. DrawDelta.X := DrawOrigin.X;
  557. DrawDelta.y := DrawOrigin.y
  558. end
  559. end;
  560. procedure SetDrawOrigin(x, y: Integer);
  561. begin
  562. DrawOrigin.x := x;
  563. DrawOrigin.y := y;
  564. SetDelta;
  565. end;
  566. procedure SetDrawOriginP(var P: TPoint);
  567. begin
  568. SetDrawOrigin(P.x, P.y)
  569. end;
  570. procedure SetClipRect(x1, y1, x2, y2: Integer);
  571. begin
  572. Cliprect.Assign(x1, y1, x2, y2);
  573. if not NoGraphics
  574. then begin
  575. if ClipRect.Empty
  576. then gl_setclippingwindow(0, 0, 0, 0)
  577. else gl_setclippingwindow(x1, y1, x2 - 1, y2 - 1);
  578. {gl_enableclipping(0);}
  579. end;
  580. SetDelta
  581. end;
  582. procedure SetClipRectR(var R: TRect);
  583. begin
  584. SetClipRect(R.A.X, R.A.Y, R.B.X, R.B.Y);
  585. end;
  586. procedure SetMetaOrigin(x, y: Integer);
  587. begin
  588. MetaOrigin.x := x;
  589. MetaOrigin.y := y
  590. end;
  591. procedure SetMetaOriginP(P: TPoint);
  592. begin
  593. SetMetaOrigin(P.x, P.y)
  594. end;
  595. procedure SetMetaClipRect(x1, y1, x2, y2: Integer);
  596. begin
  597. MetaCliprect.Assign(x1, y1, x2, y2)
  598. end;
  599. procedure SetMetaClipRectR(var R: TRect);
  600. begin
  601. MetaCliprect := R
  602. end;
  603. function GetBuffer(Size: Word): pointer;
  604. begin
  605. { No metafiling available. }
  606. GetBuffer := nil
  607. end;
  608. Procedure HoriLine(x1,y1,x2: Integer);
  609. begin
  610. Line(x1, y1, x2, y1)
  611. end;
  612. Procedure VertLine(x1,y1,y2: Integer);
  613. begin
  614. Line(x1, y1, x1, y2)
  615. end;
  616. procedure FillCircle(xm, ym, r: Integer);
  617. begin
  618. FillEllipse(xm, ym, r, r)
  619. end;
  620. { Text routines }
  621. function TextWidth(s: string): Integer;
  622. var
  623. i: Integer;
  624. begin
  625. if DoUseMarker
  626. then begin
  627. For i := Length(s) downto 1 do
  628. If s[i] = TheMarker then Delete(s, i, 1);
  629. If s = ''
  630. then TextWidth := 0
  631. else TextWidth := Length(s) * FontWidth
  632. end
  633. else TextWidth := Length(s) * FontWidth
  634. end;
  635. function TextHeight(s: string): Integer;
  636. begin
  637. TextHeight := FontHeight
  638. end;
  639. procedure OutText(TextString: string);
  640. begin
  641. OutTextXY(GetX, GetY, TextString)
  642. end;
  643. procedure OutTextXY(X, Y: Integer; TextString: string);
  644. var
  645. P, Q: PChar;
  646. i: Integer;
  647. col: Boolean;
  648. begin
  649. if NoGraphics or (TextString='') then Exit;
  650. gl_setwritemode(FONT_COMPRESSED + WRITEMODE_MASKED);
  651. case sHoriz of
  652. CenterText : Dec(x, TextWidth(TextString) div 2);
  653. RightText : Dec(x, TextWidth(TextString));
  654. end; { case }
  655. case sVert of
  656. CenterText : Dec(y, TextHeight(TextString) div 2);
  657. BottomText, BaseLine : Dec(y, TextHeight(TextString));
  658. end; { case }
  659. MoveTo(X, Y);
  660. P := @TextString[1]; Q := P;
  661. col := false;
  662. gl_setfontcolors(BackColor, TextColor);
  663. For i := 1 to Length(TextString) do
  664. begin
  665. If (Q[0] = TheMarker) and DoUseMarker
  666. then begin
  667. If col then gl_setfontcolors(BackColor, MarkColor)
  668. else gl_setfontcolors(BackColor, TextColor);
  669. If Q <> P then begin
  670. gl_writen(CurX, CurY, Q-P, P);
  671. MoveRel(FontWidth * (Q-P), 0)
  672. end;
  673. col := not col;
  674. P := Q + 1
  675. end;
  676. {Inc(Q)} Q := Q + 1
  677. end;
  678. If col then gl_setfontcolors(BackColor, MarkColor)
  679. else gl_setfontcolors(BackColor, TextColor);
  680. If Q <> P then begin
  681. gl_writen(CurX, CurY, Q-P, P);
  682. MoveRel(FontWidth * (Q-P), 0)
  683. end
  684. end;
  685. procedure SetTextJustify(Horiz, Vert: Word);
  686. begin
  687. sHoriz := Horiz; sVert := Vert;
  688. end;
  689. procedure SetTextStyle(Font, Direction: Word; CharSize: Word);
  690. begin
  691. end;
  692. procedure SetUserCharSize(MultX, DivX, MultY, DivY: Word);
  693. begin
  694. end;
  695. procedure SetKern(Enable: Boolean);
  696. begin
  697. end;
  698. procedure SetMarker(Marker: Char);
  699. begin
  700. TheMarker := Marker
  701. end;
  702. procedure SetTextParams(Font: Word; CharSpace: Integer; Color: Word;
  703. UseMarker: Boolean);
  704. type
  705. pp = ^pointer;
  706. function FixCol(Col: Byte): Byte;
  707. { SVGALIB cannot write black characters... }
  708. begin
  709. if Col=0 then FixCol := 1 else FixCol := Col
  710. end; { FixCol }
  711. begin
  712. sColor := Color; sCharSpace := CharSpace; sFont := Font;
  713. if not NoGraphics then begin
  714. TextColor := ColorTable[FixCol(Color and 15)];
  715. MarkColor := ColorTable[FixCol((Color shr 8) and 15)];
  716. DoUseMarker := UseMarker;
  717. gl_setfont(8, 8, (pp(@gl_font8x8))^);
  718. end
  719. end;
  720. function GetResX: Integer;
  721. begin
  722. GetResX := 96;
  723. end; { GetResX }
  724. function GetResY: Integer;
  725. begin
  726. GetResY := 96
  727. end; { GetResY }
  728. function GetAspect: Real;
  729. begin
  730. GetAspect := 1.0
  731. end; { GetAspect }
  732. procedure SetViewPort(x1, y1, x2, y2: Integer; Clip: Boolean);
  733. begin
  734. SetDrawOrigin(x1, y1);
  735. if Clip then SetClipRect(x1, y1, x2+1, y2+1)
  736. else SetClipRect(0, 0, SizeX, SizeY)
  737. end;
  738. { VGAMEM }
  739. type
  740. TImage = record
  741. end;
  742. procedure CopyScreen(x1, y1, x2, y2, x3, y3: Integer);
  743. begin
  744. if not NoGraphics and (x2 > x1) and (y2 > y1)
  745. then gl_copyboxfromcontext(PhysicalScreen^, x1, y1, x2 - x1, y2 - y1, x3, y3);
  746. end;
  747. { BGI-like Image routines
  748. }
  749. function CopyImage(Image: pointer): pointer;
  750. begin
  751. CopyImage := nil
  752. end;
  753. function CutImage(x1, y1, x2, y2: Integer): pointer;
  754. var
  755. Image: PBitmap;
  756. begin
  757. GetMem(Image, ImageSize(x1, y1, x2, y2));
  758. if Image <> nil
  759. then GetImage(x1, y1, x2, y2, Image^);
  760. CutImage := Image;
  761. end;
  762. procedure GetImageExtent(Image: pointer; var Extent: Objects.TPoint);
  763. begin
  764. if Image = nil
  765. then begin
  766. Extent.X := 0;
  767. Extent.Y := 0
  768. end
  769. else begin
  770. Extent.X := PBitmap(Image)^.Width;
  771. Extent.Y := PBitmap(Image)^.Height
  772. end;
  773. end;
  774. procedure FreeImage(Image: pointer);
  775. var
  776. P: TPoint;
  777. begin
  778. if Image <> nil
  779. then begin
  780. GetImageExtent(Image, P);
  781. FreeMem(Image, ImageSize(0, 0, P.x - 1, P.y - 1));
  782. end;
  783. end;
  784. function LoadImage(var S: TStream): pointer;
  785. begin
  786. LoadImage := nil
  787. end;
  788. function MaskedImage(Image: pointer): pointer;
  789. begin
  790. MaskedImage := nil;
  791. end;
  792. procedure PasteImage(X, Y: Integer; Image: pointer; BitBlt: Word);
  793. begin
  794. if Image <> nil then PutImage(X, Y, Image^, BitBlt)
  795. end;
  796. procedure StoreImage(var S: TStream; Image: pointer);
  797. begin
  798. end;
  799. { Storing screen regions }
  800. function PrepBuf(var R: Objects.TRect; Action: Word; var Buf: TVgaBuf): Boolean;
  801. begin
  802. if BackScreen <> nil
  803. then begin
  804. Buf.Bounds := R;
  805. gl_setcontext(BackScreen);
  806. gl_disableclipping;
  807. case Action of
  808. pbCopy : gl_copyboxfromcontext(PhysicalScreen^,
  809. R.A.X, R.A.Y, R.B.X - R.A.X, R.B.Y - R.A.Y,
  810. R.A.X, R.A.Y);
  811. pbClear : gl_fillbox(R.A.X, R.A.Y, R.B.X - R.A.X, R.B.Y - R.A.Y, 0);
  812. end;
  813. PrepBuf := true;
  814. SetDrawOrigin(0, 0);
  815. SetClipRectR(R);
  816. end
  817. else PrepBuf := false
  818. end; { PrepBuf }
  819. procedure EndBufDraw;
  820. begin
  821. if not NoGraphics
  822. then gl_setcontext(PhysicalScreen);
  823. end; { EndBufDraw }
  824. procedure ReleaseBuf(var Buf: TVgaBuf);
  825. begin
  826. end; { ReleaseBuf }
  827. procedure PasteRectAt(var R: Objects.TRect; P: Objects.TPoint; var Buf: TVgaBuf);
  828. begin
  829. if not NoGraphics and (BackScreen <> nil)
  830. then gl_copyboxfromcontext(BackScreen^,
  831. R.A.X, R.A.Y, R.B.X - R.A.X, R.B.Y - R.A.Y,
  832. P.X, P.Y);
  833. end;
  834. procedure PasteRect(var R: Objects.TRect; var Buf: TVgaBuf);
  835. begin
  836. PasteRectAt(R, R.A, Buf);
  837. end; { PasteRect }
  838. function StoreScreen(x1, y1, x2, y2: Integer): PScreenBuf;
  839. var
  840. s: LongInt;
  841. p: pointer;
  842. SaveOrigin: TPoint;
  843. function NewScreenBuf(AMode: Word; AnInfo: LongInt): PScreenBuf;
  844. var
  845. p: PScreenBuf;
  846. Begin
  847. New(p);
  848. p^.Mode := AMode;
  849. p^.Size := s;
  850. p^.Rect.Assign(x1, y1, x2, y2);
  851. p^.Info := AnInfo;
  852. NewScreenBuf := p
  853. End;
  854. Begin
  855. { General Images }
  856. s := 0;
  857. SaveOrigin := DrawOrigin;
  858. SetDrawOrigin(0, 0);
  859. p := CutImage(x1, y1, x2-1, y2-1);
  860. SetDrawOriginP(SaveOrigin);
  861. If p <> nil
  862. then StoreScreen := NewScreenBuf(2, LongInt(p))
  863. else StoreScreen := nil
  864. End;
  865. procedure FreeScreenBuf(Buf: PScreenBuf);
  866. Begin
  867. If Buf <> nil then Begin
  868. case Buf^.Mode of
  869. 2 : FreeImage(pointer(Buf^.Info));
  870. end;
  871. Dispose(Buf)
  872. End
  873. End;
  874. procedure DrawScreenBufAt(Buf: PScreenBuf; x3, y3: Integer);
  875. var
  876. SaveOrigin: TPoint;
  877. Begin
  878. If Buf <> nil then
  879. case Buf^.Mode of
  880. 2 :
  881. begin
  882. SaveOrigin := DrawOrigin;
  883. SetDrawOrigin(0, 0);
  884. PasteImage(x3, y3, pointer(Buf^.Info), NormalPut);
  885. SetDrawOriginP(SaveOrigin);
  886. end
  887. end
  888. End;
  889. procedure DrawScreenBuf(Buf: PScreenBuf);
  890. Begin
  891. If Buf <> nil then
  892. DrawScreenBufAt(Buf, Buf^.Rect.A.x, Buf^.Rect.A.y)
  893. End;
  894. function GetVgaMemCaps: Word;
  895. begin
  896. GetVgaMemCaps := vmcCopy
  897. end;
  898. procedure GetTextMetrics(var Metrics: TTextMetric);
  899. begin
  900. with Metrics do
  901. begin
  902. tmHeight := 8;
  903. tmAscent := 8;
  904. tmDescent := 0;
  905. tmInternalLeading := 0;
  906. tmExternalLeading := 0;
  907. tmAveCharWidth := 8;
  908. tmMaxCharWidth := 8;
  909. tmWeight := 700;
  910. tmItalic := 0;
  911. tmUnderlined := 0;
  912. tmStruckOut := 0;
  913. tmFirstChar := 0;
  914. tmLastChar := 255;
  915. tmDefaultChar := 32;
  916. tmBreakChar := 32;
  917. tmPitchAndFamily := 0;
  918. tmCharSet := 0;
  919. tmOverhang := 0;
  920. tmDigitizedAspectX := 100;
  921. tmDigitizedAspectY := 100
  922. end;
  923. end;
  924. { ---------------------------------------------------------------------
  925. Real graph implementation
  926. ---------------------------------------------------------------------}
  927. function GetX: Integer;
  928. begin
  929. GetX := CurX - DrawDelta.X
  930. end;
  931. function GetY: Integer;
  932. begin
  933. GetY := CurY - DrawDelta.Y
  934. end;
  935. { Pixel-oriented routines }
  936. procedure PutPixel(X, Y: Integer; Pixel: Word);
  937. begin
  938. if not NoGraphics
  939. then gl_setpixel(X + DrawDelta.X, Y + DrawDelta.Y, Pixel)
  940. end;
  941. function GetPixel(X, Y: Integer): Word;
  942. begin
  943. if NoGraphics
  944. then GetPixel := 0
  945. else GetPixel := gl_getpixel(X + DrawDelta.X, Y + DrawDelta.Y)
  946. end;
  947. { Line-oriented primitives }
  948. procedure SetWriteMode(WriteMode: Integer);
  949. begin
  950. { Graph.SetWriteMode(WriteMode) }
  951. end;
  952. procedure LineTo(X, Y: Integer);
  953. begin
  954. if not NoGraphics
  955. then gl_line(CurX, CurY, X + DrawDelta.X, Y + DrawDelta.Y, TheColor);
  956. CurX := X + DrawDelta.X;
  957. CurY := Y + DrawDelta.Y
  958. end;
  959. procedure LineRel(Dx, Dy: Integer);
  960. begin
  961. if not NoGraphics
  962. then gl_line(CurX, CurY, CurX + Dx, CurY + Dy, TheColor);
  963. CurX := CurX + Dx;
  964. CurY := CurY + Dy
  965. end;
  966. procedure MoveTo(X, Y: Integer);
  967. begin
  968. CurX := X + DrawDelta.X;
  969. CurY := Y + DrawDelta.Y
  970. end;
  971. procedure MoveRel(Dx, Dy: Integer);
  972. begin
  973. CurX := CurX + Dx;
  974. CurY := CurY + Dy
  975. end;
  976. procedure Line(x1, y1, x2, y2: Integer);
  977. begin
  978. if not NoGraphics
  979. then gl_line(x1 + DrawDelta.X, y1 + DrawDelta.Y,
  980. x2 + DrawDelta.X, y2 + DrawDelta.Y, TheColor)
  981. end;
  982. procedure SetLineStyle(LineStyle: Word; Pattern: Word; Thickness: Word);
  983. begin
  984. end;
  985. procedure SetFillPattern(Pattern: FillPatternType; Color: Word);
  986. begin
  987. end;
  988. { Linearly bounded primitives }
  989. procedure Rectangle(x1, y1, x2, y2: Integer);
  990. begin
  991. MoveTo(x1, y1);
  992. LineTo(x2, y1);
  993. LineTo(x2, y2);
  994. LineTo(x1, y2);
  995. LineTo(x1, y1)
  996. end;
  997. procedure Bar(x1, y1, x2, y2: Integer);
  998. var
  999. R: TRect;
  1000. begin
  1001. if not NoGraphics
  1002. then begin
  1003. R.Assign(x1 + DrawDelta.X, y1 + DrawDelta.Y,
  1004. x2 + DrawDelta.X + 1, y2 + DrawDelta.Y + 1);
  1005. R.Intersect(ClipRect);
  1006. if not R.Empty
  1007. then gl_fillbox(R.A.X, R.A.Y,
  1008. R.B.X - R.A.X, R.B.Y - R.A.Y, TheFillColor)
  1009. end;
  1010. end;
  1011. procedure Bar3D(x1, y1, x2, y2: Integer; Depth: Word; Top: Boolean);
  1012. begin
  1013. Bar(x1,y1,x2,y2);
  1014. Rectangle(x1,y1,x2,y2);
  1015. if top then begin
  1016. Moveto(x1,y1);
  1017. Lineto(x1+depth,y1-depth);
  1018. Lineto(x2+depth,y1-depth);
  1019. Lineto(x2,y1);
  1020. end;
  1021. Moveto(x2+depth,y1-depth);
  1022. Lineto(x2+depth,y2-depth);
  1023. Lineto(x2,y2);
  1024. end;
  1025. procedure DrawPoly(NumPoints: Word; var PolyPoints);
  1026. type
  1027. ppointtype = ^pointtype;
  1028. var
  1029. i : longint;
  1030. begin
  1031. line(ppointtype(@polypoints)[NumPoints-1].x,
  1032. ppointtype(@polypoints)[NumPoints-1].y,
  1033. ppointtype(@polypoints)[0].x,
  1034. ppointtype(@polypoints)[0].y);
  1035. for i:=0 to NumPoints-2 do
  1036. line(ppointtype(@polypoints)[i].x,
  1037. ppointtype(@polypoints)[i].y,
  1038. ppointtype(@polypoints)[i+1].x,
  1039. ppointtype(@polypoints)[i+1].y);
  1040. end;
  1041. procedure FillPoly(NumPoints: Word; var PolyPoints);
  1042. begin
  1043. end;
  1044. procedure SetFillStyle(Pattern: Word; Color: Word);
  1045. begin
  1046. TheFillColor := ColorTable[Color]
  1047. end;
  1048. procedure FloodFill(X, Y: Integer; Border: Word);
  1049. begin
  1050. end;
  1051. { Nonlinearly bounded primitives
  1052. }
  1053. Var LastArcCoords : ArcCoordsType;
  1054. procedure SetArcCoords (X,y,xradius,yradius,Stangle,endangle : integer);
  1055. begin
  1056. LastArcCoords.X:=X;
  1057. LastArccOords.y:=y;
  1058. Lastarccoords.xstart:=x+round(xradius*cos(stangle*pi/180));
  1059. Lastarccoords.ystart:=y-round(yradius*sin(stangle*pi/180));
  1060. LastArccoords.xend:=x+round(xradius*cos(endangle*pi/180));
  1061. LastArccoords.yend:=y-round(yradius*sin(endangle*pi/180));
  1062. end;
  1063. procedure GetArcCoords(var ArcCoords: ArcCoordsType);
  1064. begin
  1065. ArcCoords:=LastArcCoords;
  1066. end;
  1067. procedure Arc(X, Y: Integer; StAngle, EndAngle, Radius: Word);
  1068. begin
  1069. Ellipse (X,y,stangle,endangle,Radius,radius);
  1070. end;
  1071. procedure Circle(X, Y: Integer; Radius: Word);
  1072. begin
  1073. if not NoGraphics
  1074. then gl_circle(X + DrawDelta.X, Y + DrawDelta.Y, Radius, TheColor)
  1075. end;
  1076. procedure Ellipse(X, Y: Integer;
  1077. StAngle, EndAngle: Word; XRadius, YRadius : Word);
  1078. Var I : longint;
  1079. tmpang : real;
  1080. begin
  1081. SetArcCoords (X,Y,xradius,yradius,Stangle,EndAngle);
  1082. For i:= StAngle To EndAngle Do
  1083. Begin
  1084. tmpAng:= i*Pi/180;
  1085. curX:= X + Round (xRadius*Cos (tmpAng));
  1086. curY:= Y - Round (YRadius*Sin (tmpAng));
  1087. PutPixel (curX, curY, TheColor);
  1088. End;
  1089. end;
  1090. procedure FillEllipse(X, Y: Integer; XRadius, YRadius : Word);
  1091. Var I,tmpcolor : longint;
  1092. tmpang : real;
  1093. tmpx,tmpy : Integer;
  1094. begin
  1095. tmpcolor:=Thecolor;
  1096. SetColor(TheFillColor);
  1097. For i:= 0 to 180 Do
  1098. Begin
  1099. tmpAng:= i*Pi/180;
  1100. curX:= Round (xRadius*Cos (tmpAng));
  1101. curY:= Round (YRadius*Sin (tmpAng));
  1102. tmpX:= X - curx;
  1103. tmpy:= Y + cury;
  1104. curx:=x+curx;
  1105. cury:=y-cury;
  1106. Line (curX, curY,tmpx,tmpy);
  1107. PutPixel (curx,cury,tmpcolor);
  1108. PutPixel (tmpx,tmpy,tmpcolor);
  1109. End;
  1110. SetColor(tmpcolor);
  1111. end;
  1112. procedure SetAspectRatio(Xasp, Yasp: Word);
  1113. begin
  1114. end;
  1115. procedure PieSlice(X, Y: Integer; StAngle, EndAngle, Radius: Word);
  1116. Begin
  1117. sector (x,y,stangle,endangle,radius,radius);
  1118. end;
  1119. procedure Sector(X, Y: Integer;
  1120. StAngle, EndAngle, XRadius, YRadius: Word);
  1121. Var I,tmpcolor : longint;
  1122. tmpang : real;
  1123. ac : arccoordstype;
  1124. begin
  1125. tmpcolor:=Thecolor;
  1126. SetColor(TheFillColor);
  1127. For i:= stangle to endangle Do
  1128. Begin
  1129. tmpAng:= i*Pi/180;
  1130. curX:= x+Round (xRadius*Cos (tmpAng));
  1131. curY:= y-Round (YRadius*Sin (tmpAng));
  1132. Line (x,y,curX, curY);
  1133. PutPixel (curx,cury,tmpcolor);
  1134. End;
  1135. SetColor(tmpcolor);
  1136. getarccoords(ac);
  1137. Line (x,y,ac.xstart,ac.ystart);
  1138. Line (x,y,ac.xend,ac.yend);
  1139. end;
  1140. { Color routines
  1141. }
  1142. procedure SetBkColor(ColorNum: Word);
  1143. begin
  1144. BackColor := ColorTable[ColorNum];
  1145. end;
  1146. procedure SetColor(Color: Word);
  1147. begin
  1148. TheColor := ColorTable[Color];
  1149. end;
  1150. procedure GetImage(x1, y1, x2, y2: Integer; var BitMap);
  1151. var
  1152. SaveClipRect: TRect;
  1153. begin
  1154. with TBitmap(Bitmap) do
  1155. begin
  1156. Width := x2 - x1 + 1;
  1157. Height := y2 - y1 + 1;
  1158. if not NoGraphics
  1159. then begin
  1160. {gl_disableclipping(0);}
  1161. SaveClipRect := ClipRect;
  1162. SetClipRect(0, 0, SizeX, SizeY);
  1163. gl_getbox(x1 + DrawDelta.X, y1 + DrawDelta.Y,
  1164. x2 - x1 + 1, y2 - y1 + 1, @Data);
  1165. SetClipRectR(SaveClipRect)
  1166. end;
  1167. end;
  1168. end;
  1169. procedure PutImage(X, Y: Integer; var BitMap; BitBlt: Word);
  1170. var
  1171. R: TRect;
  1172. SaveClipRect: TRect;
  1173. begin
  1174. if not NoGraphics then
  1175. with TBitmap(Bitmap) do
  1176. begin
  1177. {gl_putbox(x + DrawDelta.X, y + DrawDelta.Y, Width, Height, @Data)}
  1178. R.Assign(X + DrawDelta.X, Y + DrawDelta.Y,
  1179. X + DrawDelta.X + Width, Y + DrawDelta.Y + Height);
  1180. R.Intersect(ClipRect);
  1181. if not R.Empty
  1182. then begin
  1183. {gl_disableclipping(0);}
  1184. SaveClipRect := ClipRect;
  1185. SetClipRect(0, 0, SizeX, SizeY);
  1186. gl_putboxpart(R.A.X, R.A.Y,
  1187. R.B.X - R.A.X, R.B.Y - R.A.Y,
  1188. Width, Height,
  1189. @Data,
  1190. R.A.X - X, R.A.Y - Y);
  1191. SetClipRectR(SaveClipRect);
  1192. end;
  1193. end;
  1194. end; { PutImage }
  1195. function ImageSize(x1, y1, x2, y2: Integer): LongInt;
  1196. begin
  1197. if NoGraphics
  1198. then ImageSize := SizeOf(TBitmap)
  1199. else ImageSize := SizeOf(TBitmap)
  1200. + LongInt(x2 - x1 + 1) * LongInt(y2 - y1 + 1) * PhysicalScreen^.BytesPerPixel;
  1201. end;
  1202. function GetMaxX : Integer;
  1203. begin
  1204. GetMaxX:=vga_getxdim;
  1205. end;
  1206. function GetMAxY : Integer;
  1207. begin
  1208. GetMaxY:=vga_getydim;
  1209. end;
  1210. Procedure DetectGraph (Var Driver,Mode : Integer);
  1211. begin
  1212. Driver:=9;
  1213. Mode:=vga_getdefaultmode;
  1214. If Mode=-1 then mode:=0;
  1215. end;
  1216. Procedure InitGraph (Var Driver,Mode : Integer;DriverPath : String);
  1217. var
  1218. VgaMode: Integer;
  1219. ModeInfo: pvga_modeinfo;
  1220. begin
  1221. If Mode=0 then
  1222. VgaMode := vga_getdefaultmode
  1223. else
  1224. VGAMode :=Mode;
  1225. if (VgaMode = -1) then VgaMode := G320X200X256;
  1226. if (not vga_hasmode(VgaMode))
  1227. then begin
  1228. WriteLn('BGI: Mode not available.');
  1229. Halt(1)
  1230. end;
  1231. ModeInfo := vga_getmodeinfo(VgaMode);
  1232. {IsVirtual := (ModeInfo^.colors = 16) or (ModeInfo^.flags and IS_MODEX <> 0);}
  1233. IsVirtual := true;
  1234. { We always want a back screen (for buffering). }
  1235. if IsVirtual
  1236. then begin
  1237. { Create virtual screen }
  1238. gl_setcontextvgavirtual(VgaMode);
  1239. BackScreen := gl_allocatecontext;
  1240. gl_getcontext(BackScreen)
  1241. end;
  1242. vga_setmode(VgaMode);
  1243. gl_setcontextvga(VgaMode); { Physical screen context. }
  1244. PhysicalScreen := gl_allocatecontext;
  1245. gl_getcontext(PhysicalScreen);
  1246. if (PhysicalScreen^.colors = 256) then gl_setrgbpalette;
  1247. SetColors;
  1248. SizeX := PhysicalScreen^.Width;
  1249. SizeY := PhysicalScreen^.Height
  1250. end;
  1251. Procedure CloseGraph;
  1252. begin
  1253. DoneVideo;
  1254. end;
  1255. begin
  1256. { Give up root permissions if we are root. }
  1257. if geteuid = 0 then vga_init;
  1258. end.
  1259. {
  1260. $Log$
  1261. Revision 1.7 1998-08-24 08:23:47 michael
  1262. Better initgraph handling.
  1263. Revision 1.6 1998/08/14 09:20:36 michael
  1264. Typo fixed. linklib gl to linklib vgagl
  1265. Revision 1.5 1998/08/12 14:01:08 michael
  1266. small fix in sector, pieslice replaced by call to sector
  1267. Revision 1.4 1998/08/12 13:25:33 michael
  1268. + added arc,ellipse,fillelipse,sector,pieslice
  1269. Revision 1.3 1998/08/10 09:01:58 michael
  1270. + Added some functions to improve compatibility
  1271. Revision 1.2 1998/05/12 10:42:47 peter
  1272. * moved getopts to inc/, all supported OS's need argc,argv exported
  1273. + strpas, strlen are now exported in the systemunit
  1274. * removed logs
  1275. * removed $ifdef ver_above
  1276. Revision 1.1 1998/04/15 13:40:11 michael
  1277. + Initial implementation of graph unit
  1278. }