graph.pp 89 KB

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