i am converting my code from vb to c++ there are some dynamic points which are there to draw different shapes.
in vb they have properties such as .ScaleWidth, .ScaleHeight, .ScaleTop , .ScaleLeft.
what they had done is they had scaled according to width and height using these properties and draw points(shapes) on the picture box in vb.
but in mfc i have all the input points required but when iam drawing not able to draw properly or correctly. please help me i.e not able to scale properly please help me out.
What I have tried:
void CPDlgToolPreview::S_SetDrawingScale()
{
short i;
float lnMaxX;
float lnMaxY;
float lnMinX;
float lnMinY;
const int BigNumber = 1000000000;
float lnWidth;
float lnHeight;
lnMaxX = (float)(-BigNumber);
lnMaxY = (float)(-BigNumber);
lnMinX = (float)(BigNumber);
lnMinY = (float)(BigNumber);
for (i = 0; i < mlPoints; i++)
{
if (moPts[i].X > lnMaxX) lnMaxX = (float)(moPts[i].X);
if (moPts[i].Y > lnMaxY) lnMaxY = (float)(moPts[i].Y);
if (moPts[i].X < lnMinX) lnMinX = (float)(moPts[i].X);
if (moPts[i].Y < lnMinY) lnMinY = (float)(moPts[i].Y);
}
lnWidth = lnMaxX - lnMinX;
lnHeight = lnMaxY - lnMinY;
CRect cRect;
m_cPreview.GetClientRect(&cRect);
if ( lnWidth / cRect.Width() > lnHeight / cRect.Height() )
{
nScaleWidth = lnWidth*1.2;
nScaleHeight = cRect.Height() *nScaleWidth / cRect.Width();
}
else
{
nScaleHeight = lnHeight*1.2;
nScaleWidth = cRect.Width() *nScaleHeight / cRect.Height();
}
nScaleleft = -nScaleWidth / 2;
nScaletop = -((nScaleHeight - lnHeight) / 2) - lnHeight;
}
for (short i = 2; i < mlPoints; i++)
{
DrawLine(m_cPreview, moPts[i].X , moPts[i].Y);
}
void DrawLine(CWnd *wnd, int x1, int y1, int x2, int y2, int rgb)
{
CDC *cdc = wnd->GetDC();
CPen *oldPen = cdc->SelectObject(new CPen(0, 3, rgb));
cdc->MoveTo(x1, y1);
cdc->LineTo(nCurrentx = x2, currenty= y2);
delete (CPen *)cdc->SelectObject(oldPen);
wnd->ReleaseDC(cdc);
}
where to use these scaleleft, nScaleHeight etc to get proper shape.