int CParentNode::setReadOnlyAttribute4AllNonReadOnlyNodes()
{
	int nRet = 1;
	CNode *pNode;
	CFormulaNode *pForm;
	for( long i = 0; i < GetChildCount(); i++ )
	{
		pNode = GetChild( i );
		if( pNode->GetType() == NODE_PLANETEXT )
		{
			if( !pNode->isReadOnly() )
				nRet = 0;
			else
				pNode->setReadOnly();
		}
		else if( ((CParentNode*) pNode)->GetChildCount() )
		{
			int n = ((CParentNode*) pNode)->setReadOnlyAttribute4AllNonReadOnlyNodes();
			switch( pNode->GetType() )
			{
			case NODE_FORMULA:
				pForm = ((CFormulaNode*)pNode);
				if( !pForm->isReadOnly() )
				{
					if( ::mml_is_cm_token( pForm->to_mathml_data.name ) )
					{
						if( n && pForm->GetParent() )
						{
							CFormulaNode *frmParent = pForm->GetParent()->getParentContentFormulaNode( 1 );
							if( frmParent )
								pForm->setReadOnly();
						}
					}
					else
						nRet = 0;
				}
				break;
			case NODE_LINE:
				if( n ) pNode->setReadOnly();
				break;
			case NODE_FRAME:
				pNode->setReadOnly();
				break;
			default:
				break;
			}
		}
		else
			nRet = 0;
	}
	return nRet;
}
CLineNode* CFormulaNode::getFormulaLineChild( long frame_idx, long child_idx )
{
	CNode* pFrame = GetChild( frame_idx );

	if( !pFrame || pFrame->GetType() != NODE_FRAME )
		return NULL;

	CNode* fch = ((CFrameNode*) pFrame)->GetChild( child_idx );
	if( !fch || fch->GetType() != NODE_LINE)
		return NULL;

	return (CLineNode*) fch;
}
Beispiel #3
0
void CControl::Initialize()
{
    super::Initialize();
    m_bUninitialize = false;
    if ( strcmp( m_strName.c_str(), DEFAULT_CONTROL_NAME ) == 0)
    {
        SetName( GetDefaultName() );
    }
    else
    {
        CWindowManager::GetInstance()->RegisterControl( this );
    }
    CalcInheritColor();
    CRenderTarget* pMainRenderTarget = CRenderManager::GetInstance()->GetCurrentRenderTarget();
    BEATS_ASSERT( pMainRenderTarget );
    CNode* pParentNode = GetParentNode();
    if ( nullptr == pParentNode)
    {
        CWindowManager::GetInstance()->AddToRoot( this );
    }
    if (nullptr == pParentNode || pParentNode->GetType() != eNT_NodeGUI )
    {
        //update control vertex by render target
        OnParentSizeChange( (float)pMainRenderTarget->GetWidth(), (float)pMainRenderTarget->GetHeight());
    }
}
CFormulaNode* CFormulaNode::getFormulaDeepFormulaChild( long frame_idx, long child_idx )
{
	CNode *ret = getFormulaDeepChild( frame_idx, child_idx );
	if( !ret || ret->GetType() != NODE_FORMULA )
		return NULL;
	return (CFormulaNode*) ret;
}
CFormulaNode* CLineNode::InsertMMLFormulaNode_OTHERS( FXmlBtn *ptrFXmlBtn, AST_TXML_Compound *node, int is_hidden )
{
	CFormulaNode *new_node = 0;
	CFrameNode *pFrameNode = 0;
	CNode *pCurNode = 0;

	if( !ptrFXmlBtn )
		return NULL; // error: Internal error

	if( ptrFXmlBtn->getNodeType() == NODE_FORMULA )
	{
		new_node = CreateFormulaNode( *ptrFXmlBtn );
		if( !new_node ) return NULL; // error: Internal error

		pFrameNode = (CFrameNode *)GetFrameNode();
		if( pFrameNode ) new_node->SetLevel( pFrameNode->GetLevel() );
		AddChild( new_node );

		if( node )
		{
			pCurNode = new_node->GetFirstChild();
			if( pCurNode && pCurNode->GetType() == NODE_FRAME )
			{
				if( ((CFrameNode*)pCurNode)->GetFirstChild() )
					((CFrameNode*)pCurNode)->DeleteChild( ((CFrameNode*)pCurNode)->GetFirstChild() );
				pCurNode->read_mathml( node );
			}
		}
	}
	if( new_node && is_hidden )
		new_node->setHidden();
	return new_node;
}
CFormulaNode* CFormulaNode::getSemanticsOrCTokenNodeWrapped()
{
	for( CNode *curNode = this; curNode != 0; curNode = curNode->GetParent() )
	{
		if( curNode->GetType() == NODE_FORMULA && curNode->to_mathml_data.is_content != 0 )
		{
			if( !xml_strcmp( curNode->to_mathml_data.name, FBL_TAG_semantics ) || 
				!xml_strcmp( curNode->to_mathml_data.name, FBL_TAG_annotation ) || 
				::mml_is_cm_token( curNode->to_mathml_data.name ) )
				return (CFormulaNode*)curNode;
			else if( curNode->to_mathml_data.name == FBL_TAG_annotation_xml )
			{
				QString attrValue = _T("");
				struct HMathMLAttr mml_attr_by_this_node( getMathMLAttr() );
				if( mml_attr_by_this_node.getFilteredAttr( FBL_ATTR_encoding, attrValue ) == 0 &&
					attrValue == FBL_VAL_MathML_Content )
				{
					continue;
				}
				return (CFormulaNode*)curNode;
			}
		}
	}
	return 0;
}
CNode* CFormulaNode::getSingleChild( long frame_idx )
{
	CNode *node = GetChild( frame_idx );
	if( !node || node->GetType() != NODE_FRAME ) return 0;
	CFrameNode *frame = (CFrameNode*)node;

	if( frame->GetChildCount() != 1 ) return 0;
	node = frame->GetFirstChild();
	if( !node || node->GetType() != NODE_LINE ) return 0;
	CLineNode *line = (CLineNode*)node;

	if( line->GetChildCount() != 1 ) return 0;
	node = line->GetFirstChild();
	if( !node ) return 0;

	return node;
}
Beispiel #8
0
void CControl::WorldToLocal(float &x, float &y)
{
    CNode* pParent = GetParentNode();
    if( pParent && pParent->GetType() == eNT_NodeGUI )
    {
       down_cast<CControl*>(pParent)->WorldToLocal(x, y);
    }
    ParentToLocal(x, y);
}
Beispiel #9
0
void CControl::LocalToWorld(float &x, float &y)
{
    LocalToParent(x, y);

    CNode* pParent = GetParentNode();
    if( pParent && pParent->GetType() == eNT_NodeGUI )
    {
        down_cast<CControl*>(pParent)->LocalToWorld(x, y);
    }
}
CFormulaNode* CFormulaNode::getSingleFormulaChild_ContentEmptyFrame( long frame_idx )
{
	CNode *node = getSingleChild( frame_idx );
	if( !node || node->GetType() != NODE_FORMULA ) return 0;
	if( (node->to_mathml_data.is_content || node->isAutodetectContent()) &&
		((CFormulaNode*) node)->getCalcButtonID() == HF_BTNID_EMPTY_FRAME )
	{
		return (CFormulaNode*) node;
	}
	return 0;
}
CPlaneText* CFormulaNode::getSingleFormulaChild_ContentText( long frame_idx )
{
	CNode *node = getSingleChild( frame_idx );
	if( !node || node->GetType() != NODE_FORMULA ||
		((CFormulaNode*) node)->getCalcButtonID() != HF_BTNID_EMPTY_FRAME )
		return 0;
	if( node->to_mathml_data.is_content || node->isAutodetectContent() )
	{
		return ((CFormulaNode*) node)->getSingleTextChild();
	}
	return 0;
}
Beispiel #12
0
bool CControl::HandleTouchEvent( CTouchEvent* event )
{
    bool bRet = false;
    if ( m_bResiveTouchEvent )
    {
        const CVec2& pos = event->GetTouchPoint();
        if ( event->GetType() == eET_EVENT_TOUCH_MOVED )
        {
            m_bTouchInRect = HitTest(pos.x, pos.y);
            if ( m_bTouchInRect )
            {
                OnTouchMove( pos.x, pos.y );
                bRet = true;
            }
            else
            {
                if ( m_bClick )
                {
                    StopClickAnimation();
                }
            }
        }
        else
        {
            if( event->GetType() == eET_EVENT_TOUCH_ENDED && m_bClick )
            {
                OnTouchEnded( pos.x, pos.y );
            }
            else
            {
                bRet = HitTest(pos.x, pos.y);
                if(bRet)
                {
                    if ( m_bDispatchEventToParent )
                    {
                        CNode* pParent = GetParentNode();
                        bRet = pParent && pParent->GetType() == eNT_NodeGUI;
                        if (bRet)
                        {
                            down_cast<CControl*>(pParent)->DispatchEvent( event->GetType(), pos.x, pos.y, event->GetDelta() );
                        }
                    }
                    else
                    {
                        DispatchEvent( event->GetType(), pos.x, pos.y, event->GetDelta() );
                    }
                }
            }
        }
    }
    return bRet;
}
void CFormulaNode::getChildDimensions_Vertical( RealFde *destDim )
{
	CNode *padded = getSingleChild();
	if( padded && padded->getAlignmentType() == FBtnChildPos::MSPACE_Exact_HeightDepth )
	{
		if( padded->GetType() == NODE_FORMULA )
		{
			((CFormulaNode*)padded)->calculatePadded_Vertical( destDim );
			return;
		}
		else if( padded->GetType() == NODE_PLANETEXT )
		{
			destDim[ MML_MPADDED_UNITS_HEIGHT ] = padded->getMMLHeight();
			destDim[ MML_MPADDED_UNITS_DEPTH ]  = padded->getMMLDepth();
			return;
		}
	}

	RealFde ascent = ::calculateCurrentTextAscent( GetLevel() );
	destDim[ MML_MPADDED_UNITS_DEPTH ] = ::calculateCurrentDepth( GetLevel(), ascent );
	destDim[ MML_MPADDED_UNITS_HEIGHT ] = ::calculateCurrentHeight( GetChild( 0 ), 1, GetLevel(), ascent );
}
long CFormulaNode::getUpperFormulaChildrenCount4Content()
{
	long lRet = 0;
	CLineNode *_line = getContentFormulaSingleLineChild();
	if( _line )
	{
		CNode *pNode;
		for( long i = 0; i < _line->GetChildCount(); i++ )
		{
			pNode = _line->GetChild( i );
			if( pNode->GetType() == NODE_FORMULA )
				lRet++;
		}
	}
	return lRet;
}
Beispiel #15
0
void CControl::CalcInheritColor()
{
    CNode* pParent = GetParentNode();
    if ( pParent && pParent->GetType() == eNT_NodeGUI )
    {
        CControl* m_pParentNode = (CControl*)pParent;
        CColor inheritColor = m_pParentNode->GetColor( false );
        m_colorInherit.r = (unsigned char)(m_color.r * 0.5f + inheritColor.r * 0.5f);
        m_colorInherit.g = (unsigned char)(m_color.g * 0.5f + inheritColor.g * 0.5f);
        m_colorInherit.b = (unsigned char)(m_color.b * 0.5f + inheritColor.b * 0.5f);
        m_colorInherit.a = (unsigned char)(m_color.a * 0.5f + inheritColor.a * 0.5f);
    }
    else
    {
        m_colorInherit = m_color;
    }
}
void CParentNode::setReadOnlyAttribute4AllNonEmptyNodes()
{
	CNode *pNode;
	for( long i = 0; i < GetChildCount(); i++ )
	{
		pNode = GetChild( i );
		if( pNode->GetType() == NODE_PLANETEXT )
		{
			pNode->setReadOnly();
		}
		else if( ((CParentNode*) pNode)->GetChildCount() )
		{
			pNode->setReadOnly();
			((CParentNode*) pNode)->setReadOnlyAttribute4AllNonEmptyNodes();
		}
	}
}
Beispiel #17
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;
}
CNode* CFormulaNode::getFormulaDeepChild( long frame_idx, long child_idx )
{
	CNode* pFrame = GetChild( frame_idx );

	if( !pFrame || pFrame->GetType() != NODE_FRAME )
		return NULL;

	if( !((CFrameNode*) pFrame)->GetFirstChild() ||
		((CFrameNode*) pFrame)->GetFirstChild()->GetType() != NODE_LINE )
		return NULL;

	CLineNode* pLine = (CLineNode*) ((CFrameNode*) pFrame)->GetFirstChild();

	if( child_idx == -1 )
		return pLine->GetLastChild();
	else if( child_idx == 0 )
		return pLine->GetFirstChild();
	return pLine->GetChild( child_idx );
}
int CParentNode::haveChild( CNode *pNode )
{
	for( long no = 0; no < GetChildCount(); no++ )
	{
		CNode *child = GetChild( no );
		if( child == pNode ) return 1;

		switch( child->GetType() )
		{
		case NODE_FRAME:
		case NODE_LINE:
		case NODE_FORMULA:
			if( ((CParentNode*) child)->haveChild( pNode ) ) return 1;
			break;
		default:
			break;
		}
	}
	return 0;
}
CFormulaNode* CFormulaNode::getRecursiveApplyOperand( bool lastChild, QString exceptId )
{
	CFormulaNode *tryFormulaNode = this;
	for(;;)
	{
		CNode *contentNode = 0;
		if( tryFormulaNode->isAutodetectContent() && 
			tryFormulaNode->getCalcButtonID() == HF_BTNID_EMPTY_FRAME )
		{
			contentNode = tryFormulaNode->getSingleChild( 0 );
		}
		else if( tryFormulaNode->to_mathml_data.is_content &&
				::mml_is_cm_apply( tryFormulaNode->to_mathml_data.name ) && 
				tryFormulaNode->getCalcButtonID() != exceptId )
		{
			contentNode = lastChild ? tryFormulaNode->getFormulaDeepChild( 0, -1 ) : tryFormulaNode->getFormulaDeepChild( 0, 0 );
		}
		if( contentNode && contentNode->GetType() == NODE_FORMULA && (contentNode->to_mathml_data.is_content || contentNode->isAutodetectContent()) )
			tryFormulaNode = (CFormulaNode*) contentNode;
		else
			break;
	}
	return tryFormulaNode;
}
CFormulaNode* CLineNode::InsertMMLFormulaNode_OTHERS( FXmlBtn *ptrFXmlBtn, AST_TXML_Tag *node, int is_hidden )
{
	long cb = 0;
	CFormulaNode *new_node = 0/*, *box_node = 0, *child_node = 0*/;
	CFrameNode *pFrameNode = 0;
	//CLineNode *parent_line = 0;
	CNode *pCurNode = 0;

	if( !ptrFXmlBtn )
		return NULL; // error: Internal error

//	if( !node->getTags() || node->getTags()->getChildNumber() == 0 )
//		return NULL;	//error: Error encountered and repaired: Too few Child node->getTagName() in node

	if( ptrFXmlBtn->getNodeType() == NODE_FORMULA )
	{
		new_node = CreateFormulaNode( *ptrFXmlBtn );
		if( !new_node ) return NULL; // error: Internal error

		AST_TXML_Attribute *colorAttr = node->getAttribute( FBL_ATTR_color );
		QColor grPrimColor = QColor(0, 0, 0);
		if( colorAttr &&
			::mml_mathcolor2color( colorAttr->getStringValue(), grPrimColor, QColor(0, 0, 0) ) == 0 )
		{
			new_node->setLineColor( grPrimColor );
		}

		pFrameNode = (CFrameNode *)GetFrameNode();
		if( pFrameNode ) new_node->SetLevel( pFrameNode->GetLevel() );
		AddChild( new_node );

		if( node->getTags() && node->getTags()->getChildNumber() > 0 )
		{
			if( new_node->GetChildCount() < node->getTags()->getChildNumber() )
			{	//error: Error encountered and repaired: Too many Child node->getTagName() in node
				//delete new_node;
				//return;
				if( xml_strcmp( node->getTagName(), FBL_TAG_merror ) )
				{
					QString mess = _T("Too many children in ") + node->getTagName();
					InsertMMLFormulaNode_MERROR( mess );
				}
			}

			if( new_node->GetChildCount() > node->getTags()->getChildNumber() )
			{	//error: Error encountered and repaired: Too few Child node->getTagName() in node
				//delete new_node;
				//return;
				if( xml_strcmp( node->getTagName(), FBL_TAG_merror ) )
				{
					QString mess = _T("Too few children in ") + node->getTagName();
					InsertMMLFormulaNode_MERROR( mess );
				}
			}

			pCurNode = new_node->GetFirstChild();
			cb = 0;
			while( pCurNode && cb < new_node->GetChildCount() && cb < node->getTags()->getChildNumber() )
			{
				if( pCurNode->GetType() == NODE_FRAME && 
					node->getTags()->getChild( cb ) &&
					node->getTags()->getChild( cb )->getNodeType() == ASTT_TXML_Tag )
				{
					
					if( ((CFrameNode*)pCurNode)->GetFirstChild() )
						((CFrameNode*)pCurNode)->DeleteChild( ((CFrameNode*)pCurNode)->GetFirstChild() );
					pCurNode->read_mathml( (AST_TXML_Tag*)node->getTags()->getChild( cb ) );
				}
				pCurNode = pCurNode->GetNext();
				cb++;
			}
		}
	}
	if( new_node && is_hidden )
		new_node->setHidden();
	return new_node;
}
Beispiel #22
0
void CG8bitSparseImage::MaskFill (CG32bitImage &Dest, int xDest, int yDest, int cxDest, int cyDest, int xSrc, int ySrc, CG32bitPixel rgbColor) const

//	MaskFill
//
//	Fills the destination image with the given color through our mask.

	{
	//	Make sure we're in bounds

	if (!Dest.AdjustCoords(&xSrc, &ySrc, GetWidth(), GetHeight(), 
			&xDest, &yDest,
			&cxDest, &cyDest))
		return;

	//	Short-circuit

	if (rgbColor.GetAlpha() == 0x00)
		return;

	//	Compute a pre-multiplied color

	BYTE *pAlpha = CG32bitPixel::AlphaTable(rgbColor.GetAlpha());
	CG32bitPixel rgbPreMultColor = CG32bitPixel(pAlpha[rgbColor.GetRed()], pAlpha[rgbColor.GetGreen()], pAlpha[rgbColor.GetBlue()], rgbColor.GetAlpha());

	//	Loop

	int yPos = ySrc;
	int yPosEnd = ySrc + cyDest;
	int yTile = yPos / m_cyTile;
	int yOffset = ClockMod(yPos, m_cyTile);
	int xTileStart = xSrc / m_cxTile;
	int xOffsetStart = ClockMod(xSrc, m_cxTile);

	int yDestPos = yDest;
	while (yPos < yPosEnd)
		{
		int cyTileLeft = Min(m_cyTile - yOffset, yPosEnd - yPos);

		//	Is this a valid tile row, then continue

		if (yTile >= 0 && yTile < m_yTileCount)
			{
			int xPos = xSrc;
			int xPosEnd = xSrc + cxDest;
			int xTile = xTileStart;
			int xOffset = xOffsetStart;

			int xDestPos = xDest;
			while (xPos < xPosEnd)
				{
				int cxTileLeft = Min(m_cxTile - xOffset, xPosEnd - xPos);

				//	If this is a valid tile, then we can continue

				if (xTile >= 0 && xTile < m_xTileCount)
					{
					const CNode &Tile = GetTile(xTile, yTile);

					switch (Tile.GetType())
						{
						case typeByte:
							{
							BYTE byAlpha = Tile.GetByte();
							if (byAlpha == 0x00)
								{}
							else if (byAlpha == 0xff)
								Dest.Fill(xDestPos, yDestPos, cxTileLeft, cyTileLeft, rgbColor);
							else
								//	We just modify the alpha on the original color (Fill will take care of the rest)
								Dest.Fill(xDestPos, yDestPos, cxTileLeft, cyTileLeft, CG32bitPixel(rgbColor, CG32bitPixel::BlendAlpha(rgbColor.GetAlpha(), byAlpha)));
							break;
							}

						case typeNodeArray:
							{
							CNode *Rows = Tile.GetNodeArray();
							CNode *pSrcRow = Rows + yOffset;
							CNode *pSrcRowEnd = pSrcRow + cyTileLeft;

							CG32bitPixel *pDestRow = Dest.GetPixelPos(xDestPos, yDestPos);

							while (pSrcRow < pSrcRowEnd)
								{
								CG32bitPixel *pDest = pDestRow;
								CG32bitPixel *pDestEnd = pDestRow + cxTileLeft;

								switch (pSrcRow->GetType())
									{
									case typeByte:
										{
										BYTE byAlpha = pSrcRow->GetByte();
										if (byAlpha == 0x00)
											{}
										else if (byAlpha == 0xff)
											{
											BYTE byFillAlpha = rgbColor.GetAlpha();
											if (byFillAlpha == 0xff)
												{
												while (pDest < pDestEnd)
													*pDest++ = rgbColor;
												}
											else
												{
												BYTE *pAlphaInv = CG32bitPixel::AlphaTable(byFillAlpha ^ 0xff);

												BYTE byRed = rgbPreMultColor.GetRed();
												BYTE byGreen = rgbPreMultColor.GetGreen();
												BYTE byBlue = rgbPreMultColor.GetBlue();

												while (pDest < pDestEnd)
													{
													BYTE byRedResult = pAlphaInv[pDest->GetRed()] + byRed;
													BYTE byGreenResult = pAlphaInv[pDest->GetGreen()] + byGreen;
													BYTE byBlueResult = pAlphaInv[pDest->GetBlue()] + byBlue;

													*pDest++ = CG32bitPixel(byRedResult, byGreenResult, byBlueResult);
													}
												}
											}
										else
											{
											//	Blend the alphas together
											BYTE byFillAlpha = CG32bitPixel::BlendAlpha(byAlpha, rgbColor.GetAlpha());

											BYTE *pAlpha = CG32bitPixel::AlphaTable(byFillAlpha);
											BYTE *pAlphaInv = CG32bitPixel::AlphaTable(byFillAlpha ^ 0xff);

											BYTE byRed = pAlpha[rgbColor.GetRed()];
											BYTE byGreen = pAlpha[rgbColor.GetBlue()];
											BYTE byBlue = pAlpha[rgbColor.GetGreen()];

											while (pDest < pDestEnd)
												{
												BYTE byRedResult = pAlphaInv[pDest->GetRed()] + byRed;
												BYTE byGreenResult = pAlphaInv[pDest->GetGreen()] + byGreen;
												BYTE byBlueResult = pAlphaInv[pDest->GetBlue()] + byBlue;

												*pDest++ = CG32bitPixel(byRedResult, byGreenResult, byBlueResult);
												}
											}
										break;
										}

									case typeByteArray:
										{
										BYTE *pSrcAlpha = pSrcRow->GetByteArray() + xOffset;
										BYTE *pSrcAlphaEnd = pSrcAlpha + cxTileLeft;

										BYTE byColorAlpha = rgbColor.GetAlpha();
										if (byColorAlpha == 0xff)
											{
											while (pSrcAlpha < pSrcAlphaEnd)
												{
												if (*pSrcAlpha == 0x00)
													{}
												else if (*pSrcAlpha == 0xff)
													*pDest = rgbColor;
												else
													{
													BYTE *pAlpha = CG32bitPixel::AlphaTable(*pSrcAlpha);
													BYTE *pAlphaInv = CG32bitPixel::AlphaTable(*pSrcAlpha ^ 0xff);

													BYTE byRedResult = pAlphaInv[pDest->GetRed()] + pAlpha[rgbColor.GetRed()];
													BYTE byGreenResult = pAlphaInv[pDest->GetGreen()] + pAlpha[rgbColor.GetGreen()];
													BYTE byBlueResult = pAlphaInv[pDest->GetBlue()] + pAlpha[rgbColor.GetBlue()];

													*pDest = CG32bitPixel(byRedResult, byGreenResult, byBlueResult);
													}

												pSrcAlpha++;
												pDest++;
												}
											}
										else
											{
											BYTE *pAlphaFFInv = CG32bitPixel::AlphaTable(byColorAlpha ^ 0xff);

											while (pSrcAlpha < pSrcAlphaEnd)
												{
												if (*pSrcAlpha == 0x00)
													{}
												else if (*pSrcAlpha == 0xff)
													{
													BYTE byRedResult = pAlphaFFInv[pDest->GetRed()] + rgbPreMultColor.GetRed();
													BYTE byGreenResult = pAlphaFFInv[pDest->GetGreen()] + rgbPreMultColor.GetGreen();
													BYTE byBlueResult = pAlphaFFInv[pDest->GetBlue()] + rgbPreMultColor.GetBlue();

													*pDest = CG32bitPixel(byRedResult, byGreenResult, byBlueResult);
													}
												else
													{
													BYTE byFillAlpha = CG32bitPixel::BlendAlpha(*pSrcAlpha, byColorAlpha);

													BYTE *pAlpha = CG32bitPixel::AlphaTable(byFillAlpha);
													BYTE *pAlphaInv = CG32bitPixel::AlphaTable(byFillAlpha ^ 0xff);

													BYTE byRedResult = pAlphaInv[pDest->GetRed()] + pAlpha[rgbColor.GetRed()];
													BYTE byGreenResult = pAlphaInv[pDest->GetGreen()] + pAlpha[rgbColor.GetGreen()];
													BYTE byBlueResult = pAlphaInv[pDest->GetBlue()] + pAlpha[rgbColor.GetBlue()];

													*pDest = CG32bitPixel(byRedResult, byGreenResult, byBlueResult);
													}

												pSrcAlpha++;
												pDest++;
												}
											}
										break;
										}
									}

								pSrcRow++;
								pDestRow = Dest.NextRow(pDestRow);
								}

							break;
							}
						}
					}

				//	Move to the next tile

				xTile++;
				xOffset = 0;
				xPos += cxTileLeft;
				xDestPos += cxTileLeft;
				}
			}

		//	Next tile row

		yTile++;
		yOffset = 0;
		yPos += cyTileLeft;
		yDestPos += cyTileLeft;
		}
	}
Beispiel #23
0
CVec2 CControl::CalcSizeFromMouse(float x, float y, EHitTestResult hitPos)
{
    CVec2 anchor = m_vec2Anchor;
    WorldToLocal(x, y);

    CVec2 realSize = m_vecRealSize;
    CVec2 newRealSize = realSize;
    switch(hitPos)
    {
    case eHTR_HIT_TOP_LEFT:
        if(anchor.x > 0.f)
            newRealSize.x = - x / anchor.x;
        if(anchor.y > 0.f)
            newRealSize.y = - y / anchor.y;
        break;
    case eHTR_HIT_TOP_CENTER:
        newRealSize.x = realSize.x;
        if(anchor.y > 0.f)
            newRealSize.y = - y / anchor.y;
        break;
    case eHTR_HIT_TOP_RIGHT:
        if(anchor.x < 1.f)
            newRealSize.x = x / (1 - anchor.x);
        if(anchor.y > 0.f)
            newRealSize.y = - y / anchor.y;
        break;
    case eHTR_HIT_LEFT_CENTER:
        if(anchor.x > 0.f)
            newRealSize.x = - x / anchor.x;
        newRealSize.y = realSize.y;
        break;
    case eHTR_HIT_RIGHT_CENTER:
        if(anchor.x < 1.f)
            newRealSize.x = x / (1 - anchor.x);
        newRealSize.y = realSize.y;
        break;
    case eHTR_HIT_BOTTOM_LEFT:
        if(anchor.x > 0.f)
            newRealSize.x = - x / anchor.x;
        if(anchor.y < 1.f)
            newRealSize.y = y / (1 - anchor.y);
        break;
    case  eHTR_HIT_BOTTOM_CENTER:
        newRealSize.x = realSize.x;
        if(anchor.y < 1.f)
            newRealSize.y = y / (1 - anchor.y);
        break;
    case eHTR_HIT_BOTTOM_RIGHT:
        if(anchor.x < 1.f)
            newRealSize.x = x / (1 - anchor.x);
        if(anchor.y < 1.f)
            newRealSize.y = y / (1 - anchor.y);
        break;
    default:
        BEATS_ASSERT(false);
    }

    CVec2 newSize = newRealSize;
    CNode* pParent = GetParentNode();
    if( pParent && pParent->GetType() == eNT_NodeGUI )
    {
        CVec2 realSizePercentPart = m_vecRealSize - m_vec2Size;
        newSize = newRealSize - realSizePercentPart;
    }
    return newSize;
}
CFormulaNode* CLineNode::InsertMMLFormulaNode_MTABLE( AST_TXML_Tag *node )
{
	FXmlBtn *ptrFXmlBtn = 0;
	long _toolbar_no = -1, _button_no = -1, cb = 0;
	CFormulaNode *new_node = 0;
	CFrameNode *pFrameNode = 0;
	//CLineNode *parent_line = 0;
	CNode *pCurNode = 0;

	std::vector<long> line_length;
	AST_TXML_Compound *stmt = 0;

	if( ::mml_is_table_tag_correct( node, line_length ) )
	{
		long i, j, nColumn = 0, nRow = (long) line_length.size();
		for( i = 0; i < nRow; i++ )
			if( line_length[ i ] > nColumn ) nColumn = line_length[ i ];
		if( nRow <= 0 && nColumn <= 0 )
			return 0; // error: Internal error

		if( ::getCurrentToolBarSet()->getButtonCoordByID( QString(HF_BTNID_DEFAULT_TABLE_ASK_X_ASK), _toolbar_no, _button_no ) == -1 )
			return 0; // error: Error encountered: HF table formula is absent
		ptrFXmlBtn = ::getCurrentToolBarSet()->getButtonCalc( _toolbar_no, _button_no );
		if( !ptrFXmlBtn )
			return 0; // error: Internal error
		if( ptrFXmlBtn->getNodeType() != NODE_FORMULA )
			return 0; // error: Error encountered: HF table formula has a wrong format
		if( ptrFXmlBtn->isPropertyInput( FBL_ATTR_rows ) )
			ptrFXmlBtn->setRows( nRow );
		if( ptrFXmlBtn->isPropertyInput( FBL_ATTR_columns ) )
			ptrFXmlBtn->setColumns( nColumn );
		new_node = CreateFormulaNode( *ptrFXmlBtn );
		if( !new_node || new_node->GetChildCount() != nRow * nColumn )
			return 0; // error: Internal error
		pFrameNode = (CFrameNode*)GetFrameNode();
		if( pFrameNode ) new_node->SetLevel( pFrameNode->GetLevel() );

		// read attributes
		InsertMMLFormulaNode_MTABLE_readAttr( node, new_node );

		AddChild( new_node );
		pCurNode = new_node->GetFirstChild();
		cb = 0;
		for( i = 0; i < nRow; i++ )
		{
			for( j = 0; j < nColumn; j++ )
			{
				if( !pCurNode ) return 0; // error: Internal error
				if( pCurNode->GetType() == NODE_FRAME )
				{
					stmt = mml_get_table_tag_cell( node, i, j );
					pCurNode->read_mathml( stmt );
					if( ((CFrameNode*)pCurNode)->GetChildCount() > 1 &&
						((CFrameNode*)pCurNode)->GetFirstChild() )
						((CFrameNode*)pCurNode)->DeleteChild( ((CFrameNode*)pCurNode)->GetFirstChild() );
				}
				pCurNode = pCurNode->GetNext();
			}
		}
	}
	return new_node;
}
CNode* CFormulaNode::getSingleFormulaChild( long frame_idx )
{
	CNode *node = getSingleChild( frame_idx );
	if( node && node->GetType() == NODE_FORMULA ) return node;
	return 0;
}
CPlaneText* CFormulaNode::getSingleTextChild()
{
	CNode *node = getSingleChild();
	if( node && node->GetType() == NODE_PLANETEXT ) return (CPlaneText*) node;
	return 0;
}
CFormulaNode* CLineNode::InsertMML_CM_apply__list( CCM_apply_args& _args )
{
	MMLContent_TT_mrow setitem2insert;
	CFormulaNode *_node = InsertMMLFormulaNode( setitem2insert.getRoot() );
	if( !_node ) return _node;
	CLineNode *_line1 = _node->getFormulaLineChild( 0 );
	if( !_line1 ) return _node;

	CNode *childNode = _args.l2do[ 0 ]->GetChild( 0 );
	bool bNeedWrap = childNode ? (::_CM_getPrecedence( childNode ) > mmlPrecedence_Atom) : false;
	if( bNeedWrap && childNode && childNode->GetType() == NODE_FORMULA && 
		childNode->to_mathml_data.is_content && ::mml_is_cm_apply( childNode->to_mathml_data.name ) )
	{
		if( !shouldBracket4Apply( ((CFormulaNode*) childNode)->getCalcButtonID(), -1 ) )
			bNeedWrap = false;
	}

	if( _args.form == __APPLY_RENDER_FORM_OP || !_args.l2do[ 0 ] || 
		_args.l2do[ 0 ]->GetChild( 0 ) == 0 )
		_line1->InsertMML_CM_apply__read_op( _args._h_node, _args._h_str, 0, _args.form );
	else if( bNeedWrap )
	{
		CLineNode *headLine = 0;
		if( _args.l2do[ 0 ] )
		{
			CFormulaNode *_f = _line1->InsertMMLFormulaNode( setitem2insert.getRoot() );
			Q_ASSERT( _f );
			if( _f )
			{
				_f->setAutodetectContent();
				_f->to_mathml_data.name = _T("");
				headLine = _f->getFormulaLineChild( 0 );
			}
		}
		if( headLine == 0 ) headLine = _line1;

		headLine->InsertMML_CM_apply__read_op( _args.l2do[ 0 ], _args._h_str, 0, _args.form );
		if( headLine->GetChildCount() == 1 && headLine->GetFirstChild() && headLine->GetFirstChild()->GetType() == NODE_FORMULA )
		{
			CFormulaNode *bracketsFormulaNode = (CFormulaNode*) headLine->GetFirstChild();
			CLineNode *bracketed_line = bracketsFormulaNode ? bracketsFormulaNode->CM_WrapIntoBracketsOnPrecedence( mmlPrecedence_Atom, 0, bNeedWrap, -1 ) : 0;
			if( bracketed_line )
				headLine->InsertMML_CM_remove_outof_brackets( bracketed_line );
		}
	}
	else
		_line1->InsertMML_CM_apply__read_op( _args._h_node, _args._h_str, 0, _args.form );

	CLineNode *_line2 = 0;
	if( _args.form == __APPLY_RENDER_FORM_FENCED_FUN )
	{
		CFormulaNode *_node2 = _line1->InsertMMLFormulaNode( setitem2insert.getRoot() );
		if( !_node2 ) return _node;
		_node2->to_mathml_data.name = _T("");
		_node2->to_mathml_data.is_content = CONTENT_MATHML_CONVERTION2__RECURSIVE_TREE;
		_node2->iterateNodeTree( setRecursiveReadOnly_n_IgnoreContent, 0 );
		_node2->clearIgnoreContentConversion();
		_line1->setReadOnly();
		_line2 = _node2->getFormulaLineChild( 0 );
		if( !_line2 ) return _node;	// internal error
	}
	else
		_line2 = _line1;

	setitem2insert.reset();
	
	_line2->InsertMML_CM_apply__read_op( _args._l_node, _args._l_str, 0, _args.form );

	long k;
	for( k = 1; k < (long) _args.l2do.size(); k++ )
	{
		if( _args.op_id != TAG2MML_factorial || _args.form != __APPLY_RENDER_FORM_OP )
		{
			if( k - 1 || (_args.arity == 1 && _args.form == __APPLY_RENDER_FORM_OP) )
			{
				if( _args.arity < 0 || k - 1 < _args.arity )
				{
					int readonly = (_args.form == __APPLY_RENDER_FORM_OP && k > 2 );
					_line2->InsertMML_CM_apply__read_op( _args._c_node, _args._c_str, readonly, _args.form );
				}
			}
		}
		InsertMML_CM_apply__read_arg( _line2, k, _args );
	}

	if( _args.arity >= 0 && (long) (_args.l2do.size() - 1) < _args.arity )
	{
		CFormulaNode *_row = 0;
		for( ; k < _args.arity; k++ )
		{
			if( k - 1 )
			{
				int readonly = (_args.form == __APPLY_RENDER_FORM_OP && k > 2 );
				_line2->InsertMML_CM_apply__read_op( _args._c_node, _args._c_str, readonly, _args.form );
			}
			_row = _line2->InsertMMLFormulaNode( setitem2insert.getRoot() );
			if( _row )
			{
				_row->to_mathml_data.name = _T("");
				_row->to_mathml_data.is_content = CONTENT_MATHML_CONVERTION2__RECURSIVE_TREE;
			}
		}
	}

	if( _args.op_id == TAG2MML_factorial && _args.form == __APPLY_RENDER_FORM_OP )
		_line2->InsertMML_CM_apply__read_op( _args._c_node, _args._c_str, 0, _args.form );

	_line2->InsertMML_CM_apply__read_op( _args._r_node, _args._r_str, 0, _args.form );

	return _node;
}
void CFormulaNode::RecalculateSize( int bRecalc )
{
	SizeFde sz( 0, 0 );
	int i = 0;

	sz = CFormulaExCalc::RecalculateSize( this );
	if( (i = RecalculateGrph( this, regetActiveCalc() )) != 0 )
	{
		sz = CFormulaExCalc::RecalculateSize( this );
		i = RecalculateGrph( this, regetActiveCalc() );
	}
	if( isHiddenNDisabled() )
	{
		sz.rwidth() = 0;
		if( GetParent() && GetParent()->GetSize().height() > 0 )
			sz.rheight() = GetParent()->GetSize().height();
		else
			sz.rheight() = GetDefaultSize().height();
	}
	Recalculate_VerticalCenter( sz );

	//=== 'mpadded' MathML element
	if( !isHiddenNDisabled() &&
		getAlignmentType() == FBtnChildPos::MSPACE_Exact_HeightDepth )
	{
		RealFde newValues[ MML_MPADDED_UNITS_LEN ] = { 0.0, 0.0, 0.0, 0.0 };
		RealFde childValues[ MML_MPADDED_UNITS_LEN ] = { 0.0, 0.0, 0.0, 0.0 };
		int iRet[ MML_MPADDED_UNITS_LEN ] = { -1, -1, -1, -1 };
		getChildDimensions_Vertical( childValues );
		getChildDimensions_Horizontal( childValues );

		getMathMLAttr().parseMPaddedAttr( newValues, childValues, iRet, ::getCurrentFormulatorStyle().getUnit2PX() );

		RealFde paddedLSpace = 0.0, paddedRSpace = 0.0;
		if( iRet[ MML_MPADDED_UNITS_LSPACE ] == 0 )
		{
			paddedLSpace = newValues[ MML_MPADDED_UNITS_LSPACE ];
		}
		if( iRet[ MML_MPADDED_UNITS_WIDTH ] == 0 )
		{
			RealFde width = newValues[ MML_MPADDED_UNITS_WIDTH ];
			RealFde delta = width - (paddedLSpace + childValues[ MML_MPADDED_UNITS_WIDTH ]);
			if( delta >= 0.0 )
				paddedRSpace = delta;
			else
			{
				paddedLSpace = width - childValues[ MML_MPADDED_UNITS_WIDTH ];
				if( paddedLSpace < 0.0 )
				{
					sz.rwidth() = width;
					paddedLSpace = 0.0;
				}
			}
		}

		RealFde paddedTSpace = 0.0, paddedBSpace = 0.0;
		if( iRet[ MML_MPADDED_UNITS_HEIGHT ] == 0 )
		{
			RealFde height = newValues[ MML_MPADDED_UNITS_HEIGHT ];
			RealFde delta = height - childValues[ MML_MPADDED_UNITS_HEIGHT ];
			if( delta >= 0 )
				paddedTSpace = delta;
			else
			{
				// not feasible 
			}
		}
		if( iRet[ MML_MPADDED_UNITS_DEPTH ] == 0 )
		{
			RealFde delta = newValues[ MML_MPADDED_UNITS_DEPTH ] - childValues[ MML_MPADDED_UNITS_DEPTH ];
			if( delta >= 0 )
				paddedBSpace = delta;
			else
			{
				// not feasible 
			}
		}

		if( paddedLSpace || paddedRSpace || paddedTSpace || paddedBSpace )
		{
			CNode *pNode = GetFirstChild();
			if( pNode && pNode->GetType() == NODE_FRAME )
			{
				CFrameNode *n1st = (CFrameNode*)pNode;
				n1st->setLeftIndent( paddedLSpace );
				n1st->setRightIndent( paddedRSpace );
				n1st->setTopIndent( paddedTSpace );
				n1st->setBottomIndent( paddedBSpace );
			}
		}
	}

	if( sz != GetSize() || i )
		SetSize( sz );

	if( bRecalc )
		GetParent()->RecalculateSize( bRecalc );
}
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;
}