/*
繪製雲氣泡
Canvas 繪製畫板
Rect 繪製範圍,繪製完畢後返回客戶區域
Size 氣泡大小
bDraw 是否繪製,false只是計算客戶區域大小
成功返回0,失敗返回-1
*/
int DrawCloud(TCanvas* Canvas, TRect& Rect, TColor Color, int Size, bool bDraw)
{
vector<int> szbuf;
size_t index;
Rect.left += Size;
Rect.top += Size;
Rect.right -=Size;
Rect.bottom -=Size;
if(Rect.right<Rect.Left)return -1;
if(Rect.bottom<Rect.Top)return -1;
if(!bDraw)return 0;
int px = Rect.left;
int py = Rect.top;
randomize();
index = 0;
Canvas->Brush->Color = Color;
Canvas->Pen->Color = Color;
for(; px < Rect.right; )
{
if(index==szbuf.size())szbuf.push_back(Size/4+random(Size/4*3));
int n = Rect.right-px;
if(szbuf[index] < n)
{
Canvas->Ellipse(px-szbuf[index], py-szbuf[index],
px+szbuf[index], py+szbuf[index]);
px += szbuf[index];
++index;
}
else
{
Canvas->Ellipse(px-n, py-n, px+n, py+n);
px += n;
}
}
for(; py < Rect.bottom; )
{
if(index==szbuf.size())szbuf.push_back(Size/4+random(Size/4*3));
int n = Rect.bottom-py;
if(szbuf[index] < n)
{
Canvas->Ellipse(px-szbuf[index], py-szbuf[index],
px+szbuf[index], py+szbuf[index]);
py += szbuf[index];
++index;
}
else
{
Canvas->Ellipse(px-n, py-n, px+n, py+n);
py += n;
}
}
for(; px > Rect.left; )
{
if(index==szbuf.size())szbuf.push_back(Size/4+random(Size/4*3));
int n = -Rect.left + px;
if(szbuf[index] < n)
{
Canvas->Ellipse(px-szbuf[index], py-szbuf[index],
px+szbuf[index], py+szbuf[index]);
px -= szbuf[index];
++index;
}
else
{
Canvas->Ellipse(px-n, py-n, px+n, py+n);
px -= n;
}
}
for(; py > Rect.top; )
{
if(index==szbuf.size())szbuf.push_back(Size/4+random(Size/4*3));
int n = -Rect.top+py;
if(szbuf[index] < n)
{
Canvas->Ellipse(px-szbuf[index], py-szbuf[index],
px+szbuf[index], py+szbuf[index]);
py -= szbuf[index];
++index;
}
else
{
Canvas->Ellipse(px-n, py-n, px+n, py+n);
py -= n;
}
}
Canvas->FillRect(Rect);
return 0;
}