📄 rlplot.cpp
字号:
} return false;}
bool
Bubble::DoAutoscale(anyOutput *o)
{
double dx, dy;
switch(type & 0x0f0) {
case BUBBLE_XAXIS: case BUBBLE_YAXIS:
dx = dy = fs/2.0; break;
case BUBBLE_UNITS:
dx = fPos.fx/20; dy = fPos.fy/20; break;
}
((Plot*)parent)->CheckBounds(fPos.fx+dx, fPos.fy-dy);
((Plot*)parent)->CheckBounds(fPos.fx-dx, fPos.fy+dy);
return true;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// Bars are graphic objectsBar::Bar(GraphObj *par, DataObj *d, double x, double y, int which,int xc, int xr, int yc, int yr):GraphObj(par, d){ FileIO(INIT_VARS); parent = par; fPos.fx = x; fPos.fy = y; type = which; if(type & BAR_RELWIDTH) size = 60.0; data = d; Id = GO_BAR; if(xc >= 0 || xr >= 0 || yc >= 0 || yr >= 0) { if(ssRef = (POINT*)malloc(sizeof(POINT)*2)) { ssRef[0].x = xc; ssRef[0].y = xr; ssRef[1].x = yc; ssRef[1].y = yr; cssRef = 2; } }}Bar::Bar(int src):GraphObj(0L, 0L){ FileIO(INIT_VARS); if(src == FILE_READ) { FileIO(FILE_READ); }}Bar::~Bar(){ if(mo) DelBitmapClass(mo); mo = 0L;
Command(CMD_FLUSH, 0L, 0L);}doubleBar::GetSize(int select){ switch(select){ case SIZE_XPOS: return fPos.fx; case SIZE_YPOS: return fPos.fy; } return 0.0;}boolBar::SetSize(int select, double value){ switch(select & 0xfff) { case SIZE_BAR: size = value; return true; case SIZE_BAR_LINE: BarLine.width = value; return true; case SIZE_XBASE: BarBase.fx = value; return true; case SIZE_YBASE: BarBase.fy = value; return true; } return false;}boolBar::SetColor(int select, DWORD col){ switch(select & 0xfff) { case COL_BAR_LINE: BarLine.color = col; return true; case COL_BAR_FILL: BarFill.color = col; return true; } return false;}voidBar::DoPlot(anyOutput *target){ int w; double fBase, rsize; POINT pts[2]; if(!parent || size <= 0.001) return; target->SetLine(&BarLine); target->SetFill(&BarFill); switch(type & 0xff) { case BAR_VERTU: case BAR_VERTT: case BAR_VERTB: switch(type & 0xff) { case BAR_VERTB: fBase = parent->GetSize(SIZE_BOUNDS_BOTTOM); break; case BAR_VERTT: fBase = parent->GetSize(SIZE_BOUNDS_TOP); break; case BAR_VERTU: fBase = BarBase.fy; break; } if(type & BAR_RELWIDTH) { rsize = size * parent->GetSize(SIZE_BARMINX)/100.0; pts[0].x = iround(target->fx2fix(fPos.fx - rsize/2.0)); pts[1].x = iround(target->fx2fix(fPos.fx + rsize/2.0)); } else { w = target->un2ix(size); pts[0].x = iround(target->fx2fix(fPos.fx)) - (w>>1); pts[1].x = pts[0].x + w; } if(type & BAR_CENTERED) { pts[0].y = iround(target->fy2fiy(fBase - (fPos.fy - fBase))); pts[1].y = iround(target->fy2fiy(fBase + (fPos.fy - fBase))); } else { pts[0].y = iround(target->fy2fiy(fBase)); pts[1].y = iround(target->fy2fiy(fPos.fy)); } break; case BAR_HORU: case BAR_HORR: case BAR_HORL: switch(type & 0xff) { case BAR_HORL: fBase = parent->GetSize(SIZE_BOUNDS_LEFT); break; case BAR_HORR: fBase = parent->GetSize(SIZE_BOUNDS_RIGHT); break; case BAR_HORU: fBase = BarBase.fx; break; } if(type & BAR_RELWIDTH) { rsize = size * parent->GetSize(SIZE_BARMINY)/100.0; pts[0].y = iround(target->fy2fiy(fPos.fy - rsize/2.0)); pts[1].y = iround(target->fy2fiy(fPos.fy + rsize/2.0)); } else { w = target->un2iy(size); pts[0].y = target->fy2iy(fPos.fy) - w/2; pts[1].y = pts[0].y+w; } if(type & BAR_CENTERED) { pts[0].x = target->fx2ix(fBase - (fPos.fx - fBase)); pts[1].x = target->fx2ix(fBase + (fPos.fx - fBase)); } else { pts[0].x = target->fx2ix(fBase); pts[1].x = target->fx2ix(fPos.fx); } break; default: return; } if(pts[0].x == pts[1].x || pts[0].y == pts[1].y) { target->oSolidLine(pts); } else target->oRectangle(pts[0].x, pts[0].y, pts[1].x, pts[1].y, name); SetMinMaxRect(&rDims, pts[0].x, pts[0].y, pts[1].x, pts[1].y);}
void
Bar::DoMark(anyOutput *o, bool mark)
{
if(mark){
memcpy(&mrc, &rDims, sizeof(RECT));
IncrementMinMaxRect(&mrc, 3);
mo = GetRectBitmap(&mrc, o);
o->CopyBitmap(mrc.left, mrc.top, mo, 0, 0, mrc.right-mrc.left, mrc.bottom - mrc.top, true);
o->UpdateRect(&mrc, false);
}
else RestoreRectBitmap(&mo, &mrc, o);
}
bool Bar::Command(int cmd, void *tmpl, anyOutput *o){ MouseEvent *mev; FillDEF *TmpFill; lfPOINT bl; switch (cmd) { case CMD_FLUSH: if(ssRef) free(ssRef); ssRef = 0L; if(name)free(name); name = 0L; return true; case CMD_LEGEND: if(!tmpl || ((GraphObj*)tmpl)->Id != GO_LEGEND) return false; ((Legend*)tmpl)->HasFill(&BarLine, &BarFill); break; case CMD_MOUSE_EVENT: mev = (MouseEvent *) tmpl; switch (mev->Action) { case MOUSE_LBUP: if(IsInRect(&rDims, mev->x, mev->y) && !CurrGO) { o->ShowMark(CurrGO = this, MRK_GODRAW); return true; } break; } return false; case CMD_BAR_FILL: TmpFill = (FillDEF *)tmpl; if(TmpFill) { BarFill.type = TmpFill->type; BarFill.color = TmpFill->color; BarFill.scale = TmpFill->scale; if(TmpFill->hatch) memcpy(&HatchLine, TmpFill->hatch, sizeof(LineDEF)); } return true; case CMD_BAR_TYPE: if(tmpl) type = *((int*)tmpl); return true; case CMD_SET_DATAOBJ: Id = GO_BAR; data = (DataObj *)tmpl; return true; case CMD_UPDATE: if(ssRef && cssRef >1 && data) { data->GetValue(ssRef[0].y, ssRef[0].x, &fPos.fx); data->GetValue(ssRef[1].y, ssRef[1].x, &fPos.fy); return true; } return false; case CMD_AUTOSCALE: if(parent && parent->Id >= GO_PLOT && parent->Id < GO_GRAPH) { ((Plot*)parent)->CheckBounds(fPos.fx, fPos.fy); switch(type & 0xff) { case BAR_VERTU: case BAR_VERTT: case BAR_VERTB: bl.fx = fPos.fx; switch (type & 0xff) { case BAR_VERTU: bl.fy = BarBase.fy; break; case BAR_VERTT: case BAR_VERTB: bl.fy = 0.0f; //cannot resolve break; } if(type & BAR_CENTERED) bl.fy -= fPos.fy; break; case BAR_HORU: case BAR_HORR: case BAR_HORL: bl.fy = fPos.fy; switch(type & 0xff) { case BAR_HORU: bl.fx = BarBase.fx; case BAR_HORR: case BAR_HORL: bl.fx = 0.0f; //cannot resolve } if(type & BAR_CENTERED) bl.fx -= fPos.fx; break; } ((Plot*)parent)->CheckBounds(bl.fx, bl.fy); return true; } break; } return false;}//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// Data line is a graphic objectDataLine::DataLine(GraphObj *par, DataObj *d, char *xrange, char *yrange):GraphObj(par, d){ FileIO(INIT_VARS); Id = GO_DATALINE; if(xrange)ssXref = strdup(xrange); if(yrange)ssYref = strdup(yrange); SetValues();} DataLine::DataLine(GraphObj *par, DataObj *d, lfPOINT *val, long nval):GraphObj(par, d){ FileIO(INIT_VARS); Values = val; nPnt = nval; nPntSet = nPnt-1; Id = GO_DATALINE;}DataLine::DataLine(int src):GraphObj(0L, 0L){ FileIO(INIT_VARS); if(src == FILE_READ) { FileIO(FILE_READ); }}DataLine::~DataLine(){ if(Values)free(Values); Values = 0L; if(pts) free(pts); pts = 0L; if(ssXref) free(ssXref); ssXref = 0L; if(ssYref) free(ssYref); ssYref = 0L; if(mo) DelBitmapClass(mo); mo = 0L; if(parent)parent->Command(CMD_MRK_DIRTY, 0L, 0L);}boolDataLine::SetColor(int select, DWORD col){ switch(select & 0xfff) { case COL_DATA_LINE: LineDef.color = col; return true; } return false;}voidDataLine::DoPlot(anyOutput *target){ int i; lfPOINT fip; POINT pn, *tmppts; if(!Values || nPntSet < 1) return;
if (nPntSet >= nPnt) nPntSet = nPnt-1; if(mo) DelBitmapClass(mo); mo = 0L; if(pts) free(pts); pts = 0L;
if((type & 0xff) == 9 || (type & 0xff) == 10) //splines pts = (POINT *)malloc(sizeof(POINT)*1000);
else if(type & 0xff) pts = (POINT *)malloc(sizeof(POINT)*(nPntSet+2)*2); else pts = (POINT *)malloc(sizeof(POINT)*(nPntSet+2)); if(!pts) return; if(max.fx > min.fx && max.fy > min.fy) dirty = false; else if(dirty) Command(CMD_AUTOSCALE, 0L, target); cp = 0; switch(type & 0x0f) { case 0: default: for (i = 0; i <= nPntSet; i++){ target->fp2fip(Values+i, &fip); pn.x = iround(fip.fx); pn.y = iround(fip.fy); AddToPolygon(&cp, pts, &pn); } break; case 5: target->fp2fip(Values, &fip); pn.x = iround(fip.fx); pn.y = iround(fip.fy); target->fp2fip(Values+1, &fip); pn.y += (pn.y -iround(fip.fy))>>1; AddToPolygon(&cp, pts, &pn); case 1: target->fp2fip(Values, &fip); pn.x = iround(fip.fx); pn.y = iround(+fip.fy); for (i = 0; i <= nPntSet; i++){ target->fp2fip(Values+i, &fip); pn.x = iround(fip.fx); AddToPolygon(&cp, pts, &pn); pn.y = iround(fip.fy); AddToPolygon(&cp, pts, &pn); } if((type &0xf) == 5) { target->fp2fip(Values+i-2, &fip); pn.x += (pn.x - iround(fip.fx))>>1; AddToPolygon(&cp, pts, &pn); } break; case 6: target->fp2fip(Values, &fip); pn.x = iround(fip.fx); pn.y = iround(fip.fy); target->fp2fip(Values+1, &fip); pn.x += (pn.x - iround(fip.fx))>>1; AddToPolygon(&cp, pts, &pn); case 2: target->fp2fip(Values, &fip); pn.x = iround(fip.fx); pn.y = iround(fip.fy); for (i = 0; i <= nPntSet; i++){ target->fp2fip(Values+i, &fip); pn.y = iround(fip.fy); AddToPolygon(&cp, pts, &pn); pn.x = iround(fip.fx); AddToPolygon(&cp, pts, &pn); } if((type &0xf) == 6) { target->fp2fip(Values+i-2, &fip); pn.y += (pn.y - iround(fip.fy))>>1; AddToPolygon(&cp, pts, &pn); } break; case 7: target->fp2fip(Values, &fip); pn.x = iround(fip.fx); pn.y = iround(fip.fy); target->fp2fip(Values+1, &fip); pn.x += (pn.x - iround(fip.fx))>>1; AddToPolygon(&cp, pts, &pn); case 3: target->fp2fip(Values, &fip); pn.x = iround(fip.fx); pn.y = iround(fip.fy); for (i = 0; i <= nPntSet; i++){ target->fp2fip(Values+i, &fip); pn.x = (pn.x + iround(fip.fx))>>1; AddToPolygon(&cp, pts, &pn); pn.y = iround(fip.fy); AddToPolygon(&cp, pts, &pn); pn.x = iround(fip.fx); } AddToPolygon(&cp, pts, &pn); if((type &0xf) == 7) { target->fp2fip(Values+i-2, &fip); pn.x += (pn.x - iround(fip.fx))>>1; AddToPolygon(&cp, pts, &pn); } break; case 8: target->fp2fip(Values, &fip); pn.x = iround(fip.fx); pn.y = iround(fip.fy); target->fp2fip(Values+1, &fip); pn.y += (pn.y - iround(fip.fy))>>1; AddToPolygon(&cp, pts, &pn); case 4: target->fp2fip(Values, &fip); pn.x = iround(fip.fx); pn.y = iround(fip.fy); for (i = 0; i <= nPntSet; i++){ target->fp2fip(Values+i, &fip); pn.y = (pn.y + iround(fip.fy))>>1; AddToPolygon(&cp, pts, &pn); pn.x = iround(fip.fx); AddToPolygon(&cp, pts, &pn); pn.y = iround(fip.fy); } AddToPolygon(&cp, pts, &pn); if((type &0xf) == 8) { target->fp2fip(Values+i-2, &fip); pn.y += (pn.y - iround(fip.fy))>>1; AddToPolygon(&cp, pts, &pn); } break;
case 9: case 10:
DrawSpline(target);
break; } if(cp < 2) return; if(isPolygon) { //for mark polygon only !! AddToPolygon(&cp, pts, pts); } else{ target->SetLine(&LineDef); target->oPolyline(pts, cp); } if(tmppts = (POINT*)realloc(pts, cp *sizeof(POINT))) pts = tmppts; SetMinMaxRect(&rDims, pts[0].x, pts[0].y, pts[1].x, pts[1].y); for(i = 2; i < cp; i++) UpdateMinMaxRect(&rDims, pts[i].x, pts[i].y); i = 2*target->un2ix(LineDef.width); //increase size of rectangle for marks IncrementMinMaxRect(&rDims, i);}voidDataLine::DoMark(anyOutput *o, bool mark){ if(pts && cp && o){ if(mark){ memcpy(&mrc, &rDims, sizeof(RECT)); IncrementMinMaxRect(&mrc, 6 + o->un2ix(LineDef.width)); mo = GetRectBitmap(&mrc, o); InvertLine(pts, cp, &LineDef, &mrc, o, mark); } else if(mo) RestoreRectBitmap(&mo, &mrc, o); }}bool
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -