graph.pp 85 KB

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