1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| Graphics::TBitmap *Bitmap = new Graphics::TBitmap;
//Ici en degrés
int AngleRotation1 = 0;
int AngleRotation2 = 0;
//Mes deux triangles
jTriangle *Triangle1;
jTriangle *Triangle2;
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Triangle1 = new jTriangle(this, Point(100,100), Point(150, 180), Point(10,150));
Triangle2 = new jTriangle(this, Point(150,120), Point(100, 200), Point(50,200));
/*
Pour le Triangle2, je modifie son référentiel qui est normalement fixé sur son centre de gravité.
Ici je mets n'importe quoi en fait...
*/
Triangle2->ChangeRef(Point(ClientWidth/2, ClientHeight/2));
}
void __fastcall TForm1::FormPaint(TObject *Sender)
{
DrawBitmap();
}
void __fastcall TForm1::FormResize(TObject *Sender)
{
DrawBitmap();
}
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
delete Bitmap;
Bitmap = NULL;
}
void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if(Key == VK_RIGHT)
{
AngleRotation1--;
Triangle1->Rotation(AngleRotation1, trDegree);
AngleRotation2++;
Triangle2->Rotation(AngleRotation2, trDegree);
DrawBitmap();
Key = 0;
}
else
{
if(Key == VK_LEFT)
{
AngleRotation1++;
Triangle1->Rotation(AngleRotation1, trDegree);
AngleRotation2--;
Triangle2->Rotation(AngleRotation2, trDegree);
DrawBitmap();
Key = 0;
}
}
}
//Méthode à déclarer dans la classe de TForm1, en public :
void __fastcall TForm1::DrawBitmap()
{
if(Bitmap != NULL)
{
int we = ClientWidth;
int he = ClientHeight;
if(Bitmap->Width != we) Bitmap->Width = we;
if(Bitmap->Height != he) Bitmap->Height = he;
Bitmap->Canvas->Brush->Style = bsSolid;
Bitmap->Canvas->Brush->Color = Color;
Bitmap->Canvas->FillRect(Rect(0,0,we,he));
Bitmap->Canvas->Pen->Style =psSolid;
Bitmap->Canvas->Pen->Mode = pmCopy;
//Le premier triangle
Bitmap->Canvas->Pen->Color = clYellow;
Triangle1->Draw(Bitmap->Canvas);
//Le deuxième triangle
Bitmap->Canvas->Pen->Color = clRed;
Triangle2->Draw(Bitmap->Canvas);
//On dessine le bitmap sur la form
Canvas->Draw(0,0,Bitmap);
}
} |
Partager