view EXCLUDE/GLTSF/src/Video_Mode.cpp @ 4734:0c7c67d4e6ee

Added On_Char method to Window_Listener for WM_CHAR messages. Removed a lot of TSF code because part of it was wrong and part was too complicated. Added Clear method to clear the window. IME input should work in both windowed mode and fullscreen mode with these changes. I have tested on Windows XP SP3 and Windows 7 Ultimate in VirtualBox. When you type a character (with an IME or not), the console will show the code point as U+XXXX. You use Left Alt+Shift (or whatever you have it set to) to switch input languages as usual. Hit ESC to exit (or close the window in windowed mode). The program will pause before exiting so you can review the console output (press a key to exit).
author dewyatt
date Wed, 09 Jun 2010 00:03:54 -0400
parents 6032ada8b9e5
children
line wrap: on
line source

#include "Video_Mode.hpp"
#include <vector>
#include <algorithm>
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>

namespace
{

	typedef std::vector<Video_Mode> Video_Mode_List;
	Video_Mode_List Supported_Modes;

	struct Compare_Modes
	{
		bool operator()(const Video_Mode &Mode_1, const Video_Mode &Mode_2) const
		{
			if (Mode_1.Bits_Per_Pixel > Mode_2.Bits_Per_Pixel)
				return true;
			else if (Mode_1.Bits_Per_Pixel < Mode_2.Bits_Per_Pixel)
				return false;
			else if (Mode_1.Width > Mode_2.Width)
				return true;
			else if (Mode_1.Width < Mode_2.Width)
				return false;
			else
				return Mode_1.Height > Mode_2.Height;
		}
	};

}

Video_Mode::Video_Mode() : Width(0),
						   Height(0),
						   Bits_Per_Pixel(0)
{

}

Video_Mode::Video_Mode(unsigned int The_Width, unsigned int The_Height, unsigned int The_Bits_Per_Pixel)
	: Width(The_Width),
	  Height(The_Height),
	  Bits_Per_Pixel(The_Bits_Per_Pixel)
{

}

Video_Mode Video_Mode::Get_Desktop_Mode()
{
	DEVMODE Device_Mode = {0};
	Device_Mode.dmSize = sizeof(Device_Mode);
	EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &Device_Mode);
	return Video_Mode(Device_Mode.dmPelsWidth, Device_Mode.dmPelsHeight, Device_Mode.dmBitsPerPel);
}

std::size_t Video_Mode::Get_Mode_Count()
{
	Initialize_Modes();
	return Supported_Modes.size();
}

Video_Mode Video_Mode::Get_Mode(std::size_t Index)
{
	Initialize_Modes();
	return Supported_Modes[Index];
}

bool Video_Mode::Is_Valid() const
{
	Initialize_Modes();
	return Supported_Modes.end() != std::find(Supported_Modes.begin(), Supported_Modes.end(), *this);
}

bool Video_Mode::operator==(const Video_Mode &Mode) const
{
	return (Width == Mode.Width
		&&  Height == Mode.Height
		&&  Bits_Per_Pixel == Mode.Bits_Per_Pixel);
}

bool Video_Mode::operator!=(const Video_Mode &Mode) const
{
	return !(*this == Mode);
}

void Video_Mode::Initialize_Modes()
{
	static bool Initialized = false;
	if (!Initialized)
	{
		DEVMODE Device_Mode = {0};
		Device_Mode.dmSize = sizeof(Device_Mode);
		for (std::size_t i = 0; 0 != EnumDisplaySettings(NULL, i, &Device_Mode); ++i)
		{
			Video_Mode Mode(Device_Mode.dmPelsWidth, Device_Mode.dmPelsHeight, Device_Mode.dmBitsPerPel);
			if (Supported_Modes.end() == std::find(Supported_Modes.begin(), Supported_Modes.end(), Mode))
				Supported_Modes.push_back(Mode);
		}
		std::sort(Supported_Modes.begin(), Supported_Modes.end(), Compare_Modes());
	}
}