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
| //---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "FTestLCD.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TTestLCD *TestLCD;
//---------------------------------------------------------------------------
__fastcall TTestLCD::TTestLCD(TComponent* Owner)
: TForm(Owner)
{
LCD_BACK_COLOR = clGreen;
LCD_DOT_COLOR = clBlack;
}
//---------------------------------------------------------------------------
void __fastcall TTestLCD::LCDSizeChange(TObject *Sender)
{
LCD_PIXEL_WIDTH =StrToInt(txtWidth->Text);
LCD_PIXEL_HEIGHT=StrToInt(txtHeight->Text);
LCD_PIXEL_DOT =StrToInt(txtSize->Text);
imaLCD->Width =LCD_PIXEL_WIDTH *LCD_PIXEL_DOT;
imaLCD->Height=LCD_PIXEL_HEIGHT*LCD_PIXEL_DOT;
ClearLCD();
PaintLCD();
}
//---------------------------------------------------------------------------
// Fonction pretexte pour dessiner un cercle
void TTestLCD::PaintLCD() {
int centerX=LCD_PIXEL_WIDTH/2;
int centerY=LCD_PIXEL_HEIGHT/2;
int radiusX=random(centerX);
int radiusY=random(centerY);
for (int x=0; x<radiusX; ++x) {
// Compute position
int y=sin(acos((double)x/(double)radiusX))*radiusY;
// Turn dots on
SetDotState(centerX+x,centerY+y,true);
SetDotState(centerX+x,centerY-y,true);
SetDotState(centerX-x,centerY+y,true);
SetDotState(centerX-x,centerY-y,true);
}
}
//---------------------------------------------------------------------------
// Primitives
void TTestLCD::ClearLCD() {
imaLCD->Canvas->Brush->Color=LCD_BACK_COLOR;
imaLCD->Canvas->FillRect(imaLCD->ClientRect);
}
//---------------------------------------------------------------------------
void TTestLCD::SetDotState(unsigned int x,unsigned int y,bool on) {
// Ignore if out of range
if ((x>=LCD_PIXEL_WIDTH)||(y>=LCD_PIXEL_HEIGHT)) return;
// Find the position (in bitmap coordinates) of the LCD dot
int top =y*LCD_PIXEL_DOT;
int left=x*LCD_PIXEL_DOT;
int size=LCD_PIXEL_DOT;
// Draw the LCD dot
imaLCD->Canvas->Brush->Color=(on?LCD_DOT_COLOR:LCD_BACK_COLOR);
imaLCD->Canvas->FillRect(TRect(left,top,left+size,top+size));
}
void __fastcall TTestLCD::cmdAddCircleClick(TObject *Sender)
{
PaintLCD();
}
//---------------------------------------------------------------------------
void __fastcall TTestLCD::FormCreate(TObject *Sender)
{
LCDSizeChange(Sender);
}
//--------------------------------------------------------------------------- |
Partager