예제 #1
0
// 10进制逗号分隔字符串或16进制字符串转换为Color对象
Color CDuiObject::StringToColor(LPCTSTR lpszValue, Color clrDefault)
{
	CStringA strValue;
	strValue = lpszValue;

	// 字符串为空则返回默认值
	if(strValue.IsEmpty())
	{
		return clrDefault;
	}

	// 没有逗号,则按照10进制处理
	if(strValue.Find(",") == -1)
	{
		return HexStringToColor(lpszValue);
	}

	BYTE c1,c2,c3,c4;
	CStringA s1 = "";
	CStringA s2 = "";
	CStringA s3 = "";
	CStringA s4 = "";
	int nPos = strValue.Find(",");
	if(nPos != -1)
	{
		s1 = strValue.Left(nPos);
		strValue.Delete(0, nPos+1);
		nPos = strValue.Find(",");
		if(nPos != -1)
		{
			s2 = strValue.Left(nPos);
			strValue.Delete(0, nPos+1);
			nPos = strValue.Find(",");
			if(nPos != -1)
			{
				s3 = strValue.Left(nPos);
				strValue.Delete(0, nPos+1);
				s4 = strValue;
			}else
			{
				s3 = strValue;
			}
		}
	}

	c1 = atoi(s1);
	c2 = atoi(s2);
	c3 = atoi(s3);
	c4 = atoi(s4);

	if(s4.IsEmpty())
	{
		return Color(c1, c2, c3);
	}else
	{
		return Color(c1, c2, c3, c4);
	}
}
예제 #2
0
// 加载XML节点
BOOL CSelectBox::Load(TiXmlElement* pXmlElem, BOOL bLoadSubControl)
{
	if(!__super::Load(pXmlElem))
	{
		return FALSE;
	}

    // 使用XML节点初始化控件
	if(pXmlElem != NULL)
	{
		// 加载图片和颜色列表
		TiXmlElement* pControlElem = NULL;
		for (pControlElem = pXmlElem->FirstChildElement("item"); pControlElem != NULL; pControlElem=pControlElem->NextSiblingElement())
		{
			if(pControlElem != NULL)
			{
				CString strImage = CEncodingUtil::AnsiToUnicode(pControlElem->Attribute("image"));
				CStringA strColor = pControlElem->Attribute("color");
				if(!strImage.IsEmpty())
				{
					if(strImage.Find(_T("skin:")) == 0)
					{
						strImage = CEncodingUtil::AnsiToUnicode(DuiSystem::Instance()->GetSkin(CEncodingUtil::UnicodeToAnsi(strImage)));
					}

					if(strImage.Find(_T(".")) != -1)	// 加载图片文件
					{
						CString strImgFile = DuiSystem::GetExePath() + strImage;
						SetBitmap(strImgFile);
					}else	// 加载图片资源
					{
						UINT nResourceID = _wtoi(strImage);
						if(!SetBitmap(nResourceID, -1, TEXT("PNG")))
						{
							SetBitmap(nResourceID, -1, TEXT("BMP"));
						}
					}
					m_bImage = TRUE;
				}else
				if(!strColor.IsEmpty())
				{
					Color color;
					if(strColor.Find(",") == -1)
					{
						color = HexStringToColor(strColor);
					}else
					{
						color = StringToColor(strColor);
					}
					SetColor(color);
				}
			}
		}
	}

    return TRUE;
}
예제 #3
0
		void Parser::applyFormatting(PTextView chunk, TextNode* node)
		{
			if(!node) return;
			if(node->parent)
			{
				applyFormatting(chunk, node->parent);
			}

			if(node->param.empty())
				return;

			switch(node->type)
			{
			case ColorTag:
				chunk->col = HexStringToColor(node->param);
				break;
			case BoldTag:
				chunk->isBold = true;
				break;
			case ItalicTag:
				chunk->isItalic = true;
				break;
			case ImgTag:
				{
					chunk->isImage = true;
					std::string set;
					std::string img;
					splitParams_(node->param, set, img);
					ImagesetPtr is = m_sys.getWindowManager().loadImageset(set);
					if(is) chunk->img = (*is)[img];
				}
				break;
			case UrlTag:
				{
					chunk->isURL = true;
					chunk->urlnode = node;
					std::string id;
					splitParams_(node->param, chunk->type, id);
					chunk->id = (unsigned int)atoi(id.c_str());
				}

				break;
			case TooltipTag:
				chunk->isTooltip = true;
				chunk->tooltipnode = node;
				chunk->tooltip = (unsigned int)atoi(node->param.c_str());
				break;

			case NormalTag:
			case ListTag:
			default:
				break;
			};

		}
예제 #4
0
// 加载XML节点
BOOL CSelectBox::Load(DuiXmlNode pXmlElem, BOOL bLoadSubControl)
{
	if(!__super::Load(pXmlElem))
	{
		return FALSE;
	}

	// 使用XML节点初始化控件
	if(pXmlElem != NULL)
	{
		// 加载图片和颜色列表
		DuiXmlNode pControlElem;
		for (DuiXmlNode pControlElem = pXmlElem.child(_T("item")); pControlElem; pControlElem=pControlElem.next_sibling(_T("item")))
		{
			CString strImage = pControlElem.attribute(_T("image")).value();
			CString strColor = pControlElem.attribute(_T("color")).value();
			if(!strImage.IsEmpty())
			{
				if(strImage.Find(_T("skin:")) == 0)
				{
				}

				if(strImage.Find(_T(".")) != -1)	// 加载图片文件
				{
					CString strImgFile = DuiSystem::GetExePath() + strImage;
					SetBitmap(strImgFile);
				}else	// 加载图片资源
				{
					UINT nResourceID = _wtoi(strImage);
					if(!SetBitmap(nResourceID, -1, TEXT("PNG")))
					{
						SetBitmap(nResourceID, -1, TEXT("BMP"));
					}
				}
				m_bImage = TRUE;
			}else
				if(!strColor.IsEmpty())
				{
					Color color;
					if(strColor.Find(_T(",")) == -1)
					{
						color = HexStringToColor(strColor);
					}else
					{
						color = StringToColor(strColor);
					}
					SetColor(color);
				}
		}
	}

	return TRUE;
}
예제 #5
0
bool KAppRes::LoadColorRes()
{
	bool retval = false;
	void* pBuffer = NULL;
	unsigned long dwBuffer = 0;
	TiXmlDocument xmlDoc;
	const TiXmlElement* pXmlChild = NULL;
	const TiXmlElement* pXmlItem = NULL;

	if (!GetRawDataFromRes("colors.xml", &pBuffer, dwBuffer))
		goto clean0;

	if (!xmlDoc.LoadBuffer((char*)pBuffer, (long)dwBuffer, TIXML_ENCODING_UTF8))
		goto clean0;

	pXmlChild = xmlDoc.FirstChildElement("colors");
	if (!pXmlChild)
		goto clean0;

	pXmlItem = pXmlChild->FirstChildElement("color");
	while (pXmlItem) 
	{
		std::string strId;
		std::string strColor;

		strId = pXmlItem->Attribute("id");
		strColor = pXmlItem->Attribute("value");

		if (strId.length() && strColor.length())
		{
			m_mapColorTable[strId] = HexStringToColor(strColor.c_str());
		}

		pXmlItem = pXmlItem->NextSiblingElement("color");
	}

clean0:
	if (pBuffer)
	{
		FreeRawData(pBuffer);
	}

	return retval;
}