Esempio n. 1
0
void ConsoleLog::writeColored(ConsoleLog::Color color, const char* message)
{
#ifdef OS_WIN
    const HANDLE stdoutHandle = GetStdHandle(STD_OUTPUT_HANDLE);
  
    CONSOLE_SCREEN_BUFFER_INFO bufferInfo;
    GetConsoleScreenBufferInfo(stdoutHandle, &bufferInfo);
    const WORD oldColorAttrs = bufferInfo.wAttributes;
  
    fflush(stdout);
    SetConsoleTextAttribute(stdoutHandle,
                            GetColorAttribute(color) | FOREGROUND_INTENSITY);
    fprintf(stdout, "%s\n", message);
  
    fflush(stdout);
    SetConsoleTextAttribute(stdoutHandle, oldColorAttrs);
#else
    if (!useColor_ || color == ConsoleLog::COLOR_DEFAULT) {
        printf("%s\n", message);
    } else {
        printf("\033[0;3%sm", GetColorAttribute(color));
        printf("%s", message);
        printf("\033[m\n");
    }
#endif
}
Esempio n. 2
0
int BoxWidget::Load(XmlSynthElem *elem)
{
	SynthWidget::Load(elem);
	short w;
	if (elem->GetAttribute("wid", w) == 0)
		thick = w;
	short st;
	if (elem->GetAttribute("style", st) == 0)
		style = st;
	if (elem->GetAttribute("filled", st) == 0)
		filled = st;
	GetColorAttribute(elem, "hiclr", hiClr);
	GetColorAttribute(elem, "loclr", loClr);
	return 0;
}
Esempio n. 3
0
// Windows print colored string to stdout.
void ColoredPrintf(ConsoleColor color, const char* fmt, ...)
{
	va_list args;
	va_start(args, fmt);
//	if (!use_color_)
//	{
//		vprintf(fmt, args);
//		va_end(args);
//		return;
//	}
	const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);
	// Gets the current text color.
	CONSOLE_SCREEN_BUFFER_INFO buffer_info;
	GetConsoleScreenBufferInfo(stdout_handle, &buffer_info);
	const WORD old_color_attrs = buffer_info.wAttributes;
	// We need to flush the stream buffers into the console before each
	// SetConsoleTextAttribute call lest it affect the text that is already
	// printed but has not yet reached the console.
	fflush(stdout);
	SetConsoleTextAttribute(stdout_handle,
	                        GetColorAttribute(color)
	                        | static_cast<WORD>(FOREGROUND_INTENSITY));
	vprintf(fmt, args);
	fflush(stdout);
	// Restores the text color.
	SetConsoleTextAttribute(stdout_handle, old_color_attrs);
	va_end(args);
}
int EnvelopeWidget::Load(XmlSynthElem *elem)
{
	int err = SynthWidget::Load(elem);
	float w;
	if (elem->GetAttribute("bord", w) == 0)
		border = (int)w;
	GetColorAttribute(elem, "fr", frClr);
	return err;
}
Esempio n. 5
0
///=====================================================
/// 
///=====================================================
Item::Item(const Item& other, OpenGLRenderer* renderer, const XMLNode& saveData /*= XMLNode::emptyNode()*/):
Entity(other, renderer, saveData),
m_type(other.m_type),
m_equippedSlot(other.m_equippedSlot),
m_damageReductionPercent(other.m_damageReductionPercent),
m_numUses(other.m_numUses),
m_healing(other.m_healing),
m_damage(other.m_damage){
	if (!saveData.isEmpty()){
		m_glyph = GetCharAttribute(saveData, "glyph", m_glyph);
		m_color = GetColorAttribute(saveData, "color", m_color);
	}

	m_textRenderer.SetInputString(std::string(1, m_glyph));
	m_textRenderer.SetInputStringColor(m_color);
}
Esempio n. 6
0
	// Helpers for printing colored strings to stdout. Note that on Windows, we
	// cannot simply emit special characters and have the terminal change colors.
	// This routine must actually emit the characters rather than return a string
	// that would be colored when printed, as can be done on Linux.
	void ColoredPrintf(LogogColor color, const char* fmt, ...) 
	{
		va_list args;
		va_start(args, fmt);

#if !defined(LOGOG_FLAVOR_WINDOWS) && !defined(LOGOG_FLAVOR_POSIX)
		const bool use_color = false;
#else
		static const bool in_color_mode =
			ShouldUseColor(true);//isatty(fileno(stdout)) != 0);
		const bool use_color = in_color_mode && (color != COLOR_DEFAULT);
#endif  // !LOGOG_FLAVOR_POSIX && !LOGOG_FLAVOR_WINDOWS
		// The '!= 0' comparison is necessary to satisfy MSVC 7.1.

		if (!use_color) {
			vprintf(fmt, args);
			va_end(args);
			return;
		}

#ifdef LOGOG_FLAVOR_WINDOWS
		const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);

		// Gets the current text color.
		CONSOLE_SCREEN_BUFFER_INFO buffer_info;
		GetConsoleScreenBufferInfo(stdout_handle, &buffer_info);
		const WORD old_color_attrs = buffer_info.wAttributes;

		// We need to flush the stream buffers into the console before each
		// SetConsoleTextAttribute call lest it affect the text that is already
		// printed but has not yet reached the console.
		fflush(stdout);
		SetConsoleTextAttribute(stdout_handle,
								GetColorAttribute(color) | FOREGROUND_INTENSITY);
		vprintf(fmt, args);

		fflush(stdout);
		// Restores the text color.
		SetConsoleTextAttribute(stdout_handle, old_color_attrs);
#else
		printf("\033[0;3%sm", GetAnsiColorCode(color));
		vprintf(fmt, args);
		printf("\033[m");  // Resets the terminal to default.
#endif  // LOGOG_FLAVOR_WINDOWS
		va_end(args);
	}
Esempio n. 7
0
void TestSystem::printMetrics(int is_accurate, double cpu_time, double gpu_time, double gpu_full_time, double speedup, double fullspeedup)
{
    cout << setiosflags(ios_base::left);
    stringstream stream;

#if 0
    if(is_accurate == 1)
        stream << "Pass";
    else if(is_accurate_ == 0)
        stream << "Fail";
    else if(is_accurate == -1)
        stream << " ";
    else
    {
        std::cout<<"is_accurate errer: "<<is_accurate<<"\n";
        exit(-1);
    }
#endif

    std::stringstream &cur_subtest_description = getCurSubtestDescription();

#if GTEST_OS_WINDOWS&&!GTEST_OS_WINDOWS_MOBILE

    WORD color;
    const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);
    // Gets the current text color.
    CONSOLE_SCREEN_BUFFER_INFO buffer_info;
    GetConsoleScreenBufferInfo(stdout_handle, &buffer_info);
    const WORD old_color_attrs = buffer_info.wAttributes;
    // We need to flush the stream buffers into the console before each
    // SetConsoleTextAttribute call lest it affect the text that is already
    // printed but has not yet reached the console.
    fflush(stdout);

    if(is_accurate == 1||is_accurate == -1)
    {
        color = old_color_attrs;
        printMetricsUti(cpu_time, gpu_time, gpu_full_time, speedup, fullspeedup, stream, cur_subtest_description);

    } else
    {
        color = GetColorAttribute(COLOR_RED);
        SetConsoleTextAttribute(stdout_handle,
                                color| FOREGROUND_INTENSITY);

        printMetricsUti(cpu_time, gpu_time, gpu_full_time, speedup, fullspeedup, stream, cur_subtest_description);
        fflush(stdout);
        // Restores the text color.
        SetConsoleTextAttribute(stdout_handle, old_color_attrs);
    }
#else
    GTestColor color = COLOR_RED;
    if(is_accurate == 1|| is_accurate == -1)
    {
        printMetricsUti(cpu_time, gpu_time, gpu_full_time, speedup, fullspeedup, stream, cur_subtest_description);

    } else
    {
        printf("\033[0;3%sm", GetAnsiColorCode(color));
        printMetricsUti(cpu_time, gpu_time, gpu_full_time, speedup, fullspeedup, stream, cur_subtest_description);
        printf("\033[m");  // Resets the terminal to default.
    }
#endif
}
Esempio n. 8
0
///=====================================================
/// 
///=====================================================
Item::Item(const XMLNode& itemNode, OpenGLRenderer* renderer) :
Entity(itemNode, renderer),
m_type(Undefined),
m_equippedSlot(Unequippable),
m_damageReductionPercent(0.0f),
m_numUses(1),
m_healing(0),
m_damage(0, 0){
	m_name = GetStringAttribute(itemNode, "name");

	std::string itemType = GetStringAttribute(itemNode, "type");

	m_damageReductionPercent = GetFloatAttribute(itemNode, "damageReductionPercent", m_damageReductionPercent);
	m_numUses = GetIntAttribute(itemNode, "numUses", m_numUses);
	m_healing = GetIntAttribute(itemNode, "healing", m_healing);
	m_damage = IntVec2(GetIntAttribute(itemNode, "minDamage", m_damage.x), GetIntAttribute(itemNode, "maxDamage", m_damage.y));

	RGBAchars defaultColor = RGBAchars::WHITE;
	char defaultGlyph = ':';

	if (itemType == "Weapon"){
		m_type = ItemType::Weapon;
	}
	else if (itemType == "Armor"){
		m_type = ItemType::Armor;
	}
	else if (itemType == "Consumable"){
		m_type = ItemType::Consumable;
	}
	else{ //unknown item
		assert(false);
	}

	if (m_type != ItemType::Undefined){
		defaultColor = ITEM_COLOR_TABLE[m_type];
		defaultGlyph = ITEM_SYMBOL_TABLE[m_type];
	}


	std::string itemEquipSlot = GetStringAttribute(itemNode, "equip");

	if (itemEquipSlot == "Weapon"){
		m_equippedSlot = EquipmentSlot::WeaponSlot;
	}
	else if (itemEquipSlot == "Chest"){
		m_equippedSlot = EquipmentSlot::Chest;
	}
	else if (itemEquipSlot == "Head"){
		m_equippedSlot = EquipmentSlot::Head;
	}
	else if (itemEquipSlot == "Ring"){
		m_equippedSlot = EquipmentSlot::Ring;
	}
	else if (itemEquipSlot == "Hands"){
		m_equippedSlot = EquipmentSlot::Hands;
	}
	else if (itemEquipSlot == "Feet"){
		m_equippedSlot = EquipmentSlot::Feet;
	}
	else if (itemEquipSlot == "Legs"){
		m_equippedSlot = EquipmentSlot::Legs;
	}

	m_glyph = GetCharAttribute(itemNode, "glyph", defaultGlyph);
	m_color = GetColorAttribute(itemNode, "color", defaultColor);

	m_textRenderer.SetInputString(std::string(1, m_glyph));
	m_textRenderer.SetInputStringColor(m_color);
}