Delphi - de delphi a c++ builder

 
Vista:

de delphi a c++ builder

Publicado por max (2 intervenciones) el 14/05/2006 22:09:36
tengo un obejeto creado en delphi 7 y esoy tratando de pasarlo a c++ para usarlo en builder 6.0

unit spectrum;

interface

uses
Windows, Classes, Controls, Messages, Graphics;

type
TSpectrumStyle = (ssSmooth, ssBlock);

TMiniSpectrum = class(TGraphicControl)
private
FGradient: TBitmap;
FBuffer: TBitmap;
FScale: Single;
FStyle: TSpectrumStyle;
FValues: array [0..127] of Single;
procedure SetStyle(const Value: TSpectrumStyle);
protected
procedure Paint; override;
procedure Resize; override;
procedure SetEnabled(Value: Boolean); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Draw;
published
property Align;
property Scale: Single read FScale write FScale;
property Style: TSpectrumStyle read FStyle write SetStyle;
property OnClick;
end;

implementation

uses
fmod, fmodtypes;

{ TMiniSpectrum }

constructor TMiniSpectrum.Create(AOwner: TComponent);
var
X, Y: Integer;
R, G, B: Integer;
C: TColor;
begin
inherited;
Color := clBlack;
Width := 80;
Height := 32;
FScale := 4.0;
FStyle := ssSmooth;
Enabled := False;

// Create draw buffer
FBuffer := TBitmap.Create;
FBuffer.PixelFormat := pf32bit;
FBuffer.Width := Width;
FBuffer.Height := Height;

// Create gradient bitmap
FGradient := TBitmap.Create;
FGradient.PixelFormat := pf32bit;
FGradient.Width := 4;
FGradient.Height := 32;

R := 255;
G := 0;
B := 0;

for Y := 0 to 31 do
begin
if Y > 15 then
Dec(R, 16)
else
Inc(G, 16);
if R < 0 then
R := 0;
if G > 255 then
G := 255;
C := TColor(RGB(R, G, B));
for X := 0 to 2 do
FGradient.Canvas.Pixels[X, Y] := C;
FGradient.Canvas.Pixels[3, Y] := TColor(0);
end;
end;

destructor TMiniSpectrum.Destroy;
begin
FGradient.Free;
FBuffer.Free;
inherited;
end;

type
PSingleArray = ^TSingleArray;
TSingleArray = array [0..0] of Single;

procedure TMiniSpectrum.Draw;
var
Data: PSingleArray;
PeakData: Single;
W, X, Y: Integer;
ARect: TRect;
begin
FBuffer.Canvas.Brush.Color := Color;
FBuffer.Canvas.FillRect(BoundsRect);

if Enabled then
begin
Data := PSingleArray(FSOUND_DSP_GetSpectrum);
//FSOUND_DSP_GetSpectrum es parte de una dll
// Get the peak value of each block of four values
for X := 0 to 127 do
begin
W := X * 4;
FValues[X] := Data^[W];
if Data^[W + 1] > FValues[X] then
FValues[X] := Data^[W + 1];
if Data^[W + 2] > FValues[X] then
FValues[X] := Data^[W + 2];
if Data^[W + 3] > FValues[X] then
FValues[X] := Data^[W + 3];
FValues[X] := FValues[X] * FScale;
if FValues[X] > 1.0 then
FValues[X] := 1.0;
end;

W := Width;
if W > 128 then
W := 128;

case FStyle of
ssSmooth:
begin
X := 0;
while X < W do
begin
if FValues[X] > 0.0 then
begin
Y := Height - Trunc(FValues[X] * 1.0 * Height);
FBuffer.Canvas.CopyRect(Rect(X, Y, X + 1, Height), FGradient.Canvas, Rect(0, Y, 1, FGradient.Height));
end;
Inc(X);
end;
end;
ssBlock:
begin
// Sixteen values for every column
PeakData := 0;
X := 0;
while X < W do
begin
if PeakData < FValues[X] then
PeakData := FValues[X];
if (X and 3 = 3) and (PeakData > 0.0) then
begin
Y := Height - Trunc(PeakData * 1.0 * Height);
PeakData := 0;
FBuffer.Canvas.CopyRect(Rect(X, Y, X + 4, Height), FGradient.Canvas, Rect(0, Y, 4, FGradient.Height));
end;
Inc(X);
end;
end;
end;
end
else
begin
FBuffer.Canvas.Font.Color := clWhite;
ARect := BoundsRect;
DrawText(FBuffer.Canvas.Handle, 'Click for spectrum', -1, ARect, DT_WORDBREAK or DT_NOPREFIX or DT_VCENTER or DT_CENTER);
end;

// Copy the buffer to the control
Canvas.Draw(0, 0, FBuffer);
end;

procedure TMiniSpectrum.Paint;
begin
Draw;
end;

procedure TMiniSpectrum.Resize;
begin
inherited;
if Assigned(FBuffer) then
begin
FBuffer.Width := Width;
FBuffer.Height := Height;
end;
end;

procedure TMiniSpectrum.SetEnabled(Value: Boolean);
begin
inherited;
FSOUND_DSP_SetActive(FSOUND_DSP_GetFFTUnit, Value); //parte de una dll
end;

procedure TMiniSpectrum.SetStyle(const Value: TSpectrumStyle);
begin
if FStyle <> Value then
begin
FStyle := Value;
ZeroMemory(@FValues, SizeOf(FValues));
end;
end;

end.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:de delphi a c++ builder

Publicado por max (2 intervenciones) el 14/05/2006 22:10:24
esto es lo que pude mas o menos pasar pero todabia me salata error

algo pude hacer ya q nose mucho de objetos y de pascal un poco

a ver si alguien me da una manita desde ya muchisimas gracias
Código:

//---------------------------------------------------------------------------
//el cpp
#include <vcl.h>

#pragma hdrstop

#include "MiniSpectrum.h"
#include "mainr1.h"
#include "fmod.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
//

static inline void ValidCtrCheck(TMiniSpectrum *)
{
new TMiniSpectrum(NULL);
}
//---------------------------------------------------------------------------
__fastcall TMiniSpectrum::TMiniSpectrum(TComponent* Owner)
: TGraphicControl(Owner)
{
int X, Y;
int R, G, B;
TColor C;

Color = clBlack;
Width = 80;
Height = 32;
FScale = 4.0;
FStyle = ssSmooth;
Enabled = False;

//Graphics::TBitmap* bitmap(new Graphics::TBitmap());
//TBitmap *FBuffer = new TBitmap;//->Create();
Graphics::TBitmap* FBuffer(new Graphics::TBitmap());
FBuffer->PixelFormat = pf32bit;
FBuffer->Width = Width;
FBuffer->Height = Height;

//FGradient = TBitmap->Create;
Graphics::TBitmap* FGradient(new Graphics::TBitmap());
FGradient->PixelFormat = pf32bit;
FGradient->Width = 4;
FGradient->Height = 32;

R = 255;
G = 0;
B = 0;

for(Y=0;Y<31;Y++)
{
if (Y > 15)
R-=16;
else
G+=16;

if(R < 0)
R = 0;

if (G > 255)
G = 255;

C = TColor(RGB(R, G, B));
for(X=0;X<2;X++)
FGradient->Canvas->Pixels[X,Y]=C;//a qui me salta error

FGradient->Canvas->Pixels[3,Y]=TColor(0);//a qui me salta error
}

}
//---------------------------------------------------------------------------
namespace Minispectrum
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TMiniSpectrum)};
RegisterComponents("Standard", classes, 0);
}
}
//---------------------------------------------------------------------------
void TMiniSpectrum::Draw(void)
{

float *Data;
float PeakData;
int W, X, Y;
TRect ARect;

FBuffer->Canvas->Brush->Color = Color;
FBuffer->Canvas->FillRect(BoundsRect);

if (Enabled)
{
Data =FSOUND_DSP_GetSpectrum();

for (X=0;X<127;X++)
{
W = X * 4;
FValues[X] = Data[W];
if (Data[W + 1] > FValues[X])
FValues[X] = Data[W + 1];
if (Data[W + 2] > FValues[X])
FValues[X] = Data[W + 2];
if (Data[W + 3] > FValues[X])
FValues[X] = Data[W + 3];
FValues[X] = FValues[X] * FScale;
if (FValues[X] > 1.0)
FValues[X] = 1.0;
}

W = Width;
if (W > 128)
W = 128;

switch(FStyle)
{
case ssSmooth:
{
X = 0;
while (X < W) do
{
if (FValues[X] > 0.0)
{ //*
Y = Height - Trunc(FValues[X] * 1.0 * Height);//a qui me salta //error
FBuffer->Canvas->CopyRect(Rect(X, Y, X + 1, Height), FGradient->Canvas, Rect(0, Y, 1, FGradient.Height));
}
X++;
}
}
case ssBlock:
{
// Sixteen values for every column
PeakData = 0;
X= 0;
while (X < W)
{
if (PeakData < FValues[X])
PeakData = FValues[X];
if ((X && 3 == 3) && (PeakData > 0.0) )
{
Y = Height - Trunc(PeakData * 1.0 * Height);//a qui me salta //error
PeakData = 0;
FBuffer->Canvas->CopyRect(Rect(X, Y, X + 4, Height), FGradient->Canvas, Rect(0, Y, 4, FGradient->Height));
}
++X;//Inc(X);
}
}
}
}
}
else
{
FBuffer->Canvas->Font->Color = clWhite;
ARect = BoundsRect;
DrawText(FBuffer->Canvas->Handle, "Click para ver spectrum", -1, ARect, DT_WORDBREAK || DT_NOPREFIX || DT_VCENTER || DT_CENTER);
}

// Copy the buffer to the control
Canvas->Draw(0, 0, FBuffer);
}

void __fastcall TMiniSpectrum::Paint(void)
{
Draw();
}

void __fastcall TMiniSpectrum::Resize(void)
{
inherited;
if (Assigned(FBuffer))
{
FBuffer->Width = Width;
FBuffer->Height = Height;
}
}

void __fastcall TMiniSpectrum::SetEnabled(bool Value)
{
//inherited;
FSOUND_DSP_SetActive(FSOUND_DSP_GetFFTUnit, Value)
}

void __fastcall TMiniSpectrum::SetStyle(TSpectrumStyle Value)
{
if (FStyle!=Value)
{
FStyle = Value;
ZeroMemory(@FValues, SizeOf(FValues));
}
}

//---------------------------------------------------------------------------

y este el el h
Código:

//---------------------------------------------------------------------------

#ifndef MiniSpectrumH
#define MiniSpectrumH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Classes.hpp>
#include <Controls.hpp>
//---------------------------------------------------------------------------
enum TSpectrumStyle { ssSmooth, ssBlock };//GraphicControl1 == TSpectrumStyle
class /*PACKAGE*/ TMiniSpectrum : public TGraphicControl
{
private:
Graphics::TBitmap* FGradient;
Graphics::TBitmap* FBuffer;
float FScale;
TSpectrumStyle FStyle;
float FValues[128];
virtual void __fastcall SetStyle(const TSpectrumStyle Value);
protected:
void __fastcall Paint(void);
DYNAMIC void __fastcall Resize(void);
virtual void __fastcall SetEnabled(bool Value);
public:
virtual void Draw(void);
float *TSingleArray,*PSingleArray;
__fastcall TMiniSpectrum(Classes::TComponent* Owner);
__fastcall ~TMiniSpectrum(void);

__published:
__property Align = {default=0};
__property float Scale = {read=FScale, write=FScale};
__property TSpectrumStyle Style = {read=FStyle, write=SetStyle, nodefault};
__property OnClick ;
};
//---------------------------------------------------------------------------
#endif
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar