#include <math.h>
void DrawHLine(TCanvas *Canvas, int cLeft, int cRight, int cTop, String cCaption)
{
Canvas->MoveTo(cLeft, cTop);
Canvas->LineTo(cRight, cTop);
Canvas->TextOut(cLeft - 20, cTop - 8, cCaption);
}
//---------------------------------------------------------------------------
void DrawVLine(TCanvas *Canvas, int cTop, int cBottom, int cLeft)
{
Canvas->MoveTo(cLeft, cTop);
Canvas->LineTo(cLeft, cBottom);
}
//---------------------------------------------------------------------------
void RysujSiatke(TImage *Image)
{
TRect gRect = Rect(32, 8, Image->Width - 8, Image->Height - 32);
TCanvas *gCanv = Image->Canvas;
DrawVLine(gCanv, gRect.Top, gRect.Top + gRect.Height(), gRect.Left);
int ws = floor(gRect.Width() / 5);
int lBottom = gRect.Top + floor(gRect.Height() / 5) * 5;
for(int i = 1; i < 6; i++)
{
DrawVLine(gCanv, lBottom, lBottom + 4, gRect.Left + (ws * i));
}
DrawHLine(gCanv, gRect.Left - 4, gRect.Left + gRect.Width(), gRect.Top, "25");
ws = floor(gRect.Height() / 5);
for(int i = 1; i < 6; i++)
{
DrawHLine(gCanv, gRect.Left - 4, gRect.Left + gRect.Width(),
gRect.Top + ws * i, String(25 - (i * 5)) );
}
}
//---------------------------------------------------------------------------
void DrawVRectangle(TCanvas *Canvas, int cLeft, int cTop, int cBottom, TColor Color)
{
Canvas->Brush->Style = bsSolid;
Canvas->Brush->Color = Color;
Canvas->Rectangle(cLeft, cTop, cLeft + 32, cBottom);
}
//---------------------------------------------------------------------------
void RysujSlupki(TImage *Image)
{
TRect gRect = Rect(32, 8, Image->Width - 8, Image->Height - 32);
TCanvas *gCanv = Image->Canvas;
int ws = floor(gRect.Width() / 10);
int lBottom = gRect.Top + floor(gRect.Height() / 5) * 5 + 1;
int tws = floor(gRect.Height() / 5);
int tabTop[] = {
(tws * 2) + 10,
tws - 10,
tws + 10,
(tws * 4),
(tws * 3) + 10
};
String tabCaption[] = {"0 - 5000", "5000 - 10000", "10000 - 15000",
"15000 - 20000", "20000 - "};
int wsleft = ws / 2;
int t = 0;
for(int i = 1; i < 10; i += 2)
{
DrawVRectangle(gCanv, gRect.Left + (ws * i) - 16,
gRect.Top + tabTop[t],
lBottom, clSkyBlue);
gCanv->Brush->Style = bsClear;
gCanv->TextOut(gRect.Left + (ws * i) - wsleft, lBottom, tabCaption[t]);
t++;
}
}
//---------------------------------------------------------------------------
void RysujWykres(TImage *Image)
{
RysujSiatke(Image);
RysujSlupki(Image);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
RysujWykres(Image1);
}