Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Delphi: Звук, графика и видео > не могу понять как работает SetPolyFillMode


Автор: nmn 8.8.2007, 16:23
к примеру данное изображение получено с PolyFillMode=ALTERNATE
user posted image
В MSDN написано что заливка производится между четными и нечетными сторонами региона, тогда почему центральный пентагон не залит?

Автор: Alexeis 8.8.2007, 21:57
nmn, ну без кода трудно предположить почему. Не везде же виноват дядя били, порой и у нас в коде появляются ошибки smile

Автор: nmn 8.8.2007, 22:25
Код

procedure RotatePoint(ptCenter:TFloatPoint;var pt:TFloatPoint;Angle:real);
var r,c:real;
begin
  if Angle=0 then exit;
  with pt do
    begin
      pt.X:=pt.X-ptCenter.X;
      pt.Y:=pt.Y-ptCenter.Y;
    end;
  r:=sqrt(sqr(pt.X)+sqr(pt.Y));
  if r<>0 then
    begin
      c:=abs(RadToDeg(arcsin(pt.Y/r)));
      with pt do
        if (x<0)and(y>=0) then c:=180-c
          else if (x<=0)and(y<0) then c:=c+180
            else if (x>0)and(y<0) then c:=360-c;
      Angle:=DegToRad(Angle+c);
      with pt do
        begin
          X:=R*cos(Angle)+ptCenter.X;
          Y:=R*sin(Angle)+ptCenter.Y;
        end;
    end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var rgn:hrgn;
    ptCenter,pt_:TFloatPoint;
    pt:array[1..5] of TPoint;
    i:integer;
begin
  ptCenter:=FloatPoint(150,150);
  for i:=1 to 5 do
    begin
      pt_:=FloatPoint(150,100);
      RotatePoint(ptCenter,pt_,360/5*2*(i-1));
      with pt[i] do
        begin
          X:=round(pt_.X);
          Y:=round(pt_.Y);
        end;
      Canvas.TextOut(pt[i].X,pt[i].Y,IntToStr(i-1));
    end;
  rgn:=CreatePolygonRGN(pt,5,ALTERNATE);
  Canvas.Brush.Color:=clWhite;
  PaintRGN(Canvas.Handle,rgn);
  DeleteObject(rgn);
end;

Автор: Alexeis 9.8.2007, 12:08
  Так в справке же подробно описан именно этот случай
Цитата(MSDN @ SetPolyFillMode,Remarks)

In general, the modes differ only in cases where a complex, overlapping polygon must be filled (for example, a five-sided polygon that forms a five-pointed star with a pentagon in the center). In such cases, ALTERNATE mode fills every other enclosed region within the polygon (that is, the points of the star), but WINDING mode fills all regions (that is, the points and the pentagon). 

When the fill mode is ALTERNATE, GDI fills the area between odd-numbered and even-numbered polygon sides on each scan line. That is, GDI fills the area between the first and second side, between the third and fourth side, and so on. 

When the fill mode is WINDING, GDI fills any region that has a nonzero winding value. This value is defined as the number of times a pen used to draw the polygon would go around the region. The direction of each edge of the polygon is important. 


ALTERNATE - оставит дырку ввиде пентограммы, т.е. не заливает пересекающиеся , а WINDING зальет всю звезду

Автор: nmn 9.8.2007, 15:27
Цитата(Alexeis @  9.8.2007,  12:08 Найти цитируемый пост)
ALTERNATE - оставит дырку ввиде пентограммы, т.е. не заливает пересекающиеся , а WINDING зальет всю звезду 

вот это мне и надо было

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)