graph.pp 71 KB

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