graph.pp 34 KB

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