Giter Site home page Giter Site logo

Comments (2)

slouken avatar slouken commented on August 15, 2024

Can you post a minimal repro example and steps?

Thanks!

from sdl.

GitAxeon avatar GitAxeon commented on August 15, 2024
sdl-window-resize.mp4

At the time of posting this I realized I used SDL_GetWindowSizeInPixels in the code below so please let me know if I should provide samples using SDL_GetWindowSize.

#include <SDL3/SDL.h>

#include <cstdio>

#include <windows.h>

void PrintSize(SDL_Window* window, HWND hwnd)
{
        int width = 0;
        int height = 0;
        
        SDL_GetWindowSizeInPixels(window, &width, &height);
        printf("SDL [%i, %i] ", width, height);

        RECT clientRect;
        GetClientRect(hwnd, &clientRect);
        printf("Windows [%li, %li]\n", clientRect.right - clientRect.left, clientRect.bottom - clientRect.top);
}

int main(int argc, char** argv)
{
    SDL_Init(SDL_INIT_VIDEO);

    const int initialWidth = 700;
    const int initialHeight = 300;

    SDL_Window* window = SDL_CreateWindow
    (
        "Window size test",
        initialWidth,
        initialHeight, 
        SDL_WINDOW_RESIZABLE
    );

    const HWND hwnd = (HWND)SDL_GetProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_WIN32_HWND_POINTER, NULL);

    SDL_Renderer* renderer = SDL_CreateRenderer(window, nullptr, SDL_RENDERER_PRESENTVSYNC);
    SDL_SetRenderDrawColor(renderer, 255, 165, 0, 255);

    int minWidth = -1;
    int minHeight = -1;
    SDL_GetWindowMinimumSize(window, &minWidth, &minHeight);
    printf("Min window size [%i, %i]\n", minWidth, minHeight);

    bool printOnResize = true;
    bool open = true;
    while(open)
    {
        SDL_Event e;
        while(SDL_PollEvent(&e))
        {
            if(e.type == SDL_EVENT_KEY_UP && e.key.keysym.sym == SDLK_1)
            {
                SDL_SetWindowSize(window, initialWidth, 1);
            }
            else if(e.type == SDL_EVENT_KEY_UP && e.key.keysym.sym == SDLK_2)
            {
                printOnResize = false;
            }
            else if(e.type == SDL_EVENT_WINDOW_RESIZED && printOnResize)
            {
                PrintSize(window, hwnd);
            }
            else if(e.type == SDL_EVENT_WINDOW_CLOSE_REQUESTED)
            {
                open = false;
            }
        }

        if(printOnResize == false)
            PrintSize(window, hwnd);

        SDL_RenderClear(renderer);
        SDL_RenderPresent(renderer);
    }

    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);
    SDL_Quit();

    return (0);
}

from sdl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.