Roulio52
Messages postés10Date d'inscriptionmardi 15 février 2005StatutMembreDernière intervention28 août 2007
-
7 juin 2007 à 08:49
cs_rt15
Messages postés3874Date d'inscriptionmardi 8 mars 2005StatutModérateurDernière intervention 7 novembre 2014
-
7 juin 2007 à 10:13
Salut à tous !
Je suis un petit débutant en C++,
et je commence à créer un petit paint sous borland.
J'ai un code DELPHI qui pourrait m'être super utile (permettant de faire un dégradé sur le fond d'un form).
et j'essaye de le convertir pour borland en C++ mais mes connaissances en DELPHI et en C++ ne me permettent pas d'avancer :S
Des âmes charitables qui pourrait m'aider pendant que je continue à chercher ?
Procedure Degrader(Form : Tform;FStartColor:Tcolor;FEndColor:Tcolor;Vertical : boolean);
Var
aBand : TRect; { Bande rectangulaire de couleur courante }
i : Integer; { Compteur pour parcourir la hauteur de la fiche }
FStartRGB : Array[0..2] of Byte; { RGB de la couleur de départ }
FCurrentRGB : Array[0..2] of Byte; { RGB de la couleur courante }
FDeltaRGB : Array[0..2] of Integer; { RGB à ajouter à la couleur de départ pour atteindre la couleur de fin }
Begin
{ Calcul des valeurs RGB pour la couleur courante }
FStartRGB[0] := GetRValue( ColorToRGB( FStartColor ) );
FStartRGB[1] := GetGValue( ColorToRGB( FStartColor ) );
FStartRGB[2] := GetBValue( ColorToRGB( FStartColor ) );
{ Calcul des valeurs à ajouter pour atteindre la couleur de fin }
FDeltaRGB[0] := GetRValue( ColorToRGB( FEndColor )) - FStartRGB[0] ;
FDeltaRGB[1] := GetgValue( ColorToRGB( FEndColor )) - FStartRGB[1] ;
FDeltaRGB[2] := GetbValue( ColorToRGB( FEndColor )) - FStartRGB[2] ;
{ Initialisation des dimensions de la bande de couleur }
aBand.Left :=0;
aBand.Right:=Form.Width;
{ Boucle pour remplir la fiche courante en dégradé }
With Form.Canvas Do
Begin
Pen.Style:=psSolid;
Pen.Mode:=pmCopy;
For i:= 0 To 255
Do Begin
{ Dimensions verticales de la bande }
If Vertical = true then begin
aBand.Left :=0;
aBand.Right:=Form.Width;
aBand.Top := MulDiv( i , Form.Height , 256 );
aBand.Bottom := MulDiv( i+1 , Form.Height , 256 );
End
Else begin
aBand.Top:=0;
aBand.Bottom:=form.Height;
aBand.left := MulDiv( i , Form.width , 256 );
aBand.right := MulDiv( i+1 , Form.width , 256 );
End;
{ Calcul de la couleur courante }
FCurrentRGB[0] := (FStartRGB[0] + MulDiv( i , FDeltaRGB[0] , 255 )) mod 256;
FCurrentRGB[1] := (FStartRGB[1] + MulDiv( i , FDeltaRGB[1] , 255 )) mod 256;
FCurrentRGB[2] := (FStartRGB[2] + MulDiv( i , FDeltaRGB[2] , 255 )) mod 256;
{ Affichage sur la fiche }
Brush.color:=RGB(FCurrentRGB[0],FCurrentRGB[1],FCurrentRGB[2]);
FillRect(aBand);
End;
End;
End;
procedure TForm1.DegradeClick(Sender: TObject);
var i : integer;
begin
Degrader(Form1,panel1.Color,panel2.Color,RadioButton2.Checked);
end;
procedure TForm1.Panel1Click(Sender: TObject);
begin
ColorDialog1.Color:=(sender as Tpanel).Color;
if ColorDialog1.Execute then (sender as Tpanel).Color:=ColorDialog1.Color;
Degrade.Click;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
Degrade.Click;
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
Degrade.Click;
end;
procedure TForm1.FormResize(Sender: TObject);
begin
Degrade.Click;
end;
end.
Voilà le programme est assez petit ca devrait pas être compliqué mais je comprend rien :S
Merci à tous ceux qui pourront m'aider !
A touti !
cs_rt15
Messages postés3874Date d'inscriptionmardi 8 mars 2005StatutModérateurDernière intervention 7 novembre 201413 7 juin 2007 à 10:13
Salut,
L'affectation s'écrit :en Delphi et en C++.
Le ; a le même rôle dans les deux langages.
begin -> {
end; -> }
On manipule jamais les objets en Delphi, mais des références sur ceux ci.
par exemple, form1:= form2; reviend à une affectation de pointeur si ce sont des TForm (Et accessoirement une fuite de mémoire de l'objet pointé par form1 dans certains cas).
Donc Sender: TObject doit ressemblé à ça : TObject & Sender.
Et les . sont remplacés par des ->.
Je ne crois pas que le with existe en C++. Il permet d'accéder aux propriétés et méthodes de la classe sans avoir à la nommer. (Moins de code à écrire donc). Il faudrat donc rajouter canvas-> à Pen et à deux trois autres trucs.
Pour l'algo golobal, on dirait une interpolation assez classque, même si je n'aime pas trop le for i:= 0 to 255. Je sais pas si ça rend bien sur des forms de plus de 255 pixels de largeur ou hauteur.
Concrètement, il dessin des rectangle de couleur interpolée entre la valeur final et la valeur initiale.