fill.ppi 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1993,97 by the Free Pascal development team.
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. procedure floodfill(x,y:integer; border:longint);
  12. var bordercol : longint;
  13. fillcol : longint;
  14. viewport : viewporttype;
  15. offset : longint;
  16. procedure fill(x,y:integer);
  17. var start,ende,xx : integer;
  18. col : longint;
  19. begin
  20. xx:=x; col:=getpixel(xx,y);
  21. if col=bordercol then exit;
  22. while (col<>bordercol) and (xx > viewport.x1) and (col<>fillcol)
  23. do begin
  24. xx:=xx-1; col:=getpixel(xx,y);
  25. end;
  26. start:=xx+1;
  27. xx:=x+1; col:=getpixel(xx,y);
  28. while (col<>bordercol) and (xx < viewport.x2) and (col<>fillcol)
  29. do begin
  30. xx:=xx+1; col:=getpixel(xx,y);
  31. end;
  32. ende:=xx-1;
  33. patternline(start,ende,y);
  34. offset:=(y * _maxy + start) shr 8;
  35. if (y > viewport.y1)
  36. then begin
  37. xx:=start;
  38. repeat
  39. col:=getpixel(xx,y-1);
  40. if (col<>bordercol) and (col<>fillcol)
  41. then begin
  42. fill(xx,y-1);
  43. break;
  44. end;
  45. xx:=xx+1;
  46. until xx > ende;
  47. end;
  48. if (y > viewport.y1)
  49. then begin
  50. xx:=start;
  51. repeat
  52. col:=getpixel(xx,y+1);
  53. if (col<>bordercol) and (col<>fillcol) then fill(xx,y+1);
  54. xx:=xx+1;
  55. until xx > ende;
  56. end;
  57. end;
  58. begin
  59. fillchar(buffermem^,buffersize,0);
  60. if aktviewport.clip then viewport:=aktviewport else viewport:=aktscreen;
  61. viewport.x2:=viewport.x2-viewport.x1;
  62. viewport.y2:=viewport.y2-viewport.y1;
  63. viewport.x1:=0;
  64. viewport.y1:=0;
  65. bordercol:=convert(border);
  66. if BytesPerPixel=1
  67. then begin
  68. bordercol:=bordercol and $FF;
  69. fillcol:=aktfillsettings.color and $FF;
  70. end
  71. else begin
  72. bordercol:=bordercol and $FFFF;
  73. fillcol:=aktfillsettings.color and $FFFF;
  74. end;
  75. fill(x,y);
  76. end;
  77. procedure GetFillSettings(var Fillinfo:Fillsettingstype);
  78. begin
  79. _graphresult:=grOk;
  80. if not isgraphmode then
  81. begin
  82. _graphresult:=grnoinitgraph;
  83. exit;
  84. end;
  85. Fillinfo:=aktfillsettings;
  86. end;
  87. procedure GetFillPattern(var FillPattern:FillPatternType);
  88. begin
  89. _graphresult:=grOk;
  90. if not isgraphmode then
  91. begin
  92. _graphresult:=grnoinitgraph;
  93. exit;
  94. end;
  95. FillPattern:=aktfillpattern;
  96. end;
  97. procedure SetFillPattern(pattern : FillPatternType;color : longint);
  98. begin
  99. _graphresult:=grOk;
  100. if not isgraphmode then
  101. begin
  102. _graphresult:=grnoinitgraph;
  103. exit;
  104. end;
  105. fillpattern[12]:=pattern;
  106. SetFillStyle(12,color);
  107. end;
  108. procedure SetFillStyle(pattern : word ;color : longint);
  109. var i,j:Integer;
  110. mask:Byte;
  111. begin
  112. _graphresult:=grOk;
  113. if not isgraphmode then
  114. begin
  115. _graphresult:=grnoinitgraph;
  116. exit;
  117. end;
  118. { g�ltige Paramter ? }
  119. if (pattern<0) or (pattern>12) then
  120. begin
  121. _graphresult:=grError;
  122. exit;
  123. end;
  124. { Muster laden }
  125. aktfillpattern:=fillpattern[pattern];
  126. aktfillsettings.pattern:=pattern;
  127. aktfillsettings.color:=convert(color);
  128. i:=1; j:=0;
  129. repeat
  130. mask:=$80;
  131. repeat
  132. if (aktfillpattern[i] and mask) = 0
  133. then PatternBuffer[j]:=aktbackcolor else PatternBuffer[j]:=aktfillsettings.color;
  134. mask:=mask shr 1;
  135. j:=j+1;
  136. until mask=0;
  137. i:=i+1;
  138. until i > 8;
  139. end;
  140. procedure GetLineSettings(var LineInfo : LineSettingsType);
  141. begin
  142. _graphresult:=grOk;
  143. if not isgraphmode then
  144. begin
  145. _graphresult:=grnoinitgraph;
  146. exit;
  147. end;
  148. lineinfo:=aktlineinfo;
  149. end;
  150. {
  151. $Log$
  152. Revision 1.1 1998-03-25 11:18:42 root
  153. Initial revision
  154. Revision 1.3 1998/01/26 11:57:57 michael
  155. + Added log at the end
  156. Working file: rtl/dos/ppi/fill.ppi
  157. description:
  158. ----------------------------
  159. revision 1.2
  160. date: 1997/12/01 12:21:29; author: michael; state: Exp; lines: +13 -1
  161. + added copyright reference in header.
  162. ----------------------------
  163. revision 1.1
  164. date: 1997/11/27 08:33:51; author: michael; state: Exp;
  165. Initial revision
  166. ----------------------------
  167. revision 1.1.1.1
  168. date: 1997/11/27 08:33:51; author: michael; state: Exp; lines: +0 -0
  169. FPC RTL CVS start
  170. =============================================================================
  171. }