implement open file dialog for linux

This commit is contained in:
2019-10-04 10:00:50 +02:00
parent 4298652476
commit a1c0dcb007
3 changed files with 15 additions and 2 deletions

View File

@@ -27,6 +27,7 @@ add_executable(panopainter
../libs/poly2tri/poly2tri/sweep/sweep_context.cc ../libs/poly2tri/poly2tri/sweep/sweep_context.cc
../libs/poly2tri/poly2tri/sweep/sweep.cc ../libs/poly2tri/poly2tri/sweep/sweep.cc
../libs/fmt/src/format.cc ../libs/fmt/src/format.cc
../libs/tinyfiledialogs/tinyfiledialogs.c
../src/pch.cpp ../src/pch.cpp
../src/util.cpp ../src/util.cpp
../src/rtt.cpp ../src/rtt.cpp
@@ -115,6 +116,7 @@ target_include_directories(panopainter PRIVATE
../libs/hash-library ../libs/hash-library
../libs/fmt/include ../libs/fmt/include
../libs/glad/include ../libs/glad/include
../libs/tinyfiledialogs
) )
target_link_libraries(panopainter glfw curl GL dl X11 pthread) target_link_libraries(panopainter glfw curl GL dl X11 pthread)

View File

@@ -70,13 +70,13 @@ int main(int argc, char** args)
return 1; return 1;
} }
glfwSetCursorPosCallback(wnd, [](GLFWwindow* w, double x, double y){ glfwSetCursorPosCallback(wnd, [](GLFWwindow* wnd, double x, double y){
g_cursor_pos = glm::vec2(x, y); g_cursor_pos = glm::vec2(x, y);
app.ui_task_async([=]{ app.ui_task_async([=]{
app.mouse_move(x, y, 1.f, kEventSource::Mouse, false); app.mouse_move(x, y, 1.f, kEventSource::Mouse, false);
}); });
}); });
glfwSetMouseButtonCallback(wnd, [](GLFWwindow* w, int button, int action, int mods){ glfwSetMouseButtonCallback(wnd, [](GLFWwindow* wnd, int button, int action, int mods){
app.ui_task_async([=]{ app.ui_task_async([=]{
if (action == GLFW_PRESS) if (action == GLFW_PRESS)
app.mouse_down(button, g_cursor_pos.x, g_cursor_pos.y, 1.f, kEventSource::Mouse, false); app.mouse_down(button, g_cursor_pos.x, g_cursor_pos.y, 1.f, kEventSource::Mouse, false);
@@ -95,6 +95,11 @@ int main(int argc, char** args)
glfwSetWindowShouldClose(app.glfw_window, GLFW_FALSE); glfwSetWindowShouldClose(app.glfw_window, GLFW_FALSE);
}); });
}); });
glfwSetWindowRefreshCallback(wnd, [](GLFWwindow* wnd){
app.ui_task_async([=]{
app.redraw = true;
}, true);
});
glfwMakeContextCurrent(wnd); glfwMakeContextCurrent(wnd);
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))

View File

@@ -14,6 +14,9 @@ std::string win32_open_dir();
void win32_show_cursor(bool visible); void win32_show_cursor(bool visible);
bool win32_clipboard_set_text(const std::string & s); bool win32_clipboard_set_text(const std::string & s);
std::string win32_clipboard_get_text(); std::string win32_clipboard_get_text();
#elif __APPLE__
#else
#include <tinyfiledialogs.h>
#endif #endif
@@ -190,6 +193,9 @@ void App::pick_file(std::vector<std::string> types, std::function<void (std::str
std::string path = win32_open_file(filter.c_str()); std::string path = win32_open_file(filter.c_str());
if (!path.empty()) if (!path.empty())
callback(path); callback(path);
#else
if (auto p = tinyfd_openFileDialog("Open File", "", 0, nullptr, nullptr, false))
callback(p);
#endif #endif
} }