⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rlplot.cpp

📁 Linux/windows 环境下跨平台开发程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	case SIZE_SYM_LINE:		SymLine.width = value;		return true;	case SIZE_XPOS:		fPos.fx = value;		return true;	case SIZE_YPOS:		fPos.fy = value;		return true;	}	return false;}DWORDSymbol::GetColor(int select){	switch(select) {	case COL_SYM_LINE:		return SymLine.color;	case COL_SYM_FILL:		return SymFill.color;	default:		return parent ? parent->GetColor(select) : defs.Color(select);		}}boolSymbol::SetColor(int select, DWORD col){	switch(select & 0xfff) {	case COL_SYM_LINE:		SymLine.color = col;		if(SymTxt) SymTxt->ColTxt = col;		return true;	case COL_SYM_FILL:		SymFill.color = col;		return true;	default:		return false;		}}voidSymbol::DoPlot(anyOutput *target){	int ix, iy, rx, ry, atype;	lfPOINT fip;	POINT pts[5];	FillDEF cf;	if(size <= 0.001) return;	atype = (type  & 0xfff);	memcpy(&cf, &SymFill, sizeof(FillDEF));	if(atype == SYM_CIRCLEF || atype == SYM_RECTF || atype == SYM_TRIAUF ||		atype == SYM_TRIADF || atype == SYM_DIAMONDF) cf.color = SymLine.color;	if(type & SYM_POS_PARENT) {		if(!parent) return;		fip.fx = parent->GetSize(SIZE_XCENTER);		fip.fy = parent->GetSize(SIZE_YCENTER);		}	else if(!target->fp2fip(&fPos, &fip)) return;	ix = iround(fip.fx);		iy = iround(fip.fy);	target->SetLine(&SymLine);	switch(atype){	default:	case SYM_CIRCLE:		//circle	case SYM_CIRCLEF:		//filled circle		rx = target->un2ix(size/2.0);		ry = target->un2iy(size/2.0); 		target->SetFill(&cf);		target->oCircle(ix-rx, iy-ry, ix+rx+1, iy+ry+1, name);		rx--;ry--;			//smaller marking rectangle		break;	case SYM_RECT:			//rectange (square)	case SYM_RECTF:			//filled rectangle		rx = target->un2ix(size/2.25676);		ry = target->un2iy(size/2.25676);		target->SetFill(&cf);		target->oRectangle(ix-rx, iy-ry, ix+rx+1, iy+ry+1, name);		break;	case SYM_TRIAU:			//triangles up and down, open or closed	case SYM_TRIAUF:	case SYM_TRIAD:		case SYM_TRIADF:		rx = target->un2ix(size/1.48503);		ry = target->un2iy(size/1.48503);		target->SetFill(&cf);		pts[0].x = pts[3].x = ix - rx;		pts[1].x = ix;		pts[2].x = ix+rx;		if(atype == SYM_TRIAU || atype == SYM_TRIAUF) {		//patch by anonymous			pts[0].y = pts[2].y = pts[3].y = iy+target->un2iy(size*0.38878f);			pts[1].y = iy-target->un2iy(size*0.77756f);			}		else {			pts[0].y = pts[2].y = pts[3].y = iy-target->un2iy(size*0.38878f);			pts[1].y = iy+target->un2iy(size*0.77756f);			}		target->oPolygon(pts, 4);		rx--; ry--;		break;	case SYM_DIAMOND:	case SYM_DIAMONDF:		rx = target->un2ix(size/1.59588f);		ry = target->un2iy(size/1.59588f);		target->SetFill(&cf);		pts[0].x = pts[2].x = pts[4].x = ix;				pts[0].y = pts[4].y = iy -ry;		pts[1].x = ix +rx;					pts[1].y = pts[3].y = iy;		pts[2].y = iy +ry;					pts[3].x = ix-rx;		target->oPolygon(pts, 5);		rx--;									ry--;		break;	case SYM_STAR:			//star is a combination of + and x symbols	case SYM_PLUS:			//draw a + sign	case SYM_HLINE:		case SYM_VLINE:		rx = target->un2ix(size/2.0f);		ry = target->un2iy(size/2.0f);		pts[0].x = pts[1].x = ix;		pts[0].y = iy - ry;					pts[1].y = iy + ry +1;		if(type != SYM_HLINE) target->oPolyline(pts, 2);		pts[0].x = ix -rx;					pts[1].x = ix + rx +1;		pts[0].y = pts[1].y = iy;		if(atype != SYM_VLINE) target->oPolyline(pts, 2);		if(atype == SYM_VLINE){ rx = 2; break;}		if(atype == SYM_HLINE){ ry = 2; break;}		if(atype == SYM_PLUS) break;		//continue with x symbol for star	case SYM_CROSS:			//draw a x symbol		rx = target->un2ix(size/2.5);		ry = target->un2iy(size/2.5);		pts[0].x = ix - rx;					pts[1].x = ix + rx;		pts[0].y = iy - ry;					pts[1].y = iy + ry;		target->oPolyline(pts, 2);		Swap(pts[0].y, pts[1].y);		target->oPolyline(pts, 2);		break;	case SYM_TEXT:		if(!SymTxt) Command(CMD_SETTEXT, (void *)"text", target);		if(!SymTxt || !SymTxt->text || !SymTxt->text[0])return;		SymTxt->iSize = target->un2iy(SymTxt->fSize = size *1.5);		target->SetTextSpec(SymTxt);
		fmtText(target, ix, iy, SymTxt->text);		if (target->oGetTextExtent(SymTxt->text, 0, &rx, &ry)){			rx >>= 1;		ry >>= 1;			}		else rx = ry = 10;		}	rDims.left = ix-rx-1;				rDims.right = ix+rx+1;	rDims.top = iy-ry-1;				rDims.bottom = iy+ry+1;}bool Symbol::Command(int cmd, void *tmpl, anyOutput *o){	MouseEvent *mev;	char *tmptxt;	AccRange *ac;	int i, r, c;	switch (cmd) {	case CMD_FLUSH:		if(SymTxt) {			if(SymTxt->text) free(SymTxt->text);			free(SymTxt);			}		if(ssRef) free(ssRef);	ssRef = 0L;		if(name)free(name);		name = 0L;		return true;	case CMD_REDRAW:		//if we come here its most likely the result of Undo		if(parent && parent->Id==GO_REGRESSION)			return parent->Command(CMD_MRK_DIRTY, 0L, o);		return false;	case CMD_GETTEXT:		if(SymTxt && SymTxt->text && tmpl) {			strcpy((char*)tmpl, SymTxt->text);			return true;			}		return false;	case CMD_SYMTEXT_UNDO:		if(SymTxt && SymTxt->text){			Undo.String(this, &SymTxt->text, UNDO_CONTINUE);
			if(tmpl) {
				if(SymTxt->text = (char*)realloc(SymTxt->text, strlen((char*)tmpl))+2)
					strcpy(SymTxt->text, (char*)tmpl);
				}
			else if(SymTxt->text) SymTxt->text[0] = 0;
			return true;			}		//fall through if its new	case CMD_SYMTEXT:		case CMD_SETTEXT:		if(!SymTxt && (SymTxt = (TextDEF *) calloc(1, sizeof(TextDEF)))) {			SymTxt->ColTxt = SymLine.color;			SymTxt->fSize = size*1.5;			SymTxt->ColBg = parent ? parent->GetColor(COL_BG) : 0x00ffffffL;			SymTxt->Align = TXA_VCENTER | TXA_HCENTER;			SymTxt->Style = TXS_NORMAL;				SymTxt->Mode = TXM_TRANSPARENT;			SymTxt->Font = FONT_HELVETICA;			SymTxt->text = 0L;			}		if(!SymTxt) return false;		if(tmpl) {
			if(SymTxt->text = (char*)realloc(SymTxt->text, strlen((char*)tmpl)+1))
				strcpy(SymTxt->text, (char*)tmpl);
			}
		else if(SymTxt->text) SymTxt->text[0] = 0;
		return true;	case CMD_SYM_TYPE:		if(tmpl)type = *((int*)tmpl);		return true;	case CMD_GETTEXTDEF:		if(!SymTxt || !tmpl) return false;		memcpy(tmpl, SymTxt, sizeof(TextDEF));		return true;	case CMD_SYMTEXTDEF:		case CMD_SETTEXTDEF:		if(!tmpl)return false;		if(SymTxt) tmptxt = SymTxt->text;		else tmptxt = 0L;		if(!SymTxt && !(SymTxt = (TextDEF *) calloc(1, sizeof(TextDEF)))) return false;		memcpy(SymTxt, tmpl, sizeof(TextDEF));		SymTxt->text = tmptxt;		return true;	case CMD_SYM_RANGETEXT:		case CMD_RANGETEXT:		if(!data || !tmpl) return false;		if(!(tmptxt = (char*)malloc(500)))return false;		if((ac = new AccRange((char*)tmpl)) && ac->GetFirst(&c, &r)) {			for(i = 0, tmptxt[0] = 0; i <= idx; i++) ac->GetNext(&c, &r);			data->GetText(r, c, tmptxt, 500);			delete(ac);			}		Command(CMD_SETTEXT, tmptxt, 0L);		free(tmptxt);		return true;	case CMD_SET_DATAOBJ:		Id = GO_SYMBOL;		data = (DataObj *)tmpl;		return true;	case CMD_MOUSE_EVENT:		mev = (MouseEvent *) tmpl;		switch (mev->Action) {		case MOUSE_LBUP:			if(IsInRect(&rDims, mev->x, mev->y) && !CurrGO) {				o->ShowMark(&rDims, MRK_INVERT);				CurrGO = this;				return true;				}			break;			}		break;	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);			return true;			}		break;		}	return false;}//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// Bubbles are graphic objectsBubble::Bubble(GraphObj *par, DataObj *d, double x, double y, double s, int which, 	FillDEF *fill, LineDEF *outline, int xc, int xr, int yc, int yr, int sc,	int sr):GraphObj(par, d){	FileIO(INIT_VARS);	fPos.fx = x;	fPos.fy = y;	fs = s;	type = which;	if(fill) {		memcpy(&BubbleFill,fill, sizeof(FillDEF));		if(BubbleFill.hatch) memcpy(&BubbleFillLine, BubbleFill.hatch, sizeof(LineDEF));		}	BubbleFill.hatch = &BubbleFillLine;	if(outline)memcpy(&BubbleLine, outline, sizeof(LineDEF));	Id = GO_BUBBLE;	if(xc >= 0 || xr >= 0 || yc >= 0 || yr >= 0 || sc >= 0 || sr >= 0) {		if(ssRef = (POINT*)malloc(sizeof(POINT)*3)) {			ssRef[0].x = xc;	ssRef[0].y = xr;			ssRef[1].x = yc;	ssRef[1].y = yr;			ssRef[2].x = sc;	ssRef[2].y = sr;			cssRef = 3;			}		}}Bubble::Bubble(int src):GraphObj(0L, 0L){	FileIO(INIT_VARS);	if(src == FILE_READ) {		FileIO(FILE_READ);		}}Bubble::~Bubble(){	Command(CMD_FLUSH, 0L, 0L);}voidBubble::DoPlot(anyOutput *o){	int x1, y1, x2, y2, ix, iy, tmp;	double fix, fiy;	o->SetLine(&BubbleLine);	o->SetFill(&BubbleFill);	switch(type & 0x0f0) {	case BUBBLE_UNITS:		fix = o->un2fix(fs);		fiy = o->un2fiy(fs);		break;	case BUBBLE_XAXIS:		fix = (o->fx2fix(fPos.fx+fs) - o->fx2fix(fPos.fx-fs))/2.0;		fiy = fix * (o->un2fiy(10.0f)/o->un2fix(10.0f));	//x and y resolution different ?		break;	case BUBBLE_YAXIS:		fix = (o->fy2fiy(fPos.fy-fs) - o->fy2fiy(fPos.fy+fs))/2.0;		fiy = fix * (o->un2fiy(10.0f)/o->un2fix(10.0f));	//x and y resolution different ?		break;		}	fix = fix < 0.0 ? -fix : fix;							//sign must be positive	fiy = fiy < 0.0 ? -fiy : fiy;	rDims.left = rDims.right = iround(o->fx2fix(fPos.fx));	rDims.top = rDims.bottom = iround(o->fy2fiy(fPos.fy));	switch(type & 0x00f) {	case BUBBLE_CIRCLE:		ix = (int)(fix/2.0);			iy = (int)(fiy/2.0);		tmp = iround(o->fx2fix(fPos.fx));		x1 = tmp - ix;		x2 = tmp + ix;		tmp = iround(o->fy2fiy(fPos.fy));		y1 = tmp - iy;		y2 = tmp + iy;		o->oCircle(x1, y1, x2, y2, name);		UpdateMinMaxRect(&rDims, x1, y1);	UpdateMinMaxRect(&rDims, x2, y2);		break;	case BUBBLE_SQUARE:		if((type & 0xf00) == BUBBLE_CIRCUM) {			ix = iround(fix*.392699081);		iy = iround(fiy*.392699081);			}		else if((type & 0xf00) == BUBBLE_AREA) {			ix = iround(fix*.443113462);		iy = iround(fiy*.443113462);			}		else {			ix = iround(fix*.353553391);		iy = iround(fiy*.353553391);			}		tmp = iround(o->fx2fix(fPos.fx));		x1 = tmp - ix;		x2 = tmp + ix;		tmp = iround(o->fy2fiy(fPos.fy));		y1 = tmp - iy;		y2 = tmp + iy;		o->oRectangle(x1, y1, x2, y2, name);		UpdateMinMaxRect(&rDims, x1, y1);	UpdateMinMaxRect(&rDims, x2, y2);		break;	case BUBBLE_UPTRIA:	case BUBBLE_DOWNTRIA:		if((type & 0xf00) == BUBBLE_CIRCUM) {			fix *= .523598775;		fiy *= .523598775;			}		else if((type & 0xf00) == BUBBLE_AREA) {			fix *= .673386843;		fiy *= .673386843;			}		else {			fix *=.433012702;		fiy *= .433012702;			}		ix =  iround(fix);		iy = iround(fiy*.57735);		tmp = iround(o->fx2fix(fPos.fx));		pts[0].x = pts[3].x = tmp - ix;		pts[1].x = tmp + ix;		pts[2].x = tmp;		tmp = iround(o->fy2fiy(fPos.fy));		if((type & 0x00f) == BUBBLE_UPTRIA) {			pts[0].y = pts[1].y = pts[3].y = tmp + iy;			pts[2].y = tmp - iround(fiy*1.1547);			}		else {			pts[0].y = pts[1].y = pts[3].y = tmp - iy;			pts[2].y = tmp + iround(fiy*1.1547);			}		o->oPolygon(pts, 4);		UpdateMinMaxRect(&rDims, pts[0].x, pts[0].y);		UpdateMinMaxRect(&rDims, pts[1].x, pts[2].y);		break;		}}voidBubble::DoMark(anyOutput *o, bool mark){	if(mark) {		BubbleFillLine.color ^= 0x00ffffffL;		BubbleFill.color ^= 0x00ffffffL;		DoPlot(o);		BubbleFill.color ^= 0x00ffffffL;		BubbleFillLine.color ^= 0x00ffffffL;		}	else {		if(parent) parent->DoPlot(o);		else DoPlot(o);		}	o->UpdateRect(&rDims, false);}bool Bubble::Command(int cmd, void *tmpl, anyOutput *o){	MouseEvent *mev;	bool bSelected = false;	unsigned long n, s;	POINT p;	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(&BubbleLine, &BubbleFill);
		break;
	case CMD_MOUSE_EVENT:		mev = (MouseEvent *) tmpl;		switch (mev->Action) {		case MOUSE_LBUP:			if(IsInRect(&rDims, p.x = mev->x, p.y = mev->y) && !CurrGO) {				switch(type & 0x00f) {				case BUBBLE_CIRCLE:					n = s = p.x - ((rDims.right+rDims.left)>>1);					s *= n;					n = p.y - ((rDims.bottom+rDims.top)>>1);					n = isqr(s += n*n) -2;					bSelected = ((unsigned)((rDims.right-rDims.left)>>1) > n);					break;				case BUBBLE_SQUARE:					bSelected = true;					break;				case BUBBLE_UPTRIA:				case BUBBLE_DOWNTRIA:					if(!(bSelected = IsInPolygon(&p, pts, 4)))						bSelected = IsCloseToPL(p, pts, 4);					break;					}				if(bSelected) o->ShowMark(this, MRK_GODRAW);				return bSelected;				}			break;			}		break;	case CMD_SET_DATAOBJ:		Id = GO_BUBBLE;		data = (DataObj*)tmpl;		return true;	case CMD_UPDATE:		if(ssRef && cssRef >2 && data) {			data->GetValue(ssRef[0].y, ssRef[0].x, &fPos.fx);			data->GetValue(ssRef[1].y, ssRef[1].x, &fPos.fy);			data->GetValue(ssRef[2].y, ssRef[2].x, &fs);			return true;			}		return false;	case CMD_BUBBLE_ATTRIB:		if(tmpl) {			type &= ~0xff0;			type |= (*((int*)tmpl) & 0xff0);			return true;			}		return false;	case CMD_BUBBLE_TYPE:		if(tmpl) {			type &= ~0x00f;			type |= (*((int*)tmpl) & 0x00f);			return true;			}		return false;	case CMD_BUBBLE_FILL:		if(tmpl) {			BubbleFill.type = ((FillDEF*)tmpl)->type;			BubbleFill.color = ((FillDEF*)tmpl)->color;			BubbleFill.scale = ((FillDEF*)tmpl)->scale;			if(((FillDEF*)tmpl)->hatch)				memcpy(&BubbleFillLine, ((FillDEF*)tmpl)->hatch, sizeof(LineDEF));			}		return true;	case CMD_BUBBLE_LINE:		if(tmpl) memcpy(&BubbleLine, tmpl, sizeof(LineDEF));		return true;	case CMD_AUTOSCALE:
		return DoAutoscale(o);		break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -