Public feed #376605

Untitled

public text v1 · immutable
Raw Edit
·published 2007-03-01 04:00 UTC
rendered paste body
function ControlledColorSearch(var x, y:integer; Color, x1, y1, x2, y2, Tol: Integer; Flip: Boolean; Wnd: Hwnd): Boolean; stdcall;
var
  WndDC: HDC;
  xx, yy: Integer;
  VarInt:Tpoint;
Begin
  WndDC := GetDC(Wnd);
  if x1>x2 then varint.X := -1
  else varint.x := 1;
  if y1>y2 then varint.y := -1
  else varint.Y := 1;
  if (x<>0) and (y<>0) then
  begin
    if flip = False then
    begin
      if (y = y2) and (x<>x2) then
      begin
        yy:=y1;
        xx:=x+varint.x;
      end
      else if (y=y2) and (x=x2) then
      begin
        result:=False;
        exit;
      end
      else if y<>y2 then
        YY:=y+varint.y;
    end
    else
    begin
      if (x = x2) and (y<>y2) then
      begin
        xx:=x1;
        yy:=y+varint.y;
      end
      else if (x=x2) and (y=y2) then
      begin
        result:=False;
        exit;
      end
      else if x<>x2 then
        xx:=x+varint.x;
    end;
  end
  else begin
  yy:=y1;
  xx:=x1;
  end;
  if not Flip then
  begin
    for xx := x1 to x2 do
      for yy := y1 to y2 do
        if SimilarColors(Color, GetPixel(WndDC, x, y), Tol) then
        begin
          Result := True;
          ReleaseDC(Wnd, WndDC);
          x := xx;
          y := yy;
          exit;
        end;
  end
  else if flip = true then
  begin
    for yy := y1 to y2 do
      for xx := x1 to x2 do
        if SimilarColors(Color, GetPixel(WndDC, x, y), Tol) then
        begin
          Result := True;
          ReleaseDC(Wnd, WndDC);
          x := xx;
          y := yy;
          exit;
        end;
  end;
  Result := False;
  x := -1;
  y := -1;
  ReleaseDC(Wnd, WndDC);
end;