Composant LCD avec TShape
Bonjour à tous,
Pour notre logiciel disponible sur notre site http://sites.google.com/site/outilsobdfacile/
Je travaille sur un composant graphique qui simulera un afficheur LCD.. Mais voilà j'experimente quelque soucis de lenteur..
Le principe est le suivant je créer un TShape vert et j'ajoute x pixels qui sont eux des TShape (noir) et après je joue sur la propriété visible pour afficher du texte. Celà donne le résultat suivant
http://img822.imageshack.us/img822/4818/lcdd.jpg
Uploaded with ImageShack.us
Jusqu'ici tout va bien, vous me direz, sauf que l'affichage initiale du composant prends environ 10s... ET c'est très long 10s sans rien qui se passe pour un programme
Voici le code qui prends un temps fou
Code:
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
|
void __fastcall TForm1::FormCreate(TObject *Sender)
{
//Create the green background
TShape *ShapeBack = new TShape(NULL);
ShapeBack->Parent = Form1;
ShapeBack->Top = LCD_TOP_POSITION;
ShapeBack->Left = LCD_LEFT_POSITION;
ShapeBack->Width = LCD_PIXEL_WIDTH * LCD_PIXEL_DOT;
ShapeBack->Height = LCD_PIXEL_HEIGHT * LCD_PIXEL_DOT;
ShapeBack->Brush->Color = LCD_BACK_COLOR;
//ShapeBack->Visible = TRUE;
//Now create each pixel
for(int x = 0; x < LCD_PIXEL_WIDTH ; x++)
{
for(int y = 0; y < LCD_PIXEL_HEIGHT ; y++)
{
Pixels[x][y] = new TShape(NULL);
Pixels[x][y]->Parent = Form1;
Pixels[x][y]->Width = LCD_PIXEL_DOT;
Pixels[x][y]->Height = LCD_PIXEL_DOT;
Pixels[x][y]->Top = LCD_TOP_POSITION + (y * LCD_PIXEL_DOT);
Pixels[x][y]->Left = LCD_LEFT_POSITION + (x * LCD_PIXEL_DOT);
Pixels[x][y]->Brush->Color = LCD_PIXEL_COLOR;
//Pixels[x][y]->Visible = TRUE;
}
}
} |
La ligne suivante Pixels[x][y]->Parent = Form1; me semble louche mais je suis un pro du C embarqué et de l'OBD.. mais le C++ je me debrouille, mais sans plus :cry:
Je vous remercie d'avance pour votre expertise
Salutations
Cnavas, ou pourquoi ne pas utiliser Label?
Bonjour,
Tout à fait d'accord avec Patrick pour l'utilisation de la propriété Canvas qui peut être liée à Form1 ou à un objet Image (TImage).
Mais pourquoi ne pas tout simplement utiliser Label (TLabel) qui fait déjà tout ça de manière très efficace? ::zoubi:
http://a.imageshack.us/img72/9476/exemple1.jpg
Le code:
Code:
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
|
//---------------------------------------------------------------------------
void __fastcall TForm1::Button_Label1Click(TObject *Sender)
{
Label1->Color = clOlive; // couleur de fond
Label1->Font->Color = clBlack; // couleur du texte
Label1->Font->Name = "Courier"; // Police
Label1->Font->Height = 55; // taille
Label1->Caption = Edit1->Text;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button_CanvasClick(TObject *Sender)
{
Form1->Canvas->TextHeight(40);
Form1->Canvas->TextWidth(28);
Form1->Canvas->Font->Color = clBlack;
Form1->Canvas->Font->Name = "Courier";
Form1->Canvas->Font->Size = 40;
TRect TheRect;
TheRect = Rect(150,50,400,100);
Canvas->TextRect(TheRect, 150, 50, Edit1->Text);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormPaint(TObject *Sender)
{
Button_CanvasClick(Sender);
} |