graph.pp 78 KB

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