graph.pp 97 KB

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