graph.pp 103 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 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. { - Imagesize returns a longint instead of a word }
  38. { - ImageSize cannot return an error value }
  39. {-------------------------------------------------------}
  40. { AUTHORS: }
  41. { Gernot Tenchio - original version }
  42. { Florian Klaempfl - major updates }
  43. { Pierre Mueller - major bugfixes }
  44. { Carl Eric Codere - complete rewrite }
  45. { Thomas Schatzl - optimizations,routines and }
  46. { suggestions. }
  47. { Jonas Maebe - bugfixes and optimizations }
  48. { Credits (external): }
  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. {--------------------------------------------------------}
  188. { text.inc will crash on aligned requirement machines. }
  189. { (packed record for fontrec) }
  190. {$ifndef fpc}
  191. {$G+}
  192. {$endif}
  193. Interface
  194. {$ifdef win32}
  195. uses
  196. windows;
  197. {$endif win32}
  198. type smallint = -32768..32767;
  199. const
  200. maxsmallint = high(smallint);
  201. { error codes }
  202. grOk = 0;
  203. grNoInitGraph = -1;
  204. grNotDetected = -2;
  205. grFileNotFound = -3;
  206. grInvalidDriver = -4;
  207. grNoLoadMem = -5;
  208. grNoScanMem = -6;
  209. grNoFloodMem = -7;
  210. grFontNotFound = -8;
  211. grNoFontMem = -9;
  212. grInvalidMode = -10;
  213. grError = -11;
  214. grIOerror = -12;
  215. grInvalidFont = -13;
  216. grInvalidFontNum = -14;
  217. grInvalidVersion = -18;
  218. { Color constants for setpalette }
  219. black = 0;
  220. blue = 1;
  221. green = 2;
  222. cyan = 3;
  223. red = 4;
  224. magenta = 5;
  225. brown = 6;
  226. lightgray = 7;
  227. darkgray = 8;
  228. lightblue = 9;
  229. lightgreen = 10;
  230. lightcyan = 11;
  231. lightred = 12;
  232. lightmagenta = 13;
  233. yellow = 14;
  234. white = 15;
  235. EGABlack = 0;
  236. EGABlue = 1;
  237. EGAGreen = 2;
  238. EGACyan = 3;
  239. EGARed = 4;
  240. EGAMagenta = 5;
  241. EGALightgray= 7;
  242. EGABrown = 20;
  243. EGADarkgray = 56;
  244. EGALightblue = 57;
  245. EGALightgreen = 58;
  246. EGALightcyan = 59;
  247. EGALightred = 60;
  248. EGALightmagenta=61;
  249. EGAYellow = 62;
  250. EGAWhite = 63;
  251. { Line styles for GetLineStyle/SetLineStyle }
  252. SolidLn = 0;
  253. DottedLn = 1;
  254. CenterLn = 2;
  255. DashedLn = 3;
  256. UserBitLn = 4;
  257. NormWidth = 1;
  258. ThickWidth = 3;
  259. { Set/GetTextStyle Konstanten: }
  260. DefaultFont = 0;
  261. TriplexFont = 1;
  262. SmallFont = 2;
  263. SansSerifFont = 3;
  264. GothicFont = 4;
  265. ScriptFont = 5;
  266. SimpleFont = 6;
  267. TSCRFont = 7;
  268. LCOMFont = 8;
  269. EuroFont = 9;
  270. BoldFont = 10;
  271. HorizDir = 0;
  272. VertDir = 1;
  273. UserCharSize = 0;
  274. ClipOn = true;
  275. ClipOff = false;
  276. { Bar3D constants }
  277. TopOn = true;
  278. TopOff = false;
  279. { fill pattern for Get/SetFillStyle: }
  280. EmptyFill = 0;
  281. SolidFill = 1;
  282. LineFill = 2;
  283. LtSlashFill = 3;
  284. SlashFill = 4;
  285. BkSlashFill = 5;
  286. LtBkSlashFill = 6;
  287. HatchFill = 7;
  288. XHatchFill = 8;
  289. InterleaveFill = 9;
  290. WideDotFill = 10;
  291. CloseDotFill = 11;
  292. UserFill = 12;
  293. { bitblt operators }
  294. NormalPut = 0;
  295. CopyPut = 0;
  296. XORPut = 1;
  297. OrPut = 2;
  298. AndPut = 3;
  299. NotPut = 4;
  300. { SetTextJustify constants }
  301. LeftText = 0;
  302. CenterText = 1;
  303. RightText = 2;
  304. BottomText = 0;
  305. TopText = 2;
  306. { graphic drivers }
  307. CurrentDriver = -128;
  308. Detect = 0;
  309. LowRes = 1;
  310. HercMono = 7;
  311. VGA = 9;
  312. VESA = 10;
  313. { graph modes }
  314. Default = 0;
  315. { VGA Driver modes }
  316. VGALo = 0;
  317. VGAMed = 1;
  318. VGAHi = 2;
  319. { Hercules mono card }
  320. HercMonoHi = 0;
  321. MaxColors = 255; { Maximum possible colors using a palette }
  322. { otherwise, direct color encoding }
  323. type
  324. RGBRec = packed record
  325. Red: smallint;
  326. Green: smallint;
  327. Blue : smallint;
  328. end;
  329. PaletteType = record
  330. Size : longint;
  331. Colors : array[0..MaxColors] of RGBRec;
  332. end;
  333. LineSettingsType = record
  334. linestyle : word;
  335. pattern : word;
  336. thickness : word;
  337. end;
  338. TextSettingsType = record
  339. font : word;
  340. direction : word;
  341. charsize : word;
  342. horiz : word;
  343. vert : word;
  344. end;
  345. FillSettingsType = record
  346. pattern : word;
  347. color : word;
  348. end;
  349. FillPatternType = array[1..8] of byte;
  350. PointType = record
  351. x,y : smallint;
  352. end;
  353. ViewPortType = record
  354. x1,y1,x2,y2 : smallint;
  355. Clip : boolean;
  356. end;
  357. ArcCoordsType = record
  358. x,y : smallint;
  359. xstart,ystart : smallint;
  360. xend,yend : smallint;
  361. end;
  362. {$IFDEF FPC}
  363. graph_int = longint; { platform specific smallint used for indexes;
  364. should be 16 bits on TP/BP and 32 bits on every-
  365. thing else for speed reasons }
  366. graph_float = single; { the platform's preferred floating point size }
  367. {$ELSE}
  368. graph_int = smallint; { platform specific smallint used for indexes;
  369. should be 16 bits on TP/BP and 32 bits on every-
  370. thing else for speed reasons }
  371. graph_float = real; { the platform's preferred floating point size }
  372. {$ENDIF}
  373. const
  374. fillpatternTable : array[0..12] of FillPatternType = (
  375. ($00,$00,$00,$00,$00,$00,$00,$00), { background color }
  376. ($ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff), { foreground color }
  377. ($ff,$ff,$00,$00,$ff,$ff,$00,$00), { horizontal lines }
  378. ($01,$02,$04,$08,$10,$20,$40,$80), { slashes }
  379. ($07,$0e,$1c,$38,$70,$e0,$c1,$83), { thick slashes }
  380. ($07,$83,$c1,$e0,$70,$38,$1c,$0e), { thick backslashes }
  381. ($5a,$2d,$96,$4b,$a5,$d2,$69,$b4), { backslashes }
  382. ($ff,$88,$88,$88,$ff,$88,$88,$88), { small boxes }
  383. ($18,$24,$42,$81,$81,$42,$24,$18), { rhombus }
  384. ($cc,$33,$cc,$33,$cc,$33,$cc,$33), { wall pattern }
  385. ($80,$00,$08,$00,$80,$00,$08,$00), { wide points }
  386. ($88,$00,$22,$00,$88,$00,$22,$00), { dense points }
  387. (0,0,0,0,0,0,0,0) { user defined line style }
  388. );
  389. { ******************** PROCEDURAL VARIABLES ********************* }
  390. { * These are hooks which have device specific stuff in them, * }
  391. { * therefore to add new modes or to redirect these routines * }
  392. { * then declare variables of these types as shown below. * }
  393. {-----------------------------------------------------------------}
  394. TYPE
  395. { This is the standard putpixel routine used by all function }
  396. { drawing routines, it will use the viewport settings, as }
  397. { well as clip, and use the current foreground color to plot }
  398. { the desired pixel. }
  399. defpixelproc = procedure(X,Y: smallint);
  400. { standard plot and get pixel }
  401. getpixelproc = function(X,Y: smallint): word;
  402. putpixelproc = procedure(X,Y: smallint; Color: Word);
  403. { clears the viewport, also used to clear the device }
  404. clrviewproc = procedure;
  405. { putimage procedure, can be hooked to accomplish transparency }
  406. putimageproc = procedure (X,Y: smallint; var Bitmap; BitBlt: Word);
  407. getimageproc = procedure(X1,Y1,X2,Y2: smallint; Var Bitmap);
  408. imagesizeproc= function (X1,Y1,X2,Y2: smallint): longint;
  409. graphfreememprc = procedure (var P: Pointer; size: word);
  410. graphgetmemprc = procedure (var P: pointer; size: word);
  411. { internal routines -- can be hooked for much faster drawing }
  412. { draw filled horizontal lines using current color }
  413. { on entry coordinates are already clipped. }
  414. hlineproc = procedure (x, x2,y : smallint);
  415. { on entry coordinates are already clipped. }
  416. { draw filled vertical line using current color }
  417. vlineproc = procedure (x,y,y2: smallint);
  418. { this routine is used to draw filled patterns for all routines }
  419. { that require it. (FillPoly, FloodFill, Sector, etc... }
  420. { clipping is verified, uses current Fill settings for drawing }
  421. patternlineproc = procedure (x1,x2,y: smallint);
  422. { this routine is used to draw all circles/ellipses/sectors }
  423. { more info... on this later... }
  424. ellipseproc = procedure (X,Y: smallint;XRadius: word;
  425. YRadius:word; stAngle,EndAngle: word; fp: PatternLineProc);
  426. { Line routine - draws lines thick/norm widths with current }
  427. { color and line style - LINE must be clipped here. }
  428. lineproc = procedure (X1, Y1, X2, Y2 : smallint);
  429. { this routine is used for FloodFill - it returns an entire }
  430. { screen scan line with a word for each pixel in the scanline. }
  431. { Also handy for GetImage, so I added x coords as well (JM) }
  432. getscanlineproc = procedure (X1, X2, Y : smallint; var data);
  433. { changes the active display screen where we draw to... }
  434. setactivepageproc = procedure (page: word);
  435. { changes the active display screen which we see ... }
  436. setvisualpageproc = procedure (page: word);
  437. { this routine actually switches to the desired video mode. }
  438. initmodeproc = procedure;
  439. { this routine is called to save the sate just before a mode set }
  440. savestateproc = procedure;
  441. { this routine is called in closegraph to cleanup... }
  442. restorestateproc = procedure;
  443. { This routine is a hook for SetRGBPalette }
  444. setrgbpaletteproc =
  445. procedure(ColorNum, RedValue, GreenValue, BlueValue: smallint);
  446. { This routine is a hook for GetRGBPalette }
  447. getrgbpaletteproc =
  448. procedure(ColorNum: smallint; var
  449. RedValue, GreenValue, BlueValue: smallint);
  450. TYPE
  451. {-----------------------------------}
  452. { Linked list for mode information }
  453. { This list is set up by one of the }
  454. { following routines: }
  455. { It lists all available resolutions}
  456. { on this display adapter. }
  457. {-----------------------------------}
  458. { QueryAdapter() }
  459. { DetectGraph() }
  460. { InitGraph() }
  461. {-----------------------------------}
  462. PModeInfo = ^TModeInfo;
  463. TModeInfo = record
  464. DriverNumber: smallint;
  465. ModeNumber: smallint;
  466. MaxColor: Longint; { Maximum colors on screen }
  467. PaletteSize : Longint; { Maximum palette entry we can change }
  468. XAspect : word; { XAspect ratio correction factor }
  469. YAspect : word; { YAspect ratio correction factor }
  470. MaxX: word; { Max-X row }
  471. MaxY: word; { Max. column. }
  472. DirectColor: boolean; { Is this a direct color mode?? }
  473. Hardwarepages: byte; { total number of image pages - 1 }
  474. ModeName: String[18];
  475. { necessary hooks ... }
  476. DirectPutPixel : DefPixelProc;
  477. GetPixel : GetPixelProc;
  478. PutPixel : PutPixelProc;
  479. SetRGBPalette : SetRGBPaletteProc;
  480. GetRGBPalette : GetRGBPaletteProc;
  481. { defaults possible ... }
  482. SetVisualPage : SetVisualPageProc;
  483. SetActivePage : SetActivePageProc;
  484. ClearViewPort : ClrViewProc;
  485. PutImage : PutImageProc;
  486. GetImage : GetImageProc;
  487. ImageSize : ImageSizeProc;
  488. GetScanLine : GetScanLineProc;
  489. Line : LineProc;
  490. InternalEllipse: EllipseProc;
  491. PatternLine : PatternLineProc;
  492. HLine : HLineProc;
  493. VLine : VLineProc;
  494. InitMode : InitModeProc;
  495. next: PModeInfo;
  496. end;
  497. VAR
  498. DirectPutPixel : DefPixelProc;
  499. ClearViewPort : ClrViewProc;
  500. PutPixel : PutPixelProc;
  501. PutImage : PutImageProc;
  502. GetImage : GetImageProc;
  503. ImageSize : ImageSizeProc;
  504. GetPixel : GetPixelProc;
  505. SetVisualPage : SetVisualPageProc;
  506. SetActivePage : SetActivePageProc;
  507. SetRGBPalette : SetRGBPaletteProc;
  508. GetRGBPalette : GetRGBPaletteProc;
  509. GraphFreeMemPtr: graphfreememprc;
  510. GraphGetMemPtr : graphgetmemprc;
  511. GetScanLine : GetScanLineProc;
  512. Line : LineProc;
  513. InternalEllipse: EllipseProc;
  514. PatternLine : PatternLineProc;
  515. HLine : HLineProc;
  516. VLine : VLineProc;
  517. SaveVideoState : SaveStateProc;
  518. RestoreVideoState: RestoreStateProc;
  519. ExitSave: pointer;
  520. Procedure Closegraph;
  521. procedure SetLineStyle(LineStyle: word; Pattern: word; Thickness: word);
  522. function GraphErrorMsg(ErrorCode: smallint): string;
  523. Function GetMaxX: smallint;
  524. Function GetMaxY: smallint;
  525. Procedure SetViewPort(X1, Y1, X2, Y2: smallint; Clip: Boolean);
  526. Function GraphResult: smallint;
  527. function GetModeName(ModeNumber: smallint): string;
  528. procedure SetGraphMode(Mode: smallint);
  529. function GetGraphMode: smallint;
  530. function GetMaxMode: word;
  531. procedure RestoreCrtMode;
  532. procedure GetModeRange(GraphDriver: smallint; var LoMode, HiMode: smallint);
  533. Function GetX: smallint;
  534. Function GetY: smallint;
  535. procedure GraphDefaults;
  536. procedure ClearDevice;
  537. procedure GetViewSettings(var viewport : ViewPortType);
  538. procedure SetWriteMode(WriteMode : smallint);
  539. procedure GetFillSettings(var Fillinfo:Fillsettingstype);
  540. procedure GetFillPattern(var FillPattern:FillPatternType);
  541. procedure GetLineSettings(var ActiveLineInfo : LineSettingsType);
  542. procedure InitGraph(var GraphDriver:smallint;var GraphMode:smallint;const PathToDriver:String);
  543. procedure DetectGraph(var GraphDriver:smallint;var GraphMode:smallint);
  544. function InstallUserDriver(Name: string; AutoDetectPtr: Pointer): smallint;
  545. function RegisterBGIDriver(driver: pointer): smallint;
  546. procedure SetFillStyle(Pattern : word; Color: word);
  547. procedure SetFillPattern(Pattern: FillPatternType; Color: word);
  548. Function GetDriverName: string;
  549. procedure MoveRel(Dx, Dy: smallint);
  550. procedure MoveTo(X,Y: smallint);
  551. procedure SetDirectVideo(DirectAccess: boolean);
  552. function GetDirectVideo: boolean;
  553. { -------------------- Color/Palette ------------------------------- }
  554. procedure SetBkColor(ColorNum: Word);
  555. function GetColor: Word;
  556. function GetBkColor: Word;
  557. procedure SetColor(Color: Word);
  558. function GetMaxColor: word;
  559. procedure SetAllPalette(var Palette:PaletteType);
  560. procedure SetPalette(ColorNum: word; Color: shortint);
  561. procedure GetPalette(var Palette: PaletteType);
  562. function GetPaletteSize: smallint;
  563. procedure GetDefaultPalette(var Palette: PaletteType);
  564. { -------------------- Shapes/Lines -------------------------------- }
  565. procedure Rectangle(x1,y1,x2,y2:smallint);
  566. procedure Bar(x1,y1,x2,y2:smallint);
  567. procedure Bar3D(x1, y1, x2, y2 : smallint;depth : word;top : boolean);
  568. procedure FillPoly(NumPoints: word; Var PolyPoints);
  569. procedure DrawPoly(NumPoints : word;var polypoints);
  570. procedure LineRel(Dx, Dy: smallint);
  571. procedure LineTo(X,Y : smallint);
  572. procedure FloodFill(x : smallint; y : smallint; Border: word);
  573. { -------------------- Circle related routines --------------------- }
  574. procedure GetAspectRatio(var Xasp,Yasp : word);
  575. procedure SetAspectRatio(Xasp, Yasp : word);
  576. procedure GetArcCoords(var ArcCoords: ArcCoordsType);
  577. procedure Arc(X,Y : smallint; StAngle,EndAngle,Radius: word);
  578. procedure PieSlice(X,Y,stangle,endAngle:smallint;Radius: Word);
  579. procedure FillEllipse(X, Y: smallint; XRadius, YRadius: Word);
  580. procedure Circle(X, Y: smallint; Radius:Word);
  581. procedure Sector(x, y: smallint; StAngle,EndAngle, XRadius, YRadius: Word);
  582. procedure Ellipse(X,Y : smallint; stAngle, EndAngle: word; XRadius,
  583. YRadius: word);
  584. { --------------------- Text related routines --------------------- }
  585. function InstallUserFont(const FontFileName : string) : smallint;
  586. function RegisterBGIfont(font : pointer) : smallint;
  587. procedure GetTextSettings(var TextInfo : TextSettingsType);
  588. function TextHeight(const TextString : string) : word;
  589. function TextWidth(const TextString : string) : word;
  590. procedure SetTextJustify(horiz,vert : word);
  591. procedure SetTextStyle(font,direction : word;charsize : word);
  592. procedure SetUserCharSize(Multx,Divx,Multy,Divy : word);
  593. procedure OutTextXY(x,y : smallint;const TextString : string);
  594. procedure OutText(const TextString : string);
  595. { Load extra graph additions per system like mode constants }
  596. {$i graphh.inc}
  597. Implementation
  598. { what a mess ... it would be much better if the graph unit }
  599. { would follow the structure of the FPC system unit: }
  600. { the main file is system depended and the system independend part }
  601. { is included (FK) }
  602. {$ifdef fpc}
  603. {$ifdef go32v2}
  604. {$define dpmi}
  605. uses go32,ports;
  606. Type TDPMIRegisters = go32.registers;
  607. {$endif go32v2}
  608. {$ifdef win32}
  609. uses
  610. strings;
  611. {$endif}
  612. {$ifdef linux}
  613. uses linux;
  614. {$endif}
  615. {$else fpc}
  616. {$IFDEF DPMI}
  617. uses WinAPI;
  618. {$ENDIF}
  619. {$endif fpc}
  620. {$ifdef logging}
  621. var debuglog: text;
  622. function strf(l: longint): string;
  623. begin
  624. str(l, strf)
  625. end;
  626. Procedure Log(Const s: String);
  627. Begin
  628. Append(debuglog);
  629. Write(debuglog, s);
  630. Close(debuglog);
  631. End;
  632. Procedure LogLn(Const s: string);
  633. Begin
  634. Append(debuglog);
  635. Writeln(debuglog,s);
  636. Close(debuglog);
  637. End;
  638. {$endif logging}
  639. const
  640. StdBufferSize = 4096; { Buffer size for FloodFill }
  641. type
  642. tinttable = array[0..16383] of smallint;
  643. pinttable = ^tinttable;
  644. WordArray = Array [0..StdbufferSize] Of word;
  645. PWordArray = ^WordArray;
  646. const
  647. { Mask for each bit in byte used to determine pattern }
  648. BitArray: Array[0..7] of byte =
  649. ($01,$02,$04,$08,$10,$20,$40,$80);
  650. RevbitArray: Array[0..7] of byte =
  651. ($80,$40,$20,$10,$08,$04,$02,$01);
  652. { pre expanded line patterns }
  653. { 0 = LSB of byte pattern }
  654. { 15 = MSB of byte pattern }
  655. LinePatterns: Array[0..15] of BOOLEAN =
  656. (TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,
  657. TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE);
  658. const
  659. BGIPath : string = '.';
  660. { Default font 8x8 system from IBM PC }
  661. {$i fontdata.inc}
  662. var
  663. CurrentColor: Word;
  664. CurrentBkColor: Word;
  665. CurrentX : smallint; { viewport relative }
  666. CurrentY : smallint; { viewport relative }
  667. ClipPixels: Boolean; { Should cliiping be enabled }
  668. CurrentWriteMode: smallint;
  669. _GraphResult : smallint;
  670. LineInfo : LineSettingsType;
  671. FillSettings: FillSettingsType;
  672. { information for Text Output routines }
  673. CurrentTextInfo : TextSettingsType;
  674. CurrentXRatio, CurrentYRatio: graph_float;
  675. installedfonts: longint; { Number of installed fonts }
  676. StartXViewPort: smallint; { absolute }
  677. StartYViewPort: smallint; { absolute }
  678. ViewWidth : smallint;
  679. ViewHeight: smallint;
  680. IsGraphMode : Boolean; { Indicates if we are in graph mode or not }
  681. ArcCall: ArcCoordsType; { Information on the last call to Arc or Ellipse }
  682. var
  683. { ******************** HARDWARE INFORMATION ********************* }
  684. { Should be set in InitGraph once only. }
  685. IntCurrentMode : smallint;
  686. IntCurrentDriver : smallint; { Currently loaded driver }
  687. XAspect : word;
  688. YAspect : word;
  689. MaxX : smallint; { Maximum resolution - ABSOLUTE }
  690. MaxY : smallint; { Maximum resolution - ABSOLUTE }
  691. MaxColor : Longint;
  692. PaletteSize : longint; { Maximum palette entry we can set, usually equal}
  693. { maxcolor. }
  694. HardwarePages : byte; { maximum number of hardware visual pages }
  695. DriverName: String;
  696. DirectColor : Boolean ; { Is it a direct color mode? }
  697. ModeList : PModeInfo;
  698. DirectVideo : Boolean; { Direct access to video memory? }
  699. {--------------------------------------------------------------------------}
  700. { }
  701. { LINE AND LINE RELATED ROUTINES }
  702. { }
  703. {--------------------------------------------------------------------------}
  704. {$i clip.inc}
  705. procedure HLineDefault(x,x2,y: smallint); {$ifndef fpc}far;{$endif fpc}
  706. var
  707. xtmp: smallint;
  708. Begin
  709. { must we swap the values? }
  710. if x >= x2 then
  711. Begin
  712. xtmp := x2;
  713. x2 := x;
  714. x:= xtmp;
  715. end;
  716. { First convert to global coordinates }
  717. X := X + StartXViewPort;
  718. X2 := X2 + StartXViewPort;
  719. Y := Y + StartYViewPort;
  720. if ClipPixels then
  721. Begin
  722. if LineClipped(x,y,x2,y,StartXViewPort,StartYViewPort,
  723. StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
  724. exit;
  725. end;
  726. for x:= x to x2 do
  727. DirectPutPixel(X,Y);
  728. end;
  729. procedure VLineDefault(x,y,y2: smallint); {$ifndef fpc}far;{$endif fpc}
  730. var
  731. ytmp: smallint;
  732. Begin
  733. { must we swap the values? }
  734. if y >= y2 then
  735. Begin
  736. ytmp := y2;
  737. y2 := y;
  738. y:= ytmp;
  739. end;
  740. { First convert to global coordinates }
  741. X := X + StartXViewPort;
  742. Y2 := Y2 + StartYViewPort;
  743. Y := Y + StartYViewPort;
  744. if ClipPixels then
  745. Begin
  746. if LineClipped(x,y,x,y2,StartXViewPort,StartYViewPort,
  747. StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
  748. exit;
  749. end;
  750. for y := y to y2 do Directputpixel(x,y)
  751. End;
  752. Procedure DirectPutPixelClip(x,y: smallint);
  753. { for thickwidth lines, because they may call DirectPutPixel for coords }
  754. { outside the current viewport (bug found by CEC) }
  755. Begin
  756. If (Not ClipPixels) Or
  757. ((X >= StartXViewPort) And (X <= (StartXViewPort + ViewWidth)) And
  758. (Y >= StartYViewPort) And (Y <= (StartYViewPort + ViewHeight))) then
  759. Begin
  760. DirectPutPixel(x,y)
  761. End
  762. End;
  763. procedure LineDefault(X1, Y1, X2, Y2: smallint); {$ifndef fpc}far;{$endif fpc}
  764. var X, Y : smallint;
  765. deltax, deltay : smallint;
  766. d, dinc1, dinc2: smallint;
  767. xinc1 : smallint;
  768. xinc2 : smallint;
  769. yinc1 : smallint;
  770. yinc2 : smallint;
  771. i : smallint;
  772. Flag : Boolean; { determines pixel direction in thick lines }
  773. NumPixels : smallint;
  774. PixelCount : smallint;
  775. OldCurrentColor: Word;
  776. swtmp : smallint;
  777. TmpNumPixels : smallint;
  778. begin
  779. {******************************************}
  780. { SOLID LINES }
  781. {******************************************}
  782. if lineinfo.LineStyle = SolidLn then
  783. Begin
  784. { we separate normal and thick width for speed }
  785. { and because it would not be 100% compatible }
  786. { with the TP graph unit otherwise }
  787. if y1 = y2 then
  788. Begin
  789. {******************************************}
  790. { SOLID LINES HORIZONTAL }
  791. {******************************************}
  792. if lineinfo.Thickness=NormWidth then
  793. hline(x1,x2,y2)
  794. else
  795. begin
  796. { thick width }
  797. hline(x1,x2,y2-1);
  798. hline(x1,x2,y2);
  799. hline(x2,x2,y2+1);
  800. end;
  801. end
  802. else
  803. if x1 = x2 then
  804. Begin
  805. {******************************************}
  806. { SOLID LINES VERTICAL }
  807. {******************************************}
  808. if lineinfo.Thickness=NormWidth then
  809. vline(x1,y1,y2)
  810. else
  811. begin
  812. { thick width }
  813. vline(x1-1,y1,y2);
  814. vline(x1,y1,y2);
  815. vline(x1+1,y1,y2);
  816. end;
  817. end
  818. else
  819. begin
  820. { Convert to global coordinates. }
  821. x1 := x1 + StartXViewPort;
  822. x2 := x2 + StartXViewPort;
  823. y1 := y1 + StartYViewPort;
  824. y2 := y2 + StartYViewPort;
  825. { if fully clipped then exit... }
  826. if ClipPixels then
  827. begin
  828. if LineClipped(x1,y1,x2,y2,StartXViewPort, StartYViewPort,
  829. StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
  830. exit;
  831. end;
  832. {******************************************}
  833. { SLOPED SOLID LINES }
  834. {******************************************}
  835. oldCurrentColor :=
  836. CurrentColor;
  837. { Calculate deltax and deltay for initialisation }
  838. deltax := abs(x2 - x1);
  839. deltay := abs(y2 - y1);
  840. { Initialize all vars based on which is the independent variable }
  841. if deltax >= deltay then
  842. begin
  843. Flag := FALSE;
  844. { x is independent variable }
  845. numpixels := deltax + 1;
  846. d := (2 * deltay) - deltax;
  847. dinc1 := deltay Shl 1;
  848. dinc2 := (deltay - deltax) shl 1;
  849. xinc1 := 1;
  850. xinc2 := 1;
  851. yinc1 := 0;
  852. yinc2 := 1;
  853. end
  854. else
  855. begin
  856. Flag := TRUE;
  857. { y is independent variable }
  858. numpixels := deltay + 1;
  859. d := (2 * deltax) - deltay;
  860. dinc1 := deltax Shl 1;
  861. dinc2 := (deltax - deltay) shl 1;
  862. xinc1 := 0;
  863. xinc2 := 1;
  864. yinc1 := 1;
  865. yinc2 := 1;
  866. end;
  867. { Make sure x and y move in the right directions }
  868. if x1 > x2 then
  869. begin
  870. xinc1 := - xinc1;
  871. xinc2 := - xinc2;
  872. end;
  873. if y1 > y2 then
  874. begin
  875. yinc1 := - yinc1;
  876. yinc2 := - yinc2;
  877. end;
  878. { Start drawing at <x1, y1> }
  879. x := x1;
  880. y := y1;
  881. If LineInfo.Thickness=NormWidth then
  882. Begin
  883. { Draw the pixels }
  884. for i := 1 to numpixels do
  885. begin
  886. DirectPutPixel(x, y);
  887. if d < 0 then
  888. begin
  889. d := d + dinc1;
  890. x := x + xinc1;
  891. y := y + yinc1;
  892. end
  893. else
  894. begin
  895. d := d + dinc2;
  896. x := x + xinc2;
  897. y := y + yinc2;
  898. end;
  899. CurrentColor := OldCurrentColor;
  900. end;
  901. end
  902. else
  903. { Thick width lines }
  904. begin
  905. { Draw the pixels }
  906. for i := 1 to numpixels do
  907. begin
  908. { all depending on the slope, we can determine }
  909. { in what direction the extra width pixels will be put }
  910. If Flag then
  911. Begin
  912. DirectPutPixelClip(x-1,y);
  913. DirectPutPixelClip(x,y);
  914. DirectPutPixelClip(x+1,y);
  915. end
  916. else
  917. Begin
  918. DirectPutPixelClip(x, y-1);
  919. DirectPutPixelClip(x, y);
  920. DirectPutPixelClip(x, y+1);
  921. end;
  922. if d < 0 then
  923. begin
  924. d := d + dinc1;
  925. x := x + xinc1;
  926. y := y + yinc1;
  927. end
  928. else
  929. begin
  930. d := d + dinc2;
  931. x := x + xinc2;
  932. y := y + yinc2;
  933. end;
  934. CurrentColor := OldCurrentColor;
  935. end;
  936. end;
  937. end;
  938. end
  939. else
  940. {******************************************}
  941. { begin patterned lines }
  942. {******************************************}
  943. Begin
  944. { Convert to global coordinates. }
  945. x1 := x1 + StartXViewPort;
  946. x2 := x2 + StartXViewPort;
  947. y1 := y1 + StartYViewPort;
  948. y2 := y2 + StartYViewPort;
  949. { if fully clipped then exit... }
  950. if ClipPixels then
  951. begin
  952. if LineClipped(x1,y1,x2,y2,StartXViewPort, StartYViewPort,
  953. StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
  954. exit;
  955. end;
  956. OldCurrentColor := CurrentColor;
  957. PixelCount:=0;
  958. if y1 = y2 then
  959. Begin
  960. { Check if we must swap }
  961. if x1 >= x2 then
  962. Begin
  963. swtmp := x1;
  964. x1 := x2;
  965. x2 := swtmp;
  966. end;
  967. if LineInfo.Thickness = NormWidth then
  968. Begin
  969. for PixelCount:=x1 to x2 do
  970. { optimization: PixelCount mod 16 }
  971. if LinePatterns[PixelCount and 15] = TRUE then
  972. begin
  973. DirectPutPixel(PixelCount,y2);
  974. end;
  975. end
  976. else
  977. Begin
  978. for i:=-1 to 1 do
  979. Begin
  980. for PixelCount:=x1 to x2 do
  981. { Optimization from Thomas - mod 16 = and 15 }
  982. {this optimization has been performed by the compiler
  983. for while as well (JM)}
  984. if LinePatterns[PixelCount and 15] = TRUE then
  985. begin
  986. DirectPutPixelClip(PixelCount,y2+i);
  987. end;
  988. end;
  989. end;
  990. end
  991. else
  992. if x1 = x2 then
  993. Begin
  994. { Check if we must swap }
  995. if y1 >= y2 then
  996. Begin
  997. swtmp := y1;
  998. y1 := y2;
  999. y2 := swtmp;
  1000. end;
  1001. if LineInfo.Thickness = NormWidth then
  1002. Begin
  1003. for PixelCount:=y1 to y2 do
  1004. { compare if we should plot a pixel here , compare }
  1005. { with predefined line patterns... }
  1006. if LinePatterns[PixelCount and 15] = TRUE then
  1007. begin
  1008. DirectPutPixel(x1,PixelCount);
  1009. end;
  1010. end
  1011. else
  1012. Begin
  1013. for i:=-1 to 1 do
  1014. Begin
  1015. for PixelCount:=y1 to y2 do
  1016. { compare if we should plot a pixel here , compare }
  1017. { with predefined line patterns... }
  1018. if LinePatterns[PixelCount and 15] = TRUE then
  1019. begin
  1020. DirectPutPixelClip(x1+i,PixelCount);
  1021. end;
  1022. end;
  1023. end;
  1024. end
  1025. else
  1026. Begin
  1027. oldCurrentColor := CurrentColor;
  1028. { Calculate deltax and deltay for initialisation }
  1029. deltax := abs(x2 - x1);
  1030. deltay := abs(y2 - y1);
  1031. { Initialize all vars based on which is the independent variable }
  1032. if deltax >= deltay then
  1033. begin
  1034. Flag := FALSE;
  1035. { x is independent variable }
  1036. numpixels := deltax + 1;
  1037. d := (2 * deltay) - deltax;
  1038. dinc1 := deltay Shl 1;
  1039. dinc2 := (deltay - deltax) shl 1;
  1040. xinc1 := 1;
  1041. xinc2 := 1;
  1042. yinc1 := 0;
  1043. yinc2 := 1;
  1044. end
  1045. else
  1046. begin
  1047. Flag := TRUE;
  1048. { y is independent variable }
  1049. numpixels := deltay + 1;
  1050. d := (2 * deltax) - deltay;
  1051. dinc1 := deltax Shl 1;
  1052. dinc2 := (deltax - deltay) shl 1;
  1053. xinc1 := 0;
  1054. xinc2 := 1;
  1055. yinc1 := 1;
  1056. yinc2 := 1;
  1057. end;
  1058. { Make sure x and y move in the right directions }
  1059. if x1 > x2 then
  1060. begin
  1061. xinc1 := - xinc1;
  1062. xinc2 := - xinc2;
  1063. end;
  1064. if y1 > y2 then
  1065. begin
  1066. yinc1 := - yinc1;
  1067. yinc2 := - yinc2;
  1068. end;
  1069. { Start drawing at <x1, y1> }
  1070. x := x1;
  1071. y := y1;
  1072. If LineInfo.Thickness=ThickWidth then
  1073. Begin
  1074. TmpNumPixels := NumPixels-1;
  1075. { Draw the pixels }
  1076. for i := 0 to TmpNumPixels do
  1077. begin
  1078. { all depending on the slope, we can determine }
  1079. { in what direction the extra width pixels will be put }
  1080. If Flag then
  1081. Begin
  1082. { compare if we should plot a pixel here , compare }
  1083. { with predefined line patterns... }
  1084. if LinePatterns[i and 15] = TRUE then
  1085. begin
  1086. DirectPutPixelClip(x-1,y);
  1087. DirectPutPixelClip(x,y);
  1088. DirectPutPixelClip(x+1,y);
  1089. end;
  1090. end
  1091. else
  1092. Begin
  1093. { compare if we should plot a pixel here , compare }
  1094. { with predefined line patterns... }
  1095. if LinePatterns[i and 15] = TRUE then
  1096. begin
  1097. DirectPutPixelClip(x,y-1);
  1098. DirectPutPixelClip(x,y);
  1099. DirectPutPixelClip(x,y+1);
  1100. end;
  1101. end;
  1102. if d < 0 then
  1103. begin
  1104. d := d + dinc1;
  1105. x := x + xinc1;
  1106. y := y + yinc1;
  1107. end
  1108. else
  1109. begin
  1110. d := d + dinc2;
  1111. x := x + xinc2;
  1112. y := y + yinc2;
  1113. end;
  1114. end;
  1115. end
  1116. else
  1117. Begin
  1118. { instead of putting in loop , substract by one now }
  1119. TmpNumPixels := NumPixels-1;
  1120. { NormWidth }
  1121. for i := 0 to TmpNumPixels do
  1122. begin
  1123. if LinePatterns[i and 15] = TRUE then
  1124. begin
  1125. DirectPutPixel(x,y);
  1126. end;
  1127. if d < 0 then
  1128. begin
  1129. d := d + dinc1;
  1130. x := x + xinc1;
  1131. y := y + yinc1;
  1132. end
  1133. else
  1134. begin
  1135. d := d + dinc2;
  1136. x := x + xinc2;
  1137. y := y + yinc2;
  1138. end;
  1139. end;
  1140. end
  1141. end;
  1142. {******************************************}
  1143. { end patterned lines }
  1144. {******************************************}
  1145. { restore color }
  1146. CurrentColor:=OldCurrentColor;
  1147. end;
  1148. end; { Line }
  1149. {********************************************************}
  1150. { Procedure DummyPatternLine() }
  1151. {--------------------------------------------------------}
  1152. { This is suimply an procedure that does nothing which }
  1153. { can be passed as a patternlineproc for non-filled }
  1154. { ellipses }
  1155. {********************************************************}
  1156. Procedure DummyPatternLine(x1, x2, y: smallint); {$ifdef tp} far; {$endif tp}
  1157. begin
  1158. end;
  1159. {********************************************************}
  1160. { Procedure InternalEllipse() }
  1161. {--------------------------------------------------------}
  1162. { This routine first calculates all points required to }
  1163. { draw a circle to the screen, and stores the points }
  1164. { to display in a buffer before plotting them. The }
  1165. { aspect ratio of the screen is taken into account when }
  1166. { calculating the values. }
  1167. {--------------------------------------------------------}
  1168. { INPUTS: X,Y : Center coordinates of Ellipse. }
  1169. { XRadius - X-Axis radius of ellipse. }
  1170. { YRadius - Y-Axis radius of ellipse. }
  1171. { stAngle, EndAngle: Start angle and end angles of the }
  1172. { ellipse (used for partial ellipses and circles) }
  1173. { pl: procedure which either draws a patternline (for }
  1174. { FillEllipse) or does nothing (arc etc) }
  1175. {--------------------------------------------------------}
  1176. { NOTE: - }
  1177. { - }
  1178. {********************************************************}
  1179. Procedure InternalEllipseDefault(X,Y: smallint;XRadius: word;
  1180. YRadius:word; stAngle,EndAngle: word; pl: PatternLineProc); {$ifndef fpc}far;{$endif fpc}
  1181. Const ConvFac = Pi/180.0;
  1182. var
  1183. j, Delta, DeltaEnd: graph_float;
  1184. NumOfPixels: longint;
  1185. TempTerm: graph_float;
  1186. xtemp, ytemp, xp, yp, xm, ym, xnext, ynext,
  1187. plxpyp, plxmyp, plxpym, plxmym: smallint;
  1188. BackupColor, TmpAngle, OldLineWidth: word;
  1189. Begin
  1190. If LineInfo.ThickNess = ThickWidth Then
  1191. { first draw the two outer ellipses using normwidth and no filling (JM) }
  1192. Begin
  1193. OldLineWidth := LineInfo.Thickness;
  1194. LineInfo.Thickness := NormWidth;
  1195. InternalEllipseDefault(x,y,XRadius,YRadius,StAngle,EndAngle,
  1196. {$ifdef fpc}@{$endif fpc}DummyPatternLine);
  1197. InternalEllipseDefault(x,y,XRadius+1,YRadius+1,StAngle,EndAngle,
  1198. {$ifdef fpc}@{$endif fpc}DummyPatternLine);
  1199. If (XRadius > 0) and (YRadius > 0) Then
  1200. { draw the smallest ellipse last, since that one will use the }
  1201. { original pl, so it could possibly draw patternlines (JM) }
  1202. Begin
  1203. Dec(XRadius);
  1204. Dec(YRadius);
  1205. End
  1206. Else Exit;
  1207. { restore line thickness }
  1208. LineInfo.Thickness := OldLineWidth;
  1209. End;
  1210. { Adjust for screen aspect ratio }
  1211. XRadius:=(longint(XRadius)*10000) div XAspect;
  1212. YRadius:=(longint(YRadius)*10000) div YAspect;
  1213. If xradius = 0 then inc(xradius);
  1214. if yradius = 0 then inc(yradius);
  1215. { check for an ellipse with negligable x and y radius }
  1216. If (xradius <= 1) and (yradius <= 1) then
  1217. begin
  1218. putpixel(x,y,CurrentColor);
  1219. ArcCall.X := X;
  1220. ArcCall.Y := Y;
  1221. ArcCall.XStart := X;
  1222. ArcCall.YStart := Y;
  1223. ArcCall.XEnd := X;
  1224. ArcCall.YEnd := Y;
  1225. exit;
  1226. end;
  1227. { check if valid angles }
  1228. stangle := stAngle mod 361;
  1229. EndAngle := EndAngle mod 361;
  1230. { if impossible angles then swap them! }
  1231. if Endangle < StAngle then
  1232. Begin
  1233. TmpAngle:=EndAngle;
  1234. EndAngle:=StAngle;
  1235. Stangle:=TmpAngle;
  1236. end;
  1237. { approximate the number of pixels required by using the circumference }
  1238. { equation of an ellipse. }
  1239. { Changed this formula a it (trial and error), but the net result is that }
  1240. { less pixels have to be calculated now }
  1241. NumOfPixels:=Round(Sqrt(3)*sqrt(sqr(XRadius)+sqr(YRadius)));
  1242. { Calculate the angle precision required }
  1243. Delta := 90.0 / NumOfPixels;
  1244. { for restoring after PatternLine }
  1245. BackupColor := CurrentColor;
  1246. { removed from inner loop to make faster }
  1247. { store some arccall info }
  1248. ArcCall.X := X;
  1249. ArcCall.Y := Y;
  1250. TempTerm := (StAngle)*ConvFac;
  1251. ArcCall.XStart := round(XRadius*Cos(TempTerm)) + X;
  1252. ArcCall.YStart := round(YRadius*Sin(TempTerm+Pi)) + Y;
  1253. TempTerm := (EndAngle)*ConvFac;
  1254. ArcCall.XEnd := round(XRadius*Cos(TempTerm)) + X;
  1255. ArcCall.YEnd := round(YRadius*Sin(TempTerm+Pi)) + Y;
  1256. { Always just go over the first 90 degrees. Could be optimized a }
  1257. { bit if StAngle and EndAngle lie in the same quadrant, left as an }
  1258. { exercise for the reader :) (JM) }
  1259. j := 0;
  1260. { calculate stop position, go 1 further than 90 because otherwise }
  1261. { 1 pixel is sometimes not drawn (JM) }
  1262. DeltaEnd := 91;
  1263. { Calculate points }
  1264. xnext := XRadius;
  1265. ynext := 0;
  1266. Repeat
  1267. xtemp := xnext;
  1268. ytemp := ynext;
  1269. { this is used by both sin and cos }
  1270. TempTerm := (j+Delta)*ConvFac;
  1271. { Calculate points }
  1272. xnext := round(XRadius*Cos(TempTerm));
  1273. ynext := round(YRadius*Sin(TempTerm+Pi));
  1274. xp := x + xtemp;
  1275. xm := x - xtemp;
  1276. yp := y + ytemp;
  1277. ym := y - ytemp;
  1278. plxpyp := maxsmallint;
  1279. plxmyp := -maxsmallint-1;
  1280. plxpym := maxsmallint;
  1281. plxmym := -maxsmallint-1;
  1282. If (j >= StAngle) and (j <= EndAngle) then
  1283. begin
  1284. plxpyp := xp;
  1285. PutPixel(xp,yp,CurrentColor);
  1286. end;
  1287. If ((180-j) >= StAngle) and ((180-j) <= EndAngle) then
  1288. begin
  1289. plxmyp := xm;
  1290. PutPixel(xm,yp,CurrentColor);
  1291. end;
  1292. If ((j+180) >= StAngle) and ((j+180) <= EndAngle) then
  1293. begin
  1294. plxmym := xm;
  1295. PutPixel(xm,ym,CurrentColor);
  1296. end;
  1297. If ((360-j) >= StAngle) and ((360-j) <= EndAngle) then
  1298. begin
  1299. plxpym := xp;
  1300. PutPixel(xp,ym,CurrentColor);
  1301. end;
  1302. If (ynext <> ytemp) and
  1303. (xp - xm >= 1) then
  1304. begin
  1305. CurrentColor := FillSettings.Color;
  1306. pl(plxmyp+1,plxpyp-1,yp);
  1307. pl(plxmym+1,plxpym-1,ym);
  1308. CurrentColor := BackupColor;
  1309. end;
  1310. j:=j+Delta;
  1311. Until j > (DeltaEnd);
  1312. end;
  1313. {********************************************************}
  1314. { Procedure InternalEllipse() }
  1315. {--------------------------------------------------------}
  1316. { This routine first calculates all points required to }
  1317. { draw a circle to the screen, and stores the points }
  1318. { to display in a buffer before plotting them. The }
  1319. { aspect ratio of the screen is taken into account when }
  1320. { calculating the values. }
  1321. {--------------------------------------------------------}
  1322. { INPUTS: X,Y : Center coordinates of Ellipse. }
  1323. { XRadius - X-Axis radius of ellipse. }
  1324. { YRadius - Y-Axis radius of ellipse. }
  1325. { stAngle, EndAngle: Start angle and end angles of the }
  1326. { ellipse (used for partial ellipses and circles) }
  1327. {--------------------------------------------------------}
  1328. { NOTE: - uses the current write mode. }
  1329. { - Angles must both be between 0 and 360 }
  1330. {********************************************************}
  1331. (*
  1332. Procedure InternalEllipseDefault (x, y : smallint;
  1333. xradius, yradius, stAngle, EndAngle : Word; pl: PatternLineProc); {$ifndef fpc} far; {$endif fpc}
  1334. { Draw an ellipse arc. Crude but it works (anyone have a better one?) }
  1335. Var
  1336. aSqr, bSqr, twoaSqr, twobSqr, xa, ya, twoXbSqr, twoYaSqr, error : LongInt;
  1337. Alpha, TempTerm : graph_float;
  1338. BackupColor: Word;
  1339. plxpyp, plxmyp, plxpym, plxmym: smallint;
  1340. const
  1341. RadToDeg = 180/Pi;
  1342. Procedure PlotPoints;
  1343. var
  1344. i,j: smallint;
  1345. xm, ym: smallint;
  1346. xp, yp: smallint;
  1347. Begin
  1348. ym := y-ya;
  1349. yp := y+ya;
  1350. xm := x-xa;
  1351. xp := x+xa;
  1352. plxpyp := maxsmallint;
  1353. plxmyp := -maxsmallint-1;
  1354. plxpym := maxsmallint;
  1355. plxmym := -maxsmallint-1;
  1356. if LineInfo.Thickness = Normwidth then
  1357. Begin
  1358. If (Alpha+270>=StAngle) And (Alpha+270<=EndAngle) then
  1359. Begin
  1360. plxmym := xm;
  1361. PutPixel (xm,ym, CurrentColor);
  1362. End;
  1363. If ((180+270)-Alpha>=StAngle) And ((180+270)-Alpha<=EndAngle) then
  1364. Begin
  1365. plxmyp := xm;
  1366. PutPixel (xm,yp, CurrentColor);
  1367. End;
  1368. If ((180+270)+Alpha>=StAngle) And ((180+270)+Alpha<=EndAngle) then
  1369. Begin
  1370. plxpyp := xp;
  1371. PutPixel (xp,yp, CurrentColor);
  1372. End;
  1373. If ((360+270)-Alpha>=StAngle) And ((360+270)-Alpha<=EndAngle) then
  1374. Begin
  1375. plxpym := xp;
  1376. PutPixel (xp,ym, CurrentColor);
  1377. End;
  1378. end
  1379. else
  1380. Begin
  1381. If (Alpha+270>=StAngle) And (Alpha+270<=EndAngle) then
  1382. Begin
  1383. plxmym := xm + 1;
  1384. for i:=-1 to 1 do
  1385. for j:=-1 to 1 do
  1386. PutPixel (xm+i,ym+j, CurrentColor);
  1387. End;
  1388. If ((180+270)-Alpha>=StAngle) And ((180+270)-Alpha<=EndAngle) then
  1389. Begin
  1390. plxmyp := xm + 1;
  1391. for i:=-1 to 1 do
  1392. for j:=-1 to 1 do
  1393. PutPixel (xm+i,yp+j, CurrentColor);
  1394. End;
  1395. If ((180+270)+Alpha>=StAngle) And ((180+270)+Alpha<=EndAngle) then
  1396. Begin
  1397. plxpyp := xp - 1;
  1398. for i:=-1 to 1 do
  1399. for j:=-1 to 1 do
  1400. PutPixel (xp+i,yp+j, CurrentColor);
  1401. End;
  1402. If ((360+270)-Alpha>=StAngle) And ((360+270)-Alpha<=EndAngle) then
  1403. Begin
  1404. plxpym := xp - 1;
  1405. for i:=-1 to 1 do
  1406. for j:=-1 to 1 do
  1407. PutPixel (xp+i,ym+j, CurrentColor);
  1408. End;
  1409. end;
  1410. If (xp <> xm) then
  1411. begin
  1412. CurrentColor := FillSettings.Color;
  1413. pl(plxmyp+1,plxpyp-1,yp);
  1414. pl(plxmym+1,plxpym-1,ym);
  1415. CurrentColor := BackupColor;
  1416. end;
  1417. End;
  1418. Begin
  1419. { check for an ellipse with negligable x and y radius }
  1420. If (xradius <= 1) and (yradius <= 1) then
  1421. begin
  1422. putpixel(x,y,CurrentColor);
  1423. ArcCall.X := X;
  1424. ArcCall.Y := Y;
  1425. ArcCall.XStart := X;
  1426. ArcCall.YStart := Y;
  1427. ArcCall.XEnd := X;
  1428. ArcCall.YEnd := Y;
  1429. exit;
  1430. end;
  1431. { for restoring after PatternLine }
  1432. BackupColor := CurrentColor;
  1433. If xradius = 0 then inc(xradius);
  1434. if yradius = 0 then inc(yradius);
  1435. { store arccall info }
  1436. ArcCall.x := x;
  1437. ArcCall.y := y;
  1438. TempTerm := StAngle*RadToDeg;
  1439. ArcCall.XStart := round(XRadius*Cos(TempTerm)) + X;
  1440. ArcCall.YStart := round(YRadius*Sin(TempTerm+Pi)) + Y;
  1441. TempTerm := EndAngle*RadToDeg;
  1442. ArcCall.XEnd := round(XRadius*Cos(TempTerm)) + X;
  1443. ArcCall.YEnd := round(YRadius*Sin(TempTerm+Pi)) + Y;
  1444. StAngle:=StAngle MOD 361;
  1445. EndAngle:=EndAngle MOD 361;
  1446. StAngle := StAngle + 270;
  1447. EndAngle := EndAngle + 270;
  1448. If StAngle>EndAngle then
  1449. Begin
  1450. StAngle:=StAngle Xor EndAngle; EndAngle:=EndAngle Xor StAngle; StAngle:=EndAngle Xor StAngle;
  1451. End;
  1452. { Adjust for screen aspect ratio }
  1453. XRadius:=(longint(XRadius)*10000) div XAspect;
  1454. YRadius:=(longint(YRadius)*10000) div YAspect;
  1455. aSqr:=LongInt (xradius)*LongInt (xradius);
  1456. bSqr:=LongInt (yradius)*LongInt (yradius);
  1457. twoaSqr:=2*aSqr;
  1458. twobSqr:=2*bSqr;
  1459. xa:=0;
  1460. ya:=yradius;
  1461. twoXbSqr:=0;
  1462. twoYaSqr:=ya*twoaSqr;
  1463. error:=-ya*aSqr;
  1464. While twoXbSqr<=twoYaSqr Do Begin
  1465. If ya=0 then Alpha:=90 Else Alpha:=RadToDeg*Arctan (xa/ya); { Crude but it works }
  1466. PlotPoints;
  1467. Inc (xa);
  1468. Inc (twoXbSqr,twobSqr);
  1469. Inc (error,twoXbSqr-bSqr);
  1470. If error>=0 then Begin
  1471. Dec (ya);
  1472. Dec (twoYaSqr,twoaSqr);
  1473. Dec (error,twoYaSqr);
  1474. End;
  1475. End;
  1476. xa:=xradius;
  1477. ya:=0;
  1478. twoXbSqr:=xa*twobSqr;
  1479. twoYaSqr:=0;
  1480. error:=-xa*bSqr;
  1481. While twoXbSqr>twoYaSqr Do Begin
  1482. If ya=0 then Alpha:=90 Else Alpha:=RadToDeg*Arctan (xa/ya);
  1483. PlotPoints;
  1484. Inc (ya);
  1485. Inc (twoYaSqr,twoaSqr);
  1486. Inc (error,twoYaSqr-aSqr);
  1487. If error>=0 then Begin
  1488. Dec (xa);
  1489. Dec (twoXbSqr,twobSqr);
  1490. Dec (error,twoXbSqr);
  1491. End;
  1492. End;
  1493. End;
  1494. *)
  1495. procedure PatternLineDefault(x1,x2,y: smallint); {$ifndef fpc}far;{$endif fpc}
  1496. {********************************************************}
  1497. { Draws a horizontal patterned line according to the }
  1498. { current Fill Settings. }
  1499. {********************************************************}
  1500. { Important notes: }
  1501. { - CurrentColor must be set correctly before entering }
  1502. { this routine. }
  1503. {********************************************************}
  1504. var
  1505. NrIterations: smallint;
  1506. i : smallint;
  1507. j : smallint;
  1508. TmpFillPattern : byte;
  1509. OldWriteMode : word;
  1510. OldCurrentColor : word;
  1511. begin
  1512. { convert to global coordinates ... }
  1513. x1 := x1 + StartXViewPort;
  1514. x2 := x2 + StartXViewPort;
  1515. y := y + StartYViewPort;
  1516. { if line was fully clipped then exit...}
  1517. if LineClipped(x1,y,x2,y,StartXViewPort,StartYViewPort,
  1518. StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
  1519. exit;
  1520. OldWriteMode := CurrentWriteMode;
  1521. CurrentWriteMode := NormalPut;
  1522. { Get the current pattern }
  1523. TmpFillPattern := FillPatternTable
  1524. [FillSettings.Pattern][(y and $7)+1];
  1525. Case TmpFillPattern Of
  1526. 0:
  1527. begin
  1528. OldCurrentColor := CurrentColor;
  1529. CurrentColor := CurrentBkColor;
  1530. { hline converts the coordinates to global ones, but that has been done }
  1531. { already here!!! Convert them back to local ones... (JM) }
  1532. HLine(x1-StartXViewPort,x2-StartXViewPort,y-StartYViewPort);
  1533. CurrentColor := OldCurrentColor;
  1534. end;
  1535. $ff:
  1536. begin
  1537. HLine(x1-StartXViewPort,x2-StartXViewPort,y-StartYViewPort);
  1538. end;
  1539. else
  1540. begin
  1541. { number of times to go throuh the 8x8 pattern }
  1542. NrIterations := abs(x2 - x1+8) div 8;
  1543. For i:= 0 to NrIterations do
  1544. Begin
  1545. for j:=0 to 7 do
  1546. Begin
  1547. { x1 mod 8 }
  1548. if RevBitArray[x1 and 7] and TmpFillPattern <> 0 then
  1549. DirectPutpixel(x1,y)
  1550. else
  1551. begin
  1552. { According to the TP graph manual, we overwrite everything }
  1553. { which is filled up - checked against VGA and CGA drivers }
  1554. { of TP. }
  1555. OldCurrentColor := CurrentColor;
  1556. CurrentColor := CurrentBkColor;
  1557. DirectPutPixel(x1,y);
  1558. CurrentColor := OldCurrentColor;
  1559. end;
  1560. Inc(x1);
  1561. if x1 > x2 then
  1562. begin
  1563. CurrentWriteMode := OldWriteMode;
  1564. exit;
  1565. end;
  1566. end;
  1567. end;
  1568. end;
  1569. End;
  1570. CurrentWriteMode := OldWriteMode;
  1571. end;
  1572. procedure LineRel(Dx, Dy: smallint);
  1573. Begin
  1574. Line(CurrentX, CurrentY, CurrentX + Dx, CurrentY + Dy);
  1575. CurrentX := CurrentX + Dx;
  1576. CurrentY := CurrentY + Dy;
  1577. end;
  1578. procedure LineTo(x,y : smallint);
  1579. Begin
  1580. Line(CurrentX, CurrentY, X, Y);
  1581. CurrentX := X;
  1582. CurrentY := Y;
  1583. end;
  1584. procedure Rectangle(x1,y1,x2,y2:smallint);
  1585. begin
  1586. { Do not draw the end points }
  1587. Line(x1,y1,x2-1,y1);
  1588. Line(x1,y1+1,x1,y2);
  1589. Line(x2,y1,x2,y2-1);
  1590. Line(x1+1,y2,x2,y2);
  1591. end;
  1592. procedure GetLineSettings(var ActiveLineInfo : LineSettingsType);
  1593. begin
  1594. Activelineinfo:=Lineinfo;
  1595. end;
  1596. procedure SetLineStyle(LineStyle: word; Pattern: word; Thickness: word);
  1597. var
  1598. i: byte;
  1599. j: byte;
  1600. Begin
  1601. if (LineStyle > UserBitLn) or ((Thickness <> Normwidth) and (Thickness <> ThickWidth)) then
  1602. _GraphResult := grError
  1603. else
  1604. begin
  1605. LineInfo.Thickness := Thickness;
  1606. LineInfo.LineStyle := LineStyle;
  1607. case LineStyle of
  1608. UserBitLn: Lineinfo.Pattern := pattern;
  1609. SolidLn: Lineinfo.Pattern := $ffff; { ------- }
  1610. DashedLn : Lineinfo.Pattern := $F8F8; { -- -- --}
  1611. DottedLn: LineInfo.Pattern := $CCCC; { - - - - }
  1612. CenterLn: LineInfo.Pattern := $FC78; { -- - -- }
  1613. end; { end case }
  1614. { setup pattern styles }
  1615. j:=16;
  1616. for i:=0 to 15 do
  1617. Begin
  1618. dec(j);
  1619. { bitwise mask for each bit in the word }
  1620. if (word($01 shl i) AND LineInfo.Pattern) <> 0 then
  1621. LinePatterns[j]:=TRUE
  1622. else
  1623. LinePatterns[j]:=FALSE;
  1624. end;
  1625. end;
  1626. end;
  1627. {--------------------------------------------------------------------------}
  1628. { }
  1629. { VIEWPORT RELATED ROUTINES }
  1630. { }
  1631. {--------------------------------------------------------------------------}
  1632. Procedure ClearViewPortDefault; {$ifndef fpc}far;{$endif fpc}
  1633. var
  1634. j: smallint;
  1635. OldWriteMode, OldCurColor: word;
  1636. LineSets : LineSettingsType;
  1637. Begin
  1638. { CP is always RELATIVE coordinates }
  1639. CurrentX := 0;
  1640. CurrentY := 0;
  1641. { Save all old settings }
  1642. OldCurColor := CurrentColor;
  1643. CurrentColor:=CurrentBkColor;
  1644. OldWriteMode:=CurrentWriteMode;
  1645. CurrentWriteMode:=NormalPut;
  1646. GetLineSettings(LineSets);
  1647. { reset to normal line style...}
  1648. SetLineStyle(SolidLn, 0, NormWidth);
  1649. { routines are relative here...}
  1650. for J:=0 to ViewHeight do
  1651. HLine(0, ViewWidth, J);
  1652. { restore old settings...}
  1653. SetLineStyle(LineSets.LineStyle, LineSets.Pattern, LineSets.Thickness);
  1654. CurrentColor := OldCurColor;
  1655. CurrentWriteMode := OldWriteMode;
  1656. end;
  1657. Procedure SetViewPort(X1, Y1, X2, Y2: smallint; Clip: Boolean);
  1658. Begin
  1659. if (X1 > GetMaxX) or (X2 > GetMaxX) or (X1 > X2) or (X1 < 0) then
  1660. Begin
  1661. _GraphResult := grError;
  1662. exit;
  1663. end;
  1664. if (Y1 > GetMaxY) or (Y2 > GetMaxY) or (Y1 > Y2) or (Y1 < 0) then
  1665. Begin
  1666. _GraphResult := grError;
  1667. exit;
  1668. end;
  1669. { CP is always RELATIVE coordinates }
  1670. CurrentX := 0;
  1671. CurrentY := 0;
  1672. StartXViewPort := X1;
  1673. StartYViewPort := Y1;
  1674. ViewWidth := X2-X1;
  1675. ViewHeight:= Y2-Y1;
  1676. ClipPixels := Clip;
  1677. end;
  1678. procedure GetViewSettings(var viewport : ViewPortType);
  1679. begin
  1680. ViewPort.X1 := StartXViewPort;
  1681. ViewPort.Y1 := StartYViewPort;
  1682. ViewPort.X2 := ViewWidth + StartXViewPort;
  1683. ViewPort.Y2 := ViewHeight + StartYViewPort;
  1684. ViewPort.Clip := ClipPixels;
  1685. end;
  1686. procedure ClearDevice;
  1687. var
  1688. ViewPort: ViewPortType;
  1689. begin
  1690. { Reset the CP }
  1691. CurrentX := 0;
  1692. CurrentY := 0;
  1693. { save viewport }
  1694. ViewPort.X1 := StartXviewPort;
  1695. ViewPort.X2 := ViewWidth - StartXViewPort;
  1696. ViewPort.Y1 := StartYViewPort;
  1697. ViewPort.Y2 := ViewHeight - StartYViewPort;
  1698. ViewPort.Clip := ClipPixels;
  1699. { put viewport to full screen }
  1700. StartXViewPort := 0;
  1701. ViewHeight := MaxY;
  1702. StartYViewPort := 0;
  1703. ViewWidth := MaxX;
  1704. ClipPixels := TRUE;
  1705. ClearViewPort;
  1706. { restore old viewport }
  1707. StartXViewPort := ViewPort.X1;
  1708. ViewWidth := ViewPort.X2-ViewPort.X1;
  1709. StartYViewPort := ViewPort.Y1;
  1710. ViewHeight := ViewPort.Y2-ViewPort.Y1;
  1711. ClipPixels := ViewPort.Clip;
  1712. end;
  1713. {--------------------------------------------------------------------------}
  1714. { }
  1715. { BITMAP PUT/GET ROUTINES }
  1716. { }
  1717. {--------------------------------------------------------------------------}
  1718. Procedure GetScanlineDefault (X1, X2, Y : smallint; Var Data); {$ifndef fpc}far;{$endif fpc}
  1719. {**********************************************************}
  1720. { Procedure GetScanLine() }
  1721. {----------------------------------------------------------}
  1722. { Returns the full scanline of the video line of the Y }
  1723. { coordinate. The values are returned in a WORD array }
  1724. { each WORD representing a pixel of the specified scanline }
  1725. { note: we only need the pixels inside the ViewPort! (JM) }
  1726. { note2: extended so you can specify start and end X coord }
  1727. { so it is usable for GetImage too (JM) }
  1728. {**********************************************************}
  1729. Var
  1730. x : smallint;
  1731. Begin
  1732. For x:=X1 to X2 Do
  1733. WordArray(Data)[x-x1]:=GetPixel(x, y);
  1734. End;
  1735. Function DefaultImageSize(X1,Y1,X2,Y2: smallint): longint; {$ifndef fpc}far;{$endif fpc}
  1736. Begin
  1737. { each pixel uses two bytes, to enable modes with colors up to 64K }
  1738. { to work. }
  1739. DefaultImageSize := 12 + (((X2-X1+1)*(Y2-Y1+1))*2);
  1740. end;
  1741. Procedure DefaultPutImage(X,Y: smallint; var Bitmap; BitBlt: Word); {$ifndef fpc}far;{$endif fpc}
  1742. type
  1743. pt = array[0..$fffffff] of word;
  1744. ptw = array[0..2] of longint;
  1745. var
  1746. k: longint;
  1747. oldCurrentColor: word;
  1748. oldCurrentWriteMode, i, j, y1, x1, deltaX, deltaX1, deltaY: smallint;
  1749. Begin
  1750. {$ifdef logging}
  1751. LogLn('putImage at ('+strf(x)+','+strf(y)+') with width '+strf(ptw(Bitmap)[0])+
  1752. ' and height '+strf(ptw(Bitmap)[1]));
  1753. deltaY := 0;
  1754. {$endif logging}
  1755. inc(x,startXViewPort);
  1756. inc(y,startYViewPort);
  1757. x1 := ptw(Bitmap)[0]+x; { get width and adjust end coordinate accordingly }
  1758. y1 := ptw(Bitmap)[1]+y; { get height and adjust end coordinate accordingly }
  1759. deltaX := 0;
  1760. deltaX1 := 0;
  1761. k := 3 * sizeOf(Longint) div sizeOf(Word); { Three reserved longs at start of bitmap }
  1762. { check which part of the image is in the viewport }
  1763. if clipPixels then
  1764. begin
  1765. if y < startYViewPort then
  1766. begin
  1767. deltaY := startYViewPort - y;
  1768. inc(k,(x1-x+1)*deltaY);
  1769. y := startYViewPort;
  1770. end;
  1771. if y1 > startYViewPort+viewHeight then
  1772. y1 := startYViewPort+viewHeight;
  1773. if x < startXViewPort then
  1774. begin
  1775. deltaX := startXViewPort-x;
  1776. x := startXViewPort;
  1777. end;
  1778. if x1 > startXViewPort + viewWidth then
  1779. begin
  1780. deltaX1 := x1 - (startXViewPort + viewWidth);
  1781. x1 := startXViewPort + viewWidth;
  1782. end;
  1783. end;
  1784. {$ifdef logging}
  1785. LogLn('deltax: '+strf(deltax)+', deltax1: '+strf(deltax1)+',deltay: '+strf(deltay));
  1786. {$endif logging}
  1787. oldCurrentColor := currentColor;
  1788. oldCurrentWriteMode := currentWriteMode;
  1789. currentWriteMode := bitBlt;
  1790. for j:=Y to Y1 do
  1791. Begin
  1792. inc(k,deltaX);
  1793. for i:=X to X1 do
  1794. begin
  1795. currentColor := pt(bitmap)[k];
  1796. directPutPixel(i,j);
  1797. inc(k);
  1798. end;
  1799. inc(k,deltaX1);
  1800. end;
  1801. currentWriteMode := oldCurrentWriteMode;
  1802. currentColor := oldCurrentColor;
  1803. end;
  1804. Procedure DefaultGetImage(X1,Y1,X2,Y2: smallint; Var Bitmap); {$ifndef fpc}far;{$endif fpc}
  1805. type
  1806. pt = array[0..$fffffff] of word;
  1807. ptw = array[0..2] of longint;
  1808. var
  1809. i,j: smallint;
  1810. k: longint;
  1811. Begin
  1812. k:= 3 * Sizeof(longint) div sizeof(word); { Three reserved longs at start of bitmap }
  1813. i := x2 - x1 + 1;
  1814. for j:=Y1 to Y2 do
  1815. Begin
  1816. GetScanLine(x1,x2,j,pt(Bitmap)[k]);
  1817. inc(k,i);
  1818. end;
  1819. ptw(Bitmap)[0] := X2-X1; { First longint is width }
  1820. ptw(Bitmap)[1] := Y2-Y1; { Second longint is height }
  1821. ptw(bitmap)[2] := 0; { Third longint is reserved}
  1822. end;
  1823. Procedure GetArcCoords(var ArcCoords: ArcCoordsType);
  1824. Begin
  1825. ArcCoords.X := ArcCall.X;
  1826. ArcCoords.Y := ArcCall.Y;
  1827. ArcCoords.XStart := ArcCall.XStart;
  1828. ArcCoords.YStart := ArcCall.YStart;
  1829. ArcCoords.XEnd := ArcCall.XEnd;
  1830. ArcCoords.YEnd := ArcCall.YEnd;
  1831. end;
  1832. procedure SetVisualPageDefault(page : word); {$ifndef fpc}far;{$endif fpc}
  1833. begin
  1834. end;
  1835. procedure SetActivePageDefault(page : word); {$ifndef fpc}far;{$endif fpc}
  1836. begin
  1837. end;
  1838. procedure DirectPutPixelDefault(X,Y: smallint);
  1839. begin
  1840. RunError(218);
  1841. end;
  1842. function GetPixelDefault(X,Y: smallint): word;
  1843. begin
  1844. RunError(218);
  1845. exit(0); { avoid warning }
  1846. end;
  1847. procedure PutPixelDefault(X,Y: smallint; Color: Word);
  1848. begin
  1849. RunError(218);
  1850. end;
  1851. procedure SetRGBPaletteDefault(ColorNum, RedValue, GreenValue, BlueValue: smallint);
  1852. begin
  1853. RunError(218);
  1854. end;
  1855. procedure GetRGBPaletteDefault(ColorNum: smallint; var
  1856. RedValue, GreenValue, BlueValue: smallint);
  1857. begin
  1858. RunError(218);
  1859. end;
  1860. Procedure DefaultHooks;
  1861. {********************************************************}
  1862. { Procedure DefaultHooks() }
  1863. {--------------------------------------------------------}
  1864. { Resets all hookable routine either to nil for those }
  1865. { which need overrides, and others to defaults. }
  1866. { This is called each time SetGraphMode() is called. }
  1867. {********************************************************}
  1868. Begin
  1869. { All default hooks procedures }
  1870. { required...}
  1871. DirectPutPixel := {$ifdef fpc}@{$endif}DirectPutPixelDefault;
  1872. PutPixel := {$ifdef fpc}@{$endif}PutPixelDefault;
  1873. GetPixel := {$ifdef fpc}@{$endif}GetPixelDefault;
  1874. SetRGBPalette := {$ifdef fpc}@{$endif}SetRGBPaletteDefault;
  1875. GetRGBPalette := {$ifdef fpc}@{$endif}GetRGBPaletteDefault;
  1876. { optional...}
  1877. SetActivePage := {$ifdef fpc}@{$endif}SetActivePageDefault;
  1878. SetVisualPage := {$ifdef fpc}@{$endif}SetVisualPageDefault;
  1879. ClearViewPort := {$ifdef fpc}@{$endif}ClearViewportDefault;
  1880. PutImage := {$ifdef fpc}@{$endif}DefaultPutImage;
  1881. GetImage := {$ifdef fpc}@{$endif}DefaultGetImage;
  1882. ImageSize := {$ifdef fpc}@{$endif}DefaultImageSize;
  1883. GraphFreeMemPtr := nil;
  1884. GraphGetMemPtr := nil;
  1885. GetScanLine := {$ifdef fpc}@{$endif}GetScanLineDefault;
  1886. Line := {$ifdef fpc}@{$endif}LineDefault;
  1887. InternalEllipse := {$ifdef fpc}@{$endif}InternalEllipseDefault;
  1888. PatternLine := {$ifdef fpc}@{$endif}PatternLineDefault;
  1889. HLine := {$ifdef fpc}@{$endif}HLineDefault;
  1890. VLine := {$ifdef fpc}@{$endif}VLineDefault;
  1891. end;
  1892. Procedure InitVars;
  1893. {********************************************************}
  1894. { Procedure InitVars() }
  1895. {--------------------------------------------------------}
  1896. { Resets all internal variables, and resets all }
  1897. { overridable routines. }
  1898. {********************************************************}
  1899. Begin
  1900. DirectVideo := TRUE; { By default use fastest access possible }
  1901. ArcCall.X := 0;
  1902. ArcCall.Y := 0;
  1903. ArcCall.XStart := 0;
  1904. ArcCall.YStart := 0;
  1905. ArcCall.XEnd := 0;
  1906. ArcCall.YEnd := 0;
  1907. { Reset to default values }
  1908. IntCurrentMode := 0;
  1909. IntCurrentDriver := 0;
  1910. XAspect := 0;
  1911. YAspect := 0;
  1912. MaxX := 0;
  1913. MaxY := 0;
  1914. MaxColor := 0;
  1915. PaletteSize := 0;
  1916. DirectColor := FALSE;
  1917. HardwarePages := 0;
  1918. if hardwarepages=0 then; { remove note }
  1919. DefaultHooks;
  1920. end;
  1921. {$i modes.inc}
  1922. {$i palette.inc}
  1923. {$i graph.inc}
  1924. function InstallUserDriver(Name: string; AutoDetectPtr: Pointer): smallint;
  1925. begin
  1926. _graphResult := grError;
  1927. InstallUserDriver:=grError;
  1928. end;
  1929. function RegisterBGIDriver(driver: pointer): smallint;
  1930. begin
  1931. _graphResult := grError;
  1932. RegisterBGIDriver:=grError;
  1933. end;
  1934. { ----------------------------------------------------------------- }
  1935. Procedure Arc(X,Y : smallint; StAngle,EndAngle,Radius: word);
  1936. { var
  1937. OldWriteMode: word;}
  1938. Begin
  1939. { Only if we are using thickwidths lines do we accept }
  1940. { XORput write modes. }
  1941. { OldWriteMode := CurrentWriteMode;
  1942. if (LineInfo.Thickness = NormWidth) then
  1943. CurrentWriteMode := NormalPut;}
  1944. InternalEllipse(X,Y,Radius,Radius,StAngle,Endangle,{$ifdef fpc}@{$endif}DummyPatternLine);
  1945. { CurrentWriteMode := OldWriteMode;}
  1946. end;
  1947. procedure Ellipse(X,Y : smallint; stAngle, EndAngle: word; XRadius,YRadius: word);
  1948. Begin
  1949. InternalEllipse(X,Y,XRadius,YRadius,StAngle,Endangle,{$ifdef fpc}@{$endif}DummyPatternLine);
  1950. end;
  1951. procedure FillEllipse(X, Y: smallint; XRadius, YRadius: Word);
  1952. {********************************************************}
  1953. { Procedure FillEllipse() }
  1954. {--------------------------------------------------------}
  1955. { Draws a filled ellipse using (X,Y) as a center point }
  1956. { and XRadius and YRadius as the horizontal and vertical }
  1957. { axes. The ellipse is filled with the current fill color}
  1958. { and fill style, and is bordered with the current color.}
  1959. {********************************************************}
  1960. begin
  1961. InternalEllipse(X,Y,XRadius,YRadius,0,360,PatternLine)
  1962. end;
  1963. procedure Circle(X, Y: smallint; Radius:Word);
  1964. {********************************************************}
  1965. { Draws a circle centered at X,Y with the given Radius. }
  1966. {********************************************************}
  1967. { Important notes: }
  1968. { - Thickwidth circles use the current write mode, while}
  1969. { normal width circles ALWAYS use CopyPut/NormalPut }
  1970. { mode. (Tested against VGA BGI driver -CEC 13/Aug/99 }
  1971. {********************************************************}
  1972. var OriginalArcInfo: ArcCoordsType;
  1973. OldWriteMode: word;
  1974. begin
  1975. if (Radius = 0) then
  1976. Exit;
  1977. if (Radius = 1) then
  1978. begin
  1979. { only normal put mode is supported by a call to PutPixel }
  1980. PutPixel(X, Y, CurrentColor);
  1981. Exit;
  1982. end;
  1983. { save state of arc information }
  1984. { because it is not needed for }
  1985. { a circle call. }
  1986. move(ArcCall,OriginalArcInfo, sizeof(ArcCall));
  1987. if LineInfo.Thickness = Normwidth then
  1988. begin
  1989. OldWriteMode := CurrentWriteMode;
  1990. CurrentWriteMode := CopyPut;
  1991. end;
  1992. InternalEllipse(X,Y,Radius,Radius,0,360,{$ifdef fpc}@{$endif}DummyPatternLine);
  1993. if LineInfo.Thickness = Normwidth then
  1994. CurrentWriteMode := OldWriteMode;
  1995. { restore arc information }
  1996. move(OriginalArcInfo, ArcCall,sizeof(ArcCall));
  1997. end;
  1998. procedure SectorPL(x1,x2,y: smallint); {$ifndef fpc}far;{$endif fpc}
  1999. var plx1, plx2: smallint;
  2000. {$ifdef sectorpldebug}
  2001. t : text;
  2002. {$endif sectorpldebug}
  2003. begin
  2004. {$ifdef sectorpldebug}
  2005. assign(t,'sector.log');
  2006. append(t);
  2007. writeln(t,'Got here for line ',y);
  2008. close(t);
  2009. {$endif sectorpldebug}
  2010. If (x1 = -maxsmallint) Then
  2011. If (x2 = maxsmallint-1) Then
  2012. { no ellipse points drawn on this line }
  2013. If (((Y < ArcCall.Y) and (Y > ArcCall.YStart)) or
  2014. ((Y > ArcCall.Y) and (Y < ArcCall.YStart))) Then
  2015. { there is a part of the sector at this y coordinate, but no }
  2016. { ellips points are plotted on this line, so draw a patternline }
  2017. { between the lines connecting (arccall.x,arccall.y) with }
  2018. { the start and the end of the arc (JM) }
  2019. { use: y-y1=(y2-y1)/(x2-x1)*(x-x1) => }
  2020. { x = (y-y1)/(y2-y1)*(x2-x1)+x1 }
  2021. Begin
  2022. {$ifdef sectorpldebug}
  2023. If (ArcCall.YStart-ArcCall.Y) = 0 then
  2024. begin
  2025. append(t);
  2026. writeln(t,'bug1');
  2027. close(t);
  2028. runerror(202);
  2029. end;
  2030. {$endif sectorpldebug}
  2031. plx1 := (y-ArcCall.Y)*(ArcCall.XStart-ArcCall.X)
  2032. div (ArcCall.YStart-ArcCall.Y)+ArcCall.X;
  2033. {$ifdef sectorpldebug}
  2034. If (ArcCall.YEnd-ArcCall.Y) = 0 then
  2035. begin
  2036. append(t);
  2037. writeln(t,'bug2');
  2038. close(t);
  2039. runerror(202);
  2040. end;
  2041. {$endif sectorpldebug}
  2042. plx2 := (y-ArcCall.Y)*(ArcCall.XEnd-ArcCall.X)
  2043. div (ArcCall.YEnd-ArcCall.Y)+ArcCall.X;
  2044. If plx1 > plx2 then
  2045. begin
  2046. plx1 := plx1 xor plx2;
  2047. plx2 := plx1 xor plx2;
  2048. plx1 := plx1 xor plx2;
  2049. end;
  2050. {$ifdef sectorpldebug}
  2051. append(t);
  2052. writeln(t,'lines: ',plx1,' - ',plx2);
  2053. close(t);
  2054. {$endif sectorpldebug}
  2055. End
  2056. { otherwise two points which have nothing to do with the sector }
  2057. Else exit
  2058. Else
  2059. { the arc is plotted at the right side, but not at the left side, }
  2060. { fill till the line between (ArcCall.X,ArcCall.Y) and }
  2061. { (ArcCall.XStart,ArcCall.YStart) }
  2062. Begin
  2063. If (y < ArcCall.Y) then
  2064. begin
  2065. {$ifdef sectorpldebug}
  2066. If (ArcCall.YEnd-ArcCall.Y) = 0 then
  2067. begin
  2068. append(t);
  2069. writeln(t,'bug3');
  2070. close(t);
  2071. runerror(202);
  2072. end;
  2073. {$endif sectorpldebug}
  2074. plx1 := (y-ArcCall.Y)*(ArcCall.XEnd-ArcCall.X)
  2075. div (ArcCall.YEnd-ArcCall.Y)+ArcCall.X
  2076. end
  2077. else if (y > ArcCall.Y) then
  2078. begin
  2079. {$ifdef sectorpldebug}
  2080. If (ArcCall.YStart-ArcCall.Y) = 0 then
  2081. begin
  2082. append(t);
  2083. writeln(t,'bug4');
  2084. close(t);
  2085. runerror(202);
  2086. end;
  2087. {$endif sectorpldebug}
  2088. plx1 := (y-ArcCall.Y)*(ArcCall.XStart-ArcCall.X)
  2089. div (ArcCall.YStart-ArcCall.Y)+ArcCall.X
  2090. end
  2091. else plx1 := ArcCall.X;
  2092. plx2 := x2;
  2093. {$ifdef sectorpldebug}
  2094. append(t);
  2095. writeln(t,'right: ',plx1,' - ',plx2);
  2096. close(t);
  2097. {$endif sectorpldebug}
  2098. End
  2099. Else
  2100. If (x2 = maxsmallint-1) Then
  2101. { the arc is plotted at the left side, but not at the rigth side. }
  2102. { the right limit can be either the first or second line. Just take }
  2103. { the closest one, but watch out for division by zero! }
  2104. Begin
  2105. If (y < ArcCall.Y) then
  2106. begin
  2107. {$ifdef sectorpldebug}
  2108. If (ArcCall.YStart-ArcCall.Y) = 0 then
  2109. begin
  2110. append(t);
  2111. writeln(t,'bug5');
  2112. close(t);
  2113. runerror(202);
  2114. end;
  2115. {$endif sectorpldebug}
  2116. plx2 := (y-ArcCall.Y)*(ArcCall.XStart-ArcCall.X)
  2117. div (ArcCall.YStart-ArcCall.Y)+ArcCall.X
  2118. end
  2119. else if (y > ArcCall.Y) then
  2120. begin
  2121. {$ifdef sectorpldebug}
  2122. If (ArcCall.YEnd-ArcCall.Y) = 0 then
  2123. begin
  2124. append(t);
  2125. writeln(t,'bug6');
  2126. close(t);
  2127. runerror(202);
  2128. end;
  2129. {$endif sectorpldebug}
  2130. plx2 := (y-ArcCall.Y)*(ArcCall.XEnd-ArcCall.X)
  2131. div (ArcCall.YEnd-ArcCall.Y)+ArcCall.X
  2132. end
  2133. else plx2 := ArcCall.X;
  2134. plx1 := x1;
  2135. {$ifdef sectorpldebug}
  2136. append(t);
  2137. writeln(t,'left: ',plx1,' - ',plx2);
  2138. close(t);
  2139. {$endif sectorpldebug}
  2140. End
  2141. Else
  2142. { the arc is plotted at both sides }
  2143. Begin
  2144. plx1 := x1;
  2145. plx2 := x2;
  2146. {$ifdef sectorpldebug}
  2147. append(t);
  2148. writeln(t,'normal: ',plx1,' - ',plx2);
  2149. close(t);
  2150. {$endif sectorpldebug}
  2151. End;
  2152. If plx2 > plx1 then
  2153. Begin
  2154. {$ifdef sectorpldebug}
  2155. append(t);
  2156. Writeln(t,'drawing...');
  2157. close(t);
  2158. {$endif sectorpldebug}
  2159. PatternLine(plx1,plx2,y);
  2160. end;
  2161. end;
  2162. procedure Sector(x, y: smallint; StAngle,EndAngle, XRadius, YRadius: Word);
  2163. begin
  2164. internalellipse(x,y,XRadius, YRadius, StAngle, EndAngle, {$ifdef fpc}@{$endif}SectorPL);
  2165. Line(ArcCall.XStart, ArcCall.YStart, x,y);
  2166. Line(x,y,ArcCall.Xend,ArcCall.YEnd);
  2167. end;
  2168. procedure SetFillStyle(Pattern : word; Color: word);
  2169. begin
  2170. { on invalid input, the current fill setting will be }
  2171. { unchanged. }
  2172. if (Pattern > UserFill) or (Color > GetMaxColor) then
  2173. begin
  2174. _GraphResult := grError;
  2175. exit;
  2176. end;
  2177. FillSettings.Color := Color;
  2178. FillSettings.Pattern := Pattern;
  2179. end;
  2180. procedure SetFillPattern(Pattern: FillPatternType; Color: word);
  2181. {********************************************************}
  2182. { Changes the Current FillPattern to a user defined }
  2183. { pattern and changes also the current fill color. }
  2184. { The FillPattern is saved in the FillPattern array so }
  2185. { it can still be used with SetFillStyle(UserFill,Color) }
  2186. {********************************************************}
  2187. var
  2188. i: smallint;
  2189. begin
  2190. if Color > GetMaxColor then
  2191. begin
  2192. _GraphResult := grError;
  2193. exit;
  2194. end;
  2195. FillSettings.Color := Color;
  2196. FillSettings.Pattern := UserFill;
  2197. { Save the pattern in the buffer }
  2198. For i:=1 to 8 do
  2199. FillPatternTable[UserFill][i] := Pattern[i];
  2200. end;
  2201. procedure Bar(x1,y1,x2,y2:smallint);
  2202. {********************************************************}
  2203. { Important notes for compatibility with BP: }
  2204. { - WriteMode is always CopyPut }
  2205. { - No contour is drawn for the lines }
  2206. {********************************************************}
  2207. var y : smallint;
  2208. origcolor : longint;
  2209. origlinesettings: Linesettingstype;
  2210. origwritemode : smallint;
  2211. begin
  2212. origlinesettings:=lineinfo;
  2213. origcolor:=CurrentColor;
  2214. if y1>y2 then
  2215. begin
  2216. y:=y1;
  2217. y1:=y2;
  2218. y2:=y;
  2219. end;
  2220. { Always copy mode for Bars }
  2221. origwritemode := CurrentWriteMode;
  2222. CurrentWriteMode := CopyPut;
  2223. { All lines used are of this style }
  2224. Lineinfo.linestyle:=solidln;
  2225. Lineinfo.thickness:=normwidth;
  2226. case Fillsettings.pattern of
  2227. EmptyFill :
  2228. begin
  2229. Currentcolor:=CurrentBkColor;
  2230. for y:=y1 to y2 do
  2231. Hline(x1,x2,y);
  2232. end;
  2233. SolidFill :
  2234. begin
  2235. CurrentColor:=FillSettings.color;
  2236. for y:=y1 to y2 do
  2237. Hline(x1,x2,y);
  2238. end;
  2239. else
  2240. Begin
  2241. CurrentColor:=FillSettings.color;
  2242. for y:=y1 to y2 do
  2243. patternline(x1,x2,y);
  2244. end;
  2245. end;
  2246. CurrentColor:= Origcolor;
  2247. LineInfo := OrigLineSettings;
  2248. CurrentWriteMode := OrigWritemode;
  2249. end;
  2250. procedure bar3D(x1, y1, x2, y2 : smallint;depth : word;top : boolean);
  2251. var
  2252. origwritemode : smallint;
  2253. OldX, OldY : smallint;
  2254. begin
  2255. origwritemode := CurrentWriteMode;
  2256. CurrentWriteMode := CopyPut;
  2257. Bar(x1,y1,x2,y2);
  2258. Rectangle(x1,y1,x2,y2);
  2259. { Current CP should not be updated in Bar3D }
  2260. { therefore save it and then restore it on }
  2261. { exit. }
  2262. OldX := CurrentX;
  2263. OldY := CurrentY;
  2264. if top then begin
  2265. Moveto(x1,y1);
  2266. Lineto(x1+depth,y1-depth);
  2267. Lineto(x2+depth,y1-depth);
  2268. Lineto(x2,y1);
  2269. end;
  2270. if Depth <> 0 then
  2271. Begin
  2272. Moveto(x2+depth,y1-depth);
  2273. Lineto(x2+depth,y2-depth);
  2274. Lineto(x2,y2);
  2275. end;
  2276. { restore CP }
  2277. CurrentX := OldX;
  2278. CurrentY := OldY;
  2279. CurrentWriteMode := origwritemode;
  2280. end;
  2281. {--------------------------------------------------------------------------}
  2282. { }
  2283. { COLOR AND PALETTE ROUTINES }
  2284. { }
  2285. {--------------------------------------------------------------------------}
  2286. procedure SetColor(Color: Word);
  2287. Begin
  2288. CurrentColor := Color;
  2289. end;
  2290. function GetColor: Word;
  2291. Begin
  2292. GetColor := CurrentColor;
  2293. end;
  2294. function GetBkColor: Word;
  2295. Begin
  2296. GetBkColor := CurrentBkColor;
  2297. end;
  2298. procedure SetBkColor(ColorNum: Word);
  2299. { Background color means background screen color in this case, and it is }
  2300. { INDEPENDANT of the viewport settings, so we must clear the whole screen }
  2301. { with the color. }
  2302. var
  2303. ViewPort: ViewportType;
  2304. Begin
  2305. GetViewSettings(Viewport);
  2306. SetViewPort(0,0,MaxX,MaxY,FALSE);
  2307. CurrentBkColor := ColorNum;
  2308. {ClearViewPort;}
  2309. if not DirectColor and (ColorNum<256) then
  2310. SetRGBPalette(0,
  2311. DefaultColors[ColorNum].Red,
  2312. DefaultColors[ColorNum].Green,
  2313. DefaultColors[ColorNum].Blue);
  2314. SetViewport(ViewPort.X1,Viewport.Y1,Viewport.X2,Viewport.Y2,Viewport.Clip);
  2315. end;
  2316. function GetMaxColor: word;
  2317. { Checked against TP VGA driver - CEC }
  2318. begin
  2319. GetMaxColor:=MaxColor-1; { based on an index of zero so subtract one }
  2320. end;
  2321. Procedure MoveRel(Dx, Dy: smallint);
  2322. Begin
  2323. CurrentX := CurrentX + Dx;
  2324. CurrentY := CurrentY + Dy;
  2325. end;
  2326. Procedure MoveTo(X,Y: smallint);
  2327. {********************************************************}
  2328. { Procedure MoveTo() }
  2329. {--------------------------------------------------------}
  2330. { Moves the current pointer in VIEWPORT relative }
  2331. { coordinates to the specified X,Y coordinate. }
  2332. {********************************************************}
  2333. Begin
  2334. CurrentX := X;
  2335. CurrentY := Y;
  2336. end;
  2337. function GraphErrorMsg(ErrorCode: smallint): string;
  2338. Begin
  2339. GraphErrorMsg:='';
  2340. case ErrorCode of
  2341. grOk,grFileNotFound,grInvalidDriver: exit;
  2342. grNoInitGraph: GraphErrorMsg:='Graphics driver not installed';
  2343. grNotDetected: GraphErrorMsg:='Graphics hardware not detected';
  2344. grNoLoadMem,grNoScanMem,grNoFloodMem: GraphErrorMsg := 'Not enough memory for graphics';
  2345. grNoFontMem: GraphErrorMsg := 'Not enough memory to load font';
  2346. grFontNotFound: GraphErrorMsg:= 'Font file not found';
  2347. grInvalidMode: GraphErrorMsg := 'Invalid graphics mode';
  2348. grError: GraphErrorMsg:='Graphics error';
  2349. grIoError: GraphErrorMsg:='Graphics I/O error';
  2350. grInvalidFont,grInvalidFontNum: GraphErrorMsg := 'Invalid font';
  2351. grInvalidVersion: GraphErrorMsg:='Invalid driver version';
  2352. end;
  2353. end;
  2354. Function GetMaxX: smallint;
  2355. { Routine checked against VGA driver - CEC }
  2356. Begin
  2357. GetMaxX := MaxX;
  2358. end;
  2359. Function GetMaxY: smallint;
  2360. { Routine checked against VGA driver - CEC }
  2361. Begin
  2362. GetMaxY := MaxY;
  2363. end;
  2364. Function GraphResult: smallint;
  2365. Begin
  2366. GraphResult := _GraphResult;
  2367. _GraphResult := grOk;
  2368. end;
  2369. Function GetX: smallint;
  2370. Begin
  2371. GetX := CurrentX;
  2372. end;
  2373. Function GetY: smallint;
  2374. Begin
  2375. GetY := CurrentY;
  2376. end;
  2377. Function GetDriverName: string;
  2378. begin
  2379. GetDriverName:=DriverName;
  2380. end;
  2381. procedure graphdefaults;
  2382. { PS: GraphDefaults does not ZERO the ArcCall structure }
  2383. { so a call to GetArcCoords will not change even the }
  2384. { returned values even if GraphDefaults is called in }
  2385. { between. }
  2386. var
  2387. i: smallint;
  2388. begin
  2389. lineinfo.linestyle:=solidln;
  2390. lineinfo.thickness:=normwidth;
  2391. { reset line style pattern }
  2392. for i:=0 to 15 do
  2393. LinePatterns[i] := TRUE;
  2394. { By default, according to the TP prog's reference }
  2395. { the default pattern is solid, and the default }
  2396. { color is the maximum color in the palette. }
  2397. fillsettings.color:=GetMaxColor;
  2398. fillsettings.pattern:=solidfill;
  2399. { GraphDefaults resets the User Fill pattern to $ff }
  2400. { checked with VGA BGI driver - CEC }
  2401. for i:=1 to 8 do
  2402. FillPatternTable[UserFill][i] := $ff;
  2403. CurrentColor:=white;
  2404. SetBkColor(Black);
  2405. ClipPixels := TRUE;
  2406. { Reset the viewport }
  2407. StartXViewPort := 0;
  2408. StartYViewPort := 0;
  2409. ViewWidth := MaxX;
  2410. ViewHeight := MaxY;
  2411. { Reset CP }
  2412. CurrentX := 0;
  2413. CurrentY := 0;
  2414. { normal write mode }
  2415. CurrentWriteMode := CopyPut;
  2416. { Schriftart einstellen }
  2417. CurrentTextInfo.font := DefaultFont;
  2418. CurrentTextInfo.direction:=HorizDir;
  2419. CurrentTextInfo.charsize:=1;
  2420. CurrentTextInfo.horiz:=LeftText;
  2421. CurrentTextInfo.vert:=TopText;
  2422. XAspect:=10000; YAspect:=10000;
  2423. end;
  2424. procedure GetAspectRatio(var Xasp,Yasp : word);
  2425. begin
  2426. XAsp:=XAspect;
  2427. YAsp:=YAspect;
  2428. end;
  2429. procedure SetAspectRatio(Xasp, Yasp : word);
  2430. begin
  2431. Xaspect:= XAsp;
  2432. YAspect:= YAsp;
  2433. end;
  2434. procedure SetWriteMode(WriteMode : smallint);
  2435. { TP sets the writemodes according to the following scheme (JM) }
  2436. begin
  2437. Case writemode of
  2438. xorput, andput: CurrentWriteMode := XorPut;
  2439. notput, orput, copyput: CurrentWriteMode := CopyPut;
  2440. End;
  2441. end;
  2442. procedure GetFillSettings(var Fillinfo:Fillsettingstype);
  2443. begin
  2444. Fillinfo:=Fillsettings;
  2445. end;
  2446. procedure GetFillPattern(var FillPattern:FillPatternType);
  2447. begin
  2448. FillPattern:=FillpatternTable[UserFill];
  2449. end;
  2450. procedure DrawPoly(numpoints : word;var polypoints);
  2451. type
  2452. ppointtype = ^pointtype;
  2453. pt = array[0..16000] of pointtype;
  2454. var
  2455. i : longint;
  2456. begin
  2457. if numpoints < 2 then
  2458. begin
  2459. _GraphResult := grError;
  2460. exit;
  2461. end;
  2462. for i:=0 to numpoints-2 do
  2463. line(pt(polypoints)[i].x,
  2464. pt(polypoints)[i].y,
  2465. pt(polypoints)[i+1].x,
  2466. pt(polypoints)[i+1].y);
  2467. end;
  2468. procedure PieSlice(X,Y,stangle,endAngle:smallint;Radius: Word);
  2469. begin
  2470. Sector(x,y,stangle,endangle,radius,radius);
  2471. end;
  2472. {$i fills.inc}
  2473. {$i gtext.inc}
  2474. procedure DetectGraph(var GraphDriver:smallint;var GraphMode:smallint);
  2475. var LoMode, HiMode: smallint;
  2476. CpyMode: smallint;
  2477. CpyDriver: smallint;
  2478. begin
  2479. HiMode := -1;
  2480. LoMode := -1;
  2481. { We start at VGA }
  2482. GraphDriver := VGA;
  2483. CpyMode := 0;
  2484. { search all possible graphic drivers in ascending order...}
  2485. { usually the new driver numbers indicate newest hardware...}
  2486. { Internal driver numbers start at VGA=9 }
  2487. repeat
  2488. GetModeRange(GraphDriver,LoMode,HiMode);
  2489. { save the highest mode possible...}
  2490. {$ifdef logging}
  2491. logln('Found driver '+strf(graphdriver)+' with modes '+
  2492. strf(lomode)+' - '+strf(himode));
  2493. {$endif logging}
  2494. if HiMode = -1 then break;
  2495. CpyMode:=HiMode;
  2496. CpyDriver:=GraphDriver;
  2497. { go to next driver if it exists...}
  2498. Inc(GraphDriver);
  2499. until (CpyMode=-1);
  2500. { If this is equal to -1 then no graph mode possible...}
  2501. if CpyMode = -1 then
  2502. begin
  2503. _GraphResult := grNotDetected;
  2504. exit;
  2505. end;
  2506. _GraphResult := grOK;
  2507. GraphDriver := CpyDriver;
  2508. GraphMode := CpyMode;
  2509. end;
  2510. procedure InitGraph(var GraphDriver:smallint;var GraphMode:smallint;
  2511. const PathToDriver:String);
  2512. const
  2513. {$IFDEF Linux}
  2514. dirchar = '/';
  2515. {$ELSE}
  2516. dirchar = '\';
  2517. {$ENDIF}
  2518. begin
  2519. InitVars;
  2520. { path to the fonts (where they will be searched)...}
  2521. bgipath:=PathToDriver;
  2522. if (Length(bgipath) > 0) and (bgipath[length(bgipath)]<>dirchar) then
  2523. bgipath:=bgipath+dirchar;
  2524. if not assigned(SaveVideoState) then
  2525. RunError(216);
  2526. DriverName:=InternalDriverName; { DOS Graphics driver }
  2527. if (Graphdriver=Detect) then
  2528. begin
  2529. DetectGraph(GraphDriver,GraphMode);
  2530. If _GraphResult = grNotDetected then Exit;
  2531. { _GraphResult is now already set to grOK by DetectGraph }
  2532. IntCurrentDriver := GraphDriver;
  2533. SaveVideoState;
  2534. { Actually set the graph mode...}
  2535. SetGraphMode(GraphMode);
  2536. end
  2537. else
  2538. begin
  2539. { Search if that graphics modec actually exists...}
  2540. if SearchMode(GraphDriver,GraphMode) = nil then
  2541. begin
  2542. _GraphResult := grInvalidMode;
  2543. exit;
  2544. end
  2545. else
  2546. begin
  2547. _GraphResult := grOK;
  2548. IntCurrentDriver := GraphDriver;
  2549. SaveVideoState;
  2550. {$ifdef logging}
  2551. If _GraphResult <> grOK then
  2552. LogLn('Mode setting failed after savevideostate');
  2553. {$endif logging}
  2554. SetGraphMode(GraphMode);
  2555. end;
  2556. end;
  2557. end;
  2558. procedure SetDirectVideo(DirectAccess: boolean);
  2559. begin
  2560. DirectVideo := DirectAccess;
  2561. end;
  2562. function GetDirectVideo: boolean;
  2563. begin
  2564. GetDirectVideo := DirectVideo;
  2565. end;
  2566. procedure GraphExitProc; {$ifndef fpc} far; {$endif fpc}
  2567. { deallocates all memory allocated by the graph unit }
  2568. var
  2569. list: PModeInfo;
  2570. tmp : PModeInfo;
  2571. c: graph_int;
  2572. begin
  2573. { restore old exitproc! }
  2574. exitproc := exitsave;
  2575. if IsGraphMode and ((errorcode<>0) or (erroraddr<>nil)) then
  2576. CloseGraph;
  2577. {$ifdef testsave}
  2578. restorevideostate;
  2579. {$endif testsave}
  2580. { release memory allocated for fonts }
  2581. for c := 1 to installedfonts do
  2582. with fonts[c] Do
  2583. If assigned(instr) Then
  2584. Freemem(instr,instrlength);
  2585. { release memory allocated for modelist }
  2586. list := ModeList;
  2587. while assigned(list) do
  2588. begin
  2589. tmp := list;
  2590. list:=list^.next;
  2591. dispose(tmp);
  2592. end;
  2593. {$IFDEF DPMI}
  2594. { We had copied the buffer of mode information }
  2595. { and allocated it dynamically... now free it }
  2596. { Warning: if GetVESAInfo returned false, this buffer is not allocated! (JM)}
  2597. If hasVesa then
  2598. Dispose(VESAInfo.ModeList);
  2599. {$ENDIF}
  2600. end;
  2601. begin
  2602. {$ifdef logging}
  2603. assign(debuglog,'grlog.txt');
  2604. rewrite(debuglog);
  2605. close(debuglog);
  2606. {$endif logging}
  2607. isgraphmode := false;
  2608. ModeList := nil;
  2609. SaveVideoState := nil;
  2610. RestoreVideoState := nil;
  2611. {$ifdef oldfont}
  2612. {$ifdef go32v2}
  2613. LoadFont8x8;
  2614. {$endif go32v2}
  2615. {$endif oldfont}
  2616. { This must be called at startup... because GetGraphMode may }
  2617. { be called even when not in graph mode. }
  2618. {$ifdef logging}
  2619. LogLn('Calling QueryAdapterInfo...');
  2620. {$endif logging}
  2621. QueryAdapterInfo;
  2622. { Install standard fonts }
  2623. { This is done BEFORE startup... }
  2624. InstalledFonts := 0;
  2625. InstallUserFont('TRIP');
  2626. InstallUserFont('LITT');
  2627. InstallUserFont('SANS');
  2628. InstallUserFont('GOTH');
  2629. InstallUserFont('SCRI');
  2630. InstallUserFont('SIMP');
  2631. InstallUserFont('TSCR');
  2632. InstallUserFont('LCOM');
  2633. InstallUserFont('EURO');
  2634. InstallUserFont('BOLD');
  2635. { This installs an exit procedure which cleans up the mode list...}
  2636. ExitSave := ExitProc;
  2637. ExitProc := @GraphExitProc;
  2638. {$ifdef testsave}
  2639. savevideostate;
  2640. {$endif testsave}
  2641. {$ifdef win32}
  2642. charmessagehandler:=nil;
  2643. {$endif win32}
  2644. end.
  2645. {
  2646. $Log$
  2647. Revision 1.59 2000-03-17 13:28:54 sg
  2648. * Use linux unit under Linux
  2649. Revision 1.58 2000/03/08 14:20:14 jonas
  2650. * writemode was not set to normalput during clearviewport (and it uses hline)
  2651. Revision 1.57 2000/02/27 14:41:25 peter
  2652. * removed warnings/notes
  2653. Revision 1.56 2000/02/06 01:47:15 sg
  2654. * For Linux, "/" is added to the bgipath instead of "\" if this character
  2655. isn't already there.
  2656. Revision 1.55 2000/01/07 16:41:37 daniel
  2657. * copyright 2000
  2658. Revision 1.54 2000/01/07 16:32:25 daniel
  2659. * copyright 2000 added
  2660. Revision 1.53 2000/01/02 19:02:39 jonas
  2661. * removed/commented out (inited but) unused vars and unused types
  2662. Revision 1.52 1999/12/29 17:26:00 jonas
  2663. + by default, also attempt to install the fonts that come with TP7
  2664. Revision 1.51 1999/12/26 10:33:06 jonas
  2665. * XAspect and YAspect are now words instead of smallints, they
  2666. overflowed for resolutions > 640x480 otherwise
  2667. * the number of pixels required for an ellipse in internalellipsedef
  2668. is now calculated after the aspectratios have been taken into
  2669. account
  2670. Revision 1.50 1999/12/21 17:42:17 jonas
  2671. * changed vesa.inc do it doesn't try to use linear modes anymore (doesn't work
  2672. yet!!)
  2673. * fixed mode detection so the low modenumber of a driver doesn't have to be zero
  2674. anymore (so VESA autodetection now works)
  2675. Revision 1.49 1999/12/21 09:16:48 pierre
  2676. + CloseGraph if errors
  2677. Revision 1.48 1999/12/20 11:22:36 peter
  2678. * integer -> smallint to overcome -S2 switch needed for ggi version
  2679. Revision 1.47 1999/12/12 13:34:20 jonas
  2680. * putimage now performs the lipping itself and uses directputpixel
  2681. (note: this REQUIRES or/and/notput support in directputpixel,
  2682. this is not yet the case in the assembler versions!)
  2683. * YOffset addition moved in hlinevesa256 and vlinevesa256
  2684. because it uses still putpixel afterwards
  2685. Revision 1.46 1999/12/11 23:41:38 jonas
  2686. * changed definition of getscanlineproc to "getscanline(x1,x2,y:
  2687. smallint; var data);" so it can be used by getimage too
  2688. * changed getimage so it uses getscanline
  2689. * changed floodfill, getscanline16 and definitions in Linux
  2690. include files so they use this new format
  2691. + getscanlineVESA256 for 256 color VESA modes (banked)
  2692. Revision 1.45 1999/12/10 12:47:41 pierre
  2693. * SetBkColor like BP by changing Palette entry zero
  2694. Revision 1.44 1999/11/30 08:57:46 michael
  2695. + Removed charmessagehandler declaration, it is in graphh.inc
  2696. Revision 1.43 1999/11/28 16:13:55 jonas
  2697. * corrected misplacement of call to initvars in initgraph
  2698. + some extra debugging commands (for -dlogging) in the mode functions
  2699. Revision 1.42 1999/11/28 12:19:59 jonas
  2700. * _GraphResult is now properly set to grOK by DetectGraph and
  2701. InitGraph if there are no errors
  2702. Revision 1.41 1999/11/27 21:48:01 jonas
  2703. * fixed VlineVESA256 and re-enabled it in graph.inc
  2704. * added procedure detectgraph to interface of graph unit
  2705. Revision 1.40 1999/11/25 17:44:14 pierre
  2706. * memory corruption within GetImage removed
  2707. Revision 1.39 1999/11/24 23:42:31 pierre
  2708. * PutImage used an smallint index that became negative !!!!
  2709. * Default needed procedure now genrate a RTE 218 instead of a
  2710. GPF by call to nil pointer !
  2711. Revision 1.38 1999/11/11 17:55:07 florian
  2712. * the size was calculated wrong by imagesize
  2713. Revision 1.37 1999/11/11 14:07:14 florian
  2714. * better looking font
  2715. Revision 1.36 1999/11/08 15:01:38 peter
  2716. * fpcmake support
  2717. Revision 1.35 1999/11/08 11:15:22 peter
  2718. * move graph.inc to the target dir
  2719. Revision 1.34 1999/11/03 20:23:01 florian
  2720. + first release of win32 gui support
  2721. Revision 1.33 1999/10/17 10:20:13 jonas
  2722. * fixed clipping for thickwidth lines (bug 659)
  2723. * fixed the faster internalellipsedefault, but it doesn't plot
  2724. all pixels (there are gaps in the ellipses)
  2725. Revision 1.32 1999/09/28 15:07:46 jonas
  2726. * fix for disposing font data because it can contain #0 chars
  2727. Revision 1.31 1999/09/28 13:56:25 jonas
  2728. * reordered some local variables (first 4 byte vars, then 2 byte vars
  2729. etc)
  2730. * font data is now disposed in exitproc, exitproc is now called
  2731. GraphExitProc (was CleanModes) and resides in graph.pp instead of in
  2732. modes.inc
  2733. Revision 1.30 1999/09/27 23:34:41 peter
  2734. * new graph unit is default for go32v2
  2735. * removed warnings/notes
  2736. Revision 1.29 1999/09/26 13:31:06 jonas
  2737. * changed name of modeinfo variable to vesamodeinfo and fixed
  2738. associated errors (fillchar(modeinfo,sizeof(tmodeinfo),#0) instead
  2739. of sizeof(TVesamodeinfo) etc)
  2740. * changed several sizeof(type) to sizeof(varname) to avoid similar
  2741. errors in the future
  2742. Revision 1.28 1999/09/25 11:48:43 jonas
  2743. + detectgraph
  2744. * small change to internalellipsedefault so less pixels are
  2745. calculated twice
  2746. * some small corrections to graph.tex
  2747. Revision 1.27 1999/09/24 22:52:38 jonas
  2748. * optimized patternline a bit (always use hline when possible)
  2749. * isgraphmode stuff cleanup
  2750. * vesainfo.modelist now gets disposed in cleanmode instead of in
  2751. closegraph (required moving of some declarations from vesa.inc to
  2752. new vesah.inc)
  2753. * queryadapter gets no longer called from initgraph (is called from
  2754. initialization of graph unit)
  2755. * bugfix for notput in 32k and 64k vesa modes
  2756. * a div replaced by / in fillpoly
  2757. Revision 1.26 1999/09/22 13:13:35 jonas
  2758. * renamed text.inc -> gtext.inc to avoid conflict with system unit
  2759. * fixed textwidth
  2760. * isgraphmode now gets properly updated, so mode restoring works
  2761. again
  2762. Revision 1.25 1999/09/18 22:21:10 jonas
  2763. + hlinevesa256 and vlinevesa256
  2764. + support for not/xor/or/andput in vesamodes with 32k/64k colors
  2765. * lots of changes to avoid warnings under FPC
  2766. Revision 1.24 1999/09/18 16:03:37 jonas
  2767. * graph.pp: removed pieslice and sector from ToDo list
  2768. * closegraph: exits now immidiately if isgraphmode = false (caused
  2769. RTE 204 with VESA enabled if you set exitproc to call closegraph
  2770. and also called closegraph explicitely before exit, like bgidemo)
  2771. Revision 1.23 1999/09/17 13:58:31 jonas
  2772. * another fix for a case where internalellipsedefault went haywire
  2773. * sector() and pieslice() fully implemented!
  2774. * small change to prevent buffer overflow with floodfill
  2775. Revision 1.22 1999/09/15 13:37:50 jonas
  2776. * small change to internalellipsedef to be TP compatible
  2777. * fixed directputpixel for vga 320*200*256
  2778. Revision 1.21 1999/09/13 12:49:08 jonas
  2779. * fixed Arc: internallellipse went into an endless loop if StAngle =
  2780. EndAngle
  2781. * FillEllipse is now much faster: no more floodfill,
  2782. InternalEllipseDefault now draws the patternlines immediatety!
  2783. Revision 1.20 1999/09/12 17:29:00 jonas
  2784. * several changes to internalellipse to make it faster
  2785. and to make sure it updates the ArcCall correctly
  2786. (not yet done for width = 3)
  2787. * Arc mostly works now, only sometimes an endless loop, don't know
  2788. why
  2789. Revision 1.19 1999/09/11 19:43:01 jonas
  2790. * FloodFill: did not take into account current viewport settings
  2791. * GetScanLine: only get line inside viewport, data outside of it
  2792. is not used anyway
  2793. * InternalEllipseDefault: fix for when xradius or yradius = 0 and
  2794. increase xradius and yradius always by one (TP does this too)
  2795. * fixed conlict in vesa.inc from last update
  2796. * some conditionals to avoid range check and overflow errors in
  2797. places where it doesn't matter
  2798. Revision 1.18 1999/07/26 09:38:41 florian
  2799. * bar: y2 can be less y1, fixed
  2800. * settextstyle: charsize can be 0, must be changed into 1
  2801. Revision 1.17 1999/07/18 15:07:20 jonas
  2802. + xor-, and and- orput support for VESA256 modes
  2803. * compile with -dlogging if you wnt some info to be logged to grlog.txt
  2804. Revision 1.16 1999/07/14 18:18:04 florian
  2805. * cosmetic changes
  2806. }