graph.pp 38 KB

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