graph.inc 81 KB

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