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

📄 rlplot.cpp

📁 Linux/windows 环境下跨平台开发程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//RLPlot.cpp, Copyright 2000, 2001, 2002, 2003, 2004, 2005 R.Lackner////    This file is part of RLPlot.////    RLPlot is free software; you can redistribute it and/or modify//    it under the terms of the GNU General Public License as published by//    the Free Software Foundation; either version 2 of the License, or//    (at your option) any later version.////    RLPlot is distributed in the hope that it will be useful,//    but WITHOUT ANY WARRANTY; without even the implied warranty of//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the//    GNU General Public License for more details.////    You should have received a copy of the GNU General Public License//    along with RLPlot; if not, write to the Free Software//    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA//#include "rlplot.h"#include <stdio.h>#include <stdlib.h>#include <math.h>#include <string.h>extern tag_Units Units[];extern char TmpTxt[];extern Default defs;GraphObj *CurrGO, *TrackGO;			//Selected Graphic ObjectsLabel *CurrLabel = 0L;Graph *CurrGraph = 0L;dragHandle *CurrHandle = 0L;Axis **CurrAxes = 0L;UndoObj Undo;int cGraphs = 0;int cPlots = 0;int cPages = 0;//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// grapic objects//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~GraphObj::GraphObj(GraphObj *par, DataObj *d){	parent = par;	data = d;	Id = GO_UNKNOWN;	type = moveable = 0;	name = 0L;	rDims.left = rDims.right = rDims.top = rDims.bottom = 0;}GraphObj::~GraphObj(){	if(name)free(name);	name = 0L;	if(CurrGO == this) CurrGO = 0L;	if(TrackGO == this) TrackGO = 0L;}doubleGraphObj::GetSize(int select){	if(parent) return parent->GetSize(select);	else return defs.GetSize(select);}DWORD GraphObj::GetColor(int select){	return defs.Color(select);}
void
GraphObj::RegGO(void *n)
{
	((notary*)n)->AddRegGO(this);
}
void *GraphObj::ObjThere(int x, int y){	if(IsInRect(&rDims, x, y)) return this;	else return 0L;}voidGraphObj::Track(POINT *p, anyOutput *o){}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// Spread sheet buttons used for rows and columnsssButton::ssButton(GraphObj *par, int x, int y, int w, int h):GraphObj(par, 0L){	bLBdown = false;	SetMinMaxRect(&rDims, x, y, x+w, y+h);	Line.width = 0.0f;				Line.patlength = 1.0f;	Line.color = 0x00000000L;		Line.pattern = 0x00000000L;	Fill.type = FILL_NONE;			Fill.color = 0x00e8e8e8L;	Fill.scale = 1.0;				Fill.hatch = NULL;	TextDef.ColTxt = 0x00000000L;	TextDef.ColBg = 0x00ffffffL;	TextDef.fSize = 4.0;			TextDef.RotBL = TextDef.RotCHAR = 0.0;	TextDef.iSize = 0;				TextDef.Align = TXA_HLEFT | TXA_VTOP;	TextDef.Mode = TXM_TRANSPARENT;	TextDef.Style = TXS_NORMAL;	TextDef.Font = FONT_HELVETICA;	TextDef.text = 0L;
	bSelected = false;}ssButton::~ssButton(){	if(TextDef.text) free(TextDef.text);}voidssButton::DoPlot(anyOutput *o){	POINT pts[3];	Line.color = 0x00000000L;		Fill.color = bSelected ? 0x00ffffff : 0x00e8e8e8L;	o->SetLine(&Line);				o->SetFill(&Fill);	if(bLBdown){		o->oRectangle(rDims.left, rDims.top, rDims.right, rDims.bottom);		}	else {		o->oRectangle(rDims.left, rDims.top, rDims.right-1, rDims.bottom-1);		Line.color = 0x00000000L;		o->SetLine(&Line);		pts[0].x = rDims.left;					pts[0].y = pts[1].y = rDims.bottom-1;		pts[1].x = pts[2].x = rDims.right-1;	pts[2].y = rDims.top-1;		o->oPolyline(pts, 3);		Line.color = 0x00ffffffL;		o->SetLine(&Line);		pts[0].x = pts[1].x = rDims.left;		pts[0].y = rDims.bottom -3;		pts[1].y = pts[2].y = rDims.top;		pts[2].x = rDims.right -2;		o->oPolyline(pts, 3);		}	if(TextDef.text) {		o->SetTextSpec(&TextDef);#ifdef _WINDOWS		o->oTextOut((rDims.left + rDims.right)/2-2, (rDims.top + rDims.bottom)/2-1, TextDef.text, 0);#else		o->oTextOut((rDims.left + rDims.right)/2-2, (rDims.top + rDims.bottom)/2+1, TextDef.text, 0);#endif		}}voidssButton::DoMark(anyOutput *o, bool mark){	bLBdown = mark;	DoPlot(o);	o->UpdateRect(&rDims, false);}boolssButton::Command(int cmd, void *tmpl, anyOutput *o){	char *tmptxt;	MouseEvent *mev;	switch (cmd) {	case CMD_GETTEXT:		if(TextDef.text && tmpl) {			strcpy((char*)tmpl, TextDef.text);			return true;			}		return false;
	case CMD_SELECT:
		if(tmpl && *((int*)tmpl)) bSelected = true;
		else bSelected = false;
		if(o) DoPlot(o);
		return true;
	case CMD_SETTEXT:		if(TextDef.text) free(TextDef.text);		if(tmpl) TextDef.text = strdup((char*)tmpl);		else TextDef.text = 0L;		return true;	case CMD_GETTEXTDEF:		if(!tmpl) return false;		memcpy(tmpl, &TextDef, sizeof(TextDEF));		return true;	case CMD_SETTEXTDEF:		if(!tmpl)return false;		tmptxt = TextDef.text;		memcpy(&TextDef, tmpl, sizeof(TextDEF));		TextDef.text = tmptxt;		return true;	case CMD_MOUSE_EVENT:		if(!o || !(mev = (MouseEvent *) tmpl)) break;		if(IsInRect(&rDims, mev->x, mev->y)) {			if(bLBdown) {				if(!(mev->StateFlags & 0x01)) {					o->HideMark();					if(bLBdown) {						bLBdown = false; DoPlot(o);						}					}				}			else if(mev->StateFlags & 0x01) {				o->ShowMark(this, MRK_SSB_DRAW);				}			return true;			}		break;		}	return false;}//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// drag handles are graphic objects which allow the user to interactively//   change the size of an objectdragHandle::dragHandle(GraphObj *par, int which):GraphObj(par, 0L){	type = which;	Id = GO_DRAGHANDLE;	LineDef.width = LineDef.patlength = 0.0;	LineDef.color = LineDef.pattern = 0L;	FillDef.type = FILL_NONE;	FillDef.color = 0x00ffffffL;	FillDef.scale = 1.0;	FillDef.hatch = 0L;	minRC = maxRC = 0L;}dragHandle::~dragHandle(){	if(minRC) free(minRC);	if(maxRC) free(maxRC);	if(CurrHandle == this) CurrHandle = 0L;}voiddragHandle::DoPlot(anyOutput *o){	double fx, fy, dx, dy;	int ix, iy;	fPOINT3D fp3d, ifp3d;	bool is3D = false;	if(!o || !parent) return;	dx = parent->GetSize(SIZE_GRECT_LEFT);	dy = parent->GetSize(SIZE_GRECT_TOP);	SetMinMaxRect(&drec, o->co2ix(parent->GetSize(SIZE_XPOS)+dx), 		o->co2iy(parent->GetSize(SIZE_YPOS)+dy), o->co2ix(parent->GetSize(SIZE_XPOS+1)+dx),		o->co2iy(parent->GetSize(SIZE_YPOS+1)+dy));	switch(type) {	case DH_19:		case DH_12:		fx = parent->GetSize(SIZE_XPOS);	fy = parent->GetSize(SIZE_YPOS);		break;	case DH_99:		case DH_22:		fx = parent->GetSize(SIZE_XPOS+1);	fy = parent->GetSize(SIZE_YPOS+1);		break;	case DH_29:		fx = (parent->GetSize(SIZE_XPOS) + parent->GetSize(SIZE_XPOS+1))/2.0;		fy = parent->GetSize(SIZE_YPOS);		break;	case DH_39:		fx = parent->GetSize(SIZE_XPOS+1);	fy = parent->GetSize(SIZE_YPOS);		break;	case DH_49:		fx = parent->GetSize(SIZE_XPOS);		fy = (parent->GetSize(SIZE_YPOS) + parent->GetSize(SIZE_YPOS+1))/2.0;		break;	case DH_59:		fx = (parent->GetSize(SIZE_XPOS) + parent->GetSize(SIZE_XPOS+1))/2.0;		fy = (parent->GetSize(SIZE_YPOS) + parent->GetSize(SIZE_YPOS+1))/2.0;		break;	case DH_69:		fx = parent->GetSize(SIZE_XPOS+1);		fy = (parent->GetSize(SIZE_YPOS) + parent->GetSize(SIZE_YPOS+1))/2.0;		break;	case DH_79:		fx = parent->GetSize(SIZE_XPOS);		fy = parent->GetSize(SIZE_YPOS+1);		break;	case DH_89:		fx = (parent->GetSize(SIZE_XPOS) + parent->GetSize(SIZE_XPOS+1))/2.0;		fy = parent->GetSize(SIZE_YPOS+1);		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:		fp3d.fx = parent->GetSize(SIZE_XPOS + type - DH_18);		fp3d.fy = parent->GetSize(SIZE_YPOS + type - DH_18);		fp3d.fz = parent->GetSize(SIZE_ZPOS + type - DH_18);		is3D = true;		break;	default:		if(type >= DH_DATA) {			fx = parent->GetSize(SIZE_XPOS + type - DH_DATA);			fy = parent->GetSize(SIZE_YPOS + type - DH_DATA);			FillDef.color = (this == CurrHandle) ? 0x0L : 0x00ffffffL;			}		else return;		}	if(is3D) {		o->cvec2ivec(&fp3d, &ifp3d);		ix = iround(ifp3d.fx);		iy = iround(ifp3d.fy);		}	else {		ix = o->co2ix(fx+dx);	iy = o->co2iy(fy+dy);		}	SetMinMaxRect(&rDims, ix-4, iy-4, ix+4, iy+4);	memcpy(&upd, &rDims, sizeof(RECT));	switch(type) {	case DH_12:	case DH_22:	case DH_19:	case DH_29:	case DH_39:	case DH_49:	case DH_69:	case DH_79:	case DH_89:	case DH_99:		o->SetLine(&LineDef);		o->SetFill(&FillDef);		o->oRectangle(rDims.left, rDims.top, rDims.right, rDims.bottom);		o->UpdateRect(&rDims, false);		break;	case DH_59:		o->SetLine(&LineDef);		o->SetFill(&FillDef);		IncrementMinMaxRect(&rDims, 2);		o->oCircle(rDims.left, rDims.top, rDims.right, rDims.bottom);		IncrementMinMaxRect(&rDims, 1);		o->UpdateRect(&rDims, false);		break;	default:		if(type >= DH_DATA) {			o->SetLine(&LineDef);		o->SetFill(&FillDef);			o->oRectangle(rDims.left, rDims.top, rDims.right, rDims.bottom);			o->UpdateRect(&rDims, false);			}		else {			IncrementMinMaxRect(&rDims, -1);			o->UpdateRect(&rDims, true);			}		break;		}}booldragHandle::Command(int cmd, void *tmpl, anyOutput *o){	lfPOINT pos;	int idx;	if(!parent) return false;	switch (cmd) {	case CMD_MOUSECURSOR:		if(o) switch(type) {		case DH_19:	case DH_99:			o->MouseCursor(MC_SE, false);							break;		case DH_29:	case DH_89:			o->MouseCursor(MC_NORTH, false);						break;		case DH_39:	case DH_79:			o->MouseCursor(MC_NE, false);							break;		case DH_49:	case DH_69:			o->MouseCursor(MC_EAST, false);							break;		default:			if(type >= DH_DATA) o->MouseCursor(MC_SALL, false);			else o->MouseCursor(MC_MOVE, false);					break;			}		return true;	case CMD_MINRC:		if(!(minRC)) minRC = (RECT*)calloc(1, sizeof(RECT));		if(tmpl && minRC) SetMinMaxRect(minRC, ((RECT*)tmpl)->left, ((RECT*)tmpl)->top, 			((RECT*)tmpl)->right, ((RECT*)tmpl)->bottom);		return true;	case CMD_MAXRC:		if(!(maxRC)) maxRC = (RECT*)calloc(1, sizeof(RECT));		if(tmpl && maxRC) SetMinMaxRect(maxRC, ((RECT*)tmpl)->left, ((RECT*)tmpl)->top, 			((RECT*)tmpl)->right, ((RECT*)tmpl)->bottom);		return true;	case CMD_MOVE:		idx = type >= DH_DATA ? type - DH_DATA : 0;		pos.fx = NiceValue(((lfPOINT*)tmpl)[0].fx);		pos.fy = NiceValue(((lfPOINT*)tmpl)[0].fy);		if(pos.fx == 0.0 && pos.fy == 0.0) return false;		parent->Command(CMD_SAVEPOS, &idx, o);		switch(type) {		case DH_12:			parent->SetSize(SIZE_XPOS, pos.fx + parent->GetSize(SIZE_XPOS));			parent->SetSize(SIZE_YPOS, pos.fy + parent->GetSize(SIZE_YPOS));			break;		case DH_22:			parent->SetSize(SIZE_XPOS+1, pos.fx + parent->GetSize(SIZE_XPOS+1));			parent->SetSize(SIZE_YPOS+1, pos.fy + parent->GetSize(SIZE_YPOS+1));			break;		case DH_19: parent->parent->SetSize(SIZE_XPOS, 						pos.fx + parent->GetSize(SIZE_XPOS));		case DH_29: parent->parent->SetSize(SIZE_YPOS,						pos.fy + parent->GetSize(SIZE_YPOS));			break;		case DH_39: parent->parent->SetSize(SIZE_YPOS,						pos.fy + parent->GetSize(SIZE_YPOS));		case DH_69: parent->parent->SetSize(SIZE_XPOS+1,						pos.fx + parent->GetSize(SIZE_XPOS+1));			break;		case DH_99: parent->parent->SetSize(SIZE_XPOS+1, 						pos.fx + parent->GetSize(SIZE_XPOS+1));		case DH_89: parent->parent->SetSize(SIZE_YPOS+1,						pos.fy + parent->GetSize(SIZE_YPOS+1));			break;		case DH_79: parent->parent->SetSize(SIZE_YPOS+1,						pos.fy + parent->GetSize(SIZE_YPOS+1));		case DH_49:			parent->parent->SetSize(SIZE_XPOS, 						pos.fx + parent->GetSize(SIZE_XPOS));			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:		case DH_59:			return parent->parent->Command(cmd, tmpl, o);		default:			if (type >= DH_DATA) {				parent->SetSize(SIZE_XPOS + idx, pos.fx + parent->GetSize(SIZE_XPOS + idx));				parent->SetSize(SIZE_YPOS + idx, pos.fy + parent->GetSize(SIZE_YPOS + idx));				CurrGO = parent;				}			break;			}		return parent->Command(CMD_REDRAW, 0L, o);		break;		}	return false;}void *dragHandle::ObjThere(int x, int y){	if(IsInRect(&rDims, x, y)) return (CurrHandle = this);	else return 0L;}voiddragHandle::Track(POINT *p, anyOutput *o){	POINT p1, p2, pts[5];	double dx, dy;	int npts=0, idx;	DWORD color;	if(!parent || !o) return;	Command(CMD_MOUSECURSOR, 0L, o);	if(upd.right < upd.left) Swap(upd.right, upd.left);	if(upd.bottom < upd.top) Swap(upd.bottom, upd.top);	dx = parent->GetSize(SIZE_GRECT_LEFT);	dy = parent->GetSize(SIZE_GRECT_TOP);	IncrementMinMaxRect(&upd, 2);	o->UpdateRect(&upd, false);	if(type >= DH_19 && type <= DH_99) memcpy(&upd, &drec, sizeof(RECT));	color = parent->GetColor(COL_DATA_LINE);	switch(type) {	case DH_12:	case DH_22:		pts[0].x = o->co2ix(parent->GetSize(SIZE_XPOS)+dx);		pts[0].y = o->co2iy(parent->GetSize(SIZE_YPOS)+dy);		pts[1].x = o->co2ix(parent->GetSize(SIZE_XPOS+1)+dx);		pts[1].y = o->co2iy(parent->GetSize(SIZE_YPOS+1)+dy);		if(type == DH_12) {			pts[0].x += p->x;			pts[0].y += p->y;			}		else if(type == DH_22) {			pts[1].x += p->x;			pts[1].y += p->y;			}		UpdateMinMaxRect(&upd, pts[0].x, pts[0].y);		UpdateMinMaxRect(&upd, pts[1].x, pts[1].y);		npts = 2;		break;	case DH_19:		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;	case DH_29:		if(minRC && IsInRect(minRC, (upd.left + upd.right)>>1, upd.top+p->y))			upd.top = minRC->top;		else if(maxRC && !IsInRect(maxRC, (upd.left + upd.right)>>1, upd.top+p->y))			upd.top = upd.top +p->y >= maxRC->bottom? maxRC->bottom : maxRC->top;		else upd.top += p->y;		break;	case DH_39:		if(minRC && IsInRect(minRC, (upd.left + upd.right)>>1, upd.top+p->y))			upd.top = minRC->top;		else if(maxRC && !IsInRect(maxRC, (upd.left + upd.right)>>1, upd.top+p->y))			upd.top = upd.top+p->y >= maxRC->bottom ? maxRC->bottom : maxRC->top;		else upd.top += p->y;	case DH_69:

⌨️ 快捷键说明

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