Skip to content

Commit

Permalink
Call jngl::Job::onFileDrop when using Drag'n'Drop, SDL2 backend only …
Browse files Browse the repository at this point in the history
…for now
  • Loading branch information
jhasse committed Dec 2, 2024
1 parent 13fe217 commit bb1e5b8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/jngl/job.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ namespace jngl {

Job::~Job() = default;

void Job::onFileDrop(const std::filesystem::path&) {
}

void addJob(std::shared_ptr<Job> job) {
pWindow->addJob(std::move(job));
}
Expand Down
4 changes: 4 additions & 0 deletions src/jngl/job.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/// @file
#pragma once

#include <filesystem>
#include <functional>
#include <memory>

Expand Down Expand Up @@ -34,6 +35,9 @@ class Job {
/// \note JNGL's main loop calls all Jobs' draw() functions after the active Work's draw()
virtual void draw() const = 0;

/// Called when a file has been dropped onto the window
virtual void onFileDrop(const std::filesystem::path&);

/// Does nothing
Job() = default;

Expand Down
14 changes: 14 additions & 0 deletions src/sdl/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,20 @@ void Window::UpdateInput() {
width_ = originalWidth;
height_ = originalHeight;
}
break;
case SDL_DROPFILE:
if (event.drop.file) {
std::filesystem::path path(event.drop.file);
SDL_free(event.drop.file);
assert(std::filesystem::exists(path));
for (const auto& job : jobs) {
job->onFileDrop(path);
}
if (currentWork_) {
currentWork_->onFileDrop(path);
}
}
break;
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ class Test : public jngl::Work {
}
}
private:
void onFileDrop(const std::filesystem::path& file) override {
jngl::errorMessage(file.string() + " dropped on window.");
}

mutable bool drawOnFrameBuffer = false;
bool useShader = false;
mutable double rotate = 0;
Expand Down

0 comments on commit bb1e5b8

Please sign in to comment.