Giter Site home page Giter Site logo

Comments (1)

btzy avatar btzy commented on August 18, 2024

Test case (modified from mlabbe/nativefiledialog#79):

main.c:

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>

#include <SDL.h>

#include <nfd.h>

int main()
{
    SDL_Init(SDL_INIT_VIDEO);
    
    NFD_Init();

    SDL_Window *window = SDL_CreateWindow("nativefiledialog issue 79", SDL_WINDOWPOS_CENTERED,
            SDL_WINDOWPOS_CENTERED, 800, 480, SDL_WINDOW_SHOWN);

    int w, h;
    SDL_GetWindowSize(window, &w, &h);

    bool running = true;
    while (running) {
        SDL_Event e;
        while (SDL_PollEvent(&e)) {
            if (e.type == SDL_QUIT) {
                running = false;
                break;
            }
            if (e.type == SDL_MOUSEBUTTONDOWN) {
                nfdchar_t *filename;
                nfdresult_t res = NFD_OpenDialog(&filename, NULL, 0, NULL);
                if (res == NFD_OKAY) {
                    printf("Got filename: %s\n", filename);
                    free(filename);
                }
            }
        }
    }

    SDL_DestroyWindow(window);
    
    NFD_Quit();
    
    SDL_Quit();

    return 0;
}

CMakeLists.txt:

cmake_minimum_required(VERSION 3.2)
project(MyProgram)


set (CMAKE_CXX_STANDARD 17)


add_executable(MyProgram main.c)

find_package(PkgConfig REQUIRED)
pkg_check_modules(SDL2 REQUIRED sdl2)
target_include_directories(MyProgram PRIVATE ${SDL2_INCLUDE_DIRS})
target_link_libraries(MyProgram PRIVATE ${SDL2_LIBRARIES})

add_subdirectory(${PROJECT_SOURCE_DIR}/../nativefiledialog-extended ${PROJECT_SOURCE_DIR}/../nativefiledialog-extended/build)
target_link_libraries(MyProgram PRIVATE nfd)

from nativefiledialog-extended.

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.