forked from Green-Sky/tomato
start thinking about pasting files
This commit is contained in:
parent
aff239377d
commit
42b3866753
@ -19,6 +19,8 @@ add_executable(tomato
|
|||||||
texture_uploader.hpp
|
texture_uploader.hpp
|
||||||
./sdlrenderer_texture_uploader.hpp
|
./sdlrenderer_texture_uploader.hpp
|
||||||
./sdlrenderer_texture_uploader.cpp
|
./sdlrenderer_texture_uploader.cpp
|
||||||
|
./sdl_clipboard_utils.hpp
|
||||||
|
./sdl_clipboard_utils.cpp
|
||||||
./file_selector.hpp
|
./file_selector.hpp
|
||||||
./file_selector.cpp
|
./file_selector.cpp
|
||||||
|
|
||||||
|
@ -11,6 +11,11 @@
|
|||||||
#include <imgui/imgui.h>
|
#include <imgui/imgui.h>
|
||||||
#include <imgui/misc/cpp/imgui_stdlib.h>
|
#include <imgui/misc/cpp/imgui_stdlib.h>
|
||||||
|
|
||||||
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
|
#include "./sdl_clipboard_utils.hpp"
|
||||||
|
#include "SDL_clipboard.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -256,6 +261,14 @@ void ChatGui4::render(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
|
|
||||||
|
if (ImGui::IsKeyPressed(ImGuiKey_V) && ImGui::IsKeyPressed(ImGuiMod_Shortcut)) {
|
||||||
|
if (const auto* mime_type = clipboardHasImage(); mime_type != nullptr) {
|
||||||
|
size_t data_size = 0;
|
||||||
|
const auto* data = SDL_GetClipboardData(mime_type, &data_size);
|
||||||
|
// open file send preview.rawpixels
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#include <imgui/backends/imgui_impl_sdlrenderer3.h>
|
#include <imgui/backends/imgui_impl_sdlrenderer3.h>
|
||||||
|
|
||||||
#include "./theme.hpp"
|
#include "./theme.hpp"
|
||||||
#include "./sdlrenderer_texture_uploader.hpp"
|
|
||||||
|
|
||||||
#include "./start_screen.hpp"
|
#include "./start_screen.hpp"
|
||||||
|
|
||||||
@ -63,6 +62,11 @@ int main(int argc, char** argv) {
|
|||||||
quit = true;
|
quit = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (screen->handleEvent(event)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
ImGui_ImplSDL3_ProcessEvent(&event);
|
ImGui_ImplSDL3_ProcessEvent(&event);
|
||||||
}
|
}
|
||||||
if (quit) {
|
if (quit) {
|
||||||
|
@ -55,6 +55,10 @@ MainScreen::MainScreen(SDL_Renderer* renderer_, std::string save_path) :
|
|||||||
MainScreen::~MainScreen(void) {
|
MainScreen::~MainScreen(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MainScreen::handleEvent(SDL_Event& e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Screen* MainScreen::poll(bool& quit) {
|
Screen* MainScreen::poll(bool& quit) {
|
||||||
auto new_time = std::chrono::high_resolution_clock::now();
|
auto new_time = std::chrono::high_resolution_clock::now();
|
||||||
const float time_delta {std::chrono::duration<float, std::chrono::seconds::period>(new_time - last_time).count()};
|
const float time_delta {std::chrono::duration<float, std::chrono::seconds::period>(new_time - last_time).count()};
|
||||||
|
@ -55,6 +55,8 @@ struct MainScreen final : public Screen {
|
|||||||
MainScreen(SDL_Renderer* renderer_, std::string save_path);
|
MainScreen(SDL_Renderer* renderer_, std::string save_path);
|
||||||
~MainScreen(void);
|
~MainScreen(void);
|
||||||
|
|
||||||
|
bool handleEvent(SDL_Event& e) override;
|
||||||
|
|
||||||
// return nullptr if not next
|
// return nullptr if not next
|
||||||
// sets bool quit to true if exit
|
// sets bool quit to true if exit
|
||||||
Screen* poll(bool&) override;
|
Screen* poll(bool&) override;
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
struct Screen {
|
struct Screen {
|
||||||
virtual ~Screen(void) = default;
|
virtual ~Screen(void) = default;
|
||||||
|
|
||||||
|
// return true if handled
|
||||||
|
virtual bool handleEvent(SDL_Event& e) { return false; }
|
||||||
|
|
||||||
// return nullptr if not next
|
// return nullptr if not next
|
||||||
// sets bool quit to true if exit
|
// sets bool quit to true if exit
|
||||||
virtual Screen* poll(bool& quit) = 0;
|
virtual Screen* poll(bool& quit) = 0;
|
||||||
|
23
src/sdl_clipboard_utils.cpp
Normal file
23
src/sdl_clipboard_utils.cpp
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#include "./sdl_clipboard_utils.hpp"
|
||||||
|
|
||||||
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
const char* clipboardHasImage(void) {
|
||||||
|
const static std::vector<const char*> image_mime_types {
|
||||||
|
"image/webp",
|
||||||
|
"image/png",
|
||||||
|
"image/gif",
|
||||||
|
"image/jpeg",
|
||||||
|
"image/bmp",
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const char* mime_type : image_mime_types) {
|
||||||
|
if (SDL_HasClipboardData(mime_type) == SDL_TRUE) {
|
||||||
|
return mime_type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
6
src/sdl_clipboard_utils.hpp
Normal file
6
src/sdl_clipboard_utils.hpp
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// returns the mimetype (c-string) of the image in the clipboard
|
||||||
|
// or nullptr, if there is none
|
||||||
|
const char* clipboardHasImage(void);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user