示例#1
0
/**
 * Paint edge
 */
void GuiEdge::paint( QPainter * painter,
                         const QStyleOptionGraphicsItem * option, QWidget * widget)
{
	if ( succ() == 0 || pred() == 0)//!!! What is the ugliness!
	{
		out ("ERROR: the deleted edge is tried to paint!");
		return;
	}
	if (!edge_valid_priv) return;

	edgeApplStyle (painter, option);

    qreal arrowSize = 10;
//    painter->setPen( QPen( Qt::darkRed, 2, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
	GuiNode* suc = addGui ( succ());
	GuiNode* pre = addGui ( pred());
	
	if (isVirtualRootEdge() && !addGui (graph)->showVnodes()) return;//Do not show virtual root edges
	if( suc->real())
    {
		QPointF dir = (7*edge_end_dir_priv + edge_start_point_priv)/8 - edge_end_point_priv;//!!! Mnemonic rule, it must be changed
		drawLineHead (painter, edge_end_point_priv, -atan2 (dir.y(), dir.x()), 10, false);
    }

	if (edgeLabel().size() && addGui (graph)->showEdgeLabels())
	{
		drawText (painter);
	}

	painter->setBrush( Qt::transparent);//!!! change it to black, and you will see, what heppend. I can't explain this
	painter->drawPath (edge_curve_priv);
}
示例#2
0
/**
 * Destructor of GuiEdge class
 */
GuiEdge::~GuiEdge()
{
	out( "last nitems:%d, deletenig: ", addGui ( getGraph())->items().count());
	debugPrint();
	addGui( getGraph())->removeItem( addGui( this));
	out( "current nitems%d", addGui( getGraph())->items().count());
}
示例#3
0
/**
 * Update text distribution between edges
 */
void GuiEdge::updateLabels()
{
	float sum_len = 0;
	QPoint end_sequence;

	bool first_run = full_label.length() == 0;

	for (GuiEdge* i = this;;
		i->succ()->firstSucc() && (i = addGui (i->succ()->firstSucc())))
	{
		sum_len += i->length();
		if (first_run) full_label += i->edgeLabel();
		if (i->succ() && i->succ()->real())
		{
			end_sequence = addAux(i->succ())->coor();
			break;
		}
	}

	float n_letters = 0;
	float last_round_up = 0;
	int full_len = full_label.length();
	
	QPoint delta = end_sequence - edge_start_point_priv.toPoint();
	reverse = -delta.x() > delta.y();

	QString buf = full_label;

	for (GuiEdge* i = this;;
		i->succ()->firstSucc() && (i = addGui (i->succ()->firstSucc())))
	{
		i->reverse = reverse;
		n_letters = full_len*i->length()/sum_len + last_round_up;	//give an appropriate substring
		last_round_up = n_letters - (int)n_letters;

		if (i->succ() && i->succ()->real())//take the last character
			n_letters ++;

		if (reverse)
		{
			i->setEdgeLabel (buf.right (n_letters));
			buf.remove (buf.length() + 1 - n_letters, n_letters);
		}
		else
		{
			i->setEdgeLabel (buf.left (n_letters));
			buf.remove (0, n_letters);
		}
		if (i->succ() && i->succ()->real()) break;

	}
}
示例#4
0
/**
 * Insert node
 */
GuiNode* GuiEdge::insertNode ( QPointF p)	//!!! I think it's superannuated
{
	GuiNode* node = addGui ( graph->insertNodeOnEdge( this));
	
	node->setReal( false);
	node->update();
	node->setPos( p.x(), p.y());
	return node;
}
示例#5
0
文件: main.cpp 项目: jj-jabb/nv2D
void initialize ()
{
	// GUI
	addGui (  20,  20, 200, 24, "Frame Time (ms)",		GUI_PRINT,  GUI_FLOAT, &frameTime, 0, 0 );	
	addGui (  20,  50, 200, 24, "Number of Rectangles",	GUI_SLIDER, GUI_INT, &numRects, 0, 1000 );
	addGui (  20,  80, 200, 24, "Number of Circles",	GUI_SLIDER, GUI_INT, &numCircles, 0, 1000 );
	addGui (  20, 110, 200, 24, "Number of Lines",		GUI_SLIDER, GUI_INT, &numLines, 0, 10000 );	
	addGui (  20, 140, 200, 24, "Number of Text",		GUI_SLIDER, GUI_INT, &numText, 0, 1000 );
	
	glViewport( 0, 0, window_width, window_height ); 

	// required init functions
	init2D ( "arial_24" );		// specify font file (.bin/tga)
	setText ( 0.5, -0.5 );		// scale by 0.5, kerning adjust -0.5 pixels
	setview2D ( window_width, window_height );
	setorder2D ( true, -.00001 );

	PERF_INIT ( false );				// Enable CPU perf (do not require nv-perfmarker DLL)
	PERF_SET ( true, 2, false, "" );	// Perf CPU on, Perf print depth, nv-perfmarkers off, no log file
}
void CloudsVisualSystemFlocking::setupFboViewerGui(string name, ofFbo *fbo)
{
    ofxUISuperCanvas *fboGui = new ofxUISuperCanvas(ofToUpper(name), gui);
    fboGui->copyCanvasStyle(gui);
    fboGui->copyCanvasProperties(gui);
    fboGui->setName(name+"Settings");
    fboGui->setWidgetFontSize(OFX_UI_FONT_SMALL);
    fboGui->addSpacer();
    fboGui->addBaseDraws(name, fbo);
    fboGui->autoSizeToFitWidgets();
    addGui(fboGui);
}
示例#7
0
/**
 * Update position the edge
 */
void GuiEdge::updatePosition (bool original_run)
{
	GuiNode* pre = addGui (pred());
	GuiNode* suc = addGui (succ());

	edge_start_point_priv = mapFromItem( pre, pre->width()/2, pre->height()/2);
    edge_end_point_priv = mapFromItem( suc, suc->width()/2, suc->height()/2);//!!!rarely it not work

	if (pre == suc)//mesh edge
	{
		QPointF heigh (0, 2*pre->height());

		QPointF middle (pre->pos().x() - 10, pre->pos().y() + pre->height()/2);
		QPointF middleDirUp = middle + heigh;
		QPointF middleDirDown = middle - heigh;

		edge_start_dir_priv = edge_start_point_priv + heigh;
		edge_end_dir_priv = edge_end_point_priv - heigh;

		QPolygonF polygon = suc->polygon();
		polygon.translate (suc->pos());
		getIntersection (QLineF (edge_start_point_priv, edge_start_dir_priv), polygon, &edge_start_point_priv);
		getIntersection (QLineF (edge_end_point_priv, edge_end_dir_priv), polygon, &edge_end_point_priv);

		QPainterPath path;
		path.moveTo (edge_start_point_priv);
		path.cubicTo (edge_start_dir_priv, middleDirUp, middle);
		path.cubicTo (middleDirDown, edge_end_dir_priv, edge_end_point_priv);
		edge_curve_priv = path;
	}
	else
	{
		edge_valid_priv = true;
		
		QPolygonF headPolygon = suc->polygon();
		headPolygon.translate (suc->pos());
		QPolygonF tailPolygon = pre->polygon();
		tailPolygon.translate (pre->pos());


		if (suc->real())
			edge_valid_priv = edge_valid_priv && getIntersection (QLineF (edge_start_point_priv, edge_end_point_priv), headPolygon, &edge_end_point_priv) == QLineF::BoundedIntersection;
		if (pre->real()) 
			edge_valid_priv = edge_valid_priv && getIntersection (QLineF (edge_start_point_priv, edge_end_point_priv), tailPolygon, &edge_start_point_priv) == QLineF::BoundedIntersection;

		QPointF delta = edge_start_point_priv - edge_end_point_priv;
		delta.setX(0);

		if (pre->real()) 
			edge_start_dir_priv = (edge_start_point_priv + edge_end_point_priv)/2;
		else
		{
			if (pre->firstPred() != 0)
				edge_start_dir_priv = (suc->coor() - pre->firstPred()->pred()->coor())/8 + pre->coor();
			else
				edge_start_dir_priv = edge_start_point_priv - delta/2;
		}

		if (suc->real())
			edge_end_dir_priv = (edge_start_point_priv + edge_end_point_priv)/2;
		else
			if (suc->firstSucc() != 0)
				edge_end_dir_priv = (pre->coor() - suc->firstSucc()->succ()->coor())/8 + suc->coor();
			else
				edge_end_dir_priv = edge_end_point_priv + delta/2;

		QPainterPath path;
		path.moveTo (edge_start_point_priv);
		path.cubicTo (edge_start_dir_priv, edge_end_dir_priv, edge_end_point_priv);

		if (edge_valid_priv) edge_curve_priv = path;
	}

    edge_top_left_priv.setX( min< qreal>( edge_start_point_priv.x(), edge_end_point_priv.x()));
    edge_top_left_priv.setY( min< qreal>( edge_start_point_priv.y(), edge_end_point_priv.y()));
    edge_bottom_right_priv.setX( max< qreal>( edge_start_point_priv.x(), edge_end_point_priv.x()));
    edge_bottom_right_priv.setY( max< qreal>( edge_start_point_priv.y(), edge_end_point_priv.y())); 

	if (original_run)
	{
		if (Edge::succ() && !addAux (Edge::succ())->real() && Edge::succ()->firstSucc())
			addGui (Edge::succ()->firstSucc())->updatePosition (false);//avoidance sharp corners
		
		if (Edge::pred() && !addAux (Edge::pred())->real() && Edge::pred()->firstPred())
			addGui (Edge::pred()->firstPred())->updatePosition (false);//avoidance sharp corners
		
		GuiEdge* i = this;
		for (i; !i->startEdge(); i->pred()->firstPred() && (i = addGui (i->pred()->firstPred())));
		i->updateLabels();
	}
    prepareGeometryChange();
}