📄 rlplot.cpp
字号:
if(minRC && IsInRect(minRC, upd.right+p->x, (upd.top+upd.bottom)>>1)) upd.right = minRC->right; else if(maxRC && !IsInRect(maxRC, upd.right+p->x, (upd.top+upd.bottom)>>1)) upd.right = upd.right+p->x <= maxRC->left ? maxRC->left : maxRC->right; else upd.right += p->x; break; case DH_99: if(minRC && IsInRect(minRC, upd.right+p->x, (upd.top+upd.bottom)>>1)) upd.right = minRC->right; else if(maxRC && !IsInRect(maxRC, upd.right+p->x, (upd.top+upd.bottom)>>1)) upd.right = upd.right+p->x <= maxRC->left ? maxRC->left : maxRC->right; else upd.right += p->x; case DH_89: if(minRC && IsInRect(minRC, (upd.left + upd.right)>>1, upd.bottom+p->y)) upd.bottom = minRC->bottom; else if(maxRC && !IsInRect(maxRC, (upd.left + upd.right)>>1, upd.bottom+p->y)) upd.bottom = upd.bottom+p->y <= maxRC->top? maxRC->top : maxRC->bottom; else upd.bottom += p->y; break; case DH_79: if(minRC && IsInRect(minRC, (upd.left + upd.right)>>1, upd.bottom+p->y)) upd.bottom = minRC->bottom; else if(maxRC && !IsInRect(maxRC, (upd.left + upd.right)>>1, upd.bottom+p->y)) upd.bottom = upd.bottom+p->y <= maxRC->top? maxRC->top : maxRC->bottom; else upd.bottom += p->y; case DH_49: if(minRC && IsInRect(minRC, upd.left+p->x, (upd.top+upd.bottom)>>1)) upd.left = minRC->left; else if(maxRC && !IsInRect(maxRC, upd.left+p->x, (upd.top+upd.bottom)>>1)) upd.left = upd.left+p->x >= maxRC->right ? maxRC->right : maxRC->left; else upd.left += p->x; break; case DH_18: case DH_28: case DH_38: case DH_48: case DH_58: case DH_68: case DH_78: case DH_88: CurrGO = this; case DH_59: parent->parent->Track(p, o); return; default: if(type >= DH_DATA) { idx = type - DH_DATA; pts[1].x = o->co2ix(parent->GetSize(SIZE_XPOS + idx)+dx); pts[1].y = o->co2iy(parent->GetSize(SIZE_YPOS + idx)+dy); pts[1].x += p->x; pts[1].y += p->y; if(type > DH_DATA) { pts[0].x = o->co2ix(parent->GetSize(SIZE_XPOS + idx -1)+dx); pts[0].y = o->co2iy(parent->GetSize(SIZE_YPOS + idx -1)+dy); } else { pts[0].x = pts[1].x; pts[0].y = pts[1].y; } pts[2].x = o->co2ix(parent->GetSize(SIZE_XPOS + idx +1)+dx); pts[2].y = o->co2iy(parent->GetSize(SIZE_YPOS + idx +1)+dy); UpdateMinMaxRect(&upd, pts[0].x, pts[0].y); UpdateMinMaxRect(&upd, pts[1].x, pts[1].y); UpdateMinMaxRect(&upd, pts[2].x, pts[2].y); npts = 3; if(color == 0x0L || color == 0x00ffffffL) color = 0x00c0c0c0L; } else return; } if(type >= DH_19 && type <= DH_99) { pts[0].x = pts[4].x = pts[3].x = p1.x = upd.left; pts[0].y = pts[1].y = pts[4].y = p1.y = upd.top; pts[1].x = pts[2].x = p2.x = upd.right; pts[2].y = pts[3].y = p2.y = upd.bottom; npts = 5; if(parent->parent->Id == GO_ELLIPSE) o->ShowEllipse(p1, p2, color); } o->ShowLine(pts, npts, color);}//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// the dragRect object uses nine dragHandles to create a user interface// for modification of rectangular shapesdragRect::dragRect(GraphObj *par, int which):GraphObj(par, 0L){ int i; type = which; Id = GO_DRAGRECT; if(handles = (dragHandle**)calloc(9, sizeof(dragHandle*))) for(i = 0; i < 9; i++){ if(i == 4 && type == 0) handles[i] = new dragHandle(this, DH_19 + i); else if(i != 4) handles[i] = new dragHandle(this, DH_19 + i); }}dragRect::~dragRect(){ int i; if(handles) for(i = 0; i < 9; i++) if(handles[i]) DeleteGO(handles[i]);}voiddragRect::DoPlot(anyOutput *o){ int i; if(handles) for(i = 0; i < 9; i++) if(handles[i]) handles[i]->DoPlot(o);}booldragRect::Command(int cmd, void *tmpl, anyOutput *o){ int i; if(!parent) return false; switch (cmd) { case CMD_MINRC: case CMD_MAXRC: if(handles) for(i = 0; i < 9; i++) { if(handles[i]) handles[i]->Command(cmd, tmpl, o); } break; case CMD_SAVEPOS: case CMD_REDRAW: return parent->Command(cmd, tmpl, o); } return false;}void *dragRect::ObjThere(int x, int y){ int i; void *go; if(handles) for(i = 0; i < 9; i++) if(handles[i] && (go = (handles[i])->ObjThere(x, y))) return go; return 0L;}//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// implement some kind of virtual trackball for 3D plotsDrag3D::Drag3D(GraphObj *par):GraphObj(par, 0L){ int i; Id = GO_DRAG3D; if(handles = (dragHandle**)calloc(8, sizeof(dragHandle*))) for(i = 0; i < 8; i++){ handles[i] = new dragHandle(this, DH_18 + i); }}Drag3D::~Drag3D(){ int i; if(handles) for(i = 0; i < 8; i++) if(handles[i]) DeleteGO(handles[i]);}voidDrag3D::DoPlot(anyOutput *o){ int i; if(handles) for(i = 0; i < 8; i++) if(handles[i]) handles[i]->DoPlot(o);}void *Drag3D::ObjThere(int x, int y){ int i; void *go; if(handles) for(i = 0; i < 8; i++) if(handles[i] && (go = (handles[i])->ObjThere(x, y))) return go; return 0L;}//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// frame rectangleFrmRect::FrmRect(GraphObj *par, fRECT *lim, fRECT *c, fRECT *chld):GraphObj(par, 0L){ parent = par; limRC = lim; cRC = c; chldRC = chld; drag = 0L; mo = 0L; Id = GO_FRAMERECT; moveable = true; Fill.type = FILL_NONE; Line.color = FillLine.color = Fill.color = 0x00ffffffL; Line.width = FillLine.width = 0.0; Line.patlength = FillLine.patlength = Fill.scale = 1.0; Line.pattern = FillLine.pattern = 0x0L; Fill.hatch = &FillLine; minRC = maxRC = 0L;}FrmRect::~FrmRect(){ if(drag) DeleteGO(drag); drag = 0L; if(minRC) free(minRC); minRC = 0L; if(maxRC) free(maxRC); maxRC = 0L; if(mo) DelBitmapClass(mo); mo = 0L;}doubleFrmRect::GetSize(int select){ switch(select) { case SIZE_XPOS: return CurrRect.Xmin; case SIZE_XPOS+1: return CurrRect.Xmax; case SIZE_YPOS: return CurrRect.Ymin; case SIZE_YPOS+1: return CurrRect.Ymax; } return 0.0;}boolFrmRect::SetSize(int select, double value){ double tmp, o_left, o_top; o_left = cRC->Xmin; o_top = cRC->Ymin; switch (select & 0xfff) { case SIZE_XPOS: if(limRC) value -= limRC->Xmin; if(swapX) cRC->Xmax = value; else cRC->Xmin = value; break; case SIZE_XPOS+1: if(limRC) value -= limRC->Xmin; if(swapX) cRC->Xmin = value; else cRC->Xmax = value; break; case SIZE_YPOS: if(limRC) value -= limRC->Ymin; if(swapY) cRC->Ymin = value; else cRC->Ymax = value; break; case SIZE_YPOS+1: if(limRC) value -= limRC->Ymin; if(swapY) cRC->Ymax = value; else cRC->Ymin = value; break; default: return false; } if((swapX && cRC->Xmin < cRC->Xmax) || (!swapX && cRC->Xmin > cRC->Xmax)) { tmp = cRC->Xmin; cRC->Xmin = cRC->Xmax; cRC->Xmax = tmp; } if((swapY && cRC->Ymin > cRC->Ymax) || (!swapY && cRC->Ymin < cRC->Ymax)) { tmp = cRC->Ymin; cRC->Ymin = cRC->Ymax; cRC->Ymax = tmp; } if(chldRC) { //check if new rectangle is not inside child rectangle if(cRC->Xmin > o_left+ chldRC->Xmin) cRC->Xmin = o_left + chldRC->Xmin; if(cRC->Xmax < o_left+ chldRC->Xmax) cRC->Xmax = o_left + chldRC->Xmax; if(cRC->Ymin > o_top+ chldRC->Ymin) cRC->Ymin = o_top + chldRC->Ymin; if(cRC->Ymax < o_top+ chldRC->Ymax) cRC->Ymax = o_top + chldRC->Ymax; } if(chldRC && (o_left != cRC->Xmin || o_top != cRC->Ymin)) { chldRC->Xmin -= (tmp = cRC->Xmin - o_left); chldRC->Xmax -= tmp; chldRC->Ymin -= (tmp = cRC->Ymin - o_top); chldRC->Ymax -= tmp; } return true;}boolFrmRect::SetColor(int select, DWORD col){ switch(select & 0xfff){ case COL_DRECT: Line.color = col; case COL_BG: Fill.color = col; return true; case COL_GRECT: Fill.color = col; return true; case COL_GRECTLINE: Line.color = col; return true; } return false;}void FrmRect::DoMark(anyOutput *o, bool mark){ if(!parent || !o) return; if(!drag && (drag = new dragRect(this, (!limRC && parent->moveable) ? 0 : 1))){ if(minRC) drag->Command(CMD_MINRC, minRC, o); if(maxRC) drag->Command(CMD_MAXRC, maxRC, o); } if(mark && drag){ memcpy(&mrc, &rDims, sizeof(RECT)); IncrementMinMaxRect(&mrc, 6); mo = GetRectBitmap(&mrc, o); drag->DoPlot(o); o->UpdateRect(&mrc, false); } else RestoreRectBitmap(&mo, &mrc, o);}voidFrmRect::DoPlot(anyOutput *o){ int x1, y1, x2, y2; double tmp; if(!(cRC) || !o) return; o->dFillCol = Fill.color ^ 0x00ffffff; //force new brush o->dLineCol = Line.color ^ 0x00ffffff; //force new pen o->SetLine(&Line); o->SetFill(&Fill); CurrRect.Xmin = cRC->Xmin; CurrRect.Xmax = cRC->Xmax; CurrRect.Ymin = cRC->Ymax; CurrRect.Ymax = cRC->Ymin; if(limRC) { CurrRect.Xmin += limRC->Xmin; CurrRect.Xmax += limRC->Xmin; CurrRect.Ymin += limRC->Ymin; CurrRect.Ymax += limRC->Ymin; } if(swapX = (CurrRect.Xmin > CurrRect.Xmax)) { tmp = CurrRect.Xmin; CurrRect.Xmin = CurrRect.Xmax; CurrRect.Xmax = tmp; } if(swapY = (CurrRect.Ymin > CurrRect.Ymax)) { tmp = CurrRect.Ymin; CurrRect.Ymin = CurrRect.Ymax; CurrRect.Ymax = tmp; } o->oRectangle(x1 = o->co2ix(CurrRect.Xmin), y1 = o->co2iy(CurrRect.Ymin), x2 = o->co2ix(CurrRect.Xmax), y2 = o->co2iy(CurrRect.Ymax)); SetMinMaxRect(&rDims, x1, y1, x2, y2);}boolFrmRect::Command(int cmd, void *tmpl, anyOutput *o){ MouseEvent *mev; if(!parent) return false; switch (cmd) { case CMD_MOUSE_EVENT: mev = (MouseEvent *) tmpl; switch (mev->Action) { case MOUSE_LBUP: if(IsInRect(&rDims, mev->x, mev->y) && !(CurrGO) && (o)){ o->ShowMark(this, MRK_GODRAW); if(parent && parent->Id == GO_GRAPH) CurrGraph = (Graph*)parent; return true; } } return false; case CMD_MINRC: if(!(minRC)) minRC = (RECT*)calloc(1, sizeof(RECT)); if(minRC && tmpl) SetMinMaxRect(minRC, ((RECT*)tmpl)->left, ((RECT*)tmpl)->top, ((RECT*)tmpl)->right, ((RECT*)tmpl)->bottom); if(drag) drag->Command(cmd, tmpl, o); return true; case CMD_MAXRC: if(!(maxRC)) maxRC = (RECT*)calloc(1, sizeof(RECT)); if(maxRC && tmpl) SetMinMaxRect(maxRC, ((RECT*)tmpl)->left, ((RECT*)tmpl)->top, ((RECT*)tmpl)->right, ((RECT*)tmpl)->bottom); if(drag) drag->Command(cmd, tmpl, o); return true; case CMD_MOVE: cRC->Xmin += NiceValue(((lfPOINT*)tmpl)[0].fx); cRC->Ymin += NiceValue(((lfPOINT*)tmpl)[0].fy); cRC->Xmax += NiceValue(((lfPOINT*)tmpl)[0].fx); cRC->Ymax += NiceValue(((lfPOINT*)tmpl)[0].fy); case CMD_REDRAW: return parent->Command(CMD_REDRAW, 0L, o); case CMD_SAVEPOS: return parent->Command(cmd, tmpl, o); case CMD_SETCHILD: chldRC = (fRECT*)tmpl; return true; } return false;}void *FrmRect::ObjThere(int x, int y){ if(drag) return drag->ObjThere(x, y); return 0L;}voidFrmRect::Track(POINT *p, anyOutput *o){ POINT tpts[5]; RECT old_rc; if(o){ memcpy(&old_rc, &rDims, sizeof(rDims)); o->UpdateRect(&rDims, false); tpts[0].x = tpts[1].x = tpts[4].x = o->co2ix(cRC->Xmin)+p->x; tpts[0].y = tpts[3].y = tpts[4].y = o->co2iy(cRC->Ymin)+p->y; tpts[1].y = tpts[2].y = o->co2iy(cRC->Ymax)+p->y; tpts[2].x = tpts[3].x = o->co2ix(cRC->Xmax)+p->x; UpdateMinMaxRect(&rDims, tpts[0].x, tpts[0].y); UpdateMinMaxRect(&rDims, tpts[2].x, tpts[2].y); if(old_rc.left != rDims.left || old_rc.right != rDims.right || old_rc.top != rDims.top || old_rc.bottom != rDims.bottom)IncrementMinMaxRect(&rDims, 3); o->ShowLine(tpts, 5, Fill.color ^ 0x00ffffffL); }}//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// This is a special object to read certain svg-settings from a *.rlp filesvgOptions::svgOptions(int src):GraphObj(0L, 0L){ FileIO(INIT_VARS); if(defs.svgScript) free(defs.svgScript); if(defs.svgAttr) free(defs.svgAttr); defs.svgScript = defs.svgAttr = 0L; if(src == FILE_READ) { FileIO(FILE_READ); if(script) defs.svgScript = script; if(svgattr) defs.svgAttr = svgattr; script = svgattr = 0L; } Id=GO_SVGOPTIONS;}svgOptions::~svgOptions(){ if(script)free(script); script = 0L;}//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// Symbols are graphic objectsSymbol::Symbol(GraphObj *par, DataObj *d, double x, double y, int which, int xc, int xr, int yc, int yr):GraphObj(par, d){ //Symbols with no parent are part of a dialog FileIO(INIT_VARS); fPos.fx = x; fPos.fy = y; type = which; Id = GO_SYMBOL; 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; } }}Symbol::Symbol(int src):GraphObj(0L, 0L){ FileIO(INIT_VARS); if(src == FILE_READ) { FileIO(FILE_READ); SymFill.hatch = (LineDEF *) NULL; }}Symbol::~Symbol(){ Command(CMD_FLUSH, 0L, 0L);}doubleSymbol::GetSize(int select){ switch(select) { case SIZE_MINE: case SIZE_SYMBOL: return size; case SIZE_SYM_LINE: return SymLine.width; case SIZE_XPOS: return fPos.fx; case SIZE_YPOS: return fPos.fy; default: return parent ? parent->GetSize(select) : defs.GetSize(select); }}boolSymbol::SetSize(int select, double value){ switch(select & 0xfff){ case SIZE_MINE: case SIZE_SYMBOL: size = value; return true;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -