BOOL CGraphWnd::GetBoundRect(double* minx, double* maxx, double* miny, double* maxy) { int grcount = GetGraphCount(); if (grcount == 0) return FALSE; int index; BOOL b = FALSE; CGraphProps* grprop = GetFirstGraph(&index); while(grprop!=NULL) { if (grprop->GetSize() == 0 || !grprop->IsVisible()) { grprop = GetNextGraph(&index); continue; }; if (!b) { //first time *minx = grprop->min_x; *maxx = grprop->max_x; *miny = grprop->min_y; *maxy = grprop->max_y; b = TRUE; } else { if (grprop->min_x<*minx) *minx = grprop->min_x; if (grprop->max_x>*maxx) *maxx = grprop->max_x; if (grprop->min_y<*miny) *miny = grprop->min_y; if (grprop->max_y>*maxy) *maxy = grprop->max_y; }; grprop = GetNextGraph(&index); }; return b; }
void CGraphicsPropertyPage::OnGraphHideshow() { int index = m_graph_combo.GetCurSel(); if (index == -1) return; CGraphProps* grprop = grprops.GetAt(index); grprop->SetVisible(!grprop->IsVisible()); SetHideShowAttr(index); }
void CGraphicsPropertyPage::SetHideShowAttr(int selnum) { if (selnum == -1) return; CGraphProps* grprop = grprops.GetAt(selnum); CWnd* wnd = GetDlgItem(IDC_GRAPH_HIDESHOW); if (wnd == NULL) return; if (grprop->IsVisible()) { wnd->SetWindowText(_T("Hide")); } else { wnd->SetWindowText(_T("Show")); }; }
void CGraphPanel::AddPoint(SGraphChange* sgc) { //get main view pointer if (sgc->main_wnd_ptr == NULL) return; SSinglePoint ssp; CGraphProps* sgp = sgc->main_wnd_ptr->GetGraph(sgc->graphnum); if (!sgp->IsVisible()) { //if graph is not visible - do not do anything here return; }; sgp->GetPoint(sgc->index, &ssp); BOOL bNeedRedraw = FALSE; if ((unsigned long)(m_grflags & GRAPH_AUTOSCALE)) { //if grafix is autoscaled - just recalc coordinates and redraw the window if (ssp.x<__min(GetX1(), GetX2())) { SetMinX(ssp.x, FALSE); bNeedRedraw = TRUE; }; if (ssp.x>__max(GetX1(), GetX2())) { SetMaxX(ssp.x, FALSE); bNeedRedraw = TRUE; }; if (ssp.y<__min(GetY1(), GetY2())) { SetMinY(ssp.y, FALSE); bNeedRedraw = TRUE; }; if (ssp.y>__max(GetY1(), GetY2())) { SetMaxY(ssp.y, FALSE); bNeedRedraw = TRUE; }; }; //draw new point if (bNeedRedraw) { if (sgc->bRedraw) { UpdateGraphWindow(NULL); }; return; }; if (!sgc->bRedraw || offscreen == NULL) return; //if point is inside the graph - we need invalidate the whole picture if (sgc->index!=0 && sgc->index!=sgp->GetSize()-1) { if (sgc->bRedraw) { UpdateGraphWindow(NULL); }; return; }; int x, y, x1, y1; x = (int)CurrentCoordsX->WtoX(ssp.x); y = (int)CurrentCoordsY->WtoX(ssp.y); CDC* dc = offscreen->GetDibCDC(); if (dc != NULL) { CDC* cdc = GetDC(); CPen* pen = sgp->GetPen(); CBrush* brush = sgp->GetBrush(); CPen* oldpen = (CPen*)dc->SelectObject(pen); CBrush* oldbrush = (CBrush*)dc->SelectObject(brush); if (sgp->GetSize()>1) { if (sgc->index == 0) sgp->GetPoint(1, &ssp); if (sgc->index == sgp->GetSize()-1) sgp->GetPoint(sgc->index-1, &ssp); x1 = (int)CurrentCoordsX->WtoX(ssp.x); y1 = (int)CurrentCoordsY->WtoX(ssp.y); if (x != x1 || y != y1) { if ((m_grflags & GRAPH_GRAPH_SCATTER) == 0) { dc->MoveTo(x, y); dc->LineTo(x1, y1); }; if ((m_grflags & GRAPH_SQUAREPOINTS) != 0) { DrawSquarePoint(dc, x, y); }; CRect update_rect(x, y, x1, y1); update_rect.NormalizeRect(); update_rect.InflateRect(GetSquareSide(dc) + 2, GetSquareSide(dc) + 2); DoRedraw(cdc, update_rect); }; } else { if ((m_grflags & GRAPH_SQUAREPOINTS) != 0) { DrawSquarePoint(dc, x, y); CRect update_rect(x, y, x, y); update_rect.NormalizeRect(); update_rect.InflateRect(GetSquareSide(dc) + 2, GetSquareSide(dc) + 2); DoRedraw(cdc, update_rect); }; }; dc->SelectObject(oldpen); dc->SelectObject(oldbrush); sgp->ReleasePen(pen); sgp->ReleaseBrush(brush); ReleaseDC(cdc); }; }
void CGraphPanel::DrawPoints(CDC* dc, CRect& rect_to_draw) { //draw all the points SSinglePoint ssp, ssp1; int x, y, x1, y1, grnum; if (CurrentCoordsX == NULL || CurrentCoordsY == NULL) return; CGraphWnd* main_wnd = get_main_graph_window(); if (main_wnd == NULL) return; //save current state of device context int saved_dc = dc->SaveDC(); //set new clipping region dc->IntersectClipRect(rect_to_draw); //create new set of CCoordinates CCoordinates coords_x(rect_to_draw.left, rect_to_draw.right, CurrentCoordsX->v1(), CurrentCoordsX->v2()); CCoordinates coords_y(rect_to_draw.bottom, rect_to_draw.top, CurrentCoordsY->v1(), CurrentCoordsY->v2()); CGraphProps* grprop = main_wnd->GetFirstGraph(&grnum); while (grprop!=NULL) { if (grprop->GetSize() ==0 || !grprop->IsVisible()) { grprop = main_wnd->GetNextGraph(&grnum); continue; }; //set color CPen* pen = grprop->GetPen(); CBrush* brush = grprop->GetBrush(); CPen* oldpen = (CPen*)dc->SelectObject(pen); CBrush* oldbrush = (CBrush*)dc->SelectObject(brush); grprop->GetPoint(0, &ssp); x = (int)coords_x.WtoX(ssp.x); y = (int)coords_y.WtoX(ssp.y); if ((long)(m_grflags & GRAPH_SQUAREPOINTS)!=0) DrawSquarePoint(dc, x, y); for (int i=1; i<grprop->GetSize(); i++) { grprop->GetPoint(i, &ssp); x1 = (int)coords_x.WtoX(ssp.x); y1 = (int)coords_y.WtoX(ssp.y); if (x != x1 || y != y1) { if ((m_grflags & GRAPH_SQUAREPOINTS)!=0) DrawSquarePoint(dc, x1, y1); if ((m_grflags & GRAPH_GRAPH_SCATTER) == 0) { dc->MoveTo(x, y); dc->LineTo(x1, y1); }; x = x1; y = y1; }; }; dc->SelectObject(oldpen); dc->SelectObject(oldbrush); grprop->ReleasePen(pen); grprop->ReleaseBrush(brush); grprop = main_wnd->GetNextGraph(&grnum); }; dc->RestoreDC(saved_dc); }