Add better timings, and proper configuration

This commit is contained in:
TennesseeTrash 2025-06-08 00:23:46 +02:00
parent 0b32af33b8
commit 5750bb8177
13 changed files with 385 additions and 240 deletions

View file

@ -1,20 +0,0 @@
#ifndef KANIMAJI_CONFIG_HPP
#define KANIMAJI_CONFIG_HPP
#include "Colour.hpp"
namespace Kanimaji
{
struct GroupConfig
{
double Width;
Colour Colour;
};
struct AnimationSettings
{
};
}
#endif // KANIMAJI_CONFIG_HPP

View file

@ -1,9 +1,32 @@
#ifndef KANIMAJI_ERROR_HPP
#define KANIMAJI_ERROR_HPP
#include <stdexcept>
namespace Kanimaji
{
class Error : public std::runtime_error
{
using std::runtime_error::runtime_error;
};
class FileError : public Error
{
using Error::Error;
};
class ParseError : public Error
{
public:
ParseError(std::size_t current, std::string_view message);
std::size_t Position() const
{
return mPosition;
}
private:
std::size_t mPosition;
};
}
#endif // KANIMAJI_ERROR_HPP

View file

@ -1,16 +1,20 @@
#ifndef KANIMAJI_KANIMAJI_HPP
#define KANIMAJI_KANIMAJI_HPP
#include "Settings.hpp"
#include <filesystem>
#include <string>
namespace Kanimaji
{
bool Animate(const std::string& source, const std::string& destination);
using Path = std::filesystem::path;
constexpr bool Animate(const std::string& filename)
{
return Animate(filename, filename);
}
void AnimateFile(const Path& source, const Path& destination,
const AnimationSettings& settings = AnimationSettings::Default());
std::string Animate(const std::string& source,
const AnimationSettings& settings = AnimationSettings::Default());
}
#endif // KANIMAJI_KANIMAJI_HPP

View file

@ -1,5 +1,5 @@
#ifndef KANIMAJI_COLOUR_HPP
#define KANIMAJI_COLOUR_HPP
#ifndef KANIMAJI_RGB_HPP
#define KANIMAJI_RGB_HPP
#include <cstdint>
#include <string>
@ -56,16 +56,16 @@ namespace Kanimaji
}
}
struct Colour
struct RGB
{
std::uint8_t Red;
std::uint8_t Green;
std::uint8_t Blue;
static constexpr Colour FromHex(std::string_view hex)
static constexpr RGB FromHex(std::string_view hex)
{
if (hex.empty()) {
return Colour { .Red = 0, .Green = 0, .Blue = 0 };
return RGB { .Red = 0, .Green = 0, .Blue = 0 };
}
if (hex[0] == '#') {
@ -74,12 +74,12 @@ namespace Kanimaji
for (char ch : hex) {
if ((ch < '0' || ch > '9') && (ch < 'A' || ch > 'F') && (ch < 'a' && ch > 'f')) {
return Colour { .Red = 0, .Green = 0, .Blue = 0 };
return RGB { .Red = 0, .Green = 0, .Blue = 0 };
}
}
if (hex.length() == 3) {
return Colour {
return RGB {
.Red = Implementation::ToDec(hex[0]),
.Green = Implementation::ToDec(hex[1]),
.Blue = Implementation::ToDec(hex[2]),
@ -87,14 +87,14 @@ namespace Kanimaji
}
if (hex.length() == 6) {
return Colour {
return RGB {
.Red = Implementation::ToDec(hex[0], hex[1]),
.Green = Implementation::ToDec(hex[2], hex[3]),
.Blue = Implementation::ToDec(hex[4], hex[5]),
};
}
return Colour { .Red = 0, .Green = 0, .Blue = 0 };
return RGB { .Red = 0, .Green = 0, .Blue = 0 };
}
constexpr std::string ToHex() const
@ -108,4 +108,4 @@ namespace Kanimaji
};
}
#endif // KANIMAJI_COLOUR_HPP
#endif // KANIMAJI_RGB_HPP

View file

@ -0,0 +1,52 @@
#ifndef KANIMAJI_CONFIG_HPP
#define KANIMAJI_CONFIG_HPP
#include "RGB.hpp"
#include <chrono>
#include <functional>
namespace Kanimaji
{
enum class Flag {
Enable, Disable,
};
enum class Progression {
Linear,
EaseIn,
EaseOut,
EaseInOut,
};
std::string ToString(Progression progression);
struct StrokeStyle
{
double Width;
RGB Colour;
};
using TimeScalingFunc = std::function<double(double)>;
using Duration = std::chrono::duration<double, std::ratio<1>>;
struct AnimationSettings
{
Progression StrokeProgression;
StrokeStyle UnfilledStroke;
StrokeStyle FilledStroke;
RGB StrokeFillingColour;
Flag EnableBrush;
StrokeStyle Brush;
StrokeStyle BrushBorder;
TimeScalingFunc LengthToTimeScaling;
Duration WaitBeforeRepeating;
Duration DelayBetweenStrokes;
static AnimationSettings Default();
};
}
#endif // KANIMAJI_CONFIG_HPP