graph.pp 76 KB

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