Exemplo n.º 1
0
void CAniTextInput::Paint (SAniPaintCtx &Ctx)

//	Paint
//
//	Paints

	{
	//	Get the font for the input

	const CG16bitFont *pFont = m_Properties[INDEX_FONT].GetFont();
	if (pFont == NULL)
		return;

	//	Get the font for the label

	const CG16bitFont *pLabelFont = m_Properties[INDEX_LABEL_FONT].GetFont();

	//	Enabled?

	bool bEnabled = m_Properties[INDEX_ENABLED].GetBool();

	//	Get position and size

	CVector vPos = m_Properties[INDEX_POSITION].GetVector();
	CVector vSize = m_Properties[INDEX_SCALE].GetVector();
	CVector vPosTrans = Ctx.ToDest.Transform(vPos);
	CVector vPosTrans2 = Ctx.ToDest.Transform(vPos + vSize);
	CVector vSizeTrans = vPosTrans2 - vPosTrans;

	//	The field (including the label starts here)

	int x = (int)vPosTrans.GetX();
	int y = (int)vPosTrans.GetY();

	//	Figure out the position of the label

	int xLabel = x;
	int yLabel = y;

	//	Figure out the position of the input field frame

	int xField = x;
	int yField = yLabel + LABEL_PADDING + (pLabelFont ? pLabelFont->GetHeight() : 0);

	//	Figure out the position of the text within the input field

	int xText = xField + PADDING_LEFT;
	int yText = yField + PADDING_TOP;

	int cxText = 0;
	int cyText = pFont->GetHeight();

	//	Now compute the size of the input field frame

	int cxField = (int)vSizeTrans.GetX();
	int cyField = cyText + PADDING_TOP + PADDING_BOTTOM;

	//	Get color & opacity

	CG32bitPixel rgbColor = m_Properties[INDEX_COLOR].GetColor();
	DWORD dwOpacity = m_Properties[INDEX_OPACITY].GetOpacity() * Ctx.dwOpacityToDest / 255;
	if (!bEnabled)
		dwOpacity = dwOpacity / 2;

	//	Paint the label

	CString sLabel = m_Properties[INDEX_LABEL_TEXT].GetString();
	if (pLabelFont && !sLabel.IsBlank())
		{
		pLabelFont->DrawText(Ctx.Dest, 
				xLabel, 
				yLabel,
				CG32bitPixel(m_Properties[INDEX_LABEL_COLOR].GetColor(), (BYTE)dwOpacity),
				sLabel, 
				0);
		}

	//	Paint the background

	EStyleParts iStyle;
	if (!bEnabled)
		iStyle = styleFrameDisabled;
	else if (m_bFocus)
		iStyle = styleFrameFocus;
	else
		iStyle = styleFrame;

	//	Paint the button shape

	IAnimatron *pFrameStyle = GetStyle(iStyle);
	if (pFrameStyle)
		{
		pFrameStyle->SetPropertyVector(PROP_POSITION, CVector(vPos.GetX(), vPos.GetY() + yField - y));
		pFrameStyle->SetPropertyVector(PROP_SCALE, CVector(cxField, cyField));
		pFrameStyle->Paint(Ctx);
		}

	//	Get the text

	CString sText;
	if (m_bPassword)
		sText = strRepeat(CONSTLIT("•"), m_Properties[INDEX_TEXT].GetString().GetLength());
	else
		sText = m_Properties[INDEX_TEXT].GetString();

	//	Draw

	int xPos;
	pFont->DrawText(Ctx.Dest, 
			xText, 
			yText,
			CG32bitPixel(rgbColor, (BYTE)dwOpacity),
			sText, 
			0,
			&xPos);

	//	Draw state if we have the focus

	if (m_bFocus && bEnabled)
		{
		CG32bitPixel rgbFocusColor = m_Properties[INDEX_FOCUS_BORDER_COLOR].GetColor();
		Ctx.Dest.Fill(xField, yField, FOCUS_BRACKET_WIDTH, FOCUS_BRACKET_THICKNESS, rgbFocusColor);
		Ctx.Dest.Fill(xField, yField, FOCUS_BRACKET_THICKNESS, cyField, rgbFocusColor);
		Ctx.Dest.Fill(xField, yField + cyField - FOCUS_BRACKET_THICKNESS, FOCUS_BRACKET_WIDTH, FOCUS_BRACKET_THICKNESS, rgbFocusColor);

		Ctx.Dest.Fill(xField + cxField - FOCUS_BRACKET_WIDTH, yField, FOCUS_BRACKET_WIDTH, FOCUS_BRACKET_THICKNESS, rgbFocusColor);
		Ctx.Dest.Fill(xField + cxField - FOCUS_BRACKET_THICKNESS, yField, FOCUS_BRACKET_THICKNESS, cyField, rgbFocusColor);
		Ctx.Dest.Fill(xField + cxField - FOCUS_BRACKET_WIDTH, yField + cyField - FOCUS_BRACKET_THICKNESS, FOCUS_BRACKET_WIDTH, FOCUS_BRACKET_THICKNESS, rgbFocusColor);

#if 0
		DrawRectDotted(Ctx.Dest, 
				xField, 
				yField, 
				cxField, 
				cyField, 
				m_Properties[INDEX_FOCUS_BORDER_COLOR].GetColor());
#endif

		//	Paint cursor

		if ((Ctx.iFrame / CURSOR_BLINK_RATE) % 2)
			Ctx.Dest.Fill(xPos, yText, CURSOR_WIDTH, cyText, rgbColor);
		}
	}
Exemplo n.º 2
0
void GenerateEntitiesTable (const CString &sDataFile, CXMLElement *pCmdLine)
	{
	int i;
	ALERROR error;

	CString sSourceFile;
	if (!pCmdLine->FindAttribute(FILE_ATTRIB, &sSourceFile))
		{
		printf("Specify file\n");
		return;
		}

	//	Open the data file and parse all entities

	CSymbolTable Entities(FALSE, TRUE);
	CFileReadBlock DataFile(CONSTLIT("Transcendence.xml"));

	if (error = DataFile.Open())
		{
		printf("Unable to open Transcendence.xml\n");
		return;
		}

	char *pPos = DataFile.GetPointer(0, -1);
	char *pEnd = pPos + DataFile.GetLength();

	//	Look for "<!ENTITY"

	CString sName;
	DWORD dwValue;
	while (NextEntity(&pPos, pEnd, &sName, &dwValue))
		Entities.AddEntry(sName, (CObject *)dwValue);

	DataFile.Close();

	//	Open the source file and look for all entity references

	CFileReadBlock SourceFile(sSourceFile);
	if (error = SourceFile.Open())
		{
		printf("Unable to open %s\n", sSourceFile.GetASCIIZPointer());
		return;
		}

	pPos = SourceFile.GetPointer(0, -1);
	pEnd = pPos + SourceFile.GetLength();

	//	Look for entity references

	CSymbolTable Output(TRUE, TRUE);
	while (NextEntityReference(&pPos, pEnd, &sName))
		{
		//	Look for this entity

		DWORD dwValue;
		if (Entities.Lookup(sName, (CObject **)&dwValue) == NOERROR)
			{
			//	Start with the entity keyword

			CString sOutput = strPatternSubst(CONSTLIT("\t<!ENTITY %s"), sName);

			//	Add tabs

			int iTabs = (40 - (sOutput.GetLength() + 3) + 3) / 4;
			if (iTabs)
				sOutput.Append(strRepeat(CONSTLIT("\t"), iTabs));
			else
				sOutput.Append(CONSTLIT(" "));

			//	Add the value

			char szBuffer[1024];
			wsprintf(szBuffer, "\"0x%08X\">\n", dwValue);
			sOutput.Append(CString(szBuffer));

			//	Output to the table (in UNID order)

			Output.AddEntry(CString(szBuffer), new CString(sOutput));
			}
		}

	SourceFile.Close();

	//	Output table

	for (i = 0; i < Output.GetCount(); i++)
		{
		CString *pLine = (CString *)Output.GetValue(i);
		printf(pLine->GetASCIIZPointer());
		}
	}