Пример #1
0
void FlowContainer::updateAttachedPositioning()
{
	if (b_deleted)
		return;
	
	int _x = int(x())+offsetX();
	int _y = int(y())+offsetY();
	int w = int((std::floor(float((width()+8)/16)))*16);
	int h = height();
	
	if (m_ext_in)
		m_ext_in->move( _x+w/2, _y-8 );
	
	if (m_int_in)
		m_int_in->move( _x+w/2, _y+8+topStrip );
	
	if (b_expanded)
	{
		if (m_int_out)
			m_int_out->move( _x+w/2, _y+h-8-botStrip );
	
		if (m_ext_out)
			m_ext_out->move( _x+w/2, _y+h-8+botStrip );
	}
	else
	{
		// (Note: dont really care where internal nodes are if not expanded)
		
		if (m_ext_out)
			m_ext_out->move( _x+w/2, _y+8+topStrip );
	}
	
	button("expandBtn")->setGuiPartSize( 22, 22 );
	button("expandBtn")->move( int(x())+offsetX()+7, int(y())+offsetY()+1 );
}
Пример #2
0
void FlowPart::updateNodePositions() {
	if (m_orientation > 7) {
		kdWarning() << k_funcinfo << "Invalid orientation: " << m_orientation << endl;
		return;
	}

	NodeInfo *stdInputInfo = m_stdInput ? &m_nodeMap["stdinput"] : 0;
	NodeInfo *stdOutputInfo = m_stdOutput ? &m_nodeMap["stdoutput"] : 0;
	NodeInfo *altOutputInfo = m_altOutput ? &m_nodeMap["altoutput"] : 0;

	if (m_stdInput && m_stdOutput && m_altOutput) {
		stdInputInfo->orientation = diamondNodePositioning[m_orientation][0];
		stdOutputInfo->orientation = diamondNodePositioning[m_orientation][1];
		altOutputInfo->orientation = diamondNodePositioning[m_orientation][2];
	} else if (m_stdInput && m_stdOutput) {
		stdInputInfo->orientation = inOutNodePositioning[m_orientation][0];
		stdOutputInfo->orientation = inOutNodePositioning[m_orientation][1];
	} else if (m_orientation < 4) {
		if (stdInputInfo)
			stdInputInfo->orientation = inNodePositioning[m_orientation];
		else if (stdOutputInfo)
			stdOutputInfo->orientation = outNodePositioning[m_orientation];
	} else {
		kdWarning() << k_funcinfo << "Invalid orientation: " << m_orientation << endl;
		return;
	}

	const NodeInfoMap::iterator end = m_nodeMap.end();

	for (NodeInfoMap::iterator it = m_nodeMap.begin(); it != end; ++it) {
		if (!it.data().node)
			kdError() << k_funcinfo << "Node in nodemap is null" << endl;
		else {
			switch (it.data().orientation) {

			case 0:
				it.data().x = offsetX() + width() + 8;
				it.data().y = 0;
				break;

			case 270:
				it.data().x = 0;
				it.data().y = offsetY() - 8;
				break;

			case 180:
				it.data().x = offsetX() - 8;
				it.data().y = 0;
				break;

			case 90:
				it.data().x = 0;
				it.data().y = offsetY() + height() + 8;;
				break;
			}
		}
	}

	updateAttachedPositioning();
}
Пример #3
0
void ResistorDIP::updateDIPNodePositions()
{
	for ( int i=0; i<m_resistorCount; ++i )
	{
		m_nodeMap["n"+QString::number(i)].y = offsetY() + 8 + 16*i;
		m_nodeMap["p"+QString::number(i)].y = offsetY() + 8 + 16*i;
	}
	updateAttachedPositioning();
}
Пример #4
0
void FlowPart::updateAttachedPositioning() {
	if (b_deleted) return;

	//BEGIN Rearrange text if appropriate
	const QRect textPos[4] = {
		QRect(offsetX() + width(),	6,				40, 16),
		QRect(0,				offsetY() - 16,		40, 16),
		QRect(offsetX() - 40,		6,				40, 16),
		QRect(0,				offsetY() + height(),	40, 16)
	};

	NodeInfo *stdOutputInfo = m_stdOutput ? &m_nodeMap["stdoutput"] : 0;
	NodeInfo *altOutputInfo = m_altOutput ? &m_nodeMap["altoutput"] : 0;

	Text *outputTrueText = m_textMap.contains("output_true") ? m_textMap["output_true"] : 0;
	Text *outputFalseText = m_textMap.contains("output_false") ? m_textMap["output_false"] : 0;

	if (stdOutputInfo && outputTrueText)
		outputTrueText->setOriginalRect(textPos[ nodeDirToPos(stdOutputInfo->orientation)]);

	if (altOutputInfo && outputFalseText)
		outputFalseText->setOriginalRect(textPos[ nodeDirToPos(altOutputInfo->orientation)]);

	const TextMap::iterator textMapEnd = m_textMap.end();
	for (TextMap::iterator it = m_textMap.begin(); it != textMapEnd; ++it) {
		QRect pos = it.data()->recommendedRect();
		it.data()->move(pos.x() + x(), pos.y() + y());
		it.data()->setGuiPartSize(pos.width(), pos.height());
	}
	//END Rearrange text if appropriate

	const NodeInfoMap::iterator end = m_nodeMap.end();
	for (NodeInfoMap::iterator it = m_nodeMap.begin(); it != end; ++it) {
		if (!it.data().node) {
			kdError() << k_funcinfo << "Node in nodemap is null" << endl;
			continue;
		}

		double nx = it.data().x;
		double ny = it.data().y;

#define round_8(x) (((x) > 0) ? int(((x)+4)/8)*8 : int(((x)-4)/8)*8)
		nx = round_8(nx);
		ny = round_8(ny);
#undef round_8

		it.data().node->move(int(nx + x()), int(ny + y()));
		it.data().node->setOrientation(it.data().orientation);
	}
}
Пример #5
0
void FlowContainer::setFullBounds( bool full )
{
	if ( full || !b_expanded )
	{
		QRect bounds = b_expanded ? m_sizeRect : QRect( m_sizeRect.x(), m_sizeRect.y(), m_sizeRect.width(), topStrip );
		setPoints( QPolygon(bounds) );
		return;
	}
	
// 	kDebug() << k_funcinfo << "width="<<width()<<" height="<<height()<<endl;
	
	QPolygon pa(10);
	pa[0] = QPoint( 0, 0 );
	pa[1] = QPoint( width(), 0 );
	pa[2] = QPoint( width(), height() );
	pa[3] = QPoint( 0, height() );
	pa[4] = QPoint( 0, 0 );
	pa[5] = QPoint( 8, topStrip );
	pa[6] = QPoint( 8, height()-botStrip );
	pa[7] = QPoint( width()-8, height()-botStrip );
	pa[8] = QPoint( width()-8, topStrip );
	pa[9] = QPoint( 8, topStrip );
	pa.translate( offsetX(), offsetY() );
	setPoints(pa);
}
Пример #6
0
void Gosu::Image::drawRot(double x, double y, ZPos z,
    double angle, double centerX, double centerY,
    double factorX, double factorY,
    Color c,
    AlphaMode mode) const
{
    double sizeX = width()  * factorX;
    double sizeY = height() * factorY;
    double offsX = offsetX(angle, 1);
    double offsY = offsetY(angle, 1);

    // Offset to the centers of the original Image's edges when it is rotated
    // by <angle> degrees.
    double distToLeftX   = +offsY * sizeX * centerX;
    double distToLeftY   = -offsX * sizeX * centerX;
    double distToRightX  = -offsY * sizeX * (1 - centerX);
    double distToRightY  = +offsX * sizeX * (1 - centerX);
    double distToTopX    = +offsX * sizeY * centerY;
    double distToTopY    = +offsY * sizeY * centerY;
    double distToBottomX = -offsX * sizeY * (1 - centerY);
    double distToBottomY = -offsY * sizeY * (1 - centerY);

    data->draw(x + distToLeftX  + distToTopX,
               y + distToLeftY  + distToTopY, c,
               x + distToRightX + distToTopX,
               y + distToRightY + distToTopY, c,
               x + distToLeftX  + distToBottomX,
               y + distToLeftY  + distToBottomY, c,
               x + distToRightX + distToBottomX,
               y + distToRightY + distToBottomY,
               c, z, mode);
}
Пример #7
0
void CCS::FreeCameraMode::update(const Ogre::Real &timeSinceLastFrame)
{
    Ogre::Vector3 dirVector = mCameraCS->getOgreCamera()->getRealDirection();
    Ogre::Vector3 lateralVector = dirVector.crossProduct(mFixedAxis).normalisedCopy();
    Ogre::Vector3 upVector = -dirVector.crossProduct(lateralVector).normalisedCopy();

    Ogre::Vector3 displacement = ((dirVector * mLongitudinalDisplacement)
        + (upVector * mVerticalDisplacement)
        + (lateralVector * mLateralDisplacement)) * timeSinceLastFrame * mMoveFactor;

    mCameraPosition += displacement;

    if(mCollisionsEnabled)
    {
        mCameraPosition = collisionDelegate(mCameraCS->getCameraTargetPosition(), mCameraPosition);
    }

    Ogre::Quaternion offsetX(mRotY,Ogre::Vector3::UNIT_X);
    Ogre::Quaternion offsetY(mRotX,mFixedAxis);

	mCameraOrientation = offsetY * offsetX;

    mLongitudinalDisplacement = 0;
    mLateralDisplacement = 0;
    mVerticalDisplacement = 0;            
}
Пример #8
0
VarComparison::VarComparison( ICNDocument *icnDocument, bool newItem, const char *id )
	: FlowPart( icnDocument, newItem, id ? id : "varcomparison" )
{
	m_name = i18n("Variable Comparison");
	initDecisionSymbol();
	createStdInput();
	createStdOutput();
	createAltOutput();
	
	createProperty( "0var1", Variant::Type::Combo );
	property("0var1")->setCaption( i18n("Variable") );
	property("0var1")->setValue("x");
	
	createProperty( "1op", Variant::Type::Select );
	property("1op")->setAllowed( QStringList::split( ',', "==,<,>,<=,>=,!=" ) );
	property("1op")->setValue("==");
	property("1op")->setToolbarCaption(" ");
	property("1op")->setEditorCaption( i18n("Operation") );
	
	createProperty( "2var2", Variant::Type::Combo );
	property("2var2")->setToolbarCaption(" ");
	property("2var2")->setEditorCaption( i18n("Value") );
	property("2var2")->setValue("0");
	
	addDisplayText( "output_false", QRect( offsetX()+width(), 2, 40, 20 ), "No" );
	addDisplayText( "output_true", QRect( 0, offsetY()+height(), 50, 20 ), "Yes" ); 
}
Пример #9
0
void MultiInputGate::updateAttachedPositioning() {
	// Check that our ndoes have been created before we attempt to use them
	if (!m_nodeMap.contains("p1") || !m_nodeMap.contains("in" + QString::number(m_numInputs - 1)))
		return;

	int _x = offsetX() + 8;
	int _y = offsetY() + 8;

	m_nodeMap["p1"].x = logicSymbolShapeToWidth() / 2 + 8;
	m_nodeMap["p1"].y = 0;

	int n = m_numInputs;

	for (int i = 0; i < n; ++i) {
		m_nodeMap["in"+QString::number(i)].x = _x - 16;
		m_nodeMap["in"+QString::number(i)].y = _y + 16 * i;

		// The curvy part at the base of OR-like logic gates means that the
		// input needs to be increased in length

		if (m_bLikeOR) {
			int length = 8;

			if (m_logicSymbolShape == Distinctive) {
				length += (int)std::sqrt((double)(64 * n * n - (8 * n - 8 - 16 * i) * (8 * n - 8 - 16 * i))) / n;
			}

			inNode[i]->setLength(length);
		}
	}

	if (m_bDoneInit)
		Component::updateAttachedPositioning();
}
Пример #10
0
void DPLine::drawShape( QPainter & p )
{
	int x1 = int(x()+offsetX());
	int y1 = int(y()+offsetY());
	int x2 = x1+width();
	int y2 = y1+height();
	
	p.drawLine( x1, y1, x2, y2 );
}
Пример #11
0
void ResistorDIP::dataChanged()
{
	initPins();
	const double resistance = dataDouble("resistance");
	for ( int i=0; i<m_resistorCount; ++i )
		m_resistance[i]->setResistance(resistance);
	
	const QString display = QString::number( resistance / getMultiplier(resistance), 'g', 3 ) + getNumberMag(resistance) + QChar(0x3a9);
	addDisplayText( "res", QRect( offsetX(), offsetY()-16, 32, 12 ), display );
}
Пример #12
0
void ResistorDIP::drawShape( QPainter &p )
{
	int _x = int(x()+offsetX());
	int _y = int(y()+offsetY());
	
	initPainter(p);
	for ( int i=0; i<m_resistorCount; ++i )
		p.drawRect( _x, _y+16*i+2, 32, 12 );
	deinitPainter(p);
}
Пример #13
0
void MultiInputGate::updateLogicSymbolShape() {
	// Set the canvas changed for the old shape
	setChanged();

	if(KTLConfig::logicSymbolShapes() == KTLConfig::EnumLogicSymbolShapes::Distinctive) {
		m_logicSymbolShape = Distinctive;
		setSize(-m_distinctiveWidth / 2, offsetY(), m_distinctiveWidth, height(), true);
	} else {
		m_logicSymbolShape = Rectangular;
		setSize(-16, offsetY(), 32, height(), true);
	}

	updateSymbolText();
	updateAttachedPositioning();

	if (p_itemDocument)
		p_itemDocument->requestEvent(ItemDocument::ItemDocumentEvent::RerouteInvalidatedConnectors);

	// Set the canvas changed for the new shape
	setChanged();
}
Пример #14
0
void PIC_IC::initPackage( MicroInfo * microInfo )
{
	// The code in this function is a stripped down version of that in PICComponent::initPackage
	
	if (!microInfo)
		return;
	
	MicroPackage * microPackage = microInfo->package();
	if (!microPackage)
		return;
	
	//BEGIN Get pin IDs
	QStringList allPinIDs = microPackage->pinIDs();
	QStringList ioPinIDs = microPackage->pinIDs( PicPin::type_bidir | PicPin::type_input | PicPin::type_open );
	
	// Now, we make the unwanted pin ids blank, so a pin is not created for them
	const QStringList::iterator allPinIDsEnd = allPinIDs.end();
	for ( QStringList::iterator it = allPinIDs.begin(); it != allPinIDsEnd; ++it )
	{
		if ( !ioPinIDs.contains(*it) )
			*it = "";
	}
	//END Get pin IDs
	
	
	//BEGIN Remove old stuff
	// Remove old text
	TextMap textMapCopy = m_textMap;
	const TextMap::iterator textMapEnd = textMapCopy.end();
	for ( TextMap::iterator it = textMapCopy.begin(); it != textMapEnd; ++it )
		removeDisplayText(it.key());
	
	// Remove old nodes
	NodeInfoMap nodeMapCopy = m_nodeMap;
	const NodeInfoMap::iterator nodeMapEnd = nodeMapCopy.end();
	for ( NodeInfoMap::iterator it = nodeMapCopy.begin(); it != nodeMapEnd; ++it )
	{
		if ( !ioPinIDs.contains(it.key()) )
			removeNode( it.key() );
	}
	//END Remove old stuff
	
	
	
	//BEGIN Create new stuff
	initDIPSymbol( allPinIDs, 80 );
	initDIP(allPinIDs);
	//END Create new stuff
	
	
	addDisplayText( "picid", QRect(offsetX(), offsetY()-16, width(), 16), microInfo->id() );
}
Пример #15
0
void ECNand::drawShape(QPainter &p) {
	if (m_logicSymbolShape == Rectangular) {
		MultiInputGate::drawShape(p);
		return;
	}

	initPainter(p);

	int _x = (int)x() + offsetX();
	int _y = (int)y() + offsetY();
	p.drawChord(_x - width() + 6, _y, 2 * width() - 12, height(), -16 * 90, 16 * 180);
	p.drawEllipse(_x + width() - 6, _y + (height() / 2) - 3, 6, 6);
	deinitPainter(p);
}
Пример #16
0
void LEDBarGraphDisplay::drawShape(QPainter &p) {
	Component::drawShape(p);
	initPainter(p);

	// Init _x and _y to top left hand corner of component.
	int _x = (int)(x() + offsetX());
	int _y = (int)(y() + offsetY());

	// Draw LED elements, passing in a position for each.

	for (unsigned i = 0; i < m_numRows; i++)
		m_LEDParts[i]->draw(p, _x + 4, _y + (i*16) + 10, 24, 12);

	deinitPainter(p);
}
Пример #17
0
void MultiInputGate::drawShape(QPainter & p) {
	initPainter(p);

	int _x = int(x() + offsetX());
	int _y = int(y() + offsetY());

	if (m_bInvertedOutput) {
		p.drawRect(_x, _y, 32 - 6, height());
		p.drawEllipse(_x + 32 - 6, int(y()) - 3, 6, 6);
	} else {
		p.drawRect(_x, _y, 32, height());
	}

	deinitPainter(p);
}
Пример #18
0
void ECAnd::drawShape(QPainter &p) {
	if (m_logicSymbolShape == Rectangular) {
		MultiInputGate::drawShape(p);
		return;
	}

	initPainter(p);

	int _x = (int)x() + offsetX();
	int _y = (int)y() + offsetY();

	p.drawChord(_x - width(), _y, 2 * width(), height(), -16 * 90, 16 * 180);

	deinitPainter(p);
}
Пример #19
0
TestPin::TestPin( ICNDocument *icnDocument, bool newItem, const char *id )
	: FlowPart( icnDocument, newItem, id ? id : "testpin" )
{
	m_name = i18n("Test Pin State");
	initDecisionSymbol();
	createStdInput();
	createStdOutput();
	createAltOutput();
	
	createProperty( "pin", Variant::Type::Pin );
	property("pin")->setCaption( i18n("Pin") );
	property("pin")->setValue("RA0");
	
	addDisplayText( "output_false", QRect( offsetX()+width(), 2, 40, 20 ), "Low" );
	addDisplayText( "output_true", QRect( 0, offsetY()+height(), 50, 20 ), "High" );
}
Пример #20
0
void MatrixDisplay::drawShape(QPainter &p) {
    if (isSelected())
        p.setPen(m_selectedCol);

    p.drawRect(boundingRect());

    initPainter(p);

    const int _x = int(x() + offsetX());
    const int _y = int(y() + offsetY());

    // To avoid flicker, require at least a 10 ms sample before changing
    // the brightness
    double minUpdatePeriod = 0.0099;

    for (int i = 0; i < int(m_numCols); i++) {
        for (int j = 0; j < int(m_numRows); j++) {
            if (m_lastUpdatePeriod > minUpdatePeriod)
                m_LEDs[i][j].m_lastBrightness = unsigned(m_LEDs[i][j].m_avgBrightness / m_lastUpdatePeriod);

            double _b = m_LEDs[i][j].m_lastBrightness;
// FIXME: we find ourselves with RGB out of range errors after resizing. 
            QColor brush = QColor(uint(255 - (255 - _b) * (1 - m_r)),
                                  uint(255 - (255 - _b) * (1 - m_g)),
                                  uint(255 - (255 - _b) * (1 - m_b)));

            p.setBrush(brush);
            p.setPen(Qt::NoPen);
            p.drawEllipse(_x + 10 + i * 16,
			  _y + 10 + j * 16, 12, 12);
        }
    }

    if (m_lastUpdatePeriod > minUpdatePeriod) {
        m_lastUpdatePeriod = 0.0;

        for (unsigned i = 0; i < m_numCols; i++) {
            for (unsigned j = 0; j < m_numRows; j++)
                m_LEDs[i][j].m_avgBrightness = 0.0;
        }
    }

    deinitPainter(p);
}
Пример #21
0
FlowContainer::FlowContainer( ICNDocument *_icnDocument, bool newItem, const QString &id )
	: FlowPart( _icnDocument, newItem, id )
{
	m_ext_in = m_int_in = m_int_out = m_ext_out = 0l;
	b_expanded = true;
	
	addButton( "expandBtn", QRect( offsetX(), offsetY()+24 - 11, 22, 22 ), KIcon( "go-down" ), true );
	m_rectangularOverlay = new RectangularOverlay( this, 8, 8 );
	setSize( -160, -120, 320, 240 );
	
	
	m_int_in = (FPNode*)createNode( width()/2, 8+topStrip, 90, "int_in", Node::fp_out );
	m_int_out = (FPNode*)createNode( width()/2, height()-8-botStrip, 270, "int_out", Node::fp_in );
	
	button("expandBtn")->setState(true);
	
	updateAttachedPositioning();
	updateNodeLevels();
}
Пример #22
0
void DPLine::postResize()
{
	int x1 = offsetX();
	int y1 = offsetY();
	int x2 = x1+width();
	int y2 = y1+height();
	
	QPointArray p(4);
	int pw = pen().width();
	int dx = abs(x1-x2);
	int dy = abs(y1-y2);
	pw = pw * 4 / 3 + 2; // approx pw*sqrt(2) 
	int px = x1<x2 ? -pw : pw ;
	int py = y1<y2 ? -pw : pw ;
	if ( dx && dy && (dx > dy ? (dx*2/dy <= 2) : (dy*2/dx <= 2)) ) {
	// steep
		if ( px == py ) {
			p[0] = QPoint(x1   ,y1+py);
			p[1] = QPoint(x2-px,y2   );
			p[2] = QPoint(x2   ,y2-py);
			p[3] = QPoint(x1+px,y1   );
		} else {
			p[0] = QPoint(x1+px,y1   );
			p[1] = QPoint(x2   ,y2-py);
			p[2] = QPoint(x2-px,y2   );
			p[3] = QPoint(x1   ,y1+py);
		}
	} else if ( dx > dy ) {
	// horizontal
		p[0] = QPoint(x1+px,y1+py);
		p[1] = QPoint(x2-px,y2+py);
		p[2] = QPoint(x2-px,y2-py);
		p[3] = QPoint(x1+px,y1-py);
	} else {
	// vertical
		p[0] = QPoint(x1+px,y1+py);
		p[1] = QPoint(x2+px,y2-py);
		p[2] = QPoint(x2-px,y2-py);
		p[3] = QPoint(x1-px,y1+py);
	}
	setItemPoints( p, false );
}
Пример #23
0
void DPArrow::drawShape( QPainter & p )
{
	double x1 = x()+offsetX();
	double y1 = y()+offsetY();
	double x2 = x1+width();
	double y2 = y1+height();
	
	p.drawLine( int(x1), int(y1), int(x2), int(y2) );
	
	double dx = x2-x1;
	double dy = y2-y1;
	
	if ( dx == 0. && dy == 0. )
		return;
	
	double arrow_angle = ( dx == 0 ? (dy>0?(M_PI_2):(-M_PI_2)) : std::atan(dy/dx) );
	if ( dx < 0 )
		arrow_angle += M_PI;
	
	double head_angle = M_PI * m_headAngle / 180.0;
	double head_length = 10.0;
	
	// Position of arrowhead
	double x3 = x2 + head_length*std::cos( M_PI + arrow_angle - head_angle );
	double y3 = y2 + head_length*std::sin( M_PI + arrow_angle - head_angle );
	double x4 = x2 + head_length*std::cos( M_PI + arrow_angle + head_angle );
	double y4 = y2 + head_length*std::sin( M_PI + arrow_angle + head_angle );
	
	// Draw arrowhead
	QPen pen = p.pen();
	pen.setCapStyle( Qt::RoundCap );
	p.setPen(pen);
	p.setBrush(pen.color());
	QPointArray pa(3);
	pa[0] = QPoint( round_x(x2), round_x(y2) );
	pa[1] = QPoint( round_x(x3), round_x(y3) );
	pa[2] = QPoint( round_x(x4), round_x(y4) );
	p.drawPolygon(pa);
	p.drawPolyline(pa);
}
Пример #24
0
void ECXor::drawShape(QPainter &p) {
	if (m_logicSymbolShape == Rectangular) {
		MultiInputGate::drawShape(p);
		return;
	}

	initPainter(p);

	int _x = (int)x() + offsetX();
	int _y = (int)y() + offsetY();

	p.save();
	p.setPen(Qt::NoPen);
	p.drawChord(_x - width() + 16, _y, 2 * width() - 16, height(), -16 * 81, 16 * 162);
	p.restore();

	p.drawArc(_x - width() + 16, _y, 2 * width() - 16, height(), -16 * 90, 16 * 180);
	p.drawArc(_x - 8, _y, 16, height(), -16 * 90, 16 * 180);
	p.drawArc(_x, _y, 16, height(), -16 * 90, 16 * 180);

	deinitPainter(p);
}
Пример #25
0
void FlowContainer::drawShape( QPainter &p )
{
	if (b_deleted)
		return;

	if ( !m_sizeRect.isValid() )
		return;
	
	const int _x = (int)x()+offsetX();
	const int _y = (int)y()+offsetY();
	
	int col = 0xef + level()*0x6;
	if ( col > 0xff ) col = 0xff;
	p.setBrush( QColor( col, 0xff, col ) );
	if( b_expanded )
	{
		p.setPen(Qt::DotLine);
		p.drawRoundRect( _x, _y, width(), topStrip, 1500/width(), 1500/topStrip );
		p.drawRoundRect( _x, _y+height()-botStrip, width(), botStrip, 1500/width(), 1500/botStrip );
	}
	else
	{
		p.setPen(QPen((isSelected()?m_selectedCol:Qt::black),1,Qt::SolidLine));
		p.drawRoundRect( _x, _y, width(), topStrip, 1500/width(), 1500/topStrip );
	}
	
	p.setPen( Qt::black );
	p.setFont( font() );
	p.drawText( QRect( 22 + _x+8, _y, width()-8, topStrip ), Qt::AlignLeft | Qt::AlignVCenter,  m_caption );
	
	if( b_expanded )
	{
		p.setPen(Qt::SolidLine);
		p.setBrush( Qt::NoBrush );
		p.drawRoundRect( _x, _y, width(), height(), 1500/width(), 1500/height() );
	}
}
Пример #26
0
void DPImage::drawShape( QPainter & p )
{
	p.drawPixmap( int(x()+offsetX()), int(y()+offsetY()), m_image, 0, 0, width(), height() );
}
Пример #27
0
void FlowPart::drawShape(QPainter &p) {
	initPainter(p);

	const double _x = int(x() + offsetX());
	const double _y = int(y() + offsetY());
	const double w = width();
	double h = height();

	switch (m_flowSymbol) {

	case FlowPart::ps_other:
		CNItem::drawShape(p);
		break;

	case FlowPart::ps_io: {
		h--;
		double roundSize = 8;
		double slantIndent = 5;

// 		CNItem::drawShape(p);
		double inner = std::atan(h / slantIndent);
		double outer = M_PI - inner;

		int inner16 = int(16 * inner * DPR);
		int outer16 = int(16 * outer * DPR);

		p.save();
		p.setPen(Qt::NoPen);
		p.drawPolygon(areaPoints());
		p.restore();

		p.drawLine(int(_x + slantIndent + roundSize / 2),
		           int(_y),
		           int(_x + w - roundSize / 2),
		           int(_y));

		p.drawLine(int(_x + w - slantIndent - roundSize / 2),
		           int(_y + h),
		           int(_x + roundSize / 2),
		           int(_y + h));

		p.drawLine(int(_x + w + (std::sin(outer) - 1) * roundSize / 2),
		           int(_y + (1 - std::cos(outer)) * roundSize / 2),
		           int(_x + w - slantIndent + (std::sin(inner) - 1) * roundSize / 2),
		           int(_y + h + (std::cos(inner) - 1) * roundSize / 2));

		p.drawLine(int(_x + (1 - std::sin(outer)) * roundSize / 2),
		           int(_y + h + (std::cos(outer) - 1) * roundSize / 2),
		           int(_x + slantIndent + (1 - std::sin(inner)) * roundSize / 2),
		           int(_y + (1 - std::cos(inner)) * roundSize / 2));

		p.drawArc(int(_x + slantIndent),
		          int(_y),
		          int(roundSize),
		          int(roundSize),
		          90 * 16,
		          inner16);

		p.drawArc(int(_x + w - roundSize),
		          int(_y),
		          int(roundSize),
		          int(roundSize),
		          270 * 16 + inner16,
		          outer16);

		p.drawArc(int(_x - slantIndent + w - roundSize),
		          int(_y + h - roundSize),
		          int(roundSize),
		          int(roundSize),
		          270*16,
		          inner16);

		p.drawArc(int(_x),
		          int(_y + h - roundSize),
		          int(roundSize),
		          int(roundSize),
		          90*16 + inner16,
		          outer16);
		break;
	}

	case FlowPart::ps_decision:
		// TODO Make the shape nice and pretty with rounded corners
		CNItem::drawShape(p);
		break;

	case FlowPart::ps_call:
		p.drawRoundRect(int(_x), int(_y), int(w), int(h + 1), int(1000. / w), int(1000. / h));
		p.drawLine(int(_x + 8), int(_y), int(_x + 8), int(_y + h));
		p.drawLine(int(_x + w - 8), int(_y), int(_x + w - 8), int(_y + h));
		break;

	case FlowPart::ps_process:
		p.drawRoundRect(int(_x), int(_y), int(w), int(h + 1), int(1000. / w), int(1000. / h));
		break;

	case FlowPart::ps_round:
		p.drawRoundRect(int(_x), int(_y), int(w), int(h + 1), 30, 100);
		break;
	}

	p.setPen(Qt::black);

	p.setFont(font());
	p.drawText(boundingRect(), (Qt::WordBreak | Qt::AlignHCenter | Qt::AlignVCenter), m_caption);
}
Пример #28
0
void FlowLayout::updateLayout(const MFUnrecComponentPtr* Components, const Component* ParentComponent) const
{
    /*!
      totalMajorAxis will hold the width of its container, and cumMajorAxis
      will hold the width of all of the buttons. That way it will always know
      when to move to the next line. In addition, maxMinorAxis keeps track of
      the largest height so it knows how far down to move the next row. Also,
      oneInRow is used to make sure that it places at least one component in
      every row.
      */
    UInt32 AxisIndex(0);
    if(getOrientation() != HORIZONTAL_ORIENTATION ) AxisIndex = 1;
    Vec2f gap(getHorizontalGap(), getVerticalGap());
    UInt32 numGaps(0);
    /*!
      When finding the cumMinor Axis, the gap is included, because there is
      no count for how many stacks there are. When finding cumMajor, the
      gap isn't included because the total distance relies on how many
      components there are in that row/column.
      */

    Pnt2f borderTopLeft, borderBottomRight;
    dynamic_cast<const ComponentContainer*>(ParentComponent)->getInsideInsetsBounds(borderTopLeft, borderBottomRight);
    Vec2f borderSize(borderBottomRight-borderTopLeft);
    Real64 totalMajorAxis(borderSize[AxisIndex]);
    Real32 cumMajorAxis(0);
    Real32 maxMinorAxis(0);
    Real32 cumMinorAxis(0);
    Real32 prevComponent(0);
    Real64 offsetMajorAxis(0);
    Real64 offsetMinorAxis(0);
    Real64 offsetX(borderTopLeft.x());
    Real64 offsetY(borderTopLeft.y());
    bool firstOne = true;

    for(UInt32 i=0 ; i<Components->size(); ++i)
    {
    }

    for(UInt32 i=0 ; i<Components->size(); ++i)
    {
        // set the component to its preferred size
        (*Components)[i]->setSize(getAppropriateComponentSize((*Components)[i]));

        // if there is only one so far, then it can't draw it using cumMajorAxis
        // because it hasn't been set yet
        if (firstOne) // this one might draw it
        {
            firstOne = false;
            // if this is the last component or it is already too big for the
            // container, draw it centered on its line
            if (i == Components->size() || (*Components)[i]->getSize()[AxisIndex] >= totalMajorAxis)
            {
                // find how far to translate to make it properly aligned
                offsetMajorAxis = getMajorAxisAlignment()*(totalMajorAxis - (*Components)[i]->getSize()[AxisIndex]);

                if (AxisIndex)
                {
                    offsetY+= offsetMajorAxis;
                }
                else
                {
                    offsetX += offsetMajorAxis;
                }

                (*Components)[i]->setPosition(Pnt2f(offsetX, offsetY));

                // get to the next row
                if (AxisIndex)
                {
                    offsetX += (*Components)[i]->getSize()[(AxisIndex+1)%2]+gap[(AxisIndex+1)%2];
                    offsetY += -offsetMajorAxis;
                }
                else
                {
                    offsetX += -offsetMajorAxis;
                    offsetY += (*Components)[i]->getSize()[(AxisIndex+1)%2]+gap[(AxisIndex+1)%2];
                }
                // update cumMinorAxis, other values should still be at 0
                cumMinorAxis += (*Components)[i]->getSize()[(AxisIndex+1)%2];
                if(i < Components->size()-1)
                {
                    cumMinorAxis += gap[(AxisIndex+1)%2];
                }
                // update prevComponent
                prevComponent++;
                // next component is still just like the first one
                firstOne = true;
            }
            else
            {
                // update the maxMinorAxis
                maxMinorAxis = (*Components)[i]->getSize()[(AxisIndex+1)%2];
                // update cumMajorAxis
                cumMajorAxis += (*Components)[i]->getSize()[AxisIndex];
            }
        }
        else if (cumMajorAxis + (*Components)[i]->getSize()[AxisIndex] + gap[AxisIndex]*(i-prevComponent) > totalMajorAxis) // this one draws up to i
        {
            // The numGaps is one less than the number of components being drawn, but it
            // is actually translates once for each component, so it must be compensated
            // when returning to the next row.
            numGaps = i-prevComponent-1;

            // find how far to translate to make it properly aligned
            offsetMajorAxis = getMajorAxisAlignment()*(totalMajorAxis - (cumMajorAxis+numGaps*gap[AxisIndex]));


            if (AxisIndex){
                offsetY += offsetMajorAxis;
            }
            else
            {
                offsetX += offsetMajorAxis;
            }
            for (int j = prevComponent; j < i; j++)
            {
                // find how far to translate to make this button properly aligned
                offsetMinorAxis = (maxMinorAxis-(*Components)[j]->getSize()[(AxisIndex+1)%2])*getComponentAlignment();

                // translate to make it properly aligned
                if (AxisIndex)
                {	
                    offsetX += offsetMinorAxis;
                }
                else
                {
                    offsetY += offsetMinorAxis;
                }

                (*Components)[j]->setPosition(Pnt2f(offsetX, offsetY));

                // translate to next button
                if (AxisIndex)
                {
                    offsetX+=-(Real64)offsetMinorAxis;
                    offsetY+= (*Components)[j]->getSize()[AxisIndex] + gap[AxisIndex];
                }
                else
                {
                    offsetX+=(*Components)[j]->getSize()[AxisIndex] + gap[AxisIndex];
                    offsetY+= -offsetMinorAxis;
                }
            }
            // translate to the next row
            if (AxisIndex)
            {
                offsetX += maxMinorAxis+gap[(AxisIndex+1)%2];
                offsetY += -(offsetMajorAxis+cumMajorAxis+(numGaps+1)*gap[AxisIndex]);
            }
            else
            {
                offsetX += -(offsetMajorAxis+cumMajorAxis+(numGaps+1)*gap[AxisIndex]);
                offsetY += maxMinorAxis+gap[(AxisIndex+1)%2];
            }

            cumMinorAxis += maxMinorAxis + gap[(AxisIndex+1)%2];
            maxMinorAxis = (*Components)[i]->getSize()[(AxisIndex+1)%2];
            prevComponent = i;
            cumMajorAxis = (*Components)[i]->getSize()[AxisIndex];
        }
        else
        {
            // update the maxMinorAxis
            if ((*Components)[i]->getSize()[(AxisIndex+1)%2] > maxMinorAxis)
                maxMinorAxis = (*Components)[i]->getSize()[(AxisIndex+1)%2];
            // update cumMajorAxis
            cumMajorAxis += (*Components)[i]->getSize()[AxisIndex];
        }
        if (i+1 == Components->size() && !firstOne) // if on the last one, draw the last buttons
        {
            numGaps = i-prevComponent;

            // find how far to translate to make it properly aligned
            offsetMajorAxis = getMajorAxisAlignment()*(totalMajorAxis - (cumMajorAxis+numGaps*gap[AxisIndex]));

            if (AxisIndex)
            {
                offsetY += offsetMajorAxis;
            }
            else
            {			
                offsetX += offsetMajorAxis;
            }
            for (int j = prevComponent; j < i+1; j++)
            {
                // find how far to translate to make this button properly aligned
                offsetMinorAxis = (maxMinorAxis-(*Components)[j]->getSize()[(AxisIndex+1)%2])*getComponentAlignment();

                // translate to make it properly aligned
                if (AxisIndex)
                {
                    offsetX += offsetMinorAxis;
                }
                else
                {
                    offsetY += offsetMinorAxis;
                }
                (*Components)[j]->setPosition(Pnt2f(offsetX, offsetY));

                if (AxisIndex)
                {
                    offsetX += -(Real64)offsetMinorAxis;
                    offsetY += (*Components)[j]->getSize()[AxisIndex] + gap[AxisIndex];
                }
                else
                {
                    offsetX += (*Components)[j]->getSize()[AxisIndex] + gap[AxisIndex];
                    offsetY+= -(Real64)offsetMinorAxis;
                }
            }
            // translate to the next row
            if (AxisIndex)
            {
                offsetX += maxMinorAxis+gap[(AxisIndex+1)%2];
                offsetY += -(offsetMajorAxis+cumMajorAxis+(numGaps+1)*gap[AxisIndex]);
            }
            else
            {
                offsetX += -(offsetMajorAxis+cumMajorAxis+(numGaps+1)*gap[AxisIndex]);
                offsetY += maxMinorAxis+gap[(AxisIndex+1)%2];
            }
            cumMinorAxis += maxMinorAxis;
        }
    }
    //Minor Axis Alignment
    Real32 displacement(borderSize[(AxisIndex+1)%2]-cumMinorAxis);
    Pnt2f offset;
    displacement *= getMinorAxisAlignment(); 
    for (UInt32 i = 0; i < Components->size(); ++i)
    {
        offset = (*Components)[i]->getPosition();
        offset[(AxisIndex+1)%2] += displacement;
        (*Components)[i]->setPosition(offset);
    }

    for(UInt32 i=0 ; i<Components->size(); ++i)
    {
    }
}
Пример #29
0
void ECKeyPad::initPins(unsigned numCols) {
    if (numCols < 3)
        numCols = 3;
    else if (numCols > 9)
        numCols = 9;

    if (numCols == m_numCols)
        return;

    int w = sideLength(numCols);
    int h = sideLength(4);

    setSize(-int(w / 16)*8, -int(h / 16)*8, w, h, true);

    if (numCols > m_numCols) {
        // Adding columns
        for (unsigned i = 0; i < 4; i++) {
            for (unsigned j = m_numCols; j < numCols; j++)
                addButton(buttonID(i, j), QRect(0, 0, 20, 20), text[i][j]);
        }

        ECNode *cols[9];

        for (unsigned j = m_numCols; j < numCols; j++)
            cols[j] = createPin(0, 64, 270, "col_" + QString::number(j));

        for (unsigned i = 0; i < 4; i++) {
            Pin *row = &ecNodeWithID("row_" + QString::number(i))->pin();

            for (unsigned j = m_numCols; j < numCols; j++)
                m_switch[i][j] = new Switch(this, cols[j]->pin(), *row, Switch::Open);
        }
    } else {
        // Remove columns
        for (unsigned i = 0; i < 4; i++) {
            for (unsigned j = numCols; j < m_numCols; j++)
                removeWidget(buttonID(i, j));
        }

        for (unsigned j = numCols; j < m_numCols; j++)
            removeNode("col_" + QString::number(j));

        for (unsigned i = 0; i < 4; i++) {
            for (unsigned j = m_numCols; j < numCols; j++)
                delete m_switch[i][j];
        }
    }

    //BEGIN Update Positions
    m_numCols = numCols;

    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < int(m_numCols); j++) {
            widgetWithID(buttonID(i, j))->setOriginalRect(
                QRect(offsetX() + 6 + 24*j, offsetY() + 6 + 24*i, 20, 20));
        }
    }

    for (int i = 0; i < 4; i++)
        m_nodeMap["row_" + QString::number(i)].x = width() + offsetX();

    for (int j = 0; j < int(m_numCols); j++)
        m_nodeMap["col_" + QString::number(j)].x = 24 * j + offsetX() + 16;

    updateAttachedPositioning();
    //END Update Positions
}
Пример #30
0
Animation::Animation(std::string frmName, unsigned int direction) : ActiveUI()
{
    auto frm = ResourceManager::frmFileType(frmName);
    setTexture(ResourceManager::texture(frmName));


    int xOffset = frm->shiftX(direction);
    int yOffset = frm->shiftY(direction);


    // Смещение кадра в текстуре анимации
    unsigned int x = 0;
    unsigned int y = 0;

    for (unsigned int d = 0; d != direction; ++d)
    {
        y += frm->height(d); //? может i - 1
    }


    for (auto f = 0; f != frm->framesPerDirection(); ++f)
    {
        xOffset += frm->offsetX(direction, f);
        yOffset += frm->offsetY(direction, f);

        auto frame = new AnimationFrame();
        frame->setWidth(frm->width(direction, f));
        frame->setHeight(frm->height(direction, f));
        frame->setXOffset(xOffset);
        frame->setYOffset(yOffset);
        frame->setY(y);
        frame->setX(x);

        auto fps = frm->framesPerSecond();
        if (fps == 0)
        {
            frame->setDuration(1000);
        }
        else
        {
            frame->setDuration(std::round(1000.0/static_cast<double>(frm->framesPerSecond())));
        }

        x += frm->width(direction);
        frames()->push_back(frame);
    }

    if (frm->animatedPalette())
    {
        AnimatedPalette*  palette=Game::getInstance()->animatedPalette();
        auto masks = frm->animatedMasks();

        if ((*masks)[libfalltergeist::FrmFileType::MASK_MONITOR] != NULL)
        {
            for (auto i=0; i<5; i++)
            {
                unsigned int* mask = new unsigned int[frm->width() * frm->height()]();

                //modify
                for (unsigned int j = 0; j< frm->width() * frm->height(); j++)
                {
                    mask[j] = palette->color((*masks)[libfalltergeist::FrmFileType::MASK_MONITOR][j],i);
                }
                //set
                auto texture = new Texture(frm->width(), frm->height());
                texture->loadFromRGBA(mask);
                _monitorTextures.push_back(texture);
            }
        }

        if ((*masks)[libfalltergeist::FrmFileType::MASK_SLIME] != NULL)
        {
            for (auto i=0; i<4; i++)
            {
                unsigned int* mask = new unsigned int[frm->width() * frm->height()]();	

                //modify
                for (unsigned int j = 0; j< frm->width() * frm->height(); j++)
                {
                    mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_SLIME][j]),i);
                }
                //set
                auto texture = new Texture(frm->width(), frm->height());
                texture->loadFromRGBA(mask);
                _slimeTextures.push_back(texture);
            }
        }

        if ((*masks)[libfalltergeist::FrmFileType::MASK_SHORE] != NULL)
        {
            for (auto i=0; i<6; i++)
            {
                unsigned int* mask = new unsigned int[frm->width() * frm->height()]();

                //modify
                for (unsigned int j = 0; j< frm->width() * frm->height(); j++)
                {
                    mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_SHORE][j]),i);
                }
                //set
                auto texture = new Texture(frm->width(), frm->height());
                texture->loadFromRGBA(mask);
                _shoreTextures.push_back(texture);
            }
        }


        if ((*masks)[libfalltergeist::FrmFileType::MASK_FIRE_SLOW] != NULL)
        {
            for (auto i=0; i<5; i++)
            {
                unsigned int* mask = new unsigned int[frm->width() * frm->height()]();

                //modify
                for (unsigned int j = 0; j< frm->width() * frm->height(); j++)
                {
                    mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_FIRE_SLOW][j]),i);
                }
                //set
                auto texture = new Texture(frm->width(), frm->height());
                texture->loadFromRGBA(mask);
                _fireSlowTextures.push_back(texture);
            }
        }


        if ((*masks)[libfalltergeist::FrmFileType::MASK_FIRE_FAST] != NULL)
        {
            for (auto i=0; i<5; i++)
            {
                unsigned int* mask = new unsigned int[frm->width() * frm->height()]();
                //modify
                for (unsigned int j = 0; j< frm->width() * frm->height(); j++)
                {
                    mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_FIRE_FAST][j]),i);
                }
                //set
                auto texture = new Texture(frm->width(), frm->height());
                texture->loadFromRGBA(mask);
                _fireFastTextures.push_back(texture);
            }
        }

        if ((*masks)[libfalltergeist::FrmFileType::MASK_REDDOT] != NULL)
        {
            for (auto i=0; i<16; i++)
            {
                unsigned int* mask = new unsigned int[frm->width() * frm->height()]();
                //modify
                for (unsigned int j = 0; j< frm->width() * frm->height(); j++)
                {
                    mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_REDDOT][j]),i);
                }
                //set
                auto texture = new Texture(frm->width(), frm->height());
                texture->loadFromRGBA(mask);
                _reddotTextures.push_back(texture);
            }
        }
    }
}