Ver Mensaje Individual
  #3  
Antiguo 30-07-2019
bucanero bucanero is offline
Miembro
 
Registrado: nov 2013
Ubicación: Almería, España
Posts: 208
Reputación: 13
bucanero Va camino a la fama
hola

prueba el siguiente código:

se basa en determinar en el tiempo de la transición el valor que han de tener los cuatro puntos del panel, para lo cual se utiliza una función lineal donde x=0 es la posición inicial y x=AStep es el valor final, tenindo AStep el numero de pasos en que se quiere hacer la transición

Código Delphi [-]
type
  // Estructura de datos que funciona similar a como lo hace en matemáticas una
  // funcion lineal del tipo f(x) = a * x + b
  // y devuelve el valor de la función en el punto X de la linea
  TFLineal = record
  private
    a, b: Extended;
    function GetPoint(const x: Integer): Integer;
  public
    // valores iniciales para calcular la funcion lineal
    procedure init(const X1, y1, x2, y2: Integer);
    property Point[const x: Integer]: Integer read GetPoint; default;
  end;

...

{ TFLineal }
function TFLineal.GetPoint(const x: Integer): Integer;
begin
  Result := round(a * x + b);
end;

procedure TFLineal.init(const X1, y1, x2, y2: Integer);
begin
  // valores iniciales para calcular la funcion lineal
  a := (y2 - y1) / (x2 - X1);
  b := y1 - a * X1;
end;

y en la parte del formulario:


Código Delphi [-]
var
    fLeft, fWidth, fTop, fHeight: TFLineal;

...

procedure TForm2.AnimeConfig(AWinControl: TWinControl; const AWidth, AHeight,
  AStep: Word);
begin
  // se configura las coordenadas de la animación 
  fLeft.init(0, AWinControl.left, AStep, (ClientWidth - AWidth) div 2);
  fWidth.init(0, AWinControl.width, AStep, AWidth);
  fTop.init(0, AWinControl.top, AStep, (ClientHeight - AHeight) div 2);
  fHeight.init(0, AWinControl.height, AStep, AHeight);
end;

procedure TForm2.AnimeExecute(AWinControl: TWinControl; const AStep: Word);
var
  i, Ai: longint;
  tSleep:Word;
begin
  // la transicion durara 300 ms
  tSleep := 300 div AStep;
  if Tag <= 0 then begin
    i := 1;
    Ai := 1
  end
  else begin
    i := AStep - 1;
    Ai := -1;
  end;

  repeat
    with AWinControl do begin
      Left := fLeft[i];
      Top := fTop[i];
      Width := fWidth[i];
      Height := fHeight[i];
    end;
    Sleep(tSleep);
    i := i + Ai;
  until (i <= 0) or (i >= AStep);
  self.Tag := i;
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
  // configuración del ancho y alto que se quiere obtener
  AnimeConfig(Panel1, Width - 50, height - 300);
end;

procedure TForm2.Panel1DblClick(Sender: TObject);
begin
  // Se ejecuta la animación
  AnimeExecute(Panel1);
end;
Responder Con Cita