graph.inc 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by the Free Pascal development team
  5. Graph unit implementation part
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {$ifdef logging}
  13. var debuglog: text;
  14. function strf(l: longint): string;
  15. begin
  16. str(l, strf)
  17. end;
  18. Procedure Log(Const s: String);
  19. Begin
  20. Append(debuglog);
  21. Write(debuglog, s);
  22. Close(debuglog);
  23. End;
  24. Procedure LogLn(Const s: string);
  25. Begin
  26. Append(debuglog);
  27. Writeln(debuglog,s);
  28. Close(debuglog);
  29. End;
  30. {$endif logging}
  31. const
  32. StdBufferSize = 4096; { Buffer size for FloodFill }
  33. type
  34. tinttable = array[0..16383] of smallint;
  35. pinttable = ^tinttable;
  36. WordArray = Array [0..StdbufferSize] Of word;
  37. PWordArray = ^WordArray;
  38. const
  39. { Mask for each bit in byte used to determine pattern }
  40. BitArray: Array[0..7] of byte =
  41. ($01,$02,$04,$08,$10,$20,$40,$80);
  42. RevbitArray: Array[0..7] of byte =
  43. ($80,$40,$20,$10,$08,$04,$02,$01);
  44. { pre expanded line patterns }
  45. { 0 = LSB of byte pattern }
  46. { 15 = MSB of byte pattern }
  47. LinePatterns: Array[0..15] of BOOLEAN =
  48. (TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,
  49. TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE);
  50. const
  51. BGIPath : string = '.';
  52. { Default font 8x8 system from IBM PC }
  53. {$i fontdata.inc}
  54. var
  55. CurrentColor: Word;
  56. CurrentBkColor: Word;
  57. CurrentX : smallint; { viewport relative }
  58. CurrentY : smallint; { viewport relative }
  59. ClipPixels: Boolean; { Should cliiping be enabled }
  60. CurrentWriteMode: smallint;
  61. _GraphResult : smallint;
  62. LineInfo : LineSettingsType;
  63. FillSettings: FillSettingsType;
  64. { information for Text Output routines }
  65. CurrentTextInfo : TextSettingsType;
  66. CurrentXRatio, CurrentYRatio: graph_float;
  67. installedfonts: longint; { Number of installed fonts }
  68. StartXViewPort: smallint; { absolute }
  69. StartYViewPort: smallint; { absolute }
  70. ViewWidth : smallint;
  71. ViewHeight: smallint;
  72. IsGraphMode : Boolean; { Indicates if we are in graph mode or not }
  73. ArcCall: ArcCoordsType; { Information on the last call to Arc or Ellipse }
  74. var
  75. { ******************** HARDWARE INFORMATION ********************* }
  76. { Should be set in InitGraph once only. }
  77. IntCurrentMode : smallint;
  78. IntCurrentDriver : smallint; { Currently loaded driver }
  79. IntCurrentNewDriver: smallint;
  80. XAspect : word;
  81. YAspect : word;
  82. MaxX : smallint; { Maximum resolution - ABSOLUTE }
  83. MaxY : smallint; { Maximum resolution - ABSOLUTE }
  84. MaxColor : Longint;
  85. PaletteSize : longint; { Maximum palette entry we can set, usually equal}
  86. { maxcolor. }
  87. HardwarePages : byte; { maximum number of hardware visual pages }
  88. DriverName: String;
  89. DirectColor : Boolean ; { Is it a direct color mode? }
  90. ModeList : PModeInfo;
  91. {$ifndef nonewmodes}
  92. newModeList: TNewModeInfo;
  93. {$endif nonewmodes}
  94. DirectVideo : Boolean; { Direct access to video memory? }
  95. {--------------------------------------------------------------------------}
  96. { }
  97. { LINE AND LINE RELATED ROUTINES }
  98. { }
  99. {--------------------------------------------------------------------------}
  100. {$i clip.inc}
  101. procedure HLineDefault(x,x2,y: smallint); {$ifndef fpc}far;{$endif fpc}
  102. var
  103. xtmp: smallint;
  104. Begin
  105. { must we swap the values? }
  106. if x >= x2 then
  107. Begin
  108. xtmp := x2;
  109. x2 := x;
  110. x:= xtmp;
  111. end;
  112. { First convert to global coordinates }
  113. X := X + StartXViewPort;
  114. X2 := X2 + StartXViewPort;
  115. Y := Y + StartYViewPort;
  116. if ClipPixels then
  117. Begin
  118. if LineClipped(x,y,x2,y,StartXViewPort,StartYViewPort,
  119. StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
  120. exit;
  121. end;
  122. for x:= x to x2 do
  123. DirectPutPixel(X,Y);
  124. end;
  125. procedure VLineDefault(x,y,y2: smallint); {$ifndef fpc}far;{$endif fpc}
  126. var
  127. ytmp: smallint;
  128. Begin
  129. { must we swap the values? }
  130. if y >= y2 then
  131. Begin
  132. ytmp := y2;
  133. y2 := y;
  134. y:= ytmp;
  135. end;
  136. { First convert to global coordinates }
  137. X := X + StartXViewPort;
  138. Y2 := Y2 + StartYViewPort;
  139. Y := Y + StartYViewPort;
  140. if ClipPixels then
  141. Begin
  142. if LineClipped(x,y,x,y2,StartXViewPort,StartYViewPort,
  143. StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
  144. exit;
  145. end;
  146. for y := y to y2 do Directputpixel(x,y)
  147. End;
  148. Procedure DirectPutPixelClip(x,y: smallint);
  149. { for thickwidth lines, because they may call DirectPutPixel for coords }
  150. { outside the current viewport (bug found by CEC) }
  151. Begin
  152. If (Not ClipPixels) Or
  153. ((X >= StartXViewPort) And (X <= (StartXViewPort + ViewWidth)) And
  154. (Y >= StartYViewPort) And (Y <= (StartYViewPort + ViewHeight))) then
  155. Begin
  156. DirectPutPixel(x,y)
  157. End
  158. End;
  159. procedure LineDefault(X1, Y1, X2, Y2: smallint); {$ifndef fpc}far;{$endif fpc}
  160. var X, Y : smallint;
  161. deltax, deltay : smallint;
  162. d, dinc1, dinc2: smallint;
  163. xinc1 : smallint;
  164. xinc2 : smallint;
  165. yinc1 : smallint;
  166. yinc2 : smallint;
  167. i : smallint;
  168. Flag : Boolean; { determines pixel direction in thick lines }
  169. NumPixels : smallint;
  170. PixelCount : smallint;
  171. OldCurrentColor: Word;
  172. swtmp : smallint;
  173. TmpNumPixels : smallint;
  174. begin
  175. {******************************************}
  176. { SOLID LINES }
  177. {******************************************}
  178. if lineinfo.LineStyle = SolidLn then
  179. Begin
  180. { we separate normal and thick width for speed }
  181. { and because it would not be 100% compatible }
  182. { with the TP graph unit otherwise }
  183. if y1 = y2 then
  184. Begin
  185. {******************************************}
  186. { SOLID LINES HORIZONTAL }
  187. {******************************************}
  188. if lineinfo.Thickness=NormWidth then
  189. hline(x1,x2,y2)
  190. else
  191. begin
  192. { thick width }
  193. hline(x1,x2,y2-1);
  194. hline(x1,x2,y2);
  195. hline(x2,x2,y2+1);
  196. end;
  197. end
  198. else
  199. if x1 = x2 then
  200. Begin
  201. {******************************************}
  202. { SOLID LINES VERTICAL }
  203. {******************************************}
  204. if lineinfo.Thickness=NormWidth then
  205. vline(x1,y1,y2)
  206. else
  207. begin
  208. { thick width }
  209. vline(x1-1,y1,y2);
  210. vline(x1,y1,y2);
  211. vline(x1+1,y1,y2);
  212. end;
  213. end
  214. else
  215. begin
  216. { Convert to global coordinates. }
  217. x1 := x1 + StartXViewPort;
  218. x2 := x2 + StartXViewPort;
  219. y1 := y1 + StartYViewPort;
  220. y2 := y2 + StartYViewPort;
  221. { if fully clipped then exit... }
  222. if ClipPixels then
  223. begin
  224. if LineClipped(x1,y1,x2,y2,StartXViewPort, StartYViewPort,
  225. StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
  226. exit;
  227. end;
  228. {******************************************}
  229. { SLOPED SOLID LINES }
  230. {******************************************}
  231. oldCurrentColor :=
  232. CurrentColor;
  233. { Calculate deltax and deltay for initialisation }
  234. deltax := abs(x2 - x1);
  235. deltay := abs(y2 - y1);
  236. { Initialize all vars based on which is the independent variable }
  237. if deltax >= deltay then
  238. begin
  239. Flag := FALSE;
  240. { x is independent variable }
  241. numpixels := deltax + 1;
  242. d := (2 * deltay) - deltax;
  243. dinc1 := deltay Shl 1;
  244. dinc2 := (deltay - deltax) shl 1;
  245. xinc1 := 1;
  246. xinc2 := 1;
  247. yinc1 := 0;
  248. yinc2 := 1;
  249. end
  250. else
  251. begin
  252. Flag := TRUE;
  253. { y is independent variable }
  254. numpixels := deltay + 1;
  255. d := (2 * deltax) - deltay;
  256. dinc1 := deltax Shl 1;
  257. dinc2 := (deltax - deltay) shl 1;
  258. xinc1 := 0;
  259. xinc2 := 1;
  260. yinc1 := 1;
  261. yinc2 := 1;
  262. end;
  263. { Make sure x and y move in the right directions }
  264. if x1 > x2 then
  265. begin
  266. xinc1 := - xinc1;
  267. xinc2 := - xinc2;
  268. end;
  269. if y1 > y2 then
  270. begin
  271. yinc1 := - yinc1;
  272. yinc2 := - yinc2;
  273. end;
  274. { Start drawing at <x1, y1> }
  275. x := x1;
  276. y := y1;
  277. If LineInfo.Thickness=NormWidth then
  278. Begin
  279. { Draw the pixels }
  280. for i := 1 to numpixels do
  281. begin
  282. DirectPutPixel(x, y);
  283. if d < 0 then
  284. begin
  285. d := d + dinc1;
  286. x := x + xinc1;
  287. y := y + yinc1;
  288. end
  289. else
  290. begin
  291. d := d + dinc2;
  292. x := x + xinc2;
  293. y := y + yinc2;
  294. end;
  295. CurrentColor := OldCurrentColor;
  296. end;
  297. end
  298. else
  299. { Thick width lines }
  300. begin
  301. { Draw the pixels }
  302. for i := 1 to numpixels do
  303. begin
  304. { all depending on the slope, we can determine }
  305. { in what direction the extra width pixels will be put }
  306. If Flag then
  307. Begin
  308. DirectPutPixelClip(x-1,y);
  309. DirectPutPixelClip(x,y);
  310. DirectPutPixelClip(x+1,y);
  311. end
  312. else
  313. Begin
  314. DirectPutPixelClip(x, y-1);
  315. DirectPutPixelClip(x, y);
  316. DirectPutPixelClip(x, y+1);
  317. end;
  318. if d < 0 then
  319. begin
  320. d := d + dinc1;
  321. x := x + xinc1;
  322. y := y + yinc1;
  323. end
  324. else
  325. begin
  326. d := d + dinc2;
  327. x := x + xinc2;
  328. y := y + yinc2;
  329. end;
  330. CurrentColor := OldCurrentColor;
  331. end;
  332. end;
  333. end;
  334. end
  335. else
  336. {******************************************}
  337. { begin patterned lines }
  338. {******************************************}
  339. Begin
  340. { Convert to global coordinates. }
  341. x1 := x1 + StartXViewPort;
  342. x2 := x2 + StartXViewPort;
  343. y1 := y1 + StartYViewPort;
  344. y2 := y2 + StartYViewPort;
  345. { if fully clipped then exit... }
  346. if ClipPixels then
  347. begin
  348. if LineClipped(x1,y1,x2,y2,StartXViewPort, StartYViewPort,
  349. StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
  350. exit;
  351. end;
  352. OldCurrentColor := CurrentColor;
  353. PixelCount:=0;
  354. if y1 = y2 then
  355. Begin
  356. { Check if we must swap }
  357. if x1 >= x2 then
  358. Begin
  359. swtmp := x1;
  360. x1 := x2;
  361. x2 := swtmp;
  362. end;
  363. if LineInfo.Thickness = NormWidth then
  364. Begin
  365. for PixelCount:=x1 to x2 do
  366. { optimization: PixelCount mod 16 }
  367. if LinePatterns[PixelCount and 15] = TRUE then
  368. begin
  369. DirectPutPixel(PixelCount,y2);
  370. end;
  371. end
  372. else
  373. Begin
  374. for i:=-1 to 1 do
  375. Begin
  376. for PixelCount:=x1 to x2 do
  377. { Optimization from Thomas - mod 16 = and 15 }
  378. {this optimization has been performed by the compiler
  379. for while as well (JM)}
  380. if LinePatterns[PixelCount and 15] = TRUE then
  381. begin
  382. DirectPutPixelClip(PixelCount,y2+i);
  383. end;
  384. end;
  385. end;
  386. end
  387. else
  388. if x1 = x2 then
  389. Begin
  390. { Check if we must swap }
  391. if y1 >= y2 then
  392. Begin
  393. swtmp := y1;
  394. y1 := y2;
  395. y2 := swtmp;
  396. end;
  397. if LineInfo.Thickness = NormWidth then
  398. Begin
  399. for PixelCount:=y1 to y2 do
  400. { compare if we should plot a pixel here , compare }
  401. { with predefined line patterns... }
  402. if LinePatterns[PixelCount and 15] = TRUE then
  403. begin
  404. DirectPutPixel(x1,PixelCount);
  405. end;
  406. end
  407. else
  408. Begin
  409. for i:=-1 to 1 do
  410. Begin
  411. for PixelCount:=y1 to y2 do
  412. { compare if we should plot a pixel here , compare }
  413. { with predefined line patterns... }
  414. if LinePatterns[PixelCount and 15] = TRUE then
  415. begin
  416. DirectPutPixelClip(x1+i,PixelCount);
  417. end;
  418. end;
  419. end;
  420. end
  421. else
  422. Begin
  423. oldCurrentColor := CurrentColor;
  424. { Calculate deltax and deltay for initialisation }
  425. deltax := abs(x2 - x1);
  426. deltay := abs(y2 - y1);
  427. { Initialize all vars based on which is the independent variable }
  428. if deltax >= deltay then
  429. begin
  430. Flag := FALSE;
  431. { x is independent variable }
  432. numpixels := deltax + 1;
  433. d := (2 * deltay) - deltax;
  434. dinc1 := deltay Shl 1;
  435. dinc2 := (deltay - deltax) shl 1;
  436. xinc1 := 1;
  437. xinc2 := 1;
  438. yinc1 := 0;
  439. yinc2 := 1;
  440. end
  441. else
  442. begin
  443. Flag := TRUE;
  444. { y is independent variable }
  445. numpixels := deltay + 1;
  446. d := (2 * deltax) - deltay;
  447. dinc1 := deltax Shl 1;
  448. dinc2 := (deltax - deltay) shl 1;
  449. xinc1 := 0;
  450. xinc2 := 1;
  451. yinc1 := 1;
  452. yinc2 := 1;
  453. end;
  454. { Make sure x and y move in the right directions }
  455. if x1 > x2 then
  456. begin
  457. xinc1 := - xinc1;
  458. xinc2 := - xinc2;
  459. end;
  460. if y1 > y2 then
  461. begin
  462. yinc1 := - yinc1;
  463. yinc2 := - yinc2;
  464. end;
  465. { Start drawing at <x1, y1> }
  466. x := x1;
  467. y := y1;
  468. If LineInfo.Thickness=ThickWidth then
  469. Begin
  470. TmpNumPixels := NumPixels-1;
  471. { Draw the pixels }
  472. for i := 0 to TmpNumPixels do
  473. begin
  474. { all depending on the slope, we can determine }
  475. { in what direction the extra width pixels will be put }
  476. If Flag then
  477. Begin
  478. { compare if we should plot a pixel here , compare }
  479. { with predefined line patterns... }
  480. if LinePatterns[i and 15] = TRUE then
  481. begin
  482. DirectPutPixelClip(x-1,y);
  483. DirectPutPixelClip(x,y);
  484. DirectPutPixelClip(x+1,y);
  485. end;
  486. end
  487. else
  488. Begin
  489. { compare if we should plot a pixel here , compare }
  490. { with predefined line patterns... }
  491. if LinePatterns[i and 15] = TRUE then
  492. begin
  493. DirectPutPixelClip(x,y-1);
  494. DirectPutPixelClip(x,y);
  495. DirectPutPixelClip(x,y+1);
  496. end;
  497. end;
  498. if d < 0 then
  499. begin
  500. d := d + dinc1;
  501. x := x + xinc1;
  502. y := y + yinc1;
  503. end
  504. else
  505. begin
  506. d := d + dinc2;
  507. x := x + xinc2;
  508. y := y + yinc2;
  509. end;
  510. end;
  511. end
  512. else
  513. Begin
  514. { instead of putting in loop , substract by one now }
  515. TmpNumPixels := NumPixels-1;
  516. { NormWidth }
  517. for i := 0 to TmpNumPixels do
  518. begin
  519. if LinePatterns[i and 15] = TRUE then
  520. begin
  521. DirectPutPixel(x,y);
  522. end;
  523. if d < 0 then
  524. begin
  525. d := d + dinc1;
  526. x := x + xinc1;
  527. y := y + yinc1;
  528. end
  529. else
  530. begin
  531. d := d + dinc2;
  532. x := x + xinc2;
  533. y := y + yinc2;
  534. end;
  535. end;
  536. end
  537. end;
  538. {******************************************}
  539. { end patterned lines }
  540. {******************************************}
  541. { restore color }
  542. CurrentColor:=OldCurrentColor;
  543. end;
  544. end; { Line }
  545. {********************************************************}
  546. { Procedure DummyPatternLine() }
  547. {--------------------------------------------------------}
  548. { This is suimply an procedure that does nothing which }
  549. { can be passed as a patternlineproc for non-filled }
  550. { ellipses }
  551. {********************************************************}
  552. Procedure DummyPatternLine(x1, x2, y: smallint); {$ifdef tp} far; {$endif tp}
  553. begin
  554. end;
  555. {********************************************************}
  556. { Procedure InternalEllipse() }
  557. {--------------------------------------------------------}
  558. { This routine first calculates all points required to }
  559. { draw a circle to the screen, and stores the points }
  560. { to display in a buffer before plotting them. The }
  561. { aspect ratio of the screen is taken into account when }
  562. { calculating the values. }
  563. {--------------------------------------------------------}
  564. { INPUTS: X,Y : Center coordinates of Ellipse. }
  565. { XRadius - X-Axis radius of ellipse. }
  566. { YRadius - Y-Axis radius of ellipse. }
  567. { stAngle, EndAngle: Start angle and end angles of the }
  568. { ellipse (used for partial ellipses and circles) }
  569. { pl: procedure which either draws a patternline (for }
  570. { FillEllipse) or does nothing (arc etc) }
  571. {--------------------------------------------------------}
  572. { NOTE: - }
  573. { - }
  574. {********************************************************}
  575. Procedure InternalEllipseDefault(X,Y: smallint;XRadius: word;
  576. YRadius:word; stAngle,EndAngle: word; pl: PatternLineProc); {$ifndef fpc}far;{$endif fpc}
  577. Const ConvFac = Pi/180.0;
  578. var
  579. j, Delta, DeltaEnd: graph_float;
  580. NumOfPixels: longint;
  581. TempTerm: graph_float;
  582. xtemp, ytemp, xp, yp, xm, ym, xnext, ynext,
  583. plxpyp, plxmyp, plxpym, plxmym: smallint;
  584. BackupColor, TmpAngle, OldLineWidth: word;
  585. Begin
  586. If LineInfo.ThickNess = ThickWidth Then
  587. { first draw the two outer ellipses using normwidth and no filling (JM) }
  588. Begin
  589. OldLineWidth := LineInfo.Thickness;
  590. LineInfo.Thickness := NormWidth;
  591. InternalEllipseDefault(x,y,XRadius,YRadius,StAngle,EndAngle,
  592. {$ifdef fpc}@{$endif fpc}DummyPatternLine);
  593. InternalEllipseDefault(x,y,XRadius+1,YRadius+1,StAngle,EndAngle,
  594. {$ifdef fpc}@{$endif fpc}DummyPatternLine);
  595. If (XRadius > 0) and (YRadius > 0) Then
  596. { draw the smallest ellipse last, since that one will use the }
  597. { original pl, so it could possibly draw patternlines (JM) }
  598. Begin
  599. Dec(XRadius);
  600. Dec(YRadius);
  601. End
  602. Else Exit;
  603. { restore line thickness }
  604. LineInfo.Thickness := OldLineWidth;
  605. End;
  606. { Adjust for screen aspect ratio }
  607. XRadius:=(longint(XRadius)*10000) div XAspect;
  608. YRadius:=(longint(YRadius)*10000) div YAspect;
  609. If xradius = 0 then inc(xradius);
  610. if yradius = 0 then inc(yradius);
  611. { check for an ellipse with negligable x and y radius }
  612. If (xradius <= 1) and (yradius <= 1) then
  613. begin
  614. putpixel(x,y,CurrentColor);
  615. ArcCall.X := X;
  616. ArcCall.Y := Y;
  617. ArcCall.XStart := X;
  618. ArcCall.YStart := Y;
  619. ArcCall.XEnd := X;
  620. ArcCall.YEnd := Y;
  621. exit;
  622. end;
  623. { check if valid angles }
  624. stangle := stAngle mod 361;
  625. EndAngle := EndAngle mod 361;
  626. { if impossible angles then swap them! }
  627. if Endangle < StAngle then
  628. Begin
  629. TmpAngle:=EndAngle;
  630. EndAngle:=StAngle;
  631. Stangle:=TmpAngle;
  632. end;
  633. { approximate the number of pixels required by using the circumference }
  634. { equation of an ellipse. }
  635. { Changed this formula a it (trial and error), but the net result is that }
  636. { less pixels have to be calculated now }
  637. NumOfPixels:=Round(Sqrt(3)*sqrt(sqr(XRadius)+sqr(YRadius)));
  638. { Calculate the angle precision required }
  639. Delta := 90.0 / NumOfPixels;
  640. { for restoring after PatternLine }
  641. BackupColor := CurrentColor;
  642. { removed from inner loop to make faster }
  643. { store some arccall info }
  644. ArcCall.X := X;
  645. ArcCall.Y := Y;
  646. TempTerm := (StAngle)*ConvFac;
  647. ArcCall.XStart := round(XRadius*Cos(TempTerm)) + X;
  648. ArcCall.YStart := round(YRadius*Sin(TempTerm+Pi)) + Y;
  649. TempTerm := (EndAngle)*ConvFac;
  650. ArcCall.XEnd := round(XRadius*Cos(TempTerm)) + X;
  651. ArcCall.YEnd := round(YRadius*Sin(TempTerm+Pi)) + Y;
  652. { Always just go over the first 90 degrees. Could be optimized a }
  653. { bit if StAngle and EndAngle lie in the same quadrant, left as an }
  654. { exercise for the reader :) (JM) }
  655. j := 0;
  656. { calculate stop position, go 1 further than 90 because otherwise }
  657. { 1 pixel is sometimes not drawn (JM) }
  658. DeltaEnd := 91;
  659. { Calculate points }
  660. xnext := XRadius;
  661. ynext := 0;
  662. Repeat
  663. xtemp := xnext;
  664. ytemp := ynext;
  665. { this is used by both sin and cos }
  666. TempTerm := (j+Delta)*ConvFac;
  667. { Calculate points }
  668. xnext := round(XRadius*Cos(TempTerm));
  669. ynext := round(YRadius*Sin(TempTerm+Pi));
  670. xp := x + xtemp;
  671. xm := x - xtemp;
  672. yp := y + ytemp;
  673. ym := y - ytemp;
  674. plxpyp := maxsmallint;
  675. plxmyp := -maxsmallint-1;
  676. plxpym := maxsmallint;
  677. plxmym := -maxsmallint-1;
  678. If (j >= StAngle) and (j <= EndAngle) then
  679. begin
  680. plxpyp := xp;
  681. PutPixel(xp,yp,CurrentColor);
  682. end;
  683. If ((180-j) >= StAngle) and ((180-j) <= EndAngle) then
  684. begin
  685. plxmyp := xm;
  686. PutPixel(xm,yp,CurrentColor);
  687. end;
  688. If ((j+180) >= StAngle) and ((j+180) <= EndAngle) then
  689. begin
  690. plxmym := xm;
  691. PutPixel(xm,ym,CurrentColor);
  692. end;
  693. If ((360-j) >= StAngle) and ((360-j) <= EndAngle) then
  694. begin
  695. plxpym := xp;
  696. PutPixel(xp,ym,CurrentColor);
  697. end;
  698. If (ynext <> ytemp) and
  699. (xp - xm >= 1) then
  700. begin
  701. CurrentColor := FillSettings.Color;
  702. pl(plxmyp+1,plxpyp-1,yp);
  703. pl(plxmym+1,plxpym-1,ym);
  704. CurrentColor := BackupColor;
  705. end;
  706. j:=j+Delta;
  707. Until j > (DeltaEnd);
  708. end;
  709. {********************************************************}
  710. { Procedure InternalEllipse() }
  711. {--------------------------------------------------------}
  712. { This routine first calculates all points required to }
  713. { draw a circle to the screen, and stores the points }
  714. { to display in a buffer before plotting them. The }
  715. { aspect ratio of the screen is taken into account when }
  716. { calculating the values. }
  717. {--------------------------------------------------------}
  718. { INPUTS: X,Y : Center coordinates of Ellipse. }
  719. { XRadius - X-Axis radius of ellipse. }
  720. { YRadius - Y-Axis radius of ellipse. }
  721. { stAngle, EndAngle: Start angle and end angles of the }
  722. { ellipse (used for partial ellipses and circles) }
  723. {--------------------------------------------------------}
  724. { NOTE: - uses the current write mode. }
  725. { - Angles must both be between 0 and 360 }
  726. {********************************************************}
  727. (*
  728. Procedure InternalEllipseDefault (x, y : smallint;
  729. xradius, yradius, stAngle, EndAngle : Word; pl: PatternLineProc); {$ifndef fpc} far; {$endif fpc}
  730. { Draw an ellipse arc. Crude but it works (anyone have a better one?) }
  731. Var
  732. aSqr, bSqr, twoaSqr, twobSqr, xa, ya, twoXbSqr, twoYaSqr, error : LongInt;
  733. Alpha, TempTerm : graph_float;
  734. BackupColor: Word;
  735. plxpyp, plxmyp, plxpym, plxmym: smallint;
  736. const
  737. RadToDeg = 180/Pi;
  738. Procedure PlotPoints;
  739. var
  740. i,j: smallint;
  741. xm, ym: smallint;
  742. xp, yp: smallint;
  743. Begin
  744. ym := y-ya;
  745. yp := y+ya;
  746. xm := x-xa;
  747. xp := x+xa;
  748. plxpyp := maxsmallint;
  749. plxmyp := -maxsmallint-1;
  750. plxpym := maxsmallint;
  751. plxmym := -maxsmallint-1;
  752. if LineInfo.Thickness = Normwidth then
  753. Begin
  754. If (Alpha+270>=StAngle) And (Alpha+270<=EndAngle) then
  755. Begin
  756. plxmym := xm;
  757. PutPixel (xm,ym, CurrentColor);
  758. End;
  759. If ((180+270)-Alpha>=StAngle) And ((180+270)-Alpha<=EndAngle) then
  760. Begin
  761. plxmyp := xm;
  762. PutPixel (xm,yp, CurrentColor);
  763. End;
  764. If ((180+270)+Alpha>=StAngle) And ((180+270)+Alpha<=EndAngle) then
  765. Begin
  766. plxpyp := xp;
  767. PutPixel (xp,yp, CurrentColor);
  768. End;
  769. If ((360+270)-Alpha>=StAngle) And ((360+270)-Alpha<=EndAngle) then
  770. Begin
  771. plxpym := xp;
  772. PutPixel (xp,ym, CurrentColor);
  773. End;
  774. end
  775. else
  776. Begin
  777. If (Alpha+270>=StAngle) And (Alpha+270<=EndAngle) then
  778. Begin
  779. plxmym := xm + 1;
  780. for i:=-1 to 1 do
  781. for j:=-1 to 1 do
  782. PutPixel (xm+i,ym+j, CurrentColor);
  783. End;
  784. If ((180+270)-Alpha>=StAngle) And ((180+270)-Alpha<=EndAngle) then
  785. Begin
  786. plxmyp := xm + 1;
  787. for i:=-1 to 1 do
  788. for j:=-1 to 1 do
  789. PutPixel (xm+i,yp+j, CurrentColor);
  790. End;
  791. If ((180+270)+Alpha>=StAngle) And ((180+270)+Alpha<=EndAngle) then
  792. Begin
  793. plxpyp := xp - 1;
  794. for i:=-1 to 1 do
  795. for j:=-1 to 1 do
  796. PutPixel (xp+i,yp+j, CurrentColor);
  797. End;
  798. If ((360+270)-Alpha>=StAngle) And ((360+270)-Alpha<=EndAngle) then
  799. Begin
  800. plxpym := xp - 1;
  801. for i:=-1 to 1 do
  802. for j:=-1 to 1 do
  803. PutPixel (xp+i,ym+j, CurrentColor);
  804. End;
  805. end;
  806. If (xp <> xm) then
  807. begin
  808. CurrentColor := FillSettings.Color;
  809. pl(plxmyp+1,plxpyp-1,yp);
  810. pl(plxmym+1,plxpym-1,ym);
  811. CurrentColor := BackupColor;
  812. end;
  813. End;
  814. Begin
  815. { check for an ellipse with negligable x and y radius }
  816. If (xradius <= 1) and (yradius <= 1) then
  817. begin
  818. putpixel(x,y,CurrentColor);
  819. ArcCall.X := X;
  820. ArcCall.Y := Y;
  821. ArcCall.XStart := X;
  822. ArcCall.YStart := Y;
  823. ArcCall.XEnd := X;
  824. ArcCall.YEnd := Y;
  825. exit;
  826. end;
  827. { for restoring after PatternLine }
  828. BackupColor := CurrentColor;
  829. If xradius = 0 then inc(xradius);
  830. if yradius = 0 then inc(yradius);
  831. { store arccall info }
  832. ArcCall.x := x;
  833. ArcCall.y := y;
  834. TempTerm := StAngle*RadToDeg;
  835. ArcCall.XStart := round(XRadius*Cos(TempTerm)) + X;
  836. ArcCall.YStart := round(YRadius*Sin(TempTerm+Pi)) + Y;
  837. TempTerm := EndAngle*RadToDeg;
  838. ArcCall.XEnd := round(XRadius*Cos(TempTerm)) + X;
  839. ArcCall.YEnd := round(YRadius*Sin(TempTerm+Pi)) + Y;
  840. StAngle:=StAngle MOD 361;
  841. EndAngle:=EndAngle MOD 361;
  842. StAngle := StAngle + 270;
  843. EndAngle := EndAngle + 270;
  844. If StAngle>EndAngle then
  845. Begin
  846. StAngle:=StAngle Xor EndAngle; EndAngle:=EndAngle Xor StAngle; StAngle:=EndAngle Xor StAngle;
  847. End;
  848. { Adjust for screen aspect ratio }
  849. XRadius:=(longint(XRadius)*10000) div XAspect;
  850. YRadius:=(longint(YRadius)*10000) div YAspect;
  851. aSqr:=LongInt (xradius)*LongInt (xradius);
  852. bSqr:=LongInt (yradius)*LongInt (yradius);
  853. twoaSqr:=2*aSqr;
  854. twobSqr:=2*bSqr;
  855. xa:=0;
  856. ya:=yradius;
  857. twoXbSqr:=0;
  858. twoYaSqr:=ya*twoaSqr;
  859. error:=-ya*aSqr;
  860. While twoXbSqr<=twoYaSqr Do Begin
  861. If ya=0 then Alpha:=90 Else Alpha:=RadToDeg*Arctan (xa/ya); { Crude but it works }
  862. PlotPoints;
  863. Inc (xa);
  864. Inc (twoXbSqr,twobSqr);
  865. Inc (error,twoXbSqr-bSqr);
  866. If error>=0 then Begin
  867. Dec (ya);
  868. Dec (twoYaSqr,twoaSqr);
  869. Dec (error,twoYaSqr);
  870. End;
  871. End;
  872. xa:=xradius;
  873. ya:=0;
  874. twoXbSqr:=xa*twobSqr;
  875. twoYaSqr:=0;
  876. error:=-xa*bSqr;
  877. While twoXbSqr>twoYaSqr Do Begin
  878. If ya=0 then Alpha:=90 Else Alpha:=RadToDeg*Arctan (xa/ya);
  879. PlotPoints;
  880. Inc (ya);
  881. Inc (twoYaSqr,twoaSqr);
  882. Inc (error,twoYaSqr-aSqr);
  883. If error>=0 then Begin
  884. Dec (xa);
  885. Dec (twoXbSqr,twobSqr);
  886. Dec (error,twoXbSqr);
  887. End;
  888. End;
  889. End;
  890. *)
  891. procedure PatternLineDefault(x1,x2,y: smallint); {$ifndef fpc}far;{$endif fpc}
  892. {********************************************************}
  893. { Draws a horizontal patterned line according to the }
  894. { current Fill Settings. }
  895. {********************************************************}
  896. { Important notes: }
  897. { - CurrentColor must be set correctly before entering }
  898. { this routine. }
  899. {********************************************************}
  900. var
  901. NrIterations: smallint;
  902. i : smallint;
  903. j : smallint;
  904. TmpFillPattern : byte;
  905. OldWriteMode : word;
  906. OldCurrentColor : word;
  907. begin
  908. { convert to global coordinates ... }
  909. x1 := x1 + StartXViewPort;
  910. x2 := x2 + StartXViewPort;
  911. y := y + StartYViewPort;
  912. { if line was fully clipped then exit...}
  913. if LineClipped(x1,y,x2,y,StartXViewPort,StartYViewPort,
  914. StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
  915. exit;
  916. OldWriteMode := CurrentWriteMode;
  917. CurrentWriteMode := NormalPut;
  918. { Get the current pattern }
  919. TmpFillPattern := FillPatternTable
  920. [FillSettings.Pattern][(y and $7)+1];
  921. Case TmpFillPattern Of
  922. 0:
  923. begin
  924. OldCurrentColor := CurrentColor;
  925. CurrentColor := CurrentBkColor;
  926. { hline converts the coordinates to global ones, but that has been done }
  927. { already here!!! Convert them back to local ones... (JM) }
  928. HLine(x1-StartXViewPort,x2-StartXViewPort,y-StartYViewPort);
  929. CurrentColor := OldCurrentColor;
  930. end;
  931. $ff:
  932. begin
  933. HLine(x1-StartXViewPort,x2-StartXViewPort,y-StartYViewPort);
  934. end;
  935. else
  936. begin
  937. { number of times to go throuh the 8x8 pattern }
  938. NrIterations := abs(x2 - x1+8) div 8;
  939. For i:= 0 to NrIterations do
  940. Begin
  941. for j:=0 to 7 do
  942. Begin
  943. { x1 mod 8 }
  944. if RevBitArray[x1 and 7] and TmpFillPattern <> 0 then
  945. DirectPutpixel(x1,y)
  946. else
  947. begin
  948. { According to the TP graph manual, we overwrite everything }
  949. { which is filled up - checked against VGA and CGA drivers }
  950. { of TP. }
  951. OldCurrentColor := CurrentColor;
  952. CurrentColor := CurrentBkColor;
  953. DirectPutPixel(x1,y);
  954. CurrentColor := OldCurrentColor;
  955. end;
  956. Inc(x1);
  957. if x1 > x2 then
  958. begin
  959. CurrentWriteMode := OldWriteMode;
  960. exit;
  961. end;
  962. end;
  963. end;
  964. end;
  965. End;
  966. CurrentWriteMode := OldWriteMode;
  967. end;
  968. procedure LineRel(Dx, Dy: smallint);
  969. Begin
  970. Line(CurrentX, CurrentY, CurrentX + Dx, CurrentY + Dy);
  971. CurrentX := CurrentX + Dx;
  972. CurrentY := CurrentY + Dy;
  973. end;
  974. procedure LineTo(x,y : smallint);
  975. Begin
  976. Line(CurrentX, CurrentY, X, Y);
  977. CurrentX := X;
  978. CurrentY := Y;
  979. end;
  980. procedure Rectangle(x1,y1,x2,y2:smallint);
  981. begin
  982. { Do not draw the end points }
  983. Line(x1,y1,x2-1,y1);
  984. Line(x1,y1+1,x1,y2);
  985. Line(x2,y1,x2,y2-1);
  986. Line(x1+1,y2,x2,y2);
  987. end;
  988. procedure GetLineSettings(var ActiveLineInfo : LineSettingsType);
  989. begin
  990. Activelineinfo:=Lineinfo;
  991. end;
  992. procedure SetLineStyle(LineStyle: word; Pattern: word; Thickness: word);
  993. var
  994. i: byte;
  995. j: byte;
  996. Begin
  997. if (LineStyle > UserBitLn) or ((Thickness <> Normwidth) and (Thickness <> ThickWidth)) then
  998. _GraphResult := grError
  999. else
  1000. begin
  1001. LineInfo.Thickness := Thickness;
  1002. LineInfo.LineStyle := LineStyle;
  1003. case LineStyle of
  1004. UserBitLn: Lineinfo.Pattern := pattern;
  1005. SolidLn: Lineinfo.Pattern := $ffff; { ------- }
  1006. DashedLn : Lineinfo.Pattern := $F8F8; { -- -- --}
  1007. DottedLn: LineInfo.Pattern := $CCCC; { - - - - }
  1008. CenterLn: LineInfo.Pattern := $FC78; { -- - -- }
  1009. end; { end case }
  1010. { setup pattern styles }
  1011. j:=16;
  1012. for i:=0 to 15 do
  1013. Begin
  1014. dec(j);
  1015. { bitwise mask for each bit in the word }
  1016. if (word($01 shl i) AND LineInfo.Pattern) <> 0 then
  1017. LinePatterns[j]:=TRUE
  1018. else
  1019. LinePatterns[j]:=FALSE;
  1020. end;
  1021. end;
  1022. end;
  1023. {--------------------------------------------------------------------------}
  1024. { }
  1025. { VIEWPORT RELATED ROUTINES }
  1026. { }
  1027. {--------------------------------------------------------------------------}
  1028. Procedure ClearViewPortDefault; {$ifndef fpc}far;{$endif fpc}
  1029. var
  1030. j: smallint;
  1031. OldWriteMode, OldCurColor: word;
  1032. LineSets : LineSettingsType;
  1033. Begin
  1034. { CP is always RELATIVE coordinates }
  1035. CurrentX := 0;
  1036. CurrentY := 0;
  1037. { Save all old settings }
  1038. OldCurColor := CurrentColor;
  1039. CurrentColor:=CurrentBkColor;
  1040. OldWriteMode:=CurrentWriteMode;
  1041. CurrentWriteMode:=NormalPut;
  1042. GetLineSettings(LineSets);
  1043. { reset to normal line style...}
  1044. SetLineStyle(SolidLn, 0, NormWidth);
  1045. { routines are relative here...}
  1046. { ViewHeight is Height-1 ! }
  1047. for J:=0 to ViewHeight do
  1048. HLine(0, ViewWidth , J);
  1049. { restore old settings...}
  1050. SetLineStyle(LineSets.LineStyle, LineSets.Pattern, LineSets.Thickness);
  1051. CurrentColor := OldCurColor;
  1052. CurrentWriteMode := OldWriteMode;
  1053. end;
  1054. Procedure SetViewPort(X1, Y1, X2, Y2: smallint; Clip: Boolean);
  1055. Begin
  1056. if (X1 > GetMaxX) or (X2 > GetMaxX) or (X1 > X2) or (X1 < 0) then
  1057. Begin
  1058. {$ifdef logging}
  1059. logln('invalid setviewport parameters: ('
  1060. +strf(x1)+','+strf(y1)+'), ('+strf(x2)+','+strf(y2)+')');
  1061. logln('maxx = '+strf(getmaxx)+', maxy = '+strf(getmaxy));
  1062. {$endif logging}
  1063. _GraphResult := grError;
  1064. exit;
  1065. end;
  1066. if (Y1 > GetMaxY) or (Y2 > GetMaxY) or (Y1 > Y2) or (Y1 < 0) then
  1067. Begin
  1068. {$ifdef logging}
  1069. logln('invalid setviewport parameters: ('
  1070. +strf(x1)+','+strf(y1)+'), ('+strf(x2)+','+strf(y2)+')');
  1071. logln('maxx = '+strf(getmaxx)+', maxy = '+strf(getmaxy));
  1072. {$endif logging}
  1073. _GraphResult := grError;
  1074. exit;
  1075. end;
  1076. { CP is always RELATIVE coordinates }
  1077. CurrentX := 0;
  1078. CurrentY := 0;
  1079. StartXViewPort := X1;
  1080. StartYViewPort := Y1;
  1081. ViewWidth := X2-X1;
  1082. ViewHeight:= Y2-Y1;
  1083. ClipPixels := Clip;
  1084. end;
  1085. procedure GetViewSettings(var viewport : ViewPortType);
  1086. begin
  1087. ViewPort.X1 := StartXViewPort;
  1088. ViewPort.Y1 := StartYViewPort;
  1089. ViewPort.X2 := ViewWidth + StartXViewPort;
  1090. ViewPort.Y2 := ViewHeight + StartYViewPort;
  1091. ViewPort.Clip := ClipPixels;
  1092. end;
  1093. procedure ClearDevice;
  1094. var
  1095. ViewPort: ViewPortType;
  1096. begin
  1097. { Reset the CP }
  1098. CurrentX := 0;
  1099. CurrentY := 0;
  1100. { save viewport }
  1101. ViewPort.X1 := StartXviewPort;
  1102. ViewPort.X2 := ViewWidth - StartXViewPort;
  1103. ViewPort.Y1 := StartYViewPort;
  1104. ViewPort.Y2 := ViewHeight - StartYViewPort;
  1105. ViewPort.Clip := ClipPixels;
  1106. { put viewport to full screen }
  1107. StartXViewPort := 0;
  1108. ViewHeight := MaxY;
  1109. StartYViewPort := 0;
  1110. ViewWidth := MaxX;
  1111. ClipPixels := TRUE;
  1112. ClearViewPort;
  1113. { restore old viewport }
  1114. StartXViewPort := ViewPort.X1;
  1115. ViewWidth := ViewPort.X2-ViewPort.X1;
  1116. StartYViewPort := ViewPort.Y1;
  1117. ViewHeight := ViewPort.Y2-ViewPort.Y1;
  1118. ClipPixels := ViewPort.Clip;
  1119. end;
  1120. {--------------------------------------------------------------------------}
  1121. { }
  1122. { BITMAP PUT/GET ROUTINES }
  1123. { }
  1124. {--------------------------------------------------------------------------}
  1125. Procedure GetScanlineDefault (X1, X2, Y : smallint; Var Data); {$ifndef fpc}far;{$endif fpc}
  1126. {**********************************************************}
  1127. { Procedure GetScanLine() }
  1128. {----------------------------------------------------------}
  1129. { Returns the full scanline of the video line of the Y }
  1130. { coordinate. The values are returned in a WORD array }
  1131. { each WORD representing a pixel of the specified scanline }
  1132. { note: we only need the pixels inside the ViewPort! (JM) }
  1133. { note2: extended so you can specify start and end X coord }
  1134. { so it is usable for GetImage too (JM) }
  1135. {**********************************************************}
  1136. Var
  1137. x : smallint;
  1138. Begin
  1139. For x:=X1 to X2 Do
  1140. WordArray(Data)[x-x1]:=GetPixel(x, y);
  1141. End;
  1142. Function DefaultImageSize(X1,Y1,X2,Y2: smallint): longint; {$ifndef fpc}far;{$endif fpc}
  1143. Begin
  1144. { each pixel uses two bytes, to enable modes with colors up to 64K }
  1145. { to work. }
  1146. DefaultImageSize := 12 + (((X2-X1+1)*(Y2-Y1+1))*2);
  1147. end;
  1148. Procedure DefaultPutImage(X,Y: smallint; var Bitmap; BitBlt: Word); {$ifndef fpc}far;{$endif fpc}
  1149. type
  1150. pt = array[0..$fffffff] of word;
  1151. ptw = array[0..2] of longint;
  1152. var
  1153. k: longint;
  1154. oldCurrentColor: word;
  1155. oldCurrentWriteMode, i, j, y1, x1, deltaX, deltaX1, deltaY: smallint;
  1156. Begin
  1157. {$ifdef logging}
  1158. LogLn('putImage at ('+strf(x)+','+strf(y)+') with width '+strf(ptw(Bitmap)[0])+
  1159. ' and height '+strf(ptw(Bitmap)[1]));
  1160. deltaY := 0;
  1161. {$endif logging}
  1162. inc(x,startXViewPort);
  1163. inc(y,startYViewPort);
  1164. x1 := ptw(Bitmap)[0]+x; { get width and adjust end coordinate accordingly }
  1165. y1 := ptw(Bitmap)[1]+y; { get height and adjust end coordinate accordingly }
  1166. deltaX := 0;
  1167. deltaX1 := 0;
  1168. k := 3 * sizeOf(Longint) div sizeOf(Word); { Three reserved longs at start of bitmap }
  1169. { check which part of the image is in the viewport }
  1170. if clipPixels then
  1171. begin
  1172. if y < startYViewPort then
  1173. begin
  1174. deltaY := startYViewPort - y;
  1175. inc(k,(x1-x+1)*deltaY);
  1176. y := startYViewPort;
  1177. end;
  1178. if y1 > startYViewPort+viewHeight then
  1179. y1 := startYViewPort+viewHeight;
  1180. if x < startXViewPort then
  1181. begin
  1182. deltaX := startXViewPort-x;
  1183. x := startXViewPort;
  1184. end;
  1185. if x1 > startXViewPort + viewWidth then
  1186. begin
  1187. deltaX1 := x1 - (startXViewPort + viewWidth);
  1188. x1 := startXViewPort + viewWidth;
  1189. end;
  1190. end;
  1191. {$ifdef logging}
  1192. LogLn('deltax: '+strf(deltax)+', deltax1: '+strf(deltax1)+',deltay: '+strf(deltay));
  1193. {$endif logging}
  1194. oldCurrentColor := currentColor;
  1195. oldCurrentWriteMode := currentWriteMode;
  1196. currentWriteMode := bitBlt;
  1197. for j:=Y to Y1 do
  1198. Begin
  1199. inc(k,deltaX);
  1200. for i:=X to X1 do
  1201. begin
  1202. currentColor := pt(bitmap)[k];
  1203. directPutPixel(i,j);
  1204. inc(k);
  1205. end;
  1206. inc(k,deltaX1);
  1207. end;
  1208. currentWriteMode := oldCurrentWriteMode;
  1209. currentColor := oldCurrentColor;
  1210. end;
  1211. Procedure DefaultGetImage(X1,Y1,X2,Y2: smallint; Var Bitmap); {$ifndef fpc}far;{$endif fpc}
  1212. type
  1213. pt = array[0..$fffffff] of word;
  1214. ptw = array[0..2] of longint;
  1215. var
  1216. i,j: smallint;
  1217. k: longint;
  1218. Begin
  1219. k:= 3 * Sizeof(longint) div sizeof(word); { Three reserved longs at start of bitmap }
  1220. i := x2 - x1 + 1;
  1221. for j:=Y1 to Y2 do
  1222. Begin
  1223. GetScanLine(x1,x2,j,pt(Bitmap)[k]);
  1224. inc(k,i);
  1225. end;
  1226. ptw(Bitmap)[0] := X2-X1; { First longint is width }
  1227. ptw(Bitmap)[1] := Y2-Y1; { Second longint is height }
  1228. ptw(bitmap)[2] := 0; { Third longint is reserved}
  1229. end;
  1230. Procedure GetArcCoords(var ArcCoords: ArcCoordsType);
  1231. Begin
  1232. ArcCoords.X := ArcCall.X;
  1233. ArcCoords.Y := ArcCall.Y;
  1234. ArcCoords.XStart := ArcCall.XStart;
  1235. ArcCoords.YStart := ArcCall.YStart;
  1236. ArcCoords.XEnd := ArcCall.XEnd;
  1237. ArcCoords.YEnd := ArcCall.YEnd;
  1238. end;
  1239. procedure SetVisualPageDefault(page : word); {$ifndef fpc}far;{$endif fpc}
  1240. begin
  1241. end;
  1242. procedure SetActivePageDefault(page : word); {$ifndef fpc}far;{$endif fpc}
  1243. begin
  1244. end;
  1245. procedure DirectPutPixelDefault(X,Y: smallint);
  1246. begin
  1247. Writeln(stderr,'Error: Not in graphics mode (use InitGraph and test GraphResult afterwards)');
  1248. Halt(1);
  1249. end;
  1250. function GetPixelDefault(X,Y: smallint): word;
  1251. begin
  1252. Writeln(stderr,'Error: Not in graphics mode (use InitGraph and test GraphResult afterwards)');
  1253. Halt(1);
  1254. exit(0); { avoid warning }
  1255. end;
  1256. procedure PutPixelDefault(X,Y: smallint; Color: Word);
  1257. begin
  1258. Writeln(stderr,'Error: Not in graphics mode (use InitGraph and test GraphResult afterwards)');
  1259. Halt(1);
  1260. end;
  1261. procedure SetRGBPaletteDefault(ColorNum, RedValue, GreenValue, BlueValue: smallint);
  1262. begin
  1263. Writeln(stderr,'Error: Not in graphics mode (use InitGraph and test GraphResult afterwards)');
  1264. Halt(1);
  1265. end;
  1266. procedure GetRGBPaletteDefault(ColorNum: smallint; var
  1267. RedValue, GreenValue, BlueValue: smallint);
  1268. begin
  1269. Writeln(stderr,'Error: Not in graphics mode (use InitGraph and test GraphResult afterwards)');
  1270. Halt(1);
  1271. end;
  1272. procedure OutTextXYDefault(x,y : smallint;const TextString : string);forward;
  1273. procedure CircleDefault(X, Y: smallint; Radius:Word);forward;
  1274. Procedure DefaultHooks;
  1275. {********************************************************}
  1276. { Procedure DefaultHooks() }
  1277. {--------------------------------------------------------}
  1278. { Resets all hookable routine either to nil for those }
  1279. { which need overrides, and others to defaults. }
  1280. { This is called each time SetGraphMode() is called. }
  1281. {********************************************************}
  1282. Begin
  1283. { All default hooks procedures }
  1284. { required...}
  1285. DirectPutPixel := {$ifdef fpc}@{$endif}DirectPutPixelDefault;
  1286. PutPixel := {$ifdef fpc}@{$endif}PutPixelDefault;
  1287. GetPixel := {$ifdef fpc}@{$endif}GetPixelDefault;
  1288. SetRGBPalette := {$ifdef fpc}@{$endif}SetRGBPaletteDefault;
  1289. GetRGBPalette := {$ifdef fpc}@{$endif}GetRGBPaletteDefault;
  1290. { optional...}
  1291. SetActivePage := {$ifdef fpc}@{$endif}SetActivePageDefault;
  1292. SetVisualPage := {$ifdef fpc}@{$endif}SetVisualPageDefault;
  1293. ClearViewPort := {$ifdef fpc}@{$endif}ClearViewportDefault;
  1294. PutImage := {$ifdef fpc}@{$endif}DefaultPutImage;
  1295. GetImage := {$ifdef fpc}@{$endif}DefaultGetImage;
  1296. ImageSize := {$ifdef fpc}@{$endif}DefaultImageSize;
  1297. GraphFreeMemPtr := nil;
  1298. GraphGetMemPtr := nil;
  1299. GetScanLine := {$ifdef fpc}@{$endif}GetScanLineDefault;
  1300. Line := {$ifdef fpc}@{$endif}LineDefault;
  1301. InternalEllipse := {$ifdef fpc}@{$endif}InternalEllipseDefault;
  1302. PatternLine := {$ifdef fpc}@{$endif}PatternLineDefault;
  1303. HLine := {$ifdef fpc}@{$endif}HLineDefault;
  1304. VLine := {$ifdef fpc}@{$endif}VLineDefault;
  1305. OuttextXY := {$ifdef fpc}@{$endif}OuttextXYDefault;
  1306. Circle := {$ifdef fpc}@{$endif}CircleDefault;
  1307. end;
  1308. Procedure InitVars;
  1309. {********************************************************}
  1310. { Procedure InitVars() }
  1311. {--------------------------------------------------------}
  1312. { Resets all internal variables, and resets all }
  1313. { overridable routines. }
  1314. {********************************************************}
  1315. Begin
  1316. DirectVideo := TRUE; { By default use fastest access possible }
  1317. ArcCall.X := 0;
  1318. ArcCall.Y := 0;
  1319. ArcCall.XStart := 0;
  1320. ArcCall.YStart := 0;
  1321. ArcCall.XEnd := 0;
  1322. ArcCall.YEnd := 0;
  1323. { Reset to default values }
  1324. IntCurrentMode := 0;
  1325. IntCurrentDriver := 0;
  1326. IntCurrentNewDriver := 0;
  1327. XAspect := 0;
  1328. YAspect := 0;
  1329. MaxX := 0;
  1330. MaxY := 0;
  1331. MaxColor := 0;
  1332. PaletteSize := 0;
  1333. DirectColor := FALSE;
  1334. HardwarePages := 0;
  1335. if hardwarepages=0 then; { remove note }
  1336. DefaultHooks;
  1337. end;
  1338. {$i modes.inc}
  1339. {$i palette.inc}
  1340. function InstallUserDriver(Name: string; AutoDetectPtr: Pointer): smallint;
  1341. begin
  1342. _graphResult := grError;
  1343. InstallUserDriver:=grError;
  1344. end;
  1345. function RegisterBGIDriver(driver: pointer): smallint;
  1346. begin
  1347. _graphResult := grError;
  1348. RegisterBGIDriver:=grError;
  1349. end;
  1350. { ----------------------------------------------------------------- }
  1351. Procedure Arc(X,Y : smallint; StAngle,EndAngle,Radius: word);
  1352. { var
  1353. OldWriteMode: word;}
  1354. Begin
  1355. { Only if we are using thickwidths lines do we accept }
  1356. { XORput write modes. }
  1357. { OldWriteMode := CurrentWriteMode;
  1358. if (LineInfo.Thickness = NormWidth) then
  1359. CurrentWriteMode := NormalPut;}
  1360. InternalEllipse(X,Y,Radius,Radius,StAngle,Endangle,{$ifdef fpc}@{$endif}DummyPatternLine);
  1361. { CurrentWriteMode := OldWriteMode;}
  1362. end;
  1363. procedure Ellipse(X,Y : smallint; stAngle, EndAngle: word; XRadius,YRadius: word);
  1364. Begin
  1365. InternalEllipse(X,Y,XRadius,YRadius,StAngle,Endangle,{$ifdef fpc}@{$endif}DummyPatternLine);
  1366. end;
  1367. procedure FillEllipse(X, Y: smallint; XRadius, YRadius: Word);
  1368. {********************************************************}
  1369. { Procedure FillEllipse() }
  1370. {--------------------------------------------------------}
  1371. { Draws a filled ellipse using (X,Y) as a center point }
  1372. { and XRadius and YRadius as the horizontal and vertical }
  1373. { axes. The ellipse is filled with the current fill color}
  1374. { and fill style, and is bordered with the current color.}
  1375. {********************************************************}
  1376. begin
  1377. InternalEllipse(X,Y,XRadius,YRadius,0,360,PatternLine)
  1378. end;
  1379. procedure CircleDefault(X, Y: smallint; Radius:Word);
  1380. {********************************************************}
  1381. { Draws a circle centered at X,Y with the given Radius. }
  1382. {********************************************************}
  1383. { Important notes: }
  1384. { - Thickwidth circles use the current write mode, while}
  1385. { normal width circles ALWAYS use CopyPut/NormalPut }
  1386. { mode. (Tested against VGA BGI driver -CEC 13/Aug/99 }
  1387. {********************************************************}
  1388. var OriginalArcInfo: ArcCoordsType;
  1389. OldWriteMode: word;
  1390. begin
  1391. if (Radius = 0) then
  1392. Exit;
  1393. if (Radius = 1) then
  1394. begin
  1395. { only normal put mode is supported by a call to PutPixel }
  1396. PutPixel(X, Y, CurrentColor);
  1397. Exit;
  1398. end;
  1399. { save state of arc information }
  1400. { because it is not needed for }
  1401. { a circle call. }
  1402. move(ArcCall,OriginalArcInfo, sizeof(ArcCall));
  1403. if LineInfo.Thickness = Normwidth then
  1404. begin
  1405. OldWriteMode := CurrentWriteMode;
  1406. CurrentWriteMode := CopyPut;
  1407. end;
  1408. InternalEllipse(X,Y,Radius,Radius,0,360,{$ifdef fpc}@{$endif}DummyPatternLine);
  1409. if LineInfo.Thickness = Normwidth then
  1410. CurrentWriteMode := OldWriteMode;
  1411. { restore arc information }
  1412. move(OriginalArcInfo, ArcCall,sizeof(ArcCall));
  1413. end;
  1414. procedure SectorPL(x1,x2,y: smallint); {$ifndef fpc}far;{$endif fpc}
  1415. var plx1, plx2: smallint;
  1416. {$ifdef sectorpldebug}
  1417. t : text;
  1418. {$endif sectorpldebug}
  1419. begin
  1420. {$ifdef sectorpldebug}
  1421. assign(t,'sector.log');
  1422. append(t);
  1423. writeln(t,'Got here for line ',y);
  1424. close(t);
  1425. {$endif sectorpldebug}
  1426. If (x1 = -maxsmallint) Then
  1427. If (x2 = maxsmallint-1) Then
  1428. { no ellipse points drawn on this line }
  1429. If (((Y < ArcCall.Y) and (Y > ArcCall.YStart)) or
  1430. ((Y > ArcCall.Y) and (Y < ArcCall.YStart))) Then
  1431. { there is a part of the sector at this y coordinate, but no }
  1432. { ellips points are plotted on this line, so draw a patternline }
  1433. { between the lines connecting (arccall.x,arccall.y) with }
  1434. { the start and the end of the arc (JM) }
  1435. { use: y-y1=(y2-y1)/(x2-x1)*(x-x1) => }
  1436. { x = (y-y1)/(y2-y1)*(x2-x1)+x1 }
  1437. Begin
  1438. {$ifdef sectorpldebug}
  1439. If (ArcCall.YStart-ArcCall.Y) = 0 then
  1440. begin
  1441. append(t);
  1442. writeln(t,'bug1');
  1443. close(t);
  1444. runerror(202);
  1445. end;
  1446. {$endif sectorpldebug}
  1447. plx1 := (y-ArcCall.Y)*(ArcCall.XStart-ArcCall.X)
  1448. div (ArcCall.YStart-ArcCall.Y)+ArcCall.X;
  1449. {$ifdef sectorpldebug}
  1450. If (ArcCall.YEnd-ArcCall.Y) = 0 then
  1451. begin
  1452. append(t);
  1453. writeln(t,'bug2');
  1454. close(t);
  1455. runerror(202);
  1456. end;
  1457. {$endif sectorpldebug}
  1458. plx2 := (y-ArcCall.Y)*(ArcCall.XEnd-ArcCall.X)
  1459. div (ArcCall.YEnd-ArcCall.Y)+ArcCall.X;
  1460. If plx1 > plx2 then
  1461. begin
  1462. plx1 := plx1 xor plx2;
  1463. plx2 := plx1 xor plx2;
  1464. plx1 := plx1 xor plx2;
  1465. end;
  1466. {$ifdef sectorpldebug}
  1467. append(t);
  1468. writeln(t,'lines: ',plx1,' - ',plx2);
  1469. close(t);
  1470. {$endif sectorpldebug}
  1471. End
  1472. { otherwise two points which have nothing to do with the sector }
  1473. Else exit
  1474. Else
  1475. { the arc is plotted at the right side, but not at the left side, }
  1476. { fill till the line between (ArcCall.X,ArcCall.Y) and }
  1477. { (ArcCall.XStart,ArcCall.YStart) }
  1478. Begin
  1479. If (y < ArcCall.Y) then
  1480. begin
  1481. {$ifdef sectorpldebug}
  1482. If (ArcCall.YEnd-ArcCall.Y) = 0 then
  1483. begin
  1484. append(t);
  1485. writeln(t,'bug3');
  1486. close(t);
  1487. runerror(202);
  1488. end;
  1489. {$endif sectorpldebug}
  1490. plx1 := (y-ArcCall.Y)*(ArcCall.XEnd-ArcCall.X)
  1491. div (ArcCall.YEnd-ArcCall.Y)+ArcCall.X
  1492. end
  1493. else if (y > ArcCall.Y) then
  1494. begin
  1495. {$ifdef sectorpldebug}
  1496. If (ArcCall.YStart-ArcCall.Y) = 0 then
  1497. begin
  1498. append(t);
  1499. writeln(t,'bug4');
  1500. close(t);
  1501. runerror(202);
  1502. end;
  1503. {$endif sectorpldebug}
  1504. plx1 := (y-ArcCall.Y)*(ArcCall.XStart-ArcCall.X)
  1505. div (ArcCall.YStart-ArcCall.Y)+ArcCall.X
  1506. end
  1507. else plx1 := ArcCall.X;
  1508. plx2 := x2;
  1509. {$ifdef sectorpldebug}
  1510. append(t);
  1511. writeln(t,'right: ',plx1,' - ',plx2);
  1512. close(t);
  1513. {$endif sectorpldebug}
  1514. End
  1515. Else
  1516. If (x2 = maxsmallint-1) Then
  1517. { the arc is plotted at the left side, but not at the rigth side. }
  1518. { the right limit can be either the first or second line. Just take }
  1519. { the closest one, but watch out for division by zero! }
  1520. Begin
  1521. If (y < ArcCall.Y) then
  1522. begin
  1523. {$ifdef sectorpldebug}
  1524. If (ArcCall.YStart-ArcCall.Y) = 0 then
  1525. begin
  1526. append(t);
  1527. writeln(t,'bug5');
  1528. close(t);
  1529. runerror(202);
  1530. end;
  1531. {$endif sectorpldebug}
  1532. plx2 := (y-ArcCall.Y)*(ArcCall.XStart-ArcCall.X)
  1533. div (ArcCall.YStart-ArcCall.Y)+ArcCall.X
  1534. end
  1535. else if (y > ArcCall.Y) then
  1536. begin
  1537. {$ifdef sectorpldebug}
  1538. If (ArcCall.YEnd-ArcCall.Y) = 0 then
  1539. begin
  1540. append(t);
  1541. writeln(t,'bug6');
  1542. close(t);
  1543. runerror(202);
  1544. end;
  1545. {$endif sectorpldebug}
  1546. plx2 := (y-ArcCall.Y)*(ArcCall.XEnd-ArcCall.X)
  1547. div (ArcCall.YEnd-ArcCall.Y)+ArcCall.X
  1548. end
  1549. else plx2 := ArcCall.X;
  1550. plx1 := x1;
  1551. {$ifdef sectorpldebug}
  1552. append(t);
  1553. writeln(t,'left: ',plx1,' - ',plx2);
  1554. close(t);
  1555. {$endif sectorpldebug}
  1556. End
  1557. Else
  1558. { the arc is plotted at both sides }
  1559. Begin
  1560. plx1 := x1;
  1561. plx2 := x2;
  1562. {$ifdef sectorpldebug}
  1563. append(t);
  1564. writeln(t,'normal: ',plx1,' - ',plx2);
  1565. close(t);
  1566. {$endif sectorpldebug}
  1567. End;
  1568. If plx2 > plx1 then
  1569. Begin
  1570. {$ifdef sectorpldebug}
  1571. append(t);
  1572. Writeln(t,'drawing...');
  1573. close(t);
  1574. {$endif sectorpldebug}
  1575. PatternLine(plx1,plx2,y);
  1576. end;
  1577. end;
  1578. procedure Sector(x, y: smallint; StAngle,EndAngle, XRadius, YRadius: Word);
  1579. begin
  1580. internalellipse(x,y,XRadius, YRadius, StAngle, EndAngle, {$ifdef fpc}@{$endif}SectorPL);
  1581. Line(ArcCall.XStart, ArcCall.YStart, x,y);
  1582. Line(x,y,ArcCall.Xend,ArcCall.YEnd);
  1583. end;
  1584. procedure SetFillStyle(Pattern : word; Color: word);
  1585. begin
  1586. { on invalid input, the current fill setting will be }
  1587. { unchanged. }
  1588. if (Pattern > UserFill) or (Color > GetMaxColor) then
  1589. begin
  1590. {$ifdef logging}
  1591. logln('invalid fillstyle parameters');
  1592. {$endif logging}
  1593. _GraphResult := grError;
  1594. exit;
  1595. end;
  1596. FillSettings.Color := Color;
  1597. FillSettings.Pattern := Pattern;
  1598. end;
  1599. procedure SetFillPattern(Pattern: FillPatternType; Color: word);
  1600. {********************************************************}
  1601. { Changes the Current FillPattern to a user defined }
  1602. { pattern and changes also the current fill color. }
  1603. { The FillPattern is saved in the FillPattern array so }
  1604. { it can still be used with SetFillStyle(UserFill,Color) }
  1605. {********************************************************}
  1606. var
  1607. i: smallint;
  1608. begin
  1609. if Color > GetMaxColor then
  1610. begin
  1611. {$ifdef logging}
  1612. logln('invalid fillpattern parameters');
  1613. {$endif logging}
  1614. _GraphResult := grError;
  1615. exit;
  1616. end;
  1617. FillSettings.Color := Color;
  1618. FillSettings.Pattern := UserFill;
  1619. { Save the pattern in the buffer }
  1620. For i:=1 to 8 do
  1621. FillPatternTable[UserFill][i] := Pattern[i];
  1622. end;
  1623. procedure Bar(x1,y1,x2,y2:smallint);
  1624. {********************************************************}
  1625. { Important notes for compatibility with BP: }
  1626. { - WriteMode is always CopyPut }
  1627. { - No contour is drawn for the lines }
  1628. {********************************************************}
  1629. var y : smallint;
  1630. origcolor : longint;
  1631. origlinesettings: Linesettingstype;
  1632. origwritemode : smallint;
  1633. begin
  1634. origlinesettings:=lineinfo;
  1635. origcolor:=CurrentColor;
  1636. if y1>y2 then
  1637. begin
  1638. y:=y1;
  1639. y1:=y2;
  1640. y2:=y;
  1641. end;
  1642. { Always copy mode for Bars }
  1643. origwritemode := CurrentWriteMode;
  1644. CurrentWriteMode := CopyPut;
  1645. { All lines used are of this style }
  1646. Lineinfo.linestyle:=solidln;
  1647. Lineinfo.thickness:=normwidth;
  1648. case Fillsettings.pattern of
  1649. EmptyFill :
  1650. begin
  1651. Currentcolor:=CurrentBkColor;
  1652. for y:=y1 to y2 do
  1653. Hline(x1,x2,y);
  1654. end;
  1655. SolidFill :
  1656. begin
  1657. CurrentColor:=FillSettings.color;
  1658. for y:=y1 to y2 do
  1659. Hline(x1,x2,y);
  1660. end;
  1661. else
  1662. Begin
  1663. CurrentColor:=FillSettings.color;
  1664. for y:=y1 to y2 do
  1665. patternline(x1,x2,y);
  1666. end;
  1667. end;
  1668. CurrentColor:= Origcolor;
  1669. LineInfo := OrigLineSettings;
  1670. CurrentWriteMode := OrigWritemode;
  1671. end;
  1672. procedure bar3D(x1, y1, x2, y2 : smallint;depth : word;top : boolean);
  1673. var
  1674. origwritemode : smallint;
  1675. OldX, OldY : smallint;
  1676. begin
  1677. origwritemode := CurrentWriteMode;
  1678. CurrentWriteMode := CopyPut;
  1679. Bar(x1,y1,x2,y2);
  1680. Rectangle(x1,y1,x2,y2);
  1681. { Current CP should not be updated in Bar3D }
  1682. { therefore save it and then restore it on }
  1683. { exit. }
  1684. OldX := CurrentX;
  1685. OldY := CurrentY;
  1686. if top then begin
  1687. Moveto(x1,y1);
  1688. Lineto(x1+depth,y1-depth);
  1689. Lineto(x2+depth,y1-depth);
  1690. Lineto(x2,y1);
  1691. end;
  1692. if Depth <> 0 then
  1693. Begin
  1694. Moveto(x2+depth,y1-depth);
  1695. Lineto(x2+depth,y2-depth);
  1696. Lineto(x2,y2);
  1697. end;
  1698. { restore CP }
  1699. CurrentX := OldX;
  1700. CurrentY := OldY;
  1701. CurrentWriteMode := origwritemode;
  1702. end;
  1703. {--------------------------------------------------------------------------}
  1704. { }
  1705. { COLOR AND PALETTE ROUTINES }
  1706. { }
  1707. {--------------------------------------------------------------------------}
  1708. procedure SetColor(Color: Word);
  1709. Begin
  1710. CurrentColor := Color;
  1711. end;
  1712. function GetColor: Word;
  1713. Begin
  1714. GetColor := CurrentColor;
  1715. end;
  1716. function GetBkColor: Word;
  1717. Begin
  1718. GetBkColor := CurrentBkColor;
  1719. end;
  1720. procedure SetBkColor(ColorNum: Word);
  1721. { Background color means background screen color in this case, and it is }
  1722. { INDEPENDANT of the viewport settings, so we must clear the whole screen }
  1723. { with the color. }
  1724. var
  1725. ViewPort: ViewportType;
  1726. Begin
  1727. GetViewSettings(Viewport);
  1728. {$ifdef logging}
  1729. logln('calling setviewport from setbkcolor');
  1730. {$endif logging}
  1731. SetViewPort(0,0,MaxX,MaxY,FALSE);
  1732. {$ifdef logging}
  1733. logln('calling setviewport from setbkcolor done');
  1734. {$endif logging}
  1735. CurrentBkColor := ColorNum;
  1736. {ClearViewPort;}
  1737. if not DirectColor and (ColorNum<256) then
  1738. SetRGBPalette(0,
  1739. DefaultColors[ColorNum].Red,
  1740. DefaultColors[ColorNum].Green,
  1741. DefaultColors[ColorNum].Blue);
  1742. SetViewport(ViewPort.X1,Viewport.Y1,Viewport.X2,Viewport.Y2,Viewport.Clip);
  1743. end;
  1744. function GetMaxColor: word;
  1745. { Checked against TP VGA driver - CEC }
  1746. begin
  1747. GetMaxColor:=MaxColor-1; { based on an index of zero so subtract one }
  1748. end;
  1749. Procedure MoveRel(Dx, Dy: smallint);
  1750. Begin
  1751. CurrentX := CurrentX + Dx;
  1752. CurrentY := CurrentY + Dy;
  1753. end;
  1754. Procedure MoveTo(X,Y: smallint);
  1755. {********************************************************}
  1756. { Procedure MoveTo() }
  1757. {--------------------------------------------------------}
  1758. { Moves the current pointer in VIEWPORT relative }
  1759. { coordinates to the specified X,Y coordinate. }
  1760. {********************************************************}
  1761. Begin
  1762. CurrentX := X;
  1763. CurrentY := Y;
  1764. end;
  1765. function GraphErrorMsg(ErrorCode: smallint): string;
  1766. Begin
  1767. GraphErrorMsg:='';
  1768. case ErrorCode of
  1769. grOk,grFileNotFound,grInvalidDriver: exit;
  1770. grNoInitGraph: GraphErrorMsg:='Graphics driver not installed';
  1771. grNotDetected: GraphErrorMsg:='Graphics hardware not detected';
  1772. grNoLoadMem,grNoScanMem,grNoFloodMem: GraphErrorMsg := 'Not enough memory for graphics';
  1773. grNoFontMem: GraphErrorMsg := 'Not enough memory to load font';
  1774. grFontNotFound: GraphErrorMsg:= 'Font file not found';
  1775. grInvalidMode: GraphErrorMsg := 'Invalid graphics mode';
  1776. grError: GraphErrorMsg:='Graphics error';
  1777. grIoError: GraphErrorMsg:='Graphics I/O error';
  1778. grInvalidFont,grInvalidFontNum: GraphErrorMsg := 'Invalid font';
  1779. grInvalidVersion: GraphErrorMsg:='Invalid driver version';
  1780. end;
  1781. end;
  1782. Function GetMaxX: smallint;
  1783. { Routine checked against VGA driver - CEC }
  1784. Begin
  1785. GetMaxX := MaxX;
  1786. end;
  1787. Function GetMaxY: smallint;
  1788. { Routine checked against VGA driver - CEC }
  1789. Begin
  1790. GetMaxY := MaxY;
  1791. end;
  1792. Function GraphResult: smallint;
  1793. Begin
  1794. GraphResult := _GraphResult;
  1795. _GraphResult := grOk;
  1796. end;
  1797. Function GetX: smallint;
  1798. Begin
  1799. GetX := CurrentX;
  1800. end;
  1801. Function GetY: smallint;
  1802. Begin
  1803. GetY := CurrentY;
  1804. end;
  1805. Function GetDriverName: string;
  1806. begin
  1807. GetDriverName:=DriverName;
  1808. end;
  1809. procedure graphdefaults;
  1810. { PS: GraphDefaults does not ZERO the ArcCall structure }
  1811. { so a call to GetArcCoords will not change even the }
  1812. { returned values even if GraphDefaults is called in }
  1813. { between. }
  1814. var
  1815. i: smallint;
  1816. begin
  1817. lineinfo.linestyle:=solidln;
  1818. lineinfo.thickness:=normwidth;
  1819. { reset line style pattern }
  1820. for i:=0 to 15 do
  1821. LinePatterns[i] := TRUE;
  1822. { By default, according to the TP prog's reference }
  1823. { the default pattern is solid, and the default }
  1824. { color is the maximum color in the palette. }
  1825. fillsettings.color:=GetMaxColor;
  1826. fillsettings.pattern:=solidfill;
  1827. { GraphDefaults resets the User Fill pattern to $ff }
  1828. { checked with VGA BGI driver - CEC }
  1829. for i:=1 to 8 do
  1830. FillPatternTable[UserFill][i] := $ff;
  1831. CurrentColor:=white;
  1832. ClipPixels := TRUE;
  1833. { Reset the viewport }
  1834. StartXViewPort := 0;
  1835. StartYViewPort := 0;
  1836. ViewWidth := MaxX;
  1837. ViewHeight := MaxY;
  1838. { Reset CP }
  1839. CurrentX := 0;
  1840. CurrentY := 0;
  1841. SetBkColor(Black);
  1842. { normal write mode }
  1843. CurrentWriteMode := CopyPut;
  1844. { Schriftart einstellen }
  1845. CurrentTextInfo.font := DefaultFont;
  1846. CurrentTextInfo.direction:=HorizDir;
  1847. CurrentTextInfo.charsize:=1;
  1848. CurrentTextInfo.horiz:=LeftText;
  1849. CurrentTextInfo.vert:=TopText;
  1850. XAspect:=10000; YAspect:=10000;
  1851. end;
  1852. procedure GetAspectRatio(var Xasp,Yasp : word);
  1853. begin
  1854. XAsp:=XAspect;
  1855. YAsp:=YAspect;
  1856. end;
  1857. procedure SetAspectRatio(Xasp, Yasp : word);
  1858. begin
  1859. Xaspect:= XAsp;
  1860. YAspect:= YAsp;
  1861. end;
  1862. procedure SetWriteMode(WriteMode : smallint);
  1863. { TP sets the writemodes according to the following scheme (JM) }
  1864. begin
  1865. Case writemode of
  1866. xorput, andput: CurrentWriteMode := XorPut;
  1867. notput, orput, copyput: CurrentWriteMode := CopyPut;
  1868. End;
  1869. end;
  1870. procedure GetFillSettings(var Fillinfo:Fillsettingstype);
  1871. begin
  1872. Fillinfo:=Fillsettings;
  1873. end;
  1874. procedure GetFillPattern(var FillPattern:FillPatternType);
  1875. begin
  1876. FillPattern:=FillpatternTable[UserFill];
  1877. end;
  1878. procedure DrawPoly(numpoints : word;var polypoints);
  1879. type
  1880. ppointtype = ^pointtype;
  1881. pt = array[0..16000] of pointtype;
  1882. var
  1883. i : longint;
  1884. begin
  1885. if numpoints < 2 then
  1886. begin
  1887. _GraphResult := grError;
  1888. exit;
  1889. end;
  1890. for i:=0 to numpoints-2 do
  1891. line(pt(polypoints)[i].x,
  1892. pt(polypoints)[i].y,
  1893. pt(polypoints)[i+1].x,
  1894. pt(polypoints)[i+1].y);
  1895. end;
  1896. procedure PieSlice(X,Y,stangle,endAngle:smallint;Radius: Word);
  1897. begin
  1898. Sector(x,y,stangle,endangle,radius,radius);
  1899. end;
  1900. {$i fills.inc}
  1901. {$i gtext.inc}
  1902. procedure internDetectGraph(var GraphDriver, GraphMode:smallint;
  1903. calledFromInitGraph: boolean);
  1904. var LoMode, HiMode: smallint;
  1905. CpyMode: smallint;
  1906. CpyDriver: smallint;
  1907. begin
  1908. HiMode := -1;
  1909. LoMode := -1;
  1910. {$ifndef nonewmodes}
  1911. if not calledFromInitGraph or
  1912. (graphDriver < lowNewDriver) or
  1913. (graphDriver > highNewDriver) then
  1914. begin
  1915. { Search lowest supported bitDepth }
  1916. graphdriver := D1bit;
  1917. while (graphDriver <= highNewDriver) and
  1918. (hiMode = -1) do
  1919. begin
  1920. getModeRange(graphDriver,loMode,hiMode);
  1921. inc(graphDriver);
  1922. end;
  1923. dec(graphdriver);
  1924. if hiMode = -1 then
  1925. begin
  1926. _GraphResult := grNotDetected;
  1927. exit;
  1928. end;
  1929. CpyMode := 0;
  1930. repeat
  1931. GetModeRange(GraphDriver,LoMode,HiMode);
  1932. { save the highest mode possible...}
  1933. {$ifdef logging}
  1934. logln('Found driver '+strf(graphdriver)+' with modes '+
  1935. strf(lomode)+' - '+strf(himode));
  1936. {$endif logging}
  1937. if HiMode <> -1 then
  1938. begin
  1939. CpyMode:=HiMode;
  1940. CpyDriver:=GraphDriver;
  1941. end;
  1942. { go to next driver if it exists...}
  1943. Inc(graphDriver);
  1944. until (graphDriver > highNewDriver);
  1945. end
  1946. else
  1947. begin
  1948. cpyMode := 0;
  1949. getModeRange(graphDriver,loMode,hiMode);
  1950. if hiMode <> -1 then
  1951. begin
  1952. cpyDriver := graphDriver;
  1953. cpyMode := hiMode;
  1954. end;
  1955. end;
  1956. if cpyMode = 0 then
  1957. begin
  1958. _GraphResult := grNotDetected;
  1959. exit;
  1960. end;
  1961. {$else nonewmodes}
  1962. { We start at VGA }
  1963. GraphDriver := VGA;
  1964. CpyMode := 0;
  1965. { search all possible graphic drivers in ascending order...}
  1966. { usually the new driver numbers indicate newest hardware...}
  1967. { Internal driver numbers start at VGA=9 }
  1968. repeat
  1969. GetModeRange(GraphDriver,LoMode,HiMode);
  1970. { save the highest mode possible...}
  1971. {$ifdef logging}
  1972. logln('Found driver '+strf(graphdriver)+' with modes '+
  1973. strf(lomode)+' - '+strf(himode));
  1974. {$endif logging}
  1975. if HiMode = -1 then break;
  1976. CpyMode:=HiMode;
  1977. CpyDriver:=GraphDriver;
  1978. { go to next driver if it exists...}
  1979. Inc(GraphDriver);
  1980. until (CpyMode=-1);
  1981. { If this is equal to -1 then no graph mode possible...}
  1982. if CpyMode = -1 then
  1983. begin
  1984. _GraphResult := grNotDetected;
  1985. exit;
  1986. end;
  1987. {$endif nonewmodes}
  1988. _GraphResult := grOK;
  1989. GraphDriver := CpyDriver;
  1990. GraphMode := CpyMode;
  1991. end;
  1992. procedure detectGraph(var GraphDriver: smallint; var GraphMode:smallint);
  1993. begin
  1994. internDetectGraph(graphDriver,graphMode,false);
  1995. end;
  1996. procedure InitGraph(var GraphDriver:smallint;var GraphMode:smallint;
  1997. const PathToDriver:String);
  1998. const
  1999. {$IFDEF Linux}
  2000. dirchar = '/';
  2001. {$ELSE}
  2002. dirchar = '\';
  2003. {$ENDIF}
  2004. begin
  2005. InitVars;
  2006. { path to the fonts (where they will be searched)...}
  2007. bgipath:=PathToDriver;
  2008. if (Length(bgipath) > 0) and (bgipath[length(bgipath)]<>dirchar) then
  2009. bgipath:=bgipath+dirchar;
  2010. if not assigned(SaveVideoState) then
  2011. RunError(216);
  2012. DriverName:=InternalDriverName; { DOS Graphics driver }
  2013. if (Graphdriver=Detect)
  2014. {$ifndef nonewmodes}
  2015. or (GraphMode = detectMode)
  2016. {$endif}
  2017. then
  2018. begin
  2019. internDetectGraph(GraphDriver,GraphMode,true);
  2020. If _GraphResult = grNotDetected then Exit;
  2021. { _GraphResult is now already set to grOK by DetectGraph }
  2022. IntCurrentDriver := GraphDriver;
  2023. IntCurrentNewDriver := GraphDriver;
  2024. SaveVideoState;
  2025. { Actually set the graph mode...}
  2026. SetGraphMode(GraphMode);
  2027. end
  2028. else
  2029. begin
  2030. { Search if that graphics modec actually exists...}
  2031. if SearchMode(GraphDriver,GraphMode) = nil then
  2032. begin
  2033. _GraphResult := grInvalidMode;
  2034. exit;
  2035. end
  2036. else
  2037. begin
  2038. _GraphResult := grOK;
  2039. IntCurrentDriver := GraphDriver;
  2040. IntCurrentNewDriver := GraphDriver;
  2041. SaveVideoState;
  2042. {$ifdef logging}
  2043. If _GraphResult <> grOK then
  2044. LogLn('Mode setting failed after savevideostate');
  2045. {$endif logging}
  2046. SetGraphMode(GraphMode);
  2047. end;
  2048. end;
  2049. end;
  2050. procedure SetDirectVideo(DirectAccess: boolean);
  2051. begin
  2052. DirectVideo := DirectAccess;
  2053. end;
  2054. function GetDirectVideo: boolean;
  2055. begin
  2056. GetDirectVideo := DirectVideo;
  2057. end;
  2058. procedure GraphExitProc; {$ifndef fpc} far; {$endif fpc}
  2059. { deallocates all memory allocated by the graph unit }
  2060. var
  2061. list: PModeInfo;
  2062. tmp : PModeInfo;
  2063. c: graph_int;
  2064. begin
  2065. { restore old exitproc! }
  2066. exitproc := exitsave;
  2067. if IsGraphMode and ((errorcode<>0) or (erroraddr<>nil)) then
  2068. CloseGraph;
  2069. {$ifdef testsave}
  2070. restorevideostate;
  2071. {$endif testsave}
  2072. { release memory allocated for fonts }
  2073. for c := 1 to installedfonts do
  2074. with fonts[c] Do
  2075. If assigned(instr) Then
  2076. Freemem(instr,instrlength);
  2077. { release memory allocated for modelist }
  2078. list := ModeList;
  2079. while assigned(list) do
  2080. begin
  2081. tmp := list;
  2082. list:=list^.next;
  2083. dispose(tmp);
  2084. end;
  2085. {$ifndef nonewmodes}
  2086. for c := lowNewDriver to highNewDriver do
  2087. begin
  2088. list := newModeList.modeinfo[c];
  2089. while assigned(list) do
  2090. begin
  2091. tmp := list;
  2092. list:=list^.next;
  2093. dispose(tmp);
  2094. end;
  2095. end;
  2096. {$endif nonewmodes}
  2097. {$IFDEF DPMI}
  2098. { We had copied the buffer of mode information }
  2099. { and allocated it dynamically... now free it }
  2100. { Warning: if GetVESAInfo returned false, this buffer is not allocated! (JM)}
  2101. If hasVesa then
  2102. Dispose(VESAInfo.ModeList);
  2103. {$ENDIF}
  2104. end;
  2105. procedure InitializeGraph;
  2106. begin
  2107. {$ifdef logging}
  2108. assign(debuglog,'grlog.txt');
  2109. rewrite(debuglog);
  2110. close(debuglog);
  2111. {$endif logging}
  2112. isgraphmode := false;
  2113. ModeList := nil;
  2114. {$ifndef nonewmodes}
  2115. fillChar(newModeList.modeinfo,sizeof(newModeList.modeinfo),#0);
  2116. { lo and hi modenumber are -1 currently (no modes supported) }
  2117. fillChar(newModeList.loHiModeNr,sizeof(newModeList.loHiModeNr),#255);
  2118. {$endif nonewmodes}
  2119. SaveVideoState := nil;
  2120. RestoreVideoState := nil;
  2121. {$ifdef oldfont}
  2122. {$ifdef go32v2}
  2123. LoadFont8x8;
  2124. {$endif go32v2}
  2125. {$endif oldfont}
  2126. { This must be called at startup... because GetGraphMode may }
  2127. { be called even when not in graph mode. }
  2128. {$ifdef logging}
  2129. LogLn('Calling QueryAdapterInfo...');
  2130. {$endif logging}
  2131. QueryAdapterInfo;
  2132. { Install standard fonts }
  2133. { This is done BEFORE startup... }
  2134. InstalledFonts := 0;
  2135. InstallUserFont('TRIP');
  2136. InstallUserFont('LITT');
  2137. InstallUserFont('SANS');
  2138. InstallUserFont('GOTH');
  2139. InstallUserFont('SCRI');
  2140. InstallUserFont('SIMP');
  2141. InstallUserFont('TSCR');
  2142. InstallUserFont('LCOM');
  2143. InstallUserFont('EURO');
  2144. InstallUserFont('BOLD');
  2145. { This installs an exit procedure which cleans up the mode list...}
  2146. ExitSave := ExitProc;
  2147. ExitProc := @GraphExitProc;
  2148. {$ifdef testsave}
  2149. savevideostate;
  2150. {$endif testsave}
  2151. {$ifdef win32}
  2152. charmessagehandler:=nil;
  2153. {$endif win32}
  2154. end;
  2155. {
  2156. $Log$
  2157. Revision 1.1 2000-07-13 06:30:51 michael
  2158. + Initial import
  2159. Revision 1.39 2000/07/07 17:29:30 jonas
  2160. * fixed setgraphmode together with the new graphdrivers
  2161. Revision 1.38 2000/06/27 13:37:04 jonas
  2162. * released -dnewmodes
  2163. Revision 1.37 2000/06/23 19:56:37 jonas
  2164. * setviewport was sometimes called with parameters from the previous
  2165. active mode, either directly from setgraphmode or from
  2166. setbkcolor
  2167. Revision 1.36 2000/06/18 18:41:18 peter
  2168. * detectmode between ifdef
  2169. Revision 1.35 2000/06/18 08:11:53 jonas
  2170. * release memory of newmodeinfo in graphexitproc
  2171. Revision 1.34 2000/06/18 06:11:20 jonas
  2172. + added missing detectMode stuff for -dnewmodes
  2173. Revision 1.33 2000/06/17 19:09:22 jonas
  2174. * new platform independent mode handling (between -dnewmodes)
  2175. Revision 1.32 2000/06/07 07:33:42 jonas
  2176. * calling a graph function when initgraph is not yet called now prints
  2177. a nice error message instead of giving a Run Time Error
  2178. Revision 1.31 2000/04/02 12:13:36 florian
  2179. * some more procedures can be now hooked by the OS specific implementation
  2180. Revision 1.30 2000/03/24 18:16:32 florian
  2181. * introduce a DrawBitmapCharHoriz procedure variable to accelerate output on
  2182. win32
  2183. Revision 1.29 2000/03/24 13:01:15 florian
  2184. * ClearViewPort fixed
  2185. Revision 1.28 2000/03/19 11:20:13 peter
  2186. * graph unit include is now independent and the dependent part
  2187. is now in graph.pp
  2188. * ggigraph unit for linux added
  2189. Revision 1.60 2000/03/18 10:45:07 sg
  2190. * Fix for ClearViewportDefault: The width and the height of the rectangle
  2191. it filled has been one pixel too high.
  2192. Revision 1.59 2000/03/17 13:28:54 sg
  2193. * Use linux unit under Linux
  2194. Revision 1.58 2000/03/08 14:20:14 jonas
  2195. * writemode was not set to normalput during clearviewport (and it uses hline)
  2196. Revision 1.57 2000/02/27 14:41:25 peter
  2197. * removed warnings/notes
  2198. Revision 1.56 2000/02/06 01:47:15 sg
  2199. * For Linux, "/" is added to the bgipath instead of "\" if this character
  2200. isn't already there.
  2201. Revision 1.55 2000/01/07 16:41:37 daniel
  2202. * copyright 2000
  2203. Revision 1.54 2000/01/07 16:32:25 daniel
  2204. * copyright 2000 added
  2205. Revision 1.53 2000/01/02 19:02:39 jonas
  2206. * removed/commented out (inited but) unused vars and unused types
  2207. Revision 1.52 1999/12/29 17:26:00 jonas
  2208. + by default, also attempt to install the fonts that come with TP7
  2209. Revision 1.51 1999/12/26 10:33:06 jonas
  2210. * XAspect and YAspect are now words instead of smallints, they
  2211. overflowed for resolutions > 640x480 otherwise
  2212. * the number of pixels required for an ellipse in internalellipsedef
  2213. is now calculated after the aspectratios have been taken into
  2214. account
  2215. Revision 1.50 1999/12/21 17:42:17 jonas
  2216. * changed vesa.inc do it doesn't try to use linear modes anymore (doesn't work
  2217. yet!!)
  2218. * fixed mode detection so the low modenumber of a driver doesn't have to be zero
  2219. anymore (so VESA autodetection now works)
  2220. Revision 1.49 1999/12/21 09:16:48 pierre
  2221. + CloseGraph if errors
  2222. Revision 1.48 1999/12/20 11:22:36 peter
  2223. * integer -> smallint to overcome -S2 switch needed for ggi version
  2224. Revision 1.47 1999/12/12 13:34:20 jonas
  2225. * putimage now performs the lipping itself and uses directputpixel
  2226. (note: this REQUIRES or/and/notput support in directputpixel,
  2227. this is not yet the case in the assembler versions!)
  2228. * YOffset addition moved in hlinevesa256 and vlinevesa256
  2229. because it uses still putpixel afterwards
  2230. Revision 1.46 1999/12/11 23:41:38 jonas
  2231. * changed definition of getscanlineproc to "getscanline(x1,x2,y:
  2232. smallint; var data);" so it can be used by getimage too
  2233. * changed getimage so it uses getscanline
  2234. * changed floodfill, getscanline16 and definitions in Linux
  2235. include files so they use this new format
  2236. + getscanlineVESA256 for 256 color VESA modes (banked)
  2237. Revision 1.45 1999/12/10 12:47:41 pierre
  2238. * SetBkColor like BP by changing Palette entry zero
  2239. Revision 1.44 1999/11/30 08:57:46 michael
  2240. + Removed charmessagehandler declaration, it is in graphh.inc
  2241. Revision 1.43 1999/11/28 16:13:55 jonas
  2242. * corrected misplacement of call to initvars in initgraph
  2243. + some extra debugging commands (for -dlogging) in the mode functions
  2244. Revision 1.42 1999/11/28 12:19:59 jonas
  2245. * _GraphResult is now properly set to grOK by DetectGraph and
  2246. InitGraph if there are no errors
  2247. Revision 1.41 1999/11/27 21:48:01 jonas
  2248. * fixed VlineVESA256 and re-enabled it in graph.inc
  2249. * added procedure detectgraph to interface of graph unit
  2250. Revision 1.40 1999/11/25 17:44:14 pierre
  2251. * memory corruption within GetImage removed
  2252. Revision 1.39 1999/11/24 23:42:31 pierre
  2253. * PutImage used an smallint index that became negative !!!!
  2254. * Default needed procedure now genrate a RTE 218 instead of a
  2255. GPF by call to nil pointer !
  2256. Revision 1.38 1999/11/11 17:55:07 florian
  2257. * the size was calculated wrong by imagesize
  2258. Revision 1.37 1999/11/11 14:07:14 florian
  2259. * better looking font
  2260. Revision 1.36 1999/11/08 15:01:38 peter
  2261. * fpcmake support
  2262. Revision 1.35 1999/11/08 11:15:22 peter
  2263. * move graph.inc to the target dir
  2264. Revision 1.34 1999/11/03 20:23:01 florian
  2265. + first release of win32 gui support
  2266. Revision 1.33 1999/10/17 10:20:13 jonas
  2267. * fixed clipping for thickwidth lines (bug 659)
  2268. * fixed the faster internalellipsedefault, but it doesn't plot
  2269. all pixels (there are gaps in the ellipses)
  2270. Revision 1.32 1999/09/28 15:07:46 jonas
  2271. * fix for disposing font data because it can contain #0 chars
  2272. Revision 1.31 1999/09/28 13:56:25 jonas
  2273. * reordered some local variables (first 4 byte vars, then 2 byte vars
  2274. etc)
  2275. * font data is now disposed in exitproc, exitproc is now called
  2276. GraphExitProc (was CleanModes) and resides in graph.pp instead of in
  2277. modes.inc
  2278. Revision 1.30 1999/09/27 23:34:41 peter
  2279. * new graph unit is default for go32v2
  2280. * removed warnings/notes
  2281. Revision 1.29 1999/09/26 13:31:06 jonas
  2282. * changed name of modeinfo variable to vesamodeinfo and fixed
  2283. associated errors (fillchar(modeinfo,sizeof(tmodeinfo),#0) instead
  2284. of sizeof(TVesamodeinfo) etc)
  2285. * changed several sizeof(type) to sizeof(varname) to avoid similar
  2286. errors in the future
  2287. Revision 1.28 1999/09/25 11:48:43 jonas
  2288. + detectgraph
  2289. * small change to internalellipsedefault so less pixels are
  2290. calculated twice
  2291. * some small corrections to graph.tex
  2292. Revision 1.27 1999/09/24 22:52:38 jonas
  2293. * optimized patternline a bit (always use hline when possible)
  2294. * isgraphmode stuff cleanup
  2295. * vesainfo.modelist now gets disposed in cleanmode instead of in
  2296. closegraph (required moving of some declarations from vesa.inc to
  2297. new vesah.inc)
  2298. * queryadapter gets no longer called from initgraph (is called from
  2299. initialization of graph unit)
  2300. * bugfix for notput in 32k and 64k vesa modes
  2301. * a div replaced by / in fillpoly
  2302. Revision 1.26 1999/09/22 13:13:35 jonas
  2303. * renamed text.inc -> gtext.inc to avoid conflict with system unit
  2304. * fixed textwidth
  2305. * isgraphmode now gets properly updated, so mode restoring works
  2306. again
  2307. Revision 1.25 1999/09/18 22:21:10 jonas
  2308. + hlinevesa256 and vlinevesa256
  2309. + support for not/xor/or/andput in vesamodes with 32k/64k colors
  2310. * lots of changes to avoid warnings under FPC
  2311. Revision 1.24 1999/09/18 16:03:37 jonas
  2312. * graph.pp: removed pieslice and sector from ToDo list
  2313. * closegraph: exits now immidiately if isgraphmode = false (caused
  2314. RTE 204 with VESA enabled if you set exitproc to call closegraph
  2315. and also called closegraph explicitely before exit, like bgidemo)
  2316. Revision 1.23 1999/09/17 13:58:31 jonas
  2317. * another fix for a case where internalellipsedefault went haywire
  2318. * sector() and pieslice() fully implemented!
  2319. * small change to prevent buffer overflow with floodfill
  2320. Revision 1.22 1999/09/15 13:37:50 jonas
  2321. * small change to internalellipsedef to be TP compatible
  2322. * fixed directputpixel for vga 320*200*256
  2323. Revision 1.21 1999/09/13 12:49:08 jonas
  2324. * fixed Arc: internallellipse went into an endless loop if StAngle =
  2325. EndAngle
  2326. * FillEllipse is now much faster: no more floodfill,
  2327. InternalEllipseDefault now draws the patternlines immediatety!
  2328. Revision 1.20 1999/09/12 17:29:00 jonas
  2329. * several changes to internalellipse to make it faster
  2330. and to make sure it updates the ArcCall correctly
  2331. (not yet done for width = 3)
  2332. * Arc mostly works now, only sometimes an endless loop, don't know
  2333. why
  2334. Revision 1.19 1999/09/11 19:43:01 jonas
  2335. * FloodFill: did not take into account current viewport settings
  2336. * GetScanLine: only get line inside viewport, data outside of it
  2337. is not used anyway
  2338. * InternalEllipseDefault: fix for when xradius or yradius = 0 and
  2339. increase xradius and yradius always by one (TP does this too)
  2340. * fixed conlict in vesa.inc from last update
  2341. * some conditionals to avoid range check and overflow errors in
  2342. places where it doesn't matter
  2343. Revision 1.18 1999/07/26 09:38:41 florian
  2344. * bar: y2 can be less y1, fixed
  2345. * settextstyle: charsize can be 0, must be changed into 1
  2346. Revision 1.17 1999/07/18 15:07:20 jonas
  2347. + xor-, and and- orput support for VESA256 modes
  2348. * compile with -dlogging if you wnt some info to be logged to grlog.txt
  2349. Revision 1.16 1999/07/14 18:18:04 florian
  2350. * cosmetic changes
  2351. }