graph.pp 36 KB

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