graph.pp 93 KB

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