Ejemplo n.º 1
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
Color CBaseHudChat::GetTextColorForClient( TextColor colorNum, int clientIndex )
{
	Color c;
	switch ( colorNum )
	{
	case COLOR_PLAYERNAME:
		c = GetClientColor( clientIndex );
	break;

	case COLOR_LOCATION:
		c = g_ColorDarkGreen;
		break;

	case COLOR_ACHIEVEMENT:
		{
			vgui::IScheme *pSourceScheme = vgui::scheme()->GetIScheme( vgui::scheme()->GetScheme( "SourceScheme" ) ); 
			if ( pSourceScheme )
			{
				c = pSourceScheme->GetColor( "SteamLightGreen", GetBgColor() );
			}
			else
			{
				c = GetDefaultTextColor();
			}
		}
		break;

	default:
		c = GetDefaultTextColor();
	}

	return Color( c[0], c[1], c[2], 255 );
}
Ejemplo n.º 2
0
void CSynBCGPEditCtrl::OnGetCharColor( TCHAR ch, int nOffset, COLORREF& clrText, COLORREF& clrBk )
{
	if (m_SynLanguage.GetCurLanguage() == SYN_INI)
	{
		if (ch == _T ('='))
		{
			clrText = m_clrSyn;
		}
	}
	if (m_bCheckColorTags)
	{

		TCHAR chOpen = _T ('<');
		TCHAR chClose = _T ('>');

		if (ch == chOpen || ch == chClose || ch == _T ('/'))
		{
			clrText = m_clrSyn;
		}
		else 
		{
			COLORREF clrDefaultBack = GetDefaultBackColor ();
			COLORREF clrDefaultTxt = GetDefaultTextColor ();
			int nBlockStart, nBlockEnd;
			if (!IsInBlock (nOffset, chOpen, chClose, nBlockStart, nBlockEnd))
			{
				clrText = clrDefaultTxt;
				clrBk = clrDefaultBack;
			}
			/*else if (GetCharAt (nBlockStart + 1) == _T ('%') && 
				GetCharAt (nBlockEnd - 1) == _T ('%'))
			{
				
			}*/
			else if (clrText == clrDefaultTxt && m_SynLanguage.GetCurLanguage() == SYN_XML)
			{
				if (ch == _T ('='))
				{
					//clrText = RGB (0, 0, 255);
				}
				else
				{
					clrText = m_clrSyn;
				}
			}
		}
	}
}
Ejemplo n.º 3
0
void CSynBCGPEditCtrl::ExportToMyHTML( CString& strHTML )
{
	g_uHtmlPos = 0;
	int nStartOffset = 0; 
	int nEndOffset = m_strBuffer.GetLength () - 1;

	COLORREF clrDefaultText = GetDefaultTextColor ();
	COLORREF clrDefaultBack = GetDefaultBackColor ();

	COLORREF clrNextWordFore	= clrDefaultText;
	COLORREF clrNextWordBk		= clrDefaultBack;

	COLORREF clrOutText = clrDefaultText;
	COLORREF clrOutBack = clrDefaultBack;

	// ----------------------------------------------
	// Build color areas for visible part of a buffer (comments, strings and so on):
	// ----------------------------------------------
	BCGP_EDIT_COLOR_BLOCK	clrBlock; 
	BOOL bIsOpenBlock = FindOpenBlock (nStartOffset, &clrBlock);

	int nCloseBlockOffset = -1;
	if (bIsOpenBlock)
	{
		nCloseBlockOffset = FindCloseBlock (nStartOffset, &clrBlock);
	}

	COLORREF clrBlockFore = (clrBlock.m_clrForeground == -1) ? GetDefaultTextColor () : clrBlock.m_clrForeground;
	COLORREF clrBlockBack = (clrBlock.m_clrBackground == -1) ? GetDefaultBackColor () : clrBlock.m_clrBackground; 

	CList <BCGP_EDIT_COLOR_AREA, BCGP_EDIT_COLOR_AREA&> colorAreas;

	if (bIsOpenBlock) 
	{
		if (nCloseBlockOffset < nEndOffset)
		{
			BuildColorAreas (colorAreas, nCloseBlockOffset, nEndOffset, NULL, FALSE);
		}
	}
	else
	{
		BuildColorAreas (colorAreas, nStartOffset, nEndOffset, NULL, FALSE);
	}

	// ---------------------------------------------
	// Draw the text for the visible part of buffer:
	// ---------------------------------------------
	TCHAR* lpszOutBuffer = (TCHAR*) alloca (sizeof (TCHAR) * m_nMaxScrollWidth);
	memset (lpszOutBuffer, 0, sizeof (TCHAR) * m_nMaxScrollWidth);
	int iIdx = 0;

	int nNextDelimiter = -1;
	int nCurrRow = 0;
	int nCurrColumn = 0;

	for (int i = nStartOffset; i <= nEndOffset; i++)
	{
		COLORREF clrForeground = clrDefaultText;
		COLORREF clrBackground = clrDefaultBack;

		TCHAR chNext = m_strBuffer [i];

		// --------------
		// Define colors:
		// --------------
		BOOL bColorFound = FALSE;

		// 1) ignore selection
		// 2) ignore colored line markers

		// 3) check for color blocks:
		if (bIsOpenBlock && i < nCloseBlockOffset)
		{
			clrForeground = clrBlockFore;
			clrBackground = clrBlockBack;
			bColorFound = TRUE;
		}
		else
		{
			// check all color areas (comments, strings and so on)
			for (POSITION pos = colorAreas.GetHeadPosition (); pos != NULL;)
			{
				BCGP_EDIT_COLOR_AREA colorArea = colorAreas.GetNext (pos);
				if (i >= colorArea.m_nStart && i <= colorArea.m_nEnd)
				{
					clrForeground = colorArea.m_clrForeground; 
					clrBackground = colorArea.m_clrBackground;

					if (clrForeground == -1)
					{
						clrForeground = clrDefaultText;
					}

					if (clrBackground == -1)
					{
						clrBackground = clrDefaultBack;
					}

					bColorFound = TRUE;
					break;
				}
			}
		}

		// 4) User can define text color by own:
		if (OnGetTextColor (i, nNextDelimiter, clrForeground, clrBackground, bColorFound))
		{
			bColorFound = TRUE;
		}

		// 5) Check all color words (keywords and words):
		if (chNext != g_chEOL)
		{
			if (nNextDelimiter == -1) 
			{
				CString strNextWord;		

				for (int iIdx = i; iIdx <= nEndOffset; iIdx++)
				{
					TCHAR ch = m_strBuffer [iIdx];
					if (m_strWordDelimeters.Find (ch) != -1)
					{
						nNextDelimiter = iIdx;
						break;
					}
				}

				if (nNextDelimiter == -1)
				{
					nNextDelimiter = nEndOffset + 1;
				}

				if (nNextDelimiter != -1)
				{
					strNextWord = 
						m_strBuffer.Mid (i, nNextDelimiter - i);
				}

				if (!OnGetWordColor (strNextWord, clrNextWordFore, clrNextWordBk, i))
				{
					clrNextWordFore = clrDefaultText;
					clrNextWordBk = clrDefaultBack;
				}
			}

			if (i >= nNextDelimiter - 1)
			{
				nNextDelimiter = -1;
			}

			if (!bColorFound)
			{
				clrForeground = clrNextWordFore;
				clrBackground = clrNextWordBk;
			}
		}

		// 6) ignore hilited text

		// 7) User can define color of current char:
		if (!bColorFound)
		{
			OnGetCharColor (chNext, i, clrForeground, clrBackground);
		}

		// -----------------------------------
		// Proceed end of same color fragment:
		// -----------------------------------

		if (clrForeground != clrOutText || clrBackground != clrOutBack)
		{ 
			clrOutText = clrForeground;
			clrOutBack = clrBackground;

			if (iIdx != 0)
			{
				CString strLine (lpszOutBuffer);
				OnPrepareHTMLString (strLine);
				strHTML += strLine;

				iIdx = 0;
				memset (lpszOutBuffer, 0, sizeof (TCHAR) * m_nMaxScrollWidth);
			}

			strHTML += ColorMyTag (clrOutText);
		}

		// --------------------
		// Proceed end of line:
		// --------------------
		if (chNext == g_chEOL)
		{
			{
				CString strLine (lpszOutBuffer);
				OnPrepareHTMLString (strLine);
				strLine += _T("<BR>");
				strLine += g_chEOL;
				strHTML += strLine;

				iIdx = 0;
				memset (lpszOutBuffer, 0, sizeof (TCHAR) * m_nMaxScrollWidth);
			}

			nCurrRow++;
			nCurrColumn = 0;
			continue;
		}

		// -------------
		// Replace Tabs:
		// -------------
		if (chNext == _T('\t'))
		{
			int nRestOfTab = m_nTabSize - nCurrColumn % m_nTabSize;
			nCurrColumn += nRestOfTab;

			for (int k = 0; k < nRestOfTab; k++)
			{
				if (iIdx + k + 1 > m_nMaxScrollWidth - 1)
				{
					CString strLine (lpszOutBuffer);
					OnPrepareHTMLString (strLine);
					strHTML += strLine;

					iIdx = 0;
					memset (lpszOutBuffer, 0, sizeof (TCHAR) * m_nMaxScrollWidth);
				}

				lpszOutBuffer [iIdx] = _T(' ');
				lpszOutBuffer [iIdx + 1] = _T ('\0');
				iIdx ++;
			}
		}

		else
		{
			nCurrColumn++;

			if (iIdx + 1 > m_nMaxScrollWidth - 1)
			{
				CString strLine (lpszOutBuffer);
				OnPrepareHTMLString (strLine);
				strHTML += strLine;

				iIdx = 0;
				memset (lpszOutBuffer, 0, sizeof (TCHAR) * m_nMaxScrollWidth);
			}

			lpszOutBuffer [iIdx] = chNext;
			lpszOutBuffer [iIdx + 1] = _T ('\0');
			iIdx++;
		}
	}

	// --------------------------
	// Draw the last of the text:
	// --------------------------
	if (iIdx != 0)
	{
		CString strLine (lpszOutBuffer);
		OnPrepareHTMLString (strLine);
		strHTML += strLine;

		iIdx = 0;
		memset (lpszOutBuffer, 0, sizeof (TCHAR) * m_nMaxScrollWidth);
	}
	if (g_uHtmlPos != 0)
	{
		strHTML += _T("</span>");
	}	
}
Ejemplo n.º 4
0
BOOL CSynBCGPEditCtrl::OnGetWordColor( const CString& strWord, COLORREF& clrText, COLORREF& clrBk, int nPos )
{
	BCGP_EDIT_SYNTAX_COLOR clrWord;

	if (strWord.IsEmpty ())
	{
		return FALSE;
	}

	if (!m_mapWordColors.Lookup (strWord, clrWord))
	{
		CString strUpper = strWord; 
		strUpper.MakeUpper ();
		if (!m_mapWordColors.Lookup (strUpper, clrWord))
		{
			if (m_bNumberColor)
			{
				int nLength = strWord.GetLength();
				for (int i = 0; i < nLength; i++)
				{
					if (!_istdigit(strWord[i]))
					{
						return FALSE;
					}
				}
				clrText = m_clrNumber;
				return TRUE;
			} 
			else
			{
				return FALSE;
			}			
		}

		if (!clrWord.m_bCaseSensitive)
		{
			clrText = clrWord.m_clrForeground;
			clrBk = clrWord.m_clrBackground;

			if (clrText == (COLORREF) -1)
			{
				clrText = GetDefaultTextColor ();
			}

			if (clrBk == (COLORREF) -1)
			{	
				clrBk = GetDefaultBackColor ();
			}

			return TRUE;
		}

		return FALSE;
	}

	if (m_mapWordColors.Lookup (strWord, clrWord))
	{
		clrText = clrWord.m_clrForeground;
		clrBk = clrWord.m_clrBackground;

		if (clrText == (COLORREF) -1)
		{
			clrText = GetDefaultTextColor ();
		}

		if (clrBk == (COLORREF) -1)
		{	
			clrBk = GetDefaultBackColor ();
		}

		return TRUE;
	}

	return FALSE;
}