graph.inc 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144
  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. var
  13. ExitSave: pointer;
  14. const
  15. firstCallOfInitGraph: boolean = true;
  16. {$ifdef logging}
  17. var debuglog: text;
  18. function strf(l: longint): string;
  19. begin
  20. str(l, strf)
  21. end;
  22. Procedure Log(Const s: String);
  23. Begin
  24. Append(debuglog);
  25. Write(debuglog, s);
  26. Close(debuglog);
  27. End;
  28. Procedure LogLn(Const s: string);
  29. Begin
  30. Append(debuglog);
  31. Writeln(debuglog,s);
  32. Close(debuglog);
  33. End;
  34. {$endif logging}
  35. const
  36. StdBufferSize = 4096; { Buffer size for FloodFill }
  37. type
  38. tinttable = array[0..16383] of smallint;
  39. pinttable = ^tinttable;
  40. WordArray = Array [0..StdbufferSize] Of word;
  41. PWordArray = ^WordArray;
  42. const
  43. { Mask for each bit in byte used to determine pattern }
  44. BitArray: Array[0..7] of byte =
  45. ($01,$02,$04,$08,$10,$20,$40,$80);
  46. RevbitArray: Array[0..7] of byte =
  47. ($80,$40,$20,$10,$08,$04,$02,$01);
  48. { pre expanded line patterns }
  49. { 0 = LSB of byte pattern }
  50. { 15 = MSB of byte pattern }
  51. LinePatterns: Array[0..15] of BOOLEAN =
  52. (TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,
  53. TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE);
  54. const
  55. BGIPath : string = '.';
  56. { Default font 8x8 system from IBM PC }
  57. {$i fontdata.inc}
  58. var
  59. CurrentColor: Word;
  60. CurrentBkColor: Word;
  61. CurrentX : smallint; { viewport relative }
  62. CurrentY : smallint; { viewport relative }
  63. ClipPixels: Boolean; { Should cliiping be enabled }
  64. CurrentWriteMode: smallint;
  65. _GraphResult : smallint;
  66. LineInfo : LineSettingsType;
  67. FillSettings: FillSettingsType;
  68. { information for Text Output routines }
  69. CurrentTextInfo : TextSettingsType;
  70. CurrentXRatio, CurrentYRatio: graph_float;
  71. installedfonts: longint; { Number of installed fonts }
  72. StartXViewPort: smallint; { absolute }
  73. StartYViewPort: smallint; { absolute }
  74. ViewWidth : smallint;
  75. ViewHeight: smallint;
  76. IsGraphMode : Boolean; { Indicates if we are in graph mode or not }
  77. ArcCall: ArcCoordsType; { Information on the last call to Arc or Ellipse }
  78. var
  79. { ******************** HARDWARE INFORMATION ********************* }
  80. { Should be set in InitGraph once only. }
  81. IntCurrentMode : smallint;
  82. IntCurrentDriver : smallint; { Currently loaded driver }
  83. IntCurrentNewDriver: smallint;
  84. XAspect : word;
  85. YAspect : word;
  86. MaxX : smallint; { Maximum resolution - ABSOLUTE }
  87. MaxY : smallint; { Maximum resolution - ABSOLUTE }
  88. MaxColor : Longint;
  89. PaletteSize : longint; { Maximum palette entry we can set, usually equal}
  90. { maxcolor. }
  91. HardwarePages : byte; { maximum number of hardware visual pages }
  92. DriverName: String;
  93. DirectColor : Boolean ; { Is it a direct color mode? }
  94. ModeList : PModeInfo;
  95. newModeList: TNewModeInfo;
  96. DirectVideo : Boolean; { Direct access to video memory? }
  97. {--------------------------------------------------------------------------}
  98. { }
  99. { LINE AND LINE RELATED ROUTINES }
  100. { }
  101. {--------------------------------------------------------------------------}
  102. {$i clip.inc}
  103. procedure HLineDefault(x,x2,y: smallint); {$ifndef fpc}far;{$endif fpc}
  104. var
  105. xtmp: smallint;
  106. Begin
  107. { must we swap the values? }
  108. if x >= x2 then
  109. Begin
  110. xtmp := x2;
  111. x2 := x;
  112. x:= xtmp;
  113. end;
  114. { First convert to global coordinates }
  115. X := X + StartXViewPort;
  116. X2 := X2 + StartXViewPort;
  117. Y := Y + StartYViewPort;
  118. if ClipPixels then
  119. Begin
  120. if LineClipped(x,y,x2,y,StartXViewPort,StartYViewPort,
  121. StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
  122. exit;
  123. end;
  124. for x:= x to x2 do
  125. DirectPutPixel(X,Y);
  126. end;
  127. procedure VLineDefault(x,y,y2: smallint); {$ifndef fpc}far;{$endif fpc}
  128. var
  129. ytmp: smallint;
  130. Begin
  131. { must we swap the values? }
  132. if y >= y2 then
  133. Begin
  134. ytmp := y2;
  135. y2 := y;
  136. y:= ytmp;
  137. end;
  138. { First convert to global coordinates }
  139. X := X + StartXViewPort;
  140. Y2 := Y2 + StartYViewPort;
  141. Y := Y + StartYViewPort;
  142. if ClipPixels then
  143. Begin
  144. if LineClipped(x,y,x,y2,StartXViewPort,StartYViewPort,
  145. StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
  146. exit;
  147. end;
  148. for y := y to y2 do Directputpixel(x,y)
  149. End;
  150. Procedure DirectPutPixelClip(x,y: smallint);
  151. { for thickwidth lines, because they may call DirectPutPixel for coords }
  152. { outside the current viewport (bug found by CEC) }
  153. Begin
  154. If (Not ClipPixels) Or
  155. ((X >= StartXViewPort) And (X <= (StartXViewPort + ViewWidth)) And
  156. (Y >= StartYViewPort) And (Y <= (StartYViewPort + ViewHeight))) then
  157. Begin
  158. DirectPutPixel(x,y)
  159. End
  160. End;
  161. procedure LineDefault(X1, Y1, X2, Y2: smallint); {$ifndef fpc}far;{$endif fpc}
  162. var X, Y : smallint;
  163. deltax, deltay : smallint;
  164. d, dinc1, dinc2: smallint;
  165. xinc1 : smallint;
  166. xinc2 : smallint;
  167. yinc1 : smallint;
  168. yinc2 : smallint;
  169. i : smallint;
  170. Flag : Boolean; { determines pixel direction in thick lines }
  171. NumPixels : smallint;
  172. PixelCount : smallint;
  173. OldCurrentColor: Word;
  174. swtmp : smallint;
  175. TmpNumPixels : smallint;
  176. begin
  177. {******************************************}
  178. { SOLID LINES }
  179. {******************************************}
  180. if lineinfo.LineStyle = SolidLn then
  181. Begin
  182. { we separate normal and thick width for speed }
  183. { and because it would not be 100% compatible }
  184. { with the TP graph unit otherwise }
  185. if y1 = y2 then
  186. Begin
  187. {******************************************}
  188. { SOLID LINES HORIZONTAL }
  189. {******************************************}
  190. if lineinfo.Thickness=NormWidth then
  191. hline(x1,x2,y2)
  192. else
  193. begin
  194. { thick width }
  195. hline(x1,x2,y2-1);
  196. hline(x1,x2,y2);
  197. hline(x2,x2,y2+1);
  198. end;
  199. end
  200. else
  201. if x1 = x2 then
  202. Begin
  203. {******************************************}
  204. { SOLID LINES VERTICAL }
  205. {******************************************}
  206. if lineinfo.Thickness=NormWidth then
  207. vline(x1,y1,y2)
  208. else
  209. begin
  210. { thick width }
  211. vline(x1-1,y1,y2);
  212. vline(x1,y1,y2);
  213. vline(x1+1,y1,y2);
  214. end;
  215. end
  216. else
  217. begin
  218. { Convert to global coordinates. }
  219. x1 := x1 + StartXViewPort;
  220. x2 := x2 + StartXViewPort;
  221. y1 := y1 + StartYViewPort;
  222. y2 := y2 + StartYViewPort;
  223. { if fully clipped then exit... }
  224. if ClipPixels then
  225. begin
  226. if LineClipped(x1,y1,x2,y2,StartXViewPort, StartYViewPort,
  227. StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
  228. exit;
  229. end;
  230. {******************************************}
  231. { SLOPED SOLID LINES }
  232. {******************************************}
  233. oldCurrentColor :=
  234. CurrentColor;
  235. { Calculate deltax and deltay for initialisation }
  236. deltax := abs(x2 - x1);
  237. deltay := abs(y2 - y1);
  238. { Initialize all vars based on which is the independent variable }
  239. if deltax >= deltay then
  240. begin
  241. Flag := FALSE;
  242. { x is independent variable }
  243. numpixels := deltax + 1;
  244. d := (2 * deltay) - deltax;
  245. dinc1 := deltay Shl 1;
  246. dinc2 := (deltay - deltax) shl 1;
  247. xinc1 := 1;
  248. xinc2 := 1;
  249. yinc1 := 0;
  250. yinc2 := 1;
  251. end
  252. else
  253. begin
  254. Flag := TRUE;
  255. { y is independent variable }
  256. numpixels := deltay + 1;
  257. d := (2 * deltax) - deltay;
  258. dinc1 := deltax Shl 1;
  259. dinc2 := (deltax - deltay) shl 1;
  260. xinc1 := 0;
  261. xinc2 := 1;
  262. yinc1 := 1;
  263. yinc2 := 1;
  264. end;
  265. { Make sure x and y move in the right directions }
  266. if x1 > x2 then
  267. begin
  268. xinc1 := - xinc1;
  269. xinc2 := - xinc2;
  270. end;
  271. if y1 > y2 then
  272. begin
  273. yinc1 := - yinc1;
  274. yinc2 := - yinc2;
  275. end;
  276. { Start drawing at <x1, y1> }
  277. x := x1;
  278. y := y1;
  279. If LineInfo.Thickness=NormWidth then
  280. Begin
  281. { Draw the pixels }
  282. for i := 1 to numpixels do
  283. begin
  284. DirectPutPixel(x, y);
  285. if d < 0 then
  286. begin
  287. d := d + dinc1;
  288. x := x + xinc1;
  289. y := y + yinc1;
  290. end
  291. else
  292. begin
  293. d := d + dinc2;
  294. x := x + xinc2;
  295. y := y + yinc2;
  296. end;
  297. CurrentColor := OldCurrentColor;
  298. end;
  299. end
  300. else
  301. { Thick width lines }
  302. begin
  303. { Draw the pixels }
  304. for i := 1 to numpixels do
  305. begin
  306. { all depending on the slope, we can determine }
  307. { in what direction the extra width pixels will be put }
  308. If Flag then
  309. Begin
  310. DirectPutPixelClip(x-1,y);
  311. DirectPutPixelClip(x,y);
  312. DirectPutPixelClip(x+1,y);
  313. end
  314. else
  315. Begin
  316. DirectPutPixelClip(x, y-1);
  317. DirectPutPixelClip(x, y);
  318. DirectPutPixelClip(x, y+1);
  319. end;
  320. if d < 0 then
  321. begin
  322. d := d + dinc1;
  323. x := x + xinc1;
  324. y := y + yinc1;
  325. end
  326. else
  327. begin
  328. d := d + dinc2;
  329. x := x + xinc2;
  330. y := y + yinc2;
  331. end;
  332. CurrentColor := OldCurrentColor;
  333. end;
  334. end;
  335. end;
  336. end
  337. else
  338. {******************************************}
  339. { begin patterned lines }
  340. {******************************************}
  341. Begin
  342. { Convert to global coordinates. }
  343. x1 := x1 + StartXViewPort;
  344. x2 := x2 + StartXViewPort;
  345. y1 := y1 + StartYViewPort;
  346. y2 := y2 + StartYViewPort;
  347. { if fully clipped then exit... }
  348. if ClipPixels then
  349. begin
  350. if LineClipped(x1,y1,x2,y2,StartXViewPort, StartYViewPort,
  351. StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
  352. exit;
  353. end;
  354. OldCurrentColor := CurrentColor;
  355. PixelCount:=0;
  356. if y1 = y2 then
  357. Begin
  358. { Check if we must swap }
  359. if x1 >= x2 then
  360. Begin
  361. swtmp := x1;
  362. x1 := x2;
  363. x2 := swtmp;
  364. end;
  365. if LineInfo.Thickness = NormWidth then
  366. Begin
  367. for PixelCount:=x1 to x2 do
  368. { optimization: PixelCount mod 16 }
  369. if LinePatterns[PixelCount and 15] = TRUE then
  370. begin
  371. DirectPutPixel(PixelCount,y2);
  372. end;
  373. end
  374. else
  375. Begin
  376. for i:=-1 to 1 do
  377. Begin
  378. for PixelCount:=x1 to x2 do
  379. { Optimization from Thomas - mod 16 = and 15 }
  380. {this optimization has been performed by the compiler
  381. for while as well (JM)}
  382. if LinePatterns[PixelCount and 15] = TRUE then
  383. begin
  384. DirectPutPixelClip(PixelCount,y2+i);
  385. end;
  386. end;
  387. end;
  388. end
  389. else
  390. if x1 = x2 then
  391. Begin
  392. { Check if we must swap }
  393. if y1 >= y2 then
  394. Begin
  395. swtmp := y1;
  396. y1 := y2;
  397. y2 := swtmp;
  398. end;
  399. if LineInfo.Thickness = NormWidth then
  400. Begin
  401. for PixelCount:=y1 to y2 do
  402. { compare if we should plot a pixel here , compare }
  403. { with predefined line patterns... }
  404. if LinePatterns[PixelCount and 15] = TRUE then
  405. begin
  406. DirectPutPixel(x1,PixelCount);
  407. end;
  408. end
  409. else
  410. Begin
  411. for i:=-1 to 1 do
  412. Begin
  413. for PixelCount:=y1 to y2 do
  414. { compare if we should plot a pixel here , compare }
  415. { with predefined line patterns... }
  416. if LinePatterns[PixelCount and 15] = TRUE then
  417. begin
  418. DirectPutPixelClip(x1+i,PixelCount);
  419. end;
  420. end;
  421. end;
  422. end
  423. else
  424. Begin
  425. oldCurrentColor := CurrentColor;
  426. { Calculate deltax and deltay for initialisation }
  427. deltax := abs(x2 - x1);
  428. deltay := abs(y2 - y1);
  429. { Initialize all vars based on which is the independent variable }
  430. if deltax >= deltay then
  431. begin
  432. Flag := FALSE;
  433. { x is independent variable }
  434. numpixels := deltax + 1;
  435. d := (2 * deltay) - deltax;
  436. dinc1 := deltay Shl 1;
  437. dinc2 := (deltay - deltax) shl 1;
  438. xinc1 := 1;
  439. xinc2 := 1;
  440. yinc1 := 0;
  441. yinc2 := 1;
  442. end
  443. else
  444. begin
  445. Flag := TRUE;
  446. { y is independent variable }
  447. numpixels := deltay + 1;
  448. d := (2 * deltax) - deltay;
  449. dinc1 := deltax Shl 1;
  450. dinc2 := (deltax - deltay) shl 1;
  451. xinc1 := 0;
  452. xinc2 := 1;
  453. yinc1 := 1;
  454. yinc2 := 1;
  455. end;
  456. { Make sure x and y move in the right directions }
  457. if x1 > x2 then
  458. begin
  459. xinc1 := - xinc1;
  460. xinc2 := - xinc2;
  461. end;
  462. if y1 > y2 then
  463. begin
  464. yinc1 := - yinc1;
  465. yinc2 := - yinc2;
  466. end;
  467. { Start drawing at <x1, y1> }
  468. x := x1;
  469. y := y1;
  470. If LineInfo.Thickness=ThickWidth then
  471. Begin
  472. TmpNumPixels := NumPixels-1;
  473. { Draw the pixels }
  474. for i := 0 to TmpNumPixels do
  475. begin
  476. { all depending on the slope, we can determine }
  477. { in what direction the extra width pixels will be put }
  478. If Flag then
  479. Begin
  480. { compare if we should plot a pixel here , compare }
  481. { with predefined line patterns... }
  482. if LinePatterns[i and 15] = TRUE then
  483. begin
  484. DirectPutPixelClip(x-1,y);
  485. DirectPutPixelClip(x,y);
  486. DirectPutPixelClip(x+1,y);
  487. end;
  488. end
  489. else
  490. Begin
  491. { compare if we should plot a pixel here , compare }
  492. { with predefined line patterns... }
  493. if LinePatterns[i and 15] = TRUE then
  494. begin
  495. DirectPutPixelClip(x,y-1);
  496. DirectPutPixelClip(x,y);
  497. DirectPutPixelClip(x,y+1);
  498. end;
  499. end;
  500. if d < 0 then
  501. begin
  502. d := d + dinc1;
  503. x := x + xinc1;
  504. y := y + yinc1;
  505. end
  506. else
  507. begin
  508. d := d + dinc2;
  509. x := x + xinc2;
  510. y := y + yinc2;
  511. end;
  512. end;
  513. end
  514. else
  515. Begin
  516. { instead of putting in loop , substract by one now }
  517. TmpNumPixels := NumPixels-1;
  518. { NormWidth }
  519. for i := 0 to TmpNumPixels do
  520. begin
  521. if LinePatterns[i and 15] = TRUE then
  522. begin
  523. DirectPutPixel(x,y);
  524. end;
  525. if d < 0 then
  526. begin
  527. d := d + dinc1;
  528. x := x + xinc1;
  529. y := y + yinc1;
  530. end
  531. else
  532. begin
  533. d := d + dinc2;
  534. x := x + xinc2;
  535. y := y + yinc2;
  536. end;
  537. end;
  538. end
  539. end;
  540. {******************************************}
  541. { end patterned lines }
  542. {******************************************}
  543. { restore color }
  544. CurrentColor:=OldCurrentColor;
  545. end;
  546. end; { Line }
  547. {********************************************************}
  548. { Procedure DummyPatternLine() }
  549. {--------------------------------------------------------}
  550. { This is suimply an procedure that does nothing which }
  551. { can be passed as a patternlineproc for non-filled }
  552. { ellipses }
  553. {********************************************************}
  554. Procedure DummyPatternLine(x1, x2, y: smallint); {$ifdef tp} far; {$endif tp}
  555. begin
  556. end;
  557. {********************************************************}
  558. { Procedure InternalEllipse() }
  559. {--------------------------------------------------------}
  560. { This routine first calculates all points required to }
  561. { draw a circle to the screen, and stores the points }
  562. { to display in a buffer before plotting them. The }
  563. { aspect ratio of the screen is taken into account when }
  564. { calculating the values. }
  565. {--------------------------------------------------------}
  566. { INPUTS: X,Y : Center coordinates of Ellipse. }
  567. { XRadius - X-Axis radius of ellipse. }
  568. { YRadius - Y-Axis radius of ellipse. }
  569. { stAngle, EndAngle: Start angle and end angles of the }
  570. { ellipse (used for partial ellipses and circles) }
  571. { pl: procedure which either draws a patternline (for }
  572. { FillEllipse) or does nothing (arc etc) }
  573. {--------------------------------------------------------}
  574. { NOTE: - }
  575. { - }
  576. {********************************************************}
  577. Procedure InternalEllipseDefault(X,Y: smallint;XRadius: word;
  578. YRadius:word; stAngle,EndAngle: word; pl: PatternLineProc); {$ifndef fpc}far;{$endif fpc}
  579. Const ConvFac = Pi/180.0;
  580. var
  581. j, Delta, DeltaEnd: graph_float;
  582. NumOfPixels: longint;
  583. TempTerm: graph_float;
  584. xtemp, ytemp, xp, yp, xm, ym, xnext, ynext,
  585. plxpyp, plxmyp, plxpym, plxmym: smallint;
  586. BackupColor, TmpAngle, OldLineWidth: word;
  587. Begin
  588. If LineInfo.ThickNess = ThickWidth Then
  589. { first draw the two outer ellipses using normwidth and no filling (JM) }
  590. Begin
  591. OldLineWidth := LineInfo.Thickness;
  592. LineInfo.Thickness := NormWidth;
  593. InternalEllipseDefault(x,y,XRadius,YRadius,StAngle,EndAngle,
  594. {$ifdef fpc}@{$endif fpc}DummyPatternLine);
  595. InternalEllipseDefault(x,y,XRadius+1,YRadius+1,StAngle,EndAngle,
  596. {$ifdef fpc}@{$endif fpc}DummyPatternLine);
  597. If (XRadius > 0) and (YRadius > 0) Then
  598. { draw the smallest ellipse last, since that one will use the }
  599. { original pl, so it could possibly draw patternlines (JM) }
  600. Begin
  601. Dec(XRadius);
  602. Dec(YRadius);
  603. End
  604. Else Exit;
  605. { restore line thickness }
  606. LineInfo.Thickness := OldLineWidth;
  607. End;
  608. { Adjust for screen aspect ratio }
  609. XRadius:=(longint(XRadius)*10000) div XAspect;
  610. YRadius:=(longint(YRadius)*10000) div YAspect;
  611. If xradius = 0 then inc(xradius);
  612. if yradius = 0 then inc(yradius);
  613. { check for an ellipse with negligable x and y radius }
  614. If (xradius <= 1) and (yradius <= 1) then
  615. begin
  616. putpixel(x,y,CurrentColor);
  617. ArcCall.X := X;
  618. ArcCall.Y := Y;
  619. ArcCall.XStart := X;
  620. ArcCall.YStart := Y;
  621. ArcCall.XEnd := X;
  622. ArcCall.YEnd := Y;
  623. exit;
  624. end;
  625. { check if valid angles }
  626. stangle := stAngle mod 361;
  627. EndAngle := EndAngle mod 361;
  628. { if impossible angles then swap them! }
  629. if Endangle < StAngle then
  630. Begin
  631. TmpAngle:=EndAngle;
  632. EndAngle:=StAngle;
  633. Stangle:=TmpAngle;
  634. end;
  635. { approximate the number of pixels required by using the circumference }
  636. { equation of an ellipse. }
  637. { Changed this formula a it (trial and error), but the net result is that }
  638. { less pixels have to be calculated now }
  639. NumOfPixels:=Round(Sqrt(3)*sqrt(sqr(XRadius)+sqr(YRadius)));
  640. { Calculate the angle precision required }
  641. Delta := 90.0 / NumOfPixels;
  642. { for restoring after PatternLine }
  643. BackupColor := CurrentColor;
  644. { removed from inner loop to make faster }
  645. { store some arccall info }
  646. ArcCall.X := X;
  647. ArcCall.Y := Y;
  648. TempTerm := (StAngle)*ConvFac;
  649. ArcCall.XStart := round(XRadius*Cos(TempTerm)) + X;
  650. ArcCall.YStart := round(YRadius*Sin(TempTerm+Pi)) + Y;
  651. TempTerm := (EndAngle)*ConvFac;
  652. ArcCall.XEnd := round(XRadius*Cos(TempTerm)) + X;
  653. ArcCall.YEnd := round(YRadius*Sin(TempTerm+Pi)) + Y;
  654. { Always just go over the first 90 degrees. Could be optimized a }
  655. { bit if StAngle and EndAngle lie in the same quadrant, left as an }
  656. { exercise for the reader :) (JM) }
  657. j := 0;
  658. { calculate stop position, go 1 further than 90 because otherwise }
  659. { 1 pixel is sometimes not drawn (JM) }
  660. DeltaEnd := 91;
  661. { Calculate points }
  662. xnext := XRadius;
  663. ynext := 0;
  664. Repeat
  665. xtemp := xnext;
  666. ytemp := ynext;
  667. { this is used by both sin and cos }
  668. TempTerm := (j+Delta)*ConvFac;
  669. { Calculate points }
  670. xnext := round(XRadius*Cos(TempTerm));
  671. ynext := round(YRadius*Sin(TempTerm+Pi));
  672. xp := x + xtemp;
  673. xm := x - xtemp;
  674. yp := y + ytemp;
  675. ym := y - ytemp;
  676. plxpyp := maxsmallint;
  677. plxmyp := -maxsmallint-1;
  678. plxpym := maxsmallint;
  679. plxmym := -maxsmallint-1;
  680. If (j >= StAngle) and (j <= EndAngle) then
  681. begin
  682. plxpyp := xp;
  683. PutPixel(xp,yp,CurrentColor);
  684. end;
  685. If ((180-j) >= StAngle) and ((180-j) <= EndAngle) then
  686. begin
  687. plxmyp := xm;
  688. PutPixel(xm,yp,CurrentColor);
  689. end;
  690. If ((j+180) >= StAngle) and ((j+180) <= EndAngle) then
  691. begin
  692. plxmym := xm;
  693. PutPixel(xm,ym,CurrentColor);
  694. end;
  695. If ((360-j) >= StAngle) and ((360-j) <= EndAngle) then
  696. begin
  697. plxpym := xp;
  698. PutPixel(xp,ym,CurrentColor);
  699. end;
  700. If (ynext <> ytemp) and
  701. (xp - xm >= 1) then
  702. begin
  703. CurrentColor := FillSettings.Color;
  704. pl(plxmyp+1,plxpyp-1,yp);
  705. pl(plxmym+1,plxpym-1,ym);
  706. CurrentColor := BackupColor;
  707. end;
  708. j:=j+Delta;
  709. Until j > (DeltaEnd);
  710. end;
  711. procedure PatternLineDefault(x1,x2,y: smallint); {$ifndef fpc}far;{$endif fpc}
  712. {********************************************************}
  713. { Draws a horizontal patterned line according to the }
  714. { current Fill Settings. }
  715. {********************************************************}
  716. { Important notes: }
  717. { - CurrentColor must be set correctly before entering }
  718. { this routine. }
  719. {********************************************************}
  720. var
  721. NrIterations: smallint;
  722. i : smallint;
  723. j : smallint;
  724. TmpFillPattern : byte;
  725. OldWriteMode : word;
  726. OldCurrentColor : word;
  727. begin
  728. { convert to global coordinates ... }
  729. x1 := x1 + StartXViewPort;
  730. x2 := x2 + StartXViewPort;
  731. y := y + StartYViewPort;
  732. { if line was fully clipped then exit...}
  733. if LineClipped(x1,y,x2,y,StartXViewPort,StartYViewPort,
  734. StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
  735. exit;
  736. OldWriteMode := CurrentWriteMode;
  737. CurrentWriteMode := NormalPut;
  738. { Get the current pattern }
  739. TmpFillPattern := FillPatternTable
  740. [FillSettings.Pattern][(y and $7)+1];
  741. Case TmpFillPattern Of
  742. 0:
  743. begin
  744. OldCurrentColor := CurrentColor;
  745. CurrentColor := CurrentBkColor;
  746. { hline converts the coordinates to global ones, but that has been done }
  747. { already here!!! Convert them back to local ones... (JM) }
  748. HLine(x1-StartXViewPort,x2-StartXViewPort,y-StartYViewPort);
  749. CurrentColor := OldCurrentColor;
  750. end;
  751. $ff:
  752. begin
  753. HLine(x1-StartXViewPort,x2-StartXViewPort,y-StartYViewPort);
  754. end;
  755. else
  756. begin
  757. { number of times to go throuh the 8x8 pattern }
  758. NrIterations := abs(x2 - x1+8) div 8;
  759. For i:= 0 to NrIterations do
  760. Begin
  761. for j:=0 to 7 do
  762. Begin
  763. { x1 mod 8 }
  764. if RevBitArray[x1 and 7] and TmpFillPattern <> 0 then
  765. DirectPutpixel(x1,y)
  766. else
  767. begin
  768. { According to the TP graph manual, we overwrite everything }
  769. { which is filled up - checked against VGA and CGA drivers }
  770. { of TP. }
  771. OldCurrentColor := CurrentColor;
  772. CurrentColor := CurrentBkColor;
  773. DirectPutPixel(x1,y);
  774. CurrentColor := OldCurrentColor;
  775. end;
  776. Inc(x1);
  777. if x1 > x2 then
  778. begin
  779. CurrentWriteMode := OldWriteMode;
  780. exit;
  781. end;
  782. end;
  783. end;
  784. end;
  785. End;
  786. CurrentWriteMode := OldWriteMode;
  787. end;
  788. procedure LineRel(Dx, Dy: smallint);
  789. Begin
  790. Line(CurrentX, CurrentY, CurrentX + Dx, CurrentY + Dy);
  791. CurrentX := CurrentX + Dx;
  792. CurrentY := CurrentY + Dy;
  793. end;
  794. procedure LineTo(x,y : smallint);
  795. Begin
  796. Line(CurrentX, CurrentY, X, Y);
  797. CurrentX := X;
  798. CurrentY := Y;
  799. end;
  800. procedure Rectangle(x1,y1,x2,y2:smallint);
  801. begin
  802. { Do not draw the end points }
  803. Line(x1,y1,x2-1,y1);
  804. Line(x1,y1+1,x1,y2);
  805. Line(x2,y1,x2,y2-1);
  806. Line(x1+1,y2,x2,y2);
  807. end;
  808. procedure GetLineSettings(var ActiveLineInfo : LineSettingsType);
  809. begin
  810. Activelineinfo:=Lineinfo;
  811. end;
  812. procedure SetLineStyle(LineStyle: word; Pattern: word; Thickness: word);
  813. var
  814. i: byte;
  815. j: byte;
  816. Begin
  817. if (LineStyle > UserBitLn) or ((Thickness <> Normwidth) and (Thickness <> ThickWidth)) then
  818. _GraphResult := grError
  819. else
  820. begin
  821. LineInfo.Thickness := Thickness;
  822. LineInfo.LineStyle := LineStyle;
  823. case LineStyle of
  824. UserBitLn: Lineinfo.Pattern := pattern;
  825. SolidLn: Lineinfo.Pattern := $ffff; { ------- }
  826. DashedLn : Lineinfo.Pattern := $F8F8; { -- -- --}
  827. DottedLn: LineInfo.Pattern := $CCCC; { - - - - }
  828. CenterLn: LineInfo.Pattern := $FC78; { -- - -- }
  829. end; { end case }
  830. { setup pattern styles }
  831. j:=16;
  832. for i:=0 to 15 do
  833. Begin
  834. dec(j);
  835. { bitwise mask for each bit in the word }
  836. if (word($01 shl i) AND LineInfo.Pattern) <> 0 then
  837. LinePatterns[j]:=TRUE
  838. else
  839. LinePatterns[j]:=FALSE;
  840. end;
  841. end;
  842. end;
  843. {--------------------------------------------------------------------------}
  844. { }
  845. { VIEWPORT RELATED ROUTINES }
  846. { }
  847. {--------------------------------------------------------------------------}
  848. Procedure ClearViewPortDefault; {$ifndef fpc}far;{$endif fpc}
  849. var
  850. j: smallint;
  851. OldWriteMode, OldCurColor: word;
  852. LineSets : LineSettingsType;
  853. Begin
  854. { CP is always RELATIVE coordinates }
  855. CurrentX := 0;
  856. CurrentY := 0;
  857. { Save all old settings }
  858. OldCurColor := CurrentColor;
  859. CurrentColor:=CurrentBkColor;
  860. OldWriteMode:=CurrentWriteMode;
  861. CurrentWriteMode:=NormalPut;
  862. GetLineSettings(LineSets);
  863. { reset to normal line style...}
  864. SetLineStyle(SolidLn, 0, NormWidth);
  865. { routines are relative here...}
  866. { ViewHeight is Height-1 ! }
  867. for J:=0 to ViewHeight do
  868. HLine(0, ViewWidth , J);
  869. { restore old settings...}
  870. SetLineStyle(LineSets.LineStyle, LineSets.Pattern, LineSets.Thickness);
  871. CurrentColor := OldCurColor;
  872. CurrentWriteMode := OldWriteMode;
  873. end;
  874. Procedure SetViewPort(X1, Y1, X2, Y2: smallint; Clip: Boolean);
  875. Begin
  876. if (X1 > GetMaxX) or (X2 > GetMaxX) or (X1 > X2) or (X1 < 0) then
  877. Begin
  878. {$ifdef logging}
  879. logln('invalid setviewport parameters: ('
  880. +strf(x1)+','+strf(y1)+'), ('+strf(x2)+','+strf(y2)+')');
  881. logln('maxx = '+strf(getmaxx)+', maxy = '+strf(getmaxy));
  882. {$endif logging}
  883. _GraphResult := grError;
  884. exit;
  885. end;
  886. if (Y1 > GetMaxY) or (Y2 > GetMaxY) or (Y1 > Y2) or (Y1 < 0) then
  887. Begin
  888. {$ifdef logging}
  889. logln('invalid setviewport parameters: ('
  890. +strf(x1)+','+strf(y1)+'), ('+strf(x2)+','+strf(y2)+')');
  891. logln('maxx = '+strf(getmaxx)+', maxy = '+strf(getmaxy));
  892. {$endif logging}
  893. _GraphResult := grError;
  894. exit;
  895. end;
  896. { CP is always RELATIVE coordinates }
  897. CurrentX := 0;
  898. CurrentY := 0;
  899. StartXViewPort := X1;
  900. StartYViewPort := Y1;
  901. ViewWidth := X2-X1;
  902. ViewHeight:= Y2-Y1;
  903. ClipPixels := Clip;
  904. end;
  905. procedure GetViewSettings(var viewport : ViewPortType);
  906. begin
  907. ViewPort.X1 := StartXViewPort;
  908. ViewPort.Y1 := StartYViewPort;
  909. ViewPort.X2 := ViewWidth + StartXViewPort;
  910. ViewPort.Y2 := ViewHeight + StartYViewPort;
  911. ViewPort.Clip := ClipPixels;
  912. end;
  913. procedure ClearDevice;
  914. var
  915. ViewPort: ViewPortType;
  916. begin
  917. { Reset the CP }
  918. CurrentX := 0;
  919. CurrentY := 0;
  920. { save viewport }
  921. ViewPort.X1 := StartXviewPort;
  922. ViewPort.X2 := ViewWidth - StartXViewPort;
  923. ViewPort.Y1 := StartYViewPort;
  924. ViewPort.Y2 := ViewHeight - StartYViewPort;
  925. ViewPort.Clip := ClipPixels;
  926. { put viewport to full screen }
  927. StartXViewPort := 0;
  928. ViewHeight := MaxY;
  929. StartYViewPort := 0;
  930. ViewWidth := MaxX;
  931. ClipPixels := TRUE;
  932. ClearViewPort;
  933. { restore old viewport }
  934. StartXViewPort := ViewPort.X1;
  935. ViewWidth := ViewPort.X2-ViewPort.X1;
  936. StartYViewPort := ViewPort.Y1;
  937. ViewHeight := ViewPort.Y2-ViewPort.Y1;
  938. ClipPixels := ViewPort.Clip;
  939. end;
  940. {--------------------------------------------------------------------------}
  941. { }
  942. { BITMAP PUT/GET ROUTINES }
  943. { }
  944. {--------------------------------------------------------------------------}
  945. Procedure GetScanlineDefault (X1, X2, Y : smallint; Var Data); {$ifndef fpc}far;{$endif fpc}
  946. {**********************************************************}
  947. { Procedure GetScanLine() }
  948. {----------------------------------------------------------}
  949. { Returns the full scanline of the video line of the Y }
  950. { coordinate. The values are returned in a WORD array }
  951. { each WORD representing a pixel of the specified scanline }
  952. { note: we only need the pixels inside the ViewPort! (JM) }
  953. { note2: extended so you can specify start and end X coord }
  954. { so it is usable for GetImage too (JM) }
  955. {**********************************************************}
  956. Var
  957. x : smallint;
  958. Begin
  959. For x:=X1 to X2 Do
  960. WordArray(Data)[x-x1]:=GetPixel(x, y);
  961. End;
  962. Function DefaultImageSize(X1,Y1,X2,Y2: smallint): longint; {$ifndef fpc}far;{$endif fpc}
  963. Begin
  964. { each pixel uses two bytes, to enable modes with colors up to 64K }
  965. { to work. }
  966. DefaultImageSize := 12 + (((X2-X1+1)*(Y2-Y1+1))*2);
  967. end;
  968. Procedure DefaultPutImage(X,Y: smallint; var Bitmap; BitBlt: Word); {$ifndef fpc}far;{$endif fpc}
  969. type
  970. pt = array[0..$fffffff] of word;
  971. ptw = array[0..2] of longint;
  972. var
  973. k: longint;
  974. oldCurrentColor: word;
  975. oldCurrentWriteMode, i, j, y1, x1, deltaX, deltaX1, deltaY: smallint;
  976. Begin
  977. {$ifdef logging}
  978. LogLn('putImage at ('+strf(x)+','+strf(y)+') with width '+strf(ptw(Bitmap)[0])+
  979. ' and height '+strf(ptw(Bitmap)[1]));
  980. deltaY := 0;
  981. {$endif logging}
  982. inc(x,startXViewPort);
  983. inc(y,startYViewPort);
  984. { width/height are 1-based, coordinates are zero based }
  985. x1 := ptw(Bitmap)[0]+x-1; { get width and adjust end coordinate accordingly }
  986. y1 := ptw(Bitmap)[1]+y-1; { get height and adjust end coordinate accordingly }
  987. deltaX := 0;
  988. deltaX1 := 0;
  989. k := 3 * sizeOf(Longint) div sizeOf(Word); { Three reserved longs at start of bitmap }
  990. { check which part of the image is in the viewport }
  991. if clipPixels then
  992. begin
  993. if y < startYViewPort then
  994. begin
  995. deltaY := startYViewPort - y;
  996. inc(k,(x1-x+1)*deltaY);
  997. y := startYViewPort;
  998. end;
  999. if y1 > startYViewPort+viewHeight then
  1000. y1 := startYViewPort+viewHeight;
  1001. if x < startXViewPort then
  1002. begin
  1003. deltaX := startXViewPort-x;
  1004. x := startXViewPort;
  1005. end;
  1006. if x1 > startXViewPort + viewWidth then
  1007. begin
  1008. deltaX1 := x1 - (startXViewPort + viewWidth);
  1009. x1 := startXViewPort + viewWidth;
  1010. end;
  1011. end;
  1012. {$ifdef logging}
  1013. LogLn('deltax: '+strf(deltax)+', deltax1: '+strf(deltax1)+',deltay: '+strf(deltay));
  1014. {$endif logging}
  1015. oldCurrentColor := currentColor;
  1016. oldCurrentWriteMode := currentWriteMode;
  1017. currentWriteMode := bitBlt;
  1018. for j:=Y to Y1 do
  1019. Begin
  1020. inc(k,deltaX);
  1021. for i:=X to X1 do
  1022. begin
  1023. currentColor := pt(bitmap)[k];
  1024. directPutPixel(i,j);
  1025. inc(k);
  1026. end;
  1027. inc(k,deltaX1);
  1028. end;
  1029. currentWriteMode := oldCurrentWriteMode;
  1030. currentColor := oldCurrentColor;
  1031. end;
  1032. Procedure DefaultGetImage(X1,Y1,X2,Y2: smallint; Var Bitmap); {$ifndef fpc}far;{$endif fpc}
  1033. type
  1034. pt = array[0..$fffffff] of word;
  1035. ptw = array[0..2] of longint;
  1036. var
  1037. i,j: smallint;
  1038. k: longint;
  1039. Begin
  1040. k:= 3 * Sizeof(longint) div sizeof(word); { Three reserved longs at start of bitmap }
  1041. i := x2 - x1 + 1;
  1042. for j:=Y1 to Y2 do
  1043. Begin
  1044. GetScanLine(x1,x2,j,pt(Bitmap)[k]);
  1045. inc(k,i);
  1046. end;
  1047. ptw(Bitmap)[0] := X2-X1+1; { First longint is width }
  1048. ptw(Bitmap)[1] := Y2-Y1+1; { Second longint is height }
  1049. ptw(bitmap)[2] := 0; { Third longint is reserved}
  1050. end;
  1051. Procedure GetArcCoords(var ArcCoords: ArcCoordsType);
  1052. Begin
  1053. ArcCoords.X := ArcCall.X;
  1054. ArcCoords.Y := ArcCall.Y;
  1055. ArcCoords.XStart := ArcCall.XStart;
  1056. ArcCoords.YStart := ArcCall.YStart;
  1057. ArcCoords.XEnd := ArcCall.XEnd;
  1058. ArcCoords.YEnd := ArcCall.YEnd;
  1059. end;
  1060. procedure SetVisualPageDefault(page : word); {$ifndef fpc}far;{$endif fpc}
  1061. begin
  1062. end;
  1063. procedure SetActivePageDefault(page : word); {$ifndef fpc}far;{$endif fpc}
  1064. begin
  1065. end;
  1066. procedure DirectPutPixelDefault(X,Y: smallint);
  1067. begin
  1068. Writeln(stderr,'Error: Not in graphics mode (use InitGraph and test GraphResult afterwards)');
  1069. Halt(1);
  1070. end;
  1071. function GetPixelDefault(X,Y: smallint): word;
  1072. begin
  1073. Writeln(stderr,'Error: Not in graphics mode (use InitGraph and test GraphResult afterwards)');
  1074. Halt(1);
  1075. exit(0); { avoid warning }
  1076. end;
  1077. procedure PutPixelDefault(X,Y: smallint; Color: Word);
  1078. begin
  1079. Writeln(stderr,'Error: Not in graphics mode (use InitGraph and test GraphResult afterwards)');
  1080. Halt(1);
  1081. end;
  1082. procedure SetRGBPaletteDefault(ColorNum, RedValue, GreenValue, BlueValue: smallint);
  1083. begin
  1084. Writeln(stderr,'Error: Not in graphics mode (use InitGraph and test GraphResult afterwards)');
  1085. Halt(1);
  1086. end;
  1087. procedure GetRGBPaletteDefault(ColorNum: smallint; var
  1088. RedValue, GreenValue, BlueValue: smallint);
  1089. begin
  1090. Writeln(stderr,'Error: Not in graphics mode (use InitGraph and test GraphResult afterwards)');
  1091. Halt(1);
  1092. end;
  1093. procedure OutTextXYDefault(x,y : smallint;const TextString : string);forward;
  1094. procedure CircleDefault(X, Y: smallint; Radius:Word);forward;
  1095. {$i palette.inc}
  1096. Procedure DefaultHooks;
  1097. {********************************************************}
  1098. { Procedure DefaultHooks() }
  1099. {--------------------------------------------------------}
  1100. { Resets all hookable routine either to nil for those }
  1101. { which need overrides, and others to defaults. }
  1102. { This is called each time SetGraphMode() is called. }
  1103. {********************************************************}
  1104. Begin
  1105. { All default hooks procedures }
  1106. { required...}
  1107. DirectPutPixel := {$ifdef fpc}@{$endif}DirectPutPixelDefault;
  1108. PutPixel := {$ifdef fpc}@{$endif}PutPixelDefault;
  1109. GetPixel := {$ifdef fpc}@{$endif}GetPixelDefault;
  1110. SetRGBPalette := {$ifdef fpc}@{$endif}SetRGBPaletteDefault;
  1111. GetRGBPalette := {$ifdef fpc}@{$endif}GetRGBPaletteDefault;
  1112. { optional...}
  1113. SetAllPalette := {$ifdef fpc}@{$endif}SetAllPaletteDefault;
  1114. SetActivePage := {$ifdef fpc}@{$endif}SetActivePageDefault;
  1115. SetVisualPage := {$ifdef fpc}@{$endif}SetVisualPageDefault;
  1116. ClearViewPort := {$ifdef fpc}@{$endif}ClearViewportDefault;
  1117. PutImage := {$ifdef fpc}@{$endif}DefaultPutImage;
  1118. GetImage := {$ifdef fpc}@{$endif}DefaultGetImage;
  1119. ImageSize := {$ifdef fpc}@{$endif}DefaultImageSize;
  1120. GraphFreeMemPtr := nil;
  1121. GraphGetMemPtr := nil;
  1122. GetScanLine := {$ifdef fpc}@{$endif}GetScanLineDefault;
  1123. Line := {$ifdef fpc}@{$endif}LineDefault;
  1124. InternalEllipse := {$ifdef fpc}@{$endif}InternalEllipseDefault;
  1125. PatternLine := {$ifdef fpc}@{$endif}PatternLineDefault;
  1126. HLine := {$ifdef fpc}@{$endif}HLineDefault;
  1127. VLine := {$ifdef fpc}@{$endif}VLineDefault;
  1128. OuttextXY := {$ifdef fpc}@{$endif}OuttextXYDefault;
  1129. Circle := {$ifdef fpc}@{$endif}CircleDefault;
  1130. end;
  1131. Procedure InitVars;
  1132. {********************************************************}
  1133. { Procedure InitVars() }
  1134. {--------------------------------------------------------}
  1135. { Resets all internal variables, and resets all }
  1136. { overridable routines. }
  1137. {********************************************************}
  1138. Begin
  1139. DirectVideo := TRUE; { By default use fastest access possible }
  1140. ArcCall.X := 0;
  1141. ArcCall.Y := 0;
  1142. ArcCall.XStart := 0;
  1143. ArcCall.YStart := 0;
  1144. ArcCall.XEnd := 0;
  1145. ArcCall.YEnd := 0;
  1146. { Reset to default values }
  1147. IntCurrentMode := 0;
  1148. IntCurrentDriver := 0;
  1149. IntCurrentNewDriver := 0;
  1150. XAspect := 0;
  1151. YAspect := 0;
  1152. MaxX := 0;
  1153. MaxY := 0;
  1154. MaxColor := 0;
  1155. PaletteSize := 0;
  1156. DirectColor := FALSE;
  1157. HardwarePages := 0;
  1158. if hardwarepages=0 then; { remove note }
  1159. DefaultHooks;
  1160. end;
  1161. {$i modes.inc}
  1162. function InstallUserDriver(Name: string; AutoDetectPtr: Pointer): smallint;
  1163. begin
  1164. _graphResult := grError;
  1165. InstallUserDriver:=grError;
  1166. end;
  1167. function RegisterBGIDriver(driver: pointer): smallint;
  1168. begin
  1169. _graphResult := grError;
  1170. RegisterBGIDriver:=grError;
  1171. end;
  1172. { ----------------------------------------------------------------- }
  1173. Procedure Arc(X,Y : smallint; StAngle,EndAngle,Radius: word);
  1174. { var
  1175. OldWriteMode: word;}
  1176. Begin
  1177. { Only if we are using thickwidths lines do we accept }
  1178. { XORput write modes. }
  1179. { OldWriteMode := CurrentWriteMode;
  1180. if (LineInfo.Thickness = NormWidth) then
  1181. CurrentWriteMode := NormalPut;}
  1182. InternalEllipse(X,Y,Radius,Radius,StAngle,Endangle,{$ifdef fpc}@{$endif}DummyPatternLine);
  1183. { CurrentWriteMode := OldWriteMode;}
  1184. end;
  1185. procedure Ellipse(X,Y : smallint; stAngle, EndAngle: word; XRadius,YRadius: word);
  1186. Begin
  1187. InternalEllipse(X,Y,XRadius,YRadius,StAngle,Endangle,{$ifdef fpc}@{$endif}DummyPatternLine);
  1188. end;
  1189. procedure FillEllipse(X, Y: smallint; XRadius, YRadius: Word);
  1190. {********************************************************}
  1191. { Procedure FillEllipse() }
  1192. {--------------------------------------------------------}
  1193. { Draws a filled ellipse using (X,Y) as a center point }
  1194. { and XRadius and YRadius as the horizontal and vertical }
  1195. { axes. The ellipse is filled with the current fill color}
  1196. { and fill style, and is bordered with the current color.}
  1197. {********************************************************}
  1198. begin
  1199. InternalEllipse(X,Y,XRadius,YRadius,0,360,PatternLine)
  1200. end;
  1201. procedure CircleDefault(X, Y: smallint; Radius:Word);
  1202. {********************************************************}
  1203. { Draws a circle centered at X,Y with the given Radius. }
  1204. {********************************************************}
  1205. { Important notes: }
  1206. { - Thickwidth circles use the current write mode, while}
  1207. { normal width circles ALWAYS use CopyPut/NormalPut }
  1208. { mode. (Tested against VGA BGI driver -CEC 13/Aug/99 }
  1209. {********************************************************}
  1210. var OriginalArcInfo: ArcCoordsType;
  1211. OldWriteMode: word;
  1212. begin
  1213. if (Radius = 0) then
  1214. Exit;
  1215. if (Radius = 1) then
  1216. begin
  1217. { only normal put mode is supported by a call to PutPixel }
  1218. PutPixel(X, Y, CurrentColor);
  1219. Exit;
  1220. end;
  1221. { save state of arc information }
  1222. { because it is not needed for }
  1223. { a circle call. }
  1224. move(ArcCall,OriginalArcInfo, sizeof(ArcCall));
  1225. if LineInfo.Thickness = Normwidth then
  1226. begin
  1227. OldWriteMode := CurrentWriteMode;
  1228. CurrentWriteMode := CopyPut;
  1229. end;
  1230. InternalEllipse(X,Y,Radius,Radius,0,360,{$ifdef fpc}@{$endif}DummyPatternLine);
  1231. if LineInfo.Thickness = Normwidth then
  1232. CurrentWriteMode := OldWriteMode;
  1233. { restore arc information }
  1234. move(OriginalArcInfo, ArcCall,sizeof(ArcCall));
  1235. end;
  1236. procedure SectorPL(x1,x2,y: smallint); {$ifndef fpc}far;{$endif fpc}
  1237. var plx1, plx2: smallint;
  1238. begin
  1239. If (x1 = -maxsmallint) Then
  1240. If (x2 = maxsmallint-1) Then
  1241. { no ellipse points drawn on this line }
  1242. If (((Y < ArcCall.Y) and (Y > ArcCall.YStart)) or
  1243. ((Y > ArcCall.Y) and (Y < ArcCall.YStart))) Then
  1244. { there is a part of the sector at this y coordinate, but no }
  1245. { ellips points are plotted on this line, so draw a patternline }
  1246. { between the lines connecting (arccall.x,arccall.y) with }
  1247. { the start and the end of the arc (JM) }
  1248. { use: y-y1=(y2-y1)/(x2-x1)*(x-x1) => }
  1249. { x = (y-y1)/(y2-y1)*(x2-x1)+x1 }
  1250. Begin
  1251. plx1 := (y-ArcCall.Y)*(ArcCall.XStart-ArcCall.X)
  1252. div (ArcCall.YStart-ArcCall.Y)+ArcCall.X;
  1253. plx2 := (y-ArcCall.Y)*(ArcCall.XEnd-ArcCall.X)
  1254. div (ArcCall.YEnd-ArcCall.Y)+ArcCall.X;
  1255. If plx1 > plx2 then
  1256. begin
  1257. plx1 := plx1 xor plx2;
  1258. plx2 := plx1 xor plx2;
  1259. plx1 := plx1 xor plx2;
  1260. end;
  1261. End
  1262. { otherwise two points which have nothing to do with the sector }
  1263. Else exit
  1264. Else
  1265. { the arc is plotted at the right side, but not at the left side, }
  1266. { fill till the line between (ArcCall.X,ArcCall.Y) and }
  1267. { (ArcCall.XStart,ArcCall.YStart) }
  1268. Begin
  1269. If (y < ArcCall.Y) then
  1270. begin
  1271. plx1 := (y-ArcCall.Y)*(ArcCall.XEnd-ArcCall.X)
  1272. div (ArcCall.YEnd-ArcCall.Y)+ArcCall.X
  1273. end
  1274. else if (y > ArcCall.Y) then
  1275. begin
  1276. plx1 := (y-ArcCall.Y)*(ArcCall.XStart-ArcCall.X)
  1277. div (ArcCall.YStart-ArcCall.Y)+ArcCall.X
  1278. end
  1279. else plx1 := ArcCall.X;
  1280. plx2 := x2;
  1281. End
  1282. Else
  1283. If (x2 = maxsmallint-1) Then
  1284. { the arc is plotted at the left side, but not at the rigth side. }
  1285. { the right limit can be either the first or second line. Just take }
  1286. { the closest one, but watch out for division by zero! }
  1287. Begin
  1288. If (y < ArcCall.Y) then
  1289. begin
  1290. plx2 := (y-ArcCall.Y)*(ArcCall.XStart-ArcCall.X)
  1291. div (ArcCall.YStart-ArcCall.Y)+ArcCall.X
  1292. end
  1293. else if (y > ArcCall.Y) then
  1294. begin
  1295. plx2 := (y-ArcCall.Y)*(ArcCall.XEnd-ArcCall.X)
  1296. div (ArcCall.YEnd-ArcCall.Y)+ArcCall.X
  1297. end
  1298. else plx2 := ArcCall.X;
  1299. plx1 := x1;
  1300. End
  1301. Else
  1302. { the arc is plotted at both sides }
  1303. Begin
  1304. plx1 := x1;
  1305. plx2 := x2;
  1306. End;
  1307. If plx2 > plx1 then
  1308. Begin
  1309. PatternLine(plx1,plx2,y);
  1310. end;
  1311. end;
  1312. procedure Sector(x, y: smallint; StAngle,EndAngle, XRadius, YRadius: Word);
  1313. begin
  1314. internalellipse(x,y,XRadius, YRadius, StAngle, EndAngle, {$ifdef fpc}@{$endif}SectorPL);
  1315. Line(ArcCall.XStart, ArcCall.YStart, x,y);
  1316. Line(x,y,ArcCall.Xend,ArcCall.YEnd);
  1317. end;
  1318. procedure SetFillStyle(Pattern : word; Color: word);
  1319. begin
  1320. { on invalid input, the current fill setting will be }
  1321. { unchanged. }
  1322. if (Pattern > UserFill) or (Color > GetMaxColor) then
  1323. begin
  1324. {$ifdef logging}
  1325. logln('invalid fillstyle parameters');
  1326. {$endif logging}
  1327. _GraphResult := grError;
  1328. exit;
  1329. end;
  1330. FillSettings.Color := Color;
  1331. FillSettings.Pattern := Pattern;
  1332. end;
  1333. procedure SetFillPattern(Pattern: FillPatternType; Color: word);
  1334. {********************************************************}
  1335. { Changes the Current FillPattern to a user defined }
  1336. { pattern and changes also the current fill color. }
  1337. { The FillPattern is saved in the FillPattern array so }
  1338. { it can still be used with SetFillStyle(UserFill,Color) }
  1339. {********************************************************}
  1340. var
  1341. i: smallint;
  1342. begin
  1343. if Color > GetMaxColor then
  1344. begin
  1345. {$ifdef logging}
  1346. logln('invalid fillpattern parameters');
  1347. {$endif logging}
  1348. _GraphResult := grError;
  1349. exit;
  1350. end;
  1351. FillSettings.Color := Color;
  1352. FillSettings.Pattern := UserFill;
  1353. { Save the pattern in the buffer }
  1354. For i:=1 to 8 do
  1355. FillPatternTable[UserFill][i] := Pattern[i];
  1356. end;
  1357. procedure Bar(x1,y1,x2,y2:smallint);
  1358. {********************************************************}
  1359. { Important notes for compatibility with BP: }
  1360. { - WriteMode is always CopyPut }
  1361. { - No contour is drawn for the lines }
  1362. {********************************************************}
  1363. var y : smallint;
  1364. origcolor : longint;
  1365. origlinesettings: Linesettingstype;
  1366. origwritemode : smallint;
  1367. begin
  1368. origlinesettings:=lineinfo;
  1369. origcolor:=CurrentColor;
  1370. if y1>y2 then
  1371. begin
  1372. y:=y1;
  1373. y1:=y2;
  1374. y2:=y;
  1375. end;
  1376. { Always copy mode for Bars }
  1377. origwritemode := CurrentWriteMode;
  1378. CurrentWriteMode := CopyPut;
  1379. { All lines used are of this style }
  1380. Lineinfo.linestyle:=solidln;
  1381. Lineinfo.thickness:=normwidth;
  1382. case Fillsettings.pattern of
  1383. EmptyFill :
  1384. begin
  1385. Currentcolor:=CurrentBkColor;
  1386. for y:=y1 to y2 do
  1387. Hline(x1,x2,y);
  1388. end;
  1389. SolidFill :
  1390. begin
  1391. CurrentColor:=FillSettings.color;
  1392. for y:=y1 to y2 do
  1393. Hline(x1,x2,y);
  1394. end;
  1395. else
  1396. Begin
  1397. CurrentColor:=FillSettings.color;
  1398. for y:=y1 to y2 do
  1399. patternline(x1,x2,y);
  1400. end;
  1401. end;
  1402. CurrentColor:= Origcolor;
  1403. LineInfo := OrigLineSettings;
  1404. CurrentWriteMode := OrigWritemode;
  1405. end;
  1406. procedure bar3D(x1, y1, x2, y2 : smallint;depth : word;top : boolean);
  1407. var
  1408. origwritemode : smallint;
  1409. OldX, OldY : smallint;
  1410. begin
  1411. origwritemode := CurrentWriteMode;
  1412. CurrentWriteMode := CopyPut;
  1413. Bar(x1,y1,x2,y2);
  1414. Rectangle(x1,y1,x2,y2);
  1415. { Current CP should not be updated in Bar3D }
  1416. { therefore save it and then restore it on }
  1417. { exit. }
  1418. OldX := CurrentX;
  1419. OldY := CurrentY;
  1420. if top then begin
  1421. Moveto(x1,y1);
  1422. Lineto(x1+depth,y1-depth);
  1423. Lineto(x2+depth,y1-depth);
  1424. Lineto(x2,y1);
  1425. end;
  1426. if Depth <> 0 then
  1427. Begin
  1428. Moveto(x2+depth,y1-depth);
  1429. Lineto(x2+depth,y2-depth);
  1430. Lineto(x2,y2);
  1431. end;
  1432. { restore CP }
  1433. CurrentX := OldX;
  1434. CurrentY := OldY;
  1435. CurrentWriteMode := origwritemode;
  1436. end;
  1437. {--------------------------------------------------------------------------}
  1438. { }
  1439. { COLOR AND PALETTE ROUTINES }
  1440. { }
  1441. {--------------------------------------------------------------------------}
  1442. procedure SetColor(Color: Word);
  1443. Begin
  1444. CurrentColor := Color;
  1445. end;
  1446. function GetColor: Word;
  1447. Begin
  1448. GetColor := CurrentColor;
  1449. end;
  1450. function GetBkColor: Word;
  1451. Begin
  1452. GetBkColor := CurrentBkColor;
  1453. end;
  1454. procedure SetBkColor(ColorNum: Word);
  1455. { Background color means background screen color in this case, and it is }
  1456. { INDEPENDANT of the viewport settings, so we must clear the whole screen }
  1457. { with the color. }
  1458. var
  1459. ViewPort: ViewportType;
  1460. Begin
  1461. GetViewSettings(Viewport);
  1462. {$ifdef logging}
  1463. logln('calling setviewport from setbkcolor');
  1464. {$endif logging}
  1465. SetViewPort(0,0,MaxX,MaxY,FALSE);
  1466. {$ifdef logging}
  1467. logln('calling setviewport from setbkcolor done');
  1468. {$endif logging}
  1469. CurrentBkColor := ColorNum;
  1470. {ClearViewPort;}
  1471. if not DirectColor and (ColorNum<256) then
  1472. SetRGBPalette(0,
  1473. DefaultColors[ColorNum].Red,
  1474. DefaultColors[ColorNum].Green,
  1475. DefaultColors[ColorNum].Blue);
  1476. SetViewport(ViewPort.X1,Viewport.Y1,Viewport.X2,Viewport.Y2,Viewport.Clip);
  1477. end;
  1478. function GetMaxColor: word;
  1479. { Checked against TP VGA driver - CEC }
  1480. begin
  1481. GetMaxColor:=MaxColor-1; { based on an index of zero so subtract one }
  1482. end;
  1483. Procedure MoveRel(Dx, Dy: smallint);
  1484. Begin
  1485. CurrentX := CurrentX + Dx;
  1486. CurrentY := CurrentY + Dy;
  1487. end;
  1488. Procedure MoveTo(X,Y: smallint);
  1489. {********************************************************}
  1490. { Procedure MoveTo() }
  1491. {--------------------------------------------------------}
  1492. { Moves the current pointer in VIEWPORT relative }
  1493. { coordinates to the specified X,Y coordinate. }
  1494. {********************************************************}
  1495. Begin
  1496. CurrentX := X;
  1497. CurrentY := Y;
  1498. end;
  1499. function GraphErrorMsg(ErrorCode: smallint): string;
  1500. Begin
  1501. GraphErrorMsg:='';
  1502. case ErrorCode of
  1503. grOk,grFileNotFound,grInvalidDriver: exit;
  1504. grNoInitGraph: GraphErrorMsg:='Graphics driver not installed';
  1505. grNotDetected: GraphErrorMsg:='Graphics hardware not detected';
  1506. grNoLoadMem,grNoScanMem,grNoFloodMem: GraphErrorMsg := 'Not enough memory for graphics';
  1507. grNoFontMem: GraphErrorMsg := 'Not enough memory to load font';
  1508. grFontNotFound: GraphErrorMsg:= 'Font file not found';
  1509. grInvalidMode: GraphErrorMsg := 'Invalid graphics mode';
  1510. grError: GraphErrorMsg:='Graphics error';
  1511. grIoError: GraphErrorMsg:='Graphics I/O error';
  1512. grInvalidFont,grInvalidFontNum: GraphErrorMsg := 'Invalid font';
  1513. grInvalidVersion: GraphErrorMsg:='Invalid driver version';
  1514. end;
  1515. end;
  1516. Function GetMaxX: smallint;
  1517. { Routine checked against VGA driver - CEC }
  1518. Begin
  1519. GetMaxX := MaxX;
  1520. end;
  1521. Function GetMaxY: smallint;
  1522. { Routine checked against VGA driver - CEC }
  1523. Begin
  1524. GetMaxY := MaxY;
  1525. end;
  1526. Function GraphResult: smallint;
  1527. Begin
  1528. GraphResult := _GraphResult;
  1529. _GraphResult := grOk;
  1530. end;
  1531. Function GetX: smallint;
  1532. Begin
  1533. GetX := CurrentX;
  1534. end;
  1535. Function GetY: smallint;
  1536. Begin
  1537. GetY := CurrentY;
  1538. end;
  1539. Function GetDriverName: string;
  1540. begin
  1541. GetDriverName:=DriverName;
  1542. end;
  1543. procedure graphdefaults;
  1544. { PS: GraphDefaults does not ZERO the ArcCall structure }
  1545. { so a call to GetArcCoords will not change even the }
  1546. { returned values even if GraphDefaults is called in }
  1547. { between. }
  1548. var
  1549. i: smallint;
  1550. begin
  1551. lineinfo.linestyle:=solidln;
  1552. lineinfo.thickness:=normwidth;
  1553. { reset line style pattern }
  1554. for i:=0 to 15 do
  1555. LinePatterns[i] := TRUE;
  1556. { By default, according to the TP prog's reference }
  1557. { the default pattern is solid, and the default }
  1558. { color is the maximum color in the palette. }
  1559. fillsettings.color:=GetMaxColor;
  1560. fillsettings.pattern:=solidfill;
  1561. { GraphDefaults resets the User Fill pattern to $ff }
  1562. { checked with VGA BGI driver - CEC }
  1563. for i:=1 to 8 do
  1564. FillPatternTable[UserFill][i] := $ff;
  1565. CurrentColor:=white;
  1566. ClipPixels := TRUE;
  1567. { Reset the viewport }
  1568. StartXViewPort := 0;
  1569. StartYViewPort := 0;
  1570. ViewWidth := MaxX;
  1571. ViewHeight := MaxY;
  1572. { Reset CP }
  1573. CurrentX := 0;
  1574. CurrentY := 0;
  1575. SetBkColor(Black);
  1576. { normal write mode }
  1577. CurrentWriteMode := CopyPut;
  1578. { Schriftart einstellen }
  1579. CurrentTextInfo.font := DefaultFont;
  1580. CurrentTextInfo.direction:=HorizDir;
  1581. CurrentTextInfo.charsize:=1;
  1582. CurrentTextInfo.horiz:=LeftText;
  1583. CurrentTextInfo.vert:=TopText;
  1584. XAspect:=10000; YAspect:=10000;
  1585. end;
  1586. procedure GetAspectRatio(var Xasp,Yasp : word);
  1587. begin
  1588. XAsp:=XAspect;
  1589. YAsp:=YAspect;
  1590. end;
  1591. procedure SetAspectRatio(Xasp, Yasp : word);
  1592. begin
  1593. Xaspect:= XAsp;
  1594. YAspect:= YAsp;
  1595. end;
  1596. procedure SetWriteMode(WriteMode : smallint);
  1597. { TP sets the writemodes according to the following scheme (JM) }
  1598. begin
  1599. Case writemode of
  1600. xorput, andput: CurrentWriteMode := XorPut;
  1601. notput, orput, copyput: CurrentWriteMode := CopyPut;
  1602. End;
  1603. end;
  1604. procedure GetFillSettings(var Fillinfo:Fillsettingstype);
  1605. begin
  1606. Fillinfo:=Fillsettings;
  1607. end;
  1608. procedure GetFillPattern(var FillPattern:FillPatternType);
  1609. begin
  1610. FillPattern:=FillpatternTable[UserFill];
  1611. end;
  1612. procedure DrawPoly(numpoints : word;var polypoints);
  1613. type
  1614. ppointtype = ^pointtype;
  1615. pt = array[0..16000] of pointtype;
  1616. var
  1617. i : longint;
  1618. begin
  1619. if numpoints < 2 then
  1620. begin
  1621. _GraphResult := grError;
  1622. exit;
  1623. end;
  1624. for i:=0 to numpoints-2 do
  1625. line(pt(polypoints)[i].x,
  1626. pt(polypoints)[i].y,
  1627. pt(polypoints)[i+1].x,
  1628. pt(polypoints)[i+1].y);
  1629. end;
  1630. procedure PieSlice(X,Y,stangle,endAngle:smallint;Radius: Word);
  1631. begin
  1632. Sector(x,y,stangle,endangle,radius,radius);
  1633. end;
  1634. {$i fills.inc}
  1635. {$i gtext.inc}
  1636. procedure internDetectGraph(var GraphDriver, GraphMode:smallint;
  1637. calledFromInitGraph: boolean);
  1638. var LoMode, HiMode: smallint;
  1639. CpyMode: smallint;
  1640. CpyDriver: smallint;
  1641. begin
  1642. HiMode := -1;
  1643. LoMode := -1;
  1644. if not calledFromInitGraph or
  1645. (graphDriver < lowNewDriver) or
  1646. (graphDriver > highNewDriver) then
  1647. begin
  1648. { Search lowest supported bitDepth }
  1649. graphdriver := D1bit;
  1650. while (graphDriver <= highNewDriver) and
  1651. (hiMode = -1) do
  1652. begin
  1653. getModeRange(graphDriver,loMode,hiMode);
  1654. inc(graphDriver);
  1655. end;
  1656. dec(graphdriver);
  1657. if hiMode = -1 then
  1658. begin
  1659. _GraphResult := grNotDetected;
  1660. exit;
  1661. end;
  1662. CpyMode := 0;
  1663. repeat
  1664. GetModeRange(GraphDriver,LoMode,HiMode);
  1665. { save the highest mode possible...}
  1666. {$ifdef logging}
  1667. logln('Found driver '+strf(graphdriver)+' with modes '+
  1668. strf(lomode)+' - '+strf(himode));
  1669. {$endif logging}
  1670. if HiMode <> -1 then
  1671. begin
  1672. CpyMode:=HiMode;
  1673. CpyDriver:=GraphDriver;
  1674. end;
  1675. { go to next driver if it exists...}
  1676. Inc(graphDriver);
  1677. until (graphDriver > highNewDriver);
  1678. end
  1679. else
  1680. begin
  1681. cpyMode := 0;
  1682. getModeRange(graphDriver,loMode,hiMode);
  1683. if hiMode <> -1 then
  1684. begin
  1685. cpyDriver := graphDriver;
  1686. cpyMode := hiMode;
  1687. end;
  1688. end;
  1689. if cpyMode = 0 then
  1690. begin
  1691. _GraphResult := grNotDetected;
  1692. exit;
  1693. end;
  1694. _GraphResult := grOK;
  1695. GraphDriver := CpyDriver;
  1696. GraphMode := CpyMode;
  1697. end;
  1698. procedure detectGraph(var GraphDriver: smallint; var GraphMode:smallint);
  1699. begin
  1700. internDetectGraph(graphDriver,graphMode,false);
  1701. end;
  1702. procedure InitGraph(var GraphDriver:smallint;var GraphMode:smallint;
  1703. const PathToDriver:String);
  1704. const
  1705. dirchar = System.DirectorySeparator;
  1706. begin
  1707. InitVars;
  1708. { path to the fonts (where they will be searched)...}
  1709. bgipath:=PathToDriver;
  1710. if (Length(bgipath) > 0) and (bgipath[length(bgipath)]<>dirchar) then
  1711. bgipath:=bgipath+dirchar;
  1712. if not assigned(SaveVideoState) then
  1713. RunError(216);
  1714. DriverName:=InternalDriverName; { DOS Graphics driver }
  1715. if (Graphdriver=Detect)
  1716. or (GraphMode = detectMode)
  1717. then
  1718. begin
  1719. internDetectGraph(GraphDriver,GraphMode,true);
  1720. If _GraphResult = grNotDetected then Exit;
  1721. { _GraphResult is now already set to grOK by DetectGraph }
  1722. IntCurrentDriver := GraphDriver;
  1723. if (graphDriver >= lowNewDriver) and
  1724. (graphDriver <= highNewDriver) then
  1725. IntCurrentNewDriver := GraphDriver
  1726. else IntCurrentNewDriver := -1;
  1727. { Actually set the graph mode...}
  1728. if firstCallOfInitgraph then
  1729. begin
  1730. SaveVideoState;
  1731. firstCallOfInitgraph := false;
  1732. end;
  1733. SetGraphMode(GraphMode);
  1734. end
  1735. else
  1736. begin
  1737. { Search if that graphics modec actually exists...}
  1738. if SearchMode(GraphDriver,GraphMode) = nil then
  1739. begin
  1740. _GraphResult := grInvalidMode;
  1741. exit;
  1742. end
  1743. else
  1744. begin
  1745. _GraphResult := grOK;
  1746. IntCurrentDriver := GraphDriver;
  1747. if (graphDriver >= lowNewDriver) and
  1748. (graphDriver <= highNewDriver) then
  1749. IntCurrentNewDriver := GraphDriver
  1750. else IntCurrentNewDriver := -1;
  1751. if firstCallOfInitgraph then
  1752. begin
  1753. SaveVideoState;
  1754. firstCallOfInitgraph := false;
  1755. end;
  1756. SetGraphMode(GraphMode);
  1757. end;
  1758. end;
  1759. end;
  1760. procedure SetDirectVideo(DirectAccess: boolean);
  1761. begin
  1762. DirectVideo := DirectAccess;
  1763. end;
  1764. function GetDirectVideo: boolean;
  1765. begin
  1766. GetDirectVideo := DirectVideo;
  1767. end;
  1768. procedure GraphExitProc; {$ifndef fpc} far; {$endif fpc}
  1769. { deallocates all memory allocated by the graph unit }
  1770. var
  1771. list: PModeInfo;
  1772. tmp : PModeInfo;
  1773. c: longint;
  1774. begin
  1775. { restore old exitproc! }
  1776. exitproc := exitsave;
  1777. if IsGraphMode and ((errorcode<>0) or (erroraddr<>nil)) then
  1778. CloseGraph;
  1779. { release memory allocated for fonts }
  1780. for c := 1 to installedfonts do
  1781. with fonts[c] Do
  1782. If assigned(instr) Then
  1783. Freemem(instr,instrlength);
  1784. { release memory allocated for modelist }
  1785. list := ModeList;
  1786. while assigned(list) do
  1787. begin
  1788. tmp := list;
  1789. list:=list^.next;
  1790. dispose(tmp);
  1791. end;
  1792. for c := lowNewDriver to highNewDriver do
  1793. begin
  1794. list := newModeList.modeinfo[c];
  1795. while assigned(list) do
  1796. begin
  1797. tmp := list;
  1798. list:=list^.next;
  1799. dispose(tmp);
  1800. end;
  1801. end;
  1802. {$IFDEF DPMI}
  1803. { We had copied the buffer of mode information }
  1804. { and allocated it dynamically... now free it }
  1805. { Warning: if GetVESAInfo returned false, this buffer is not allocated! (JM)}
  1806. If hasVesa then
  1807. Dispose(VESAInfo.ModeList);
  1808. {$ENDIF}
  1809. end;
  1810. procedure InitializeGraph;
  1811. begin
  1812. {$ifdef logging}
  1813. assign(debuglog,'grlog.txt');
  1814. rewrite(debuglog);
  1815. close(debuglog);
  1816. {$endif logging}
  1817. isgraphmode := false;
  1818. ModeList := nil;
  1819. fillChar(newModeList.modeinfo,sizeof(newModeList.modeinfo),#0);
  1820. { lo and hi modenumber are -1 currently (no modes supported) }
  1821. fillChar(newModeList.loHiModeNr,sizeof(newModeList.loHiModeNr),#255);
  1822. SaveVideoState := nil;
  1823. RestoreVideoState := nil;
  1824. { This must be called at startup... because GetGraphMode may }
  1825. { be called even when not in graph mode. }
  1826. {$ifdef logging}
  1827. LogLn('Calling QueryAdapterInfo...');
  1828. {$endif logging}
  1829. QueryAdapterInfo;
  1830. { Install standard fonts }
  1831. { This is done BEFORE startup... }
  1832. InstalledFonts := 0;
  1833. InstallUserFont('TRIP');
  1834. InstallUserFont('LITT');
  1835. InstallUserFont('SANS');
  1836. InstallUserFont('GOTH');
  1837. InstallUserFont('SCRI');
  1838. InstallUserFont('SIMP');
  1839. InstallUserFont('TSCR');
  1840. InstallUserFont('LCOM');
  1841. InstallUserFont('EURO');
  1842. InstallUserFont('BOLD');
  1843. { This installs an exit procedure which cleans up the mode list...}
  1844. ExitSave := ExitProc;
  1845. ExitProc := @GraphExitProc;
  1846. {$ifdef win32}
  1847. charmessagehandler:=nil;
  1848. {$endif win32}
  1849. end;
  1850. {
  1851. $Log$
  1852. Revision 1.9 2002-09-07 15:07:47 peter
  1853. * old logs removed and tabs fixed
  1854. Revision 1.8 2002/09/07 12:43:02 carl
  1855. - unit cleanup (removed unused defines)
  1856. Revision 1.7 2002/06/01 19:42:02 marco
  1857. * Renamefest
  1858. }