graph.pp 83 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1993,99 by the Free Pascal development team
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. Unit Graph;
  12. {-------------------------------------------------------}
  13. { Differences with TP Graph unit: }
  14. { - default putimage and getimage only support a max. }
  15. { of 64K colors on screen, because all pixels are }
  16. { saved as words. }
  17. { - Set RGB Palette is not used, SetPalette must be }
  18. { used instead. }
  19. { - In the TP graph unit, Clipping is always performed }
  20. { on strings written with OutText, and this clipping }
  21. { is done on a character per character basis (for }
  22. { example, if ONE part of a character is outside the }
  23. { viewport , then that character is not written at }
  24. { all to the screen. In FPC Pascal, clipping is done }
  25. { on a PIXEL basis, not a character basis, so part of }
  26. { characters which are not entirely in the viewport }
  27. { may appear on the screen. }
  28. { - SetTextStyle only conforms to the TP version when }
  29. { the correct (and expected) values are used for }
  30. { CharSize for stroked fonts (4 = stroked fonts) }
  31. { - InstallUserDriver is not supported, so always }
  32. { returns an error. }
  33. { - RegisterBGIDriver is not supported, so always }
  34. { returns an error. }
  35. { - DrawPoly XORPut mode is not exactly the same as in }
  36. { the TP graph unit. }
  37. { - FillEllipse does not support XORPut mode with a }
  38. { bounded FloodFill. Mode is always CopyPut mode. }
  39. { - Imagesize returns a longint instead of a word }
  40. { - ImageSize cannot return an error value }
  41. {-------------------------------------------------------}
  42. { AUTHORS: }
  43. { Gernot Tenchio - original version }
  44. { Florian Klaempfl - major updates }
  45. { Pierre Mueller - major bugfixes }
  46. { Carl Eric Codere - complete rewrite }
  47. { Thomas Schatzl - optimizations,routines and }
  48. { Credits (external): suggestions. }
  49. { - Original FloodFill code by }
  50. { Menno Victor van der star }
  51. { (the code has been heavily modified) }
  52. {-------------------------------------------------------}
  53. {-------------------------------------------------------}
  54. { For significant speed improvements , is is recommended }
  55. { that these routines be hooked (otherwise the default, }
  56. { slower routines will be used) : }
  57. { HLine() }
  58. { VLine() }
  59. { PatternLine() }
  60. { ClearViewPort() }
  61. { PutImage() }
  62. { GetImage() - ImageSize() should also be changed }
  63. { InternalEllipse() }
  64. { Line() }
  65. { GetScanLine() }
  66. {--------------------------------------------------------}
  67. { FPC unit requirements: }
  68. { All modes should at least have 1 graphics page to }
  69. { make it possible to create animation on all supported }
  70. { systems , this can be done either by double-buffering }
  71. { yourself in the heap if no hardware is available to do}
  72. { it. }
  73. {--------------------------------------------------------}
  74. { COMPATIBILITY WARNING: Some of the compatibility tests }
  75. { were done using the CGA and other the VGA drivers. }
  76. { Within the BGI drivers themselves the BEHAVIOUR is not }
  77. { the same, so be warned!!! }
  78. {--------------------------------------------------------}
  79. { History log: }
  80. { 15th February 1999: }
  81. { + Added support for system font in vertical mode }
  82. { + system font is now available for all platforms }
  83. { * font support routines now compile }
  84. { * textHeight would not return correct size for system }
  85. { font }
  86. { * Alignment of fonts partly fixed }
  87. { 17th Feb. 1999: }
  88. { + First support for stroked fonts }
  89. { 18th Feb. 1999: }
  90. { * bugfix of line drawing which fixes stroked font }
  91. { displays. }
  92. { 23rd Feb. 1999: }
  93. { + Applied Pierre's patches to font }
  94. { + Added scaling of bitmapped fonts }
  95. { + Vertical stroked fonts }
  96. { 24th Feb. 1999: }
  97. { * Scaling of stroked fonts must be done using FPs }
  98. { to be 100% compatible with turbo pascal }
  99. { + Sped up by 40% stroked font scaling calculations }
  100. { + RegisterBGIFont }
  101. { 9th march 1999: }
  102. { + Starting implementing Fillpoly() }
  103. { 15th march 1999: }
  104. { + SetFillStyle() }
  105. { + patternLine() }
  106. { + Bar() }
  107. { * GraphDefaults would not make the Default color }
  108. { of the fill pattern to the Max. Palette entry. }
  109. { + SetFillPattern() }
  110. { 20th march 1999: }
  111. { * GraphDefaults would not reset to the text system }
  112. { * DefaultFont would write one character too much to }
  113. { the screen }
  114. { + Sloped thick lines in Line() }
  115. { + Sloped patterned lines in Line() }
  116. { * GraphDefaults would not reset the User Fill pattern}
  117. { to $ff }
  118. { + DirectPutPixel takes care of XOR mode writes }
  119. { improves speed by about 30% over old method of }
  120. { GetPixel XOR CurrentColor }
  121. { * Dashed LineStyle exactly like BP version now }
  122. { + Center LineStyle (checked against CGA driver) }
  123. { * GraphDefaults() now resets linepattern array }
  124. { 1st april 1999: }
  125. { + First implementation of FillPoly (incomplete) }
  126. { 2nd april 1999: }
  127. { * FillPoly did not Reset PatternLine index }
  128. { * FillPoly did not use correct color }
  129. { * PatternLine was writing modes in reverse direction }
  130. { * PatternLine would not work with non-rectangular }
  131. { shapes. }
  132. { * PatternLine must fill up the ENTIRE pattern, }
  133. { with either the foreground or background color. }
  134. { * GraphDefaults() would not call SetBkColor() }
  135. { * Fixed some memory leaks in FillPoly() }
  136. { 11th April 1999: }
  137. { * PatternLine() was drawing one pixel less then }
  138. { requested }
  139. { 12th April 1999: }
  140. { + FloodFill - first working implementation }
  141. { Horrbly slow even on very fast cpu's }
  142. { + Some suggestions of Thomas implemented }
  143. { 13th April 1999: }
  144. { * FloodFill() vertical index was off by one pixel }
  145. { * FloodFill() would never draw the last line in the }
  146. { list }
  147. { - Removed ClearViewPort320 which was wrong anyways, }
  148. { will need to be implemented later. }
  149. { * PatternLine() would not always restore write mode }
  150. { + Circle() uses NormalPut always with NormWidth lines}
  151. { + FillEllipse() initial version }
  152. { * InternalEllipse() - 0 to 360 now supported as }
  153. { angles. }
  154. { 14th April 1999: }
  155. { * mod x = and (x-1)(from Thomas Schatzl) gives a }
  156. { significant speed improvement. }
  157. { 15th april 1999: }
  158. { + Arc() ok except for Aspect Ratio, which does not }
  159. { give us the correct ratio on a 320x200 screen. }
  160. { + Added FillPoly() from Thomas Schatzl }
  161. { + More hookable routines }
  162. { 16th april 1999: }
  163. { + Line() checked ok. }
  164. { 17th april 1999: }
  165. { * GraphDefaults() would not reset CP }
  166. { + GetX(), GetY(), MoveTo() checked for viewports }
  167. { * OutTextXY() should not update the CP }
  168. { * ClearViewPort() would not update the CP }
  169. { * ClearDevice() would not update the CP }
  170. { * Sector() would update the CP by calling LineTo }
  171. { * Bar3D() would update the CP }
  172. { * PieSlice() would update the CP }
  173. { 18th april 1999: }
  174. { + Clipping algorithm }
  175. { 19th april 1999: }
  176. { + Adapterinfo structure }
  177. { 20th april 1999: }
  178. { + GetModeName }
  179. { + GetGraphMode }
  180. { + GetModeRange }
  181. {--------------------------------------------------------}
  182. { LEFT TO DO: }
  183. { - optimize scaling of stroked fonts }
  184. { - optimize InternalEllipse() }
  185. { using linear appx. of sine/cosine tables }
  186. { - justification for stroked fonts does not work }
  187. { - On Closegraph deallocate all font pointers }
  188. {--------------------------------------------------------}
  189. { text.inc will crash on aligned requirement machines. }
  190. { (packed record for fontrec) }
  191. {$G+}
  192. Interface
  193. const
  194. { error codes }
  195. grOk = 0;
  196. grNoInitGraph = -1;
  197. grNotDetected = -2;
  198. grFileNotFound = -3;
  199. grInvalidDriver = -4;
  200. grNoLoadMem = -5;
  201. grNoScanMem = -6;
  202. grNoFloodMem = -7;
  203. grFontNotFound = -8;
  204. grNoFontMem = -9;
  205. grInvalidMode = -10;
  206. grError = -11;
  207. grIOerror = -12;
  208. grInvalidFont = -13;
  209. grInvalidFontNum = -14;
  210. grInvalidVersion = -18;
  211. { Color constants for setpalette }
  212. black = 0;
  213. blue = 1;
  214. green = 2;
  215. cyan = 3;
  216. red = 4;
  217. magenta = 5;
  218. brown = 6;
  219. lightgray = 7;
  220. darkgray = 8;
  221. lightblue = 9;
  222. lightgreen = 10;
  223. lightcyan = 11;
  224. lightred = 12;
  225. lightmagenta = 13;
  226. yellow = 14;
  227. white = 15;
  228. EGABlack = 0;
  229. EGABlue = 1;
  230. EGAGreen = 2;
  231. EGACyan = 3;
  232. EGARed = 4;
  233. EGAMagenta = 5;
  234. EGALightgray= 7;
  235. EGABrown = 20;
  236. EGADarkgray = 56;
  237. EGALightblue = 57;
  238. EGALightgreen = 58;
  239. EGALightcyan = 59;
  240. EGALightred = 60;
  241. EGALightmagenta=61;
  242. EGAYellow = 62;
  243. EGAWhite = 63;
  244. { Line styles for GetLineStyle/SetLineStyle }
  245. SolidLn = 0;
  246. DottedLn = 1;
  247. CenterLn = 2;
  248. DashedLn = 3;
  249. UserBitLn = 4;
  250. NormWidth = 1;
  251. ThickWidth = 3;
  252. { Set/GetTextStyle Konstanten: }
  253. DefaultFont = 0;
  254. TriplexFont = 1;
  255. SmallFont = 2;
  256. SansSerifFont = 3;
  257. GothicFont = 4;
  258. ScriptFont = 5;
  259. SimpleFont = 6;
  260. TSCRFont = 7;
  261. LCOMFont = 8;
  262. EuroFont = 9;
  263. BoldFont = 10;
  264. HorizDir = 0;
  265. VertDir = 1;
  266. UserCharSize = 0;
  267. ClipOn = true;
  268. ClipOff = false;
  269. { Bar3D constants }
  270. TopOn = true;
  271. TopOff = false;
  272. { fill pattern for Get/SetFillStyle: }
  273. EmptyFill = 0;
  274. SolidFill = 1;
  275. LineFill = 2;
  276. LtSlashFill = 3;
  277. SlashFill = 4;
  278. BkSlashFill = 5;
  279. LtBkSlashFill = 6;
  280. HatchFill = 7;
  281. XHatchFill = 8;
  282. InterleaveFill = 9;
  283. WideDotFill = 10;
  284. CloseDotFill = 11;
  285. UserFill = 12;
  286. { bitblt operators }
  287. NormalPut = 0;
  288. CopyPut = 0;
  289. XORPut = 1;
  290. OrPut = 2;
  291. AndPut = 3;
  292. NotPut = 4;
  293. { SetTextJustify constants }
  294. LeftText = 0;
  295. CenterText = 1;
  296. RightText = 2;
  297. BottomText = 0;
  298. TopText = 2;
  299. { graphic drivers }
  300. CurrentDriver = -128;
  301. Detect = 0;
  302. LowRes = 1;
  303. HercMono = 7;
  304. VGA = 9;
  305. VESA = 10;
  306. { graph modes }
  307. Default = 0;
  308. { VGA Driver modes }
  309. VGALo = 0;
  310. VGAMed = 1;
  311. VGAHi = 2;
  312. { Hercules mono card }
  313. HercMonoHi = 0;
  314. MaxColors = 255; { Maximum possible colors using a palette }
  315. { otherwise, direct color encoding }
  316. type
  317. RGBRec = packed record
  318. Red: integer;
  319. Green: integer;
  320. Blue : integer;
  321. end;
  322. PaletteType = record
  323. Size : longint;
  324. Colors : array[0..MaxColors] of RGBRec;
  325. end;
  326. LineSettingsType = record
  327. linestyle : word;
  328. pattern : word;
  329. thickness : word;
  330. end;
  331. TextSettingsType = record
  332. font : word;
  333. direction : word;
  334. charsize : word;
  335. horiz : word;
  336. vert : word;
  337. end;
  338. FillSettingsType = record
  339. pattern : word;
  340. color : word;
  341. end;
  342. FillPatternType = array[1..8] of byte;
  343. PointType = record
  344. x,y : integer;
  345. end;
  346. ViewPortType = record
  347. x1,y1,x2,y2 : integer;
  348. Clip : boolean;
  349. end;
  350. ArcCoordsType = record
  351. x,y : integer;
  352. xstart,ystart : integer;
  353. xend,yend : integer;
  354. end;
  355. const
  356. fillpatternTable : array[0..12] of FillPatternType = (
  357. ($00,$00,$00,$00,$00,$00,$00,$00), { background color }
  358. ($ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff), { foreground color }
  359. ($ff,$ff,$00,$00,$ff,$ff,$00,$00), { horizontal lines }
  360. ($01,$02,$04,$08,$10,$20,$40,$80), { slashes }
  361. ($07,$0e,$1c,$38,$70,$e0,$c1,$83), { thick slashes }
  362. ($07,$83,$c1,$e0,$70,$38,$1c,$0e), { thick backslashes }
  363. ($5a,$2d,$96,$4b,$a5,$d2,$69,$b4), { backslashes }
  364. ($ff,$88,$88,$88,$ff,$88,$88,$88), { small boxes }
  365. ($18,$24,$42,$81,$81,$42,$24,$18), { rhombus }
  366. ($cc,$33,$cc,$33,$cc,$33,$cc,$33), { wall pattern }
  367. ($80,$00,$08,$00,$80,$00,$08,$00), { wide points }
  368. ($88,$00,$22,$00,$88,$00,$22,$00), { dense points }
  369. (0,0,0,0,0,0,0,0) { user defined line style }
  370. );
  371. { ******************** PROCEDURAL VARIABLES ********************* }
  372. { * These are hooks which have device specific stuff in them, * }
  373. { * therefore to add new modes or to redirect these routines * }
  374. { * then declare variables of these types as shown below. * }
  375. {-----------------------------------------------------------------}
  376. TYPE
  377. { This is the standard putpixel routine used by all function }
  378. { drawing routines, it will use the viewport settings, as }
  379. { well as clip, and use the current foreground color to plot }
  380. { the desired pixel. }
  381. defpixelproc = procedure(X,Y: Integer);
  382. { standard plot and get pixel }
  383. getpixelproc = function(X,Y: Integer): word;
  384. putpixelproc = procedure(X,Y: Integer; Color: Word);
  385. { clears the viewport, also used to clear the device }
  386. clrviewproc = procedure;
  387. { putimage procedure, can be hooked to accomplish transparency }
  388. putimageproc = procedure (X,Y: Integer; var Bitmap; BitBlt: Word);
  389. getimageproc = procedure(X1,Y1,X2,Y2: Integer; Var Bitmap);
  390. imagesizeproc= function (X1,Y1,X2,Y2: Integer): longint;
  391. graphfreememprc = procedure (var P: Pointer; size: word);
  392. graphgetmemprc = procedure (var P: pointer; size: word);
  393. { internal routines -- can be hooked for much faster drawing }
  394. { draw filled horizontal lines using current color }
  395. { on entry coordinates are already clipped. }
  396. hlineproc = procedure (x, x2,y : integer);
  397. { on entry coordinates are already clipped. }
  398. { draw filled vertical line using current color }
  399. vlineproc = procedure (x,y,y2: integer);
  400. { this routine is used to draw filled patterns for all routines }
  401. { that require it. (FillPoly, FloodFill, Sector, etc... }
  402. { clipping is verified, uses current Fill settings for drawing }
  403. patternlineproc = procedure (x1,x2,y: integer);
  404. { this routine is used to draw all circles/ellipses/sectors }
  405. { more info... on this later... }
  406. ellipseproc = procedure (X,Y: Integer;XRadius: word;
  407. YRadius:word; stAngle,EndAngle: word);
  408. { Line routine - draws lines thick/norm widths with current }
  409. { color and line style - LINE must be clipped here. }
  410. lineproc = procedure (X1, Y1, X2, Y2 : Integer);
  411. { this routine is used for FloodFill - it returns an entire }
  412. { screen scan line with a word for each pixel in the scanline }
  413. getscanlineproc = procedure (Y : integer; var data);
  414. { changes the active display screen where we draw to... }
  415. setactivepageproc = procedure (page: word);
  416. { changes the active display screen which we see ... }
  417. setvisualpageproc = procedure (page: word);
  418. { this routine actually switches to the desired video mode. }
  419. initmodeproc = procedure;
  420. { this routine is called to save the sate just before a mode set }
  421. savestateproc = procedure;
  422. { this routine is called in closegraph to cleanup... }
  423. restorestateproc = procedure;
  424. { This routine is a hook for SetRGBPalette }
  425. setrgbpaletteproc =
  426. procedure(ColorNum, RedValue, GreenValue, BlueValue: Integer);
  427. { This routine is a hook for GetRGBPalette }
  428. getrgbpaletteproc =
  429. procedure(ColorNum: integer; var
  430. RedValue, GreenValue, BlueValue: Integer);
  431. TYPE
  432. {-----------------------------------}
  433. { Linked list for mode information }
  434. { This list is set up by one of the }
  435. { following routines: }
  436. { It lists all available resolutions}
  437. { on this display adapter. }
  438. {-----------------------------------}
  439. { QueryAdapter() }
  440. { DetectGraph() }
  441. { InitGraph() }
  442. {-----------------------------------}
  443. PModeInfo = ^TModeInfo;
  444. TModeInfo = record
  445. DriverNumber: Integer;
  446. ModeNumber: Integer;
  447. MaxColor: Longint; { Maximum colors on screen }
  448. PaletteSize : Longint; { Maximum palette entry we can change }
  449. XAspect : Integer; { XAspect ratio correction factor }
  450. YAspect : Integer; { YAspect ratio correction factor }
  451. MaxX: Integer; { Max-X row }
  452. MaxY: Integer; { Max. column. }
  453. DirectColor: boolean; { Is this a direct color mode?? }
  454. Hardwarepages: byte; { total number of image pages - 1 }
  455. ModeName: String[18];
  456. { necessary hooks ... }
  457. DirectPutPixel : DefPixelProc;
  458. GetPixel : GetPixelProc;
  459. PutPixel : PutPixelProc;
  460. SetRGBPalette : SetRGBPaletteProc;
  461. GetRGBPalette : GetRGBPaletteProc;
  462. { defaults possible ... }
  463. SetVisualPage : SetVisualPageProc;
  464. SetActivePage : SetActivePageProc;
  465. ClearViewPort : ClrViewProc;
  466. PutImage : PutImageProc;
  467. GetImage : GetImageProc;
  468. ImageSize : ImageSizeProc;
  469. GetScanLine : GetScanLineProc;
  470. Line : LineProc;
  471. InternalEllipse: EllipseProc;
  472. PatternLine : PatternLineProc;
  473. HLine : HLineProc;
  474. VLine : VLineProc;
  475. InitMode : InitModeProc;
  476. next: PModeInfo;
  477. end;
  478. VAR
  479. DirectPutPixel : DefPixelProc;
  480. ClearViewPort : ClrViewProc;
  481. PutPixel : PutPixelProc;
  482. PutImage : PutImageProc;
  483. GetImage : GetImageProc;
  484. ImageSize : ImageSizeProc;
  485. GetPixel : GetPixelProc;
  486. SetVisualPage : SetVisualPageProc;
  487. SetActivePage : SetActivePageProc;
  488. SetRGBPalette : SetRGBPaletteProc;
  489. GetRGBPalette : GetRGBPaletteProc;
  490. GraphFreeMemPtr: graphfreememprc;
  491. GraphGetMemPtr : graphgetmemprc;
  492. GetScanLine : GetScanLineProc;
  493. Line : LineProc;
  494. InternalEllipse: EllipseProc;
  495. PatternLine : PatternLineProc;
  496. HLine : HLineProc;
  497. VLine : VLineProc;
  498. SaveVideoState : SaveStateProc;
  499. RestoreVideoState: RestoreStateProc;
  500. Procedure Closegraph;
  501. procedure SetLineStyle(LineStyle: word; Pattern: word; Thickness: word);
  502. function GraphErrorMsg(ErrorCode: Integer): string;
  503. Function GetMaxX: Integer;
  504. Function GetMaxY: Integer;
  505. Procedure SetViewPort(X1, Y1, X2, Y2: Integer; Clip: Boolean);
  506. Function GraphResult: Integer;
  507. function GetModeName(ModeNumber: integer): string;
  508. procedure SetGraphMode(Mode: Integer);
  509. function GetGraphMode: Integer;
  510. function GetMaxMode: word;
  511. procedure RestoreCrtMode;
  512. procedure GetModeRange(GraphDriver: Integer; var LoMode, HiMode: Integer);
  513. Function GetX: Integer;
  514. Function GetY: Integer;
  515. procedure GraphDefaults;
  516. procedure ClearDevice;
  517. procedure GetViewSettings(var viewport : ViewPortType);
  518. procedure SetWriteMode(WriteMode : integer);
  519. procedure GetFillSettings(var Fillinfo:Fillsettingstype);
  520. procedure GetFillPattern(var FillPattern:FillPatternType);
  521. procedure GetLineSettings(var ActiveLineInfo : LineSettingsType);
  522. procedure InitGraph(var GraphDriver:Integer;var GraphMode:Integer;const PathToDriver:String);
  523. function InstallUserDriver(Name: string; AutoDetectPtr: Pointer): integer;
  524. function RegisterBGIDriver(driver: pointer): integer;
  525. procedure SetFillStyle(Pattern : word; Color: word);
  526. procedure SetFillPattern(Pattern: FillPatternType; Color: word);
  527. Function GetDriverName: string;
  528. procedure MoveRel(Dx, Dy: Integer);
  529. procedure MoveTo(X,Y: Integer);
  530. procedure SetDirectVideo(DirectAccess: boolean);
  531. function GetDirectVideo: boolean;
  532. { -------------------- Color/Palette ------------------------------- }
  533. procedure SetBkColor(ColorNum: Word);
  534. function GetColor: Word;
  535. function GetBkColor: Word;
  536. procedure SetColor(Color: Word);
  537. function GetMaxColor: word;
  538. procedure SetAllPalette(var Palette:PaletteType);
  539. procedure SetPalette(ColorNum: word; Color: shortint);
  540. procedure GetPalette(var Palette: PaletteType);
  541. function GetPaletteSize: integer;
  542. procedure GetDefaultPalette(var Palette: PaletteType);
  543. { -------------------- Shapes/Lines -------------------------------- }
  544. procedure Rectangle(x1,y1,x2,y2:integer);
  545. procedure Bar(x1,y1,x2,y2:integer);
  546. procedure Bar3D(x1, y1, x2, y2 : integer;depth : word;top : boolean);
  547. procedure FillPoly(NumPoints: word; Var PolyPoints);
  548. procedure DrawPoly(NumPoints : word;var polypoints);
  549. procedure LineRel(Dx, Dy: Integer);
  550. procedure LineTo(X,Y : Integer);
  551. procedure FloodFill(x : integer; y : integer; Border: word);
  552. { -------------------- Circle related routines --------------------- }
  553. procedure GetAspectRatio(var Xasp,Yasp : word);
  554. procedure SetAspectRatio(Xasp, Yasp : word);
  555. procedure GetArcCoords(var ArcCoords: ArcCoordsType);
  556. procedure Arc(X,Y : Integer; StAngle,EndAngle,Radius: word);
  557. procedure PieSlice(X,Y,stangle,endAngle:integer;Radius: Word);
  558. procedure FillEllipse(X, Y: Integer; XRadius, YRadius: Word);
  559. procedure Circle(X, Y: Integer; Radius:Word);
  560. procedure Sector(x, y: Integer; StAngle,EndAngle, XRadius, YRadius: Word);
  561. procedure Ellipse(X,Y : Integer; stAngle, EndAngle: word; XRadius,
  562. YRadius: word);
  563. { --------------------- Text related routines --------------------- }
  564. function InstallUserFont(const FontFileName : string) : integer;
  565. function RegisterBGIfont(font : pointer) : integer;
  566. procedure GetTextSettings(var TextInfo : TextSettingsType);
  567. function TextHeight(const TextString : string) : word;
  568. function TextWidth(const TextString : string) : word;
  569. procedure SetTextJustify(horiz,vert : word);
  570. procedure SetTextStyle(font,direction : word;charsize : word);
  571. procedure SetUserCharSize(Multx,Divx,Multy,Divy : word);
  572. procedure OutTextXY(x,y : integer;const TextString : string);
  573. procedure OutText(const TextString : string);
  574. Implementation
  575. {$ifdef fpc}
  576. {$ifdef go32v2}
  577. {$define dpmi}
  578. uses go32;
  579. Type TDPMIRegisters = go32.registers;
  580. {$endif go32v2}
  581. {$else fpc}
  582. {$IFDEF DPMI}
  583. uses WinAPI;
  584. {$ENDIF}
  585. {$endif fpc}
  586. const
  587. StdBufferSize = 4096; { Buffer size for FloodFill }
  588. type
  589. tinttable = array[0..8192] of integer;
  590. pinttable = ^tinttable;
  591. WordArray = Array [0..StdbufferSize] Of word;
  592. PWordArray = ^WordArray;
  593. const
  594. { Mask for each bit in byte used to determine pattern }
  595. BitArray: Array[0..7] of byte =
  596. ($01,$02,$04,$08,$10,$20,$40,$80);
  597. RevbitArray: Array[0..7] of byte =
  598. ($80,$40,$20,$10,$08,$04,$02,$01);
  599. { pre expanded line patterns }
  600. { 0 = LSB of byte pattern }
  601. { 15 = MSB of byte pattern }
  602. LinePatterns: Array[0..15] of BOOLEAN =
  603. (TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,
  604. TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE);
  605. const
  606. BGIPath : string = '.';
  607. { Default font 8x8 system from IBM PC }
  608. {$i fontdata.inc}
  609. var
  610. CurrentColor: Word;
  611. CurrentBkColor: Word;
  612. CurrentX : Integer; { viewport relative }
  613. CurrentY : Integer; { viewport relative }
  614. ClipPixels: Boolean; { Should cliiping be enabled }
  615. CurrentWriteMode: Integer;
  616. _GraphResult : Integer;
  617. LineInfo : LineSettingsType;
  618. FillSettings: FillSettingsType;
  619. { information for Text Output routines }
  620. CurrentTextInfo : TextSettingsType;
  621. CurrentXRatio: Real;
  622. CurrentYRatio: Real;
  623. installedfonts: longint; { Number of installed fonts }
  624. StartXViewPort: Integer; { absolute }
  625. StartYViewPort: Integer; { absolute }
  626. ViewWidth : Integer;
  627. ViewHeight: Integer;
  628. IsGraphMode : Boolean; { Indicates if we are in graph mode or not }
  629. ArcCall: ArcCoordsType; { Information on the last call to Arc or Ellipse }
  630. var
  631. { ******************** HARDWARE INFORMATION ********************* }
  632. { Should be set in InitGraph once only. }
  633. IntCurrentMode : Integer;
  634. IntCurrentDriver : Integer; { Currently loaded driver }
  635. XAspect : Integer;
  636. YAspect : Integer;
  637. MaxX : Integer; { Maximum resolution - ABSOLUTE }
  638. MaxY : Integer; { Maximum resolution - ABSOLUTE }
  639. MaxColor : Longint;
  640. PaletteSize : longint; { Maximum palette entry we can set, usually equal}
  641. { maxcolor. }
  642. HardwarePages : byte; { maximum number of hardware visual pages }
  643. DriverName: String;
  644. DirectColor : Boolean ; { Is it a direct color mode? }
  645. ModeList : PModeInfo;
  646. DirectVideo : Boolean; { Direct access to video memory? }
  647. {--------------------------------------------------------------------------}
  648. { }
  649. { LINE AND LINE RELATED ROUTINES }
  650. { }
  651. {--------------------------------------------------------------------------}
  652. {$i clip.inc}
  653. procedure HLineDefault(x,x2,y: integer); far;
  654. var
  655. Col: word;
  656. xtmp: integer;
  657. Begin
  658. { must we swap the values? }
  659. if x >= x2 then
  660. Begin
  661. xtmp := x2;
  662. x2 := x;
  663. x:= xtmp;
  664. end;
  665. { First convert to global coordinates }
  666. X := X + StartXViewPort;
  667. X2 := X2 + StartXViewPort;
  668. Y := Y + StartYViewPort;
  669. if ClipPixels then
  670. Begin
  671. if LineClipped(x,y,x2,y,StartXViewPort,StartYViewPort,
  672. StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
  673. exit;
  674. end;
  675. for x:= x to x2 do
  676. DirectPutPixel(X,Y);
  677. end;
  678. procedure VLineDefault(x,y,y2: integer); far;
  679. var
  680. Col: word;
  681. ytmp: integer;
  682. Begin
  683. { must we swap the values? }
  684. if y >= y2 then
  685. Begin
  686. ytmp := y2;
  687. y2 := y;
  688. y:= ytmp;
  689. end;
  690. { First convert to global coordinates }
  691. X := X + StartXViewPort;
  692. Y2 := Y2 + StartYViewPort;
  693. Y := Y + StartYViewPort;
  694. if ClipPixels then
  695. Begin
  696. if LineClipped(x,y,x,y2,StartXViewPort,StartYViewPort,
  697. StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
  698. exit;
  699. end;
  700. for y := y to y2 do Directputpixel(x,y)
  701. End;
  702. procedure LineDefault(X1, Y1, X2, Y2: Integer); far;
  703. var X, Y : Integer;
  704. deltax, deltay : Integer;
  705. d, dinc1, dinc2: Integer;
  706. xinc1 : Integer;
  707. xinc2 : Integer;
  708. yinc1 : Integer;
  709. yinc2 : Integer;
  710. i, j : Integer;
  711. Flag : Boolean; { determines pixel direction in thick lines }
  712. NumPixels : Integer;
  713. PixelCount : Integer;
  714. OldCurrentColor: Word;
  715. swtmp : integer;
  716. TmpNumPixels : integer;
  717. begin
  718. {******************************************}
  719. { SOLID LINES }
  720. {******************************************}
  721. if lineinfo.LineStyle = SolidLn then
  722. Begin
  723. { we separate normal and thick width for speed }
  724. { and because it would not be 100% compatible }
  725. { with the TP graph unit otherwise }
  726. if y1 = y2 then
  727. Begin
  728. {******************************************}
  729. { SOLID LINES HORIZONTAL }
  730. {******************************************}
  731. if lineinfo.Thickness=NormWidth then
  732. hline(x1,x2,y2)
  733. else
  734. begin
  735. { thick width }
  736. hline(x1,x2,y2-1);
  737. hline(x1,x2,y2);
  738. hline(x2,x2,y2+1);
  739. end;
  740. end
  741. else
  742. if x1 = x2 then
  743. Begin
  744. {******************************************}
  745. { SOLID LINES VERTICAL }
  746. {******************************************}
  747. if lineinfo.Thickness=NormWidth then
  748. vline(x1,y1,y2)
  749. else
  750. begin
  751. { thick width }
  752. vline(x1-1,y1,y2);
  753. vline(x1,y1,y2);
  754. vline(x1+1,y1,y2);
  755. end;
  756. end
  757. else
  758. begin
  759. { Convert to global coordinates. }
  760. x1 := x1 + StartXViewPort;
  761. x2 := x2 + StartXViewPort;
  762. y1 := y1 + StartYViewPort;
  763. y2 := y2 + StartYViewPort;
  764. { if fully clipped then exit... }
  765. if ClipPixels then
  766. begin
  767. if LineClipped(x1,y1,x2,y2,StartXViewPort, StartYViewPort,
  768. StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
  769. exit;
  770. end;
  771. {******************************************}
  772. { SLOPED SOLID LINES }
  773. {******************************************}
  774. oldCurrentColor := CurrentColor;
  775. { Calculate deltax and deltay for initialisation }
  776. deltax := abs(x2 - x1);
  777. deltay := abs(y2 - y1);
  778. { Initialize all vars based on which is the independent variable }
  779. if deltax >= deltay then
  780. begin
  781. Flag := FALSE;
  782. { x is independent variable }
  783. numpixels := deltax + 1;
  784. d := (2 * deltay) - deltax;
  785. dinc1 := deltay Shl 1;
  786. dinc2 := (deltay - deltax) shl 1;
  787. xinc1 := 1;
  788. xinc2 := 1;
  789. yinc1 := 0;
  790. yinc2 := 1;
  791. end
  792. else
  793. begin
  794. Flag := TRUE;
  795. { y is independent variable }
  796. numpixels := deltay + 1;
  797. d := (2 * deltax) - deltay;
  798. dinc1 := deltax Shl 1;
  799. dinc2 := (deltax - deltay) shl 1;
  800. xinc1 := 0;
  801. xinc2 := 1;
  802. yinc1 := 1;
  803. yinc2 := 1;
  804. end;
  805. { Make sure x and y move in the right directions }
  806. if x1 > x2 then
  807. begin
  808. xinc1 := - xinc1;
  809. xinc2 := - xinc2;
  810. end;
  811. if y1 > y2 then
  812. begin
  813. yinc1 := - yinc1;
  814. yinc2 := - yinc2;
  815. end;
  816. { Start drawing at <x1, y1> }
  817. x := x1;
  818. y := y1;
  819. If LineInfo.Thickness=NormWidth then
  820. Begin
  821. { Draw the pixels }
  822. for i := 1 to numpixels do
  823. begin
  824. DirectPutPixel(x, y);
  825. if d < 0 then
  826. begin
  827. d := d + dinc1;
  828. x := x + xinc1;
  829. y := y + yinc1;
  830. end
  831. else
  832. begin
  833. d := d + dinc2;
  834. x := x + xinc2;
  835. y := y + yinc2;
  836. end;
  837. CurrentColor := OldCurrentColor;
  838. end;
  839. end
  840. else
  841. { Thick width lines }
  842. begin
  843. { Draw the pixels }
  844. for i := 1 to numpixels do
  845. begin
  846. { all depending on the slope, we can determine }
  847. { in what direction the extra width pixels will be put }
  848. If Flag then
  849. Begin
  850. DirectPutPixel(x-1,y);
  851. DirectPutPixel(x,y);
  852. DirectPutPixel(x+1,y);
  853. end
  854. else
  855. Begin
  856. DirectPutPixel(x, y-1);
  857. DirectPutPixel(x, y);
  858. DirectPutPixel(x, y+1);
  859. end;
  860. if d < 0 then
  861. begin
  862. d := d + dinc1;
  863. x := x + xinc1;
  864. y := y + yinc1;
  865. end
  866. else
  867. begin
  868. d := d + dinc2;
  869. x := x + xinc2;
  870. y := y + yinc2;
  871. end;
  872. CurrentColor := OldCurrentColor;
  873. end;
  874. end;
  875. end;
  876. end
  877. else
  878. {******************************************}
  879. { begin patterned lines }
  880. {******************************************}
  881. Begin
  882. { Convert to global coordinates. }
  883. x1 := x1 + StartXViewPort;
  884. x2 := x2 + StartXViewPort;
  885. y1 := y1 + StartYViewPort;
  886. y2 := y2 + StartYViewPort;
  887. { if fully clipped then exit... }
  888. if ClipPixels then
  889. begin
  890. if LineClipped(x1,y1,x2,y2,StartXViewPort, StartYViewPort,
  891. StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
  892. exit;
  893. end;
  894. OldCurrentColor := CurrentColor;
  895. PixelCount:=0;
  896. if y1 = y2 then
  897. Begin
  898. { Check if we must swap }
  899. if x1 >= x2 then
  900. Begin
  901. swtmp := x1;
  902. x1 := x2;
  903. x2 := swtmp;
  904. end;
  905. if LineInfo.Thickness = NormWidth then
  906. Begin
  907. for PixelCount:=x1 to x2 do
  908. { optimization: PixelCount mod 16 }
  909. if LinePatterns[PixelCount and 15] = TRUE then
  910. begin
  911. DirectPutPixel(PixelCount,y2);
  912. end;
  913. end
  914. else
  915. Begin
  916. for i:=-1 to 1 do
  917. Begin
  918. for PixelCount:=x1 to x2 do
  919. { Optimization from Thomas - mod 16 = and 15 }
  920. {this optimization has been performed by the compiler
  921. for while as well (JM)}
  922. if LinePatterns[PixelCount and 15] = TRUE then
  923. begin
  924. DirectPutPixel(PixelCount,y2+i);
  925. end;
  926. end;
  927. end;
  928. end
  929. else
  930. if x1 = x2 then
  931. Begin
  932. { Check if we must swap }
  933. if y1 >= y2 then
  934. Begin
  935. swtmp := y1;
  936. y1 := y2;
  937. y2 := swtmp;
  938. end;
  939. if LineInfo.Thickness = NormWidth then
  940. Begin
  941. for PixelCount:=y1 to y2 do
  942. { compare if we should plot a pixel here , compare }
  943. { with predefined line patterns... }
  944. if LinePatterns[PixelCount and 15] = TRUE then
  945. begin
  946. DirectPutPixel(x1,PixelCount);
  947. end;
  948. end
  949. else
  950. Begin
  951. for i:=-1 to 1 do
  952. Begin
  953. for PixelCount:=y1 to y2 do
  954. { compare if we should plot a pixel here , compare }
  955. { with predefined line patterns... }
  956. if LinePatterns[PixelCount and 15] = TRUE then
  957. begin
  958. DirectPutPixel(x1+i,PixelCount);
  959. end;
  960. end;
  961. end;
  962. end
  963. else
  964. Begin
  965. oldCurrentColor := CurrentColor;
  966. { Calculate deltax and deltay for initialisation }
  967. deltax := abs(x2 - x1);
  968. deltay := abs(y2 - y1);
  969. { Initialize all vars based on which is the independent variable }
  970. if deltax >= deltay then
  971. begin
  972. Flag := FALSE;
  973. { x is independent variable }
  974. numpixels := deltax + 1;
  975. d := (2 * deltay) - deltax;
  976. dinc1 := deltay Shl 1;
  977. dinc2 := (deltay - deltax) shl 1;
  978. xinc1 := 1;
  979. xinc2 := 1;
  980. yinc1 := 0;
  981. yinc2 := 1;
  982. end
  983. else
  984. begin
  985. Flag := TRUE;
  986. { y is independent variable }
  987. numpixels := deltay + 1;
  988. d := (2 * deltax) - deltay;
  989. dinc1 := deltax Shl 1;
  990. dinc2 := (deltax - deltay) shl 1;
  991. xinc1 := 0;
  992. xinc2 := 1;
  993. yinc1 := 1;
  994. yinc2 := 1;
  995. end;
  996. { Make sure x and y move in the right directions }
  997. if x1 > x2 then
  998. begin
  999. xinc1 := - xinc1;
  1000. xinc2 := - xinc2;
  1001. end;
  1002. if y1 > y2 then
  1003. begin
  1004. yinc1 := - yinc1;
  1005. yinc2 := - yinc2;
  1006. end;
  1007. { Start drawing at <x1, y1> }
  1008. x := x1;
  1009. y := y1;
  1010. If LineInfo.Thickness=ThickWidth then
  1011. Begin
  1012. TmpNumPixels := NumPixels-1;
  1013. { Draw the pixels }
  1014. for i := 0 to TmpNumPixels do
  1015. begin
  1016. { all depending on the slope, we can determine }
  1017. { in what direction the extra width pixels will be put }
  1018. If Flag then
  1019. Begin
  1020. { compare if we should plot a pixel here , compare }
  1021. { with predefined line patterns... }
  1022. if LinePatterns[i and 15] = TRUE then
  1023. begin
  1024. DirectPutPixel(x-1,y);
  1025. DirectPutPixel(x,y);
  1026. DirectPutPixel(x+1,y);
  1027. end;
  1028. end
  1029. else
  1030. Begin
  1031. { compare if we should plot a pixel here , compare }
  1032. { with predefined line patterns... }
  1033. if LinePatterns[i and 15] = TRUE then
  1034. begin
  1035. DirectPutPixel(x,y-1);
  1036. DirectPutPixel(x,y);
  1037. DirectPutPixel(x,y+1);
  1038. end;
  1039. end;
  1040. if d < 0 then
  1041. begin
  1042. d := d + dinc1;
  1043. x := x + xinc1;
  1044. y := y + yinc1;
  1045. end
  1046. else
  1047. begin
  1048. d := d + dinc2;
  1049. x := x + xinc2;
  1050. y := y + yinc2;
  1051. end;
  1052. end;
  1053. end
  1054. else
  1055. Begin
  1056. { instead of putting in loop , substract by one now }
  1057. TmpNumPixels := NumPixels-1;
  1058. { NormWidth }
  1059. for i := 0 to TmpNumPixels do
  1060. begin
  1061. if LinePatterns[i and 15] = TRUE then
  1062. begin
  1063. DirectPutPixel(x,y);
  1064. end;
  1065. if d < 0 then
  1066. begin
  1067. d := d + dinc1;
  1068. x := x + xinc1;
  1069. y := y + yinc1;
  1070. end
  1071. else
  1072. begin
  1073. d := d + dinc2;
  1074. x := x + xinc2;
  1075. y := y + yinc2;
  1076. end;
  1077. end;
  1078. end
  1079. end;
  1080. {******************************************}
  1081. { end patterned lines }
  1082. {******************************************}
  1083. { restore color }
  1084. CurrentColor:=OldCurrentColor;
  1085. end;
  1086. end; { Line }
  1087. {********************************************************}
  1088. { Procedure InternalEllipse() }
  1089. {--------------------------------------------------------}
  1090. { This routine first calculates all points required to }
  1091. { draw a circle to the screen, and stores the points }
  1092. { to display in a buffer before plotting them. The }
  1093. { aspect ratio of the screen is taken into account when }
  1094. { calculating the values. }
  1095. {--------------------------------------------------------}
  1096. { INPUTS: X,Y : Center coordinates of Ellipse. }
  1097. { XRadius - X-Axis radius of ellipse. }
  1098. { YRadius - Y-Axis radius of ellipse. }
  1099. { stAngle, EndAngle: Start angle and end angles of the }
  1100. { ellipse (used for partial ellipses and circles) }
  1101. {--------------------------------------------------------}
  1102. { NOTE: - uses the current write mode. }
  1103. { - Angles must both be between 0 and 360 }
  1104. {********************************************************}
  1105. Procedure InternalEllipseDefault(X,Y: Integer;XRadius: word;
  1106. YRadius:word; stAngle,EndAngle: word); far;
  1107. var
  1108. i:integer;
  1109. xpt: pinttable;
  1110. ypt: pinttable;
  1111. j,Delta:real;
  1112. NumOfPixels: longint;
  1113. NumOfPix: Array[0..2] of longint;
  1114. count: longint;
  1115. ConvFac,TempTerm: real;
  1116. aval,bval: integer;
  1117. OldcurrentColor: word;
  1118. TmpAngle: word;
  1119. DeltaAngle: word;
  1120. Begin
  1121. { check if valid angles }
  1122. stangle := stAngle mod 361;
  1123. EndAngle := EndAngle mod 361;
  1124. { if impossible angles then swap them! }
  1125. if Endangle < StAngle then
  1126. Begin
  1127. TmpAngle:=EndAngle;
  1128. EndAngle:=StAngle;
  1129. Stangle:=TmpAngle;
  1130. end;
  1131. { calculate difference of angle now so we don't always have to calculate it }
  1132. DeltaAngle:= EndAngle-StAngle;
  1133. i:=0;
  1134. if LineInfo.Thickness=NormWidth then
  1135. Begin
  1136. { approximate the number of pixels required by using the circumference }
  1137. { equation of an ellipse. }
  1138. NumOfPixels:=8*Round(2*sqrt((sqr(XRadius)+sqr(YRadius)) div 2));
  1139. GetMem(xpt,NumOfpixels*sizeof(word));
  1140. GetMem(ypt,NumOfPixels*sizeof(word));
  1141. { Calculate the angle precision required }
  1142. Delta := DeltaAngle / (NumOfPixels);
  1143. { Adjust for screen aspect ratio }
  1144. XRadius:=(longint(XRadius)*10000) div XAspect;
  1145. YRadius:=(longint(YRadius)*10000) div YAspect;
  1146. { Initial counter value }
  1147. j:=Delta+StAngle;
  1148. { removed from inner loop to make faster }
  1149. ConvFac:=Pi/180.0;
  1150. Repeat
  1151. { this used by both sin and cos }
  1152. TempTerm := j*ConvFac;
  1153. { Calculate points }
  1154. xpt^[i]:=round(XRadius*Cos(TempTerm));
  1155. { calculate the value of y }
  1156. ypt^[i]:=round(YRadius*Sin(TempTerm+Pi));
  1157. j:=j+Delta;
  1158. inc(i);
  1159. Until j > DeltaAngle;
  1160. end
  1161. else
  1162. {******************************************}
  1163. { CIRCLE OR ELLIPSE WITH THICKNESS=3 }
  1164. {******************************************}
  1165. Begin
  1166. NumOfPix[1]:=8*Round(2*sqrt((sqr(XRadius)+sqr(YRadius)) div 2));
  1167. NumOfPix[0]:=8*Round(2*sqrt((sqr(XRadius-1)+sqr(YRadius-1)) div 2));
  1168. NumOfPix[2]:=8*Round(2*sqrt((sqr(XRadius+1)+sqr(YRadius+1)) div 2));
  1169. GetMem(xpt,(NumOfPix[1]+NumOfPix[2]+NumOfPix[0])*sizeof(word));
  1170. GetMem(ypt,(NumOfPix[1]+NumOfPix[2]+NumOfPix[0])*sizeof(word));
  1171. { removed from inner loop to make faster }
  1172. ConvFac:=Pi/180.0;
  1173. for Count:=0 to 2 do
  1174. Begin
  1175. aval:=XRadius+Count-1;
  1176. bval:=YRadius+Count-1;
  1177. Delta := DeltaAngle / (NumOfPix[Count]);
  1178. aval:= (longint(aval)*10000) div XAspect;
  1179. bval:= (longint(bval)*10000) div YAspect;
  1180. j:=Delta+Stangle;
  1181. Repeat
  1182. { this used by both sin and cos }
  1183. TempTerm := j*ConvFac;
  1184. xpt^[i]:=round((aval)*Cos(TempTerm));
  1185. { calculate the value of y }
  1186. ypt^[i]:=round(bval*Sin(TempTerm+Pi));
  1187. j:=j+Delta;
  1188. inc(i);
  1189. Until j > DeltaAngle;
  1190. end;
  1191. end;
  1192. {******************************************}
  1193. { NOW ALL PIXEL POINTS ARE IN BUFFER }
  1194. { plot them all to the screen }
  1195. {******************************************}
  1196. Count:=0;
  1197. OldcurrentColor:=currentColor;
  1198. Repeat
  1199. PutPixel(xpt^[Count]+X,ypt^[Count]+Y,CurrentColor);
  1200. inc(count);
  1201. until Count>=i;
  1202. { Get End and Start points into the ArcCall information record }
  1203. ArcCall.X := X;
  1204. ArcCall.Y := Y;
  1205. ArcCall.XStart := xpt^[0] + X;
  1206. ArcCall.YStart := ypt^[0] + Y;
  1207. ArcCall.XEnd := xpt^[Count-1] + X;
  1208. ArcCall.YEnd := ypt^[Count-1] + Y;
  1209. CurrentColor:=OldCurrentColor;
  1210. if LineInfo.Thickness=NormWidth then
  1211. Begin
  1212. Freemem(xpt,NumOfPixels*sizeof(word));
  1213. Freemem(ypt,NumOfPixels*sizeof(word));
  1214. end
  1215. else
  1216. Begin
  1217. FreeMem(xpt,(NumOfPix[1]+NumOfPix[2]+NumOfPix[0])*sizeof(word));
  1218. FreeMem(ypt,(NumOfPix[1]+NumOfPix[2]+NumOfPix[0])*sizeof(word));
  1219. end;
  1220. end;
  1221. {********************************************************}
  1222. { Procedure InternalEllipse() }
  1223. {--------------------------------------------------------}
  1224. { This routine first calculates all points required to }
  1225. { draw a circle to the screen, and stores the points }
  1226. { to display in a buffer before plotting them. The }
  1227. { aspect ratio of the screen is taken into account when }
  1228. { calculating the values. }
  1229. {--------------------------------------------------------}
  1230. { INPUTS: X,Y : Center coordinates of Ellipse. }
  1231. { XRadius - X-Axis radius of ellipse. }
  1232. { YRadius - Y-Axis radius of ellipse. }
  1233. { stAngle, EndAngle: Start angle and end angles of the }
  1234. { ellipse (used for partial ellipses and circles) }
  1235. {--------------------------------------------------------}
  1236. { NOTE: - uses the current write mode. }
  1237. { - Angles must both be between 0 and 360 }
  1238. {********************************************************}
  1239. (*
  1240. Procedure InternalEllipseDefault (x, y : integer;
  1241. xradius, yradius, stAngle, EndAngle : Word); far
  1242. { Draw an ellipse arc. Crude but it works (anyone have a better one?) }
  1243. Var
  1244. aSqr, bSqr, twoaSqr, twobSqr, xa, ya, twoXbSqr, twoYaSqr, error : LongInt;
  1245. Alpha : Real;
  1246. const
  1247. RadToDeg = 180/Pi;
  1248. Procedure PlotPoints;
  1249. var
  1250. i,j: integer;
  1251. xm, ym: integer;
  1252. xp, yp: integer;
  1253. Begin
  1254. ym := y-ya;
  1255. yp := y+ya;
  1256. xm := x-xa;
  1257. xp := x+xa;
  1258. if LineInfo.Thickness = Normwidth then
  1259. Begin
  1260. If (Alpha>=StAngle) And (Alpha<=EndAngle) then
  1261. PutPixel (xm,ym, CurrentColor);
  1262. If (180-Alpha>=StAngle) And (180-Alpha<=EndAngle) then
  1263. PutPixel (xm,yp, CurrentColor);
  1264. If (180+Alpha>=StAngle) And (180+Alpha<=EndAngle) then
  1265. PutPixel (xp,yp, CurrentColor);
  1266. If (360-Alpha>=StAngle) And (360-Alpha<=EndAngle) then
  1267. PutPixel (xp,ym, CurrentColor);
  1268. end
  1269. else
  1270. Begin
  1271. If (Alpha>=StAngle) And (Alpha<=EndAngle) then
  1272. for i:=-1 to 1 do
  1273. for j:=-1 to 1 do
  1274. PutPixel (xm+i,ym+j, CurrentColor);
  1275. If (180-Alpha>=StAngle) And (180-Alpha<=EndAngle) then
  1276. for i:=-1 to 1 do
  1277. for j:=-1 to 1 do
  1278. PutPixel (xm+i,yp+j, CurrentColor);
  1279. If (180+Alpha>=StAngle) And (180+Alpha<=EndAngle) then
  1280. for i:=-1 to 1 do
  1281. for j:=-1 to 1 do
  1282. PutPixel (xp+i,yp+j, CurrentColor);
  1283. If (360-Alpha>=StAngle) And (360-Alpha<=EndAngle) then
  1284. for i:=-1 to 1 do
  1285. for j:=-1 to 1 do
  1286. PutPixel (xp+i,ym+j, CurrentColor);
  1287. end;
  1288. End;
  1289. Begin
  1290. StAngle:=StAngle MOD 361;
  1291. EndAngle:=EndAngle MOD 361;
  1292. StAngle := StAngle + 270;
  1293. EndAngle := EndAngle + 270;
  1294. If StAngle>EndAngle then
  1295. Begin
  1296. StAngle:=StAngle Xor EndAngle; EndAngle:=EndAngle Xor StAngle; StAngle:=EndAngle Xor StAngle;
  1297. End;
  1298. { Adjust for screen aspect ratio }
  1299. XRadius:=(longint(XRadius)*10000) div XAspect;
  1300. YRadius:=(longint(YRadius)*10000) div YAspect;
  1301. aSqr:=LongInt (xradius)*LongInt (xradius);
  1302. bSqr:=LongInt (yradius)*LongInt (yradius);
  1303. twoaSqr:=2*aSqr;
  1304. twobSqr:=2*bSqr;
  1305. xa:=0;
  1306. ya:=yradius;
  1307. twoXbSqr:=0;
  1308. twoYaSqr:=ya*twoaSqr;
  1309. error:=-ya*aSqr;
  1310. While twoXbSqr<=twoYaSqr Do Begin
  1311. If ya=0 then Alpha:=90 Else Alpha:=RadToDeg*Arctan (xa/ya); { Crude but it works }
  1312. PlotPoints;
  1313. Inc (xa);
  1314. Inc (twoXbSqr,twobSqr);
  1315. Inc (error,twoXbSqr-bSqr);
  1316. If error>=0 then Begin
  1317. Dec (ya);
  1318. Dec (twoYaSqr,twoaSqr);
  1319. Dec (error,twoYaSqr);
  1320. End;
  1321. End;
  1322. xa:=xradius;
  1323. ya:=0;
  1324. twoXbSqr:=xa*twobSqr;
  1325. twoYaSqr:=0;
  1326. error:=-xa*bSqr;
  1327. While twoXbSqr>twoYaSqr Do Begin
  1328. If ya=0 then Alpha:=90 Else Alpha:=RadToDeg*Arctan (xa/ya);
  1329. PlotPoints;
  1330. Inc (ya);
  1331. Inc (twoYaSqr,twoaSqr);
  1332. Inc (error,twoYaSqr-aSqr);
  1333. If error>=0 then Begin
  1334. Dec (xa);
  1335. Dec (twoXbSqr,twobSqr);
  1336. Dec (error,twoXbSqr);
  1337. End;
  1338. End;
  1339. End;
  1340. *)
  1341. procedure PatternLineDefault(x1,x2,y: integer); far;
  1342. {********************************************************}
  1343. { Draws a horizontal patterned line according to the }
  1344. { current Fill Settings. }
  1345. {********************************************************}
  1346. { Important notes: }
  1347. { - CurrentColor must be set correctly before entering }
  1348. { this routine. }
  1349. {********************************************************}
  1350. var
  1351. NrIterations: Integer;
  1352. i : Integer;
  1353. j : Integer;
  1354. TmpFillPattern : byte;
  1355. OldWriteMode : word;
  1356. OldCurrentColor : word;
  1357. begin
  1358. { convert to global coordinates ... }
  1359. x1 := x1 + StartXViewPort;
  1360. x2 := x2 + StartXViewPort;
  1361. y := y + StartYViewPort;
  1362. { if line was fully clipped then exit...}
  1363. if LineClipped(x1,y,x2,y,StartXViewPort,StartYViewPort,
  1364. StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
  1365. exit;
  1366. OldWriteMode := CurrentWriteMode;
  1367. CurrentWriteMode := NormalPut;
  1368. { number of times to go throuh the 8x8 pattern }
  1369. NrIterations := abs(x2 - x1) div 8;
  1370. Inc(NrIterations);
  1371. { Get the current pattern }
  1372. TmpFillPattern := FillPatternTable
  1373. { [FillSettings.Pattern][(((y+viewport.x1) and $7)+1];}
  1374. [FillSettings.Pattern][(y and $7)+1];
  1375. if FillSettings.Pattern = EmptyFill then
  1376. begin
  1377. OldCurrentColor := CurrentColor;
  1378. CurrentColor := CurrentBkColor;
  1379. HLine(x1,x2,y);
  1380. CurrentColor := OldCurrentColor;
  1381. end
  1382. else
  1383. if FillSettings.Pattern = SolidFill then
  1384. begin
  1385. HLine(x1,x2,y);
  1386. end
  1387. else
  1388. begin
  1389. For i:= 0 to NrIterations do
  1390. Begin
  1391. for j:=0 to 7 do
  1392. Begin
  1393. { x1 mod 8 }
  1394. if RevBitArray[x1 and 7] and TmpFillPattern <> 0 then
  1395. DirectPutpixel(x1,y)
  1396. else
  1397. begin
  1398. { According to the TP graph manual, we overwrite everything }
  1399. { which is filled up - checked against VGA and CGA drivers }
  1400. { of TP. }
  1401. OldCurrentColor := CurrentColor;
  1402. CurrentColor := CurrentBkColor;
  1403. DirectPutPixel(x1,y);
  1404. CurrentColor := OldCurrentColor;
  1405. end;
  1406. Inc(x1);
  1407. if x1 > x2 then
  1408. begin
  1409. CurrentWriteMode := OldWriteMode;
  1410. exit;
  1411. end;
  1412. end;
  1413. end;
  1414. end;
  1415. CurrentWriteMode := OldWriteMode;
  1416. end;
  1417. procedure LineRel(Dx, Dy: Integer);
  1418. Begin
  1419. Line(CurrentX, CurrentY, CurrentX + Dx, CurrentY + Dy);
  1420. CurrentX := CurrentX + Dx;
  1421. CurrentY := CurrentY + Dy;
  1422. end;
  1423. procedure LineTo(x,y : Integer);
  1424. Begin
  1425. Line(CurrentX, CurrentY, X, Y);
  1426. CurrentX := X;
  1427. CurrentY := Y;
  1428. end;
  1429. procedure Rectangle(x1,y1,x2,y2:integer);
  1430. begin
  1431. { Do not draw the end points }
  1432. Line(x1,y1,x2-1,y1);
  1433. Line(x1,y1+1,x1,y2);
  1434. Line(x2,y1,x2,y2-1);
  1435. Line(x1+1,y2,x2,y2);
  1436. end;
  1437. procedure GetLineSettings(var ActiveLineInfo : LineSettingsType);
  1438. begin
  1439. Activelineinfo:=Lineinfo;
  1440. end;
  1441. procedure SetLineStyle(LineStyle: word; Pattern: word; Thickness: word);
  1442. var
  1443. i: byte;
  1444. j: byte;
  1445. Begin
  1446. if (LineStyle > UserBitLn) or ((Thickness <> Normwidth) and (Thickness <> ThickWidth)) then
  1447. _GraphResult := grError
  1448. else
  1449. begin
  1450. LineInfo.Thickness := Thickness;
  1451. LineInfo.LineStyle := LineStyle;
  1452. case LineStyle of
  1453. UserBitLn: Lineinfo.Pattern := pattern;
  1454. SolidLn: Lineinfo.Pattern := $ffff; { ------- }
  1455. DashedLn : Lineinfo.Pattern := $F8F8; { -- -- --}
  1456. DottedLn: LineInfo.Pattern := $CCCC; { - - - - }
  1457. CenterLn: LineInfo.Pattern := $FC78; { -- - -- }
  1458. end; { end case }
  1459. { setup pattern styles }
  1460. j:=15;
  1461. for i:=0 to 15 do
  1462. Begin
  1463. { bitwise mask for each bit in the word }
  1464. if (word($01 shl i) AND LineInfo.Pattern) <> 0 then
  1465. LinePatterns[j]:=TRUE
  1466. else
  1467. LinePatterns[j]:=FALSE;
  1468. Dec(j);
  1469. end;
  1470. end;
  1471. end;
  1472. {--------------------------------------------------------------------------}
  1473. { }
  1474. { VIEWPORT RELATED ROUTINES }
  1475. { }
  1476. {--------------------------------------------------------------------------}
  1477. Procedure ClearViewPortDefault; far;
  1478. var
  1479. j: integer;
  1480. OldWriteMode, OldCurColor: word;
  1481. LineSets : LineSettingsType;
  1482. Begin
  1483. { CP is always RELATIVE coordinates }
  1484. CurrentX := 0;
  1485. CurrentY := 0;
  1486. { Save all old settings }
  1487. OldCurColor := CurrentColor;
  1488. CurrentColor:=CurrentBkColor;
  1489. OldWriteMode:=CurrentWriteMode;
  1490. GetLineSettings(LineSets);
  1491. { reset to normal line style...}
  1492. SetLineStyle(SolidLn, 0, NormWidth);
  1493. { routines are relative here...}
  1494. for J:=0 to ViewHeight do
  1495. HLine(0, ViewWidth, J);
  1496. { restore old settings...}
  1497. SetLineStyle(LineSets.LineStyle, LineSets.Pattern, LineSets.Thickness);
  1498. CurrentColor := OldCurColor;
  1499. CurrentWriteMode := OldWriteMode;
  1500. end;
  1501. Procedure SetViewPort(X1, Y1, X2, Y2: Integer; Clip: Boolean);
  1502. Begin
  1503. if (X1 > GetMaxX) or (X2 > GetMaxX) or (X1 > X2) or (X1 < 0) then
  1504. Begin
  1505. _GraphResult := grError;
  1506. exit;
  1507. end;
  1508. if (Y1 > GetMaxY) or (Y2 > GetMaxY) or (Y1 > Y2) or (Y1 < 0) then
  1509. Begin
  1510. _GraphResult := grError;
  1511. exit;
  1512. end;
  1513. { CP is always RELATIVE coordinates }
  1514. CurrentX := 0;
  1515. CurrentY := 0;
  1516. StartXViewPort := X1;
  1517. StartYViewPort := Y1;
  1518. ViewWidth := X2-X1;
  1519. ViewHeight:= Y2-Y1;
  1520. ClipPixels := Clip;
  1521. end;
  1522. procedure GetViewSettings(var viewport : ViewPortType);
  1523. begin
  1524. ViewPort.X1 := StartXViewPort;
  1525. ViewPort.Y1 := StartYViewPort;
  1526. ViewPort.X2 := ViewWidth + StartXViewPort;
  1527. ViewPort.Y2 := ViewHeight + StartYViewPort;
  1528. ViewPort.Clip := ClipPixels;
  1529. end;
  1530. procedure ClearDevice;
  1531. var
  1532. ViewPort: ViewPortType;
  1533. begin
  1534. { Reset the CP }
  1535. CurrentX := 0;
  1536. CurrentY := 0;
  1537. { save viewport }
  1538. ViewPort.X1 := StartXviewPort;
  1539. ViewPort.X2 := ViewWidth - StartXViewPort;
  1540. ViewPort.Y1 := StartYViewPort;
  1541. ViewPort.Y2 := ViewHeight - StartYViewPort;
  1542. ViewPort.Clip := ClipPixels;
  1543. { put viewport to full screen }
  1544. StartXViewPort := 0;
  1545. ViewHeight := MaxY;
  1546. StartYViewPort := 0;
  1547. ViewWidth := MaxX;
  1548. ClipPixels := TRUE;
  1549. ClearViewPort;
  1550. { restore old viewport }
  1551. StartXViewPort := ViewPort.X1;
  1552. ViewWidth := ViewPort.X2-ViewPort.X1;
  1553. StartYViewPort := ViewPort.Y1;
  1554. ViewHeight := ViewPort.Y2-ViewPort.Y1;
  1555. ClipPixels := ViewPort.Clip;
  1556. end;
  1557. {--------------------------------------------------------------------------}
  1558. { }
  1559. { BITMAP PUT/GET ROUTINES }
  1560. { }
  1561. {--------------------------------------------------------------------------}
  1562. Procedure GetScanlineDefault (Y : Integer; Var Data); far;
  1563. {********************************************************}
  1564. { Procedure GetScanLine() }
  1565. {--------------------------------------------------------}
  1566. { Returns the full scanline of the video line of the Y }
  1567. { coordinate. The values are returned in a WORD array }
  1568. { each WORD representing a pixel of the specified scanline}
  1569. {********************************************************}
  1570. Var
  1571. Offset, x : Integer;
  1572. Begin
  1573. For x:=0 to MaxX Do Begin
  1574. WordArray(Data)[x]:=GetPixel(x, y);
  1575. End;
  1576. End;
  1577. Function DefaultImageSize(X1,Y1,X2,Y2: Integer): longint; far;
  1578. Begin
  1579. { each pixel uses two bytes, to enable modes with colors up to 64K }
  1580. { to work. }
  1581. DefaultImageSize := 12 + (((X2-X1)*(Y2-Y1))*2);
  1582. end;
  1583. Procedure DefaultPutImage(X,Y: Integer; var Bitmap; BitBlt: Word); far;
  1584. type
  1585. pt = array[0..32000] of word;
  1586. ptw = array[0..3] of longint;
  1587. var
  1588. color: word;
  1589. i,j: Integer;
  1590. Y1,X1: Integer;
  1591. k: integer;
  1592. Begin
  1593. X1:= ptw(Bitmap)[0]+X; { get width and adjust end coordinate accordingly }
  1594. Y1:= ptw(Bitmap)[1]+Y; { get height and adjust end coordinate accordingly }
  1595. k:= 12; { Three reserved longs at start of bitmap }
  1596. for j:=Y to Y1 do
  1597. Begin
  1598. for i:=X to X1 do
  1599. begin
  1600. case BitBlt of
  1601. {$R-}
  1602. CopyPut: color:= pt(Bitmap)[k]; { also = normalput }
  1603. XORPut: color:= pt(Bitmap)[k] XOR GetPixel(i,j);
  1604. OrPut: color:= pt(Bitmap)[k] OR GetPixel(i,j);
  1605. AndPut: color:= pt(Bitmap)[k] AND GetPixel(i,j);
  1606. NotPut: color:= not pt(Bitmap)[k];
  1607. {$ifdef debug}
  1608. {$R+}
  1609. {$endif debug}
  1610. end;
  1611. putpixel(i,j,color);
  1612. Inc(k);
  1613. end;
  1614. end;
  1615. end;
  1616. Procedure DefaultGetImage(X1,Y1,X2,Y2: Integer; Var Bitmap); far;
  1617. type
  1618. pt = array[0..32000] of word;
  1619. ptw = array[0..3] of longint;
  1620. var
  1621. i,j: integer;
  1622. k: longint;
  1623. Begin
  1624. k:= 12; { Three reserved longs at start of bitmap }
  1625. for j:=Y1 to Y2 do
  1626. Begin
  1627. for i:=X1 to X2 do
  1628. begin
  1629. {$R-}
  1630. pt(Bitmap)[k] :=getpixel(i,j);
  1631. {$ifdef debug}
  1632. {$R+}
  1633. {$endif debug}
  1634. Inc(k);
  1635. end;
  1636. end;
  1637. ptw(Bitmap)[0] := X2-X1; { First longint is width }
  1638. ptw(Bitmap)[1] := Y2-Y1; { Second longint is height }
  1639. ptw(bitmap)[2] := 0; { Third longint is reserved}
  1640. end;
  1641. Procedure GetArcCoords(var ArcCoords: ArcCoordsType);
  1642. Begin
  1643. ArcCoords.X := ArcCall.X;
  1644. ArcCoords.Y := ArcCall.Y;
  1645. ArcCoords.XStart := ArcCall.XStart;
  1646. ArcCoords.YStart := ArcCall.YStart;
  1647. ArcCoords.XEnd := ArcCall.XEnd;
  1648. ArcCoords.YEnd := ArcCall.YEnd;
  1649. end;
  1650. procedure SetVisualPageDefault(page : word); far;
  1651. begin
  1652. end;
  1653. procedure SetActivePageDefault(page : word); far;
  1654. begin
  1655. end;
  1656. Procedure DefaultHooks;
  1657. {********************************************************}
  1658. { Procedure DefaultHooks() }
  1659. {--------------------------------------------------------}
  1660. { Resets all hookable routine either to nil for those }
  1661. { which need overrides, and others to defaults. }
  1662. { This is called each time SetGraphMode() is called. }
  1663. {********************************************************}
  1664. Begin
  1665. { All default hooks procedures }
  1666. { required...}
  1667. DirectPutPixel := nil;
  1668. PutPixel := nil;
  1669. GetPixel := nil;
  1670. SetRGBPalette := nil;
  1671. GetRGBPalette := nil;
  1672. { optional...}
  1673. {$ifdef fpc}
  1674. SetActivePage := @SetActivePageDefault;
  1675. SetVisualPage := @SetVisualPageDefault;
  1676. ClearViewPort := @ClearViewportDefault;
  1677. PutImage := @DefaultPutImage;
  1678. GetImage := @DefaultGetImage;
  1679. ImageSize := @DefaultImageSize;
  1680. {$else fpc}
  1681. SetActivePage := SetActivePageDefault;
  1682. SetVisualPage := SetVisualPageDefault;
  1683. ClearViewPort := ClearViewportDefault;
  1684. PutImage := DefaultPutImage;
  1685. GetImage := DefaultGetImage;
  1686. ImageSize := DefaultImageSize;
  1687. {$endif fpc}
  1688. GraphFreeMemPtr := nil;
  1689. GraphGetMemPtr := nil;
  1690. {$ifdef fpc}
  1691. GetScanLine := @GetScanLineDefault;
  1692. Line := @LineDefault;
  1693. InternalEllipse := @InternalEllipseDefault;
  1694. PatternLine := @PatternLineDefault;
  1695. HLine := @HLineDefault;
  1696. VLine := @VLineDefault;
  1697. {$else fpc}
  1698. GetScanLine := GetScanLineDefault;
  1699. Line := LineDefault;
  1700. InternalEllipse := InternalEllipseDefault;
  1701. PatternLine := PatternLineDefault;
  1702. HLine := HLineDefault;
  1703. VLine := VLineDefault;
  1704. {$endif fpc}
  1705. end;
  1706. Procedure InitVars;
  1707. {********************************************************}
  1708. { Procedure InitVars() }
  1709. {--------------------------------------------------------}
  1710. { Resets all internal variables, and resets all }
  1711. { overridable routines. }
  1712. {********************************************************}
  1713. Begin
  1714. DirectVideo := TRUE; { By default use fastest access possible }
  1715. ArcCall.X := 0;
  1716. ArcCall.Y := 0;
  1717. ArcCall.XStart := 0;
  1718. ArcCall.YStart := 0;
  1719. ArcCall.XEnd := 0;
  1720. ArcCall.YEnd := 0;
  1721. { Reset to default values }
  1722. IntCurrentMode := 0;
  1723. IntCurrentDriver := 0;
  1724. XAspect := 0;
  1725. YAspect := 0;
  1726. MaxX := 0;
  1727. MaxY := 0;
  1728. MaxColor := 0;
  1729. PaletteSize := 0;
  1730. DirectColor := FALSE;
  1731. HardwarePages := 0;
  1732. DefaultHooks;
  1733. end;
  1734. {$i modes.inc}
  1735. {$i graph.inc}
  1736. function InstallUserDriver(Name: string; AutoDetectPtr: Pointer): integer;
  1737. begin
  1738. _graphResult := grError;
  1739. end;
  1740. function RegisterBGIDriver(driver: pointer): integer;
  1741. begin
  1742. _graphResult := grError;
  1743. end;
  1744. { ----------------------------------------------------------------- }
  1745. Procedure Arc(X,Y : Integer; StAngle,EndAngle,Radius: word);
  1746. var
  1747. OldWriteMode: word;
  1748. Begin
  1749. if (Radius = 0) then
  1750. Exit;
  1751. if (Radius = 1) then
  1752. begin
  1753. { must use clipping ... }
  1754. { don't need to explicitly set NormalPut mode }
  1755. { because PutPixel only supports normal put }
  1756. PutPixel(X, Y,CurrentColor);
  1757. Exit;
  1758. end;
  1759. { Only if we are using thickwidths lines do we accept }
  1760. { XORput write modes. }
  1761. OldWriteMode := CurrentWriteMode;
  1762. if (LineInfo.Thickness = NormWidth) then
  1763. CurrentWriteMode := NormalPut;
  1764. InternalEllipse(X,Y,Radius,Radius,StAngle,Endangle);
  1765. CurrentWriteMode := OldWriteMode;
  1766. end;
  1767. procedure Ellipse(X,Y : Integer; stAngle, EndAngle: word; XRadius,YRadius: word);
  1768. Begin
  1769. InternalEllipse(X,Y,XRadius,YRadius,stAngle,EndAngle);
  1770. end;
  1771. procedure FillEllipse(X, Y: Integer; XRadius, YRadius: Word);
  1772. {********************************************************}
  1773. { Procedure FillEllipse() }
  1774. {--------------------------------------------------------}
  1775. { Draws a filled ellipse using (X,Y) as a center point }
  1776. { and XRadius and YRadius as the horizontal and vertical }
  1777. { axes. The ellipse is filled with the current fill color}
  1778. { and fill style, and is bordered with the current color.}
  1779. {--------------------------------------------------------}
  1780. { Important notes: }
  1781. { - CONTRRARY to VGA BGI - SetWriteMode DOES not }
  1782. { affect the contour of the ellipses. BGI mode }
  1783. { supports XORPut but the FloodFill() is still bounded}
  1784. { by the ellipse. In OUR case, XOR Mode is simply }
  1785. { not supported. }
  1786. {********************************************************}
  1787. var
  1788. OldWriteMode: Word;
  1789. begin
  1790. { only normal put supported }
  1791. OldWriteMode := CurrentWriteMode;
  1792. CurrentWriteMode := NormalPut;
  1793. InternalEllipse(X,Y,XRadius,YRadius,0,360);
  1794. FloodFill(X,Y,CurrentColor);
  1795. { restore old write mode }
  1796. CurrentWriteMode := OldWriteMode;
  1797. end;
  1798. procedure Circle(X, Y: Integer; Radius:Word);
  1799. {********************************************************}
  1800. { Draws a circle centered at X,Y with the given Radius. }
  1801. {********************************************************}
  1802. { Important notes: }
  1803. { - Thickwidth circles use the current write mode, while}
  1804. { normal width circles ALWAYS use CopyPut/NormalPut }
  1805. { mode. (Tested against VGA BGI driver -CEC 13/Aug/99 }
  1806. {********************************************************}
  1807. var OriginalArcInfo: ArcCoordsType;
  1808. OldWriteMode: word;
  1809. begin
  1810. if (Radius = 0) then
  1811. Exit;
  1812. if (Radius = 1) then
  1813. begin
  1814. { only normal put mode is supported by a call to PutPixel }
  1815. PutPixel(X, Y, CurrentColor);
  1816. Exit;
  1817. end;
  1818. { save state of arc information }
  1819. { because it is not needed for }
  1820. { a circle call. }
  1821. move(ArcCall,OriginalArcInfo, sizeof(ArcCall));
  1822. if LineInfo.Thickness = Normwidth then
  1823. begin
  1824. OldWriteMode := CurrentWriteMode;
  1825. CurrentWriteMode := CopyPut;
  1826. end;
  1827. InternalEllipse(X,Y,Radius,Radius,0,360);
  1828. if LineInfo.Thickness = Normwidth then
  1829. CurrentWriteMode := OldWriteMode;
  1830. { restore arc information }
  1831. move(OriginalArcInfo, ArcCall,sizeof(ArcCall));
  1832. end;
  1833. procedure Sector(x, y: Integer; StAngle,EndAngle, XRadius, YRadius: Word);
  1834. var angle : real;
  1835. writemode : word;
  1836. begin
  1837. Ellipse(x,y,stAngle,endAngle,XRadius,YRadius);
  1838. { As in the TP graph unit - the line settings are used to }
  1839. { define the outline of the sector. }
  1840. writemode:=Currentwritemode;
  1841. Currentwritemode:=normalput;
  1842. Line(ArcCall.XStart, ArcCall.YStart, x,y);
  1843. Line(x,y,ArcCall.Xend,ArcCall.YEnd);
  1844. { we must take care of clipping so we call PutPixel instead }
  1845. { of DirectPutPixel... }
  1846. PutPixel(ArcCall.xstart,ArcCall.ystart,CurrentColor);
  1847. PutPixel(x,y,CurrentColor);
  1848. PutPixel(ArcCall.xend,ArcCall.yend,CurrentColor);
  1849. stangle:=Stangle mod 360; EndAngle:=Endangle mod 360;
  1850. if stAngle<=Endangle then
  1851. Angle:=(stAngle+EndAngle)/2
  1852. else
  1853. angle:=(stAngle-360+EndAngle)/2;
  1854. { fill from the point in the middle of the slice }
  1855. XRadius:=(longint(XRadius)*10000) div XAspect;
  1856. YRadius:=(longint(YRadius)*10000) div YAspect;
  1857. { avoid rounding errors }
  1858. if abs(ArcCall.xstart-ArcCall.xend)
  1859. +abs(ArcCall.ystart-ArcCall.yend)>2 then
  1860. FloodFill(x+round(sin((angle+90)*Pi/180)*XRadius/2),
  1861. y+round(cos((angle+90)*Pi/180)*YRadius/2),CurrentColor);
  1862. CurrentWriteMode := writemode;
  1863. end;
  1864. procedure SetFillStyle(Pattern : word; Color: word);
  1865. begin
  1866. { on invalid input, the current fill setting will be }
  1867. { unchanged. }
  1868. if (Pattern > UserFill) or (Color > GetMaxColor) then
  1869. begin
  1870. _GraphResult := grError;
  1871. exit;
  1872. end;
  1873. FillSettings.Color := Color;
  1874. FillSettings.Pattern := Pattern;
  1875. end;
  1876. procedure SetFillPattern(Pattern: FillPatternType; Color: word);
  1877. {********************************************************}
  1878. { Changes the Current FillPattern to a user defined }
  1879. { pattern and changes also the current fill color. }
  1880. { The FillPattern is saved in the FillPattern array so }
  1881. { it can still be used with SetFillStyle(UserFill,Color) }
  1882. {********************************************************}
  1883. var
  1884. i: integer;
  1885. begin
  1886. if Color > GetMaxColor then
  1887. begin
  1888. _GraphResult := grError;
  1889. exit;
  1890. end;
  1891. FillSettings.Color := Color;
  1892. FillSettings.Pattern := UserFill;
  1893. { Save the pattern in the buffer }
  1894. For i:=1 to 8 do
  1895. FillPatternTable[UserFill][i] := Pattern[i];
  1896. end;
  1897. procedure Bar(x1,y1,x2,y2:integer);
  1898. {********************************************************}
  1899. { Important notes for compatibility with BP: }
  1900. { - WriteMode is always CopyPut }
  1901. { - No contour is drawn for the lines }
  1902. {********************************************************}
  1903. var y : Integer;
  1904. origcolor : longint;
  1905. origlinesettings: Linesettingstype;
  1906. origwritemode : Integer;
  1907. begin
  1908. origlinesettings:=lineinfo;
  1909. origcolor:=CurrentColor;
  1910. { Always copy mode for Bars }
  1911. origwritemode := CurrentWriteMode;
  1912. CurrentWriteMode := CopyPut;
  1913. { All lines used are of this style }
  1914. Lineinfo.linestyle:=solidln;
  1915. Lineinfo.thickness:=normwidth;
  1916. case Fillsettings.pattern of
  1917. EmptyFill :
  1918. begin
  1919. Currentcolor:=CurrentBkColor;
  1920. for y:=y1 to y2 do
  1921. Hline(x1,x2,y);
  1922. end;
  1923. SolidFill :
  1924. begin
  1925. CurrentColor:=FillSettings.color;
  1926. for y:=y1 to y2 do
  1927. Hline(x1,x2,y);
  1928. end;
  1929. else
  1930. Begin
  1931. CurrentColor:=FillSettings.color;
  1932. for y:=y1 to y2 do
  1933. patternline(x1,x2,y);
  1934. end;
  1935. end;
  1936. CurrentColor:= Origcolor;
  1937. LineInfo := OrigLineSettings;
  1938. CurrentWriteMode := OrigWritemode;
  1939. end;
  1940. procedure bar3D(x1, y1, x2, y2 : integer;depth : word;top : boolean);
  1941. var
  1942. origwritemode : integer;
  1943. OldX, OldY : integer;
  1944. begin
  1945. origwritemode := CurrentWriteMode;
  1946. CurrentWriteMode := CopyPut;
  1947. Bar(x1,y1,x2,y2);
  1948. Rectangle(x1,y1,x2,y2);
  1949. { Current CP should not be updated in Bar3D }
  1950. { therefore save it and then restore it on }
  1951. { exit. }
  1952. OldX := CurrentX;
  1953. OldY := CurrentY;
  1954. if top then begin
  1955. Moveto(x1,y1);
  1956. Lineto(x1+depth,y1-depth);
  1957. Lineto(x2+depth,y1-depth);
  1958. Lineto(x2,y1);
  1959. end;
  1960. if Depth <> 0 then
  1961. Begin
  1962. Moveto(x2+depth,y1-depth);
  1963. Lineto(x2+depth,y2-depth);
  1964. Lineto(x2,y2);
  1965. end;
  1966. { restore CP }
  1967. CurrentX := OldX;
  1968. CurrentY := OldY;
  1969. CurrentWriteMode := origwritemode;
  1970. end;
  1971. {--------------------------------------------------------------------------}
  1972. { }
  1973. { COLOR AND PALETTE ROUTINES }
  1974. { }
  1975. {--------------------------------------------------------------------------}
  1976. {$i palette.inc}
  1977. procedure SetColor(Color: Word);
  1978. Begin
  1979. CurrentColor := Color;
  1980. end;
  1981. function GetColor: Word;
  1982. Begin
  1983. GetColor := CurrentColor;
  1984. end;
  1985. function GetBkColor: Word;
  1986. Begin
  1987. GetBkColor := CurrentBkColor;
  1988. end;
  1989. procedure SetBkColor(ColorNum: Word);
  1990. { Background color means background screen color in this case, and it is }
  1991. { INDEPENDANT of the viewport settings, so we must clear the whole screen }
  1992. { with the color. }
  1993. var
  1994. ViewPort: ViewportType;
  1995. Begin
  1996. GetViewSettings(Viewport);
  1997. SetViewPort(0,0,MaxX,MaxY,FALSE);
  1998. CurrentBkColor := ColorNum;
  1999. ClearViewPort;
  2000. SetViewport(ViewPort.X1,Viewport.Y1,Viewport.X2,Viewport.Y2,Viewport.Clip);
  2001. end;
  2002. function GetMaxColor: word;
  2003. { Checked against TP VGA driver - CEC }
  2004. begin
  2005. GetMaxColor:=MaxColor-1; { based on an index of zero so subtract one }
  2006. end;
  2007. Procedure MoveRel(Dx, Dy: Integer);
  2008. Begin
  2009. CurrentX := CurrentX + Dx;
  2010. CurrentY := CurrentY + Dy;
  2011. end;
  2012. Procedure MoveTo(X,Y: Integer);
  2013. {********************************************************}
  2014. { Procedure MoveTo() }
  2015. {--------------------------------------------------------}
  2016. { Moves the current pointer in VIEWPORT relative }
  2017. { coordinates to the specified X,Y coordinate. }
  2018. {********************************************************}
  2019. Begin
  2020. CurrentX := X;
  2021. CurrentY := Y;
  2022. end;
  2023. function GraphErrorMsg(ErrorCode: Integer): string;
  2024. Begin
  2025. GraphErrorMsg:='';
  2026. case ErrorCode of
  2027. grOk,grFileNotFound,grInvalidDriver: exit;
  2028. grNoInitGraph: GraphErrorMsg:='Graphics driver not installed';
  2029. grNotDetected: GraphErrorMsg:='Graphics hardware not detected';
  2030. grNoLoadMem,grNoScanMem,grNoFloodMem: GraphErrorMsg := 'Not enough memory for graphics';
  2031. grNoFontMem: GraphErrorMsg := 'Not enough memory to load font';
  2032. grFontNotFound: GraphErrorMsg:= 'Font file not found';
  2033. grInvalidMode: GraphErrorMsg := 'Invalid graphics mode';
  2034. grError: GraphErrorMsg:='Graphics error';
  2035. grIoError: GraphErrorMsg:='Graphics I/O error';
  2036. grInvalidFont,grInvalidFontNum: GraphErrorMsg := 'Invalid font';
  2037. grInvalidVersion: GraphErrorMsg:='Invalid driver version';
  2038. end;
  2039. end;
  2040. Function GetMaxX: Integer;
  2041. { Routine checked against VGA driver - CEC }
  2042. Begin
  2043. GetMaxX := MaxX;
  2044. end;
  2045. Function GetMaxY: Integer;
  2046. { Routine checked against VGA driver - CEC }
  2047. Begin
  2048. GetMaxY := MaxY;
  2049. end;
  2050. Function GraphResult: Integer;
  2051. Begin
  2052. GraphResult := _GraphResult;
  2053. _GraphResult := grOk;
  2054. end;
  2055. Function GetX: Integer;
  2056. Begin
  2057. GetX := CurrentX;
  2058. end;
  2059. Function GetY: Integer;
  2060. Begin
  2061. GetY := CurrentY;
  2062. end;
  2063. Function GetDriverName: string;
  2064. var
  2065. mode: PModeInfo;
  2066. begin
  2067. GetDriverName:=DriverName;
  2068. end;
  2069. procedure graphdefaults;
  2070. { PS: GraphDefaults does not ZERO the ArcCall structure }
  2071. { so a call to GetArcCoords will not change even the }
  2072. { returned values even if GraphDefaults is called in }
  2073. { between. }
  2074. var
  2075. i: integer;
  2076. begin
  2077. lineinfo.linestyle:=solidln;
  2078. lineinfo.thickness:=normwidth;
  2079. { reset line style pattern }
  2080. for i:=0 to 15 do
  2081. LinePatterns[i] := TRUE;
  2082. { By default, according to the TP prog's reference }
  2083. { the default pattern is solid, and the default }
  2084. { color is the maximum color in the palette. }
  2085. fillsettings.color:=GetMaxColor;
  2086. fillsettings.pattern:=solidfill;
  2087. { GraphDefaults resets the User Fill pattern to $ff }
  2088. { checked with VGA BGI driver - CEC }
  2089. for i:=1 to 8 do
  2090. FillPatternTable[UserFill][i] := $ff;
  2091. CurrentColor:=white;
  2092. SetBkColor(Black);
  2093. ClipPixels := TRUE;
  2094. { Reset the viewport }
  2095. StartXViewPort := 0;
  2096. StartYViewPort := 0;
  2097. ViewWidth := MaxX;
  2098. ViewHeight := MaxY;
  2099. { Reset CP }
  2100. CurrentX := 0;
  2101. CurrentY := 0;
  2102. { normal write mode }
  2103. CurrentWriteMode := CopyPut;
  2104. { Schriftart einstellen }
  2105. CurrentTextInfo.font := DefaultFont;
  2106. CurrentTextInfo.direction:=HorizDir;
  2107. CurrentTextInfo.charsize:=1;
  2108. CurrentTextInfo.horiz:=LeftText;
  2109. CurrentTextInfo.vert:=TopText;
  2110. XAspect:=10000; YAspect:=10000;
  2111. end;
  2112. procedure GetAspectRatio(var Xasp,Yasp : word);
  2113. begin
  2114. XAsp:=XAspect;
  2115. YAsp:=YAspect;
  2116. end;
  2117. procedure SetAspectRatio(Xasp, Yasp : word);
  2118. begin
  2119. Xaspect:= XAsp;
  2120. YAspect:= YAsp;
  2121. end;
  2122. procedure SetWriteMode(WriteMode : integer);
  2123. begin
  2124. if (writemode<>xorput) and (writemode<>CopyPut) then
  2125. exit;
  2126. CurrentWriteMode := WriteMode;
  2127. end;
  2128. procedure GetFillSettings(var Fillinfo:Fillsettingstype);
  2129. begin
  2130. Fillinfo:=Fillsettings;
  2131. end;
  2132. procedure GetFillPattern(var FillPattern:FillPatternType);
  2133. begin
  2134. FillPattern:=FillpatternTable[UserFill];
  2135. end;
  2136. procedure DrawPoly(numpoints : word;var polypoints);
  2137. type
  2138. ppointtype = ^pointtype;
  2139. pt = array[0..16000] of pointtype;
  2140. var
  2141. i : longint;
  2142. begin
  2143. if numpoints < 2 then
  2144. begin
  2145. _GraphResult := grError;
  2146. exit;
  2147. end;
  2148. for i:=0 to numpoints-2 do
  2149. line(pt(polypoints)[i].x,
  2150. pt(polypoints)[i].y,
  2151. pt(polypoints)[i+1].x,
  2152. pt(polypoints)[i+1].y);
  2153. end;
  2154. procedure PieSlice(X,Y,stangle,endAngle:integer;Radius: Word);
  2155. var angle : real;
  2156. XRadius, YRadius : word;
  2157. writemode : word;
  2158. begin
  2159. Arc(x,y,StAngle,EndAngle,Radius);
  2160. Line(ArcCall.XStart, ArcCall.YStart, x,y);
  2161. Line(x,y, ArcCall.XEnd, ArcCall.YEnd);
  2162. { must use PutPixel() instead of DirectPutPixel because we need }
  2163. { clipping... }
  2164. PutPixel(ArcCall.xstart,ArcCall.ystart,CurrentColor);
  2165. PutPixel(x,y,CurrentColor);
  2166. PutPixel(ArcCall.xend,ArcCall.yend,CurrentColor);
  2167. Stangle:=stAngle mod 360; EndAngle:=Endangle mod 360;
  2168. if Stangle<=Endangle then
  2169. angle:=(StAngle+EndAngle)/2
  2170. else
  2171. angle:=(Stangle-360+Endangle)/2;
  2172. { fill from the point in the middle of the slice }
  2173. XRadius:=(longint(Radius)*10000) div XAspect;
  2174. YRadius:=(longint(Radius)*10000) div YAspect;
  2175. { avoid rounding errors }
  2176. if abs(ArcCall.xstart-ArcCall.xend)
  2177. +abs(ArcCall.ystart-ArcCall.yend)>2 then
  2178. { FloodFill(x+round(sin((angle+90)*Pi/180)*XRadius/2),
  2179. y+round(cos((angle+90)*Pi/180)*YRadius/2),truecolor);}
  2180. { CurrentWriteMode := writemode;}
  2181. end;
  2182. {$i fills.inc}
  2183. {$i text.inc}
  2184. procedure InitGraph(var GraphDriver:Integer;var GraphMode:Integer;
  2185. const PathToDriver:String);
  2186. var i,index:Integer;
  2187. LoMode, HiMode: Integer;
  2188. CpyMode: Integer;
  2189. CpyDriver: Integer;
  2190. begin
  2191. { path to the fonts (where they will be searched)...}
  2192. bgipath:=PathToDriver;
  2193. if bgipath[length(bgipath)]<>'\' then
  2194. bgipath:=bgipath+'\';
  2195. { make sure our driver list is setup...}
  2196. QueryAdapterInfo;
  2197. if not assigned(SaveVideoState) then
  2198. RunError(216);
  2199. SaveVideoState;
  2200. InitVars;
  2201. DriverName:=InternalDriverName; { DOS Graphics driver }
  2202. if (Graphdriver=Detect) then
  2203. begin
  2204. HiMode := -1;
  2205. LoMode := -1;
  2206. { We start at VGA-1 }
  2207. GraphDriver := VGA;
  2208. CpyMode := 0;
  2209. { search all possible graphic drivers in ascending order...}
  2210. { usually the new driver numbers indicate newest hardware...}
  2211. { Internal driver numbers start at VGA=9 }
  2212. repeat
  2213. GetModeRange(GraphDriver,LoMode,HiMode);
  2214. { save the highest mode possible...}
  2215. if HiMode = -1 then break;
  2216. CpyMode:=HiMode;
  2217. CpyDriver:=GraphDriver;
  2218. { go to next driver if it exists...}
  2219. Inc(GraphDriver);
  2220. until (CpyMode=-1);
  2221. IntCurrentDriver := CpyDriver;
  2222. { If this is equal to -1 then no graph mode possible...}
  2223. if CpyMode = -1 then
  2224. begin
  2225. _GraphResult := grNotDetected;
  2226. exit;
  2227. end;
  2228. { Actually set the graph mode...}
  2229. SetGraphMode(CpyMode);
  2230. end
  2231. else
  2232. begin
  2233. { Search if that graphics modec actually exists...}
  2234. if SearchMode(GraphDriver,GraphMode) = nil then
  2235. begin
  2236. _GraphResult := grInvalidMode;
  2237. exit;
  2238. end
  2239. else
  2240. begin
  2241. IntCurrentDriver := GraphDriver;
  2242. SetGraphMode(GraphMode);
  2243. end;
  2244. end;
  2245. end;
  2246. procedure SetDirectVideo(DirectAccess: boolean);
  2247. begin
  2248. DirectVideo := DirectAccess;
  2249. end;
  2250. function GetDirectVideo: boolean;
  2251. begin
  2252. GetDirectVideo := DirectVideo;
  2253. end;
  2254. var
  2255. ExitSave: pointer;
  2256. begin
  2257. ModeList := nil;
  2258. SaveVideoState := nil;
  2259. RestoreVideoState := nil;
  2260. SavePtr := Nil;
  2261. { This must be called at startup... because GetGraphMode may }
  2262. { be called even when not in graph mode. }
  2263. QueryAdapterInfo;
  2264. { Install standard fonts }
  2265. { This is done BEFORE startup... }
  2266. InstalledFonts := 0;
  2267. InstallUserFont('TRIP');
  2268. InstallUserFont('LITT');
  2269. InstallUserFont('SANS');
  2270. InstallUserFont('GOTH');
  2271. { This installs an exit procedure which cleans up the mode list...}
  2272. ExitSave := ExitProc;
  2273. ExitProc := @CleanMode;
  2274. end.
  2275. PieSlice
  2276. Sector
  2277. SetGraphBufSize
  2278. SetBkColor
  2279. DetectGraph
  2280. { DetectGraph() }
  2281. { SetBkColor() }
  2282. {
  2283. $log$
  2284. }