# HG changeset patch # User Sam Lantinga # Date 1282505996 25200 # Node ID 102675835e08f19a7e6612e128b1d77127a718a5 # Parent 518d1679d2d0399e9308680f49c6aa13b42990fe Removed Daniel's test code diff -r 518d1679d2d0 -r 102675835e08 EXCLUDE/GLIMM/GLIMM.sln --- a/EXCLUDE/GLIMM/GLIMM.sln Sun Aug 22 12:39:27 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 10.00 -# Visual Studio 2008 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GLIMM", "GLIMM.vcproj", "{F21B830F-20A9-4473-B67A-21D1743C6E19}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {F21B830F-20A9-4473-B67A-21D1743C6E19}.Debug|Win32.ActiveCfg = Debug|Win32 - {F21B830F-20A9-4473-B67A-21D1743C6E19}.Debug|Win32.Build.0 = Debug|Win32 - {F21B830F-20A9-4473-B67A-21D1743C6E19}.Release|Win32.ActiveCfg = Release|Win32 - {F21B830F-20A9-4473-B67A-21D1743C6E19}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff -r 518d1679d2d0 -r 102675835e08 EXCLUDE/GLIMM/GLIMM.vcproj --- a/EXCLUDE/GLIMM/GLIMM.vcproj Sun Aug 22 12:39:27 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,233 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff -r 518d1679d2d0 -r 102675835e08 EXCLUDE/GLIMM/include/App.hpp --- a/EXCLUDE/GLIMM/include/App.hpp Sun Aug 22 12:39:27 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ -#ifndef APP_HPP -#define APP_HPP - -#include "Window.hpp" - -class App : public Window_Listener -{ -public: - App(); - virtual ~App(); - - void Initialize(); - void Finalize(); - - void Run(); - - virtual void On_Close(); - virtual void On_Key_Down(int Key); - virtual void On_Key_Up(int Key); - virtual void On_Char(unsigned int Char); - virtual void On_Resized(unsigned int Width, unsigned int Height); - virtual void On_Mouse_Button_Down(Mouse_Button Button); - -private: - void Update(); - void Draw(); - - static const int Width = 800; - static const int Height = 600; - static const int Bits_Per_Pixel = 32; - static const bool Fullscreen = true; - - Window my_Window; - bool my_Done; -}; - -#endif diff -r 518d1679d2d0 -r 102675835e08 EXCLUDE/GLIMM/include/IMM.hpp --- a/EXCLUDE/GLIMM/include/IMM.hpp Sun Aug 22 12:39:27 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -#ifndef IMM_HPP -#define IMM_HPP - -#define WIN32_LEAN_AND_MEAN -#include -#include - -class IMM -{ -public: - IMM(); - ~IMM(); - - void Initialize(HWND Window); - void Finalize(); - - LRESULT Handle_Message(HWND Window, UINT Message, WPARAM wParam, LPARAM lParam, bool &Ate); - - void Enable(); - void Disable(); - bool Is_Enabled(); - void Toggle(); - - void Focus_Gained(); - void Focus_Lost(); - -private: - void Update_Input_Locale(); - void Cancel_Composition(); - void Input_Language_Changed(); - - bool my_COM_Initialized; - ITfThreadMgr *my_Thread_Manager; - HWND my_Window; - HIMC my_Context; - HKL my_HKL; - bool my_Vertical_Candidates; - bool my_Enabled; -}; - -#endif diff -r 518d1679d2d0 -r 102675835e08 EXCLUDE/GLIMM/include/Video_Mode.hpp --- a/EXCLUDE/GLIMM/include/Video_Mode.hpp Sun Aug 22 12:39:27 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -#ifndef VIDEO_MODE_HPP -#define VIDEO_MODE_HPP - -#include - -class Video_Mode -{ -public: - Video_Mode(); - Video_Mode(unsigned int The_Width, unsigned int The_Height, unsigned int The_Bits_Per_Pixel); - - static Video_Mode Get_Desktop_Mode(); - - static std::size_t Get_Mode_Count(); - static Video_Mode Get_Mode(std::size_t Index); - - bool Is_Valid() const; - - bool operator==(const Video_Mode &Mode) const; - bool operator!=(const Video_Mode &Mode) const; - - unsigned int Width; - unsigned int Height; - unsigned int Bits_Per_Pixel; - -private: - static void Initialize_Modes(); -}; - -#endif diff -r 518d1679d2d0 -r 102675835e08 EXCLUDE/GLIMM/include/Window.hpp --- a/EXCLUDE/GLIMM/include/Window.hpp Sun Aug 22 12:39:27 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -#ifndef WINDOW_HPP -#define WINDOW_HPP - -#include - -#define WIN32_LEAN_AND_MEAN -#include - -#include "Video_Mode.hpp" -#include "Window_Listener.hpp" -#include "IMM.hpp" - -class Window -{ -public: - Window(); - ~Window(); - - void Initialize(const std::wstring &Title, const Video_Mode &Mode, bool Fullscreen); - void Finalize(); - - void Set_Listener(Window_Listener *Listener); - - void Show(); - void Hide(); - - void Handle_Events(); - void Display(); - - void Show_Cursor(); - void Hide_Cursor(); - - HWND Get_Handle(); - IMM &Get_IMM(); - -private: - static const wchar_t *Window_Class_Name; - - void Register_Class(); - void Unregister_Class(); - - void Create_Window(const std::wstring &Title, const Video_Mode &Mode, bool Fullscreen); - void Destroy_Window(); - - void Create_Context(const Video_Mode &Mode); - void Destroy_Context(); - - void Switch_To_Fullscreen(const Video_Mode &Mode); - - LRESULT Handle_Message(HWND Handle, UINT Message, WPARAM wParam, LPARAM lParam); - static LRESULT CALLBACK Window_Procedure(HWND Handle, UINT Message, WPARAM wParam, LPARAM lParam); - - HWND my_Handle; - Video_Mode my_Video_Mode; - bool my_Fullscreen; - HDC my_Device_Context; - HGLRC my_GL_Context; - bool my_Class_Registered; - Window_Listener *my_Listener; - IMM my_IMM; -}; - -#endif diff -r 518d1679d2d0 -r 102675835e08 EXCLUDE/GLIMM/include/Window_Listener.hpp --- a/EXCLUDE/GLIMM/include/Window_Listener.hpp Sun Aug 22 12:39:27 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -#ifndef WINDOW_LISTENER_HPP -#define WINDOW_LISTENER_HPP - -enum Mouse_Button -{ - Mouse_Button_Left, - Mouse_Button_Right -}; - -class Window_Listener -{ -public: - virtual void On_Close(){} - virtual void On_Key_Down(int Key){} - virtual void On_Key_Up(int Key){} - virtual void On_Char(unsigned int Char){} - virtual void On_Resized(unsigned int Width, unsigned int Height){} - virtual void On_Mouse_Button_Down(Mouse_Button Button){} - virtual void On_Mouse_Button_Up(Mouse_Button Button){} - -}; - -#endif diff -r 518d1679d2d0 -r 102675835e08 EXCLUDE/GLIMM/src/App.cpp --- a/EXCLUDE/GLIMM/src/App.cpp Sun Aug 22 12:39:27 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,113 +0,0 @@ -#include "App.hpp" -#include -#include - -#pragma comment(lib, "glu32.lib") - -GLfloat Rotation = 0.0f; - -App::App() : my_Done(false) -{ - -} - -App::~App() -{ - Finalize(); -} - -void App::Initialize() -{ - Finalize(); - - my_Window.Initialize(L"GLIMM", Video_Mode(Width, Height, Bits_Per_Pixel), Fullscreen); - my_Window.Set_Listener(this); - my_Window.Show(); - my_Window.Hide_Cursor(); -} - -void App::Finalize() -{ - my_Window.Finalize(); -} - -void App::Run() -{ - Initialize(); - while (!my_Done) - { - my_Window.Handle_Events(); - - Update(); - Draw(); - my_Window.Display(); - } -} - -void App::On_Close() -{ - my_Done = true; - my_Window.Hide(); -} - -void App::On_Key_Down(int Key) -{ - switch (Key) - { - case VK_ESCAPE: - On_Close(); - break; - } -} - -void App::On_Key_Up(int Key) -{ - -} - -void App::On_Char(unsigned int Char) -{ - printf("Char: U+%04X\n", Char); -} - -void App::On_Resized(unsigned int Width, unsigned int Height) -{ - glViewport(0, 0, Width, Height); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); -} - -void App::On_Mouse_Button_Down(Mouse_Button Button) -{ - switch (Button) - { - case Mouse_Button_Left: - my_Window.Get_IMM().Toggle(); - break; - } -} - -void App::Update() -{ - Rotation += 0.2f; -} - -void App::Draw() -{ - glClear(GL_COLOR_BUFFER_BIT); - - glLoadIdentity(); - glRotatef(Rotation, 0.0f, 0.0f, -1.0f); - - glBegin(GL_TRIANGLES); - glColor3f(0.7f, 0.0f, 0.0f); - glVertex3f(0.0f, 0.5f, 0.0f); - glColor3f(0.0f, 0.7f, 0.0f); - glVertex3f(-0.5f, -0.5f, 0.0f); - glColor3f(0.0f, 0.0f, 0.7f); - glVertex3f(0.5f, -0.5f, 0.0f); - glEnd(); -} diff -r 518d1679d2d0 -r 102675835e08 EXCLUDE/GLIMM/src/IMM.cpp --- a/EXCLUDE/GLIMM/src/IMM.cpp Sun Aug 22 12:39:27 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,237 +0,0 @@ -#include "IMM.hpp" -#include - -IMM::IMM() : my_COM_Initialized(false), - my_Thread_Manager(0), - my_Window(0), - my_Context(0), - my_HKL(0), - my_Vertical_Candidates(false), - my_Enabled(false) -{ - -} - -IMM::~IMM() -{ - Finalize(); -} - -void IMM::Initialize(HWND Window) -{ - Finalize(); - - my_Window = Window; - - if (SUCCEEDED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED))) - { - my_COM_Initialized = true; - if (SUCCEEDED(CoCreateInstance(CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, IID_ITfThreadMgr, reinterpret_cast(&my_Thread_Manager)))) - { - ITfDocumentMgr *Document_Manager = 0; - if (SUCCEEDED(my_Thread_Manager->AssociateFocus(Window, NULL, &Document_Manager))) - { - if (Document_Manager) - Document_Manager->Release(); - } - else - printf("Warning: ITfThreadMgr->AssociateFocus failed\n"); - } - else - printf("Warning: Failed to create ITfThreadMgr instance\n"); - } - else - printf("Warning: Failed to initialize COM\n"); - - ImmDisableTextFrameService((DWORD)-1); - - my_Context = ImmGetContext(my_Window); - ImmReleaseContext(my_Window, my_Context); - if (!my_Context) - throw std::runtime_error("No context (No IME installed?)"); - - Update_Input_Locale(); - Cancel_Composition(); - Disable(); -} - -void IMM::Finalize() -{ - if (my_Thread_Manager) - { - my_Thread_Manager->Release(); - my_Thread_Manager = 0; - } - if (my_COM_Initialized) - { - CoUninitialize(); - my_COM_Initialized = false; - } -} - -#define GET_LANG(hkl) LOWORD((hkl)) -#define GET_PRIMLANG(hkl) ((WORD)PRIMARYLANGID(GET_LANG((hkl)))) -#define GET_SUBLANG(hkl) SUBLANGID(GET_LANG((hkl))) - -void IMM::Update_Input_Locale() -{ - static HKL Previous_HKL = 0; - my_HKL = GetKeyboardLayout(0); - if (Previous_HKL == my_HKL) - return; - - Previous_HKL = my_HKL; - my_Vertical_Candidates = false; - switch (GET_PRIMLANG(my_HKL)) - { - case LANG_CHINESE: - my_Vertical_Candidates = true; - switch (GET_SUBLANG(my_HKL)) - { - case SUBLANG_CHINESE_SIMPLIFIED: - my_Vertical_Candidates = false; - break; - } - break; - case LANG_JAPANESE: - my_Vertical_Candidates = true; - break; - } -} - -LRESULT IMM::Handle_Message(HWND Window, UINT Message, WPARAM wParam, LPARAM lParam, bool &Ate) -{ - Ate = false; - switch (Message) - { - case WM_INPUTLANGCHANGE: - Input_Language_Changed(); - break; - case WM_IME_SETCONTEXT: - lParam = 0; - break; - case WM_IME_STARTCOMPOSITION: - Ate = true; - break; - case WM_IME_COMPOSITION: - { - Ate = true; - HIMC Context = ImmGetContext(Window); - if (!Context) - break; - - if (lParam & GCS_RESULTSTR) - { - LONG Length = ImmGetCompositionStringW(Context, GCS_RESULTSTR, 0, 0); - std::wstring Composition(Length / sizeof(wchar_t), 0); - Length = ImmGetCompositionStringW(Context, GCS_RESULTSTR, &Composition[0], Composition.size() * sizeof(Composition[0])); - printf("GCS_RESULTSTR: "); - for (LONG i = 0; i < Length / sizeof(wchar_t); ++i) - printf("U+%04X ", Composition[i]); - - printf("\n"); - } - if (lParam & GCS_COMPSTR) - { - LONG Length = ImmGetCompositionStringW(Context, GCS_COMPSTR, 0, 0); - std::wstring Composition(Length / sizeof(wchar_t), 0); - Length = ImmGetCompositionStringW(Context, GCS_COMPSTR, &Composition[0], Composition.size() * sizeof(Composition[0])); - printf("GCS_COMPSTR: "); - for (LONG i = 0; i < Length / sizeof(wchar_t); ++i) - printf("U+%04X ", Composition[i]); - - printf("\n"); - } - ImmReleaseContext(Window, Context); - } - break; - case WM_IME_ENDCOMPOSITION: - break; - case WM_IME_NOTIFY: - switch (wParam) - { - case IMN_SETCONVERSIONMODE: - - break; - case IMN_SETOPENSTATUS: - Update_Input_Locale(); - break; - case IMN_OPENCANDIDATE: - case IMN_CHANGECANDIDATE: - Ate = true; - break; - case IMN_CLOSECANDIDATE: - Ate = true; - break; - default: - Ate = true; - break; - } - break; - } - return 0; -} - -void IMM::Enable() -{ - ImmAssociateContext(my_Window, my_Context); - Update_Input_Locale(); - my_Enabled = true; - printf("* Enabled\n"); -} - -void IMM::Disable() -{ - ImmAssociateContext(my_Window, 0); - my_Enabled = false; - printf("* Disabled\n"); -} - -bool IMM::Is_Enabled() -{ - return my_Enabled; -} - -void IMM::Toggle() -{ - if (my_Enabled) - Disable(); - else - Enable(); -} - -void IMM::Focus_Gained() -{ - if (my_Enabled) - Enable(); -} - -void IMM::Focus_Lost() -{ - bool Enabled = my_Enabled; - Cancel_Composition(); - Disable(); - my_Enabled = Enabled; -} - -void IMM::Cancel_Composition() -{ - HIMC hIMC = ImmGetContext(my_Window); - if (!hIMC) - return; - - ImmNotifyIME(hIMC, NI_COMPOSITIONSTR, CPS_CANCEL, 0); - ImmNotifyIME(hIMC, NI_CLOSECANDIDATE, 0, 0); - ImmReleaseContext(my_Window, hIMC); -} - -void IMM::Input_Language_Changed() -{ - Update_Input_Locale(); - HWND hwndImeDef = ImmGetDefaultIMEWnd(my_Window); - if (hwndImeDef) - { - SendMessageA(hwndImeDef, WM_IME_CONTROL, IMC_OPENSTATUSWINDOW, 0); - SendMessageA(hwndImeDef, WM_IME_CONTROL, IMC_CLOSESTATUSWINDOW, 0); - } -} diff -r 518d1679d2d0 -r 102675835e08 EXCLUDE/GLIMM/src/Main.cpp --- a/EXCLUDE/GLIMM/src/Main.cpp Sun Aug 22 12:39:27 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -#include "App.hpp" -#include - -int main(int argc, char *argv[]) -{ - int Result = EXIT_SUCCESS; - try - { - App theApp; - theApp.Run(); - } - catch (const std::exception& e) - { - printf("Error: %s\n", e.what()); - Result = EXIT_FAILURE; - } - catch (...) - { - printf("Unhandled exception\n"); - Result = EXIT_FAILURE; - } - system("PAUSE"); - return Result; -} diff -r 518d1679d2d0 -r 102675835e08 EXCLUDE/GLIMM/src/Video_Mode.cpp --- a/EXCLUDE/GLIMM/src/Video_Mode.cpp Sun Aug 22 12:39:27 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,100 +0,0 @@ -#include "Video_Mode.hpp" -#include -#include -#define WIN32_LEAN_AND_MEAN -#include - -namespace -{ - - typedef std::vector 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()); - } -} diff -r 518d1679d2d0 -r 102675835e08 EXCLUDE/GLIMM/src/Window.cpp --- a/EXCLUDE/GLIMM/src/Window.cpp Sun Aug 22 12:39:27 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,317 +0,0 @@ -#include "Window.hpp" -#include - -#pragma comment(lib, "opengl32.lib") - -const wchar_t *Window::Window_Class_Name = L"GLTSF"; - -Window::Window() : my_Handle(0), - my_Device_Context(0), - my_GL_Context(0), - my_Class_Registered(false), - my_Listener(0) -{ - -} - -Window::~Window() -{ - Finalize(); - Show_Cursor(); -} - -void Window::Initialize(const std::wstring &Title, const Video_Mode &Mode, bool Fullscreen) -{ - Finalize(); - - my_Video_Mode = Mode; - if (!my_Video_Mode.Is_Valid()) - throw std::runtime_error("Invalid video mode"); - - my_Fullscreen = Fullscreen; - Register_Class(); - Create_Window(Title, Mode, Fullscreen); - Show(); - my_IMM.Initialize(my_Handle); -} - -void Window::Finalize() -{ - my_IMM.Finalize(); - Destroy_Window(); - Unregister_Class(); -} - -void Window::Set_Listener(Window_Listener *Listener) -{ - my_Listener = Listener; -} - -void Window::Show() -{ - if (my_Handle) - ShowWindow(my_Handle, SW_SHOW); -} - -void Window::Hide() -{ - if (my_Handle) - ShowWindow(my_Handle, SW_HIDE); -} - -void Window::Handle_Events() -{ - MSG Message = {0}; - while (PeekMessageW(&Message, NULL, 0, 0, PM_REMOVE)) - { - TranslateMessage(&Message); - DispatchMessageW(&Message); - } -} - -void Window::Display() -{ - if (my_Device_Context && my_GL_Context) - SwapBuffers(my_Device_Context); -} - -void Window::Show_Cursor() -{ - ShowCursor(TRUE); -} - -void Window::Hide_Cursor() -{ - ShowCursor(FALSE); -} - -HWND Window::Get_Handle() -{ - return my_Handle; -} - -IMM & Window::Get_IMM() -{ - return my_IMM; -} - -void Window::Register_Class() -{ - WNDCLASSEXW Window_Class = {0}; - Window_Class.cbSize = sizeof(Window_Class); - Window_Class.style = 0; - Window_Class.lpfnWndProc = &Window::Window_Procedure; - Window_Class.cbClsExtra = 0; - Window_Class.cbWndExtra = 0; - Window_Class.hInstance = GetModuleHandle(NULL); - Window_Class.hIcon = NULL; - Window_Class.hCursor = NULL; - Window_Class.hbrBackground = NULL; - Window_Class.lpszMenuName = NULL; - Window_Class.lpszClassName = Window_Class_Name; - Window_Class.hIconSm = NULL; - if (0 == RegisterClassExW(&Window_Class)) - throw std::runtime_error("Failed to register window class"); - - my_Class_Registered = true; -} - -void Window::Unregister_Class() -{ - if (my_Class_Registered) - { - if (0 == UnregisterClassW(Window_Class_Name, GetModuleHandle(NULL))) - printf("Warning: Failed to unregister window class\n"); - - my_Class_Registered = false; - } -} - -void Window::Create_Window(const std::wstring &Title, const Video_Mode &Mode, bool Fullscreen) -{ - HDC Screen_DC = GetDC(NULL); - int Left = (GetDeviceCaps(Screen_DC, HORZRES) - my_Video_Mode.Width) / 2; - int Top = (GetDeviceCaps(Screen_DC, VERTRES) - my_Video_Mode.Height) / 2; - int Width = my_Video_Mode.Width; - int Height = my_Video_Mode.Height; - ReleaseDC(NULL, Screen_DC); - - DWORD Style = WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU; - if (!my_Fullscreen) - { - RECT Rect = {0, 0, Width, Height}; - AdjustWindowRect(&Rect, Style, false); - Width = Rect.right - Rect.left; - Height = Rect.bottom - Rect.top; - } - my_Handle = CreateWindowW(Window_Class_Name, Title.c_str(), Style, Left, Top, Width, Height, NULL, NULL, GetModuleHandle(NULL), this); - if (!my_Handle) - throw std::runtime_error("Failed to create window"); - - if (Fullscreen) - Switch_To_Fullscreen(Mode); - - Create_Context(Mode); - - RECT Rect = {0}; - GetClientRect(my_Handle, &Rect); - //TODO: ... -} - -void Window::Destroy_Window() -{ - Destroy_Context(); - if (my_Handle) - { - DestroyWindow(my_Handle); - my_Handle = 0; - - if (my_Fullscreen) - ChangeDisplaySettings(NULL, 0); - } -} - -void Window::Create_Context(const Video_Mode &Mode) -{ - my_Device_Context = GetDC(my_Handle); - if (!my_Device_Context) - throw std::runtime_error("Failed to get device context"); - - PIXELFORMATDESCRIPTOR Pixel_Descriptor = {0}; - Pixel_Descriptor.nSize = sizeof(Pixel_Descriptor); - Pixel_Descriptor.nVersion = 1; - Pixel_Descriptor.iLayerType = PFD_MAIN_PLANE; - Pixel_Descriptor.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; - Pixel_Descriptor.iPixelType = PFD_TYPE_RGBA; - Pixel_Descriptor.cColorBits = static_cast(Mode.Bits_Per_Pixel); - Pixel_Descriptor.cDepthBits = 24; - Pixel_Descriptor.cStencilBits = 8; - Pixel_Descriptor.cAlphaBits = Mode.Bits_Per_Pixel == 32 ? 8 : 0; - - int Best_Format = ChoosePixelFormat(my_Device_Context, &Pixel_Descriptor); - if (0 == Best_Format) - throw std::runtime_error("Failed to find suitable pixel format"); - - PIXELFORMATDESCRIPTOR Actual_Format = {0}; - Actual_Format.nSize = sizeof(Actual_Format); - Actual_Format.nVersion = 1; - DescribePixelFormat(my_Device_Context, Best_Format, sizeof(Actual_Format), &Actual_Format); - if (!SetPixelFormat(my_Device_Context, Best_Format, &Actual_Format)) - throw std::runtime_error("Failed to set device pixel format"); - - my_GL_Context = wglCreateContext(my_Device_Context); - if (!my_GL_Context) - throw std::runtime_error("Failed to create OpenGL context"); - - wglMakeCurrent(my_Device_Context, my_GL_Context); -} - -void Window::Destroy_Context() -{ - if (my_GL_Context) - { - wglDeleteContext(my_GL_Context); - my_GL_Context = 0; - } - if (my_Device_Context) - { - ReleaseDC(my_Handle, my_Device_Context); - my_Device_Context = 0; - } -} - -void Window::Switch_To_Fullscreen(const Video_Mode &Mode) -{ - DEVMODE Device_Mode = {0}; - Device_Mode.dmSize = sizeof(Device_Mode); - Device_Mode.dmPelsWidth = Mode.Width; - Device_Mode.dmPelsHeight = Mode.Height; - Device_Mode.dmBitsPerPel = Mode.Bits_Per_Pixel; - Device_Mode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; - - if (DISP_CHANGE_SUCCESSFUL != ChangeDisplaySettings(&Device_Mode, CDS_FULLSCREEN)) - throw std::runtime_error("Failed to change to fullscreen mode"); - - SetWindowLong(my_Handle, GWL_STYLE, WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS); - SetWindowLong(my_Handle, GWL_EXSTYLE, WS_EX_APPWINDOW); - - SetWindowPos(my_Handle, HWND_TOP, 0, 0, Mode.Width, Mode.Height, SWP_FRAMECHANGED); -} - -LRESULT CALLBACK Window::Window_Procedure(HWND Handle, UINT Message, WPARAM wParam, LPARAM lParam) -{ - switch (Message) - { - case WM_CREATE: - { - LONG This = reinterpret_cast(reinterpret_cast(lParam)->lpCreateParams); - SetWindowLongPtr(Handle, GWLP_USERDATA, This); - return 0; - } - break; - case WM_DESTROY: - PostQuitMessage(0); - return 0; - break; - default: - { - Window* Win = reinterpret_cast(GetWindowLongPtr(Handle, GWLP_USERDATA)); - if (Win) - return Win->Handle_Message(Handle, Message, wParam, lParam); - } - break; - } - return DefWindowProcW(Handle, Message, wParam, lParam); -} - -#define Call_Listener(x)\ - if (my_Listener) my_Listener->x - -LRESULT Window::Handle_Message(HWND Handle, UINT Message, WPARAM wParam, LPARAM lParam) -{ - bool IMM_Message = false; - LRESULT Result = my_IMM.Handle_Message(Handle, Message, wParam, lParam, IMM_Message); - if (IMM_Message) - return Result; - - switch (Message) - { - case WM_SIZE: - Call_Listener(On_Resized(LOWORD(lParam), HIWORD(lParam))); - break; - case WM_CLOSE: - Call_Listener(On_Close()); - break; - case WM_KEYDOWN: - Call_Listener(On_Key_Down(wParam)); - break; - case WM_KEYUP: - Call_Listener(On_Key_Up(wParam)); - break; - case WM_CHAR: - Call_Listener(On_Char(wParam)); - break; - case WM_SETFOCUS: - my_IMM.Focus_Gained(); - break; - case WM_KILLFOCUS: - my_IMM.Focus_Lost(); - break; - case WM_LBUTTONDOWN: - Call_Listener(On_Mouse_Button_Down(Mouse_Button_Left)); - break; - case WM_LBUTTONUP: - Call_Listener(On_Mouse_Button_Up(Mouse_Button_Left)); - break; - case WM_RBUTTONDOWN: - Call_Listener(On_Mouse_Button_Down(Mouse_Button_Right)); - break; - case WM_RBUTTONUP: - Call_Listener(On_Mouse_Button_Up(Mouse_Button_Right)); - break; - default: - return DefWindowProcW(Handle, Message, wParam, lParam); - break; - } - return 0; -} diff -r 518d1679d2d0 -r 102675835e08 EXCLUDE/GLTSF/GLTSF.sln --- a/EXCLUDE/GLTSF/GLTSF.sln Sun Aug 22 12:39:27 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GLTSF", "GLTSF.vcxproj", "{790D58BA-E5F6-4286-A9C6-0DC28779789D}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {790D58BA-E5F6-4286-A9C6-0DC28779789D}.Debug|Win32.ActiveCfg = Debug|Win32 - {790D58BA-E5F6-4286-A9C6-0DC28779789D}.Debug|Win32.Build.0 = Debug|Win32 - {790D58BA-E5F6-4286-A9C6-0DC28779789D}.Release|Win32.ActiveCfg = Release|Win32 - {790D58BA-E5F6-4286-A9C6-0DC28779789D}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff -r 518d1679d2d0 -r 102675835e08 EXCLUDE/GLTSF/GLTSF.vcproj --- a/EXCLUDE/GLTSF/GLTSF.vcproj Sun Aug 22 12:39:27 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,231 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff -r 518d1679d2d0 -r 102675835e08 EXCLUDE/GLTSF/GLTSF.vcxproj --- a/EXCLUDE/GLTSF/GLTSF.vcxproj Sun Aug 22 12:39:27 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,99 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - {790D58BA-E5F6-4286-A9C6-0DC28779789D} - Win32Proj - GLTSF - - - - Application - true - Unicode - - - Application - false - true - Unicode - - - - - - - - - - - - - true - $(SolutionDir)bin\ - obj\$(Configuration)\ - - - false - $(SolutionDir)bin\ - obj\$(Configuration)\ - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - include;%(AdditionalIncludeDirectories) - - - Console - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - include;%(AdditionalIncludeDirectories) - - - Console - true - true - true - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff -r 518d1679d2d0 -r 102675835e08 EXCLUDE/GLTSF/GLTSF.vcxproj.filters --- a/EXCLUDE/GLTSF/GLTSF.vcxproj.filters Sun Aug 22 12:39:27 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - \ No newline at end of file diff -r 518d1679d2d0 -r 102675835e08 EXCLUDE/GLTSF/GLTSF_vs2008.sln --- a/EXCLUDE/GLTSF/GLTSF_vs2008.sln Sun Aug 22 12:39:27 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 10.00 -# Visual Studio 2008 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GLTSF", "GLTSF.vcproj", "{FC8A9A48-6667-4BDE-8E9B-5859408AEE83}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {FC8A9A48-6667-4BDE-8E9B-5859408AEE83}.Debug|Win32.ActiveCfg = Debug|Win32 - {FC8A9A48-6667-4BDE-8E9B-5859408AEE83}.Debug|Win32.Build.0 = Debug|Win32 - {FC8A9A48-6667-4BDE-8E9B-5859408AEE83}.Release|Win32.ActiveCfg = Release|Win32 - {FC8A9A48-6667-4BDE-8E9B-5859408AEE83}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff -r 518d1679d2d0 -r 102675835e08 EXCLUDE/GLTSF/include/App.hpp --- a/EXCLUDE/GLTSF/include/App.hpp Sun Aug 22 12:39:27 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -#ifndef APP_HPP -#define APP_HPP - -#include "Window.hpp" - -class App : public Window_Listener -{ -public: - App(); - virtual ~App(); - - void Initialize(); - void Finalize(); - - void Run(); - - virtual void On_Close(); - virtual void On_Key_Down(int Key); - virtual void On_Key_Up(int Key); - virtual void On_Char(unsigned int Char); - virtual void On_Resized(unsigned int Width, unsigned int Height); - -private: - void Update(); - void Draw(); - - static const int Width = 800; - static const int Height = 600; - static const int Bits_Per_Pixel = 32; - static const bool Fullscreen = true; - - Window my_Window; - bool my_Done; -}; - -#endif diff -r 518d1679d2d0 -r 102675835e08 EXCLUDE/GLTSF/include/TSF.hpp --- a/EXCLUDE/GLTSF/include/TSF.hpp Sun Aug 22 12:39:27 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,83 +0,0 @@ -#ifndef TSF_HPP -#define TSF_HPP - -#include -#include - -class TSF -{ -public: - static void Initialize(); - static void Finalize(); - -private: - class TSF_Text_Store : public ITextStoreACP, public ITfContextOwnerCompositionSink - { - public: - //IUnknown - STDMETHODIMP QueryInterface(REFIID riid, void **ppvObject); - STDMETHODIMP_(ULONG) AddRef(); - STDMETHODIMP_(ULONG) Release(); - - //ITextStoreACP - STDMETHODIMP AdviseSink(REFIID riid, IUnknown *punk, DWORD dwMask); - STDMETHODIMP UnadviseSink(IUnknown *punk); - STDMETHODIMP RequestLock(DWORD dwLockFlags, HRESULT *phrSession); - STDMETHODIMP GetStatus(TS_STATUS *pdcs); - STDMETHODIMP QueryInsert(LONG acpTestStart, LONG acpTestEnd, ULONG cch, LONG *pacpResultStart, LONG *pacpResultEnd); - STDMETHODIMP GetSelection(ULONG ulIndex, ULONG ulCount, TS_SELECTION_ACP *pSelection, ULONG *pcFetched); - STDMETHODIMP SetSelection(ULONG ulCount, const TS_SELECTION_ACP *pSelection); - STDMETHODIMP GetText(LONG acpStart, LONG acpEnd, WCHAR *pchPlain, ULONG cchPlainReq, ULONG *pcchPlainRet, TS_RUNINFO *prgRunInfo, ULONG cRunInfoReq, ULONG *pcRunInfoRet, LONG *pacpNext); - STDMETHODIMP SetText(DWORD dwFlags, LONG acpStart, LONG acpEnd, const WCHAR *pchText, ULONG cch, TS_TEXTCHANGE *pChange); - STDMETHODIMP GetFormattedText(LONG acpStart, LONG acpEnd, IDataObject **ppDataObject); - STDMETHODIMP GetEmbedded(LONG acpPos, REFGUID rguidService, REFIID riid, IUnknown **ppunk); - STDMETHODIMP QueryInsertEmbedded(const GUID *pguidService, const FORMATETC *pFormatEtc, BOOL *pfInsertable); - STDMETHODIMP InsertEmbedded(DWORD dwFlags, LONG acpStart, LONG acpEnd, IDataObject *pDataObject, TS_TEXTCHANGE *pChange); - STDMETHODIMP InsertTextAtSelection(DWORD dwFlags, const WCHAR *pchText, ULONG cch, LONG *pacpStart, LONG *pacpEnd, TS_TEXTCHANGE *pChange); - STDMETHODIMP InsertEmbeddedAtSelection(DWORD dwFlags, IDataObject *pDataObject, LONG *pacpStart, LONG *pacpEnd, TS_TEXTCHANGE *pChange); - STDMETHODIMP RequestSupportedAttrs(DWORD dwFlags, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs); - STDMETHODIMP RequestAttrsAtPosition(LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs, DWORD dwFlags); - STDMETHODIMP RequestAttrsTransitioningAtPosition(LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs, DWORD dwFlags); - STDMETHODIMP FindNextAttrTransition(LONG acpStart, LONG acpHalt, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs, DWORD dwFlags, LONG *pacpNext, BOOL *pfFound, LONG *plFoundOffset); - STDMETHODIMP RetrieveRequestedAttrs(ULONG ulCount, TS_ATTRVAL *paAttrVals, ULONG *pcFetched); - STDMETHODIMP GetEndACP(LONG *pacp); - STDMETHODIMP GetActiveView(TsViewCookie *pvcView); - STDMETHODIMP GetACPFromPoint(TsViewCookie vcView, const POINT *ptScreen, DWORD dwFlags, LONG *pacp); - STDMETHODIMP GetTextExt(TsViewCookie vcView, LONG acpStart, LONG acpEnd, RECT *prc, BOOL *pfClipped); - STDMETHODIMP GetScreenExt(TsViewCookie vcView, RECT *prc); - STDMETHODIMP GetWnd(TsViewCookie vcView, HWND *phwnd); - - //ITfOwnerCompositionSink - STDMETHODIMP OnStartComposition(ITfCompositionView *pComposition, BOOL *pfOk); - STDMETHODIMP OnUpdateComposition(ITfCompositionView *pComposition, ITfRange *pRangeNew); - STDMETHODIMP OnEndComposition(ITfCompositionView *pComposition); - - void Initialize(); - void Finalize(); - - TSF_Text_Store(); - ~TSF_Text_Store(); - - private: - ULONG my_Reference_Count; - CComPtr my_Document_Manager; - CComPtr my_Context; - DWORD my_Edit_Cookie; - CComPtr my_Sink; - DWORD my_Sink_Mask; - DWORD my_Lock; - DWORD my_Lock_Queued; - CComPtr my_Composition_View; - TS_SELECTION_ACP my_Composition_Selection; - }; - - TSF(); - - static bool COM_Initialized; - - static CComPtr Thread_Manager; - static TfClientId Client_Id; - static TSF_Text_Store *Text_Store; -}; - -#endif diff -r 518d1679d2d0 -r 102675835e08 EXCLUDE/GLTSF/include/Video_Mode.hpp --- a/EXCLUDE/GLTSF/include/Video_Mode.hpp Sun Aug 22 12:39:27 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -#ifndef VIDEO_MODE_HPP -#define VIDEO_MODE_HPP - -#include - -class Video_Mode -{ -public: - Video_Mode(); - Video_Mode(unsigned int The_Width, unsigned int The_Height, unsigned int The_Bits_Per_Pixel); - - static Video_Mode Get_Desktop_Mode(); - - static std::size_t Get_Mode_Count(); - static Video_Mode Get_Mode(std::size_t Index); - - bool Is_Valid() const; - - bool operator==(const Video_Mode &Mode) const; - bool operator!=(const Video_Mode &Mode) const; - - unsigned int Width; - unsigned int Height; - unsigned int Bits_Per_Pixel; - -private: - static void Initialize_Modes(); -}; - -#endif diff -r 518d1679d2d0 -r 102675835e08 EXCLUDE/GLTSF/include/Window.hpp --- a/EXCLUDE/GLTSF/include/Window.hpp Sun Aug 22 12:39:27 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -#ifndef WINDOW_HPP -#define WINDOW_HPP - -#include - -#define WIN32_LEAN_AND_MEAN -#include - -#include "Video_Mode.hpp" -#include "Window_Listener.hpp" -#include "TSF.hpp" - -class Window -{ -public: - Window(); - ~Window(); - - void Initialize(const std::wstring &Title, const Video_Mode &Mode, bool Fullscreen); - void Finalize(); - - void Set_Listener(Window_Listener *Listener); - - void Show(); - void Hide(); - - void Handle_Events(); - void Display(); - - void Show_Cursor(); - void Hide_Cursor(); - -private: - static const wchar_t *Window_Class_Name; - - void Register_Class(); - void Unregister_Class(); - - void Create_Window(const std::wstring &Title, const Video_Mode &Mode, bool Fullscreen); - void Destroy_Window(); - - void Create_Context(const Video_Mode &Mode); - void Destroy_Context(); - - void Switch_To_Fullscreen(const Video_Mode &Mode); - - LRESULT Handle_Message(HWND Handle, UINT Message, WPARAM wParam, LPARAM lParam); - static LRESULT CALLBACK Window_Procedure(HWND Handle, UINT Message, WPARAM wParam, LPARAM lParam); - - HWND my_Handle; - Video_Mode my_Video_Mode; - bool my_Fullscreen; - HDC my_Device_Context; - HGLRC my_GL_Context; - bool my_Class_Registered; - Window_Listener *my_Listener; -}; - -#endif diff -r 518d1679d2d0 -r 102675835e08 EXCLUDE/GLTSF/include/Window_Listener.hpp --- a/EXCLUDE/GLTSF/include/Window_Listener.hpp Sun Aug 22 12:39:27 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -#ifndef WINDOW_LISTENER_HPP -#define WINDOW_LISTENER_HPP - -class Window_Listener -{ -public: - virtual void On_Close(){} - virtual void On_Key_Down(int Key){} - virtual void On_Key_Up(int Key){} - virtual void On_Char(unsigned int Char){} - virtual void On_Resized(unsigned int Width, unsigned int Height){} -}; - -#endif diff -r 518d1679d2d0 -r 102675835e08 EXCLUDE/GLTSF/src/App.cpp --- a/EXCLUDE/GLTSF/src/App.cpp Sun Aug 22 12:39:27 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,105 +0,0 @@ -#include "App.hpp" -#include "TSF.hpp" -#include -#include - -#pragma comment(lib, "glu32.lib") - -GLfloat Rotation = 0.0f; - -App::App() : my_Done(false) -{ - TSF::Initialize(); -} - -App::~App() -{ - Finalize(); - TSF::Finalize(); -} - -void App::Initialize() -{ - Finalize(); - - my_Window.Initialize(L"GLTSF", Video_Mode(Width, Height, Bits_Per_Pixel), Fullscreen); - my_Window.Set_Listener(this); - my_Window.Show(); - my_Window.Hide_Cursor(); -} - -void App::Finalize() -{ - my_Window.Finalize(); -} - -void App::Run() -{ - Initialize(); - while (!my_Done) - { - my_Window.Handle_Events(); - - Update(); - Draw(); - my_Window.Display(); - } -} - -void App::On_Close() -{ - my_Done = true; - my_Window.Hide(); -} - -void App::On_Key_Down(int Key) -{ - switch (Key) - { - case VK_ESCAPE: - On_Close(); - break; - } -} - -void App::On_Key_Up(int Key) -{ - -} - -void App::On_Char(unsigned int Char) -{ - printf("Char: U+%04X\n", Char); -} - -void App::On_Resized(unsigned int Width, unsigned int Height) -{ - glViewport(0, 0, Width, Height); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); -} - -void App::Update() -{ - Rotation += 0.2f; -} - -void App::Draw() -{ - glClear(GL_COLOR_BUFFER_BIT); - - glLoadIdentity(); - glRotatef(Rotation, 0.0f, 0.0f, -1.0f); - - glBegin(GL_TRIANGLES); - glColor3f(0.7f, 0.0f, 0.0f); - glVertex3f(0.0f, 0.5f, 0.0f); - glColor3f(0.0f, 0.7f, 0.0f); - glVertex3f(-0.5f, -0.5f, 0.0f); - glColor3f(0.0f, 0.0f, 0.7f); - glVertex3f(0.5f, -0.5f, 0.0f); - glEnd(); -} diff -r 518d1679d2d0 -r 102675835e08 EXCLUDE/GLTSF/src/Main.cpp --- a/EXCLUDE/GLTSF/src/Main.cpp Sun Aug 22 12:39:27 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -#include "App.hpp" -#include - -int main(int argc, char *argv[]) -{ - int Result = EXIT_SUCCESS; - try - { - App theApp; - theApp.Run(); - } - catch (const std::exception& e) - { - printf("Error: %s\n", e.what()); - Result = EXIT_FAILURE; - } - catch (...) - { - printf("Unhandled exception\n"); - Result = EXIT_FAILURE; - } - system("PAUSE"); - return Result; -} diff -r 518d1679d2d0 -r 102675835e08 EXCLUDE/GLTSF/src/TSF.cpp --- a/EXCLUDE/GLTSF/src/TSF.cpp Sun Aug 22 12:39:27 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,360 +0,0 @@ -#include "TSF.hpp" -#include - -bool TSF::COM_Initialized = false; -CComPtr TSF::Thread_Manager; -TfClientId TSF::Client_Id; -TSF::TSF_Text_Store *TSF::Text_Store = NULL; - -void TSF::Initialize() -{ - if (!COM_Initialized) - { - HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); - if (S_OK != hr && S_FALSE != hr) - throw std::runtime_error("Failed to initialize COM"); - - COM_Initialized = true; - } - if (!Thread_Manager) - { - if (FAILED(CoCreateInstance(CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, IID_ITfThreadMgr, reinterpret_cast(&Thread_Manager)))) - throw std::runtime_error("Failed to create ITfThreadMgr instance"); - - if (FAILED(Thread_Manager->Activate(&Client_Id))) - throw std::runtime_error("ITfThreadMgr::Activate failed"); - - Text_Store = new TSF_Text_Store; - Text_Store->Initialize(); - } -} - -void TSF::Finalize() -{ - if (Thread_Manager) - { - Thread_Manager->Deactivate(); - Thread_Manager = NULL; - } - if (COM_Initialized) - { - CoUninitialize(); - COM_Initialized = false; - } -} - -STDMETHODIMP TSF::TSF_Text_Store::QueryInterface(REFIID riid, void **ppvObject) -{ - *ppvObject = NULL; - if (IID_IUnknown == riid || IID_ITextStoreACP == riid) - *ppvObject = static_cast(this); - else if (IID_ITfContextOwnerCompositionSink == riid) - *ppvObject = static_cast(this); - - if (*ppvObject) - { - AddRef(); - return S_OK; - } - return E_NOINTERFACE; -} - -STDMETHODIMP_(ULONG) TSF::TSF_Text_Store::AddRef() -{ - return ++my_Reference_Count; -} - -STDMETHODIMP_(ULONG) TSF::TSF_Text_Store::Release() -{ - --my_Reference_Count; - if (0 != my_Reference_Count) - return my_Reference_Count; - - delete this; - return 0; -} - -#define CHECK_CONDITION(condition, retval, function, line) \ - if (!condition) \ - { \ - printf("%s:%d: Condition failure: %s\n", function, line, #condition); \ - } - -#define ENSURE(condition, retval) CHECK_CONDITION(condition, retval, __FUNCTION__, __LINE__) - -STDMETHODIMP TSF::TSF_Text_Store::AdviseSink(REFIID riid, IUnknown *punk, DWORD dwMask) -{ - ENSURE(punk && IID_ITextStoreACP == riid, E_INVALIDARG); - - if (!my_Sink) - { - HRESULT hr = punk->QueryInterface(&my_Sink); - ENSURE(SUCCEEDED(hr) && my_Sink, E_UNEXPECTED); - } - else - { - CComPtr Unknown_1, Unknown_2; - punk->QueryInterface(&Unknown_1); - my_Sink->QueryInterface(&Unknown_2); - if (Unknown_1 != Unknown_2) - return CONNECT_E_ADVISELIMIT; - } - my_Sink_Mask = dwMask; - return S_OK; -} - -STDMETHODIMP TSF::TSF_Text_Store::UnadviseSink(IUnknown *punk) -{ - ENSURE(punk, E_INVALIDARG); - ENSURE(my_Sink, CONNECT_E_NOCONNECTION); - - CComPtr Unknown_1, Unknown_2; - punk->QueryInterface(&Unknown_1); - my_Sink->QueryInterface(&Unknown_2); - - if (Unknown_1 != Unknown_2) - return CONNECT_E_NOCONNECTION; - - my_Sink = NULL; - my_Sink_Mask = 0; - return S_OK; -} - -STDMETHODIMP TSF::TSF_Text_Store::RequestLock(DWORD dwLockFlags, HRESULT *phrSession) -{ - ENSURE(my_Sink, E_FAIL); - ENSURE(phrSession, E_INVALIDARG); - if (my_Lock) - { - if (TS_LF_READ == (my_Lock & TS_LF_READWRITE) - && TS_LF_READWRITE == (dwLockFlags & TS_LF_READWRITE) - && !(dwLockFlags & TS_LF_SYNC)) - { - *phrSession = TS_S_ASYNC; - my_Lock_Queued = dwLockFlags & (~TS_LF_SYNC); - } - else - { - *phrSession = TS_E_SYNCHRONOUS; - return E_FAIL; - } - } - else - { - my_Lock = dwLockFlags & (~TS_LF_SYNC); - *phrSession = my_Sink->OnLockGranted(my_Lock); - while (my_Lock_Queued) - { - my_Lock = my_Lock_Queued; - my_Lock_Queued = 0; - my_Sink->OnLockGranted(my_Lock); - } - my_Lock = 0; - } - return S_OK; -} - -STDMETHODIMP TSF::TSF_Text_Store::GetStatus(TS_STATUS *pdcs) -{ - ENSURE(pdcs, E_INVALIDARG); - pdcs->dwDynamicFlags = 0; - pdcs->dwStaticFlags = TS_SS_NOHIDDENTEXT; - return S_OK; -} - -STDMETHODIMP TSF::TSF_Text_Store::QueryInsert(LONG acpTestStart, LONG acpTestEnd, ULONG cch, LONG *pacpResultStart, LONG *pacpResultEnd) -{ - ENSURE(0 <= acpTestStart && acpTestStart <= acpTestEnd && pacpResultStart && pacpResultEnd, E_INVALIDARG); - - *pacpResultStart = acpTestStart; - *pacpResultEnd = acpTestStart + cch; - return S_OK; -} - -STDMETHODIMP TSF::TSF_Text_Store::GetSelection(ULONG ulIndex, ULONG ulCount, TS_SELECTION_ACP *pSelection, ULONG *pcFetched) -{ - ENSURE(TS_LF_READ == (my_Lock && TS_LF_READ), TS_E_NOLOCK); - ENSURE(ulCount && pSelection && pcFetched, E_INVALIDARG); - - *pcFetched = 0; - ENSURE(TS_DEFAULT_SELECTION == ulIndex || 0 == ulIndex, TS_E_NOSELECTION); - if (my_Composition_View) - { - *pSelection = my_Composition_Selection; - } - else - { - //TODO - } - *pcFetched = 1; - return S_OK; -} - -STDMETHODIMP TSF::TSF_Text_Store::SetSelection(ULONG ulCount, const TS_SELECTION_ACP *pSelection) -{ - return E_NOTIMPL; -} - -STDMETHODIMP TSF::TSF_Text_Store::GetText(LONG acpStart, LONG acpEnd, WCHAR *pchPlain, ULONG cchPlainReq, ULONG *pcchPlainRet, TS_RUNINFO *prgRunInfo, ULONG cRunInfoReq, ULONG *pcRunInfoRet, LONG *pacpNext) -{ - ENSURE(TS_LF_READ == (my_Lock & TS_LF_READ), TS_E_NOLOCK); - ENSURE(pcchPlainRet && (pchPlain || prgRunInfo) - && (!cchPlainReq == !pchPlain) - && (!cRunInfoReq == !prgRunInfo), E_INVALIDARG); - ENSURE(0 <= acpStart && -1 <= acpEnd - && (-1 == acpEnd || acpStart <= acpEnd), TS_E_INVALIDPOS); - - *pcchPlainRet = 0; - if (pchPlain && cchPlainReq) *pchPlain = 0; - if (pcRunInfoRet) *pcRunInfoRet = 0; - //TODO - return S_OK; -} - -STDMETHODIMP TSF::TSF_Text_Store::SetText(DWORD dwFlags, LONG acpStart, LONG acpEnd, const WCHAR *pchText, ULONG cch, TS_TEXTCHANGE *pChange) -{ - return E_NOTIMPL; -} - -STDMETHODIMP TSF::TSF_Text_Store::GetFormattedText(LONG acpStart, LONG acpEnd, IDataObject **ppDataObject) -{ - //not needed - return E_NOTIMPL; -} - -STDMETHODIMP TSF::TSF_Text_Store::GetEmbedded(LONG acpPos, REFGUID rguidService, REFIID riid, IUnknown **ppunk) -{ - //not needed - return E_NOTIMPL; -} - -STDMETHODIMP TSF::TSF_Text_Store::QueryInsertEmbedded(const GUID *pguidService, const FORMATETC *pFormatEtc, BOOL *pfInsertable) -{ - if (!pfInsertable) - return E_INVALIDARG; - - //Not supported - *pfInsertable = FALSE; - return E_NOTIMPL; -} - -STDMETHODIMP TSF::TSF_Text_Store::InsertEmbedded(DWORD dwFlags, LONG acpStart, LONG acpEnd, IDataObject *pDataObject, TS_TEXTCHANGE *pChange) -{ - return E_NOTIMPL; -} - -STDMETHODIMP TSF::TSF_Text_Store::InsertTextAtSelection(DWORD dwFlags, const WCHAR *pchText, ULONG cch, LONG *pacpStart, LONG *pacpEnd, TS_TEXTCHANGE *pChange) -{ - return E_NOTIMPL; -} - -STDMETHODIMP TSF::TSF_Text_Store::InsertEmbeddedAtSelection(DWORD dwFlags, IDataObject *pDataObject, LONG *pacpStart, LONG *pacpEnd, TS_TEXTCHANGE *pChange) -{ - //not needed - return E_NOTIMPL; -} - -STDMETHODIMP TSF::TSF_Text_Store::RequestSupportedAttrs(DWORD dwFlags, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs) -{ - //not needed - return E_NOTIMPL; -} - -STDMETHODIMP TSF::TSF_Text_Store::RequestAttrsAtPosition(LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs, DWORD dwFlags) -{ - //not needed - return E_NOTIMPL; -} - -STDMETHODIMP TSF::TSF_Text_Store::RequestAttrsTransitioningAtPosition(LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs, DWORD dwFlags) -{ - //not needed - return E_NOTIMPL; -} - -STDMETHODIMP TSF::TSF_Text_Store::FindNextAttrTransition(LONG acpStart, LONG acpHalt, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs, DWORD dwFlags, LONG *pacpNext, BOOL *pfFound, LONG *plFoundOffset) -{ - //not needed - return E_NOTIMPL; -} - -STDMETHODIMP TSF::TSF_Text_Store::RetrieveRequestedAttrs(ULONG ulCount, TS_ATTRVAL *paAttrVals, ULONG *pcFetched) -{ - //not needed - return E_NOTIMPL; -} - -STDMETHODIMP TSF::TSF_Text_Store::GetEndACP(LONG *pacp) -{ - return E_NOTIMPL; -} - -STDMETHODIMP TSF::TSF_Text_Store::GetActiveView(TsViewCookie *pvcView) -{ - return E_NOTIMPL; -} - -STDMETHODIMP TSF::TSF_Text_Store::GetACPFromPoint(TsViewCookie vcView, const POINT *ptScreen, DWORD dwFlags, LONG *pacp) -{ - return E_NOTIMPL; -} - -STDMETHODIMP TSF::TSF_Text_Store::GetTextExt(TsViewCookie vcView, LONG acpStart, LONG acpEnd, RECT *prc, BOOL *pfClipped) -{ - return E_NOTIMPL; -} - -STDMETHODIMP TSF::TSF_Text_Store::GetScreenExt(TsViewCookie vcView, RECT *prc) -{ - return E_NOTIMPL; -} - -STDMETHODIMP TSF::TSF_Text_Store::GetWnd(TsViewCookie vcView, HWND *phwnd) -{ - return E_NOTIMPL; -} - -STDMETHODIMP TSF::TSF_Text_Store::OnStartComposition(ITfCompositionView *pComposition, BOOL *pfOk) -{ - return E_NOTIMPL; -} - -STDMETHODIMP TSF::TSF_Text_Store::OnUpdateComposition(ITfCompositionView *pComposition, ITfRange *pRangeNew) -{ - return E_NOTIMPL; -} - -STDMETHODIMP TSF::TSF_Text_Store::OnEndComposition(ITfCompositionView *pComposition) -{ - return E_NOTIMPL; -} - -TSF::TSF_Text_Store::TSF_Text_Store() : my_Reference_Count(1), - my_Edit_Cookie(0), - my_Lock(0), - my_Lock_Queued(0) -{ - -} - -TSF::TSF_Text_Store::~TSF_Text_Store() -{ - -} - -void TSF::TSF_Text_Store::Initialize() -{ - if (FAILED(Thread_Manager->CreateDocumentMgr(&my_Document_Manager))) - throw std::runtime_error("Failed to create document manager"); - - if (FAILED(my_Document_Manager->CreateContext(Client_Id, 0, static_cast(this), &my_Context, &my_Edit_Cookie))) - throw std::runtime_error("Failed to create document context"); - - if (FAILED(my_Document_Manager->Push(my_Context))) - throw std::runtime_error("Failed to push context"); -} - -void TSF::TSF_Text_Store::Finalize() -{ - -} diff -r 518d1679d2d0 -r 102675835e08 EXCLUDE/GLTSF/src/Video_Mode.cpp --- a/EXCLUDE/GLTSF/src/Video_Mode.cpp Sun Aug 22 12:39:27 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,100 +0,0 @@ -#include "Video_Mode.hpp" -#include -#include -#define WIN32_LEAN_AND_MEAN -#include - -namespace -{ - - typedef std::vector 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()); - } -} diff -r 518d1679d2d0 -r 102675835e08 EXCLUDE/GLTSF/src/Window.cpp --- a/EXCLUDE/GLTSF/src/Window.cpp Sun Aug 22 12:39:27 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,281 +0,0 @@ -#include "Window.hpp" -#include - -#pragma comment(lib, "opengl32.lib") - -const wchar_t *Window::Window_Class_Name = L"GLTSF"; - -Window::Window() : my_Handle(0), - my_Device_Context(0), - my_GL_Context(0), - my_Class_Registered(false), - my_Listener(0) -{ - -} - -Window::~Window() -{ - Finalize(); - Show_Cursor(); -} - -void Window::Initialize(const std::wstring &Title, const Video_Mode &Mode, bool Fullscreen) -{ - Finalize(); - - my_Video_Mode = Mode; - if (!my_Video_Mode.Is_Valid()) - throw std::runtime_error("Invalid video mode"); - - my_Fullscreen = Fullscreen; - Register_Class(); - Create_Window(Title, Mode, Fullscreen); -} - -void Window::Finalize() -{ - Destroy_Window(); - Unregister_Class(); -} - -void Window::Set_Listener(Window_Listener *Listener) -{ - my_Listener = Listener; -} - -void Window::Register_Class() -{ - WNDCLASSEXW Window_Class = {0}; - Window_Class.cbSize = sizeof(Window_Class); - Window_Class.style = 0; - Window_Class.lpfnWndProc = &Window::Window_Procedure; - Window_Class.cbClsExtra = 0; - Window_Class.cbWndExtra = 0; - Window_Class.hInstance = GetModuleHandle(NULL); - Window_Class.hIcon = NULL; - Window_Class.hCursor = NULL; - Window_Class.hbrBackground = NULL; - Window_Class.lpszMenuName = NULL; - Window_Class.lpszClassName = Window_Class_Name; - Window_Class.hIconSm = NULL; - if (0 == RegisterClassExW(&Window_Class)) - throw std::runtime_error("Failed to register window class"); - - my_Class_Registered = true; -} - -void Window::Unregister_Class() -{ - if (my_Class_Registered) - { - if (0 == UnregisterClassW(Window_Class_Name, GetModuleHandle(NULL))) - printf("Warning: Failed to unregister window class\n"); - - my_Class_Registered = false; - } -} - -void Window::Create_Window(const std::wstring &Title, const Video_Mode &Mode, bool Fullscreen) -{ - HDC Screen_DC = GetDC(NULL); - int Left = (GetDeviceCaps(Screen_DC, HORZRES) - my_Video_Mode.Width) / 2; - int Top = (GetDeviceCaps(Screen_DC, VERTRES) - my_Video_Mode.Height) / 2; - int Width = my_Video_Mode.Width; - int Height = my_Video_Mode.Height; - ReleaseDC(NULL, Screen_DC); - - DWORD Style = WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU; - if (!my_Fullscreen) - { - RECT Rect = {0, 0, Width, Height}; - AdjustWindowRect(&Rect, Style, false); - Width = Rect.right - Rect.left; - Height = Rect.bottom - Rect.top; - } - my_Handle = CreateWindowW(Window_Class_Name, Title.c_str(), Style, Left, Top, Width, Height, NULL, NULL, GetModuleHandle(NULL), this); - if (!my_Handle) - throw std::runtime_error("Failed to create window"); - - if (Fullscreen) - Switch_To_Fullscreen(Mode); - - Create_Context(Mode); - - RECT Rect = {0}; - GetClientRect(my_Handle, &Rect); - //TODO: ... -} - -void Window::Destroy_Window() -{ - Destroy_Context(); - if (my_Handle) - { - DestroyWindow(my_Handle); - my_Handle = 0; - - if (my_Fullscreen) - ChangeDisplaySettings(NULL, 0); - } -} - -void Window::Create_Context(const Video_Mode &Mode) -{ - my_Device_Context = GetDC(my_Handle); - if (!my_Device_Context) - throw std::runtime_error("Failed to get device context"); - - PIXELFORMATDESCRIPTOR Pixel_Descriptor = {0}; - Pixel_Descriptor.nSize = sizeof(Pixel_Descriptor); - Pixel_Descriptor.nVersion = 1; - Pixel_Descriptor.iLayerType = PFD_MAIN_PLANE; - Pixel_Descriptor.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; - Pixel_Descriptor.iPixelType = PFD_TYPE_RGBA; - Pixel_Descriptor.cColorBits = static_cast(Mode.Bits_Per_Pixel); - Pixel_Descriptor.cDepthBits = 24; - Pixel_Descriptor.cStencilBits = 8; - Pixel_Descriptor.cAlphaBits = Mode.Bits_Per_Pixel == 32 ? 8 : 0; - - int Best_Format = ChoosePixelFormat(my_Device_Context, &Pixel_Descriptor); - if (0 == Best_Format) - throw std::runtime_error("Failed to find suitable pixel format"); - - PIXELFORMATDESCRIPTOR Actual_Format = {0}; - Actual_Format.nSize = sizeof(Actual_Format); - Actual_Format.nVersion = 1; - DescribePixelFormat(my_Device_Context, Best_Format, sizeof(Actual_Format), &Actual_Format); - if (!SetPixelFormat(my_Device_Context, Best_Format, &Actual_Format)) - throw std::runtime_error("Failed to set device pixel format"); - - my_GL_Context = wglCreateContext(my_Device_Context); - if (!my_GL_Context) - throw std::runtime_error("Failed to create OpenGL context"); - - wglMakeCurrent(my_Device_Context, my_GL_Context); -} - -void Window::Destroy_Context() -{ - if (my_GL_Context) - { - wglDeleteContext(my_GL_Context); - my_GL_Context = 0; - } - if (my_Device_Context) - { - ReleaseDC(my_Handle, my_Device_Context); - my_Device_Context = 0; - } -} - -void Window::Switch_To_Fullscreen(const Video_Mode &Mode) -{ - DEVMODE Device_Mode = {0}; - Device_Mode.dmSize = sizeof(Device_Mode); - Device_Mode.dmPelsWidth = Mode.Width; - Device_Mode.dmPelsHeight = Mode.Height; - Device_Mode.dmBitsPerPel = Mode.Bits_Per_Pixel; - Device_Mode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; - - if (DISP_CHANGE_SUCCESSFUL != ChangeDisplaySettings(&Device_Mode, CDS_FULLSCREEN)) - throw std::runtime_error("Failed to change to fullscreen mode"); - - SetWindowLong(my_Handle, GWL_STYLE, WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS); - SetWindowLong(my_Handle, GWL_EXSTYLE, WS_EX_APPWINDOW); - - SetWindowPos(my_Handle, HWND_TOP, 0, 0, Mode.Width, Mode.Height, SWP_FRAMECHANGED); -} - -LRESULT CALLBACK Window::Window_Procedure(HWND Handle, UINT Message, WPARAM wParam, LPARAM lParam) -{ - switch (Message) - { - case WM_CREATE: - { - LONG This = reinterpret_cast(reinterpret_cast(lParam)->lpCreateParams); - SetWindowLongPtr(Handle, GWLP_USERDATA, This); - return 0; - } - break; - case WM_DESTROY: - PostQuitMessage(0); - return 0; - break; - default: - { - Window* Win = reinterpret_cast(GetWindowLongPtr(Handle, GWLP_USERDATA)); - if (Win) - return Win->Handle_Message(Handle, Message, wParam, lParam); - } - break; - } - return DefWindowProcW(Handle, Message, wParam, lParam); -} - -#define Call_Listener(x)\ - if (my_Listener) my_Listener->x - -LRESULT Window::Handle_Message(HWND Handle, UINT Message, WPARAM wParam, LPARAM lParam) -{ - switch (Message) - { - case WM_SIZE: - Call_Listener(On_Resized(LOWORD(lParam), HIWORD(lParam))); - break; - case WM_CLOSE: - Call_Listener(On_Close()); - break; - case WM_KEYDOWN: - Call_Listener(On_Key_Down(wParam)); - break; - case WM_KEYUP: - Call_Listener(On_Key_Up(wParam)); - break; - case WM_CHAR: - Call_Listener(On_Char(wParam)); - break; - default: - return DefWindowProcW(Handle, Message, wParam, lParam); - break; - } - return 0; -} - -void Window::Show() -{ - if (my_Handle) - ShowWindow(my_Handle, SW_SHOW); -} - -void Window::Hide() -{ - if (my_Handle) - ShowWindow(my_Handle, SW_HIDE); -} - -void Window::Handle_Events() -{ - MSG Message = {0}; - while (PeekMessageW(&Message, NULL, 0, 0, PM_REMOVE)) - { - TranslateMessage(&Message); - DispatchMessageW(&Message); - } -} - -void Window::Display() -{ - if (my_Device_Context && my_GL_Context) - SwapBuffers(my_Device_Context); -} - -void Window::Show_Cursor() -{ - ShowCursor(TRUE); -} - -void Window::Hide_Cursor() -{ - ShowCursor(FALSE); -}