graph.pp 68 KB

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