2023-10-04 02:11:06 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <functional>
|
|
|
|
#include <memory>
|
2023-10-04 20:17:53 +02:00
|
|
|
#include <vector>
|
2023-10-04 02:11:06 +02:00
|
|
|
|
|
|
|
#include "./image_loader.hpp"
|
|
|
|
#include "./texture_cache.hpp"
|
|
|
|
|
|
|
|
struct SendImagePopup {
|
|
|
|
TextureUploaderI& _tu;
|
|
|
|
|
|
|
|
// private
|
|
|
|
std::vector<std::unique_ptr<ImageLoaderI>> _image_loaders;
|
2023-10-09 21:17:00 +02:00
|
|
|
std::vector<std::unique_ptr<ImageEncoderI>> _image_encoders;
|
2023-10-04 02:11:06 +02:00
|
|
|
|
|
|
|
// copy of the original data, dont touch!
|
|
|
|
std::vector<uint8_t> original_data;
|
|
|
|
bool original_raw {false};
|
|
|
|
std::string original_file_ext; // if !original_raw
|
|
|
|
|
|
|
|
ImageLoaderI::ImageResult original_image;
|
|
|
|
|
|
|
|
struct Rect {
|
2023-10-05 14:23:39 +02:00
|
|
|
int32_t x {0};
|
|
|
|
int32_t y {0};
|
2023-10-04 02:11:06 +02:00
|
|
|
|
2023-10-05 14:23:39 +02:00
|
|
|
int32_t w {0};
|
|
|
|
int32_t h {0};
|
2023-10-04 02:11:06 +02:00
|
|
|
};
|
|
|
|
Rect crop_rect;
|
2023-10-05 14:54:42 +02:00
|
|
|
Rect crop_before_drag;
|
2023-10-04 02:11:06 +02:00
|
|
|
|
2024-02-29 19:15:33 +01:00
|
|
|
bool cropping {false};
|
2023-10-05 16:24:51 +02:00
|
|
|
bool dragging_last_frame_ul {false};
|
|
|
|
bool dragging_last_frame_lr {false};
|
2023-10-05 14:23:39 +02:00
|
|
|
|
2023-10-04 02:11:06 +02:00
|
|
|
// texture to render (orig img)
|
|
|
|
TextureEntry preview_image;
|
|
|
|
|
2023-10-04 20:17:53 +02:00
|
|
|
bool compress {false};
|
|
|
|
uint32_t quality {80u};
|
2023-10-09 21:17:00 +02:00
|
|
|
uint32_t compression_level {8u};
|
2023-10-04 20:17:53 +02:00
|
|
|
|
2023-10-05 18:26:35 +02:00
|
|
|
float time {0.f}; // cycling form 0 to 1 over time
|
|
|
|
|
2023-10-04 02:11:06 +02:00
|
|
|
bool _open_popup {false};
|
|
|
|
|
|
|
|
std::function<void(const std::vector<uint8_t>&, std::string_view)> _on_send = [](const auto&, auto){};
|
|
|
|
std::function<void(void)> _on_cancel = [](){};
|
|
|
|
|
|
|
|
void reset(void);
|
|
|
|
|
|
|
|
// loads the image in original_data
|
|
|
|
// fills in original_image, preview_image and crop_rect
|
|
|
|
// returns if loaded successfully
|
|
|
|
bool load(void);
|
|
|
|
|
2023-10-05 14:54:42 +02:00
|
|
|
static Rect sanitizeCrop(Rect crop_rect, int32_t image_width, int32_t image_height);
|
2023-10-04 20:17:53 +02:00
|
|
|
|
2023-10-04 02:11:06 +02:00
|
|
|
public:
|
|
|
|
SendImagePopup(TextureUploaderI& tu);
|
|
|
|
|
|
|
|
void sendMemory(
|
|
|
|
const uint8_t* data, size_t data_size,
|
|
|
|
std::function<void(const std::vector<uint8_t>&, std::string_view)>&& on_send,
|
|
|
|
std::function<void(void)>&& on_cancel
|
|
|
|
);
|
|
|
|
// from memory_raw
|
|
|
|
// from file_path
|
|
|
|
|
|
|
|
// call this each frame
|
2024-01-07 16:33:08 +01:00
|
|
|
void render(float time_delta);
|
2023-10-04 02:11:06 +02:00
|
|
|
};
|
|
|
|
|