ggwave-gui : wip file sharing support

This commit is contained in:
Georgi Gerganov
2020-12-30 12:04:38 +02:00
parent 442479bbaf
commit 82b0748830
12 changed files with 516 additions and 48 deletions

View File

@@ -7,10 +7,37 @@
#include <SDL.h>
#include <SDL_opengl.h>
// ImGui helpers
#include <fstream>
#include <vector>
#include <iterator>
bool ImGui_BeginFrame(SDL_Window * window);
bool ImGui_EndFrame(SDL_Window * window);
std::vector<char> readFile(const char* filename) {
// open the file:
std::ifstream file(filename, std::ios::binary);
// Stop eating new lines in binary mode!!!
file.unsetf(std::ios::skipws);
// get its size:
std::streampos fileSize;
file.seekg(0, std::ios::end);
fileSize = file.tellg();
file.seekg(0, std::ios::beg);
// reserve capacity
std::vector<char> vec;
vec.reserve(fileSize);
// read the data:
vec.insert(vec.begin(),
std::istream_iterator<char>(file),
std::istream_iterator<char>());
return vec;
}
// ImGui helpers
bool ImGui_BeginFrame(SDL_Window * window) {
SDL_Event event;
@@ -19,6 +46,12 @@ bool ImGui_BeginFrame(SDL_Window * window) {
ImGui_ProcessEvent(&event);
if (event.type == SDL_QUIT) return false;
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window)) return false;
if (event.type == SDL_DROPFILE) {
printf("Dropped file: '%s'\n", event.drop.file);
auto data = readFile(event.drop.file);
addFile(event.drop.file, event.drop.file, std::move(data));
break;
}
}
ImGui_NewFrame(window);
@@ -123,20 +156,24 @@ int main(int argc, char** argv) {
return -1;
}
ImGui_PreInit();
int windowX = 400;
int windowY = 600;
const char * windowTitle = "ggwave-gui";
SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
SDL_Window * window = SDL_CreateWindow(windowTitle, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, windowX, windowY, window_flags);
void * gl_context = SDL_GL_CreateContext(window);
SDL_GL_MakeCurrent(window, gl_context);
SDL_GL_SetSwapInterval(1); // Enable vsync
ImGui_Init(window, gl_context);
ImGui_SetStyle();
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
ImGui_NewFrame(window);
ImGui::Render();