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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
| __fastcall TVumetre::TVumetre(TComponent *Owner)
: TGraphicControl(Owner)
{
Width = 100;
Height = 100;
Min = 0;
Max = 100;
Position = 0;
Overdrive = 90;
}
__fastcall TVumetre::~TVumetre()
{
}
void __fastcall TVumetre::Paint()
{
Canvas->Brush->Style = bsSolid;
Canvas->Pen->Mode = pmCopy;
Canvas->Pen->Style = psSolid;
switch(Modele)
{
case tCarre : ModeleCarre(); break;
case tRond : ModeleRond(); break;
}
}
int __fastcall TVumetre::arrondir(double d)
{
int n = d;
double r = d - n;
return(n + (r * 2));
}
void __fastcall TVumetre::ModeleCarre()
{
double pi = 3.14159265358979;
int w = Width;
int x = w / 2;
int h = Height;
int t = h * 2 / 3;
TCanvas *C = Canvas;
TPen *P = Canvas->Pen;
TBrush *B = Canvas->Brush;
P->Color = clWhite;
B->Color = clWhite;
C->Rectangle(0, 0, w, t);
//graduations
int yc = h * 6 / 8;
P->Color = clGreen;
int r = h * 4 / 7;
C->Arc(x - r, yc - r, x + r, yc + r, x + r, yc - r, x - r, yc - r);
//valeurs max et min
C->Font->Name = "Terminal";
C->Font->Size = 6;
C->Font->Color = clGreen;
double angle = 135 * pi / 180.0;
int xa = arrondir(cos(angle) * (r - 10));
int ya = arrondir(sin(angle) * (r - 10));
C->TextOut(x + xa, yc - ya, IntToStr(Min));
angle = 45 * pi / 180.0;
xa = arrondir(cos(angle) * (r - 10));
ya = arrondir(sin(angle) * (r - 10));
int we = Canvas->TextWidth(IntToStr(Max)) / 2;
C->TextOut(x + xa - we, yc - ya, IntToStr(Max));
//Position aiguille : de Min à Max pour un angle compris entre 135° et 45°
int a = Max - Min;
angle = 135 ;//Min
if(a != 0) angle = angle - (90 * Position / a);
angle = angle * pi / 180.0;
r = r + 4;
xa = arrondir(cos(angle) * r);
ya = arrondir(sin(angle) * r);
P->Color = clBlue;
C->MoveTo(x + xa, yc - ya);
C->LineTo(x,yc);
//
P->Color = TColor(0x00E0E0E0);
B->Color = TColor(0x00E0E0E0);
C->Rectangle(0, t, w, h);
P->Color = clGray;
C->MoveTo(0,t); C->LineTo(w,t);
P->Color = clBlack;
C->Font->Size = 5;
C->Font->Color = clBlack;
AnsiString Fabricant = "henderson's";
we = C->TextWidth(Fabricant);
int he = C->TextHeight(Fabricant);
int tp = h - (he + 4);
C->TextOut(4, tp, Fabricant);
//
P->Color = clRed;
B->Color = clYellow;
C->Ellipse(x - 4, yc - 4, x + 4, yc + 4);
// Overdrive LED
xa = w - 16;
ya = h * 5 / 6;
P->Color = clBlack;
if(Position > Overdrive)
{
C->Brush->Color = clRed;
}
else
{
C->Brush->Color = clMaroon;
}
C->Ellipse(xa-4, ya - 4, xa + 4, ya + 4);
// Effet 3D
P->Color = clWhite;
C->MoveTo(w,0); C->LineTo(0, 0); C->LineTo(0, h);
w--; h--;
P->Color = clBlack;
C->MoveTo(w,0); C->LineTo(w, h); C->LineTo(0, h);
}
void __fastcall TVumetre::ModeleRond()
{
// A faire...
}
void __fastcall TVumetre::Refreq(int N)
{
Position = N;
Paint();
} |
Partager