Пример #1
0
double GetDlgItemAngle(UI::Control * hWnd, UINT nID, bool* bTrans)
{
	WCHAR buf[64];
	ASSERT(0);
#if 0
	GetDlgItemText(hWnd, nID, buf, sizeof(buf));
#endif

	if (bTrans) *bTrans = true;

	return getfnumber(buf);
}
Пример #2
0
int GetTransformValuesArray(const WCHAR* str, vector<double>& values)
{
//	int len = str.GetLength();
	const WCHAR* p = str;

	while (*p && isspace(*p)) p++;	// Skip spaces

	//int i = 0;
	while (*p)
	{
		double value = getfnumber(&p);
		if (p == NULL)
		{
			values.RemoveAll();	// On error, make all values parsed so far invalid?
			return 0;
		}

			/*
		CWCharString str_value;
		while (*p && (*p != ',') && (*p != ' '))
		{
			str_value += *p;
			p++;
		}

		while (i < len && p[i] == ' ') i++;	// Skip spaces
		*/

		if (*p == L',') p++;

		//str_value.TrimRight();
		//str_value.TrimRight();

		//double value = atof(str_value);
		values.Add(value);

		while (*p && isspace(*p)) p++;	// Skip spaces
	}

	return values.GetSize();
}
Пример #3
0
ErrorCode ParseRGBAColor(/*[in]*/ const WCHAR* p, /*[out]*/ const WCHAR** pp, /*[out,retval]*/ Graphics::Color* pVal)
{
	if ((p[0] == 'r') && (p[1] == 'g') && (p[2] == 'b') && (p[3] == 'a'))
	{
		p += 4;

		while (*p && *p == L' ') p++;	// Skip spaces

		if (*p++ != L'(') return -1;	// Error

		while (*p && *p == L' ') p++;	// Skip spaces
		double red = getfnumber(&p);
		if (p == NULL) return -1;
		if (*p == L'%')
		{
			p++;
			red = red * 255 / 100;
		}
		while (*p && *p == L' ') p++;	// Skip spaces
		if (*p++ != L',') return -1;

		while (*p && *p == L' ') p++;	// Skip spaces
		double green = getfnumber(&p);
		if (p == NULL) return -1;
		if (*p == L'%')
		{
			p++;
			green = green * 255 / 100;
		}

		while (*p && *p == L' ') p++;	// Skip spaces
		if (*p++ != L',') return -1;

		while (*p && *p == L' ') p++;	// Skip spaces
		double blue = getfnumber(&p);
		if (p == NULL) return -1;
		if (*p == L'%')
		{
			p++;
			blue = blue * 255 / 100;
		}

		while (*p && *p == L' ') p++;	// Skip spaces
		if (*p++ != L',') return -1;

		while (*p && *p == L' ') p++;	// Skip spaces
		double alpha = getfnumber(&p);
		if (p == NULL) return -1;

		alpha *= 255;

		while (*p && *p == L' ') p++;	// Skip spaces

		if (*p++ != L')') return -1;	// Error

		*pp = p;

		if (red < 0) red = 0;
		else if (red > 255) red = 255;

		if (green < 0) green = 0;
		else if (green > 255) green = 255;

		if (blue < 0) blue = 0;
		else if (blue > 255) blue = 255;

		if (alpha < 0) alpha = 0;
		else if (alpha > 255) alpha = 255;

		*pVal = Graphics::Color((uint8)alpha, (uint8)red, (uint8)green, (uint8)blue);
		return 0;
	}
	else
	{
		return ParseRGBColor(p, pp, pVal);
	}
}
Пример #4
0
ErrorCode ParseRGBColor(/*[in]*/ const WCHAR* p, /*[out]*/ const WCHAR** pp, /*[out,retval]*/ Graphics::Color* pVal)
{
	ASSERT(pVal != NULL);
	ASSERT(pp != NULL);
	*pp = NULL;

	if (*p == '#')
	{
		p++;

		const WCHAR* s = p;
		while (*p && isxdigit(*p))
		{
			p++;
		}

		if (p-s == 3)
		{
			*pp = p;

			*pVal = Graphics::Color(255,
							(Hex2Number(s[0])<<4) | Hex2Number(s[0]),
							(Hex2Number(s[1])<<4) | Hex2Number(s[1]),
							(Hex2Number(s[2])<<4) | Hex2Number(s[2]));

			return 0;
		}
		else if (p-s == 6)
		{
			*pp = p;

			*pVal = Graphics::Color(255,
							(Hex2Number(s[0])<<4) | Hex2Number(s[1]),
							(Hex2Number(s[2])<<4) | Hex2Number(s[3]),
							(Hex2Number(s[4])<<4) | Hex2Number(s[5]));

			return 0;
		}
	}
	else if ((p[0] == 'r') && (p[1] == 'g') && (p[2] == 'b'))
	{
		p += 3;

		while (*p && *p == L' ') p++;	// Skip spaces

		if (*p++ != L'(') return -1;	// Error

		while (*p && *p == L' ') p++;	// Skip spaces
		double red = getfnumber(&p);
		if (p == NULL) return -1;
		if (*p == L'%')
		{
			p++;
			red = red * 255 / 100;
		}
		while (*p && *p == L' ') p++;	// Skip spaces
		if (*p++ != L',') return -1;

		while (*p && *p == L' ') p++;	// Skip spaces
		double green = getfnumber(&p);
		if (p == NULL) return -1;
		if (*p == L'%')
		{
			p++;
			green = green * 255 / 100;
		}

		while (*p && *p == L' ') p++;	// Skip spaces
		if (*p++ != L',') return -1;

		while (*p && *p == L' ') p++;	// Skip spaces
		double blue = getfnumber(&p);
		if (p == NULL) return -1;
		if (*p == L'%')
		{
			p++;
			blue = blue * 255 / 100;
		}

		while (*p && *p == L' ') p++;	// Skip spaces

		if (*p++ != L')') return -1;	// Error

		*pp = p;

		if (red < 0) red = 0;
		else if (red > 255) red = 255;

		if (green < 0) green = 0;
		else if (green > 255) green = 255;

		if (blue < 0) blue = 0;
		else if (blue > 255) blue = 255;

		*pVal = Graphics::Color(255, (uint8)red, (uint8)green, (uint8)blue);
		return 0;
	}
	else	// Named color
	{
		// TODO, smarter search given that array is sorted
		// TODO, make one array only
		int i = 0;

		ASSERT(0);
#if 0
		while (i < ColorNames_length)
		{
		//	int len = wcslen(ColorNames[i].name);

			if (ColorNames[i].get_Name() == p, len))
			{
				*pp = p + len;
				*pVal = ColorNames[i].clr | 0xff000000;
				return 0;
			}

			++i;
		}

		i = 0;
		while (SystemColors[i].name)
		{
			int len = wcslen(SystemColors[i].name);

			if (!wcsncmp(SystemColors[i].name, p, len))
			{
				*pp = p + len;
				*pVal = SystemColors[i].clr | 0xff000000;
				return 0;
			}

			i++;
		}
#endif
	}

	return -1;
}