graph.pp 103 KB

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