2019-01-13 03:53:42 +01:00
|
|
|
//
|
|
|
|
// Created by Syméon on 13/01/2019.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef FEIS_TOOLBOX_H
|
|
|
|
#define FEIS_TOOLBOX_H
|
|
|
|
|
2019-01-13 22:29:29 +01:00
|
|
|
#define IM_MAX(_A,_B) (((_A) >= (_B)) ? (_A) : (_B))
|
|
|
|
|
2019-01-13 03:53:42 +01:00
|
|
|
#include <SFML/Window.hpp>
|
|
|
|
#include <filesystem>
|
|
|
|
|
|
|
|
namespace Toolbox {
|
|
|
|
bool isShortcutPressed(std::initializer_list<sf::Keyboard::Key> anyOf, std::initializer_list<sf::Keyboard::Key> allOf);
|
|
|
|
void pushNewRecentFile(std::filesystem::path path);
|
|
|
|
std::vector<std::string> getRecentFiles();
|
2019-01-13 22:29:29 +01:00
|
|
|
|
|
|
|
struct CustomConstraints {
|
|
|
|
static void ContentSquare(ImGuiSizeCallbackData* data) {
|
|
|
|
float TitlebarHeight = ImGui::GetFontSize() + ImGui::GetStyle().FramePadding.y * 2.f;
|
|
|
|
float y = data->DesiredSize.y - TitlebarHeight;
|
|
|
|
float x = data->DesiredSize.x;
|
|
|
|
data->DesiredSize = ImVec2(IM_MAX(x,y), IM_MAX(x,y) + TitlebarHeight);
|
|
|
|
}
|
|
|
|
};
|
2019-01-13 03:53:42 +01:00
|
|
|
}
|
|
|
|
|
2019-01-14 04:20:30 +01:00
|
|
|
template<typename T>
|
|
|
|
class AffineTransform {
|
|
|
|
public:
|
|
|
|
AffineTransform(T low_input, T high_input, T low_output, T high_output) {
|
|
|
|
if (low_input == high_input) {
|
|
|
|
throw std::invalid_argument("low and high input values for affine transform must be different !");
|
|
|
|
}
|
|
|
|
a = (high_output-low_output)/(high_input-low_input);
|
|
|
|
b = (high_input*low_output - high_output*low_input)/(high_input-low_input);
|
|
|
|
};
|
|
|
|
T transform(T val) {return a*val + b;};
|
|
|
|
T backwards_transform(T val) {
|
|
|
|
// if we're too close to zero
|
|
|
|
if (std::abs(a) < 10e-10) {
|
|
|
|
throw std::runtime_error("Can't apply backwards transformation, coefficient is too close to zero");
|
|
|
|
} else {
|
|
|
|
return (val-b)/a;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
private:
|
|
|
|
T a;
|
|
|
|
T b;
|
|
|
|
};
|
|
|
|
|
2019-01-13 03:53:42 +01:00
|
|
|
#endif //FEIS_TOOLBOX_H
|