Re: PolyLine and autoscrolling canvas
Hello again Joe and Stephen,
I've corrected whatever you suggested to, Joe, made a Create() method
to initialize, removed the OnCreate and the rest of stuffs...
Stephen, I modified also the OnPaint() thing as you said as you can
see below:
void CCaChart::OnPaint()
{
CPaintDC dc(this); // device context for painting
dc.SetBkColor(RGB(0,0,0));
CRect rect;
GetClientRect(&rect);
int save = dc.SaveDC();
if(bSetDraw)
{
CMemDC mDC(&dc);
//mDC.SetBkColor(RGB(0,0,0));
mDC.SetMapMode(MM_ANISOTROPIC);
mDC.SetWindowOrg(rect.BottomRight());
mDC.SetViewportOrg(0, 0);
mDC.SetViewportExt(-1, -1);
//mDC.SetViewportExt(-rect.right, -rect.bottom);
mDC.SetWindowExt(1, 1);
//mDC.SetWindowExt(rect.Width(), rect.Height());
// ********** Background ***********
// Grid
if (bActivateGrid)
{
CPen qLinePen(PS_SOLID, 1, RGB(0,139,0));
mDC.SelectObject(&qLinePen);
// Grid - Horizontal lines
mDC.MoveTo(1, 0);
mDC.LineTo(rect.Width(), 0);
int height = rect.Height();
int maxlines = height / (int)12.5;
for (int i=1;i<=maxlines;i++){
int y_axis = (int)((double)i * 12.5);
if (y_axis <= rect.Height()) {
mDC.MoveTo(1, y_axis);
mDC.LineTo(rect.Width(),
y_axis);
}
}
// Grid - Vertical lines
mDC.MoveTo(0, 0);
mDC.LineTo(0, rect.Height());
int width = rect.Width();
maxlines = width / (int)12.5;
for (int i=1;i<=maxlines;i++){
int x_axis = (int)(((double)i * 12.5)
- gridOffset);
if (x_axis <= rect.Width()) {
mDC.MoveTo(x_axis, 1);
mDC.LineTo(x_axis,
rect.Height());
}
}
qLinePen.DeleteObject();
}
// *********** graphic component ***********
// based on choice of graph type
CPen qPolylinePen(PS_SOLID, 1, RGB(0, 255, 0));
switch (iGraphType)
{
case GRAPH_BARS:
break;
case GRAPH_LINES:
{
if (vtPoints.capacity() == 1)
{
mDC.SelectObject(qPolylinePen);
vectfPoints* pointsline =
&vtPoints[0];
mDC.Polyline(&(*pointsline)
[0], (int)pointsline->size());
//mDC->PolyPolyline()
qPolylinePen.DeleteObject();
}
}
break;
default:
break;
}
GDI_FLUSH();
}
dc.RestoreDC(save);
}
but when I resize window the vertical and horizontal lines are
repainted to the whole canvas but the Polyline stuff isn't rescaled; I
mean I have values in the vtPoints array which MM_ANISOTROPIC should
rescale automatically due having set SetViewportExt and SetWindowExt
respectively to -1, -1 and 1, 1 so I guess it should scale 1:1 and the
polyline graphic should be adjusted when resizing window....but it
doesn't... what I could have missed or made wrong in those
SetViewportExt and SetWindowExt?...
Thanks
Ciao
Luigi