<commit_before>#include "Window.h"
#include "GLState.h"
#include <exception>
#include <thread>

namespace ojgl {

Window::Window(unsigned width, unsigned height, bool fullScreen)
    : _width(width)
    , _height(height)
{
    ShowCursor(false);
 
	_hWnd = CreateOpenGLWindow("minimal", 0, 0, PFD_TYPE_RGBA, 0, fullScreen);
    if (_hWnd == nullptr) {
        exit(1);
    }

    _hDC = GetDC(_hWnd);
    _hRC = wglCreateContext(_hDC);
    wglMakeCurrent(_hDC, _hRC);
    ShowWindow(_hWnd, 1);

    Window* pThis = this;
    SetLastError(0);
    if (!SetWindowLongPtr(_hWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(pThis))) {
        if (GetLastError() != 0) {
            throw std::runtime_error("SetWindowLongPtr failed in Window");
        }
    }
}

Window::~Window()
{
    wglMakeCurrent(nullptr, nullptr);
    ReleaseDC(_hWnd, _hDC);
    wglDeleteContext(_hRC);
    DestroyWindow(_hWnd);
}

void Window::getMessages()
{
    while (PeekMessage(&_msg, nullptr, 0, 0, PM_REMOVE)) {
        TranslateMessage(&_msg);
        DispatchMessage(&_msg);
    }
}

std::vector<UINT> Window::getPressedKeys()
{
    auto keys = _keys;
    _keys.clear();
    return keys;
}

HWND Window::CreateFullscreenWindow(HWND hwnd, HINSTANCE hInstance)
{
    HMONITOR hmon = MonitorFromWindow(hwnd,
        MONITOR_DEFAULTTONEAREST);
    MONITORINFO mi = { sizeof(mi) };
    if (!GetMonitorInfo(hmon, &mi)) {
        return nullptr;
    }
    return CreateWindow(TEXT("static"),
        TEXT("something interesting might go here"),
        WS_POPUP | WS_VISIBLE,
        mi.rcMonitor.left,
        mi.rcMonitor.top,
        mi.rcMonitor.right - mi.rcMonitor.left,
        mi.rcMonitor.bottom - mi.rcMonitor.top,
        hwnd, nullptr, hInstance, nullptr);
}

HWND Window::CreateOpenGLWindow(const char* title, int x, int y, BYTE type, DWORD flags, bool fullScreen)
{
    int pf;
    HDC hDC;
    HWND hWnd;
    WNDCLASS wc;
    PIXELFORMATDESCRIPTOR pfd;
    static HINSTANCE hInstance = nullptr;

    /* only register the window class once - use hInstance as a flag. */
    if (!hInstance) {
        hInstance = GetModuleHandle(NULL);
        wc.style = CS_OWNDC;
        wc.lpfnWndProc = (WNDPROC)WindowProc;
        wc.cbClsExtra = 0;
        wc.cbWndExtra = 0;
        wc.hInstance = hInstance;
        wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
        wc.hCursor = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = NULL;
        wc.lpszMenuName = NULL;
        wc.lpszClassName = L"OpenGL";

        if (!RegisterClass(&wc)) {
            MessageBox(NULL, L"RegisterClass() failed:  "
                             "Cannot register window class.",
                L"Error", MB_OK);
            return NULL;
        }
    }

    hWnd = CreateWindow(L"OpenGL", L"Hej", WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
        x, y, this->_width, this->_height, NULL, NULL, hInstance, NULL);
    if (fullScreen) {
        hWnd = CreateFullscreenWindow(hWnd, hInstance);
    }

    if (hWnd == NULL) {
        MessageBox(NULL, L"CreateWindow() failed:  Cannot create a window.",
            L"Error", MB_OK);
        return NULL;
    }

    hDC = GetDC(hWnd);

    /* there is no guarantee that the contents of the stack that become
		the pfd are zeroed, therefore _make sure_ to clear these bits. */
    memset(&pfd, 0, sizeof(pfd));
    pfd.nSize = sizeof(pfd);<commit_msg>Changed title<commit_after>#include "Window.h"
#include "GLState.h"
#include <exception>
#include <thread>

namespace ojgl {

Window::Window(unsigned width, unsigned height, bool fullScreen)
    : _width(width)
    , _height(height)
{
    ShowCursor(false);
 
	_hWnd = CreateOpenGLWindow("minimal", 0, 0, PFD_TYPE_RGBA, 0, fullScreen);
    if (_hWnd == nullptr) {
        exit(1);
    }

    _hDC = GetDC(_hWnd);
    _hRC = wglCreateContext(_hDC);
    wglMakeCurrent(_hDC, _hRC);
    ShowWindow(_hWnd, 1);

    Window* pThis = this;
    SetLastError(0);
    if (!SetWindowLongPtr(_hWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(pThis))) {
        if (GetLastError() != 0) {
            throw std::runtime_error("SetWindowLongPtr failed in Window");
        }
    }
}

Window::~Window()
{
    wglMakeCurrent(nullptr, nullptr);
    ReleaseDC(_hWnd, _hDC);
    wglDeleteContext(_hRC);
    DestroyWindow(_hWnd);
}

void Window::getMessages()
{
    while (PeekMessage(&_msg, nullptr, 0, 0, PM_REMOVE)) {
        TranslateMessage(&_msg);
        DispatchMessage(&_msg);
    }
}

std::vector<UINT> Window::getPressedKeys()
{
    auto keys = _keys;
    _keys.clear();
    return keys;
}

HWND Window::CreateFullscreenWindow(HWND hwnd, HINSTANCE hInstance)
{
    HMONITOR hmon = MonitorFromWindow(hwnd,
        MONITOR_DEFAULTTONEAREST);
    MONITORINFO mi = { sizeof(mi) };
    if (!GetMonitorInfo(hmon, &mi)) {
        return nullptr;
    }
    return CreateWindow(TEXT("static"),
        TEXT("something interesting might go here"),
        WS_POPUP | WS_VISIBLE,
        mi.rcMonitor.left,
        mi.rcMonitor.top,
        mi.rcMonitor.right - mi.rcMonitor.left,
        mi.rcMonitor.bottom - mi.rcMonitor.top,
        hwnd, nullptr, hInstance, nullptr);
}

HWND Window::CreateOpenGLWindow(const char* title, int x, int y, BYTE type, DWORD flags, bool fullScreen)
{
    int pf;
    HDC hDC;
    HWND hWnd;
    WNDCLASS wc;
    PIXELFORMATDESCRIPTOR pfd;
    static HINSTANCE hInstance = nullptr;

    /* only register the window class once - use hInstance as a flag. */
    if (!hInstance) {
        hInstance = GetModuleHandle(NULL);
        wc.style = CS_OWNDC;
        wc.lpfnWndProc = (WNDPROC)WindowProc;
        wc.cbClsExtra = 0;
        wc.cbWndExtra = 0;
        wc.hInstance = hInstance;
        wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
        wc.hCursor = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = NULL;
        wc.lpszMenuName = NULL;
        wc.lpszClassName = L"OpenGL";

        if (!RegisterClass(&wc)) {
            MessageBox(NULL, L"RegisterClass() failed:  "
                             "Cannot register window class.",
                L"Error", MB_OK);
            return NULL;
        }
    }

    hWnd = CreateWindow(L"OpenGL", L"Eldur - OJ", WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
        x, y, this->_width, this->_height, NULL, NULL, hInstance, NULL);
    if (fullScreen) {
        hWnd = CreateFullscreenWindow(hWnd, hInstance);
    }

    if (hWnd == NULL) {
        MessageBox(NULL, L"CreateWindow() failed:  Cannot create a window.",
            L"Error", MB_OK);
        return NULL;
    }

    hDC = GetDC(hWnd);

    /* there is no guarantee that the contents of the stack that become
		the pfd are zeroed, therefore _make sure_ to clear these bits. */
    memset(&pfd, 0, sizeof(pfd));
    pfd.nSize = sizeof(pfd);
{'fraction_non_alphanumeric': 0.1207586309082827, 'fraction_numerical': 0.0035560823825751963, 'mean_word_length': 2.7067545304777596, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6406563', 'n_tokens_mistral': 2376, 'n_tokens_neox': 2303, 'n_words': 517}