<commit_before>// Copyright (C) 2017 <NAME>
// This file is part of the Ouzel engine.

#include "CursorResourceWin.h"
#include "utils/Log.h"

namespace ouzel
{
    namespace input
    {
        CursorResourceWin::~CursorResourceWin()
        {
            if (cursor && !shared) DestroyCursor(cursor);
        }

        bool CursorResourceWin::upload()
        {
            std::lock_guard<std::mutex> lock(uploadMutex);

            if (dirty)
            {
                if (cursor)
                {
                    if (!shared) DestroyCursor(cursor);
                    cursor = 0;
                }

                if (data.empty())
                {
                    switch (systemCursor)
                    {
                        case SystemCursor::DEFAULT:
                            cursor = LoadCursor(nullptr, IDC_ARROW);
                            break;
                        case SystemCursor::ARROW:
                            cursor = LoadCursor(nullptr, IDC_ARROW);
                            break;
                        case SystemCursor::HAND:
                            cursor = LoadCursor(nullptr, IDC_HAND);
                            break;
                        case SystemCursor::HORIZONTAL_RESIZE:
                            cursor = LoadCursor(nullptr, IDC_SIZEWE);
                            break;
                        case SystemCursor::VERTICAL_RESIZE:
                            cursor = LoadCursor(nullptr, IDC_SIZENS);
                            break;
                        case SystemCursor::CROSS:
                            cursor = LoadCursor(nullptr, IDC_CROSS);
                            break;
                        case SystemCursor::I_BEAM:
                            cursor = LoadCursor(nullptr, IDC_IBEAM);
                            break;
                    }

                    if (!cursor)
                    {
                        Log(Log::Level::ERR) << "Failed to load cursor";
                        return false;
                    }

                    shared = true;
                }
                else
                {

                }

                dirty = false;
            }

            return true;
        }
    } // namespace input
} // namespace ouzel
<commit_msg>Implement cursor loading on Windows<commit_after>// Copyright (C) 2017 <NAME>
// This file is part of the Ouzel engine.

#include "CursorResourceWin.h"
#include "utils/Log.h"

namespace ouzel
{
    namespace input
    {
        CursorResourceWin::~CursorResourceWin()
        {
            if (cursor && !shared) DestroyCursor(cursor);
        }

        bool CursorResourceWin::upload()
        {
            std::lock_guard<std::mutex> lock(uploadMutex);

            if (dirty)
            {
                if (cursor)
                {
                    if (!shared) DestroyCursor(cursor);
                    cursor = 0;
                }

                if (data.empty())
                {
                    switch (systemCursor)
                    {
                        case SystemCursor::DEFAULT:
                            cursor = LoadCursor(nullptr, IDC_ARROW);
                            break;
                        case SystemCursor::ARROW:
                            cursor = LoadCursor(nullptr, IDC_ARROW);
                            break;
                        case SystemCursor::HAND:
                            cursor = LoadCursor(nullptr, IDC_HAND);
                            break;
                        case SystemCursor::HORIZONTAL_RESIZE:
                            cursor = LoadCursor(nullptr, IDC_SIZEWE);
                            break;
                        case SystemCursor::VERTICAL_RESIZE:
                            cursor = LoadCursor(nullptr, IDC_SIZENS);
                            break;
                        case SystemCursor::CROSS:
                            cursor = LoadCursor(nullptr, IDC_CROSS);
                            break;
                        case SystemCursor::I_BEAM:
                            cursor = LoadCursor(nullptr, IDC_IBEAM);
                            break;
                    }

                    if (!cursor)
                    {
                        Log(Log::Level::ERR) << "Failed to load cursor";
                        return false;
                    }

                    shared = true;
                }
                else
                {
                    BITMAPV5HEADER bitmapHeader;
                    ZeroMemory(&bitmapHeader, sizeof(bitmapHeader));
                    bitmapHeader.bV5Size = sizeof(BITMAPV5HEADER);
                    bitmapHeader.bV5Width = static_cast<LONG>(size.v[0]);
                    bitmapHeader.bV5Height = -static_cast<LONG>(size.v[1]);
                    bitmapHeader.bV5Planes = 1;
                    bitmapHeader.bV5BitCount = 32;
                    bitmapHeader.bV5Compression = BI_BITFIELDS;
                    bitmapHeader.bV5RedMask = 0x00ff0000;
                    bitmapHeader.bV5GreenMask = 0x000ff00;
                    bitmapHeader.bV5BlueMask = 0x000000ff;
                    bitmapHeader.bV5AlphaMask = 0xff000000;

                    HDC dc = GetDC(nullptr);
                    unsigned char* target = nullptr;
                    HBITMAP color = CreateDIBSection(dc,
                                                     reinterpret_cast<BITMAPINFO*>(&bitmapHeader),
                                                     DIB_RGB_COLORS,
                                                     reinterpret_cast<void**>(&target),
                                                     NULL,
                                                     static_cast<DWORD>(0));
                    ReleaseDC(nullptr, dc);

                    if (!color)
                    {
                        Log(Log::Level::ERR) << "Failed to create RGBA bitmap";
                        return false;
                    }

                    HBITMAP mask = CreateBitmap(static_cast<LONG>(size.v[0]),
                                                static_cast<LONG>(size.v[1]),
                                                1, 1, nullptr);
                    if (!mask)
                    {
                        Log(Log::Level::ERR) << "Failed to create mask bitmap";
                        DeleteObject(color);
                        return false;
                    }

                    for (int i = 0; i < static_cast<int>(size.v[0]) * static_cast<int>(size.v[1]); i++)
                    {
                        target[i * 4 + 0] = data[i * 4 + 2];
                        target[i * 4 + 1] = data[i * 4 + 1];
                        target[i * 4 + 2] = data[i * 4 + 0];
                        target[i * 4 + 3] = data[i * 4 + 3];
                    }

                    ICONINFO iconInfo;
                    ZeroMemory(&iconInfo, sizeof(iconInfo));
                    iconInfo.fIcon = FALSE;
                    iconInfo.xHotspot = static_cast<DWORD>(hotSpot.v[0]);
                    iconInfo.yHotspot = static_cast<int>(size.v[1]) - static_cast<DWORD>(hotSpot.v[1]) - 1;
                    iconInfo.hbmMask = mask;
                    iconInfo.hbmColor = color;

                    cursor = CreateIconIndirect(&iconInfo);

                    DeleteObject(color);
                    DeleteObject(mask);

                    if (!cursor)
                    {
                        Log(Log::Level::ERR) << "Failed to create cursor";
                        return false;
                    }

                    shared = false;
                }

                dirty = false;
            }

            return true;
        }
    } // namespace input
} // namespace ouzel

{'fraction_non_alphanumeric': 0.08204732510288065, 'fraction_numerical': 0.010545267489711935, 'mean_word_length': 0.8785024154589371, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2222228', 'n_tokens_mistral': 1889, 'n_tokens_neox': 1731, 'n_words': 346}