RealFde CFormulaNode::getAscent( const SizeFde &sz )
{
	RealFde vc = sz.height() / 2.0;

	switch( getAlignmentType() )
	{
	case FBtnChildPos::TableCenter2Baseline:
		if( (getAlignmentValue() - 1) >= 0 && (getAlignmentValue() - 1) < GetChildCount() )
		{
			CNode *pNode = GetChild( getAlignmentValue() - 1 );
			if( pNode != NULL )
				vc = pNode->GetPosition().y() + pNode->GetSize().height() / 2.0;
		}
		break;

	case FBtnChildPos::TableTop2Baseline:
		if( (getAlignmentValue() - 1) >= 0 && (getAlignmentValue() - 1) < GetChildCount() )
		{
			CNode *pNode = GetChild( getAlignmentValue() - 1 );
			if( pNode != NULL )
				vc = pNode->GetPosition().y();
			else
				vc = 0.0;
		}
		else
			vc = 0.0;
		break;

	case FBtnChildPos::TableBottom2Baseline:
		if( (getAlignmentValue() - 1) >= 0 && (getAlignmentValue() - 1) < GetChildCount() )
		{
			CNode *pNode = GetChild( getAlignmentValue() - 1 );
			if( pNode != NULL )
				vc = pNode->GetPosition().y() + pNode->GetSize().height();
			else
				vc = sz.height();
		}
		else
			vc = sz.height();
		break;
	default:
		vc = sz.height() - ::calculateCurrentTextDescent( GetLevel() );
		break;
	}

	return vc;
}
int CFormulaNode::Draw( CFmlDrawEngine& fde, const PointFde& tl, const RectFde& rc )
{
	QString _mathbackground = getMathMLAttr().getFilteredAttr( FBL_ATTR_mathbackground );
	if( isHidden() || to_mathml_data.name == FBL_TAG_mstyle )
	{
		if( _mathbackground.length() )
		{
			QColor dest_bkcolor;
			QString backcolor_str = _mathbackground;
			int rr = ::mml_mathcolor2color( backcolor_str, dest_bkcolor, QColor(0, 0, 0) );
			if( rr != -1 )
			{
				// Paint the background
				fde.FillRectangle( tl.x(), tl.y(), GetSize().width(), GetSize().height(), FS_LogBrush(dest_bkcolor, Qt::SolidPattern) ); 
			}
		}
		if( isHidden() )
			return 0;
	}

	if( !isFrameHidden() )
	{
		// draw child items
		RectFde rcItem;
		CNode *pNode = NULL;
		for( long i = 0; i < GetChildCount(); i++ )
		{
			pNode = GetChild( i );
			PointFde res = tl + pNode->GetPosition();
			rcItem.setLeft( res.x() );
			rcItem.setRight( rcItem.left() + pNode->GetSize().width() );
			rcItem.setTop( res.y() );
			rcItem.setBottom( rcItem.top() + pNode->GetSize().height() );

			if( rcItem.left() > rc.right() || rcItem.top() > rc.bottom() || rcItem.right() < rc.left() || rcItem.bottom() < rc.top() )
				continue;

			pNode->Draw( fde, PointFde( rcItem.left(), rcItem.top() ), rc );
		}
	}

	// draw graph primitives
	CNodeExInfo_GraphPrimitive::Draw( fde, tl, this );

	return 1;
}
Example #3
0
CVec2 CControl::CalcPosFromMouse(float x, float y) const
{
    CVec2 pos(x, y);
    CNode* pParent = GetParentNode();
    if( pParent && pParent->GetType() == eNT_NodeGUI )
    {
        ((CControl*)pParent)->WorldToLocal(x, y);
        pos.x = x - ((CControl*)pParent)->GetRealSize().x * m_vec2PercentPosition.x;
        pos.y = y - ((CControl*)pParent)->GetRealSize().y * m_vec2PercentPosition.y;
        CVec3 paretnPosition = pParent->GetPosition();
        ((CControl*)pParent)->LocalToWorld( paretnPosition.x, paretnPosition.y );
        CVec2 parentRealAnchor( paretnPosition.x, paretnPosition.y );
        pos.x += parentRealAnchor.x;
        pos.y += parentRealAnchor.y;
    }
    return pos;
}
Example #4
0
void CCamera3D::OnTransformed()
{
	m_View = CMatrix4::IDENTY;
		
	CMatrix4 rotate = CMatrix4::IDENTY;

	CNode* node = m_Node;
	node->GetTransform();

	//TODO: Optimize rotation
	CVector3 rot = CVector3(0.0f, 0.0f, node->GetRotation().Z);
	rotate.Rotate(rot);

	m_View *= rotate;

	rot = CVector3(node->GetRotation().X, 0.0f, 0.0f);
	rotate.Rotate(rot);

	m_View *= rotate;

	rot = CVector3(0.0f, node->GetRotation().Y, 0.0f);
	rotate.Rotate(rot);

	m_View *= rotate;

	CMatrix4 translate = CMatrix4::IDENTY;
	translate.Translate(node->GetPosition());

	m_View *= translate;

	CMatrix4 frustum = CMatrix4::IDENTY;

	frustum *= m_Projection;
	frustum *= m_View;

	m_Frustum.Setup(frustum);
}
int CFormulaNode::RunCalc()
{
	if( !getCalc() )
	{
		if( getCalcButtonID().length() )
			setMissButton();
		return 0;
	}
	if( !getCalc()->isPositionRunExist() ) return 0;

	QVector<RealFde> frames_ltrb;
	frames_ltrb.fill( 0.0, 4 * GetChildCount() );
	QVector<RealFde> frames_margin_ltrb;
	frames_margin_ltrb.fill( 0.0, 4 * GetChildCount() );
	QVector<RealFde> primitive_ltrb;
	primitive_ltrb.fill( 0.0, 4 * GetChildCount() );

	long i;
	CNode *pCurNode = GetFirstChild();
	if( pCurNode->GetType() != NODE_FRAME ) return 0;
	for( i = 0; i < GetChildCount() && pCurNode; pCurNode = pCurNode->GetNext(), i++ )
	{
		frames_ltrb[ i * 4 + SVG_NodeTemplate_Parameter_Left ] = pCurNode->GetPosition().x();
		frames_ltrb[ i * 4 + SVG_NodeTemplate_Parameter_Top ] = pCurNode->GetPosition().y();
		frames_ltrb[ i * 4 + SVG_NodeTemplate_Parameter_Right ] = pCurNode->GetPosition().x() + pCurNode->GetSize().width();
		frames_ltrb[ i * 4 + SVG_NodeTemplate_Parameter_Bottom ] = pCurNode->GetPosition().y() + pCurNode->GetSize().height();

		frames_margin_ltrb[ i * 4 + SVG_NodeTemplate_Parameter_Left ] = ((CFrameNode*) pCurNode)->getLeftIndent();
		frames_margin_ltrb[ i * 4 + SVG_NodeTemplate_Parameter_Top ] = ((CFrameNode*) pCurNode)->getTopIndent();
		frames_margin_ltrb[ i * 4 + SVG_NodeTemplate_Parameter_Right ] = ((CFrameNode*) pCurNode)->getRightIndent();
		frames_margin_ltrb[ i * 4 + SVG_NodeTemplate_Parameter_Bottom ] = ((CFrameNode*) pCurNode)->getBottomIndent();
	}

	for( i = 0; i < getGraphPrimNumber(); i++ )
	{
		primitive_ltrb.push_back( getGraphPrimitivePositionCoord( i, 0 ) );
		primitive_ltrb.push_back( getGraphPrimitivePositionCoord( i, 1 ) );
		primitive_ltrb.push_back( getGraphPrimitivePositionCoord( i, 2 ) );
		primitive_ltrb.push_back( getGraphPrimitivePositionCoord( i, 3 ) );
	}

	UseBtnCalc_InitByThisSize( *getCalc() );
	int ret = getCalc()->PositionRun( frames_ltrb, frames_margin_ltrb, primitive_ltrb );

	// reset parent margins
	UseBtnCalc_ChangeThisMargin( *getCalc() );

	for( i = 0; i < getGraphPrimNumber(); i++ )
	{
		if( getCalc()->isFormulaTypeGraphics( i ) )
		{
			setGraphPrimitivePositionCoord( 
				i, SVG_NodeTemplate_Parameter_Left,
				primitive_ltrb[ i * 4 + SVG_NodeTemplate_Parameter_Left ] );
			setGraphPrimitivePositionCoord( 
				i, SVG_NodeTemplate_Parameter_Top,
				primitive_ltrb[ i * 4 + SVG_NodeTemplate_Parameter_Top ] );
			setGraphPrimitivePositionCoord( 
				i, SVG_NodeTemplate_Parameter_Right,
				primitive_ltrb[ i * 4 + SVG_NodeTemplate_Parameter_Right ] );
			setGraphPrimitivePositionCoord( 
				i, SVG_NodeTemplate_Parameter_Bottom,
				primitive_ltrb[ i * 4 + SVG_NodeTemplate_Parameter_Bottom ] );
		}
	}

	if( ret )
	{
		pCurNode = GetFirstChild();
		i = 0;
		while( pCurNode )
		{
			((CFrameNode*) pCurNode)->setLeftIndent( frames_margin_ltrb[ i * 4 + SVG_NodeTemplate_Parameter_Left ] );
			((CFrameNode*) pCurNode)->setTopIndent( frames_margin_ltrb[ i * 4 + SVG_NodeTemplate_Parameter_Top ] );
			((CFrameNode*) pCurNode)->setRightIndent( frames_margin_ltrb[ i * 4 + SVG_NodeTemplate_Parameter_Right ] );
			((CFrameNode*) pCurNode)->setBottomIndent( frames_margin_ltrb[ i * 4 + SVG_NodeTemplate_Parameter_Bottom ] );
			pCurNode = pCurNode->GetNext();
			i++;
		}
		RecalculateSizeChild();
	}

	return ret;
}
void CFormulaNode::Recalculate_VerticalCenter( const SizeFde &sz )
{
	RealFde vc = sz.height() / 2.0;

	switch( getAlignmentType() )
	{
	case FBtnChildPos::Child:
		if( getAlignmentValue() >= 1 && (getAlignmentValue() - 1) < getGraphPrimNumber() )
		{
			const RectFde& _t = getGraphPrimitivePositionRect( getAlignmentValue() - 1 );
			vc = (_t.top() + _t.bottom()) / 2.0;
		}
		break;
	case FBtnChildPos::Child_Average:
		if( getAlignmentValue() >= 1 && (getAlignmentValue() - 1) < getGraphPrimNumber() )
		{
			vc = 0.0;
			for( long i = 0; i <= getAlignmentValue() - 1; i++ )
			{
				const RectFde& _t = getGraphPrimitivePositionRect( i );
				vc += _t.top() + _t.bottom();
			}
			vc = vc / (getAlignmentValue() * 2.0);
		}
		break;
	case FBtnChildPos::MSPACE_Exact_HeightDepth:
	case FBtnChildPos::Frame:
		if( (getAlignmentValue() - 1) >= 0 && (getAlignmentValue() - 1) < GetChildCount() )
		{
			CNode *pNode = GetChild( getAlignmentValue() - 1 );
			if( pNode )
				vc = pNode->GetPosition().y() + pNode->GetVerticalCenter();
		}
		break;
	case FBtnChildPos::Frame_Blank_Average:
		{
			CNode *pNodeFirst = GetFirstChild();
			CNode *pNodeLast  = GetLastChild();
			if( pNodeFirst != NULL && pNodeLast != NULL )
			{
				vc = (pNodeFirst->GetPosition().y() + pNodeFirst->GetSize().height() + pNodeLast->GetPosition().y()) / 2.0;
			}
		}
		break;
	case FBtnChildPos::Half:
		break;

	case FBtnChildPos::TableAxis:
		if( (getAlignmentValue() - 1) >= 0 && (getAlignmentValue() - 1) < GetChildCount() )
		{
			CNode *pNode = GetChild( getAlignmentValue() - 1 );
			if( pNode )
				vc = pNode->GetPosition().y() + pNode->GetSize().height() / 2.0;
		}
		break;

	case FBtnChildPos::TableCenter2Baseline:
	case FBtnChildPos::TableTop2Baseline:
	case FBtnChildPos::TableBottom2Baseline:
		{
			RealFde asc = ::getCurrentDefaultAscent( GetLevel() );
			RealFde h = ::getCurrentDefaultSize( GetLevel() ).height();
			vc = getAscent( sz ) - asc + h - asc / 2.0;
		}
		break;

	default:
		break;
	}

	SetVerticalCenter( vc );
}
Example #7
0
/*****************************************************************
* GeneratePath()		Uses A* PathFinding to generate a path from
*						the start position to the goal position
*
* Ins:					int
*						int
*
* Outs:					None
*
* Returns:				vector<CNode*>
*
* Mod. Date:		    08/16/2015
* Mod. Initials:	    NS
*****************************************************************/
vector<XMFLOAT3> CPathFinding::GeneratePath(int _start, int _goal, bool smoothed)
{
	GetReadyForNewSearch();

	// Create the first PathNode
	CPathNode* curPathNode = new CPathNode(m_pGraph->GetNodes()[_start]);
	m_pqNodeQue.push(curPathNode);
	m_umVisitedNodes[_start] = curPathNode;

	// Create all local variables here for attempt at optimization
	CPathNode* theNode = nullptr;
	CPathNode* visitedNode = nullptr;
	CPathNode* nextPathNode = nullptr;
	CNode* curNode;
	CNode* adjNode;
	CEdge* curEdge;
	float newFinalCost;
	float newCost;
	float oldCost;
	float curCost;
	float newHeuristic;
	int adjNodeIndex;
	int curNodeIndex;
	vector<XMFLOAT3> path;

	// Loop while there are edges to explore
	while (!m_pqNodeQue.empty())
	{
		// Get the next node.
		curPathNode = m_pqNodeQue.front();
		m_pqNodeQue.pop();

		// Access the node and it's index for future use
		curNode = curPathNode->GetNode();
		curNodeIndex = curNode->GetIndex();

		// If the destination is found
		if (curNodeIndex == _goal)
		{
			// Clear the old path
			m_lPath.clear();

			// Build the path
			theNode = m_umVisitedNodes[curNode->GetIndex()];

			// Untill we trace back to the _start node
			while (theNode != nullptr)
			{
				// Add the node to the path
				m_lPath.push_back(theNode->GetNode());

				// Advance to the next connected node
				theNode = theNode->m_cpParent;
			}
			if (smoothed)
				path = SmoothPath(m_lPath);
			else
			{
				for (size_t currNode = 0; currNode < m_lPath.size(); currNode++)
					path.push_back(m_lPath[currNode]->GetPosition());
			}

			
			

			
			
				/*m_umVisitedNodes.clear();
				^^^^^^^^^^^^^^^^^^^^^^^^^^
				This stupid line of code caused us so many headaches that I can't bring
				 myself to actually delete it. Forever it shall live in the belly of our 
				 pathfinding code*/

			return path;
		}

		// For each edge the node has
		for (size_t edge = 0; edge < curNode->GetEdges().size(); edge++)
		{
			// Get the current Edge and the node attatched to it
			curEdge = curNode->GetEdges()[edge];
			adjNodeIndex = curEdge->GetAdjNode();
			adjNode = m_pGraph->GetNodes()[adjNodeIndex];

			// Calculate the cost to the adj Node from _start Node (Total cost so far)
			curCost = curNode->GetCost() + curEdge->GetEdgeCost();

			// If the node has been visited
			if (m_umVisitedNodes[adjNodeIndex] != nullptr)
			{
				visitedNode = m_umVisitedNodes[adjNodeIndex];

				// The cost it took previously to get to the node
				oldCost = visitedNode->GetNode()->GetCost();

				// If the new cost is less the the old one
				if (curCost < oldCost)
				{
					m_pqNodeQue.remove(visitedNode);
					visitedNode->GetNode()->SetCost(curCost);

					newFinalCost = visitedNode->GetNode()->GetCost() + visitedNode->GetNode()->GetHeuristic() * m_fHeuristicWeight;
					visitedNode->GetNode()->SetFinalCost(newFinalCost);

					visitedNode->m_cpParent = curPathNode;
					m_pqNodeQue.push(visitedNode);
				}

			}
			else // If it has not been visited
			{
				// Set the cost adj notes cost (Total of what it takes to get here)
				newCost = curNode->GetCost() + curEdge->GetEdgeCost();
				adjNode->SetCost(newCost);

				// Set the HeuristicCost
				newHeuristic = CalculateCost(m_pGraph->GetNodes()[_goal]->GetPosition(), adjNode->GetPosition());
				adjNode->SetHeuristic(newHeuristic);

				// Set the new FinalCost // ?? 
				newFinalCost = newCost + newHeuristic * m_fHeuristicWeight;
				adjNode->SetFinalCost(newFinalCost);

				// Create a PathNode for the adj node (Note adj to the one I'm on)
				nextPathNode = new CPathNode(adjNode);

				// Set it's parent to the one I'm on (Coming from)
				nextPathNode->m_cpParent = curPathNode;

				// Add it to the que to be checked.
				m_pqNodeQue.push(nextPathNode);

				// Mark it as visited
				m_umVisitedNodes[adjNodeIndex] = nextPathNode;
			}
		}
	}
	return path;
}