Ticket #3875: 3875_cursor_hidpi_scaling_1.patch

File 3875_cursor_hidpi_scaling_1.patch, 6.6 KB (added by Dario Ostuni, 7 years ago)
  • binaries/data/mods/public/gui/credits/texts/programming.json

    diff --git a/binaries/data/mods/public/gui/credits/texts/programming.json b/binaries/data/mods/public/gui/credits/texts/programming.json
    index 87f5cf2b..ce1d5042 100644
    a b  
    5353            {"name": "Daniel Trevitz"},
    5454            {"nick": "DanCar", "name": "Daniel Cardenas"},
    5555            {"nick": "danger89", "name": "Melroy van den Berg"},
     56            {"nick": "Dariost", "name": "Dario Ostuni"},
    5657            {"nick": "Dave", "name": "David Protasowski"},
    5758            {"nick": "dax", "name": "Dacian Fiordean"},
    5859            {"nick": "deebee", "name": "Deepak Anthony"},
  • source/lib/res/graphics/cursor.cpp

    diff --git a/source/lib/res/graphics/cursor.cpp b/source/lib/res/graphics/cursor.cpp
    index c02ca42e..4d0ad944 100644
    a b class SDLCursor  
    5252    SDL_Cursor* cursor;
    5353
    5454public:
    55     Status create(const PIVFS& vfs, const VfsPath& pathname, int hotspotx_, int hotspoty_)
     55    Status create(const PIVFS& vfs, const VfsPath& pathname, int hotspotx_, int hotspoty_, double scale)
    5656    {
    5757        shared_ptr<u8> file; size_t fileSize;
    5858        RETURN_STATUS_IF_ERR(vfs->LoadFile(pathname, file, fileSize));
    public:  
    7070        surface = SDL_CreateRGBSurfaceFrom(bgra_img, (int)t.m_Width, (int)t.m_Height, 32, (int)t.m_Width*4, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
    7171        if (!surface)
    7272            return ERR::FAIL;
     73        if (scale != 1.0)
     74        {
     75            SDL_Surface* scaled_surface = SDL_CreateRGBSurface(0, surface->w * scale, surface->h * scale, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
     76            if (!scaled_surface)
     77                return ERR::FAIL;
     78            if (SDL_BlitScaled(surface, NULL, scaled_surface, NULL))
     79                return ERR::FAIL;
     80            SDL_FreeSurface(surface);
     81            surface = scaled_surface;
     82        }
    7383        cursor = SDL_CreateColorCursor(surface, hotspotx_, hotspoty_);
    7484        if (!cursor)
    7585            return ERR::FAIL;
    class GLCursor  
    99109    int hotspotx, hotspoty;
    100110
    101111public:
    102     Status create(const PIVFS& vfs, const VfsPath& pathname, int hotspotx_, int hotspoty_)
     112    Status create(const PIVFS& vfs, const VfsPath& pathname, int hotspotx_, int hotspoty_, double scale)
    103113    {
    104114        ht = ogl_tex_load(vfs, pathname);
    105115        RETURN_STATUS_IF_ERR(ht);
    106116
    107117        size_t width, height;
    108118        (void)ogl_tex_get_size(ht, &width, &height, 0);
    109         w = (GLint)width;
    110         h = (GLint)height;
     119        w = (GLint)(width * scale);
     120        h = (GLint)(height * scale);
    111121
    112122        hotspotx = hotspotx_; hotspoty = hotspoty_;
    113123
    enum CursorKind  
    169179
    170180struct Cursor
    171181{
     182    double scale;
     183
    172184    // require kind == CK_OpenGL after reload
    173185    bool forceGL;
    174186
    H_TYPE_DEFINE(Cursor);  
    185197
    186198static void Cursor_init(Cursor* c, va_list args)
    187199{
     200    c->scale = va_arg(args, double);
    188201    c->forceGL = (va_arg(args, int) != 0);
    189202}
    190203
    static Status Cursor_reload(Cursor* c, const PIVFS& vfs, const VfsPath& name, Ha  
    227240    const VfsPath pathnameImage = pathname.ChangeExtension(L".png");
    228241
    229242    // try loading as SDL2 cursor
    230     if (!c->forceGL && c->sdl_cursor.create(vfs, pathnameImage, hotspotx, hotspoty) == INFO::OK)
     243    if (!c->forceGL && c->sdl_cursor.create(vfs, pathnameImage, hotspotx, hotspoty, c->scale) == INFO::OK)
    231244        c->kind = CK_SDL;
    232245    // fall back to GLCursor (system cursor code is disabled or failed)
    233     else if(c->gl_cursor.create(vfs, pathnameImage, hotspotx, hotspoty) == INFO::OK)
     246    else if(c->gl_cursor.create(vfs, pathnameImage, hotspotx, hotspoty, c->scale) == INFO::OK)
    234247    {
    235248        c->kind = CK_OpenGL;
    236249    }
    static Status Cursor_to_string(const Cursor* c, wchar_t* buf)  
    297310// in other words, we continually create/free the cursor resource in
    298311// cursor_draw and trust h_mgr's caching to absorb it.
    299312
    300 static Handle cursor_load(const PIVFS& vfs, const VfsPath& name, bool forceGL)
     313static Handle cursor_load(const PIVFS& vfs, const VfsPath& name, double scale, bool forceGL)
    301314{
    302     return h_alloc(H_Cursor, vfs, name, 0, (int)forceGL);
     315    return h_alloc(H_Cursor, vfs, name, 0, scale, (int)forceGL);
    303316}
    304317
    305318void cursor_shutdown()
    static Status cursor_free(Handle& h)  
    313326}
    314327
    315328
    316 Status cursor_draw(const PIVFS& vfs, const wchar_t* name, int x, int y, bool forceGL)
     329Status cursor_draw(const PIVFS& vfs, const wchar_t* name, int x, int y, double scale, bool forceGL)
    317330{
    318331    // hide the cursor
    319332    if(!name)
    Status cursor_draw(const PIVFS& vfs, const wchar_t* name, int x, int y, bool for  
    322335        return INFO::OK;
    323336    }
    324337
    325     Handle hc = cursor_load(vfs, name, forceGL);
     338    Handle hc = cursor_load(vfs, name, scale, forceGL);
    326339    // TODO: if forceGL changes at runtime after a cursor is first created,
    327340    // we might reuse a cached version of the cursor with the old forceGL flag
    328341
  • source/lib/res/graphics/cursor.h

    diff --git a/source/lib/res/graphics/cursor.h b/source/lib/res/graphics/cursor.h
    index 074e9770..3bca60b6 100644
    a b  
    3939 *        mouse Y coordinate to be subtracted from the client area height.
    4040 *        Making the caller responsible for this avoids a dependency on
    4141 *        the g_yres global variable.)
     42 * @param scale Scale factor for drawing the cursor.
    4243 * @param forceGL Require the OpenGL cursor implementation, not hardware cursor
    4344 *
    4445 * Uses a hardware mouse cursor where available, otherwise a
    4546 * portable OpenGL implementation.
    4647 **/
    47 extern Status cursor_draw(const PIVFS& vfs, const wchar_t* name, int x, int y, bool forceGL);
     48extern Status cursor_draw(const PIVFS& vfs, const wchar_t* name, int x, int y, double scale, bool forceGL);
    4849
    4950/**
    5051 * Forcibly frees all cursor handles.
  • source/ps/GameSetup/GameSetup.cpp

    diff --git a/source/ps/GameSetup/GameSetup.cpp b/source/ps/GameSetup/GameSetup.cpp
    index b834b630..04811b8c 100644
    a b void Render()  
    274274        CStrW cursorName = g_CursorName;
    275275        if (cursorName.empty())
    276276        {
    277             cursor_draw(g_VFS, NULL, g_mouse_x, g_yres-g_mouse_y, false);
     277            cursor_draw(g_VFS, NULL, g_mouse_x, g_yres-g_mouse_y, 1.0 / g_GuiScale, false);
    278278        }
    279279        else
    280280        {
    void Render()  
    299299#if OS_ANDROID
    300300#warning TODO: cursors for Android
    301301#else
    302             if (cursor_draw(g_VFS, cursorName.c_str(), g_mouse_x, g_yres-g_mouse_y, forceGL) < 0)
     302            if (cursor_draw(g_VFS, cursorName.c_str(), g_mouse_x, g_yres-g_mouse_y, 1.0 / g_GuiScale, forceGL) < 0)
    303303                LOGWARNING("Failed to draw cursor '%s'", utf8_from_wstring(cursorName));
    304304#endif
    305305
    static void ShutdownPs()  
    591591    UnloadHotkeys();
    592592
    593593    // disable the special Windows cursor, or free textures for OGL cursors
    594     cursor_draw(g_VFS, 0, g_mouse_x, g_yres-g_mouse_y, false);
     594    cursor_draw(g_VFS, 0, g_mouse_x, g_yres-g_mouse_y, 1.0, false);
    595595}
    596596
    597597