Improved custom event code and fixed some warnings
This commit is contained in:
parent
da1a1c26cb
commit
b2fe1ab7ba
52 changed files with 193 additions and 240 deletions
|
|
@ -5,64 +5,25 @@
|
|||
|
||||
namespace CustomEvents {
|
||||
|
||||
std::queue<std::any> eventDataQueue;
|
||||
|
||||
bool alreadyInitialized = false;
|
||||
|
||||
void init() {
|
||||
if(!alreadyInitialized) {
|
||||
PASTE_EVENT = SDL_RegisterEvents(1);
|
||||
OPEN_INFINIPAINT_FILE_EVENT = SDL_RegisterEvents(1);
|
||||
PasteEvent::EVENT_NUM = SDL_RegisterEvents(1);
|
||||
OpenInfiniPaintFileEvent::EVENT_NUM = SDL_RegisterEvents(1);
|
||||
AddFileToCanvasEvent::EVENT_NUM = SDL_RegisterEvents(1);
|
||||
alreadyInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Paste event
|
||||
|
||||
uint32_t PASTE_EVENT;
|
||||
std::queue<PasteEventData> pasteEventData;
|
||||
|
||||
bool emit_paste_event(const PasteEventData& pasteData) {
|
||||
SDL_Event event;
|
||||
SDL_zero(event);
|
||||
event.type = PASTE_EVENT;
|
||||
if(SDL_PushEvent(&event)) {
|
||||
pasteEventData.push(pasteData);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
void pop_event() {
|
||||
eventDataQueue.pop();
|
||||
}
|
||||
|
||||
const PasteEventData& get_paste_event_data() {
|
||||
return pasteEventData.front();
|
||||
}
|
||||
|
||||
void pop_paste_event_data() {
|
||||
pasteEventData.pop();
|
||||
}
|
||||
|
||||
|
||||
// Open InfiniPaint file event
|
||||
|
||||
uint32_t OPEN_INFINIPAINT_FILE_EVENT;
|
||||
std::queue<OpenInfiniPaintFileEventData> openInfiniPaintFileEventData;
|
||||
|
||||
bool emit_open_infinipaint_file_event(const OpenInfiniPaintFileEventData& openData) {
|
||||
SDL_Event event;
|
||||
SDL_zero(event);
|
||||
event.type = OPEN_INFINIPAINT_FILE_EVENT;
|
||||
if(SDL_PushEvent(&event)) {
|
||||
openInfiniPaintFileEventData.push(openData);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const OpenInfiniPaintFileEventData& get_open_infinipaint_file_event_data() {
|
||||
return openInfiniPaintFileEventData.front();
|
||||
}
|
||||
|
||||
void pop_open_infinipaint_file_event_data() {
|
||||
openInfiniPaintFileEventData.pop();
|
||||
}
|
||||
uint32_t PasteEvent::EVENT_NUM;
|
||||
uint32_t OpenInfiniPaintFileEvent::EVENT_NUM;
|
||||
uint32_t AddFileToCanvasEvent::EVENT_NUM;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,33 +2,46 @@
|
|||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <optional>
|
||||
#include <queue>
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_events.h>
|
||||
#include "RichText/TextBox.hpp"
|
||||
|
||||
namespace CustomEvents {
|
||||
void init();
|
||||
|
||||
// Paste event
|
||||
enum class PasteEventDataType {
|
||||
TEXT,
|
||||
IMAGE
|
||||
};
|
||||
struct PasteEventData {
|
||||
PasteEventDataType type;
|
||||
extern std::queue<std::any> eventDataQueue;
|
||||
|
||||
template <typename T> bool emit_event(const T& data) {
|
||||
SDL_Event event;
|
||||
SDL_zero(event);
|
||||
event.type = T::EVENT_NUM;
|
||||
if(SDL_PushEvent(&event)) {
|
||||
eventDataQueue.push(data);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename T> const T& get_event() {
|
||||
return std::any_cast<const T&>(eventDataQueue.front());
|
||||
}
|
||||
|
||||
void pop_event();
|
||||
|
||||
struct PasteEvent {
|
||||
static uint32_t EVENT_NUM;
|
||||
enum class DataType {
|
||||
TEXT,
|
||||
IMAGE
|
||||
} type;
|
||||
std::string data;
|
||||
std::optional<RichText::TextData> richText;
|
||||
std::optional<Vector2f> mousePos;
|
||||
};
|
||||
|
||||
bool emit_paste_event(const PasteEventData& pasteData);
|
||||
const PasteEventData& get_paste_event_data();
|
||||
void pop_paste_event_data();
|
||||
|
||||
extern uint32_t PASTE_EVENT;
|
||||
|
||||
|
||||
// Open InfiniPaint file event
|
||||
|
||||
struct OpenInfiniPaintFileEventData {
|
||||
struct OpenInfiniPaintFileEvent {
|
||||
static uint32_t EVENT_NUM;
|
||||
bool isClient;
|
||||
std::optional<std::filesystem::path> filePathSource;
|
||||
std::string netSource;
|
||||
|
|
@ -36,9 +49,15 @@ namespace CustomEvents {
|
|||
std::string_view fileDataBuffer;
|
||||
};
|
||||
|
||||
bool emit_open_infinipaint_file_event(const OpenInfiniPaintFileEventData& openData);
|
||||
const OpenInfiniPaintFileEventData& get_open_infinipaint_file_event_data();
|
||||
void pop_open_infinipaint_file_event_data();
|
||||
|
||||
extern uint32_t OPEN_INFINIPAINT_FILE_EVENT;
|
||||
struct AddFileToCanvasEvent {
|
||||
static uint32_t EVENT_NUM;
|
||||
enum class Type {
|
||||
BUFFER,
|
||||
PATH
|
||||
} type;
|
||||
std::string name;
|
||||
std::string buffer;
|
||||
std::filesystem::path filePath;
|
||||
Vector2f pos;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,16 +58,19 @@ void DrawingProgram::on_tab_out() {
|
|||
controls.middleClickHeld = false;
|
||||
}
|
||||
|
||||
void DrawingProgram::input_paste_callback(const CustomEvents::PasteEventData& paste) {
|
||||
drawTool->input_paste_callback(paste);
|
||||
void DrawingProgram::input_paste_callback(const CustomEvents::PasteEvent& paste) {
|
||||
if(paste.type == CustomEvents::PasteEvent::DataType::IMAGE)
|
||||
selection.paste_image_process_event(paste);
|
||||
else
|
||||
drawTool->input_paste_callback(paste);
|
||||
}
|
||||
|
||||
void DrawingProgram::input_drop_file_callback(const InputManager::DropCallbackArgs& drop) {
|
||||
if(std::filesystem::is_regular_file(drop.data)) {
|
||||
#ifdef __EMSCRIPTEN_
|
||||
add_file_to_canvas_by_path(drop.data, world.main.input.mouse.pos, true);
|
||||
add_file_to_canvas_by_path(drop.data, world.main.input.mouse.pos);
|
||||
#else
|
||||
add_file_to_canvas_by_path(drop.data, drop.pos, true);
|
||||
add_file_to_canvas_by_path(drop.data, drop.pos);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
@ -422,7 +425,10 @@ void DrawingProgram::popup_menu_action_button(const char* id, const char* text,
|
|||
.drawType = GUIStuff::SelectableButton::DrawType::TRANSPARENT_ALL,
|
||||
.wide = true,
|
||||
.centered = false,
|
||||
.onClick = onClick
|
||||
.onClick = [&, onClick] {
|
||||
onClick();
|
||||
clear_right_click_popup();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -442,7 +448,9 @@ void DrawingProgram::selection_action_menu(Vector2f popupPos) {
|
|||
});
|
||||
popup_menu_action_button("Paste Image", "Paste Image", [&, popupPos] {
|
||||
selection.deselect_all();
|
||||
selection.paste_image(popupPos * world.main.g.final_gui_scale());
|
||||
world.main.input.call_paste(CustomEvents::PasteEvent::DataType::IMAGE, {
|
||||
.pastePosition = popupPos * world.main.g.final_gui_scale()
|
||||
});
|
||||
});
|
||||
if(selection.is_something_selected()) {
|
||||
popup_menu_action_button("Copy", "Copy", [&] {
|
||||
|
|
@ -463,8 +471,8 @@ void DrawingProgram::selection_action_menu(Vector2f popupPos) {
|
|||
});
|
||||
}
|
||||
}, LayoutElement::Callbacks{
|
||||
.mouseButton = [&](LayoutElement*, const InputManager::MouseButtonCallbackArgs& button) {
|
||||
if(button.down && button.button != InputManager::MouseButton::RIGHT)
|
||||
.mouseButton = [&](LayoutElement* l, const InputManager::MouseButtonCallbackArgs& button) {
|
||||
if(button.down && button.button != InputManager::MouseButton::RIGHT && !l->mouseHovering)
|
||||
clear_right_click_popup();
|
||||
}
|
||||
});
|
||||
|
|
@ -510,11 +518,6 @@ void DrawingProgram::modify_grid(const NetworkingObjects::NetObjWeakPtr<WorldGri
|
|||
}
|
||||
|
||||
void DrawingProgram::update() {
|
||||
if(addFileInNextFrame) {
|
||||
add_file_to_canvas_by_path_execute(addFileInfo.first, addFileInfo.second);
|
||||
addFileInNextFrame = false;
|
||||
}
|
||||
|
||||
selection.update();
|
||||
drawTool->tool_update();
|
||||
|
||||
|
|
@ -652,16 +655,11 @@ void DrawingProgram::update_downloading_dropped_files() {
|
|||
});
|
||||
}
|
||||
|
||||
void DrawingProgram::add_file_to_canvas_by_path(const std::filesystem::path& filePath, Vector2f dropPos, bool addInSameThread) {
|
||||
if(addInSameThread)
|
||||
add_file_to_canvas_by_path_execute(filePath, dropPos);
|
||||
else if(!addFileInNextFrame) {
|
||||
addFileInfo = {filePath, dropPos};
|
||||
addFileInNextFrame = true;
|
||||
}
|
||||
void DrawingProgram::input_add_file_to_canvas_callback(const CustomEvents::AddFileToCanvasEvent& addFile) {
|
||||
add_file_to_canvas_by_path(addFile.filePath, addFile.pos);
|
||||
}
|
||||
|
||||
void DrawingProgram::add_file_to_canvas_by_path_execute(const std::filesystem::path& filePath, Vector2f dropPos) {
|
||||
void DrawingProgram::add_file_to_canvas_by_path(const std::filesystem::path& filePath, Vector2f dropPos) {
|
||||
if(layerMan.is_a_layer_being_edited()) {
|
||||
NetworkingObjects::NetObjTemporaryPtr<ResourceData> imageTempPtr = world.rMan.add_resource_file(filePath);
|
||||
if(imageTempPtr) {
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class DrawingProgram {
|
|||
void read_components_client(cereal::PortableBinaryInputArchive& a);
|
||||
void init_server_callbacks();
|
||||
void init_client_callbacks();
|
||||
void add_file_to_canvas_by_path(const std::filesystem::path& filePath, Vector2f dropPos, bool addInSameThread);
|
||||
void add_file_to_canvas_by_path(const std::filesystem::path& filePath, Vector2f dropPos);
|
||||
CanvasComponentContainer::ObjInfo* add_file_to_canvas_by_data(const std::string& fileName, std::string_view fileBuffer, Vector2f dropPos);
|
||||
void get_used_resources(std::unordered_set<NetworkingObjects::NetObjID>& resourceSet);
|
||||
|
||||
|
|
@ -59,7 +59,8 @@ class DrawingProgram {
|
|||
void send_transforms_for(const std::vector<CanvasComponentContainer::ObjInfo*>& objsToSendTransformsFor);
|
||||
|
||||
void on_tab_out();
|
||||
void input_paste_callback(const CustomEvents::PasteEventData& paste);
|
||||
void input_add_file_to_canvas_callback(const CustomEvents::AddFileToCanvasEvent& addFile);
|
||||
void input_paste_callback(const CustomEvents::PasteEvent& paste);
|
||||
void input_drop_text_callback(const InputManager::DropCallbackArgs& drop);
|
||||
void input_drop_file_callback(const InputManager::DropCallbackArgs& drop);
|
||||
void input_text_key_callback(const InputManager::KeyCallbackArgs& key);
|
||||
|
|
@ -80,7 +81,6 @@ class DrawingProgram {
|
|||
void process_transform_message(const std::vector<std::pair<NetworkingObjects::NetObjID, CoordSpaceHelper>>& transforms);
|
||||
|
||||
void drag_drop_update();
|
||||
void add_file_to_canvas_by_path_execute(const std::filesystem::path& filePath, Vector2f dropPos);
|
||||
void check_updateable_components();
|
||||
void update_downloading_dropped_files();
|
||||
|
||||
|
|
@ -88,9 +88,6 @@ class DrawingProgram {
|
|||
void popup_menu_action_button(const char* id, const char* text, const std::function<void()>& onClick);
|
||||
void rebuild_cache();
|
||||
|
||||
std::atomic<bool> addFileInNextFrame = false;
|
||||
std::pair<std::filesystem::path, Vector2f> addFileInfo;
|
||||
|
||||
float drag_point_radius();
|
||||
void draw_drag_circle(SkCanvas* canvas, const Vector2f& pos, const SkColor4f& c, const DrawData& drawData, float radiusMultiplier = 1.0f);
|
||||
SkPaint select_tool_line_paint(const DrawData& drawData);
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
#include "../InputManager.hpp"
|
||||
#include <Helpers/Parallel.hpp>
|
||||
#include <Helpers/Logger.hpp>
|
||||
#include <chrono>
|
||||
|
||||
#ifdef USE_SKIA_BACKEND_GRAPHITE
|
||||
#include <include/gpu/graphite/Surface.h>
|
||||
|
|
@ -423,7 +422,9 @@ void DrawingProgramSelection::input_key_callback_display_selection(const InputMa
|
|||
case InputManager::KEY_PASTE_IMAGE: {
|
||||
if(key.down && !key.repeat) {
|
||||
deselect_all();
|
||||
paste_image(drawP.world.main.input.mouse.pos);
|
||||
drawP.world.main.input.call_paste(CustomEvents::PasteEvent::DataType::IMAGE, {
|
||||
.pastePosition = drawP.world.main.input.mouse.pos
|
||||
});
|
||||
drawP.world.main.g.gui.set_to_layout();
|
||||
}
|
||||
break;
|
||||
|
|
@ -689,39 +690,19 @@ void DrawingProgramSelection::paste_clipboard(Vector2f pasteScreenPos) {
|
|||
}
|
||||
}
|
||||
|
||||
void DrawingProgramSelection::paste_image(Vector2f pasteScreenPos) {
|
||||
void DrawingProgramSelection::paste_image_process_event(const CustomEvents::PasteEvent& paste) {
|
||||
check_add_stroke_color_change_undo();
|
||||
|
||||
if(drawP.layerMan.is_a_layer_being_edited()) {
|
||||
#ifdef __EMSCRIPTEN__
|
||||
struct PasteData {
|
||||
std::weak_ptr<World> w;
|
||||
Vector2f screenPos;
|
||||
};
|
||||
static PasteData pasteData;
|
||||
pasteData.screenPos = pasteScreenPos;
|
||||
pasteData.w = make_weak_ptr(drawP.world.main.world);
|
||||
emscripten_browser_clipboard::paste_async_image([](std::string_view pasteData, void* callbackData){
|
||||
PasteData* p = (PasteData*)callbackData;
|
||||
std::shared_ptr<World> wLock = p->w.lock();
|
||||
if(wLock)
|
||||
wLock->drawProg.add_file_to_canvas_by_data("Image from clipboard", pasteData, p->screenPos);
|
||||
else
|
||||
Logger::get().log("INFO", "Loading image to canvas that has been destroyed");
|
||||
}, &pasteData);
|
||||
#else
|
||||
if(!drawP.is_selection_allowing_tool(drawP.drawTool->get_type()))
|
||||
drawP.switch_to_tool(DrawingProgramToolType::EDIT);
|
||||
if(!drawP.is_selection_allowing_tool(drawP.drawTool->get_type()))
|
||||
drawP.switch_to_tool(DrawingProgramToolType::EDIT);
|
||||
|
||||
std::vector<CanvasComponentContainer::ObjInfo*> compSetInserted;
|
||||
drawP.world.main.input.get_clipboard_image_data_SDL([&](std::string_view pasteData) {
|
||||
compSetInserted.emplace_back(drawP.add_file_to_canvas_by_data("Image from clipboard", pasteData, pasteScreenPos));
|
||||
});
|
||||
if(!compSetInserted.empty() && compSetInserted.back() != nullptr) {
|
||||
drawP.drawCache.erase_component(compSetInserted.back());
|
||||
set_to_selection(compSetInserted);
|
||||
}
|
||||
#endif
|
||||
std::vector<CanvasComponentContainer::ObjInfo*> compSetInserted;
|
||||
compSetInserted.emplace_back(drawP.add_file_to_canvas_by_data("Image from clipboard", paste.data, paste.mousePos.value()));
|
||||
if(compSetInserted.back() != nullptr) {
|
||||
drawP.drawCache.erase_component(compSetInserted.back());
|
||||
set_to_selection(compSetInserted);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ class DrawingProgramSelection {
|
|||
void sort_selection();
|
||||
void deselect_all();
|
||||
void paste_clipboard(Vector2f pasteScreenPos);
|
||||
void paste_image(Vector2f pasteScreenPos);
|
||||
void paste_image_process_event(const CustomEvents::PasteEvent& paste);
|
||||
std::unordered_set<CanvasComponentContainer::ObjInfo*> get_selection_as_set();
|
||||
void push_selection_to_front();
|
||||
void push_selection_to_back();
|
||||
|
|
|
|||
|
|
@ -6,9 +6,7 @@
|
|||
#include "DrawingProgramToolBase.hpp"
|
||||
#include "../../CanvasComponents/BrushStrokeCanvasComponent.hpp"
|
||||
#include "Helpers/NetworkingObjects/NetObjTemporaryPtr.decl.hpp"
|
||||
#include "Helpers/NetworkingObjects/NetObjWeakPtr.hpp"
|
||||
#include "../../CanvasComponents/CanvasComponentContainer.hpp"
|
||||
#include <chrono>
|
||||
|
||||
#include "../../GUIStuff/ElementHelpers/TextLabelHelpers.hpp"
|
||||
#include "../../GUIStuff/ElementHelpers/CheckBoxHelpers.hpp"
|
||||
|
|
@ -176,7 +174,6 @@ void BrushTool::gui_toolbox() {
|
|||
using namespace GUIStuff;
|
||||
using namespace ElementHelpers;
|
||||
|
||||
Toolbar& t = drawP.world.main.toolbar;
|
||||
auto& gui = drawP.world.main.g.gui;
|
||||
|
||||
gui.new_id("brush tool", [&] {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
#include <include/core/SkPath.h>
|
||||
#include <include/core/SkVertices.h>
|
||||
#include <Helpers/SCollision.hpp>
|
||||
#include <deque>
|
||||
#include <include/core/SkCanvas.h>
|
||||
#include "../../CanvasComponents/CanvasComponentContainer.hpp"
|
||||
#include <Helpers/NetworkingObjects/NetObjWeakPtr.hpp>
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ std::unique_ptr<DrawingProgramToolBase> DrawingProgramToolBase::allocate_tool_ty
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
void DrawingProgramToolBase::input_paste_callback(const CustomEvents::PasteEventData& paste) {}
|
||||
void DrawingProgramToolBase::input_paste_callback(const CustomEvents::PasteEvent& paste) {}
|
||||
void DrawingProgramToolBase::input_text_key_callback(const InputManager::KeyCallbackArgs& key) {}
|
||||
void DrawingProgramToolBase::input_text_callback(const InputManager::TextCallbackArgs& text) {}
|
||||
void DrawingProgramToolBase::input_key_callback(const InputManager::KeyCallbackArgs& key) {}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class DrawingProgramToolBase {
|
|||
virtual void draw(SkCanvas* canvas, const DrawData& drawData) = 0;
|
||||
virtual void switch_tool(DrawingProgramToolType newTool) = 0;
|
||||
virtual bool prevent_undo_or_redo() = 0;
|
||||
virtual void input_paste_callback(const CustomEvents::PasteEventData& paste);
|
||||
virtual void input_paste_callback(const CustomEvents::PasteEvent& paste);
|
||||
virtual void input_text_key_callback(const InputManager::KeyCallbackArgs& key);
|
||||
virtual void input_text_callback(const InputManager::TextCallbackArgs& text);
|
||||
virtual void input_key_callback(const InputManager::KeyCallbackArgs& key);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#include "EditTool.hpp"
|
||||
#include <chrono>
|
||||
#include "../DrawingProgram.hpp"
|
||||
#include "../../MainProgram.hpp"
|
||||
#include "../../DrawData.hpp"
|
||||
|
|
@ -29,7 +28,6 @@ void EditTool::gui_toolbox() {
|
|||
using namespace GUIStuff;
|
||||
using namespace ElementHelpers;
|
||||
|
||||
Toolbar& t = drawP.world.main.toolbar;
|
||||
auto& gui = drawP.world.main.g.gui;
|
||||
|
||||
if(objInfoBeingEdited)
|
||||
|
|
@ -46,7 +44,7 @@ void EditTool::erase_component(CanvasComponentContainer::ObjInfo* erasedComp) {
|
|||
switch_tool(get_type());
|
||||
}
|
||||
|
||||
void EditTool::input_paste_callback(const CustomEvents::PasteEventData& paste) {
|
||||
void EditTool::input_paste_callback(const CustomEvents::PasteEvent& paste) {
|
||||
if(objInfoBeingEdited)
|
||||
compEditTool->input_paste_callback(paste);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class EditTool : public DrawingProgramToolBase {
|
|||
virtual void switch_tool(DrawingProgramToolType newTool) override;
|
||||
virtual void draw(SkCanvas* canvas, const DrawData& drawData) override;
|
||||
virtual bool prevent_undo_or_redo() override;
|
||||
virtual void input_paste_callback(const CustomEvents::PasteEventData& paste) override;
|
||||
virtual void input_paste_callback(const CustomEvents::PasteEvent& paste) override;
|
||||
virtual void input_text_key_callback(const InputManager::KeyCallbackArgs& key) override;
|
||||
virtual void input_text_callback(const InputManager::TextCallbackArgs& text) override;
|
||||
virtual void input_key_callback(const InputManager::KeyCallbackArgs& key) override;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#include "../../../World.hpp"
|
||||
#include "../../../MainProgram.hpp"
|
||||
#include "../EditTool.hpp"
|
||||
#include "../../../CanvasComponents/BrushStrokeCanvasComponent.hpp"
|
||||
|
||||
#include "../../../GUIStuff/ElementHelpers/TextLabelHelpers.hpp"
|
||||
#include "../../../GUIStuff/ElementHelpers/LayoutHelpers.hpp"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
#pragma once
|
||||
#include "DrawingProgramEditToolBase.hpp"
|
||||
#include "../../../CanvasComponents/BrushStrokeCanvasComponent.hpp"
|
||||
#include <Helpers/SCollision.hpp>
|
||||
#include <any>
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ void DrawingProgramEditToolBase::right_click_popup_gui(Vector2f popupPos) {
|
|||
t.paint_popup(popupPos);
|
||||
}
|
||||
|
||||
void DrawingProgramEditToolBase::input_paste_callback(const CustomEvents::PasteEventData& paste) {}
|
||||
void DrawingProgramEditToolBase::input_paste_callback(const CustomEvents::PasteEvent& paste) {}
|
||||
void DrawingProgramEditToolBase::input_text_key_callback(const InputManager::KeyCallbackArgs& key) {}
|
||||
void DrawingProgramEditToolBase::input_text_callback(const InputManager::TextCallbackArgs& text) {}
|
||||
void DrawingProgramEditToolBase::input_key_callback(const InputManager::KeyCallbackArgs& key) {}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class DrawingProgramEditToolBase {
|
|||
virtual bool edit_update() = 0;
|
||||
virtual void edit_gui() = 0;
|
||||
virtual void right_click_popup_gui(Vector2f popupPos);
|
||||
virtual void input_paste_callback(const CustomEvents::PasteEventData& paste);
|
||||
virtual void input_paste_callback(const CustomEvents::PasteEvent& paste);
|
||||
virtual void input_text_key_callback(const InputManager::KeyCallbackArgs& key);
|
||||
virtual void input_text_callback(const InputManager::TextCallbackArgs& text);
|
||||
virtual void input_key_callback(const InputManager::KeyCallbackArgs& key);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
#include "../../../MainProgram.hpp"
|
||||
#include "../../../DrawData.hpp"
|
||||
#include <cereal/types/vector.hpp>
|
||||
#include <memory>
|
||||
#include "../EditTool.hpp"
|
||||
|
||||
#include "../../../GUIStuff/ElementHelpers/TextLabelHelpers.hpp"
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
#include "../EditTool.hpp"
|
||||
#include "DrawingProgramEditToolBase.hpp"
|
||||
#include "Eigen/Geometry"
|
||||
#include <fstream>
|
||||
|
||||
#include "../../../GUIStuff/ElementHelpers/TextLabelHelpers.hpp"
|
||||
#include "../../../GUIStuff/ElementHelpers/ButtonHelpers.hpp"
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
#include "../../DrawingProgram.hpp"
|
||||
#include "../../../World.hpp"
|
||||
#include "../../../MainProgram.hpp"
|
||||
#include <memory>
|
||||
#include "../EditTool.hpp"
|
||||
|
||||
#include "../../../GUIStuff/ElementHelpers/NumberSliderHelpers.hpp"
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
#include "../../DrawingProgram.hpp"
|
||||
#include "../../../MainProgram.hpp"
|
||||
#include "../../../DrawData.hpp"
|
||||
#include "Helpers/ConvertVec.hpp"
|
||||
#include "Helpers/SCollision.hpp"
|
||||
#include <cereal/types/vector.hpp>
|
||||
#include <include/core/SkFontStyle.h>
|
||||
|
|
@ -204,7 +203,7 @@ void TextBoxEditTool::edit_gui() {
|
|||
});
|
||||
}
|
||||
|
||||
void TextBoxEditTool::input_paste_callback(const CustomEvents::PasteEventData& paste) {
|
||||
void TextBoxEditTool::input_paste_callback(const CustomEvents::PasteEvent& paste) {
|
||||
if(textboxID.has_value() && textboxID.value() == drawP.world.main.input.text.current_textbox_editing_id()) {
|
||||
auto& a = static_cast<TextBoxCanvasComponent&>(comp->obj->get_comp());
|
||||
if(userInput->input_paste_callback(paste)) {
|
||||
|
|
@ -289,10 +288,10 @@ void TextBoxEditTool::right_click_popup_gui(Vector2f popupPos) {
|
|||
text_label_light(gui, "Text menu");
|
||||
InputManager& input = drawP.world.main.input;
|
||||
drawP.popup_menu_action_button("Paste", "Paste", [&] {
|
||||
drawP.world.main.input.call_paste(CustomEvents::PasteEventDataType::TEXT, { .allowRichText = true });
|
||||
drawP.world.main.input.call_paste(CustomEvents::PasteEvent::DataType::TEXT, { .allowRichText = true });
|
||||
});
|
||||
drawP.popup_menu_action_button("Paste without formatting", "Paste without formatting", [&] {
|
||||
drawP.world.main.input.call_paste(CustomEvents::PasteEventDataType::TEXT, { .allowRichText = false });
|
||||
drawP.world.main.input.call_paste(CustomEvents::PasteEvent::DataType::TEXT, { .allowRichText = false });
|
||||
});
|
||||
if(a.cursor->selectionBeginPos != a.cursor->selectionEndPos) {
|
||||
drawP.popup_menu_action_button("Copy", "Copy", [&] {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class TextBoxEditTool : public DrawingProgramEditToolBase {
|
|||
virtual void edit_gui() override;
|
||||
virtual void right_click_popup_gui(Vector2f popupPos) override;
|
||||
|
||||
virtual void input_paste_callback(const CustomEvents::PasteEventData& paste) override;
|
||||
virtual void input_paste_callback(const CustomEvents::PasteEvent& paste) override;
|
||||
virtual void input_text_key_callback(const InputManager::KeyCallbackArgs& key) override;
|
||||
virtual void input_text_callback(const InputManager::TextCallbackArgs& text) override;
|
||||
virtual void input_mouse_button_on_canvas_callback(const InputManager::MouseButtonCallbackArgs& button, bool isDraggingPoint) override;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ void EllipseDrawTool::gui_toolbox() {
|
|||
using namespace GUIStuff;
|
||||
using namespace ElementHelpers;
|
||||
|
||||
Toolbar& t = drawP.world.main.toolbar;
|
||||
auto& gui = drawP.world.main.g.gui;
|
||||
auto& toolConfig = drawP.world.main.toolConfig;
|
||||
auto& fillStrokeMode = toolConfig.ellipseDraw.fillStrokeMode;
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ void EraserTool::gui_toolbox() {
|
|||
using namespace GUIStuff;
|
||||
using namespace ElementHelpers;
|
||||
|
||||
Toolbar& t = drawP.world.main.toolbar;
|
||||
auto& gui = drawP.world.main.g.gui;
|
||||
gui.new_id("eraser tool", [&] {
|
||||
text_label_centered(gui, "Eraser");
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
#include <include/core/SkCanvas.h>
|
||||
#include "../../DrawData.hpp"
|
||||
#include "DrawingProgramToolBase.hpp"
|
||||
#include "../DrawingProgramCache.hpp"
|
||||
|
||||
class DrawingProgram;
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ void EyeDropperTool::gui_toolbox() {
|
|||
using namespace GUIStuff;
|
||||
using namespace ElementHelpers;
|
||||
|
||||
Toolbar& t = drawP.world.main.toolbar;
|
||||
auto& gui = drawP.world.main.g.gui;
|
||||
auto& selectingStrokeColor = drawP.world.main.toolConfig.eyeDropper.selectingStrokeColor;
|
||||
gui.new_id("Color select tool", [&] {
|
||||
|
|
|
|||
|
|
@ -2,11 +2,9 @@
|
|||
#include "../DrawingProgram.hpp"
|
||||
#include "../../MainProgram.hpp"
|
||||
#include "../../DrawData.hpp"
|
||||
#include "Helpers/Networking/NetLibrary.hpp"
|
||||
#include "Helpers/NetworkingObjects/NetObjTemporaryPtr.decl.hpp"
|
||||
#include <Helpers/NetworkingObjects/NetObjWeakPtr.hpp>
|
||||
#include <Helpers/NetworkingObjects/NetObjGenericSerializedClass.hpp>
|
||||
#include <cstddef>
|
||||
|
||||
#include "../../GUIStuff/ElementHelpers/TextLabelHelpers.hpp"
|
||||
#include "../../GUIStuff/ElementHelpers/LayoutHelpers.hpp"
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
#include "Helpers/SCollision.hpp"
|
||||
#include "../../CoordSpaceHelper.hpp"
|
||||
#include <ranges>
|
||||
#include "../../DrawCollision.hpp"
|
||||
#include <earcut.hpp>
|
||||
#include <include/core/SkPathBuilder.h>
|
||||
|
||||
|
|
@ -41,7 +40,6 @@ DrawingProgramToolType LassoSelectTool::get_type() {
|
|||
}
|
||||
|
||||
void LassoSelectTool::gui_toolbox() {
|
||||
auto& t = drawP.world.main.toolbar;
|
||||
auto& gui = drawP.world.main.g.gui;
|
||||
gui.new_id("lasso select tool", [&] {
|
||||
GUIStuff::ElementHelpers::text_label_centered(gui, "Lasso Select");
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
#include "../../CanvasComponents/BrushStrokeCanvasComponent.hpp"
|
||||
#include "../../CanvasComponents/CanvasComponentContainer.hpp"
|
||||
#include "Helpers/MathExtras.hpp"
|
||||
#include <limits>
|
||||
|
||||
#include "../../GUIStuff/ElementHelpers/TextLabelHelpers.hpp"
|
||||
#include "../../GUIStuff/ElementHelpers/CheckBoxHelpers.hpp"
|
||||
|
|
@ -22,7 +21,6 @@ DrawingProgramToolType LineDrawTool::get_type() {
|
|||
void LineDrawTool::gui_toolbox() {
|
||||
using namespace GUIStuff;
|
||||
using namespace ElementHelpers;
|
||||
Toolbar& t = drawP.world.main.toolbar;
|
||||
auto& gui = drawP.world.main.g.gui;
|
||||
auto& toolConfig = drawP.world.main.toolConfig;
|
||||
gui.new_id("rect draw tool", [&] {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ DrawingProgramToolType PanCanvasTool::get_type() {
|
|||
}
|
||||
|
||||
void PanCanvasTool::gui_toolbox() {
|
||||
Toolbar& t = drawP.world.main.toolbar;
|
||||
auto& gui = drawP.world.main.g.gui;
|
||||
gui.new_id("Pan canvas tool", [&] {
|
||||
GUIStuff::ElementHelpers::text_label_centered(gui, "Pan tool");
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ void RectDrawTool::gui_toolbox() {
|
|||
using namespace GUIStuff;
|
||||
using namespace ElementHelpers;
|
||||
|
||||
Toolbar& t = drawP.world.main.toolbar;
|
||||
auto& gui = drawP.world.main.g.gui;
|
||||
auto& toolConfig = drawP.world.main.toolConfig;
|
||||
auto& fillStrokeMode = toolConfig.rectDraw.fillStrokeMode;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ DrawingProgramToolType RectSelectTool::get_type() {
|
|||
}
|
||||
|
||||
void RectSelectTool::gui_toolbox() {
|
||||
auto& t = drawP.world.main.toolbar;
|
||||
auto& gui = drawP.world.main.g.gui;
|
||||
gui.new_id("rectangle select tool", [&] {
|
||||
GUIStuff::ElementHelpers::text_label_centered(gui, "Rectangle Select");
|
||||
|
|
|
|||
|
|
@ -17,9 +17,7 @@
|
|||
#include <include/encode/SkPngEncoder.h>
|
||||
#include <include/encode/SkWebpEncoder.h>
|
||||
#include <include/encode/SkJpegEncoder.h>
|
||||
#include <fstream>
|
||||
#include <include/gpu/GpuTypes.h>
|
||||
#include "../../FileHelpers.hpp"
|
||||
#include <filesystem>
|
||||
#ifdef USE_SKIA_BACKEND_GRAPHITE
|
||||
#include <include/gpu/graphite/Surface.h>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
#include "TextBoxTool.hpp"
|
||||
#include <chrono>
|
||||
#include "../DrawingProgram.hpp"
|
||||
#include "../../MainProgram.hpp"
|
||||
#include "../../DrawData.hpp"
|
||||
#include "Helpers/MathExtras.hpp"
|
||||
#include "Helpers/SCollision.hpp"
|
||||
#include <cereal/types/vector.hpp>
|
||||
#include <memory>
|
||||
#include "../../CanvasComponents/TextBoxCanvasComponent.hpp"
|
||||
|
|
@ -22,7 +20,6 @@ DrawingProgramToolType TextBoxTool::get_type() {
|
|||
}
|
||||
|
||||
void TextBoxTool::gui_toolbox() {
|
||||
Toolbar& t = drawP.world.main.toolbar;
|
||||
auto& gui = drawP.world.main.g.gui;
|
||||
gui.new_id("textbox tool", [&] {
|
||||
GUIStuff::ElementHelpers::text_label_centered(gui, "Place textbox");
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ DrawingProgramToolType ZoomCanvasTool::get_type() {
|
|||
}
|
||||
|
||||
void ZoomCanvasTool::gui_toolbox() {
|
||||
Toolbar& t = drawP.world.main.toolbar;
|
||||
auto& gui = drawP.world.main.g.gui;
|
||||
gui.new_id("Zoom canvas tool", [&] {
|
||||
GUIStuff::ElementHelpers::text_label_centered(gui, "Zoom tool");
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ void GUIHolder::draw(SkCanvas* canvas, bool skiaAA) {
|
|||
gui.draw(canvas, skiaAA);
|
||||
}
|
||||
|
||||
void GUIHolder::input_paste_callback(const CustomEvents::PasteEventData& paste) {
|
||||
void GUIHolder::input_paste_callback(const CustomEvents::PasteEvent& paste) {
|
||||
gui.input_paste_callback(paste);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class GUIHolder {
|
|||
void delete_cache_surface();
|
||||
void draw(SkCanvas* canvas, bool skiaAA);
|
||||
|
||||
void input_paste_callback(const CustomEvents::PasteEventData& paste);
|
||||
void input_paste_callback(const CustomEvents::PasteEvent& paste);
|
||||
void input_text_key_callback(const InputManager::KeyCallbackArgs& key);
|
||||
void input_text_callback(const InputManager::TextCallbackArgs& text);
|
||||
void input_key_callback(const InputManager::KeyCallbackArgs& key);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace GUIStuff {
|
|||
void Element::update() {}
|
||||
void Element::deselect() {}
|
||||
|
||||
void Element::input_paste_callback(const CustomEvents::PasteEventData& paste) { }
|
||||
void Element::input_paste_callback(const CustomEvents::PasteEvent& paste) { }
|
||||
void Element::input_text_key_callback(const InputManager::KeyCallbackArgs& key) { }
|
||||
void Element::input_text_callback(const InputManager::TextCallbackArgs& text) { }
|
||||
void Element::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) { }
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ namespace GUIStuff {
|
|||
virtual void update();
|
||||
virtual void deselect();
|
||||
|
||||
virtual void input_paste_callback(const CustomEvents::PasteEventData& paste);
|
||||
virtual void input_paste_callback(const CustomEvents::PasteEvent& paste);
|
||||
virtual void input_text_key_callback(const InputManager::KeyCallbackArgs& key);
|
||||
virtual void input_text_callback(const InputManager::TextCallbackArgs& text);
|
||||
virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button);
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ template <typename T> class TextBox : public Element {
|
|||
virtual void update() override;
|
||||
virtual void deselect() override;
|
||||
virtual void clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) override;
|
||||
virtual void input_paste_callback(const CustomEvents::PasteEventData& paste) override;
|
||||
virtual void input_paste_callback(const CustomEvents::PasteEvent& paste) override;
|
||||
virtual void input_text_key_callback(const InputManager::KeyCallbackArgs& key) override;
|
||||
virtual void input_text_callback(const InputManager::TextCallbackArgs& text) override;
|
||||
virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) override;
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ template <typename T> bool TextBox<T>::is_selected() const {
|
|||
return edit.has_value();
|
||||
}
|
||||
|
||||
template <typename T> void TextBox<T>::input_paste_callback(const CustomEvents::PasteEventData& paste) {
|
||||
template <typename T> void TextBox<T>::input_paste_callback(const CustomEvents::PasteEvent& paste) {
|
||||
if(is_selected() && edit.value().userInput.input_paste_callback(paste))
|
||||
after_text_input_callback();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -495,7 +495,7 @@ void GUIManager::deselect_all() {
|
|||
e->elem->deselect();
|
||||
}
|
||||
|
||||
void GUIManager::input_paste_callback(const CustomEvents::PasteEventData& paste) {
|
||||
void GUIManager::input_paste_callback(const CustomEvents::PasteEvent& paste) {
|
||||
for(ElementContainer* e : orderedElements)
|
||||
e->elem->input_paste_callback(paste);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ class GUIManager {
|
|||
|
||||
DefaultStringArena strArena;
|
||||
|
||||
void input_paste_callback(const CustomEvents::PasteEventData& paste);
|
||||
void input_paste_callback(const CustomEvents::PasteEvent& paste);
|
||||
void input_text_key_callback(const InputManager::KeyCallbackArgs& key);
|
||||
void input_text_callback(const InputManager::TextCallbackArgs& text);
|
||||
void input_key_callback(const InputManager::KeyCallbackArgs& key);
|
||||
|
|
|
|||
|
|
@ -362,16 +362,6 @@ uint32_t InputManager::make_generic_key_mod(SDL_Keymod m) {
|
|||
return toRet;
|
||||
}
|
||||
|
||||
void InputManager::backend_open_infinipaint_file_event() {
|
||||
main.input_open_infinipaint_file_callback(CustomEvents::get_open_infinipaint_file_event_data());
|
||||
CustomEvents::pop_open_infinipaint_file_event_data();
|
||||
}
|
||||
|
||||
void InputManager::backend_paste_event() {
|
||||
main.input_paste_callback(CustomEvents::get_paste_event_data());
|
||||
CustomEvents::pop_paste_event_data();
|
||||
}
|
||||
|
||||
void InputManager::backend_input_text_event(const std::string& str) {
|
||||
main.input_text_callback(TextCallbackArgs{ .str = str });
|
||||
}
|
||||
|
|
@ -934,7 +924,7 @@ void InputManager::backend_key_down_update(const SDL_KeyboardEvent& e) {
|
|||
set_key_down(e, f->second, acceptingTextInput);
|
||||
}
|
||||
|
||||
void InputManager::call_paste(CustomEvents::PasteEventDataType type, const InputManagerCallPasteInfo& info) {
|
||||
void InputManager::call_paste(CustomEvents::PasteEvent::DataType type, const InputManagerCallPasteInfo& info) {
|
||||
// Workaround for not being able to copy richtext to system clipboard, this should at least work within the application itself
|
||||
#ifdef __EMSCRIPTEN__
|
||||
if(type == PasteDataType::TEXT) {
|
||||
|
|
@ -944,25 +934,49 @@ void InputManager::call_paste(CustomEvents::PasteEventDataType type, const Input
|
|||
inMan->process_text_paste(pData);
|
||||
}, this);
|
||||
}
|
||||
else {
|
||||
struct PasteData {
|
||||
std::optional<Vector2f> pos;
|
||||
InputManager* t;
|
||||
};
|
||||
static PasteData pasteData;
|
||||
pasteData.pos = info.pastePosition;
|
||||
pasteData.t = this;
|
||||
emscripten_browser_clipboard::paste_async_image([](std::string_view pasteData, void* callbackData){
|
||||
PasteData* p = (PasteData*)callbackData;
|
||||
p->t->process_image_paste(pasteData, p->pos);
|
||||
}, &pasteData);
|
||||
}
|
||||
#else
|
||||
switch(type) {
|
||||
case CustomEvents::PasteEventDataType::TEXT:
|
||||
case CustomEvents::PasteEvent::DataType::TEXT:
|
||||
process_text_paste(get_clipboard_str_SDL(), info.allowRichText);
|
||||
break;
|
||||
case CustomEvents::PasteEventDataType::IMAGE:
|
||||
case CustomEvents::PasteEvent::DataType::IMAGE:
|
||||
get_clipboard_image_data_SDL([&](std::string_view pasteData) {
|
||||
process_image_paste(pasteData, info.pastePosition);
|
||||
});
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void InputManager::process_text_paste(const std::string& pasteStr, bool allowRichText) {
|
||||
CustomEvents::emit_paste_event({
|
||||
.type = CustomEvents::PasteEventDataType::TEXT,
|
||||
CustomEvents::emit_event<CustomEvents::PasteEvent>({
|
||||
.type = CustomEvents::PasteEvent::DataType::TEXT,
|
||||
.data = pasteStr,
|
||||
.richText = allowRichText && lastCopiedRichText.has_value() && lastCopiedRichText.value().get_plain_text() == remove_carriage_returns_from_str(pasteStr) ? lastCopiedRichText : std::nullopt
|
||||
});
|
||||
}
|
||||
|
||||
void InputManager::process_image_paste(std::string_view pasteData, const std::optional<Vector2f>& pastePos) {
|
||||
CustomEvents::emit_event<CustomEvents::PasteEvent>({
|
||||
.type = CustomEvents::PasteEvent::DataType::IMAGE,
|
||||
.data = std::string(pasteData),
|
||||
.mousePos = pastePos
|
||||
});
|
||||
}
|
||||
|
||||
bool InputManager::ctrl_or_meta_held() {
|
||||
return key(KEY_GENERIC_LCTRL).held || key(KEY_GENERIC_LMETA).held;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,15 +4,11 @@
|
|||
#include <SDL3/SDL_properties.h>
|
||||
#include <SDL3/SDL_touch.h>
|
||||
#include <array>
|
||||
#include "RichText/TextStyleModifier.hpp"
|
||||
#include "RichText/TextBox.hpp"
|
||||
#include "TimePoint.hpp"
|
||||
#include <Helpers/Hashes.hpp>
|
||||
#include <unordered_map>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <queue>
|
||||
#include <Helpers/CallbackManager.hpp>
|
||||
#include "UndoManager.hpp"
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_events.h>
|
||||
|
|
@ -260,8 +256,6 @@ struct InputManager {
|
|||
void touch_finger_do_mouse_up(const SDL_TouchFingerEvent& f);
|
||||
void touch_finger_do_mouse_motion(const SDL_TouchFingerEvent& f);
|
||||
|
||||
void backend_open_infinipaint_file_event();
|
||||
void backend_paste_event();
|
||||
void backend_input_text_event(const std::string& str);
|
||||
void backend_drop_file_event(const SDL_DropEvent& e);
|
||||
void backend_drop_text_event(const SDL_DropEvent& e);
|
||||
|
|
@ -288,8 +282,9 @@ struct InputManager {
|
|||
std::string get_clipboard_str_SDL();
|
||||
void get_clipboard_image_data_SDL(const std::function<void(std::string_view data)>& callback);
|
||||
|
||||
void call_paste(CustomEvents::PasteEventDataType type, const InputManagerCallPasteInfo& info = {});
|
||||
void call_paste(CustomEvents::PasteEvent::DataType type, const InputManagerCallPasteInfo& info = {});
|
||||
void process_text_paste(const std::string& pasteStr, bool allowRichText);
|
||||
void process_image_paste(std::string_view pasteData, const std::optional<Vector2f>& pastePos);
|
||||
|
||||
std::optional<RichText::TextData> lastCopiedRichText;
|
||||
|
||||
|
|
|
|||
|
|
@ -267,7 +267,7 @@ sk_sp<SkSurface> MainProgram::create_native_surface(Vector2i resolution, bool is
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
void MainProgram::create_new_tab(const CustomEvents::OpenInfiniPaintFileEventData& openFile) {
|
||||
void MainProgram::create_new_tab(const CustomEvents::OpenInfiniPaintFileEvent& openFile) {
|
||||
std::shared_ptr<World> newWorld;
|
||||
try {
|
||||
newWorld = std::make_shared<World>(*this, openFile);
|
||||
|
|
@ -295,12 +295,18 @@ void MainProgram::post_callback() {
|
|||
g.post_callback();
|
||||
}
|
||||
|
||||
void MainProgram::input_open_infinipaint_file_callback(const CustomEvents::OpenInfiniPaintFileEventData& openFile) {
|
||||
void MainProgram::input_add_file_to_canvas_callback(const CustomEvents::AddFileToCanvasEvent& addFile) {
|
||||
if(world)
|
||||
world->input_add_file_to_canvas_callback(addFile);
|
||||
post_callback();
|
||||
}
|
||||
|
||||
void MainProgram::input_open_infinipaint_file_callback(const CustomEvents::OpenInfiniPaintFileEvent& openFile) {
|
||||
create_new_tab(openFile);
|
||||
post_callback();
|
||||
}
|
||||
|
||||
void MainProgram::input_paste_callback(const CustomEvents::PasteEventData& paste) {
|
||||
void MainProgram::input_paste_callback(const CustomEvents::PasteEvent& paste) {
|
||||
g.input_paste_callback(paste);
|
||||
if(world)
|
||||
world->input_paste_callback(paste);
|
||||
|
|
@ -330,7 +336,7 @@ void MainProgram::input_drop_file_callback(const InputManager::DropCallbackArgs&
|
|||
if(std::filesystem::is_regular_file(drop.data)) {
|
||||
std::filesystem::path droppedFilePath(drop.data);
|
||||
if(droppedFilePath.has_extension() && droppedFilePath.extension().string() == std::string("." + World::FILE_EXTENSION)) {
|
||||
CustomEvents::emit_open_infinipaint_file_event({
|
||||
CustomEvents::emit_event<CustomEvents::OpenInfiniPaintFileEvent>({
|
||||
.isClient = false,
|
||||
.filePathSource = droppedFilePath
|
||||
});
|
||||
|
|
|
|||
|
|
@ -119,8 +119,10 @@ class MainProgram {
|
|||
GlobalConfig conf;
|
||||
|
||||
std::optional<unsigned> keybindWaiting;
|
||||
void input_open_infinipaint_file_callback(const CustomEvents::OpenInfiniPaintFileEventData& openFile);
|
||||
void input_paste_callback(const CustomEvents::PasteEventData& paste);
|
||||
void input_add_file_to_canvas_callback(const CustomEvents::AddFileToCanvasEvent& addFile);
|
||||
void input_open_infinipaint_file_callback(const CustomEvents::OpenInfiniPaintFileEvent& openFile);
|
||||
void input_paste_callback(const CustomEvents::PasteEvent& paste);
|
||||
|
||||
bool input_keybind_callback(const Vector2ui32& newKey);
|
||||
void input_drop_file_callback(const InputManager::DropCallbackArgs& drop);
|
||||
void input_drop_text_callback(const InputManager::DropCallbackArgs& drop);
|
||||
|
|
@ -141,7 +143,7 @@ class MainProgram {
|
|||
void input_window_resize_callback(const InputManager::WindowResizeCallbackArgs& w);
|
||||
void input_window_scale_callback(const InputManager::WindowScaleCallbackArgs& w);
|
||||
|
||||
void create_new_tab(const CustomEvents::OpenInfiniPaintFileEventData& openFile);
|
||||
void create_new_tab(const CustomEvents::OpenInfiniPaintFileEvent& openFile);
|
||||
void set_tab_to_close(World* world);
|
||||
void switch_to_tab(size_t wIndex);
|
||||
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ RichTextUserInput::RichTextUserInput(const std::shared_ptr<RichText::TextBox>& i
|
|||
modMap(initModMap)
|
||||
{}
|
||||
|
||||
bool RichTextUserInput::input_paste_callback(const CustomEvents::PasteEventData& paste) {
|
||||
if(paste.type == CustomEvents::PasteEventDataType::TEXT) {
|
||||
bool RichTextUserInput::input_paste_callback(const CustomEvents::PasteEvent& paste) {
|
||||
if(paste.type == CustomEvents::PasteEvent::DataType::TEXT) {
|
||||
do_textbox_operation_with_undo([&]() {
|
||||
if(paste.richText.has_value())
|
||||
textBox->process_rich_text_input(*cursor, paste.richText.value());
|
||||
|
|
@ -104,7 +104,7 @@ RichTextUserInput::Changes RichTextUserInput::input_key_callback(InputManager& i
|
|||
toRet.textEdited = true;
|
||||
break;
|
||||
case InputManager::KEY_TEXT_PASTE:
|
||||
input.call_paste(CustomEvents::PasteEventDataType::TEXT);
|
||||
input.call_paste(CustomEvents::PasteEvent::DataType::TEXT);
|
||||
break;
|
||||
case InputManager::KEY_TEXT_SELECTALL:
|
||||
textBox->process_key_input(*cursor, RichText::TextBox::InputKey::SELECT_ALL, input.ctrl_or_meta_held(), input.key(InputManager::KEY_GENERIC_LSHIFT).held, modMapOpt);
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ class RichTextUserInput {
|
|||
bool cursorChanged = false;
|
||||
};
|
||||
Changes input_key_callback(InputManager& input, const InputManager::KeyCallbackArgs& key);
|
||||
bool input_paste_callback(const CustomEvents::PasteEventData& paste);
|
||||
bool input_paste_callback(const CustomEvents::PasteEvent& paste);
|
||||
void add_text_to_textbox(const std::string& inputText);
|
||||
void do_textbox_operation_with_undo(const std::function<void()>& func);
|
||||
void add_textbox_undo(const RichText::TextBox::Cursor& prevCursor, const RichText::TextData& prevRichText);
|
||||
|
|
|
|||
|
|
@ -619,7 +619,7 @@ void Toolbar::top_toolbar() {
|
|||
});
|
||||
};
|
||||
menu_popup_text_button("new file local", "New File", [&] {
|
||||
CustomEvents::emit_open_infinipaint_file_event({
|
||||
CustomEvents::emit_event<CustomEvents::OpenInfiniPaintFileEvent>({
|
||||
.isClient = false
|
||||
});
|
||||
});
|
||||
|
|
@ -630,24 +630,23 @@ void Toolbar::top_toolbar() {
|
|||
menu_popup_text_button("screenshot", "Screenshot", [&] { main.world->drawProg.switch_to_tool(DrawingProgramToolType::SCREENSHOT); });
|
||||
menu_popup_text_button("add image or file to canvas", "Add Image/File to Canvas", [&] {
|
||||
#ifdef __EMSCRIPTEN__
|
||||
static std::weak_ptr<World> worldWeakPtr;
|
||||
worldWeakPtr = make_weak_ptr(main.world);
|
||||
emscripten_browser_file::upload("*", [](std::string const& fileName, std::string const& mimeType, std::string_view buffer, void* callbackData) {
|
||||
if(!buffer.empty()) {
|
||||
auto world = ((std::weak_ptr<World>*)callbackData)->lock();
|
||||
if(world)
|
||||
world->drawProg.add_file_to_canvas_by_data(fileName, buffer, world->main.window.size.cast<float>() / 2.0f);
|
||||
else
|
||||
Logger::get().log("INFO", "Loading image to canvas that has been destroyed");
|
||||
auto& main = *static_cast<MainProgram*>(callbackData);
|
||||
CustomEvents::emit_event<CustomEvents::AddFileToCanvasEvent>({
|
||||
.type = CustomEvents::AddFileToCanvasEvent::Type::BUFFER,
|
||||
.name = fileName,
|
||||
.buffer = std::string(buffer)
|
||||
});
|
||||
}
|
||||
}, &worldWeakPtr);
|
||||
}, &main);
|
||||
#else
|
||||
open_file_selector("Open File", {{"Any File", "*"}}, [w = make_weak_ptr(main.world)](const std::filesystem::path& p, const auto& e) {
|
||||
auto wLock = w.lock();
|
||||
if(wLock)
|
||||
wLock->drawProg.add_file_to_canvas_by_path(p, wLock->main.window.size.cast<float>() / 2.0f, false);
|
||||
else
|
||||
Logger::get().log("INFO", "Loading image to canvas that has been destroyed");
|
||||
open_file_selector("Open File", {{"Any File", "*"}}, [&](const std::filesystem::path& p, const auto& e) {
|
||||
CustomEvents::emit_event<CustomEvents::AddFileToCanvasEvent>({
|
||||
.type = CustomEvents::AddFileToCanvasEvent::Type::PATH,
|
||||
.filePath = p,
|
||||
.pos = main.window.size.cast<float>() / 2.0f
|
||||
});
|
||||
});
|
||||
#endif
|
||||
});
|
||||
|
|
@ -1492,8 +1491,6 @@ void Toolbar::performance_metrics() {
|
|||
|
||||
void Toolbar::player_list() {
|
||||
auto& gui = main.g.gui;
|
||||
auto& io = gui.io;
|
||||
|
||||
|
||||
center_obstructing_window_gui("player client list", CLAY_SIZING_FIT(500), CLAY_SIZING_FIT(0), [&] {
|
||||
gui.new_id("client list", [&] {
|
||||
|
|
@ -1564,7 +1561,7 @@ void Toolbar::open_world_file(bool isClient, const std::string& netSource, const
|
|||
}, &uploadData);
|
||||
#else
|
||||
open_file_selector("Open", {{"InfiniPaint Canvas", World::FILE_EXTENSION}, {"Any File", "*"}}, [&, isClient = isClient, netSource = netSource, serverLocalID2 = serverLocalID2](const std::filesystem::path& p, const auto& e) {
|
||||
CustomEvents::emit_open_infinipaint_file_event({
|
||||
CustomEvents::emit_event<CustomEvents::OpenInfiniPaintFileEvent>({
|
||||
.isClient = isClient,
|
||||
.filePathSource = p,
|
||||
.netSource = netSource,
|
||||
|
|
@ -1600,7 +1597,6 @@ void Toolbar::center_obstructing_window_gui(const char* id, Clay_SizingAxis x, C
|
|||
|
||||
void Toolbar::text_button_wide(const char* id, const char* str, const std::function<void()>& onClick) {
|
||||
auto& gui = main.g.gui;
|
||||
auto& io = gui.io;
|
||||
|
||||
text_button(gui, id, str, {
|
||||
.wide = true,
|
||||
|
|
@ -1610,7 +1606,6 @@ void Toolbar::text_button_wide(const char* id, const char* str, const std::funct
|
|||
|
||||
void Toolbar::options_menu() {
|
||||
auto& gui = main.g.gui;
|
||||
auto& io = gui.io;
|
||||
|
||||
switch(optionsMenuType) {
|
||||
case HOST_MENU: {
|
||||
|
|
@ -1641,7 +1636,7 @@ void Toolbar::options_menu() {
|
|||
else if(serverToConnectTo.substr(0, NetLibrary::GLOBALID_LEN) == NetLibrary::get_global_id())
|
||||
Logger::get().log("USERINFO", "Connect issue: Can't connect to your own address");
|
||||
else {
|
||||
CustomEvents::emit_open_infinipaint_file_event({
|
||||
CustomEvents::emit_event<CustomEvents::OpenInfiniPaintFileEvent>({
|
||||
.isClient = true,
|
||||
.netSource = serverToConnectTo
|
||||
});
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@
|
|||
#include <EmscriptenHelpers/emscripten_browser_file.h>
|
||||
#endif
|
||||
|
||||
World::World(MainProgram& initMain, const CustomEvents::OpenInfiniPaintFileEventData& worldInfo):
|
||||
World::World(MainProgram& initMain, const CustomEvents::OpenInfiniPaintFileEvent& worldInfo):
|
||||
netObjMan(!worldInfo.isClient),
|
||||
main(initMain),
|
||||
undo(*this),
|
||||
|
|
@ -250,7 +250,12 @@ void World::on_tab_out() {
|
|||
rMan.clear_display_cache();
|
||||
}
|
||||
|
||||
void World::input_paste_callback(const CustomEvents::PasteEventData& paste) {
|
||||
void World::input_add_file_to_canvas_callback(const CustomEvents::AddFileToCanvasEvent& addFile) {
|
||||
if(!clientStillConnecting)
|
||||
drawProg.input_add_file_to_canvas_callback(addFile);
|
||||
}
|
||||
|
||||
void World::input_paste_callback(const CustomEvents::PasteEvent& paste) {
|
||||
if(!clientStillConnecting)
|
||||
drawProg.input_paste_callback(paste);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class World {
|
|||
static constexpr std::string FILE_EXTENSION = "infpnt";
|
||||
static constexpr size_t CHAT_SIZE = 10;
|
||||
|
||||
World(MainProgram& initMain, const CustomEvents::OpenInfiniPaintFileEventData& worldInfo);
|
||||
World(MainProgram& initMain, const CustomEvents::OpenInfiniPaintFileEvent& worldInfo);
|
||||
|
||||
// NOTE: Keep at the very beginning so that it's destroyed last
|
||||
NetworkingObjects::NetObjManager netObjMan;
|
||||
|
|
@ -89,7 +89,8 @@ class World {
|
|||
std::shared_ptr<NetServer> netServer;
|
||||
std::shared_ptr<NetClient> netClient;
|
||||
|
||||
void input_paste_callback(const CustomEvents::PasteEventData& paste);
|
||||
void input_add_file_to_canvas_callback(const CustomEvents::AddFileToCanvasEvent& addFile);
|
||||
void input_paste_callback(const CustomEvents::PasteEvent& paste);
|
||||
void input_drop_file_callback(const InputManager::DropCallbackArgs& drop);
|
||||
void input_drop_text_callback(const InputManager::DropCallbackArgs& drop);
|
||||
void input_text_key_callback(const InputManager::KeyCallbackArgs& key);
|
||||
|
|
|
|||
16
src/main.cpp
16
src/main.cpp
|
|
@ -794,10 +794,18 @@ SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) {
|
|||
case SDL_EVENT_SCREEN_KEYBOARD_HIDDEN:
|
||||
break;
|
||||
default: {
|
||||
if(event->type == CustomEvents::PASTE_EVENT)
|
||||
mS.m->input.backend_paste_event();
|
||||
else if(event->type == CustomEvents::OPEN_INFINIPAINT_FILE_EVENT)
|
||||
mS.m->input.backend_open_infinipaint_file_event();
|
||||
if(event->type == CustomEvents::PasteEvent::EVENT_NUM) {
|
||||
mS.m->input_paste_callback(CustomEvents::get_event<CustomEvents::PasteEvent>());
|
||||
CustomEvents::pop_event();
|
||||
}
|
||||
else if(event->type == CustomEvents::OpenInfiniPaintFileEvent::EVENT_NUM) {
|
||||
mS.m->input_open_infinipaint_file_callback(CustomEvents::get_event<CustomEvents::OpenInfiniPaintFileEvent>());
|
||||
CustomEvents::pop_event();
|
||||
}
|
||||
else if(event->type == CustomEvents::AddFileToCanvasEvent::EVENT_NUM) {
|
||||
mS.m->input_add_file_to_canvas_callback(CustomEvents::get_event<CustomEvents::AddFileToCanvasEvent>());
|
||||
CustomEvents::pop_event();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue