graph.pp 92 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. { - Imagesize returns a longint instead of a word }
  38. { - ImageSize cannot return an error value }
  39. {-------------------------------------------------------}
  40. { AUTHORS: }
  41. { Gernot Tenchio - original version }
  42. { Florian Klaempfl - major updates }
  43. { Pierre Mueller - major bugfixes }
  44. { Carl Eric Codere - complete rewrite }
  45. { Thomas Schatzl - optimizations,routines and }
  46. { suggestions. }
  47. { Jonas Maebe - bugfixes and optimizations }
  48. { Credits (external): }
  49. { - Original FloodFill code by }
  50. { Menno Victor van der star }
  51. { (the code has been heavily modified) }
  52. {-------------------------------------------------------}
  53. {-------------------------------------------------------}
  54. { For significant speed improvements , is is recommended }
  55. { that these routines be hooked (otherwise the default, }
  56. { slower routines will be used) : }
  57. { HLine() }
  58. { VLine() }
  59. { PatternLine() }
  60. { ClearViewPort() }
  61. { PutImage() }
  62. { GetImage() - ImageSize() should also be changed }
  63. { InternalEllipse() }
  64. { Line() }
  65. { GetScanLine() }
  66. {--------------------------------------------------------}
  67. { FPC unit requirements: }
  68. { All modes should at least have 1 graphics page to }
  69. { make it possible to create animation on all supported }
  70. { systems , this can be done either by double-buffering }
  71. { yourself in the heap if no hardware is available to do}
  72. { it. }
  73. {--------------------------------------------------------}
  74. { COMPATIBILITY WARNING: Some of the compatibility tests }
  75. { were done using the CGA and other the VGA drivers. }
  76. { Within the BGI drivers themselves the BEHAVIOUR is not }
  77. { the same, so be warned!!! }
  78. {--------------------------------------------------------}
  79. { History log: }
  80. { 15th February 1999: }
  81. { + Added support for system font in vertical mode }
  82. { + system font is now available for all platforms }
  83. { * font support routines now compile }
  84. { * textHeight would not return correct size for system }
  85. { font }
  86. { * Alignment of fonts partly fixed }
  87. { 17th Feb. 1999: }
  88. { + First support for stroked fonts }
  89. { 18th Feb. 1999: }
  90. { * bugfix of line drawing which fixes stroked font }
  91. { displays. }
  92. { 23rd Feb. 1999: }
  93. { + Applied Pierre's patches to font }
  94. { + Added scaling of bitmapped fonts }
  95. { + Vertical stroked fonts }
  96. { 24th Feb. 1999: }
  97. { * Scaling of stroked fonts must be done using FPs }
  98. { to be 100% compatible with turbo pascal }
  99. { + Sped up by 40% stroked font scaling calculations }
  100. { + RegisterBGIFont }
  101. { 9th march 1999: }
  102. { + Starting implementing Fillpoly() }
  103. { 15th march 1999: }
  104. { + SetFillStyle() }
  105. { + patternLine() }
  106. { + Bar() }
  107. { * GraphDefaults would not make the Default color }
  108. { of the fill pattern to the Max. Palette entry. }
  109. { + SetFillPattern() }
  110. { 20th march 1999: }
  111. { * GraphDefaults would not reset to the text system }
  112. { * DefaultFont would write one character too much to }
  113. { the screen }
  114. { + Sloped thick lines in Line() }
  115. { + Sloped patterned lines in Line() }
  116. { * GraphDefaults would not reset the User Fill pattern}
  117. { to $ff }
  118. { + DirectPutPixel takes care of XOR mode writes }
  119. { improves speed by about 30% over old method of }
  120. { GetPixel XOR CurrentColor }
  121. { * Dashed LineStyle exactly like BP version now }
  122. { + Center LineStyle (checked against CGA driver) }
  123. { * GraphDefaults() now resets linepattern array }
  124. { 1st april 1999: }
  125. { + First implementation of FillPoly (incomplete) }
  126. { 2nd april 1999: }
  127. { * FillPoly did not Reset PatternLine index }
  128. { * FillPoly did not use correct color }
  129. { * PatternLine was writing modes in reverse direction }
  130. { * PatternLine would not work with non-rectangular }
  131. { shapes. }
  132. { * PatternLine must fill up the ENTIRE pattern, }
  133. { with either the foreground or background color. }
  134. { * GraphDefaults() would not call SetBkColor() }
  135. { * Fixed some memory leaks in FillPoly() }
  136. { 11th April 1999: }
  137. { * PatternLine() was drawing one pixel less then }
  138. { requested }
  139. { 12th April 1999: }
  140. { + FloodFill - first working implementation }
  141. { Horrbly slow even on very fast cpu's }
  142. { + Some suggestions of Thomas implemented }
  143. { 13th April 1999: }
  144. { * FloodFill() vertical index was off by one pixel }
  145. { * FloodFill() would never draw the last line in the }
  146. { list }
  147. { - Removed ClearViewPort320 which was wrong anyways, }
  148. { will need to be implemented later. }
  149. { * PatternLine() would not always restore write mode }
  150. { + Circle() uses NormalPut always with NormWidth lines}
  151. { + FillEllipse() initial version }
  152. { * InternalEllipse() - 0 to 360 now supported as }
  153. { angles. }
  154. { 14th April 1999: }
  155. { * mod x = and (x-1)(from Thomas Schatzl) gives a }
  156. { significant speed improvement. }
  157. { 15th april 1999: }
  158. { + Arc() ok except for Aspect Ratio, which does not }
  159. { give us the correct ratio on a 320x200 screen. }
  160. { + Added FillPoly() from Thomas Schatzl }
  161. { + More hookable routines }
  162. { 16th april 1999: }
  163. { + Line() checked ok. }
  164. { 17th april 1999: }
  165. { * GraphDefaults() would not reset CP }
  166. { + GetX(), GetY(), MoveTo() checked for viewports }
  167. { * OutTextXY() should not update the CP }
  168. { * ClearViewPort() would not update the CP }
  169. { * ClearDevice() would not update the CP }
  170. { * Sector() would update the CP by calling LineTo }
  171. { * Bar3D() would update the CP }
  172. { * PieSlice() would update the CP }
  173. { 18th april 1999: }
  174. { + Clipping algorithm }
  175. { 19th april 1999: }
  176. { + Adapterinfo structure }
  177. { 20th april 1999: }
  178. { + GetModeName }
  179. { + GetGraphMode }
  180. { + GetModeRange }
  181. {--------------------------------------------------------}
  182. { LEFT TO DO: }
  183. { - optimize scaling of stroked fonts }
  184. { - optimize InternalEllipse() }
  185. { using linear appx. of sine/cosine tables }
  186. { - justification for stroked fonts does not work }
  187. { - On Closegraph deallocate all font pointers }
  188. {--------------------------------------------------------}
  189. { text.inc will crash on aligned requirement machines. }
  190. { (packed record for fontrec) }
  191. {$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); {$ifndef fpc}far;{$endif fpc}
  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); {$ifndef fpc}far;{$endif fpc}
  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); {$ifndef fpc}far;{$endif fpc}
  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: - }
  1144. { - }
  1145. {********************************************************}
  1146. Procedure InternalEllipseDefault(X,Y: Integer;XRadius: word;
  1147. YRadius:word; stAngle,EndAngle: word; pl: PatternLineProc); {$ifndef fpc}far;{$endif fpc}
  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:=Round(Sqrt(3)*sqrt(sqr(XRadius)+sqr(YRadius)));
  1212. { Calculate the angle precision required }
  1213. Delta := 90.0 / (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) 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); {$ifndef fpc}far;{$endif fpc}
  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. { Get the current pattern }
  1439. TmpFillPattern := FillPatternTable
  1440. [FillSettings.Pattern][(y and $7)+1];
  1441. Case TmpFillPattern Of
  1442. 0:
  1443. begin
  1444. OldCurrentColor := CurrentColor;
  1445. CurrentColor := CurrentBkColor;
  1446. { hline converts the coordinates to global ones, but that has been done }
  1447. { already here!!! Convert them back to local ones... (JM) }
  1448. HLine(x1-StartXViewPort,x2-StartXViewPort,y-StartYViewPort);
  1449. CurrentColor := OldCurrentColor;
  1450. end;
  1451. $ff:
  1452. begin
  1453. HLine(x1-StartXViewPort,x2-StartXViewPort,y-StartYViewPort);
  1454. end;
  1455. else
  1456. begin
  1457. { number of times to go throuh the 8x8 pattern }
  1458. NrIterations := abs(x2 - x1+1) div 8;
  1459. Inc(NrIterations);
  1460. For i:= 0 to NrIterations do
  1461. Begin
  1462. for j:=0 to 7 do
  1463. Begin
  1464. { x1 mod 8 }
  1465. if RevBitArray[x1 and 7] and TmpFillPattern <> 0 then
  1466. DirectPutpixel(x1,y)
  1467. else
  1468. begin
  1469. { According to the TP graph manual, we overwrite everything }
  1470. { which is filled up - checked against VGA and CGA drivers }
  1471. { of TP. }
  1472. OldCurrentColor := CurrentColor;
  1473. CurrentColor := CurrentBkColor;
  1474. DirectPutPixel(x1,y);
  1475. CurrentColor := OldCurrentColor;
  1476. end;
  1477. Inc(x1);
  1478. if x1 > x2 then
  1479. begin
  1480. CurrentWriteMode := OldWriteMode;
  1481. exit;
  1482. end;
  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; {$ifndef fpc}far;{$endif fpc}
  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); {$ifndef fpc}far;{$endif fpc}
  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; {$ifndef fpc}far;{$endif fpc}
  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); {$ifndef fpc}far;{$endif fpc}
  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); {$ifndef fpc}far;{$endif fpc}
  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); {$ifndef fpc}far;{$endif fpc}
  1723. begin
  1724. end;
  1725. procedure SetActivePageDefault(page : word); {$ifndef fpc}far;{$endif fpc}
  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. {$ifdef DPMI}
  1807. {$i vesah.inc}
  1808. {$endif DPMI}
  1809. {$i modes.inc}
  1810. {$i graph.inc}
  1811. function InstallUserDriver(Name: string; AutoDetectPtr: Pointer): integer;
  1812. begin
  1813. _graphResult := grError;
  1814. end;
  1815. function RegisterBGIDriver(driver: pointer): integer;
  1816. begin
  1817. _graphResult := grError;
  1818. end;
  1819. { ----------------------------------------------------------------- }
  1820. Procedure Arc(X,Y : Integer; StAngle,EndAngle,Radius: word);
  1821. { var
  1822. OldWriteMode: word;}
  1823. Begin
  1824. { Only if we are using thickwidths lines do we accept }
  1825. { XORput write modes. }
  1826. { OldWriteMode := CurrentWriteMode;
  1827. if (LineInfo.Thickness = NormWidth) then
  1828. CurrentWriteMode := NormalPut;}
  1829. {$ifdef fpc}
  1830. InternalEllipse(X,Y,Radius,Radius,StAngle,Endangle,@DummyPatternLine);
  1831. {$else fpc}
  1832. InternalEllipse(X,Y,Radius,Radius,StAngle,Endangle,DummyPatternLine);
  1833. {$endif fpc}
  1834. { CurrentWriteMode := OldWriteMode;}
  1835. end;
  1836. procedure Ellipse(X,Y : Integer; stAngle, EndAngle: word; XRadius,YRadius: word);
  1837. Begin
  1838. {$ifdef fpc}
  1839. InternalEllipse(X,Y,XRadius,YRadius,StAngle,Endangle,@DummyPatternLine);
  1840. {$else fpc}
  1841. InternalEllipse(X,Y,XRadius,YRadius,StAngle,Endangle,DummyPatternLine);
  1842. {$endif fpc}
  1843. end;
  1844. procedure FillEllipse(X, Y: Integer; XRadius, YRadius: Word);
  1845. {********************************************************}
  1846. { Procedure FillEllipse() }
  1847. {--------------------------------------------------------}
  1848. { Draws a filled ellipse using (X,Y) as a center point }
  1849. { and XRadius and YRadius as the horizontal and vertical }
  1850. { axes. The ellipse is filled with the current fill color}
  1851. { and fill style, and is bordered with the current color.}
  1852. {********************************************************}
  1853. begin
  1854. InternalEllipse(X,Y,XRadius,YRadius,0,360,PatternLine)
  1855. end;
  1856. procedure Circle(X, Y: Integer; Radius:Word);
  1857. {********************************************************}
  1858. { Draws a circle centered at X,Y with the given Radius. }
  1859. {********************************************************}
  1860. { Important notes: }
  1861. { - Thickwidth circles use the current write mode, while}
  1862. { normal width circles ALWAYS use CopyPut/NormalPut }
  1863. { mode. (Tested against VGA BGI driver -CEC 13/Aug/99 }
  1864. {********************************************************}
  1865. var OriginalArcInfo: ArcCoordsType;
  1866. OldWriteMode: word;
  1867. begin
  1868. if (Radius = 0) then
  1869. Exit;
  1870. if (Radius = 1) then
  1871. begin
  1872. { only normal put mode is supported by a call to PutPixel }
  1873. PutPixel(X, Y, CurrentColor);
  1874. Exit;
  1875. end;
  1876. { save state of arc information }
  1877. { because it is not needed for }
  1878. { a circle call. }
  1879. move(ArcCall,OriginalArcInfo, sizeof(ArcCall));
  1880. if LineInfo.Thickness = Normwidth then
  1881. begin
  1882. OldWriteMode := CurrentWriteMode;
  1883. CurrentWriteMode := CopyPut;
  1884. end;
  1885. {$ifdef fpc}
  1886. InternalEllipse(X,Y,Radius,Radius,0,360,@DummyPatternLine);
  1887. {$else fpc}
  1888. InternalEllipse(X,Y,Radius,Radius,0,360,DummyPatternLine);
  1889. {$endif fpc}
  1890. if LineInfo.Thickness = Normwidth then
  1891. CurrentWriteMode := OldWriteMode;
  1892. { restore arc information }
  1893. move(OriginalArcInfo, ArcCall,sizeof(ArcCall));
  1894. end;
  1895. procedure SectorPL(x1,x2,y: Integer); {$ifndef fpc}far;{$endif fpc}
  1896. var plx1, plx2: integer;
  1897. {$ifdef sectorpldebug}
  1898. t : text;
  1899. {$endif sectorpldebug}
  1900. begin
  1901. {$ifdef sectorpldebug}
  1902. assign(t,'sector.log');
  1903. append(t);
  1904. writeln(t,'Got here for line ',y);
  1905. close(t);
  1906. {$endif sectorpldebug}
  1907. If (x1 = -maxint) Then
  1908. If (x2 = maxint-1) Then
  1909. { no ellipse points drawn on this line }
  1910. If (((Y < ArcCall.Y) and (Y > ArcCall.YStart)) or
  1911. ((Y > ArcCall.Y) and (Y < ArcCall.YStart))) Then
  1912. { there is a part of the sector at this y coordinate, but no }
  1913. { ellips points are plotted on this line, so draw a patternline }
  1914. { between the lines connecting (arccall.x,arccall.y) with }
  1915. { the start and the end of the arc (JM) }
  1916. { use: y-y1=(y2-y1)/(x2-x1)*(x-x1) => }
  1917. { x = (y-y1)/(y2-y1)*(x2-x1)+x1 }
  1918. Begin
  1919. {$ifdef sectorpldebug}
  1920. If (ArcCall.YStart-ArcCall.Y) = 0 then
  1921. begin
  1922. append(t);
  1923. writeln(t,'bug1');
  1924. close(t);
  1925. runerror(202);
  1926. end;
  1927. {$endif sectorpldebug}
  1928. plx1 := (y-ArcCall.Y)*(ArcCall.XStart-ArcCall.X)
  1929. div (ArcCall.YStart-ArcCall.Y)+ArcCall.X;
  1930. {$ifdef sectorpldebug}
  1931. If (ArcCall.YEnd-ArcCall.Y) = 0 then
  1932. begin
  1933. append(t);
  1934. writeln(t,'bug2');
  1935. close(t);
  1936. runerror(202);
  1937. end;
  1938. {$endif sectorpldebug}
  1939. plx2 := (y-ArcCall.Y)*(ArcCall.XEnd-ArcCall.X)
  1940. div (ArcCall.YEnd-ArcCall.Y)+ArcCall.X;
  1941. If plx1 > plx2 then
  1942. begin
  1943. plx1 := plx1 xor plx2;
  1944. plx2 := plx1 xor plx2;
  1945. plx1 := plx1 xor plx2;
  1946. end;
  1947. {$ifdef sectorpldebug}
  1948. append(t);
  1949. writeln(t,'lines: ',plx1,' - ',plx2);
  1950. close(t);
  1951. {$endif sectorpldebug}
  1952. End
  1953. { otherwise two points which have nothing to do with the sector }
  1954. Else exit
  1955. Else
  1956. { the arc is plotted at the right side, but not at the left side, }
  1957. { fill till the line between (ArcCall.X,ArcCall.Y) and }
  1958. { (ArcCall.XStart,ArcCall.YStart) }
  1959. Begin
  1960. If (y < ArcCall.Y) then
  1961. begin
  1962. {$ifdef sectorpldebug}
  1963. If (ArcCall.YEnd-ArcCall.Y) = 0 then
  1964. begin
  1965. append(t);
  1966. writeln(t,'bug3');
  1967. close(t);
  1968. runerror(202);
  1969. end;
  1970. {$endif sectorpldebug}
  1971. plx1 := (y-ArcCall.Y)*(ArcCall.XEnd-ArcCall.X)
  1972. div (ArcCall.YEnd-ArcCall.Y)+ArcCall.X
  1973. end
  1974. else if (y > ArcCall.Y) then
  1975. begin
  1976. {$ifdef sectorpldebug}
  1977. If (ArcCall.YStart-ArcCall.Y) = 0 then
  1978. begin
  1979. append(t);
  1980. writeln(t,'bug4');
  1981. close(t);
  1982. runerror(202);
  1983. end;
  1984. {$endif sectorpldebug}
  1985. plx1 := (y-ArcCall.Y)*(ArcCall.XStart-ArcCall.X)
  1986. div (ArcCall.YStart-ArcCall.Y)+ArcCall.X
  1987. end
  1988. else plx1 := ArcCall.X;
  1989. plx2 := x2;
  1990. {$ifdef sectorpldebug}
  1991. append(t);
  1992. writeln(t,'right: ',plx1,' - ',plx2);
  1993. close(t);
  1994. {$endif sectorpldebug}
  1995. End
  1996. Else
  1997. If (x2 = maxint-1) Then
  1998. { the arc is plotted at the left side, but not at the rigth side. }
  1999. { the right limit can be either the first or second line. Just take }
  2000. { the closest one, but watch out for division by zero! }
  2001. Begin
  2002. If (y < ArcCall.Y) then
  2003. begin
  2004. {$ifdef sectorpldebug}
  2005. If (ArcCall.YStart-ArcCall.Y) = 0 then
  2006. begin
  2007. append(t);
  2008. writeln(t,'bug5');
  2009. close(t);
  2010. runerror(202);
  2011. end;
  2012. {$endif sectorpldebug}
  2013. plx2 := (y-ArcCall.Y)*(ArcCall.XStart-ArcCall.X)
  2014. div (ArcCall.YStart-ArcCall.Y)+ArcCall.X
  2015. end
  2016. else if (y > ArcCall.Y) then
  2017. begin
  2018. {$ifdef sectorpldebug}
  2019. If (ArcCall.YEnd-ArcCall.Y) = 0 then
  2020. begin
  2021. append(t);
  2022. writeln(t,'bug6');
  2023. close(t);
  2024. runerror(202);
  2025. end;
  2026. {$endif sectorpldebug}
  2027. plx2 := (y-ArcCall.Y)*(ArcCall.XEnd-ArcCall.X)
  2028. div (ArcCall.YEnd-ArcCall.Y)+ArcCall.X
  2029. end
  2030. else plx2 := ArcCall.X;
  2031. plx1 := x1;
  2032. {$ifdef sectorpldebug}
  2033. append(t);
  2034. writeln(t,'left: ',plx1,' - ',plx2);
  2035. close(t);
  2036. {$endif sectorpldebug}
  2037. End
  2038. Else
  2039. { the arc is plotted at both sides }
  2040. Begin
  2041. plx1 := x1;
  2042. plx2 := x2;
  2043. {$ifdef sectorpldebug}
  2044. append(t);
  2045. writeln(t,'normal: ',plx1,' - ',plx2);
  2046. close(t);
  2047. {$endif sectorpldebug}
  2048. End;
  2049. If plx2 > plx1 then
  2050. Begin
  2051. {$ifdef sectorpldebug}
  2052. append(t);
  2053. Writeln(t,'drawing...');
  2054. close(t);
  2055. {$endif sectorpldebug}
  2056. PatternLine(plx1,plx2,y);
  2057. end;
  2058. end;
  2059. procedure Sector(x, y: Integer; StAngle,EndAngle, XRadius, YRadius: Word);
  2060. (* var angle : graph_float;
  2061. writemode : word; *)
  2062. begin
  2063. {$ifdef fpc}
  2064. internalellipse(x,y,XRadius, YRadius, StAngle, EndAngle, @SectorPL);
  2065. {$else fpc}
  2066. internalellipse(x,y,XRadius, YRadius, StAngle, EndAngle, SectorPL);
  2067. {$endif fpc}
  2068. Line(ArcCall.XStart, ArcCall.YStart, x,y);
  2069. Line(x,y,ArcCall.Xend,ArcCall.YEnd);
  2070. end;
  2071. procedure SetFillStyle(Pattern : word; Color: word);
  2072. begin
  2073. { on invalid input, the current fill setting will be }
  2074. { unchanged. }
  2075. if (Pattern > UserFill) or (Color > GetMaxColor) then
  2076. begin
  2077. _GraphResult := grError;
  2078. exit;
  2079. end;
  2080. FillSettings.Color := Color;
  2081. FillSettings.Pattern := Pattern;
  2082. end;
  2083. procedure SetFillPattern(Pattern: FillPatternType; Color: word);
  2084. {********************************************************}
  2085. { Changes the Current FillPattern to a user defined }
  2086. { pattern and changes also the current fill color. }
  2087. { The FillPattern is saved in the FillPattern array so }
  2088. { it can still be used with SetFillStyle(UserFill,Color) }
  2089. {********************************************************}
  2090. var
  2091. i: integer;
  2092. begin
  2093. if Color > GetMaxColor then
  2094. begin
  2095. _GraphResult := grError;
  2096. exit;
  2097. end;
  2098. FillSettings.Color := Color;
  2099. FillSettings.Pattern := UserFill;
  2100. { Save the pattern in the buffer }
  2101. For i:=1 to 8 do
  2102. FillPatternTable[UserFill][i] := Pattern[i];
  2103. end;
  2104. procedure Bar(x1,y1,x2,y2:integer);
  2105. {********************************************************}
  2106. { Important notes for compatibility with BP: }
  2107. { - WriteMode is always CopyPut }
  2108. { - No contour is drawn for the lines }
  2109. {********************************************************}
  2110. var y : Integer;
  2111. origcolor : longint;
  2112. origlinesettings: Linesettingstype;
  2113. origwritemode : Integer;
  2114. begin
  2115. origlinesettings:=lineinfo;
  2116. origcolor:=CurrentColor;
  2117. if y1>y2 then
  2118. begin
  2119. y:=y1;
  2120. y1:=y2;
  2121. y2:=y;
  2122. end;
  2123. { Always copy mode for Bars }
  2124. origwritemode := CurrentWriteMode;
  2125. CurrentWriteMode := CopyPut;
  2126. { All lines used are of this style }
  2127. Lineinfo.linestyle:=solidln;
  2128. Lineinfo.thickness:=normwidth;
  2129. case Fillsettings.pattern of
  2130. EmptyFill :
  2131. begin
  2132. Currentcolor:=CurrentBkColor;
  2133. for y:=y1 to y2 do
  2134. Hline(x1,x2,y);
  2135. end;
  2136. SolidFill :
  2137. begin
  2138. CurrentColor:=FillSettings.color;
  2139. for y:=y1 to y2 do
  2140. Hline(x1,x2,y);
  2141. end;
  2142. else
  2143. Begin
  2144. CurrentColor:=FillSettings.color;
  2145. for y:=y1 to y2 do
  2146. patternline(x1,x2,y);
  2147. end;
  2148. end;
  2149. CurrentColor:= Origcolor;
  2150. LineInfo := OrigLineSettings;
  2151. CurrentWriteMode := OrigWritemode;
  2152. end;
  2153. procedure bar3D(x1, y1, x2, y2 : integer;depth : word;top : boolean);
  2154. var
  2155. origwritemode : integer;
  2156. OldX, OldY : integer;
  2157. begin
  2158. origwritemode := CurrentWriteMode;
  2159. CurrentWriteMode := CopyPut;
  2160. Bar(x1,y1,x2,y2);
  2161. Rectangle(x1,y1,x2,y2);
  2162. { Current CP should not be updated in Bar3D }
  2163. { therefore save it and then restore it on }
  2164. { exit. }
  2165. OldX := CurrentX;
  2166. OldY := CurrentY;
  2167. if top then begin
  2168. Moveto(x1,y1);
  2169. Lineto(x1+depth,y1-depth);
  2170. Lineto(x2+depth,y1-depth);
  2171. Lineto(x2,y1);
  2172. end;
  2173. if Depth <> 0 then
  2174. Begin
  2175. Moveto(x2+depth,y1-depth);
  2176. Lineto(x2+depth,y2-depth);
  2177. Lineto(x2,y2);
  2178. end;
  2179. { restore CP }
  2180. CurrentX := OldX;
  2181. CurrentY := OldY;
  2182. CurrentWriteMode := origwritemode;
  2183. end;
  2184. {--------------------------------------------------------------------------}
  2185. { }
  2186. { COLOR AND PALETTE ROUTINES }
  2187. { }
  2188. {--------------------------------------------------------------------------}
  2189. {$i palette.inc}
  2190. procedure SetColor(Color: Word);
  2191. Begin
  2192. CurrentColor := Color;
  2193. end;
  2194. function GetColor: Word;
  2195. Begin
  2196. GetColor := CurrentColor;
  2197. end;
  2198. function GetBkColor: Word;
  2199. Begin
  2200. GetBkColor := CurrentBkColor;
  2201. end;
  2202. procedure SetBkColor(ColorNum: Word);
  2203. { Background color means background screen color in this case, and it is }
  2204. { INDEPENDANT of the viewport settings, so we must clear the whole screen }
  2205. { with the color. }
  2206. var
  2207. ViewPort: ViewportType;
  2208. Begin
  2209. GetViewSettings(Viewport);
  2210. SetViewPort(0,0,MaxX,MaxY,FALSE);
  2211. CurrentBkColor := ColorNum;
  2212. ClearViewPort;
  2213. SetViewport(ViewPort.X1,Viewport.Y1,Viewport.X2,Viewport.Y2,Viewport.Clip);
  2214. end;
  2215. function GetMaxColor: word;
  2216. { Checked against TP VGA driver - CEC }
  2217. begin
  2218. GetMaxColor:=MaxColor-1; { based on an index of zero so subtract one }
  2219. end;
  2220. Procedure MoveRel(Dx, Dy: Integer);
  2221. Begin
  2222. CurrentX := CurrentX + Dx;
  2223. CurrentY := CurrentY + Dy;
  2224. end;
  2225. Procedure MoveTo(X,Y: Integer);
  2226. {********************************************************}
  2227. { Procedure MoveTo() }
  2228. {--------------------------------------------------------}
  2229. { Moves the current pointer in VIEWPORT relative }
  2230. { coordinates to the specified X,Y coordinate. }
  2231. {********************************************************}
  2232. Begin
  2233. CurrentX := X;
  2234. CurrentY := Y;
  2235. end;
  2236. function GraphErrorMsg(ErrorCode: Integer): string;
  2237. Begin
  2238. GraphErrorMsg:='';
  2239. case ErrorCode of
  2240. grOk,grFileNotFound,grInvalidDriver: exit;
  2241. grNoInitGraph: GraphErrorMsg:='Graphics driver not installed';
  2242. grNotDetected: GraphErrorMsg:='Graphics hardware not detected';
  2243. grNoLoadMem,grNoScanMem,grNoFloodMem: GraphErrorMsg := 'Not enough memory for graphics';
  2244. grNoFontMem: GraphErrorMsg := 'Not enough memory to load font';
  2245. grFontNotFound: GraphErrorMsg:= 'Font file not found';
  2246. grInvalidMode: GraphErrorMsg := 'Invalid graphics mode';
  2247. grError: GraphErrorMsg:='Graphics error';
  2248. grIoError: GraphErrorMsg:='Graphics I/O error';
  2249. grInvalidFont,grInvalidFontNum: GraphErrorMsg := 'Invalid font';
  2250. grInvalidVersion: GraphErrorMsg:='Invalid driver version';
  2251. end;
  2252. end;
  2253. Function GetMaxX: Integer;
  2254. { Routine checked against VGA driver - CEC }
  2255. Begin
  2256. GetMaxX := MaxX;
  2257. end;
  2258. Function GetMaxY: Integer;
  2259. { Routine checked against VGA driver - CEC }
  2260. Begin
  2261. GetMaxY := MaxY;
  2262. end;
  2263. Function GraphResult: Integer;
  2264. Begin
  2265. GraphResult := _GraphResult;
  2266. _GraphResult := grOk;
  2267. end;
  2268. Function GetX: Integer;
  2269. Begin
  2270. GetX := CurrentX;
  2271. end;
  2272. Function GetY: Integer;
  2273. Begin
  2274. GetY := CurrentY;
  2275. end;
  2276. Function GetDriverName: string;
  2277. begin
  2278. GetDriverName:=DriverName;
  2279. end;
  2280. procedure graphdefaults;
  2281. { PS: GraphDefaults does not ZERO the ArcCall structure }
  2282. { so a call to GetArcCoords will not change even the }
  2283. { returned values even if GraphDefaults is called in }
  2284. { between. }
  2285. var
  2286. i: integer;
  2287. begin
  2288. lineinfo.linestyle:=solidln;
  2289. lineinfo.thickness:=normwidth;
  2290. { reset line style pattern }
  2291. for i:=0 to 15 do
  2292. LinePatterns[i] := TRUE;
  2293. { By default, according to the TP prog's reference }
  2294. { the default pattern is solid, and the default }
  2295. { color is the maximum color in the palette. }
  2296. fillsettings.color:=GetMaxColor;
  2297. fillsettings.pattern:=solidfill;
  2298. { GraphDefaults resets the User Fill pattern to $ff }
  2299. { checked with VGA BGI driver - CEC }
  2300. for i:=1 to 8 do
  2301. FillPatternTable[UserFill][i] := $ff;
  2302. CurrentColor:=white;
  2303. SetBkColor(Black);
  2304. ClipPixels := TRUE;
  2305. { Reset the viewport }
  2306. StartXViewPort := 0;
  2307. StartYViewPort := 0;
  2308. ViewWidth := MaxX;
  2309. ViewHeight := MaxY;
  2310. { Reset CP }
  2311. CurrentX := 0;
  2312. CurrentY := 0;
  2313. { normal write mode }
  2314. CurrentWriteMode := CopyPut;
  2315. { Schriftart einstellen }
  2316. CurrentTextInfo.font := DefaultFont;
  2317. CurrentTextInfo.direction:=HorizDir;
  2318. CurrentTextInfo.charsize:=1;
  2319. CurrentTextInfo.horiz:=LeftText;
  2320. CurrentTextInfo.vert:=TopText;
  2321. XAspect:=10000; YAspect:=10000;
  2322. end;
  2323. procedure GetAspectRatio(var Xasp,Yasp : word);
  2324. begin
  2325. XAsp:=XAspect;
  2326. YAsp:=YAspect;
  2327. end;
  2328. procedure SetAspectRatio(Xasp, Yasp : word);
  2329. begin
  2330. Xaspect:= XAsp;
  2331. YAspect:= YAsp;
  2332. end;
  2333. procedure SetWriteMode(WriteMode : integer);
  2334. { TP sets the writemodes according to the following scheme (JM) }
  2335. begin
  2336. Case writemode of
  2337. xorput, andput: CurrentWriteMode := XorPut;
  2338. notput, orput, copyput: CurrentWriteMode := CopyPut;
  2339. End;
  2340. end;
  2341. procedure GetFillSettings(var Fillinfo:Fillsettingstype);
  2342. begin
  2343. Fillinfo:=Fillsettings;
  2344. end;
  2345. procedure GetFillPattern(var FillPattern:FillPatternType);
  2346. begin
  2347. FillPattern:=FillpatternTable[UserFill];
  2348. end;
  2349. procedure DrawPoly(numpoints : word;var polypoints);
  2350. type
  2351. ppointtype = ^pointtype;
  2352. pt = array[0..16000] of pointtype;
  2353. var
  2354. i : longint;
  2355. begin
  2356. if numpoints < 2 then
  2357. begin
  2358. _GraphResult := grError;
  2359. exit;
  2360. end;
  2361. for i:=0 to numpoints-2 do
  2362. line(pt(polypoints)[i].x,
  2363. pt(polypoints)[i].y,
  2364. pt(polypoints)[i+1].x,
  2365. pt(polypoints)[i+1].y);
  2366. end;
  2367. procedure PieSlice(X,Y,stangle,endAngle:integer;Radius: Word);
  2368. begin
  2369. Sector(x,y,stangle,endangle,radius,radius);
  2370. end;
  2371. {$i fills.inc}
  2372. {$i gtext.inc}
  2373. procedure DetectGraph(var GraphDriver:Integer;var GraphMode:Integer);
  2374. var LoMode, HiMode: Integer;
  2375. CpyMode: Integer;
  2376. CpyDriver: Integer;
  2377. begin
  2378. HiMode := -1;
  2379. LoMode := -1;
  2380. { We start at VGA }
  2381. GraphDriver := VGA;
  2382. CpyMode := 0;
  2383. { search all possible graphic drivers in ascending order...}
  2384. { usually the new driver numbers indicate newest hardware...}
  2385. { Internal driver numbers start at VGA=9 }
  2386. repeat
  2387. GetModeRange(GraphDriver,LoMode,HiMode);
  2388. { save the highest mode possible...}
  2389. if HiMode = -1 then break;
  2390. CpyMode:=HiMode;
  2391. CpyDriver:=GraphDriver;
  2392. { go to next driver if it exists...}
  2393. Inc(GraphDriver);
  2394. until (CpyMode=-1);
  2395. { If this is equal to -1 then no graph mode possible...}
  2396. if CpyMode = -1 then
  2397. begin
  2398. _GraphResult := grNotDetected;
  2399. exit;
  2400. end;
  2401. GraphDriver := CpyDriver;
  2402. GraphMode := CpyMode;
  2403. end;
  2404. procedure InitGraph(var GraphDriver:Integer;var GraphMode:Integer;
  2405. const PathToDriver:String);
  2406. begin
  2407. { path to the fonts (where they will be searched)...}
  2408. bgipath:=PathToDriver;
  2409. if bgipath[length(bgipath)]<>'\' then
  2410. bgipath:=bgipath+'\';
  2411. if not assigned(SaveVideoState) then
  2412. RunError(216);
  2413. {$ifdef logging}
  2414. LogLn('Calling SaveVideoState at '+strf(longint(savevideostate)));
  2415. {$endif logging}
  2416. SaveVideoState;
  2417. InitVars;
  2418. DriverName:=InternalDriverName; { DOS Graphics driver }
  2419. if (Graphdriver=Detect) then
  2420. begin
  2421. DetectGraph(GraphDriver,GraphMode);
  2422. If _GraphResult = grNotDetected then Exit;
  2423. IntCurrentDriver := GraphDriver;
  2424. { Actually set the graph mode...}
  2425. SetGraphMode(GraphMode);
  2426. end
  2427. else
  2428. begin
  2429. { Search if that graphics modec actually exists...}
  2430. if SearchMode(GraphDriver,GraphMode) = nil then
  2431. begin
  2432. _GraphResult := grInvalidMode;
  2433. exit;
  2434. end
  2435. else
  2436. begin
  2437. IntCurrentDriver := GraphDriver;
  2438. SetGraphMode(GraphMode);
  2439. end;
  2440. end;
  2441. end;
  2442. procedure SetDirectVideo(DirectAccess: boolean);
  2443. begin
  2444. DirectVideo := DirectAccess;
  2445. end;
  2446. function GetDirectVideo: boolean;
  2447. begin
  2448. GetDirectVideo := DirectVideo;
  2449. end;
  2450. var
  2451. ExitSave: pointer;
  2452. begin
  2453. {$ifdef logging}
  2454. assign(debuglog,'grlog.txt');
  2455. rewrite(debuglog);
  2456. close(debuglog);
  2457. {$endif logging}
  2458. isgraphmode := false;
  2459. ModeList := nil;
  2460. SaveVideoState := nil;
  2461. RestoreVideoState := nil;
  2462. SavePtr := Nil;
  2463. { This must be called at startup... because GetGraphMode may }
  2464. { be called even when not in graph mode. }
  2465. {$ifdef logging}
  2466. LogLn('Calling QueryAdapterInfo...');
  2467. {$endif logging}
  2468. QueryAdapterInfo;
  2469. { Install standard fonts }
  2470. { This is done BEFORE startup... }
  2471. InstalledFonts := 0;
  2472. InstallUserFont('TRIP');
  2473. InstallUserFont('LITT');
  2474. InstallUserFont('SANS');
  2475. InstallUserFont('GOTH');
  2476. { This installs an exit procedure which cleans up the mode list...}
  2477. ExitSave := ExitProc;
  2478. ExitProc := @CleanMode;
  2479. end.
  2480. SetGraphBufSize
  2481. SetBkColor
  2482. DetectGraph
  2483. { DetectGraph() }
  2484. { SetBkColor() }
  2485. {
  2486. $Log$
  2487. Revision 1.28 1999-09-25 11:48:43 jonas
  2488. + detectgraph
  2489. * small change to internalellipsedefault so less pixels are
  2490. calculated twice
  2491. * some small corrections to graph.tex
  2492. Revision 1.27 1999/09/24 22:52:38 jonas
  2493. * optimized patternline a bit (always use hline when possible)
  2494. * isgraphmode stuff cleanup
  2495. * vesainfo.modelist now gets disposed in cleanmode instead of in
  2496. closegraph (required moving of some declarations from vesa.inc to
  2497. new vesah.inc)
  2498. * queryadapter gets no longer called from initgraph (is called from
  2499. initialization of graph unit)
  2500. * bugfix for notput in 32k and 64k vesa modes
  2501. * a div replaced by / in fillpoly
  2502. Revision 1.26 1999/09/22 13:13:35 jonas
  2503. * renamed text.inc -> gtext.inc to avoid conflict with system unit
  2504. * fixed textwidth
  2505. * isgraphmode now gets properly updated, so mode restoring works
  2506. again
  2507. Revision 1.25 1999/09/18 22:21:10 jonas
  2508. + hlinevesa256 and vlinevesa256
  2509. + support for not/xor/or/andput in vesamodes with 32k/64k colors
  2510. * lots of changes to avoid warnings under FPC
  2511. Revision 1.24 1999/09/18 16:03:37 jonas
  2512. * graph.pp: removed pieslice and sector from ToDo list
  2513. * closegraph: exits now immidiately if isgraphmode = false (caused
  2514. RTE 204 with VESA enabled if you set exitproc to call closegraph
  2515. and also called closegraph explicitely before exit, like bgidemo)
  2516. Revision 1.23 1999/09/17 13:58:31 jonas
  2517. * another fix for a case where internalellipsedefault went haywire
  2518. * sector() and pieslice() fully implemented!
  2519. * small change to prevent buffer overflow with floodfill
  2520. Revision 1.22 1999/09/15 13:37:50 jonas
  2521. * small change to internalellipsedef to be TP compatible
  2522. * fixed directputpixel for vga 320*200*256
  2523. Revision 1.21 1999/09/13 12:49:08 jonas
  2524. * fixed Arc: internallellipse went into an endless loop if StAngle =
  2525. EndAngle
  2526. * FillEllipse is now much faster: no more floodfill,
  2527. InternalEllipseDefault now draws the patternlines immediatety!
  2528. Revision 1.20 1999/09/12 17:29:00 jonas
  2529. * several changes to internalellipse to make it faster
  2530. and to make sure it updates the ArcCall correctly
  2531. (not yet done for width = 3)
  2532. * Arc mostly works now, only sometimes an endless loop, don't know
  2533. why
  2534. Revision 1.19 1999/09/11 19:43:01 jonas
  2535. * FloodFill: did not take into account current viewport settings
  2536. * GetScanLine: only get line inside viewport, data outside of it
  2537. is not used anyway
  2538. * InternalEllipseDefault: fix for when xradius or yradius = 0 and
  2539. increase xradius and yradius always by one (TP does this too)
  2540. * fixed conlict in vesa.inc from last update
  2541. * some conditionals to avoid range check and overflow errors in
  2542. places where it doesn't matter
  2543. Revision 1.18 1999/07/26 09:38:41 florian
  2544. * bar: y2 can be less y1, fixed
  2545. * settextstyle: charsize can be 0, must be changed into 1
  2546. Revision 1.17 1999/07/18 15:07:20 jonas
  2547. + xor-, and and- orput support for VESA256 modes
  2548. * compile with -dlogging if you wnt some info to be logged to grlog.txt
  2549. Revision 1.16 1999/07/14 18:18:04 florian
  2550. * cosmetic changes
  2551. }