graph.pp 93 KB

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