//---------------------------------------------------------------------------
// Проект 35. Индикатор прогресса вручную
// Своя полоса прогресса на Canvas от 0 до 100%.
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
{
}
//---------------------------------------------------------------------------

// Рисуем прогресс сами: рамка и заполнение по проценту. fillWidth — ядро,
// переводящее процент в ширину заполнения.
int fillWidth(int percent, int fullWidth)
{
    if (percent<0) percent=0; if (percent>100) percent=100;
    return fullWidth*percent/100;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::TrackChange(TObject *Sender)
{
    int p=TrackBar1->Position;
    TCanvas *c=PaintBox1->Canvas; int W=PaintBox1->Width,H=PaintBox1->Height;
    c->Brush->Color=clBlack; c->FillRect(PaintBox1->ClientRect);
    c->Brush->Color=(TColor)RGB(111,215,196);
    c->FillRect(Rect(0,0,fillWidth(p,W),H));
    c->Brush->Style=bsClear; c->Font->Color=clWhite;
    c->TextOut(W/2-15, H/2-8, IntToStr(p)+"%");
}
//---------------------------------------------------------------------------
