graph.pp 84 KB

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