Remove namespaces, and make file-local helpers static
Names that only a namespace told apart get prefixes: TOOL_PAN, FONT_BOLD, ICON_FOLDER, COLOR_WHITE, path_to_utf8 and so on. The OpenGL shader class is ShaderProgram, and its uniform ShaderUniform, beside the document's Shader and Uniform. Free functions a member of the same name would hide are called through :: for now. Two unused shader window helpers are gone.
This commit is contained in:
1 parent
7fb2c607c2
commit
666f65bf3a
174 files changed
+2396
-3154
No files matched your search
+3
-6
@@ -2,25 +2,23 @@
|
|||||||
|
|
||||||
#include <span>
|
#include <span>
|
||||||
|
|
||||||
namespace anm2ed::resource
|
|
||||||
{
|
|
||||||
constexpr std::uint64_t FNV_OFFSET = 14695981039346656037ull;
|
constexpr std::uint64_t FNV_OFFSET = 14695981039346656037ull;
|
||||||
constexpr std::uint64_t FNV_PRIME = 1099511628211ull;
|
constexpr std::uint64_t FNV_PRIME = 1099511628211ull;
|
||||||
|
|
||||||
std::uint64_t bytes_hash(std::span<const std::uint8_t> bytes, std::uint64_t hash = FNV_OFFSET)
|
static std::uint64_t bytes_hash(std::span<const std::uint8_t> bytes, std::uint64_t hash = FNV_OFFSET)
|
||||||
{
|
{
|
||||||
for (auto byte : bytes)
|
for (auto byte : bytes)
|
||||||
hash = (hash ^ byte) * FNV_PRIME;
|
hash = (hash ^ byte) * FNV_PRIME;
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Value> std::span<const std::uint8_t> value_bytes_get(const Value& value)
|
template <class Value> static std::span<const std::uint8_t> value_bytes_get(const Value& value)
|
||||||
{
|
{
|
||||||
return {reinterpret_cast<const std::uint8_t*>(&value), sizeof(value)};
|
return {reinterpret_cast<const std::uint8_t*>(&value), sizeof(value)};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Content hash; 0 stays free to mean "no asset".
|
// Content hash; 0 stays free to mean "no asset".
|
||||||
std::uint64_t hash_finish(std::uint64_t hash) { return hash ? hash : 1; }
|
static std::uint64_t hash_finish(std::uint64_t hash) { return hash ? hash : 1; }
|
||||||
|
|
||||||
std::uint64_t AssetStore::image_add(Image image)
|
std::uint64_t AssetStore::image_add(Image image)
|
||||||
{
|
{
|
||||||
@@ -51,4 +49,3 @@ namespace anm2ed::resource
|
|||||||
auto it = audio.find(hash);
|
auto it = audio.find(hash);
|
||||||
return it == audio.end() ? nullptr : &it->second;
|
return it == audio.end() ? nullptr : &it->second;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -6,8 +6,6 @@
|
|||||||
#include "audio_data.h"
|
#include "audio_data.h"
|
||||||
#include "image.h"
|
#include "image.h"
|
||||||
|
|
||||||
namespace anm2ed::resource
|
|
||||||
{
|
|
||||||
// Immutable images and sounds keyed by content hash. Undo history records keys, never pixels or bytes, and
|
// Immutable images and sounds keyed by content hash. Undo history records keys, never pixels or bytes, and
|
||||||
// entries live until the document closes so any step can be restored.
|
// entries live until the document closes so any step can be restored.
|
||||||
class AssetStore
|
class AssetStore
|
||||||
@@ -21,4 +19,3 @@ namespace anm2ed::resource
|
|||||||
const Image* image_get(std::uint64_t) const;
|
const Image* image_get(std::uint64_t) const;
|
||||||
const AudioData* audio_get(std::uint64_t) const;
|
const AudioData* audio_get(std::uint64_t) const;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
+14
-17
@@ -6,9 +6,7 @@
|
|||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace anm2ed::resource::audio
|
struct AudioEntry
|
||||||
{
|
|
||||||
struct Entry
|
|
||||||
{
|
{
|
||||||
MIX_Audio* audio{};
|
MIX_Audio* audio{};
|
||||||
std::vector<MIX_Track*> tracks{}; // one per overlapping play, reused once finished
|
std::vector<MIX_Track*> tracks{}; // one per overlapping play, reused once finished
|
||||||
@@ -17,9 +15,9 @@ namespace anm2ed::resource::audio
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Sums the squares of the left/right samples the track plays, for its levels.
|
// Sums the squares of the left/right samples the track plays, for its levels.
|
||||||
void SDLCALL levels_update(void* userdata, MIX_Track*, const SDL_AudioSpec* spec, float* pcm, int samples)
|
static void SDLCALL levels_update(void* userdata, MIX_Track*, const SDL_AudioSpec* spec, float* pcm, int samples)
|
||||||
{
|
{
|
||||||
auto entry = (Entry*)userdata;
|
auto entry = (AudioEntry*)userdata;
|
||||||
auto channels = std::max(spec->channels, 1);
|
auto channels = std::max(spec->channels, 1);
|
||||||
float squares[2]{};
|
float squares[2]{};
|
||||||
for (int i = 0; i < samples; ++i)
|
for (int i = 0; i < samples; ++i)
|
||||||
@@ -30,31 +28,31 @@ namespace anm2ed::resource::audio
|
|||||||
entry->sampleCount += samples / channels;
|
entry->sampleCount += samples / channels;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unordered_map<std::uint64_t, Entry> entries{};
|
static std::unordered_map<std::uint64_t, AudioEntry> entries{};
|
||||||
|
|
||||||
MIX_Mixer* mixer_get()
|
static MIX_Mixer* audio_mixer_get()
|
||||||
{
|
{
|
||||||
static auto mixer = MIX_CreateMixerDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, nullptr);
|
static auto mixer = MIX_CreateMixerDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, nullptr);
|
||||||
return mixer;
|
return mixer;
|
||||||
}
|
}
|
||||||
|
|
||||||
Entry* entry_get(const AudioData& data)
|
static AudioEntry* entry_get(const AudioData& data)
|
||||||
{
|
{
|
||||||
if (!data.is_valid()) return nullptr;
|
if (!data.is_valid()) return nullptr;
|
||||||
auto [it, isNew] = entries.try_emplace(data.uid);
|
auto [it, isNew] = entries.try_emplace(data.uid);
|
||||||
if (isNew)
|
if (isNew)
|
||||||
if (auto io = SDL_IOFromConstMem(data.bytes.data(), data.bytes.size()))
|
if (auto io = SDL_IOFromConstMem(data.bytes.data(), data.bytes.size()))
|
||||||
it->second.audio = MIX_LoadAudio_IO(mixer_get(), io, true, true);
|
it->second.audio = MIX_LoadAudio_IO(audio_mixer_get(), io, true, true);
|
||||||
return it->second.audio ? &it->second : nullptr;
|
return it->second.audio ? &it->second : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_on_mixer(MIX_Track* track, MIX_Mixer* mixer) { return !mixer || MIX_GetTrackMixer(track) == mixer; }
|
static bool is_on_mixer(MIX_Track* track, MIX_Mixer* mixer) { return !mixer || MIX_GetTrackMixer(track) == mixer; }
|
||||||
|
|
||||||
// A sound can play over itself: while a track is still playing it, another track takes the new play.
|
// A sound can play over itself: while a track is still playing it, another track takes the new play.
|
||||||
void play(const AudioData& data, bool isLoop, MIX_Mixer* mixer)
|
void audio_play(const AudioData& data, bool isLoop, MIX_Mixer* mixer)
|
||||||
{
|
{
|
||||||
auto entry = entry_get(data);
|
auto entry = entry_get(data);
|
||||||
auto targetMixer = mixer ? mixer : mixer_get();
|
auto targetMixer = mixer ? mixer : audio_mixer_get();
|
||||||
if (!entry || !targetMixer) return;
|
if (!entry || !targetMixer) return;
|
||||||
|
|
||||||
auto free = std::ranges::find_if(entry->tracks, [&](MIX_Track* track)
|
auto free = std::ranges::find_if(entry->tracks, [&](MIX_Track* track)
|
||||||
@@ -74,14 +72,14 @@ namespace anm2ed::resource::audio
|
|||||||
if (options) SDL_DestroyProperties(options);
|
if (options) SDL_DestroyProperties(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
void stop(const AudioData& data, MIX_Mixer* mixer)
|
void audio_stop(const AudioData& data, MIX_Mixer* mixer)
|
||||||
{
|
{
|
||||||
if (auto it = entries.find(data.uid); it != entries.end())
|
if (auto it = entries.find(data.uid); it != entries.end())
|
||||||
for (auto track : it->second.tracks)
|
for (auto track : it->second.tracks)
|
||||||
if (is_on_mixer(track, mixer)) MIX_StopTrack(track, 0);
|
if (is_on_mixer(track, mixer)) MIX_StopTrack(track, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void track_detach(const AudioData& data, MIX_Mixer* mixer)
|
void audio_track_detach(const AudioData& data, MIX_Mixer* mixer)
|
||||||
{
|
{
|
||||||
auto it = entries.find(data.uid);
|
auto it = entries.find(data.uid);
|
||||||
if (it == entries.end()) return;
|
if (it == entries.end()) return;
|
||||||
@@ -94,14 +92,14 @@ namespace anm2ed::resource::audio
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_playing(const AudioData& data)
|
bool is_audio_playing(const AudioData& data)
|
||||||
{
|
{
|
||||||
auto it = entries.find(data.uid);
|
auto it = entries.find(data.uid);
|
||||||
return it != entries.end() && std::ranges::any_of(it->second.tracks, MIX_TrackPlaying);
|
return it != entries.end() && std::ranges::any_of(it->second.tracks, MIX_TrackPlaying);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The left/right loudness (RMS, 0-1) of what the track played since the last call.
|
// The left/right loudness (RMS, 0-1) of what the track played since the last call.
|
||||||
glm::vec2 levels_get(const AudioData& data)
|
glm::vec2 audio_levels_get(const AudioData& data)
|
||||||
{
|
{
|
||||||
auto it = entries.find(data.uid);
|
auto it = entries.find(data.uid);
|
||||||
if (it == entries.end()) return {};
|
if (it == entries.end()) return {};
|
||||||
@@ -109,4 +107,3 @@ namespace anm2ed::resource::audio
|
|||||||
auto count = (float)std::max(entry.sampleCount.exchange(0), 1);
|
auto count = (float)std::max(entry.sampleCount.exchange(0), 1);
|
||||||
return {std::sqrt(entry.squares[0].exchange(0.0f) / count), std::sqrt(entry.squares[1].exchange(0.0f) / count)};
|
return {std::sqrt(entry.squares[0].exchange(0.0f) / count), std::sqrt(entry.squares[1].exchange(0.0f) / count)};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
+5
-8
@@ -6,11 +6,8 @@
|
|||||||
#include "audio_data.h"
|
#include "audio_data.h"
|
||||||
|
|
||||||
// Playback of AudioData; decoded audio and tracks are cached per AudioData uid.
|
// Playback of AudioData; decoded audio and tracks are cached per AudioData uid.
|
||||||
namespace anm2ed::resource::audio
|
void audio_play(const AudioData&, bool = false, MIX_Mixer* = nullptr);
|
||||||
{
|
void audio_stop(const AudioData&, MIX_Mixer* = nullptr);
|
||||||
void play(const AudioData&, bool = false, MIX_Mixer* = nullptr);
|
void audio_track_detach(const AudioData&, MIX_Mixer* = nullptr);
|
||||||
void stop(const AudioData&, MIX_Mixer* = nullptr);
|
bool is_audio_playing(const AudioData&);
|
||||||
void track_detach(const AudioData&, MIX_Mixer* = nullptr);
|
glm::vec2 audio_levels_get(const AudioData&);
|
||||||
bool is_playing(const AudioData&);
|
|
||||||
glm::vec2 levels_get(const AudioData&);
|
|
||||||
}
|
|
||||||
+1
-4
@@ -5,13 +5,11 @@
|
|||||||
|
|
||||||
#include "uid.h"
|
#include "uid.h"
|
||||||
|
|
||||||
namespace anm2ed::resource
|
|
||||||
{
|
|
||||||
AudioData::AudioData(const unsigned char* memory, size_t size)
|
AudioData::AudioData(const unsigned char* memory, size_t size)
|
||||||
{
|
{
|
||||||
if (!memory || size == 0) return;
|
if (!memory || size == 0) return;
|
||||||
bytes.assign(memory, memory + size);
|
bytes.assign(memory, memory + size);
|
||||||
uid = util::uid_next();
|
uid = uid_next();
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioData::AudioData(const std::filesystem::path& path)
|
AudioData::AudioData(const std::filesystem::path& path)
|
||||||
@@ -22,4 +20,3 @@ namespace anm2ed::resource
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool AudioData::is_valid() const { return !bytes.empty(); }
|
bool AudioData::is_valid() const { return !bytes.empty(); }
|
||||||
}
|
|
||||||
@@ -5,8 +5,6 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace anm2ed::resource
|
|
||||||
{
|
|
||||||
// Encoded audio file bytes. uid identifies the bytes so playback state can be cached by it.
|
// Encoded audio file bytes. uid identifies the bytes so playback state can be cached by it.
|
||||||
struct AudioData
|
struct AudioData
|
||||||
{
|
{
|
||||||
@@ -19,4 +17,3 @@ namespace anm2ed::resource
|
|||||||
|
|
||||||
bool is_valid() const;
|
bool is_valid() const;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
@@ -7,8 +7,6 @@
|
|||||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
void AudioStream::callback(void* userData, MIX_Mixer* mixer, const SDL_AudioSpec* spec, float* pcm, int samples)
|
void AudioStream::callback(void* userData, MIX_Mixer* mixer, const SDL_AudioSpec* spec, float* pcm, int samples)
|
||||||
{
|
{
|
||||||
auto self = (AudioStream*)userData;
|
auto self = (AudioStream*)userData;
|
||||||
@@ -23,4 +21,3 @@ namespace anm2ed
|
|||||||
|
|
||||||
AudioStream::AudioStream(MIX_Mixer* mixer) { MIX_GetMixerFormat(mixer, &spec); }
|
AudioStream::AudioStream(MIX_Mixer* mixer) { MIX_GetMixerFormat(mixer, &spec); }
|
||||||
|
|
||||||
}
|
|
||||||
@@ -3,8 +3,6 @@
|
|||||||
#include <SDL3_mixer/SDL_mixer.h>
|
#include <SDL3_mixer/SDL_mixer.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
class AudioStream
|
class AudioStream
|
||||||
{
|
{
|
||||||
static void callback(void*, MIX_Mixer*, const SDL_AudioSpec*, float*, int);
|
static void callback(void*, MIX_Mixer*, const SDL_AudioSpec*, float*, int);
|
||||||
@@ -19,4 +17,3 @@ namespace anm2ed
|
|||||||
|
|
||||||
AudioStream(MIX_Mixer*);
|
AudioStream(MIX_Mixer*);
|
||||||
};
|
};
|
||||||
}
|
|
||||||
+67
-72
@@ -9,24 +9,20 @@
|
|||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
|
|
||||||
using namespace glm;
|
using namespace glm;
|
||||||
using namespace anm2ed::resource;
|
|
||||||
using namespace anm2ed::util;
|
|
||||||
|
|
||||||
namespace anm2ed
|
static void canvas_blend_premultiplied_set()
|
||||||
{
|
|
||||||
void canvas_blend_premultiplied_set()
|
|
||||||
{
|
{
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
}
|
}
|
||||||
|
|
||||||
void canvas_blend_straight_set()
|
static void canvas_blend_straight_set()
|
||||||
{
|
{
|
||||||
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vertex_array_make(GLuint& vao, GLuint& vbo, const void* data, GLsizeiptr size, GLenum usage,
|
static void vertex_array_make(GLuint& vao, GLuint& vbo, const void* data, GLsizeiptr size, GLenum usage,
|
||||||
std::initializer_list<int> attributeSizes)
|
std::initializer_list<int> attributeSizes)
|
||||||
{
|
{
|
||||||
glGenVertexArrays(1, &vao);
|
glGenVertexArrays(1, &vao);
|
||||||
@@ -75,7 +71,7 @@ namespace anm2ed
|
|||||||
|
|
||||||
mat4 Canvas::transform_get(float zoom, vec2 pan) const
|
mat4 Canvas::transform_get(float zoom, vec2 pan) const
|
||||||
{
|
{
|
||||||
auto zoomFactor = math::percent_to_unit(zoom);
|
auto zoomFactor = percent_to_unit(zoom);
|
||||||
auto projection = glm::ortho(0.0f, (float)size.x, 0.0f, (float)size.y, -1.0f, 1.0f);
|
auto projection = glm::ortho(0.0f, (float)size.x, 0.0f, (float)size.y, -1.0f, 1.0f);
|
||||||
auto view = mat4{1.0f};
|
auto view = mat4{1.0f};
|
||||||
|
|
||||||
@@ -85,7 +81,7 @@ namespace anm2ed
|
|||||||
return projection * view;
|
return projection * view;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::axes_render(Shader& shader, float zoom, vec2 pan, vec4 color) const
|
void Canvas::axes_render(ShaderProgram& shader, float zoom, vec2 pan, vec4 color) const
|
||||||
{
|
{
|
||||||
canvas_blend_premultiplied_set();
|
canvas_blend_premultiplied_set();
|
||||||
|
|
||||||
@@ -94,15 +90,15 @@ namespace anm2ed
|
|||||||
|
|
||||||
glUseProgram(shader.id);
|
glUseProgram(shader.id);
|
||||||
|
|
||||||
glUniform4fv(glGetUniformLocation(shader.id, shader::UNIFORM_COLOR), 1, value_ptr(color));
|
glUniform4fv(glGetUniformLocation(shader.id, UNIFORM_COLOR), 1, value_ptr(color));
|
||||||
glUniform2f(glGetUniformLocation(shader.id, shader::UNIFORM_ORIGIN_NDC), originNDC.x, originNDC.y);
|
glUniform2f(glGetUniformLocation(shader.id, UNIFORM_ORIGIN_NDC), originNDC.x, originNDC.y);
|
||||||
|
|
||||||
glBindVertexArray(axisVAO);
|
glBindVertexArray(axisVAO);
|
||||||
|
|
||||||
glUniform1i(glGetUniformLocation(shader.id, shader::UNIFORM_AXIS), 0);
|
glUniform1i(glGetUniformLocation(shader.id, UNIFORM_AXIS), 0);
|
||||||
glDrawArrays(GL_LINES, 0, 2);
|
glDrawArrays(GL_LINES, 0, 2);
|
||||||
|
|
||||||
glUniform1i(glGetUniformLocation(shader.id, shader::UNIFORM_AXIS), 1);
|
glUniform1i(glGetUniformLocation(shader.id, UNIFORM_AXIS), 1);
|
||||||
glDrawArrays(GL_LINES, 0, 2);
|
glDrawArrays(GL_LINES, 0, 2);
|
||||||
|
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
@@ -110,7 +106,7 @@ namespace anm2ed
|
|||||||
canvas_blend_straight_set();
|
canvas_blend_straight_set();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::grid_render(Shader& shader, float zoom, vec2 pan, ivec2 size, ivec2 offset, vec4 color) const
|
void Canvas::grid_render(ShaderProgram& shader, float zoom, vec2 pan, ivec2 size, ivec2 offset, vec4 color) const
|
||||||
{
|
{
|
||||||
canvas_blend_premultiplied_set();
|
canvas_blend_premultiplied_set();
|
||||||
|
|
||||||
@@ -118,10 +114,10 @@ namespace anm2ed
|
|||||||
|
|
||||||
glUseProgram(shader.id);
|
glUseProgram(shader.id);
|
||||||
|
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shader.id, shader::UNIFORM_TRANSFORM), 1, GL_FALSE, value_ptr(transform));
|
glUniformMatrix4fv(glGetUniformLocation(shader.id, UNIFORM_TRANSFORM), 1, GL_FALSE, value_ptr(transform));
|
||||||
glUniform2f(glGetUniformLocation(shader.id, shader::UNIFORM_SIZE), (float)size.x, (float)size.y);
|
glUniform2f(glGetUniformLocation(shader.id, UNIFORM_SIZE), (float)size.x, (float)size.y);
|
||||||
glUniform2f(glGetUniformLocation(shader.id, shader::UNIFORM_OFFSET), (float)offset.x, (float)offset.y);
|
glUniform2f(glGetUniformLocation(shader.id, UNIFORM_OFFSET), (float)offset.x, (float)offset.y);
|
||||||
glUniform4f(glGetUniformLocation(shader.id, shader::UNIFORM_COLOR), color.r, color.g, color.b, color.a);
|
glUniform4f(glGetUniformLocation(shader.id, UNIFORM_COLOR), color.r, color.g, color.b, color.a);
|
||||||
|
|
||||||
glBindVertexArray(gridVAO);
|
glBindVertexArray(gridVAO);
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||||
@@ -131,11 +127,11 @@ namespace anm2ed
|
|||||||
canvas_blend_straight_set();
|
canvas_blend_straight_set();
|
||||||
}
|
}
|
||||||
|
|
||||||
void texture_uniform_set(const shader::Uniform& uniform, vec4 value)
|
static void texture_uniform_set(const ShaderUniform& uniform, vec4 value)
|
||||||
{
|
{
|
||||||
if (uniform.valueType == shader::UNIFORM_VALUE_INT || uniform.valueType == shader::UNIFORM_VALUE_SAMPLER2D)
|
if (uniform.valueType == UNIFORM_VALUE_INT || uniform.valueType == UNIFORM_VALUE_SAMPLER2D)
|
||||||
return glUniform1i(uniform.location, uniform.intValue);
|
return glUniform1i(uniform.location, uniform.intValue);
|
||||||
switch (shader::UNIFORM_VALUE_TYPE_INFOS[uniform.valueType].componentCount)
|
switch (UNIFORM_VALUE_TYPE_INFOS[uniform.valueType].componentCount)
|
||||||
{
|
{
|
||||||
case 2:
|
case 2:
|
||||||
return glUniform2fv(uniform.location, 1, value_ptr(value));
|
return glUniform2fv(uniform.location, 1, value_ptr(value));
|
||||||
@@ -144,28 +140,28 @@ namespace anm2ed
|
|||||||
case 4:
|
case 4:
|
||||||
return glUniform4fv(uniform.location, 1, value_ptr(value));
|
return glUniform4fv(uniform.location, 1, value_ptr(value));
|
||||||
default:
|
default:
|
||||||
if (uniform.valueType == shader::UNIFORM_VALUE_FLOAT) glUniform1f(uniform.location, value.x);
|
if (uniform.valueType == UNIFORM_VALUE_FLOAT) glUniform1f(uniform.location, value.x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 texture_uniform_components_get(const shader::Uniform& uniform, float playbackTime)
|
static vec4 texture_uniform_components_get(const ShaderUniform& uniform, float playbackTime)
|
||||||
{
|
{
|
||||||
vec4 result{};
|
vec4 result{};
|
||||||
for (int i = 0; i < (int)uniform.components.size(); ++i)
|
for (int i = 0; i < (int)uniform.components.size(); ++i)
|
||||||
result[i] = uniform.components[i].binding == shader::UNIFORM_BINDING_PLAYBACK_TIME ? playbackTime
|
result[i] = uniform.components[i].binding == UNIFORM_BINDING_PLAYBACK_TIME ? playbackTime
|
||||||
: uniform.components[i].value;
|
: uniform.components[i].value;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void texture_uniforms_set(Shader& shader, mat4 transform, vec4 tint, vec4 colorOffset, vec2 textureSize,
|
static void texture_uniforms_set(ShaderProgram& shader, mat4 transform, vec4 tint, vec4 colorOffset, vec2 textureSize,
|
||||||
float playbackTime)
|
float playbackTime)
|
||||||
{
|
{
|
||||||
if (shader.uniforms.empty())
|
if (shader.uniforms.empty())
|
||||||
{
|
{
|
||||||
glUniform1i(glGetUniformLocation(shader.id, shader::UNIFORM_TEXTURE), 0);
|
glUniform1i(glGetUniformLocation(shader.id, UNIFORM_TEXTURE), 0);
|
||||||
glUniform4fv(glGetUniformLocation(shader.id, shader::UNIFORM_COLOR_OFFSET), 1, value_ptr(colorOffset));
|
glUniform4fv(glGetUniformLocation(shader.id, UNIFORM_COLOR_OFFSET), 1, value_ptr(colorOffset));
|
||||||
glUniform4fv(glGetUniformLocation(shader.id, shader::UNIFORM_TINT), 1, value_ptr(tint));
|
glUniform4fv(glGetUniformLocation(shader.id, UNIFORM_TINT), 1, value_ptr(tint));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shader.id, shader::UNIFORM_TRANSFORM), 1, GL_FALSE, value_ptr(transform));
|
glUniformMatrix4fv(glGetUniformLocation(shader.id, UNIFORM_TRANSFORM), 1, GL_FALSE, value_ptr(transform));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,29 +171,29 @@ namespace anm2ed
|
|||||||
|
|
||||||
switch (uniform.binding)
|
switch (uniform.binding)
|
||||||
{
|
{
|
||||||
case shader::UNIFORM_BINDING_MAIN_TEXTURE:
|
case UNIFORM_BINDING_MAIN_TEXTURE:
|
||||||
glUniform1i(uniform.location, 0);
|
glUniform1i(uniform.location, 0);
|
||||||
break;
|
break;
|
||||||
case shader::UNIFORM_BINDING_TRANSFORM:
|
case UNIFORM_BINDING_TRANSFORM:
|
||||||
if (uniform.valueType == shader::UNIFORM_VALUE_MAT4)
|
if (uniform.valueType == UNIFORM_VALUE_MAT4)
|
||||||
glUniformMatrix4fv(uniform.location, 1, GL_FALSE, value_ptr(transform));
|
glUniformMatrix4fv(uniform.location, 1, GL_FALSE, value_ptr(transform));
|
||||||
break;
|
break;
|
||||||
case shader::UNIFORM_BINDING_FRAME_TINT:
|
case UNIFORM_BINDING_FRAME_TINT:
|
||||||
texture_uniform_set(uniform, tint);
|
texture_uniform_set(uniform, tint);
|
||||||
break;
|
break;
|
||||||
case shader::UNIFORM_BINDING_COLOR_OFFSET:
|
case UNIFORM_BINDING_COLOR_OFFSET:
|
||||||
texture_uniform_set(uniform, colorOffset);
|
texture_uniform_set(uniform, colorOffset);
|
||||||
break;
|
break;
|
||||||
case shader::UNIFORM_BINDING_TEXTURE_SIZE:
|
case UNIFORM_BINDING_TEXTURE_SIZE:
|
||||||
texture_uniform_set(uniform, vec4(textureSize, 0.0f, 0.0f));
|
texture_uniform_set(uniform, vec4(textureSize, 0.0f, 0.0f));
|
||||||
break;
|
break;
|
||||||
case shader::UNIFORM_BINDING_PLAYBACK_TIME:
|
case UNIFORM_BINDING_PLAYBACK_TIME:
|
||||||
texture_uniform_set(uniform, vec4(playbackTime));
|
texture_uniform_set(uniform, vec4(playbackTime));
|
||||||
break;
|
break;
|
||||||
case shader::UNIFORM_BINDING_COMPONENTS:
|
case UNIFORM_BINDING_COMPONENTS:
|
||||||
texture_uniform_set(uniform, texture_uniform_components_get(uniform, playbackTime));
|
texture_uniform_set(uniform, texture_uniform_components_get(uniform, playbackTime));
|
||||||
break;
|
break;
|
||||||
case shader::UNIFORM_BINDING_MANUAL:
|
case UNIFORM_BINDING_MANUAL:
|
||||||
texture_uniform_set(uniform, uniform.value);
|
texture_uniform_set(uniform, uniform.value);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -206,7 +202,7 @@ namespace anm2ed
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::texture_render(Shader& shader, GLuint texture, mat4 transform, vec4 tint, vec4 colorOffset,
|
void Canvas::texture_render(ShaderProgram& shader, GLuint texture, mat4 transform, vec4 tint, vec4 colorOffset,
|
||||||
float* vertices, vec2 textureSize, float playbackTime, TextureBlur blur) const
|
float* vertices, vec2 textureSize, float playbackTime, TextureBlur blur) const
|
||||||
{
|
{
|
||||||
canvas_blend_premultiplied_set();
|
canvas_blend_premultiplied_set();
|
||||||
@@ -215,9 +211,9 @@ namespace anm2ed
|
|||||||
|
|
||||||
texture_uniforms_set(shader, transform, tint, colorOffset, textureSize, playbackTime);
|
texture_uniforms_set(shader, transform, tint, colorOffset, textureSize, playbackTime);
|
||||||
// The editor's own texture shader blurs; a custom shader without these uniforms ignores them.
|
// The editor's own texture shader blurs; a custom shader without these uniforms ignores them.
|
||||||
glUniform1f(glGetUniformLocation(shader.id, shader::UNIFORM_BLUR), blur.radius);
|
glUniform1f(glGetUniformLocation(shader.id, UNIFORM_BLUR), blur.radius);
|
||||||
glUniform4fv(glGetUniformLocation(shader.id, shader::UNIFORM_REGION), 1, value_ptr(blur.region));
|
glUniform4fv(glGetUniformLocation(shader.id, UNIFORM_REGION), 1, value_ptr(blur.region));
|
||||||
glUniform2fv(glGetUniformLocation(shader.id, shader::UNIFORM_TEXEL), 1,
|
glUniform2fv(glGetUniformLocation(shader.id, UNIFORM_TEXEL), 1,
|
||||||
value_ptr(textureSize.x > 0 && textureSize.y > 0 ? 1.0f / textureSize : vec2()));
|
value_ptr(textureSize.x > 0 && textureSize.y > 0 ? 1.0f / textureSize : vec2()));
|
||||||
glVertexAttrib4fv(2, value_ptr(tint));
|
glVertexAttrib4fv(2, value_ptr(tint));
|
||||||
|
|
||||||
@@ -239,17 +235,17 @@ namespace anm2ed
|
|||||||
canvas_blend_straight_set();
|
canvas_blend_straight_set();
|
||||||
}
|
}
|
||||||
|
|
||||||
void rect_begin(Shader& shader, const mat4& transform, const mat4& model, vec4 color)
|
static void rect_begin(ShaderProgram& shader, const mat4& transform, const mat4& model, vec4 color)
|
||||||
{
|
{
|
||||||
canvas_blend_premultiplied_set();
|
canvas_blend_premultiplied_set();
|
||||||
glUseProgram(shader.id);
|
glUseProgram(shader.id);
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shader.id, shader::UNIFORM_TRANSFORM), 1, GL_FALSE, value_ptr(transform));
|
glUniformMatrix4fv(glGetUniformLocation(shader.id, UNIFORM_TRANSFORM), 1, GL_FALSE, value_ptr(transform));
|
||||||
if (auto location = glGetUniformLocation(shader.id, shader::UNIFORM_MODEL); location != -1)
|
if (auto location = glGetUniformLocation(shader.id, UNIFORM_MODEL); location != -1)
|
||||||
glUniformMatrix4fv(location, 1, GL_FALSE, value_ptr(model));
|
glUniformMatrix4fv(location, 1, GL_FALSE, value_ptr(model));
|
||||||
glUniform4fv(glGetUniformLocation(shader.id, shader::UNIFORM_COLOR), 1, value_ptr(color));
|
glUniform4fv(glGetUniformLocation(shader.id, UNIFORM_COLOR), 1, value_ptr(color));
|
||||||
}
|
}
|
||||||
|
|
||||||
void rect_end(GLuint vao, GLenum mode, int count = 4)
|
static void rect_end(GLuint vao, GLenum mode, int count = 4)
|
||||||
{
|
{
|
||||||
glBindVertexArray(vao);
|
glBindVertexArray(vao);
|
||||||
glDrawArrays(mode, 0, count);
|
glDrawArrays(mode, 0, count);
|
||||||
@@ -258,19 +254,19 @@ namespace anm2ed
|
|||||||
canvas_blend_straight_set();
|
canvas_blend_straight_set();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::dashed_render(Shader& shader, const mat4& transform, const mat4& model, vec4 color, float dashLength,
|
void Canvas::dashed_render(ShaderProgram& shader, const mat4& transform, const mat4& model, vec4 color, float dashLength,
|
||||||
float dashGap, float dashOffset, GLenum mode, int count) const
|
float dashGap, float dashOffset, GLenum mode, int count) const
|
||||||
{
|
{
|
||||||
rect_begin(shader, transform, model, color);
|
rect_begin(shader, transform, model, color);
|
||||||
|
|
||||||
auto origin = model * vec4(0.0f, 0.0f, 0.0f, 1.0f);
|
auto origin = model * vec4(0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
for (auto [name, axis] : {std::pair{shader::UNIFORM_AXIS_X, vec4(1.0f, 0.0f, 0.0f, 1.0f)},
|
for (auto [name, axis] : {std::pair{UNIFORM_AXIS_X, vec4(1.0f, 0.0f, 0.0f, 1.0f)},
|
||||||
std::pair{shader::UNIFORM_AXIS_Y, vec4(0.0f, 1.0f, 0.0f, 1.0f)}})
|
std::pair{UNIFORM_AXIS_Y, vec4(0.0f, 1.0f, 0.0f, 1.0f)}})
|
||||||
if (auto location = glGetUniformLocation(shader.id, name); location != -1)
|
if (auto location = glGetUniformLocation(shader.id, name); location != -1)
|
||||||
glUniform2fv(location, 1, value_ptr(vec2(model * axis - origin)));
|
glUniform2fv(location, 1, value_ptr(vec2(model * axis - origin)));
|
||||||
for (auto [name, value] :
|
for (auto [name, value] :
|
||||||
{std::pair{shader::UNIFORM_DASH_LENGTH, dashLength}, std::pair{shader::UNIFORM_DASH_GAP, dashGap},
|
{std::pair{UNIFORM_DASH_LENGTH, dashLength}, std::pair{UNIFORM_DASH_GAP, dashGap},
|
||||||
std::pair{shader::UNIFORM_DASH_OFFSET, dashOffset}})
|
std::pair{UNIFORM_DASH_OFFSET, dashOffset}})
|
||||||
if (auto location = glGetUniformLocation(shader.id, name); location != -1) glUniform1f(location, value);
|
if (auto location = glGetUniformLocation(shader.id, name); location != -1) glUniform1f(location, value);
|
||||||
|
|
||||||
rect_end(rectVAO, mode, count);
|
rect_end(rectVAO, mode, count);
|
||||||
@@ -278,52 +274,52 @@ namespace anm2ed
|
|||||||
|
|
||||||
// A layer draw's crop of its spritesheet. A blurred one (Flash's BlurFilter: a box `blur` canvas pixels wide) grows by
|
// A layer draw's crop of its spritesheet. A blurred one (Flash's BlurFilter: a box `blur` canvas pixels wide) grows by
|
||||||
// the box's reach, in texels at the draw's scale, and averages its crop over it.
|
// the box's reach, in texels at the draw's scale, and averages its crop over it.
|
||||||
void Canvas::layer_render(Shader& shader, GLuint texture, vec2 textureSize, const mat4& transform,
|
void Canvas::layer_render(ShaderProgram& shader, GLuint texture, vec2 textureSize, const mat4& transform,
|
||||||
const model::Draw& draw, vec4 tint, vec4 colorOffset) const
|
const Draw& draw, vec4 tint, vec4 colorOffset) const
|
||||||
{
|
{
|
||||||
auto blurred = draw;
|
auto blurred = draw;
|
||||||
auto& frame = blurred.frame;
|
auto& frame = blurred.frame;
|
||||||
TextureBlur blur{.region = vec4(frame.crop, frame.crop + frame.size) / vec4(textureSize, textureSize)};
|
TextureBlur blur{.region = vec4(frame.crop, frame.crop + frame.size) / vec4(textureSize, textureSize)};
|
||||||
if (frame.blur > 0.0f && frame.size.x > 0.0f && frame.size.y > 0.0f)
|
if (frame.blur > 0.0f && frame.size.x > 0.0f && frame.size.y > 0.0f)
|
||||||
{
|
{
|
||||||
auto canvasArea = std::abs(glm::determinant(glm::mat2(draw.parent * model::draw_quad_model_get(draw))));
|
auto canvasArea = std::abs(glm::determinant(glm::mat2(draw.parent * draw_quad_model_get(draw))));
|
||||||
auto canvasPerTexel = std::sqrt(canvasArea / (frame.size.x * frame.size.y));
|
auto canvasPerTexel = std::sqrt(canvasArea / (frame.size.x * frame.size.y));
|
||||||
blur.radius = canvasPerTexel > 0.0f ? std::round(frame.blur * 0.5f / canvasPerTexel) : 0.0f;
|
blur.radius = canvasPerTexel > 0.0f ? std::round(frame.blur * 0.5f / canvasPerTexel) : 0.0f;
|
||||||
frame.crop -= blur.radius;
|
frame.crop -= blur.radius;
|
||||||
frame.size += blur.radius * 2.0f;
|
frame.size += blur.radius * 2.0f;
|
||||||
frame.pivot += blur.radius;
|
frame.pivot += blur.radius;
|
||||||
}
|
}
|
||||||
auto vertices = math::uv_vertices_get(frame.crop / textureSize, (frame.crop + frame.size) / textureSize);
|
auto vertices = uv_vertices_get(frame.crop / textureSize, (frame.crop + frame.size) / textureSize);
|
||||||
texture_render(shader, texture, transform * blurred.parent * model::draw_quad_model_get(blurred), tint, colorOffset,
|
texture_render(shader, texture, transform * blurred.parent * draw_quad_model_get(blurred), tint, colorOffset,
|
||||||
vertices.data(), textureSize, draw.time, blur);
|
vertices.data(), textureSize, draw.time, blur);
|
||||||
}
|
}
|
||||||
|
|
||||||
// An animation's layers alone (no markers or helpers); spritesheet images are looked up by draw, custom shaders by id.
|
// An animation's layers alone (no markers or helpers); spritesheet images are looked up by draw, custom shaders by id.
|
||||||
void Canvas::layers_render(Shader& shader, const model::Model& model, const model::Animation& animation,
|
void Canvas::layers_render(ShaderProgram& shader, const Model& model, const Animation& animation,
|
||||||
const model::DrawOptions& options, const mat4& transform,
|
const DrawOptions& options, const mat4& transform,
|
||||||
const std::function<const Image*(const model::Draw&)>& image_get,
|
const std::function<const Image*(const Draw&)>& image_get,
|
||||||
const std::function<Shader*(int)>& shader_get) const
|
const std::function<ShaderProgram*(int)>& shader_get) const
|
||||||
{
|
{
|
||||||
for (const auto& draw : model::animation_draws_get(model, animation, options))
|
for (const auto& draw : animation_draws_get(model, animation, options))
|
||||||
{
|
{
|
||||||
if (draw.type != model::DrawType::LAYER) continue;
|
if (draw.type != DrawType::LAYER) continue;
|
||||||
auto& frame = draw.frame;
|
auto& frame = draw.frame;
|
||||||
auto image = image_get(draw);
|
auto image = image_get(draw);
|
||||||
if (!image || !image->is_valid() || frame.size == vec2()) continue;
|
if (!image || !image->is_valid() || frame.size == vec2()) continue;
|
||||||
auto customShader = shader_get ? shader_get(frame.shaderId) : nullptr;
|
auto customShader = shader_get ? shader_get(frame.shaderId) : nullptr;
|
||||||
layer_render(customShader ? *customShader : shader, texture::id_get(*image), image->unit_size_get(), transform,
|
layer_render(customShader ? *customShader : shader, texture_id_get(*image), image->unit_size_get(), transform,
|
||||||
draw, frame.tint, frame.colorOffset);
|
draw, frame.tint, frame.colorOffset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::rect_render(Shader& shader, const mat4& transform, const mat4& model, vec4 color, float dashLength,
|
void Canvas::rect_render(ShaderProgram& shader, const mat4& transform, const mat4& model, vec4 color, float dashLength,
|
||||||
float dashGap, float dashOffset) const
|
float dashGap, float dashOffset) const
|
||||||
{
|
{
|
||||||
dashed_render(shader, transform, model, color, dashLength, dashGap, dashOffset, GL_LINE_LOOP, RECT_VERTEX_COUNT);
|
dashed_render(shader, transform, model, color, dashLength, dashGap, dashOffset, GL_LINE_LOOP, RECT_VERTEX_COUNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// A line from start to end: the bottom edge of a rectangle laid along it.
|
// A line from start to end: the bottom edge of a rectangle laid along it.
|
||||||
void Canvas::line_render(Shader& shader, const mat4& transform, vec2 start, vec2 end, vec4 color, float dashLength,
|
void Canvas::line_render(ShaderProgram& shader, const mat4& transform, vec2 start, vec2 end, vec4 color, float dashLength,
|
||||||
float dashGap, float dashOffset) const
|
float dashGap, float dashOffset) const
|
||||||
{
|
{
|
||||||
auto direction = end - start;
|
auto direction = end - start;
|
||||||
@@ -333,7 +329,7 @@ namespace anm2ed
|
|||||||
dashed_render(shader, transform, model, color, dashLength, dashGap, dashOffset, GL_LINES, LINE_VERTEX_COUNT);
|
dashed_render(shader, transform, model, color, dashLength, dashGap, dashOffset, GL_LINES, LINE_VERTEX_COUNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::rect_fill_render(Shader& shader, const mat4& transform, const mat4& model, vec4 color) const
|
void Canvas::rect_fill_render(ShaderProgram& shader, const mat4& transform, const mat4& model, vec4 color) const
|
||||||
{
|
{
|
||||||
rect_begin(shader, transform, model, color);
|
rect_begin(shader, transform, model, color);
|
||||||
rect_end(rectVAO, GL_TRIANGLE_FAN);
|
rect_end(rectVAO, GL_TRIANGLE_FAN);
|
||||||
@@ -363,11 +359,11 @@ namespace anm2ed
|
|||||||
|
|
||||||
void Canvas::zoom_level_adjust(float& zoom, vec2& pan, vec2 focus, int levelDelta) const
|
void Canvas::zoom_level_adjust(float& zoom, vec2& pan, vec2 focus, int levelDelta) const
|
||||||
{
|
{
|
||||||
auto zoomFactor = math::percent_to_unit(zoom);
|
auto zoomFactor = percent_to_unit(zoom);
|
||||||
float newZoom = zoom_level_get(zoom, levelDelta);
|
float newZoom = zoom_level_get(zoom, levelDelta);
|
||||||
if (newZoom != zoom)
|
if (newZoom != zoom)
|
||||||
{
|
{
|
||||||
float newZoomFactor = math::percent_to_unit(newZoom);
|
float newZoomFactor = percent_to_unit(newZoom);
|
||||||
pan += focus * (zoomFactor - newZoomFactor);
|
pan += focus * (zoomFactor - newZoomFactor);
|
||||||
zoom = newZoom;
|
zoom = newZoom;
|
||||||
}
|
}
|
||||||
@@ -375,7 +371,7 @@ namespace anm2ed
|
|||||||
|
|
||||||
vec2 Canvas::position_translate(float& zoom, vec2& pan, vec2 position) const
|
vec2 Canvas::position_translate(float& zoom, vec2& pan, vec2 position) const
|
||||||
{
|
{
|
||||||
auto zoomFactor = math::percent_to_unit(zoom);
|
auto zoomFactor = percent_to_unit(zoom);
|
||||||
return (position - pan - (size * 0.5f)) / zoomFactor;
|
return (position - pan - (size * 0.5f)) / zoomFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -387,10 +383,9 @@ namespace anm2ed
|
|||||||
f32 scaleY = size.y / rect.w;
|
f32 scaleY = size.y / rect.w;
|
||||||
f32 fitScale = std::min(scaleX, scaleY);
|
f32 fitScale = std::min(scaleX, scaleY);
|
||||||
|
|
||||||
zoom = math::unit_to_percent(fitScale);
|
zoom = unit_to_percent(fitScale);
|
||||||
|
|
||||||
vec2 rectCenter = {rect.x + rect.z * 0.5f, rect.y + rect.w * 0.5f};
|
vec2 rectCenter = {rect.x + rect.z * 0.5f, rect.y + rect.w * 0.5f};
|
||||||
pan = -rectCenter * fitScale;
|
pan = -rectCenter * fitScale;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
+12
-15
@@ -13,8 +13,6 @@
|
|||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
// A box blur `radius` texels wide each way over the texture's `region` (UV min, max); outside it is clear.
|
// A box blur `radius` texels wide each way over the texture's `region` (UV min, max); outside it is clear.
|
||||||
struct TextureBlur
|
struct TextureBlur
|
||||||
{
|
{
|
||||||
@@ -53,7 +51,7 @@ namespace anm2ed
|
|||||||
static constexpr auto BORDER_DASH_LENGTH = 1.0f;
|
static constexpr auto BORDER_DASH_LENGTH = 1.0f;
|
||||||
static constexpr auto BORDER_DASH_GAP = 0.5f;
|
static constexpr auto BORDER_DASH_GAP = 0.5f;
|
||||||
static constexpr auto BORDER_DASH_OFFSET = 0.0f;
|
static constexpr auto BORDER_DASH_OFFSET = 0.0f;
|
||||||
static constexpr auto PIVOT_COLOR = types::color::PINK;
|
static constexpr auto PIVOT_COLOR = COLOR_PINK;
|
||||||
|
|
||||||
GLuint axisVAO{};
|
GLuint axisVAO{};
|
||||||
GLuint axisVBO{};
|
GLuint axisVBO{};
|
||||||
@@ -69,26 +67,25 @@ namespace anm2ed
|
|||||||
Canvas(glm::vec2);
|
Canvas(glm::vec2);
|
||||||
~Canvas();
|
~Canvas();
|
||||||
glm::mat4 transform_get(float = 100.0f, glm::vec2 = {}) const;
|
glm::mat4 transform_get(float = 100.0f, glm::vec2 = {}) const;
|
||||||
void axes_render(resource::Shader&, float, glm::vec2, glm::vec4 = glm::vec4(1.0f)) const;
|
void axes_render(ShaderProgram&, float, glm::vec2, glm::vec4 = glm::vec4(1.0f)) const;
|
||||||
void grid_render(resource::Shader&, float, glm::vec2, glm::ivec2 = glm::ivec2(32, 32), glm::ivec2 = {},
|
void grid_render(ShaderProgram&, float, glm::vec2, glm::ivec2 = glm::ivec2(32, 32), glm::ivec2 = {},
|
||||||
glm::vec4 = glm::vec4(1.0f)) const;
|
glm::vec4 = glm::vec4(1.0f)) const;
|
||||||
void texture_render(resource::Shader&, GLuint, glm::mat4 = {1.0f}, glm::vec4 = glm::vec4(1.0f), glm::vec4 = {},
|
void texture_render(ShaderProgram&, GLuint, glm::mat4 = {1.0f}, glm::vec4 = glm::vec4(1.0f), glm::vec4 = {},
|
||||||
float* = (float*)TEXTURE_VERTICES, glm::vec2 = {}, float = 0.0f, TextureBlur = {}) const;
|
float* = (float*)TEXTURE_VERTICES, glm::vec2 = {}, float = 0.0f, TextureBlur = {}) const;
|
||||||
void layer_render(resource::Shader&, GLuint, glm::vec2, const glm::mat4&, const model::Draw&, glm::vec4,
|
void layer_render(ShaderProgram&, GLuint, glm::vec2, const glm::mat4&, const Draw&, glm::vec4,
|
||||||
glm::vec4) const;
|
glm::vec4) const;
|
||||||
void rect_fill_render(resource::Shader&, const glm::mat4&, const glm::mat4&, glm::vec4 = glm::vec4(1.0f)) const;
|
void rect_fill_render(ShaderProgram&, const glm::mat4&, const glm::mat4&, glm::vec4 = glm::vec4(1.0f)) const;
|
||||||
void layers_render(resource::Shader&, const model::Model&, const model::Animation&, const model::DrawOptions&,
|
void layers_render(ShaderProgram&, const Model&, const Animation&, const DrawOptions&,
|
||||||
const glm::mat4&, const std::function<const resource::Image*(const model::Draw&)>&,
|
const glm::mat4&, const std::function<const Image*(const Draw&)>&,
|
||||||
const std::function<resource::Shader*(int)>& = {}) const;
|
const std::function<ShaderProgram*(int)>& = {}) const;
|
||||||
void dashed_render(resource::Shader&, const glm::mat4&, const glm::mat4&, glm::vec4, float, float, float, GLenum,
|
void dashed_render(ShaderProgram&, const glm::mat4&, const glm::mat4&, glm::vec4, float, float, float, GLenum,
|
||||||
int) const;
|
int) const;
|
||||||
void rect_render(resource::Shader&, const glm::mat4&, const glm::mat4&, glm::vec4 = glm::vec4(1.0f),
|
void rect_render(ShaderProgram&, const glm::mat4&, const glm::mat4&, glm::vec4 = glm::vec4(1.0f),
|
||||||
float dashLength = DASH_LENGTH, float dashGap = DASH_GAP, float dashOffset = DASH_OFFSET) const;
|
float dashLength = DASH_LENGTH, float dashGap = DASH_GAP, float dashOffset = DASH_OFFSET) const;
|
||||||
void line_render(resource::Shader&, const glm::mat4&, glm::vec2, glm::vec2, glm::vec4 = glm::vec4(1.0f),
|
void line_render(ShaderProgram&, const glm::mat4&, glm::vec2, glm::vec2, glm::vec4 = glm::vec4(1.0f),
|
||||||
float dashLength = DASH_LENGTH, float dashGap = DASH_GAP, float dashOffset = DASH_OFFSET) const;
|
float dashLength = DASH_LENGTH, float dashGap = DASH_GAP, float dashOffset = DASH_OFFSET) const;
|
||||||
float zoom_level_get(float, int) const;
|
float zoom_level_get(float, int) const;
|
||||||
void zoom_level_adjust(float&, glm::vec2&, glm::vec2, int) const;
|
void zoom_level_adjust(float&, glm::vec2&, glm::vec2, int) const;
|
||||||
glm::vec2 position_translate(float&, glm::vec2&, glm::vec2) const;
|
glm::vec2 position_translate(float&, glm::vec2&, glm::vec2) const;
|
||||||
void set_to_rect(float& zoom, glm::vec2& pan, glm::vec4 rect) const;
|
void set_to_rect(float& zoom, glm::vec2& pan, glm::vec4 rect) const;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
+49
-54
@@ -19,10 +19,6 @@
|
|||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "working_directory.h"
|
#include "working_directory.h"
|
||||||
|
|
||||||
using namespace anm2ed::util;
|
|
||||||
|
|
||||||
namespace anm2ed::cli
|
|
||||||
{
|
|
||||||
constexpr const char* USAGE = R"(usage: anm2ed <command> <file.anm2> [options]
|
constexpr const char* USAGE = R"(usage: anm2ed <command> <file.anm2> [options]
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
@@ -73,16 +69,16 @@ options:
|
|||||||
};
|
};
|
||||||
|
|
||||||
// PNG sequences go into a folder; everything else is a file.
|
// PNG sequences go into a folder; everything else is a file.
|
||||||
bool type_is_folder(const Arguments& arguments)
|
static bool type_is_folder(const Arguments& arguments)
|
||||||
{
|
{
|
||||||
return arguments.command == "render" && arguments.get("type").value_or("") == "pngs";
|
return arguments.command == "render" && arguments.get("type").value_or("") == "pngs";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<Arguments> arguments_get(int argc, const char** argv)
|
static std::optional<Arguments> arguments_get(int argc, const char** argv)
|
||||||
{
|
{
|
||||||
if (argc < 3) return {};
|
if (argc < 3) return {};
|
||||||
// Absolute, so a bare file name still has a folder for the paths in it.
|
// Absolute, so a bare file name still has a folder for the paths in it.
|
||||||
Arguments arguments{.command = argv[1], .file = std::filesystem::absolute(path::from_utf8(argv[2]))};
|
Arguments arguments{.command = argv[1], .file = std::filesystem::absolute(path_from_utf8(argv[2]))};
|
||||||
for (int i = 3; i < argc; ++i)
|
for (int i = 3; i < argc; ++i)
|
||||||
{
|
{
|
||||||
std::string name = argv[i];
|
std::string name = argv[i];
|
||||||
@@ -95,7 +91,7 @@ options:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RRGGBB (opaque) or "transparent".
|
// RRGGBB (opaque) or "transparent".
|
||||||
glm::vec4 background_get(const Arguments& arguments)
|
static glm::vec4 background_get(const Arguments& arguments)
|
||||||
{
|
{
|
||||||
auto text = arguments.get("background").value_or("transparent");
|
auto text = arguments.get("background").value_or("transparent");
|
||||||
if (text.starts_with('#')) text.erase(0, 1);
|
if (text.starts_with('#')) text.erase(0, 1);
|
||||||
@@ -108,17 +104,17 @@ options:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// --ffmpeg, or else the FFmpeg the editor's Render Animation uses (or "ffmpeg" on the PATH).
|
// --ffmpeg, or else the FFmpeg the editor's Render Animation uses (or "ffmpeg" on the PATH).
|
||||||
std::filesystem::path ffmpeg_path_get(const Arguments& arguments)
|
static std::filesystem::path ffmpeg_path_get(const Arguments& arguments)
|
||||||
{
|
{
|
||||||
if (auto ffmpeg = arguments.get("ffmpeg")) return path::from_utf8(*ffmpeg);
|
if (auto ffmpeg = arguments.get("ffmpeg")) return path_from_utf8(*ffmpeg);
|
||||||
auto settingsPath = sdl::preferences_directory_get() / "settings.ini";
|
auto settingsPath = preferences_directory_get() / "settings.ini";
|
||||||
auto settingsFfmpeg =
|
auto settingsFfmpeg =
|
||||||
path::is_exist(settingsPath) ? Settings(settingsPath).renderFFmpegPath : std::filesystem::path{};
|
is_path_exist(settingsPath) ? Settings(settingsPath).renderFFmpegPath : std::filesystem::path{};
|
||||||
return settingsFfmpeg.empty() ? std::filesystem::path("ffmpeg") : settingsFfmpeg;
|
return settingsFfmpeg.empty() ? std::filesystem::path("ffmpeg") : settingsFfmpeg;
|
||||||
}
|
}
|
||||||
|
|
||||||
// By index or name; the default animation otherwise.
|
// By index or name; the default animation otherwise.
|
||||||
std::pair<int, const model::Animation*> animation_get(const model::Model& model, const Arguments& arguments)
|
static std::pair<int, const Animation*> animation_get(const Model& model, const Arguments& arguments)
|
||||||
{
|
{
|
||||||
auto animations = model.animations_get();
|
auto animations = model.animations_get();
|
||||||
auto name = arguments.get("animation").value_or(model.animations.defaultAnimation);
|
auto name = arguments.get("animation").value_or(model.animations.defaultAnimation);
|
||||||
@@ -132,25 +128,25 @@ options:
|
|||||||
return {-1, nullptr};
|
return {-1, nullptr};
|
||||||
}
|
}
|
||||||
|
|
||||||
int info_print(const Arguments& arguments)
|
static int info_print(const Arguments& arguments)
|
||||||
{
|
{
|
||||||
model::Model model{};
|
Model model{};
|
||||||
std::string error{};
|
std::string error{};
|
||||||
if (!model::model_load(model, arguments.file, &error))
|
if (!model_load(model, arguments.file, &error))
|
||||||
{
|
{
|
||||||
std::println(stderr, "could not load {}: {}", path::to_utf8(arguments.file), error);
|
std::println(stderr, "could not load {}: {}", path_to_utf8(arguments.file), error);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
auto& content = model.content;
|
auto& content = model.content;
|
||||||
std::println("file: {}", path::to_utf8(arguments.file));
|
std::println("file: {}", path_to_utf8(arguments.file));
|
||||||
std::println("fps: {}, created by: {}", model.info.fps, model.info.createdBy);
|
std::println("fps: {}, created by: {}", model.info.fps, model.info.createdBy);
|
||||||
|
|
||||||
std::println("animations (default: {}):", model.animations.defaultAnimation);
|
std::println("animations (default: {}):", model.animations.defaultAnimation);
|
||||||
for (auto [index, animation] : model.animations_get())
|
for (auto [index, animation] : model.animations_get())
|
||||||
{
|
{
|
||||||
int layers{}, nulls{};
|
int layers{}, nulls{};
|
||||||
model::tracks_each(animation->layers, [&](const model::Track&, auto*) { ++layers; });
|
tracks_each(animation->layers, [&](const Track&, auto*) { ++layers; });
|
||||||
model::tracks_each(animation->nulls, [&](const model::Track&, auto*) { ++nulls; });
|
tracks_each(animation->nulls, [&](const Track&, auto*) { ++nulls; });
|
||||||
std::println(" [{}] {}: {} frames{}, {} layer tracks, {} null tracks, {} triggers", index, animation->name,
|
std::println(" [{}] {}: {} frames{}, {} layer tracks, {} null tracks, {} triggers", index, animation->name,
|
||||||
animation->frameNum, animation->isLoop ? ", loops" : "", layers, nulls,
|
animation->frameNum, animation->isLoop ? ", loops" : "", layers, nulls,
|
||||||
animation->triggers.frames.size());
|
animation->triggers.frames.size());
|
||||||
@@ -160,13 +156,13 @@ options:
|
|||||||
std::println("spritesheets:");
|
std::println("spritesheets:");
|
||||||
for (const auto& spritesheet : content.spritesheets)
|
for (const auto& spritesheet : content.spritesheets)
|
||||||
{
|
{
|
||||||
auto image = resource::Image(path::case_insensitive_find(spritesheet.path));
|
auto image = Image(path_case_insensitive_find(spritesheet.path));
|
||||||
auto status = image.is_valid() ? std::format("{}x{}", image.size.x, image.size.y) : std::string("missing");
|
auto status = image.is_valid() ? std::format("{}x{}", image.size.x, image.size.y) : std::string("missing");
|
||||||
std::println(" #{} {} ({}), {} regions", spritesheet.id, path::to_utf8(spritesheet.path), status,
|
std::println(" #{} {} ({}), {} regions", spritesheet.id, path_to_utf8(spritesheet.path), status,
|
||||||
spritesheet.regions.size());
|
spritesheet.regions.size());
|
||||||
}
|
}
|
||||||
for (const auto& library : content.libraries)
|
for (const auto& library : content.libraries)
|
||||||
std::println("library #{} {}", library.id, path::to_utf8(library.path));
|
std::println("library #{} {}", library.id, path_to_utf8(library.path));
|
||||||
for (const auto& layer : content.layers)
|
for (const auto& layer : content.layers)
|
||||||
if (layer.is_animation())
|
if (layer.is_animation())
|
||||||
std::println("layer #{} {} (animation {}, library #{})", layer.id, layer.name, layer.animation,
|
std::println("layer #{} {} (animation {}, library #{})", layer.id, layer.name, layer.animation,
|
||||||
@@ -178,9 +174,9 @@ options:
|
|||||||
for (const auto& event : content.events)
|
for (const auto& event : content.events)
|
||||||
std::println("event #{} {}", event.id, event.name);
|
std::println("event #{} {}", event.id, event.name);
|
||||||
for (const auto& sound : content.sounds)
|
for (const auto& sound : content.sounds)
|
||||||
std::println("sound #{} {}", sound.id, path::to_utf8(sound.path));
|
std::println("sound #{} {}", sound.id, path_to_utf8(sound.path));
|
||||||
|
|
||||||
auto issues = model::isaac_issues_get(model);
|
auto issues = isaac_issues_get(model);
|
||||||
std::println("isaac issues: {} eased frames, {} group transforms, {} skewed frames, {} shader frames, {} depth "
|
std::println("isaac issues: {} eased frames, {} group transforms, {} skewed frames, {} shader frames, {} depth "
|
||||||
"frames, {} alpha offset frames, {} blurred frames, {} extra trigger events, {} trigger sounds, "
|
"frames, {} alpha offset frames, {} blurred frames, {} extra trigger events, {} trigger sounds, "
|
||||||
"{} animation layers, {} vector spritesheets",
|
"{} animation layers, {} vector spritesheets",
|
||||||
@@ -190,7 +186,7 @@ options:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int draw_run(const Arguments& arguments)
|
static int draw_run(const Arguments& arguments)
|
||||||
{
|
{
|
||||||
auto out = arguments.get("out");
|
auto out = arguments.get("out");
|
||||||
if (!out)
|
if (!out)
|
||||||
@@ -199,7 +195,7 @@ options:
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
render::HeadlessGL gl{};
|
HeadlessGL gl{};
|
||||||
if (!gl.is_valid())
|
if (!gl.is_valid())
|
||||||
{
|
{
|
||||||
std::println(stderr, "could not create an OpenGL 3.3 context");
|
std::println(stderr, "could not create an OpenGL 3.3 context");
|
||||||
@@ -210,7 +206,7 @@ options:
|
|||||||
Document document(arguments.file, false, &error);
|
Document document(arguments.file, false, &error);
|
||||||
if (!document.is_valid())
|
if (!document.is_valid())
|
||||||
{
|
{
|
||||||
std::println(stderr, "could not load {}: {}", path::to_utf8(arguments.file), error);
|
std::println(stderr, "could not load {}: {}", path_to_utf8(arguments.file), error);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
auto [index, animation] = animation_get(document.model, arguments);
|
auto [index, animation] = animation_get(document.model, arguments);
|
||||||
@@ -220,27 +216,27 @@ options:
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& textureInfo = resource::shader::SHADERS[resource::shader::TEXTURE];
|
auto& textureInfo = SHADERS[SHADER_TEXTURE];
|
||||||
resource::Shader shader(textureInfo.vertex, textureInfo.fragment);
|
ShaderProgram shader(textureInfo.vertex, textureInfo.fragment);
|
||||||
Canvas canvas(glm::vec2(1.0f));
|
Canvas canvas(glm::vec2(1.0f));
|
||||||
auto isRootTransform = !arguments.is("no-root-transform");
|
auto isRootTransform = !arguments.is("no-root-transform");
|
||||||
auto bounds = render::animation_bounds_get(document, *animation, isRootTransform);
|
auto bounds = animation_bounds_get(document, *animation, isRootTransform);
|
||||||
auto scale = arguments.number_get("scale", SCALE_DEFAULT);
|
auto scale = arguments.number_get("scale", SCALE_DEFAULT);
|
||||||
auto background = background_get(arguments);
|
auto background = background_get(arguments);
|
||||||
auto frame_render = [&](float time)
|
auto frame_render = [&](float time)
|
||||||
{
|
{
|
||||||
return render::animation_frame_render(canvas, shader, document, *animation, time, bounds, scale, background,
|
return animation_frame_render(canvas, shader, document, *animation, time, bounds, scale, background,
|
||||||
isRootTransform);
|
isRootTransform);
|
||||||
};
|
};
|
||||||
auto outPath = path::from_utf8(*out);
|
auto outPath = path_from_utf8(*out);
|
||||||
std::error_code ec{};
|
std::error_code ec{};
|
||||||
std::filesystem::create_directories(type_is_folder(arguments) ? outPath : outPath.parent_path(), ec);
|
std::filesystem::create_directories(type_is_folder(arguments) ? outPath : outPath.parent_path(), ec);
|
||||||
|
|
||||||
if (arguments.command == "frame")
|
if (arguments.command == "frame")
|
||||||
{
|
{
|
||||||
auto pixels = frame_render(arguments.number_get("time", 0.0f));
|
auto pixels = frame_render(arguments.number_get("time", 0.0f));
|
||||||
render::pixels_unpremultiply(pixels);
|
pixels_unpremultiply(pixels);
|
||||||
if (!resource::Image::write_pixels_png(outPath, glm::ivec2(canvas.size), pixels.data()))
|
if (!Image::write_pixels_png(outPath, glm::ivec2(canvas.size), pixels.data()))
|
||||||
{
|
{
|
||||||
std::println(stderr, "could not write {}", *out);
|
std::println(stderr, "could not write {}", *out);
|
||||||
return 1;
|
return 1;
|
||||||
@@ -251,19 +247,19 @@ options:
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto typeName = arguments.get("type").value_or("sheet");
|
auto typeName = arguments.get("type").value_or("sheet");
|
||||||
auto type = typeName == "sheet" ? render::SPRITESHEET : render::PNGS;
|
auto type = typeName == "sheet" ? RENDER_SPRITESHEET : RENDER_PNGS;
|
||||||
for (int i = 0; i < render::COUNT; ++i)
|
for (int i = 0; i < RENDER_COUNT; ++i)
|
||||||
if (render::EXTENSIONS[i] == "." + typeName) type = (render::Type)i;
|
if (RENDER_EXTENSIONS[i] == "." + typeName) type = (RenderType)i;
|
||||||
if (typeName != "sheet" && typeName != "pngs" && type == render::PNGS)
|
if (typeName != "sheet" && typeName != "pngs" && type == RENDER_PNGS)
|
||||||
{
|
{
|
||||||
std::println(stderr, "unknown --type: {}", typeName);
|
std::println(stderr, "unknown --type: {}", typeName);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto fps = std::max(document.model.info.fps, 1);
|
auto fps = std::max(document.model.info.fps, 1);
|
||||||
render::RecorderOptions options{.type = type,
|
RecorderOptions options{.type = type,
|
||||||
.path = outPath,
|
.path = outPath,
|
||||||
.format = path::from_utf8(arguments.get("format").value_or("{}.png")),
|
.format = path_from_utf8(arguments.get("format").value_or("{}.png")),
|
||||||
.ffmpegPath = ffmpeg_path_get(arguments),
|
.ffmpegPath = ffmpeg_path_get(arguments),
|
||||||
.start = arguments.number_get("start", 0),
|
.start = arguments.number_get("start", 0),
|
||||||
.end = arguments.number_get("end", animation->frameNum - 1),
|
.end = arguments.number_get("end", animation->frameNum - 1),
|
||||||
@@ -271,19 +267,19 @@ options:
|
|||||||
.fps = arguments.number_get("fps", fps),
|
.fps = arguments.number_get("fps", fps),
|
||||||
.rows = arguments.number_get("rows", 0),
|
.rows = arguments.number_get("rows", 0),
|
||||||
.columns = arguments.number_get("columns", 0)};
|
.columns = arguments.number_get("columns", 0)};
|
||||||
auto count = render::frame_count_get(options.start, options.end, options.animationFps, options.fps);
|
auto count = frame_count_get(options.start, options.end, options.animationFps, options.fps);
|
||||||
if (!render::animation_record(options, canvas, shader, document, *animation, bounds, scale, background,
|
if (!animation_record(options, canvas, shader, document, *animation, bounds, scale, background,
|
||||||
isRootTransform))
|
isRootTransform))
|
||||||
{
|
{
|
||||||
std::println(stderr, "could not write {} (FFmpeg: {})", *out, path::to_utf8(options.ffmpegPath));
|
std::println(stderr, "could not write {} (FFmpeg: {})", *out, path_to_utf8(options.ffmpegPath));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::print("{}: \"{}\", {} frames ({} to {} at {} fps), each {}x{}", *out, animation->name, count, options.start,
|
std::print("{}: \"{}\", {} frames ({} to {} at {} fps), each {}x{}", *out, animation->name, count, options.start,
|
||||||
options.end, options.fps, (int)canvas.size.x, (int)canvas.size.y);
|
options.end, options.fps, (int)canvas.size.x, (int)canvas.size.y);
|
||||||
if (type == render::SPRITESHEET)
|
if (type == RENDER_SPRITESHEET)
|
||||||
{
|
{
|
||||||
auto layout = render::spritesheet_layout_get(options.rows, options.columns, count);
|
auto layout = spritesheet_layout_get(options.rows, options.columns, count);
|
||||||
std::print(", {} rows x {} columns, left to right", layout.rows, layout.columns);
|
std::print(", {} rows x {} columns, left to right", layout.rows, layout.columns);
|
||||||
}
|
}
|
||||||
std::println("");
|
std::println("");
|
||||||
@@ -291,7 +287,7 @@ options:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Saved as the editor saves it: XML (the game's copy, with the editor's embedded) or the editor's JSON.
|
// Saved as the editor saves it: XML (the game's copy, with the editor's embedded) or the editor's JSON.
|
||||||
int convert_run(const Arguments& arguments)
|
static int convert_run(const Arguments& arguments)
|
||||||
{
|
{
|
||||||
auto format = arguments.get("format").value_or("xml");
|
auto format = arguments.get("format").value_or("xml");
|
||||||
if (format != "xml" && format != "json")
|
if (format != "xml" && format != "json")
|
||||||
@@ -300,22 +296,22 @@ options:
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
// The game's copy bakes what it can't draw with OpenGL (and the document's shaders compile only with it).
|
// The game's copy bakes what it can't draw with OpenGL (and the document's shaders compile only with it).
|
||||||
std::optional<render::HeadlessGL> gl{};
|
std::optional<HeadlessGL> gl{};
|
||||||
if (format == "xml") gl.emplace();
|
if (format == "xml") gl.emplace();
|
||||||
std::string error{};
|
std::string error{};
|
||||||
Document document(arguments.file, false, &error);
|
Document document(arguments.file, false, &error);
|
||||||
auto fileUtf8 = path::to_utf8(arguments.file);
|
auto fileUtf8 = path_to_utf8(arguments.file);
|
||||||
if (!document.is_valid())
|
if (!document.is_valid())
|
||||||
{
|
{
|
||||||
std::println(stderr, "could not load {}: {}", fileUtf8, error);
|
std::println(stderr, "could not load {}: {}", fileUtf8, error);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (!error.empty()) std::println(stderr, "{}:\n{}", fileUtf8, error);
|
if (!error.empty()) std::println(stderr, "{}:\n{}", fileUtf8, error);
|
||||||
auto out = std::filesystem::absolute(arguments.get("out").transform(path::from_utf8).value_or(arguments.file));
|
auto out = std::filesystem::absolute(arguments.get("out").transform(path_from_utf8).value_or(arguments.file));
|
||||||
Options options{};
|
Options options{};
|
||||||
options.isJson = format == "json";
|
options.isJson = format == "json";
|
||||||
if (document.save(out, &error, options)) return 0;
|
if (document.save(out, &error, options)) return 0;
|
||||||
std::println(stderr, "could not write {}: {}", path::to_utf8(out), error);
|
std::println(stderr, "could not write {}: {}", path_to_utf8(out), error);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -323,10 +319,10 @@ options:
|
|||||||
|
|
||||||
bool is_cli(int argc, const char** argv)
|
bool is_cli(int argc, const char** argv)
|
||||||
{
|
{
|
||||||
return argc >= 2 && std::ranges::contains(COMMANDS, std::string_view(argv[1])) && !path::is_exist(argv[1]);
|
return argc >= 2 && std::ranges::contains(COMMANDS, std::string_view(argv[1])) && !is_path_exist(argv[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
int run(int argc, const char** argv)
|
int cli_run(int argc, const char** argv)
|
||||||
{
|
{
|
||||||
auto arguments = arguments_get(argc, argv);
|
auto arguments = arguments_get(argc, argv);
|
||||||
if (!arguments)
|
if (!arguments)
|
||||||
@@ -338,4 +334,3 @@ options:
|
|||||||
if (arguments->command == "convert") return convert_run(*arguments);
|
if (arguments->command == "convert") return convert_run(*arguments);
|
||||||
return draw_run(*arguments);
|
return draw_run(*arguments);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -3,8 +3,5 @@
|
|||||||
// The command-line mode: "anm2ed <info|frame|render> <file.anm2> [options]" looks at a file without the editor, as
|
// The command-line mode: "anm2ed <info|frame|render> <file.anm2> [options]" looks at a file without the editor, as
|
||||||
// text or drawn (by the editor's OpenGL renderer, in a hidden window) to a PNG frame, a contact sheet, PNGs, a GIF or
|
// text or drawn (by the editor's OpenGL renderer, in a hidden window) to a PNG frame, a contact sheet, PNGs, a GIF or
|
||||||
// a video.
|
// a video.
|
||||||
namespace anm2ed::cli
|
|
||||||
{
|
|
||||||
bool is_cli(int, const char**);
|
bool is_cli(int, const char**);
|
||||||
int run(int, const char**);
|
int cli_run(int, const char**);
|
||||||
}
|
|
||||||
@@ -3,8 +3,6 @@
|
|||||||
#include <SDL3/SDL_clipboard.h>
|
#include <SDL3/SDL_clipboard.h>
|
||||||
#include <SDL3/SDL_stdinc.h>
|
#include <SDL3/SDL_stdinc.h>
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
Clipboard::Clipboard() { set(""); }
|
Clipboard::Clipboard() { set(""); }
|
||||||
|
|
||||||
std::string Clipboard::get()
|
std::string Clipboard::get()
|
||||||
@@ -19,4 +17,3 @@ namespace anm2ed
|
|||||||
bool Clipboard::is_empty() { return !SDL_HasClipboardText(); }
|
bool Clipboard::is_empty() { return !SDL_HasClipboardText(); }
|
||||||
|
|
||||||
void Clipboard::set(const std::string& string) { SDL_SetClipboardText(string.c_str()); }
|
void Clipboard::set(const std::string& string) { SDL_SetClipboardText(string.c_str()); }
|
||||||
}
|
|
||||||
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
class Clipboard
|
class Clipboard
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -12,4 +10,3 @@ namespace anm2ed
|
|||||||
std::string get();
|
std::string get();
|
||||||
void set(const std::string&);
|
void set(const std::string&);
|
||||||
};
|
};
|
||||||
}
|
|
||||||
+6
-11
@@ -16,10 +16,6 @@
|
|||||||
|
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
|
|
||||||
using namespace anm2ed::util;
|
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
static void callback(void* userData, const char* const* filelist, int filter)
|
static void callback(void* userData, const char* const* filelist, int filter)
|
||||||
{
|
{
|
||||||
auto self = (Dialog*)(userData);
|
auto self = (Dialog*)(userData);
|
||||||
@@ -28,7 +24,7 @@ namespace anm2ed
|
|||||||
{
|
{
|
||||||
self->paths.clear();
|
self->paths.clear();
|
||||||
for (int i = 0; filelist[i] && strlen(filelist[i]) > 0; ++i)
|
for (int i = 0; filelist[i] && strlen(filelist[i]) > 0; ++i)
|
||||||
self->paths.push_back(path::from_utf8(filelist[i]));
|
self->paths.push_back(path_from_utf8(filelist[i]));
|
||||||
self->path = self->paths.empty() ? std::filesystem::path{} : self->paths.front();
|
self->path = self->paths.empty() ? std::filesystem::path{} : self->paths.front();
|
||||||
self->selectedFilter = filter;
|
self->selectedFilter = filter;
|
||||||
}
|
}
|
||||||
@@ -61,7 +57,7 @@ namespace anm2ed
|
|||||||
if (type == Dialog::NONE) return;
|
if (type == Dialog::NONE) return;
|
||||||
path.clear();
|
path.clear();
|
||||||
paths.clear();
|
paths.clear();
|
||||||
auto defaultPathString = path::to_utf8(defaultPath);
|
auto defaultPathString = path_to_utf8(defaultPath);
|
||||||
auto defaultPathCStr = defaultPathString.empty() ? nullptr : defaultPathString.c_str();
|
auto defaultPathCStr = defaultPathString.empty() ? nullptr : defaultPathString.c_str();
|
||||||
SDL_ShowSaveFileDialog(callback, this, window, FILTERS[TYPE_FILTERS[type]], std::size(FILTERS[TYPE_FILTERS[type]]),
|
SDL_ShowSaveFileDialog(callback, this, window, FILTERS[TYPE_FILTERS[type]], std::size(FILTERS[TYPE_FILTERS[type]]),
|
||||||
defaultPathCStr);
|
defaultPathCStr);
|
||||||
@@ -79,7 +75,7 @@ namespace anm2ed
|
|||||||
|
|
||||||
#ifdef __unix__
|
#ifdef __unix__
|
||||||
// A string as one single-quoted shell word.
|
// A string as one single-quoted shell word.
|
||||||
std::string shell_quote(std::string_view text)
|
static std::string shell_quote(std::string_view text)
|
||||||
{
|
{
|
||||||
std::string quoted = "'";
|
std::string quoted = "'";
|
||||||
for (auto character : text)
|
for (auto character : text)
|
||||||
@@ -89,10 +85,10 @@ namespace anm2ed
|
|||||||
|
|
||||||
// A file:// URI; everything but unreserved characters and slashes is percent-encoded (commas too, which dbus-send
|
// A file:// URI; everything but unreserved characters and slashes is percent-encoded (commas too, which dbus-send
|
||||||
// would otherwise take as array separators).
|
// would otherwise take as array separators).
|
||||||
std::string file_uri_get(const std::filesystem::path& path)
|
static std::string file_uri_get(const std::filesystem::path& path)
|
||||||
{
|
{
|
||||||
std::string uri = "file://";
|
std::string uri = "file://";
|
||||||
for (unsigned char character : path::to_utf8(path))
|
for (unsigned char character : path_to_utf8(path))
|
||||||
if (std::isalnum(character) || std::string_view("-._~/").contains((char)character))
|
if (std::isalnum(character) || std::string_view("-._~/").contains((char)character))
|
||||||
uri += (char)character;
|
uri += (char)character;
|
||||||
else
|
else
|
||||||
@@ -117,7 +113,7 @@ namespace anm2ed
|
|||||||
#elif __unix__
|
#elif __unix__
|
||||||
// File managers that implement org.freedesktop.FileManager1 (Nautilus, Dolphin, Nemo, Caja, Thunar...) select the
|
// File managers that implement org.freedesktop.FileManager1 (Nautilus, Dolphin, Nemo, Caja, Thunar...) select the
|
||||||
// file; anything else opens its folder.
|
// file; anything else opens its folder.
|
||||||
auto folder = shell_quote(path::to_utf8(isFile ? absolutePath.parent_path() : absolutePath));
|
auto folder = shell_quote(path_to_utf8(isFile ? absolutePath.parent_path() : absolutePath));
|
||||||
auto command = isFile ? std::format("(dbus-send --session --print-reply --dest=org.freedesktop.FileManager1 "
|
auto command = isFile ? std::format("(dbus-send --session --print-reply --dest=org.freedesktop.FileManager1 "
|
||||||
"--type=method_call /org/freedesktop/FileManager1 "
|
"--type=method_call /org/freedesktop/FileManager1 "
|
||||||
"org.freedesktop.FileManager1.ShowItems array:string:{} string:'' "
|
"org.freedesktop.FileManager1.ShowItems array:string:{} string:'' "
|
||||||
@@ -134,4 +130,3 @@ namespace anm2ed
|
|||||||
|
|
||||||
bool Dialog::is_selected(Type type) const { return this->type == type && !paths.empty(); }
|
bool Dialog::is_selected(Type type) const { return this->type == type && !paths.empty(); }
|
||||||
|
|
||||||
};
|
|
||||||
@@ -5,8 +5,6 @@
|
|||||||
|
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
class Dialog
|
class Dialog
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -96,4 +94,3 @@ namespace anm2ed
|
|||||||
void reset();
|
void reset();
|
||||||
void file_explorer_open(const std::filesystem::path&);
|
void file_explorer_open(const std::filesystem::path&);
|
||||||
};
|
};
|
||||||
}
|
|
||||||
+156
-165
@@ -28,13 +28,8 @@
|
|||||||
#include "ui/toast.h"
|
#include "ui/toast.h"
|
||||||
#include "working_directory.h"
|
#include "working_directory.h"
|
||||||
|
|
||||||
using namespace anm2ed::imgui;
|
|
||||||
using namespace anm2ed::types;
|
|
||||||
using namespace anm2ed::util;
|
|
||||||
using namespace glm;
|
using namespace glm;
|
||||||
|
|
||||||
namespace anm2ed::document
|
|
||||||
{
|
|
||||||
constexpr std::string_view BAKED_EXTENSION = ".baked.png";
|
constexpr std::string_view BAKED_EXTENSION = ".baked.png";
|
||||||
constexpr std::string_view AUTOSAVE_EXTENSION = ".autosave";
|
constexpr std::string_view AUTOSAVE_EXTENSION = ".autosave";
|
||||||
constexpr int VECTOR_LEVEL_MAX = 3;
|
constexpr int VECTOR_LEVEL_MAX = 3;
|
||||||
@@ -42,44 +37,44 @@ namespace anm2ed::document
|
|||||||
constexpr std::uint64_t HASH_COMBINE_CONSTANT = 0x9e3779b97f4a7c15ULL;
|
constexpr std::uint64_t HASH_COMBINE_CONSTANT = 0x9e3779b97f4a7c15ULL;
|
||||||
|
|
||||||
// A path written in a document in `directory`, as an absolute path.
|
// A path written in a document in `directory`, as an absolute path.
|
||||||
std::filesystem::path absolute_path_get(const std::filesystem::path& directory, const std::filesystem::path& path)
|
static std::filesystem::path absolute_path_get(const std::filesystem::path& directory, const std::filesystem::path& path)
|
||||||
{
|
{
|
||||||
util::WorkingDirectory workingDirectory(directory);
|
WorkingDirectory workingDirectory(directory);
|
||||||
std::error_code ec{};
|
std::error_code ec{};
|
||||||
auto absolutePath = std::filesystem::weakly_canonical(directory / path::case_insensitive_find(path), ec);
|
auto absolutePath = std::filesystem::weakly_canonical(directory / path_case_insensitive_find(path), ec);
|
||||||
return ec ? directory / path : absolutePath;
|
return ec ? directory / path : absolutePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
void library_load(const std::filesystem::path& path, LibraryData& library)
|
static void library_load(const std::filesystem::path& path, LibraryData& library)
|
||||||
{
|
{
|
||||||
library = {};
|
library = {};
|
||||||
std::string errorString{};
|
std::string errorString{};
|
||||||
model::model_load(library.model, path, &errorString);
|
model_load(library.model, path, &errorString);
|
||||||
// Why it couldn't load, or what a JSON library couldn't read.
|
// Why it couldn't load, or what a JSON library couldn't read.
|
||||||
if (!errorString.empty()) toast_log(Level::WARNING, TOAST_LIBRARY_ISSUES, path::to_utf8(path), errorString);
|
if (!errorString.empty()) toast_log(Level::WARNING, TOAST_LIBRARY_ISSUES, path_to_utf8(path), errorString);
|
||||||
std::error_code ec{};
|
std::error_code ec{};
|
||||||
library.writeTime = std::filesystem::last_write_time(path, ec);
|
library.writeTime = std::filesystem::last_write_time(path, ec);
|
||||||
util::WorkingDirectory workingDirectory(path.parent_path());
|
WorkingDirectory workingDirectory(path.parent_path());
|
||||||
for (const auto& spritesheet : library.model.content.spritesheets)
|
for (const auto& spritesheet : library.model.content.spritesheets)
|
||||||
library.images.emplace(spritesheet.id, resource::Image(path::case_insensitive_find(spritesheet.path)));
|
library.images.emplace(spritesheet.id, Image(path_case_insensitive_find(spritesheet.path)));
|
||||||
for (const auto& sound : library.model.content.sounds)
|
for (const auto& sound : library.model.content.sounds)
|
||||||
library.sounds.emplace(sound.id, resource::AudioData(path::case_insensitive_find(sound.path)));
|
library.sounds.emplace(sound.id, AudioData(path_case_insensitive_find(sound.path)));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t document_tab_id_next()
|
static uint64_t document_tab_id_next()
|
||||||
{
|
{
|
||||||
static uint64_t next{1};
|
static uint64_t next{1};
|
||||||
return next++;
|
return next++;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::filesystem::path shader_absolute_path_get(Document& document, const std::filesystem::path& path)
|
static std::filesystem::path shader_absolute_path_get(Document& document, const std::filesystem::path& path)
|
||||||
{
|
{
|
||||||
auto loadPath = path::backslash_handle(path);
|
auto loadPath = path_backslash_handle(path);
|
||||||
if (loadPath.empty() || loadPath.is_absolute()) return loadPath;
|
if (loadPath.empty() || loadPath.is_absolute()) return loadPath;
|
||||||
return document.directory_get() / loadPath;
|
return document.directory_get() / loadPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
void shader_status_append(const resource::ShaderCompileResult& result, std::string* status)
|
static void shader_status_append(const ShaderCompileResult& result, std::string* status)
|
||||||
{
|
{
|
||||||
if (!status) return;
|
if (!status) return;
|
||||||
|
|
||||||
@@ -93,7 +88,7 @@ namespace anm2ed::document
|
|||||||
if (!result.output.empty()) *status += result.output;
|
if (!result.output.empty()) *status += result.output;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string shader_source_lines_get(std::string_view label, std::string_view source)
|
static std::string shader_source_lines_get(std::string_view label, std::string_view source)
|
||||||
{
|
{
|
||||||
std::string output = std::format("\n{}:\n", label);
|
std::string output = std::format("\n{}:\n", label);
|
||||||
int lineNumber{1};
|
int lineNumber{1};
|
||||||
@@ -110,14 +105,14 @@ namespace anm2ed::document
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
void shader_status_format_append(std::string* status, StringType format, StringType argument)
|
static void shader_status_format_append(std::string* status, StringType format, StringType argument)
|
||||||
{
|
{
|
||||||
if (!status) return;
|
if (!status) return;
|
||||||
auto argumentString = std::string(localize.get(argument));
|
auto argumentString = std::string(localize.get(argument));
|
||||||
*status += std::vformat(localize.get(format), std::make_format_args(argumentString)) + "\n";
|
*status += std::vformat(localize.get(format), std::make_format_args(argumentString)) + "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool shader_source_load(Document& document, const std::filesystem::path& shaderPath, std::string& source,
|
static bool shader_source_load(Document& document, const std::filesystem::path& shaderPath, std::string& source,
|
||||||
StringType label, std::string* status, const char* fallback = nullptr)
|
StringType label, std::string* status, const char* fallback = nullptr)
|
||||||
{
|
{
|
||||||
if (shaderPath.empty() && !fallback)
|
if (shaderPath.empty() && !fallback)
|
||||||
@@ -131,12 +126,12 @@ namespace anm2ed::document
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto absolute = path::case_insensitive_find(shader_absolute_path_get(document, shaderPath));
|
auto absolute = path_case_insensitive_find(shader_absolute_path_get(document, shaderPath));
|
||||||
if (file::read_to_string(absolute, &source)) return true;
|
if (file_text_load(absolute, &source)) return true;
|
||||||
|
|
||||||
if (status)
|
if (status)
|
||||||
{
|
{
|
||||||
auto pathString = path::to_utf8(shaderPath);
|
auto pathString = path_to_utf8(shaderPath);
|
||||||
*status += std::vformat(localize.get(LABEL_SHADER_READ_FAILED), std::make_format_args(pathString)) + "\n";
|
*status += std::vformat(localize.get(LABEL_SHADER_READ_FAILED), std::make_format_args(pathString)) + "\n";
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -148,14 +143,14 @@ namespace anm2ed::document
|
|||||||
std::unordered_map<int, std::filesystem::path>& paths, Load&& load)
|
std::unordered_map<int, std::filesystem::path>& paths, Load&& load)
|
||||||
{
|
{
|
||||||
std::set<int> validIds{};
|
std::set<int> validIds{};
|
||||||
util::WorkingDirectory workingDirectory(document.directory_get());
|
WorkingDirectory workingDirectory(document.directory_get());
|
||||||
for (auto& element : items)
|
for (auto& element : items)
|
||||||
{
|
{
|
||||||
validIds.insert(element.id);
|
validIds.insert(element.id);
|
||||||
auto path = paths.find(element.id);
|
auto path = paths.find(element.id);
|
||||||
if (!keys.contains(element.id) || path == paths.end() || path->second != element.path)
|
if (!keys.contains(element.id) || path == paths.end() || path->second != element.path)
|
||||||
{
|
{
|
||||||
load(element.id, path::case_insensitive_find(element.path));
|
load(element.id, path_case_insensitive_find(element.path));
|
||||||
paths[element.id] = element.path;
|
paths[element.id] = element.path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -165,34 +160,31 @@ namespace anm2ed::document
|
|||||||
}
|
}
|
||||||
|
|
||||||
// A spritesheet is dirty when its path or image asset differs from what was last saved.
|
// A spritesheet is dirty when its path or image asset differs from what was last saved.
|
||||||
uint64_t spritesheet_hash_get(const model::Spritesheet& spritesheet, std::uint64_t imageKey)
|
static uint64_t spritesheet_hash_get(const Spritesheet& spritesheet, std::uint64_t imageKey)
|
||||||
{
|
{
|
||||||
auto seed = std::hash<std::string>{}(path::to_utf8(spritesheet.path));
|
auto seed = std::hash<std::string>{}(path_to_utf8(spritesheet.path));
|
||||||
return seed ^ (imageKey + HASH_COMBINE_CONSTANT + (seed << 6) + (seed >> 2));
|
return seed ^ (imageKey + HASH_COMBINE_CONSTANT + (seed << 6) + (seed >> 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference item_reference_get(Reference reference)
|
static Reference item_reference_get(Reference reference)
|
||||||
{
|
{
|
||||||
reference.frameIndex = -1;
|
reference.frameIndex = -1;
|
||||||
return reference;
|
return reference;
|
||||||
}
|
}
|
||||||
|
|
||||||
void frame_time_sync(Document& document)
|
static void frame_time_sync(Document& document)
|
||||||
{
|
{
|
||||||
auto reference = document.reference_get();
|
auto reference = document.reference_get();
|
||||||
auto item = document.model.track_get(reference);
|
auto item = document.model.track_get(reference);
|
||||||
auto frameIndex = reference.frameIndex;
|
auto frameIndex = reference.frameIndex;
|
||||||
document.frameTime = item && frameIndex >= 0 ? frame_time_from_index_get(*item, frameIndex) : 0.0f;
|
document.frameTime = item && frameIndex >= 0 ? frame_time_from_index_get(*item, frameIndex) : 0.0f;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
Document::Document(const std::filesystem::path& path, bool isNew, std::string* errorString)
|
Document::Document(const std::filesystem::path& path, bool isNew, std::string* errorString)
|
||||||
{
|
{
|
||||||
tabId = document::document_tab_id_next();
|
tabId = document_tab_id_next();
|
||||||
model = model::model_make();
|
model = model_make();
|
||||||
if (!isNew) model::model_load(model, path, errorString);
|
if (!isNew) model_load(model, path, errorString);
|
||||||
if (isNew ? !save(path, errorString) : !model.isValid)
|
if (isNew ? !save(path, errorString) : !model.isValid)
|
||||||
{
|
{
|
||||||
isValid = false;
|
isValid = false;
|
||||||
@@ -219,7 +211,7 @@ namespace anm2ed
|
|||||||
bool Document::save(const std::filesystem::path& path, std::string* errorString, Options options)
|
bool Document::save(const std::filesystem::path& path, std::string* errorString, Options options)
|
||||||
{
|
{
|
||||||
auto absolutePath = !path.empty() ? path : this->path;
|
auto absolutePath = !path.empty() ? path : this->path;
|
||||||
auto absolutePathUtf8 = path::to_utf8(absolutePath);
|
auto absolutePathUtf8 = path_to_utf8(absolutePath);
|
||||||
if (file_write(absolutePath, errorString, options))
|
if (file_write(absolutePath, errorString, options))
|
||||||
{
|
{
|
||||||
this->path = absolutePath;
|
this->path = absolutePath;
|
||||||
@@ -232,14 +224,14 @@ namespace anm2ed
|
|||||||
}
|
}
|
||||||
|
|
||||||
// A library's spritesheet path, made relative to this document (for flattening its animation layers).
|
// A library's spritesheet path, made relative to this document (for flattening its animation layers).
|
||||||
edit::SpritesheetPathGet Document::spritesheet_path_resolver_get() const
|
SpritesheetPathGet Document::spritesheet_path_resolver_get() const
|
||||||
{
|
{
|
||||||
return [this](const model::Model& source, const std::filesystem::path& spritesheetPath)
|
return [this](const Model& source, const std::filesystem::path& spritesheetPath)
|
||||||
{
|
{
|
||||||
for (const auto& [libraryPath, library] : libraries)
|
for (const auto& [libraryPath, library] : libraries)
|
||||||
if (&library.model == &source)
|
if (&library.model == &source)
|
||||||
return path::backslash_replace(
|
return path_backslash_replace(
|
||||||
path::make_relative(document::absolute_path_get(libraryPath.parent_path(), spritesheetPath),
|
path_make_relative(absolute_path_get(libraryPath.parent_path(), spritesheetPath),
|
||||||
std::filesystem::absolute(directory_get())));
|
std::filesystem::absolute(directory_get())));
|
||||||
return spritesheetPath;
|
return spritesheetPath;
|
||||||
};
|
};
|
||||||
@@ -249,48 +241,48 @@ namespace anm2ed
|
|||||||
// can't show worked around.
|
// can't show worked around.
|
||||||
bool Document::file_write(const std::filesystem::path& path, std::string* errorString, Options options)
|
bool Document::file_write(const std::filesystem::path& path, std::string* errorString, Options options)
|
||||||
{
|
{
|
||||||
std::optional<model::Model> game{};
|
std::optional<Model> game{};
|
||||||
if (!options.isJson)
|
if (!options.isJson)
|
||||||
{
|
{
|
||||||
game = edit::animation_layers_flatten(model, library_resolver_get(), spritesheet_path_resolver_get());
|
game = animation_layers_flatten(model, library_resolver_get(), spritesheet_path_resolver_get());
|
||||||
if (!model.info.isIsaacIgnored)
|
if (!model.info.isIsaacIgnored)
|
||||||
{
|
{
|
||||||
auto bakedPath = path;
|
auto bakedPath = path;
|
||||||
if (options.isPixelBaked)
|
if (options.isPixelBaked)
|
||||||
render::frames_bake(*this, *game, bakedPath.replace_extension(document::BAKED_EXTENSION));
|
frames_bake(*this, *game, bakedPath.replace_extension(BAKED_EXTENSION));
|
||||||
game = edit::isaac_bridge(std::move(*game));
|
game = isaac_bridge(std::move(*game));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
options.gameModel = game ? &*game : nullptr;
|
options.gameModel = game ? &*game : nullptr;
|
||||||
return model::model_save(model, path, errorString, options);
|
return model_save(model, path, errorString, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::filesystem::path Document::autosave_path_get()
|
std::filesystem::path Document::autosave_path_get()
|
||||||
{
|
{
|
||||||
return directory_get() /
|
return directory_get() /
|
||||||
path::from_utf8("." + path::to_utf8(filename_get()) + std::string(document::AUTOSAVE_EXTENSION));
|
path_from_utf8("." + path_to_utf8(filename_get()) + std::string(AUTOSAVE_EXTENSION));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::filesystem::path Document::path_from_autosave_get(const std::filesystem::path& path)
|
std::filesystem::path Document::path_from_autosave_get(const std::filesystem::path& path)
|
||||||
{
|
{
|
||||||
auto fileName = path::to_utf8(path.filename());
|
auto fileName = path_to_utf8(path.filename());
|
||||||
if (fileName.starts_with('.')) fileName.erase(fileName.begin());
|
if (fileName.starts_with('.')) fileName.erase(fileName.begin());
|
||||||
if (fileName.ends_with(document::AUTOSAVE_EXTENSION))
|
if (fileName.ends_with(AUTOSAVE_EXTENSION))
|
||||||
fileName.erase(fileName.size() - document::AUTOSAVE_EXTENSION.size());
|
fileName.erase(fileName.size() - AUTOSAVE_EXTENSION.size());
|
||||||
return path.parent_path() / std::filesystem::path(std::u8string(fileName.begin(), fileName.end()));
|
return path.parent_path() / std::filesystem::path(std::u8string(fileName.begin(), fileName.end()));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Document::autosave(std::string* errorString, Options options)
|
bool Document::autosave(std::string* errorString, Options options)
|
||||||
{
|
{
|
||||||
auto autosavePath = autosave_path_get();
|
auto autosavePath = autosave_path_get();
|
||||||
auto autosavePathUtf8 = path::to_utf8(autosavePath);
|
auto autosavePathUtf8 = path_to_utf8(autosavePath);
|
||||||
// An autosave is read back from the editor's copy, so the game's needs no baked spritesheet.
|
// An autosave is read back from the editor's copy, so the game's needs no baked spritesheet.
|
||||||
options.isPixelBaked = false;
|
options.isPixelBaked = false;
|
||||||
if (file_write(autosavePath, errorString, options))
|
if (file_write(autosavePath, errorString, options))
|
||||||
{
|
{
|
||||||
for (auto id : spritesheets_autosave_dirty_get())
|
for (auto id : spritesheets_autosave_dirty_get())
|
||||||
{
|
{
|
||||||
auto spritesheet = model::item_get(model.content.spritesheets, id);
|
auto spritesheet = item_get(model.content.spritesheets, id);
|
||||||
auto texture = texture_get(id);
|
auto texture = texture_get(id);
|
||||||
if (texture && texture->write(spritesheet_autosave_path_get(*spritesheet)))
|
if (texture && texture->write(spritesheet_autosave_path_get(*spritesheet)))
|
||||||
spritesheetAutosaveHashes[id] = spritesheetHashes.at(id);
|
spritesheetAutosaveHashes[id] = spritesheetHashes.at(id);
|
||||||
@@ -307,25 +299,25 @@ namespace anm2ed
|
|||||||
|
|
||||||
void Document::texture_change(int id)
|
void Document::texture_change(int id)
|
||||||
{
|
{
|
||||||
if (texture_get(id) && model::item_get(model.content.spritesheets, id)) change();
|
if (texture_get(id) && item_get(model.content.spritesheets, id)) change();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Document::texture_reload(int id)
|
bool Document::texture_reload(int id)
|
||||||
{
|
{
|
||||||
auto spritesheet = model::item_get(model.content.spritesheets, id);
|
auto spritesheet = item_get(model.content.spritesheets, id);
|
||||||
if (!spritesheet) return false;
|
if (!spritesheet) return false;
|
||||||
util::WorkingDirectory workingDirectory(directory_get());
|
WorkingDirectory workingDirectory(directory_get());
|
||||||
texture_set(id, resource::Image(path::case_insensitive_find(spritesheet->path)));
|
texture_set(id, Image(path_case_insensitive_find(spritesheet->path)));
|
||||||
texturePaths[id] = spritesheet->path;
|
texturePaths[id] = spritesheet->path;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Document::sound_reload(int id)
|
bool Document::sound_reload(int id)
|
||||||
{
|
{
|
||||||
auto sound = model::item_get(model.content.sounds, id);
|
auto sound = item_get(model.content.sounds, id);
|
||||||
if (!sound) return false;
|
if (!sound) return false;
|
||||||
util::WorkingDirectory workingDirectory(directory_get());
|
WorkingDirectory workingDirectory(directory_get());
|
||||||
sound_set(id, resource::AudioData(path::case_insensitive_find(sound->path)));
|
sound_set(id, AudioData(path_case_insensitive_find(sound->path)));
|
||||||
soundPaths[id] = sound->path;
|
soundPaths[id] = sound->path;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -341,37 +333,37 @@ namespace anm2ed
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Without an OpenGL context (as the command line converts), there is nothing to compile it with.
|
// Without an OpenGL context (as the command line converts), there is nothing to compile it with.
|
||||||
auto shaderElement = SDL_GL_GetCurrentContext() ? model::item_get(model.content.shaders, shaderId) : nullptr;
|
auto shaderElement = SDL_GL_GetCurrentContext() ? item_get(model.content.shaders, shaderId) : nullptr;
|
||||||
if (!shaderElement)
|
if (!shaderElement)
|
||||||
{
|
{
|
||||||
document::shader_status_format_append(status, LABEL_SHADER_PATH_EMPTY, LABEL_FRAGMENT);
|
shader_status_format_append(status, LABEL_SHADER_PATH_EMPTY, LABEL_FRAGMENT);
|
||||||
return shader_erase();
|
return shader_erase();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string vertexSource{};
|
std::string vertexSource{};
|
||||||
std::string fragmentSource{};
|
std::string fragmentSource{};
|
||||||
auto isVertexLoaded = document::shader_source_load(*this, shaderElement->vertex, vertexSource, LABEL_VERTEX, status,
|
auto isVertexLoaded = shader_source_load(*this, shaderElement->vertex, vertexSource, LABEL_VERTEX, status,
|
||||||
resource::shader::TEXTURE_COMPATIBILITY_VERTEX);
|
TEXTURE_COMPATIBILITY_VERTEX);
|
||||||
auto isFragmentLoaded =
|
auto isFragmentLoaded =
|
||||||
document::shader_source_load(*this, shaderElement->fragment, fragmentSource, LABEL_FRAGMENT, status);
|
shader_source_load(*this, shaderElement->fragment, fragmentSource, LABEL_FRAGMENT, status);
|
||||||
if (!isVertexLoaded || !isFragmentLoaded) return shader_erase();
|
if (!isVertexLoaded || !isFragmentLoaded) return shader_erase();
|
||||||
|
|
||||||
auto vertex = resource::shader::gles_vertex_convert(vertexSource);
|
auto vertex = gles_vertex_convert(vertexSource);
|
||||||
auto fragment = resource::shader::gles_fragment_convert(fragmentSource);
|
auto fragment = gles_fragment_convert(fragmentSource);
|
||||||
auto result = resource::shader_compile(vertex.c_str(), fragment.c_str());
|
auto result = shader_compile(vertex.c_str(), fragment.c_str());
|
||||||
document::shader_status_append(result, status);
|
shader_status_append(result, status);
|
||||||
if (status && (!result.isCompiled || !result.isLinked))
|
if (status && (!result.isCompiled || !result.isLinked))
|
||||||
{
|
{
|
||||||
*status += document::shader_source_lines_get("Converted vertex shader", vertex);
|
*status += shader_source_lines_get("Converted vertex shader", vertex);
|
||||||
*status += document::shader_source_lines_get("Converted fragment shader", fragment);
|
*status += shader_source_lines_get("Converted fragment shader", fragment);
|
||||||
}
|
}
|
||||||
if (!result.isLinked || !result.id) return shader_erase();
|
if (!result.isLinked || !result.id) return shader_erase();
|
||||||
|
|
||||||
resource::Shader runtime{};
|
ShaderProgram runtime{};
|
||||||
runtime.id = result.id;
|
runtime.id = result.id;
|
||||||
runtime.uniforms = std::move(result.uniforms);
|
runtime.uniforms = std::move(result.uniforms);
|
||||||
if (resource::shader::uniform_configs_trim(*shaderElement, runtime.uniforms)) hash_set();
|
if (uniform_configs_trim(*shaderElement, runtime.uniforms)) hash_set();
|
||||||
resource::shader::uniform_configs_apply(*shaderElement, runtime.uniforms);
|
uniform_configs_apply(*shaderElement, runtime.uniforms);
|
||||||
shaders[shaderId] = std::move(runtime);
|
shaders[shaderId] = std::move(runtime);
|
||||||
shaderVertexPaths[shaderId] = shaderElement->vertex;
|
shaderVertexPaths[shaderId] = shaderElement->vertex;
|
||||||
shaderFragmentPaths[shaderId] = shaderElement->fragment;
|
shaderFragmentPaths[shaderId] = shaderElement->fragment;
|
||||||
@@ -381,15 +373,15 @@ namespace anm2ed
|
|||||||
void Document::assets_sync()
|
void Document::assets_sync()
|
||||||
{
|
{
|
||||||
libraries_sync();
|
libraries_sync();
|
||||||
document::resources_sync(*this, model.content.spritesheets, textures, texturePaths,
|
resources_sync(*this, model.content.spritesheets, textures, texturePaths,
|
||||||
[&](int id, const std::filesystem::path& path)
|
[&](int id, const std::filesystem::path& path)
|
||||||
{ texture_set(id, resource::Image(path)); });
|
{ texture_set(id, Image(path)); });
|
||||||
document::resources_sync(*this, model.content.sounds, sounds, soundPaths,
|
resources_sync(*this, model.content.sounds, sounds, soundPaths,
|
||||||
[&](int id, const std::filesystem::path& path)
|
[&](int id, const std::filesystem::path& path)
|
||||||
{ sound_set(id, resource::AudioData(path)); });
|
{ sound_set(id, AudioData(path)); });
|
||||||
|
|
||||||
std::set<int> validShaderIds{};
|
std::set<int> validShaderIds{};
|
||||||
util::WorkingDirectory workingDirectory(directory_get());
|
WorkingDirectory workingDirectory(directory_get());
|
||||||
for (auto& shaderElement : model.content.shaders)
|
for (auto& shaderElement : model.content.shaders)
|
||||||
{
|
{
|
||||||
auto id = shaderElement.id;
|
auto id = shaderElement.id;
|
||||||
@@ -406,7 +398,7 @@ namespace anm2ed
|
|||||||
else if (isReload)
|
else if (isReload)
|
||||||
shader_reload(id);
|
shader_reload(id);
|
||||||
else if (auto shader = shader_get(id))
|
else if (auto shader = shader_get(id))
|
||||||
resource::shader::uniform_configs_apply(shaderElement, shader->uniforms);
|
uniform_configs_apply(shaderElement, shader->uniforms);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto is_invalid = [&](const auto& pair) { return !validShaderIds.contains(pair.first); };
|
auto is_invalid = [&](const auto& pair) { return !validShaderIds.contains(pair.first); };
|
||||||
@@ -426,22 +418,22 @@ namespace anm2ed
|
|||||||
|
|
||||||
std::filesystem::path Document::library_path_get(int id) const
|
std::filesystem::path Document::library_path_get(int id) const
|
||||||
{
|
{
|
||||||
auto library = model::item_get(model.content.libraries, id);
|
auto library = item_get(model.content.libraries, id);
|
||||||
return library ? document::absolute_path_get(std::filesystem::absolute(directory_get()), library->path)
|
return library ? absolute_path_get(std::filesystem::absolute(directory_get()), library->path)
|
||||||
: std::filesystem::path{};
|
: std::filesystem::path{};
|
||||||
}
|
}
|
||||||
|
|
||||||
// A library of this document (or of a copy of it) or of one of its libraries.
|
// A library of this document (or of a copy of it) or of one of its libraries.
|
||||||
const LibraryData* Document::library_get(const model::Model& from, int id) const
|
const LibraryData* Document::library_get(const Model& from, int id) const
|
||||||
{
|
{
|
||||||
auto isLibrary = std::ranges::any_of(libraries, [&](const auto& pair) { return &pair.second.model == &from; });
|
auto isLibrary = std::ranges::any_of(libraries, [&](const auto& pair) { return &pair.second.model == &from; });
|
||||||
auto link = libraryLinks.find({isLibrary ? &from : nullptr, id});
|
auto link = libraryLinks.find({isLibrary ? &from : nullptr, id});
|
||||||
return link == libraryLinks.end() ? nullptr : link->second;
|
return link == libraryLinks.end() ? nullptr : link->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
model::LibraryGet Document::library_resolver_get() const
|
LibraryGet Document::library_resolver_get() const
|
||||||
{
|
{
|
||||||
return [this](const model::Model& from, int id)
|
return [this](const Model& from, int id)
|
||||||
{
|
{
|
||||||
auto library = library_get(from, id);
|
auto library = library_get(from, id);
|
||||||
return library ? &library->model : nullptr;
|
return library ? &library->model : nullptr;
|
||||||
@@ -449,7 +441,7 @@ namespace anm2ed
|
|||||||
}
|
}
|
||||||
|
|
||||||
// An animation layer whose animation isn't there; a library that didn't load leaves the question open (false).
|
// An animation layer whose animation isn't there; a library that didn't load leaves the question open (false).
|
||||||
bool Document::is_layer_animation_missing(const model::Layer& layer) const
|
bool Document::is_layer_animation_missing(const Layer& layer) const
|
||||||
{
|
{
|
||||||
if (!layer.is_animation()) return false;
|
if (!layer.is_animation()) return false;
|
||||||
auto library = layer.libraryId == -1 ? nullptr : library_get(model, layer.libraryId);
|
auto library = layer.libraryId == -1 ? nullptr : library_get(model, layer.libraryId);
|
||||||
@@ -470,9 +462,9 @@ namespace anm2ed
|
|||||||
}
|
}
|
||||||
|
|
||||||
// A layer draw's spritesheet image, at `scale` (see vector_image_get).
|
// A layer draw's spritesheet image, at `scale` (see vector_image_get).
|
||||||
const resource::Image* Document::draw_image_get(const model::Draw& draw, float scale) const
|
const Image* Document::draw_image_get(const Draw& draw, float scale) const
|
||||||
{
|
{
|
||||||
const resource::Image* image{};
|
const Image* image{};
|
||||||
if (!draw.source || draw.source == &model) image = texture_get(draw.spritesheetId);
|
if (!draw.source || draw.source == &model) image = texture_get(draw.spritesheetId);
|
||||||
for (const auto& [path, library] : libraries)
|
for (const auto& [path, library] : libraries)
|
||||||
if (&library.model == draw.source)
|
if (&library.model == draw.source)
|
||||||
@@ -481,12 +473,12 @@ namespace anm2ed
|
|||||||
}
|
}
|
||||||
|
|
||||||
// A vector image drawn again (cached) for when `scale` screen pixels show each of its pixels; others as they are.
|
// A vector image drawn again (cached) for when `scale` screen pixels show each of its pixels; others as they are.
|
||||||
const resource::Image* Document::vector_image_get(const resource::Image* image, float scale) const
|
const Image* Document::vector_image_get(const Image* image, float scale) const
|
||||||
{
|
{
|
||||||
if (!image || !image->is_vector() || scale <= 1.0f) return image;
|
if (!image || !image->is_vector() || scale <= 1.0f) return image;
|
||||||
|
|
||||||
auto level = std::min((int)std::ceil(std::log2(scale)), document::VECTOR_LEVEL_MAX);
|
auto level = std::min((int)std::ceil(std::log2(scale)), VECTOR_LEVEL_MAX);
|
||||||
while (level > 0 && std::max(image->size.x, image->size.y) << level > document::VECTOR_SIZE_MAX)
|
while (level > 0 && std::max(image->size.x, image->size.y) << level > VECTOR_SIZE_MAX)
|
||||||
--level;
|
--level;
|
||||||
if (level == 0) return image;
|
if (level == 0) return image;
|
||||||
auto [it, isNew] = vectorImages.try_emplace({image->uid, level});
|
auto [it, isNew] = vectorImages.try_emplace({image->uid, level});
|
||||||
@@ -499,7 +491,7 @@ namespace anm2ed
|
|||||||
{
|
{
|
||||||
libraryLinks.clear();
|
libraryLinks.clear();
|
||||||
std::set<std::filesystem::path> reached{};
|
std::set<std::filesystem::path> reached{};
|
||||||
std::vector<std::pair<const model::Model*, std::filesystem::path>> pending{
|
std::vector<std::pair<const Model*, std::filesystem::path>> pending{
|
||||||
{&model, std::filesystem::absolute(directory_get())}};
|
{&model, std::filesystem::absolute(directory_get())}};
|
||||||
while (!pending.empty())
|
while (!pending.empty())
|
||||||
{
|
{
|
||||||
@@ -507,11 +499,11 @@ namespace anm2ed
|
|||||||
pending.pop_back();
|
pending.pop_back();
|
||||||
for (const auto& library : from->content.libraries)
|
for (const auto& library : from->content.libraries)
|
||||||
{
|
{
|
||||||
auto path = document::absolute_path_get(directory, library.path);
|
auto path = absolute_path_get(directory, library.path);
|
||||||
auto [it, isNew] = libraries.try_emplace(path);
|
auto [it, isNew] = libraries.try_emplace(path);
|
||||||
if (isNew)
|
if (isNew)
|
||||||
{
|
{
|
||||||
document::library_load(path, it->second);
|
library_load(path, it->second);
|
||||||
++librariesRevision;
|
++librariesRevision;
|
||||||
}
|
}
|
||||||
libraryLinks[{from == &model ? nullptr : from, library.id}] = &it->second;
|
libraryLinks[{from == &model ? nullptr : from, library.id}] = &it->second;
|
||||||
@@ -530,7 +522,7 @@ namespace anm2ed
|
|||||||
std::error_code ec{};
|
std::error_code ec{};
|
||||||
auto time = std::filesystem::last_write_time(path, ec);
|
auto time = std::filesystem::last_write_time(path, ec);
|
||||||
if (ec || time == library.writeTime) continue;
|
if (ec || time == library.writeTime) continue;
|
||||||
document::library_load(path, library);
|
library_load(path, library);
|
||||||
++librariesRevision;
|
++librariesRevision;
|
||||||
isReloaded = true;
|
isReloaded = true;
|
||||||
}
|
}
|
||||||
@@ -544,7 +536,7 @@ namespace anm2ed
|
|||||||
libraries_sync();
|
libraries_sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
const resource::Image* Document::texture_get(int id) const
|
const Image* Document::texture_get(int id) const
|
||||||
{
|
{
|
||||||
if (auto draft = textureDrafts.find(id); draft != textureDrafts.end()) return &draft->second;
|
if (auto draft = textureDrafts.find(id); draft != textureDrafts.end()) return &draft->second;
|
||||||
auto key = textures.find(id);
|
auto key = textures.find(id);
|
||||||
@@ -552,29 +544,29 @@ namespace anm2ed
|
|||||||
}
|
}
|
||||||
|
|
||||||
// A private copy of the spritesheet's image to draw on; it becomes a new asset on the next change().
|
// A private copy of the spritesheet's image to draw on; it becomes a new asset on the next change().
|
||||||
resource::Image* Document::texture_edit(int id)
|
Image* Document::texture_edit(int id)
|
||||||
{
|
{
|
||||||
auto texture = texture_get(id);
|
auto texture = texture_get(id);
|
||||||
if (!texture || texture->is_vector()) return nullptr;
|
if (!texture || texture->is_vector()) return nullptr;
|
||||||
return &textureDrafts.try_emplace(id, *texture).first->second;
|
return &textureDrafts.try_emplace(id, *texture).first->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Document::texture_set(int id, resource::Image image)
|
void Document::texture_set(int id, Image image)
|
||||||
{
|
{
|
||||||
textureDrafts.erase(id);
|
textureDrafts.erase(id);
|
||||||
textures[id] = assets.image_add(std::move(image));
|
textures[id] = assets.image_add(std::move(image));
|
||||||
}
|
}
|
||||||
|
|
||||||
const resource::AudioData* Document::sound_get(int id) const
|
const AudioData* Document::sound_get(int id) const
|
||||||
{
|
{
|
||||||
auto key = sounds.find(id);
|
auto key = sounds.find(id);
|
||||||
return key == sounds.end() ? nullptr : assets.audio_get(key->second);
|
return key == sounds.end() ? nullptr : assets.audio_get(key->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Every sound that may be playing: this document's and its libraries'.
|
// Every sound that may be playing: this document's and its libraries'.
|
||||||
std::vector<const resource::AudioData*> Document::sounds_get() const
|
std::vector<const AudioData*> Document::sounds_get() const
|
||||||
{
|
{
|
||||||
std::vector<const resource::AudioData*> result{};
|
std::vector<const AudioData*> result{};
|
||||||
for (const auto& [id, key] : sounds)
|
for (const auto& [id, key] : sounds)
|
||||||
if (auto sound = sound_get(id)) result.push_back(sound);
|
if (auto sound = sound_get(id)) result.push_back(sound);
|
||||||
for (const auto& [path, library] : libraries)
|
for (const auto& [path, library] : libraries)
|
||||||
@@ -585,19 +577,19 @@ namespace anm2ed
|
|||||||
|
|
||||||
// The sounds triggers play on an animation's frame, its children's included: one of each trigger's sounds, at random
|
// The sounds triggers play on an animation's frame, its children's included: one of each trigger's sounds, at random
|
||||||
// (or picked by `index` for repeatable renders).
|
// (or picked by `index` for repeatable renders).
|
||||||
std::vector<const resource::AudioData*> Document::trigger_sounds_get(const model::Animation& animation, int time,
|
std::vector<const AudioData*> Document::trigger_sounds_get(const Animation& animation, int time,
|
||||||
int index) const
|
int index) const
|
||||||
{
|
{
|
||||||
std::vector<const resource::AudioData*> result{};
|
std::vector<const AudioData*> result{};
|
||||||
for (const auto& [source, trigger, layerId] :
|
for (const auto& [source, trigger, layerId] :
|
||||||
model::animation_triggers_get(model, animation, time, library_resolver_get()))
|
animation_triggers_get(model, animation, time, library_resolver_get()))
|
||||||
{
|
{
|
||||||
if (trigger.soundIds.empty()) continue;
|
if (trigger.soundIds.empty()) continue;
|
||||||
auto count = trigger.soundIds.size();
|
auto count = trigger.soundIds.size();
|
||||||
auto soundIndex = std::min(
|
auto soundIndex = std::min(
|
||||||
index >= 0 ? (std::size_t)index % count : (std::size_t)math::random_in_range(0.0f, (float)count), count - 1);
|
index >= 0 ? (std::size_t)index % count : (std::size_t)random_in_range(0.0f, (float)count), count - 1);
|
||||||
auto soundId = trigger.soundIds[soundIndex];
|
auto soundId = trigger.soundIds[soundIndex];
|
||||||
const resource::AudioData* sound{};
|
const AudioData* sound{};
|
||||||
if (source == &model) sound = sound_get(soundId);
|
if (source == &model) sound = sound_get(soundId);
|
||||||
for (const auto& [path, library] : libraries)
|
for (const auto& [path, library] : libraries)
|
||||||
if (&library.model == source)
|
if (&library.model == source)
|
||||||
@@ -607,9 +599,9 @@ namespace anm2ed
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Document::sound_set(int id, resource::AudioData data) { sounds[id] = assets.audio_add(std::move(data)); }
|
void Document::sound_set(int id, AudioData data) { sounds[id] = assets.audio_add(std::move(data)); }
|
||||||
|
|
||||||
resource::Shader* Document::shader_get(int shaderId)
|
ShaderProgram* Document::shader_get(int shaderId)
|
||||||
{
|
{
|
||||||
auto it = shaders.find(shaderId);
|
auto it = shaders.find(shaderId);
|
||||||
return it == shaders.end() || !it->second.is_valid() ? nullptr : &it->second;
|
return it == shaders.end() || !it->second.is_valid() ? nullptr : &it->second;
|
||||||
@@ -618,13 +610,13 @@ namespace anm2ed
|
|||||||
bool Document::regions_trim(int spritesheetId, const std::set<int>& ids)
|
bool Document::regions_trim(int spritesheetId, const std::set<int>& ids)
|
||||||
{
|
{
|
||||||
auto texture = texture_get(spritesheetId);
|
auto texture = texture_get(spritesheetId);
|
||||||
return texture && edit::regions_trim(model, spritesheetId, ids, *texture);
|
return texture && ::regions_trim(model, spritesheetId, ids, *texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Document::spritesheet_pack(int id, int padding)
|
bool Document::spritesheet_pack(int id, int padding)
|
||||||
{
|
{
|
||||||
auto texture = texture_get(id);
|
auto texture = texture_get(id);
|
||||||
auto packed = texture ? edit::spritesheet_pack(model, id, *texture, padding) : std::nullopt;
|
auto packed = texture ? ::spritesheet_pack(model, id, *texture, padding) : std::nullopt;
|
||||||
if (!packed) return false;
|
if (!packed) return false;
|
||||||
texture_set(id, std::move(*packed));
|
texture_set(id, std::move(*packed));
|
||||||
assets_sync();
|
assets_sync();
|
||||||
@@ -634,25 +626,25 @@ namespace anm2ed
|
|||||||
bool Document::spritesheets_merge(const std::set<int>& ids, bool isAppendRight, bool isMakeRegions,
|
bool Document::spritesheets_merge(const std::set<int>& ids, bool isAppendRight, bool isMakeRegions,
|
||||||
bool isMakePrimaryRegion, Origin origin)
|
bool isMakePrimaryRegion, Origin origin)
|
||||||
{
|
{
|
||||||
auto merged = edit::spritesheets_merge(
|
auto merged = ::spritesheets_merge(
|
||||||
model, ids, [this](int id) { return texture_get(id); }, isAppendRight, isMakeRegions, isMakePrimaryRegion,
|
model, ids, [this](int id) { return texture_get(id); }, isAppendRight, isMakeRegions, isMakePrimaryRegion,
|
||||||
origin);
|
origin);
|
||||||
if (!merged) return false;
|
if (!merged) return false;
|
||||||
texture_set(*ids.begin(), std::move(*merged));
|
texture_set(*ids.begin(), std::move(*merged));
|
||||||
// The merged sheet may now be an SVG (or a PNG) under a new name; it is written when saved.
|
// The merged sheet may now be an SVG (or a PNG) under a new name; it is written when saved.
|
||||||
texturePaths[*ids.begin()] = model::item_get(model.content.spritesheets, *ids.begin())->path;
|
texturePaths[*ids.begin()] = item_get(model.content.spritesheets, *ids.begin())->path;
|
||||||
for (auto id : ids)
|
for (auto id : ids)
|
||||||
if (id != *ids.begin()) textures.erase(id);
|
if (id != *ids.begin()) textures.erase(id);
|
||||||
assets_sync();
|
assets_sync();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Document::hash_set() { hash = model::model_hash(model); }
|
void Document::hash_set() { hash = model_hash(model); }
|
||||||
|
|
||||||
void Document::clean()
|
void Document::clean()
|
||||||
{
|
{
|
||||||
assets_sync();
|
assets_sync();
|
||||||
saveHash = model::model_hash(model);
|
saveHash = model_hash(model);
|
||||||
hash = saveHash;
|
hash = saveHash;
|
||||||
lastAutosaveTime = 0.0f;
|
lastAutosaveTime = 0.0f;
|
||||||
isForceDirty = false;
|
isForceDirty = false;
|
||||||
@@ -664,7 +656,7 @@ namespace anm2ed
|
|||||||
for (auto& spritesheet : model.content.spritesheets)
|
for (auto& spritesheet : model.content.spritesheets)
|
||||||
{
|
{
|
||||||
validIds.insert(spritesheet.id);
|
validIds.insert(spritesheet.id);
|
||||||
auto currentHash = document::spritesheet_hash_get(
|
auto currentHash = spritesheet_hash_get(
|
||||||
spritesheet, textures.contains(spritesheet.id) ? textures.at(spritesheet.id) : 0);
|
spritesheet, textures.contains(spritesheet.id) ? textures.at(spritesheet.id) : 0);
|
||||||
spritesheetHashes[spritesheet.id] = currentHash;
|
spritesheetHashes[spritesheet.id] = currentHash;
|
||||||
spritesheetSaveHashes.try_emplace(spritesheet.id, currentHash);
|
spritesheetSaveHashes.try_emplace(spritesheet.id, currentHash);
|
||||||
@@ -685,12 +677,12 @@ namespace anm2ed
|
|||||||
|
|
||||||
spritesheet_hashes_sync();
|
spritesheet_hashes_sync();
|
||||||
snapshots.commit();
|
snapshots.commit();
|
||||||
index = model::UidIndex(model);
|
index = UidIndex(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Document::edit_begin(StringType label) { snapshots.push(localize.get(label)); }
|
void Document::edit_begin(StringType label) { snapshots.push(localize.get(label)); }
|
||||||
|
|
||||||
edit::Uids Document::edit_run(StringType label, const std::function<edit::Uids(model::Model&)>& operation)
|
Uids Document::edit_run(StringType label, const std::function<Uids(Model&)>& operation)
|
||||||
{
|
{
|
||||||
edit_begin(label);
|
edit_begin(label);
|
||||||
auto uids = operation(model);
|
auto uids = operation(model);
|
||||||
@@ -698,9 +690,9 @@ namespace anm2ed
|
|||||||
return uids;
|
return uids;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Reference> Document::references_get(const edit::Uids& uids) const
|
std::vector<Reference> Document::references_get(const Uids& uids) const
|
||||||
{
|
{
|
||||||
model::UidIndex index(model);
|
UidIndex index(model);
|
||||||
std::vector<Reference> references{};
|
std::vector<Reference> references{};
|
||||||
for (auto uid : uids)
|
for (auto uid : uids)
|
||||||
if (auto reference = index.reference_get(uid)) references.push_back(*reference);
|
if (auto reference = index.reference_get(uid)) references.push_back(*reference);
|
||||||
@@ -711,11 +703,11 @@ namespace anm2ed
|
|||||||
bool Document::is_autosave_dirty() { return hash != autosaveHash || !spritesheets_autosave_dirty_get().empty(); }
|
bool Document::is_autosave_dirty() { return hash != autosaveHash || !spritesheets_autosave_dirty_get().empty(); }
|
||||||
|
|
||||||
// Edited spritesheets are autosaved as a hidden copy beside their file: .<name>.png.autosave.
|
// Edited spritesheets are autosaved as a hidden copy beside their file: .<name>.png.autosave.
|
||||||
std::filesystem::path Document::spritesheet_autosave_path_get(const model::Spritesheet& spritesheet)
|
std::filesystem::path Document::spritesheet_autosave_path_get(const Spritesheet& spritesheet)
|
||||||
{
|
{
|
||||||
auto path = directory_get() / spritesheet.path;
|
auto path = directory_get() / spritesheet.path;
|
||||||
return path.parent_path() /
|
return path.parent_path() /
|
||||||
path::from_utf8("." + path::to_utf8(path.filename()) + std::string(document::AUTOSAVE_EXTENSION));
|
path_from_utf8("." + path_to_utf8(path.filename()) + std::string(AUTOSAVE_EXTENSION));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Spritesheets with unsaved pixel edits that their autosave copy doesn't have yet.
|
// Spritesheets with unsaved pixel edits that their autosave copy doesn't have yet.
|
||||||
@@ -739,8 +731,8 @@ namespace anm2ed
|
|||||||
for (const auto& spritesheet : model.content.spritesheets)
|
for (const auto& spritesheet : model.content.spritesheets)
|
||||||
{
|
{
|
||||||
auto path = spritesheet_autosave_path_get(spritesheet);
|
auto path = spritesheet_autosave_path_get(spritesheet);
|
||||||
if (!path::is_exist(path)) continue;
|
if (!is_path_exist(path)) continue;
|
||||||
if (auto image = resource::Image(path); image.is_valid()) texture_set(spritesheet.id, std::move(image));
|
if (auto image = Image(path); image.is_valid()) texture_set(spritesheet.id, std::move(image));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -754,10 +746,10 @@ namespace anm2ed
|
|||||||
|
|
||||||
void Document::spritesheet_hash_update(int id)
|
void Document::spritesheet_hash_update(int id)
|
||||||
{
|
{
|
||||||
auto spritesheet = model::item_get(model.content.spritesheets, id);
|
auto spritesheet = item_get(model.content.spritesheets, id);
|
||||||
if (!spritesheet) return;
|
if (!spritesheet) return;
|
||||||
assets_sync();
|
assets_sync();
|
||||||
spritesheetHashes[id] = document::spritesheet_hash_get(*spritesheet, textures.contains(id) ? textures.at(id) : 0);
|
spritesheetHashes[id] = spritesheet_hash_get(*spritesheet, textures.contains(id) ? textures.at(id) : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The spritesheet matches its file (just saved or reloaded); its file's time is remembered to notice later changes.
|
// The spritesheet matches its file (just saved or reloaded); its file's time is remembered to notice later changes.
|
||||||
@@ -767,7 +759,7 @@ namespace anm2ed
|
|||||||
if (spritesheetHashes.contains(id)) spritesheetSaveHashes[id] = spritesheetHashes[id];
|
if (spritesheetHashes.contains(id)) spritesheetSaveHashes[id] = spritesheetHashes[id];
|
||||||
textureWriteTimes.erase(id);
|
textureWriteTimes.erase(id);
|
||||||
spritesheets_changed_get();
|
spritesheets_changed_get();
|
||||||
if (auto spritesheet = model::item_get(model.content.spritesheets, id))
|
if (auto spritesheet = item_get(model.content.spritesheets, id))
|
||||||
{
|
{
|
||||||
std::error_code ec{};
|
std::error_code ec{};
|
||||||
std::filesystem::remove(spritesheet_autosave_path_get(*spritesheet), ec);
|
std::filesystem::remove(spritesheet_autosave_path_get(*spritesheet), ec);
|
||||||
@@ -779,11 +771,11 @@ namespace anm2ed
|
|||||||
std::set<int> Document::spritesheets_changed_get()
|
std::set<int> Document::spritesheets_changed_get()
|
||||||
{
|
{
|
||||||
std::set<int> ids{};
|
std::set<int> ids{};
|
||||||
util::WorkingDirectory workingDirectory(directory_get());
|
WorkingDirectory workingDirectory(directory_get());
|
||||||
for (const auto& spritesheet : model.content.spritesheets)
|
for (const auto& spritesheet : model.content.spritesheets)
|
||||||
{
|
{
|
||||||
std::error_code ec{};
|
std::error_code ec{};
|
||||||
auto time = std::filesystem::last_write_time(path::case_insensitive_find(spritesheet.path), ec);
|
auto time = std::filesystem::last_write_time(path_case_insensitive_find(spritesheet.path), ec);
|
||||||
if (ec) continue;
|
if (ec) continue;
|
||||||
auto [it, isNew] = textureWriteTimes.try_emplace(spritesheet.id, time);
|
auto [it, isNew] = textureWriteTimes.try_emplace(spritesheet.id, time);
|
||||||
if (!isNew && it->second != time && !spritesheet_is_dirty(spritesheet.id)) ids.insert(spritesheet.id);
|
if (!isNew && it->second != time && !spritesheet_is_dirty(spritesheet.id)) ids.insert(spritesheet.id);
|
||||||
@@ -795,16 +787,16 @@ namespace anm2ed
|
|||||||
void Document::spritesheets_reload(const std::set<int>& ids)
|
void Document::spritesheets_reload(const std::set<int>& ids)
|
||||||
{
|
{
|
||||||
edit_apply(EDIT_RELOAD_SPRITESHEETS,
|
edit_apply(EDIT_RELOAD_SPRITESHEETS,
|
||||||
[&](model::Model&)
|
[&](Model&)
|
||||||
{
|
{
|
||||||
for (auto id : ids)
|
for (auto id : ids)
|
||||||
texture_reload(id);
|
texture_reload(id);
|
||||||
});
|
});
|
||||||
for (auto id : ids)
|
for (auto id : ids)
|
||||||
if (auto spritesheet = model::item_get(model.content.spritesheets, id))
|
if (auto spritesheet = item_get(model.content.spritesheets, id))
|
||||||
{
|
{
|
||||||
spritesheet_hash_set_saved(id);
|
spritesheet_hash_set_saved(id);
|
||||||
toast_log(Level::INFO, TOAST_RELOAD_SPRITESHEET, id, path::to_utf8(spritesheet->path));
|
toast_log(Level::INFO, TOAST_RELOAD_SPRITESHEET, id, path_to_utf8(spritesheet->path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -813,16 +805,16 @@ namespace anm2ed
|
|||||||
{
|
{
|
||||||
std::set<int> converted{};
|
std::set<int> converted{};
|
||||||
edit_apply(EDIT_CONVERT_SVG_SPRITESHEETS,
|
edit_apply(EDIT_CONVERT_SVG_SPRITESHEETS,
|
||||||
[&](model::Model& model)
|
[&](Model& model)
|
||||||
{
|
{
|
||||||
for (auto id : ids)
|
for (auto id : ids)
|
||||||
{
|
{
|
||||||
auto spritesheet = model::item_get(model.content.spritesheets, id);
|
auto spritesheet = item_get(model.content.spritesheets, id);
|
||||||
auto texture = texture_get(id);
|
auto texture = texture_get(id);
|
||||||
if (!spritesheet || !texture || !texture->is_vector()) continue;
|
if (!spritesheet || !texture || !texture->is_vector()) continue;
|
||||||
auto pngPath =
|
auto pngPath =
|
||||||
std::filesystem::path(spritesheet->path).replace_extension(resource::image::PNG_EXTENSION);
|
std::filesystem::path(spritesheet->path).replace_extension(PNG_EXTENSION);
|
||||||
auto pathString = path::to_utf8(pngPath);
|
auto pathString = path_to_utf8(pngPath);
|
||||||
if (!texture->write_png(std::filesystem::absolute(directory_get()) / pngPath))
|
if (!texture->write_png(std::filesystem::absolute(directory_get()) / pngPath))
|
||||||
{
|
{
|
||||||
toast_log(Level::ERROR, TOAST_SAVE_SPRITESHEET_FAILED, id, pathString);
|
toast_log(Level::ERROR, TOAST_SAVE_SPRITESHEET_FAILED, id, pathString);
|
||||||
@@ -840,7 +832,7 @@ namespace anm2ed
|
|||||||
|
|
||||||
bool Document::spritesheet_is_dirty(int id)
|
bool Document::spritesheet_is_dirty(int id)
|
||||||
{
|
{
|
||||||
if (!model::item_get(model.content.spritesheets, id)) return false;
|
if (!item_get(model.content.spritesheets, id)) return false;
|
||||||
if (!spritesheetHashes.contains(id)) spritesheet_hash_update(id);
|
if (!spritesheetHashes.contains(id)) spritesheet_hash_update(id);
|
||||||
auto saveIt = spritesheetSaveHashes.find(id);
|
auto saveIt = spritesheetSaveHashes.find(id);
|
||||||
return saveIt != spritesheetSaveHashes.end() && spritesheetHashes.at(id) != saveIt->second;
|
return saveIt != spritesheetSaveHashes.end() && spritesheetHashes.at(id) != saveIt->second;
|
||||||
@@ -848,7 +840,7 @@ namespace anm2ed
|
|||||||
|
|
||||||
bool Document::spritesheet_any_dirty()
|
bool Document::spritesheet_any_dirty()
|
||||||
{
|
{
|
||||||
return std::ranges::any_of(model.content.spritesheets, [&](const model::Spritesheet& spritesheet)
|
return std::ranges::any_of(model.content.spritesheets, [&](const Spritesheet& spritesheet)
|
||||||
{ return spritesheet_is_dirty(spritesheet.id); });
|
{ return spritesheet_is_dirty(spritesheet.id); });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -917,7 +909,7 @@ namespace anm2ed
|
|||||||
{
|
{
|
||||||
return [format](const auto& item)
|
return [format](const auto& item)
|
||||||
{
|
{
|
||||||
auto pathString = path::to_utf8(item.path);
|
auto pathString = path_to_utf8(item.path);
|
||||||
return std::vformat(localize.get(format), std::make_format_args(item.id, pathString));
|
return std::vformat(localize.get(format), std::make_format_args(item.id, pathString));
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -933,7 +925,7 @@ namespace anm2ed
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Selects the frames an edit returned and moves the playhead to the first.
|
// Selects the frames an edit returned and moves the playhead to the first.
|
||||||
void Document::frames_select(const edit::Uids& uids)
|
void Document::frames_select(const Uids& uids)
|
||||||
{
|
{
|
||||||
auto references = references_get(uids);
|
auto references = references_get(uids);
|
||||||
if (references.empty()) return;
|
if (references.empty()) return;
|
||||||
@@ -942,7 +934,7 @@ namespace anm2ed
|
|||||||
frame_references_set({references.begin(), references.end()});
|
frame_references_set({references.begin(), references.end()});
|
||||||
reference_set(focus);
|
reference_set(focus);
|
||||||
if (auto item = model.track_get(focus); item && focus.itemType != TRIGGER)
|
if (auto item = model.track_get(focus); item && focus.itemType != TRIGGER)
|
||||||
frameTime = model::frame_time_from_index_get(*item, focus.frameIndex);
|
frameTime = frame_time_from_index_get(*item, focus.frameIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Document::frame_select(Reference frameReference)
|
void Document::frame_select(Reference frameReference)
|
||||||
@@ -971,12 +963,12 @@ namespace anm2ed
|
|||||||
{
|
{
|
||||||
selection.uids[SelectionKind::GROUPS].clear();
|
selection.uids[SelectionKind::GROUPS].clear();
|
||||||
editTarget = EditTarget::FRAME;
|
editTarget = EditTarget::FRAME;
|
||||||
if (document::item_reference_get(firstReference) != document::item_reference_get(lastReference) ||
|
if (item_reference_get(firstReference) != item_reference_get(lastReference) ||
|
||||||
firstReference.frameIndex < 0 || lastReference.frameIndex < 0)
|
firstReference.frameIndex < 0 || lastReference.frameIndex < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
auto item = model.track_get(lastReference);
|
auto item = model.track_get(lastReference);
|
||||||
if (!item || std::max(firstReference.frameIndex, lastReference.frameIndex) >= model::track_frames_count_get(*item))
|
if (!item || std::max(firstReference.frameIndex, lastReference.frameIndex) >= track_frames_count_get(*item))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
auto [firstIndex, lastIndex] = std::minmax(firstReference.frameIndex, lastReference.frameIndex);
|
auto [firstIndex, lastIndex] = std::minmax(firstReference.frameIndex, lastReference.frameIndex);
|
||||||
@@ -1013,7 +1005,7 @@ namespace anm2ed
|
|||||||
{
|
{
|
||||||
itemReference.frameIndex = -1;
|
itemReference.frameIndex = -1;
|
||||||
if (itemReference.itemType == LAYER)
|
if (itemReference.itemType == LAYER)
|
||||||
if (auto layer = model::item_get(model.content.layers, itemReference.itemID))
|
if (auto layer = item_get(model.content.layers, itemReference.itemID))
|
||||||
focused_id_set(SelectionKind::SPRITESHEETS, layer->spritesheetId);
|
focused_id_set(SelectionKind::SPRITESHEETS, layer->spritesheetId);
|
||||||
reference_set(itemReference);
|
reference_set(itemReference);
|
||||||
frame_references_clear();
|
frame_references_clear();
|
||||||
@@ -1053,7 +1045,7 @@ namespace anm2ed
|
|||||||
{
|
{
|
||||||
auto selectedItems = selected_get(SelectionKind::TRACKS);
|
auto selectedItems = selected_get(SelectionKind::TRACKS);
|
||||||
if (auto reference = reference_get(); selectedItems.empty() && reference.itemType != NONE)
|
if (auto reference = reference_get(); selectedItems.empty() && reference.itemType != NONE)
|
||||||
selectedItems.insert(document::item_reference_get(reference));
|
selectedItems.insert(item_reference_get(reference));
|
||||||
|
|
||||||
std::set<Reference> result{};
|
std::set<Reference> result{};
|
||||||
for (auto itemReference : selectedItems)
|
for (auto itemReference : selectedItems)
|
||||||
@@ -1076,7 +1068,7 @@ namespace anm2ed
|
|||||||
std::erase_if(frameReferences, [&](const Reference& frame) { return !model.frame_get(frame); });
|
std::erase_if(frameReferences, [&](const Reference& frame) { return !model.frame_get(frame); });
|
||||||
std::set<Reference> tracks{};
|
std::set<Reference> tracks{};
|
||||||
for (auto frame : frameReferences)
|
for (auto frame : frameReferences)
|
||||||
tracks.insert(document::item_reference_get(frame));
|
tracks.insert(item_reference_get(frame));
|
||||||
selected_set(SelectionKind::FRAMES, frameReferences);
|
selected_set(SelectionKind::FRAMES, frameReferences);
|
||||||
selected_set(SelectionKind::TRACKS, tracks);
|
selected_set(SelectionKind::TRACKS, tracks);
|
||||||
if (!frameReferences.empty() && !frameReferences.contains(reference_get())) reference_set(*frameReferences.begin());
|
if (!frameReferences.empty() && !frameReferences.contains(reference_get())) reference_set(*frameReferences.begin());
|
||||||
@@ -1094,7 +1086,7 @@ namespace anm2ed
|
|||||||
auto reference = reference_get();
|
auto reference = reference_get();
|
||||||
std::set<Reference> selectedReferences = selected_get(SelectionKind::TRACKS);
|
std::set<Reference> selectedReferences = selected_get(SelectionKind::TRACKS);
|
||||||
if (selectedReferences.empty() && reference.itemType != NONE)
|
if (selectedReferences.empty() && reference.itemType != NONE)
|
||||||
selectedReferences.insert(document::item_reference_get(reference));
|
selectedReferences.insert(item_reference_get(reference));
|
||||||
|
|
||||||
std::vector<Reference> result{};
|
std::vector<Reference> result{};
|
||||||
for (auto itemReference : selectedReferences)
|
for (auto itemReference : selectedReferences)
|
||||||
@@ -1110,19 +1102,19 @@ namespace anm2ed
|
|||||||
auto& items = model.content.spritesheets;
|
auto& items = model.content.spritesheets;
|
||||||
auto directory = directory_get();
|
auto directory = directory_get();
|
||||||
|
|
||||||
std::vector<std::pair<std::filesystem::path, resource::Image>> loaded{};
|
std::vector<std::pair<std::filesystem::path, Image>> loaded{};
|
||||||
for (auto& path : paths)
|
for (auto& path : paths)
|
||||||
{
|
{
|
||||||
auto storagePath = path::backslash_handle(path);
|
auto storagePath = path_backslash_handle(path);
|
||||||
std::optional<WorkingDirectory> workingDirectory{};
|
std::optional<WorkingDirectory> workingDirectory{};
|
||||||
if (!storagePath.is_absolute()) workingDirectory.emplace(directory);
|
if (!storagePath.is_absolute()) workingDirectory.emplace(directory);
|
||||||
auto texture = resource::Image(path::case_insensitive_find(storagePath));
|
auto texture = Image(path_case_insensitive_find(storagePath));
|
||||||
if (!texture.is_valid())
|
if (!texture.is_valid())
|
||||||
{
|
{
|
||||||
toast_log(Level::ERROR, TOAST_SPRITESHEET_INIT_FAILED, path::to_utf8(path));
|
toast_log(Level::ERROR, TOAST_SPRITESHEET_INIT_FAILED, path_to_utf8(path));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
loaded.emplace_back(path::backslash_replace(path::make_relative(storagePath, directory)), std::move(texture));
|
loaded.emplace_back(path_backslash_replace(path_make_relative(storagePath, directory)), std::move(texture));
|
||||||
}
|
}
|
||||||
if (loaded.empty()) return;
|
if (loaded.empty()) return;
|
||||||
|
|
||||||
@@ -1132,12 +1124,12 @@ namespace anm2ed
|
|||||||
for (auto& [relativePath, texture] : loaded)
|
for (auto& [relativePath, texture] : loaded)
|
||||||
{
|
{
|
||||||
auto& element =
|
auto& element =
|
||||||
items.emplace_back(model::Spritesheet{.id = model::item_next_id_get(items), .path = relativePath});
|
items.emplace_back(Spritesheet{.id = item_next_id_get(items), .path = relativePath});
|
||||||
texture_set(element.id, std::move(texture));
|
texture_set(element.id, std::move(texture));
|
||||||
texturePaths[element.id] = element.path;
|
texturePaths[element.id] = element.path;
|
||||||
added.insert(element.id);
|
added.insert(element.id);
|
||||||
spritesheet_hash_set_saved(element.id);
|
spritesheet_hash_set_saved(element.id);
|
||||||
toast_log(Level::INFO, TOAST_SPRITESHEET_INITIALIZED, element.id, path::to_utf8(element.path));
|
toast_log(Level::INFO, TOAST_SPRITESHEET_INITIALIZED, element.id, path_to_utf8(element.path));
|
||||||
}
|
}
|
||||||
selected_ids_set(SelectionKind::SPRITESHEETS, added);
|
selected_ids_set(SelectionKind::SPRITESHEETS, added);
|
||||||
focused_id_set(SelectionKind::SPRITESHEETS, *added.rbegin());
|
focused_id_set(SelectionKind::SPRITESHEETS, *added.rbegin());
|
||||||
@@ -1155,14 +1147,14 @@ namespace anm2ed
|
|||||||
for (auto& path : paths)
|
for (auto& path : paths)
|
||||||
{
|
{
|
||||||
if (path.empty()) continue;
|
if (path.empty()) continue;
|
||||||
auto& element = items.emplace_back(model::Sound{
|
auto& element = items.emplace_back(Sound{
|
||||||
.id = model::item_next_id_get(items),
|
.id = item_next_id_get(items),
|
||||||
.path = path::backslash_replace(path::make_relative(path::backslash_handle(path), directory_get()))});
|
.path = path_backslash_replace(path_make_relative(path_backslash_handle(path), directory_get()))});
|
||||||
WorkingDirectory workingDirectory(directory_get());
|
WorkingDirectory workingDirectory(directory_get());
|
||||||
sound_set(element.id, resource::AudioData(path::case_insensitive_find(element.path)));
|
sound_set(element.id, AudioData(path_case_insensitive_find(element.path)));
|
||||||
soundPaths[element.id] = element.path;
|
soundPaths[element.id] = element.path;
|
||||||
added.insert(element.id);
|
added.insert(element.id);
|
||||||
toast_log(Level::INFO, TOAST_SOUND_INITIALIZED, element.id, path::to_utf8(element.path));
|
toast_log(Level::INFO, TOAST_SOUND_INITIALIZED, element.id, path_to_utf8(element.path));
|
||||||
}
|
}
|
||||||
selected_ids_set(SelectionKind::SOUNDS, added);
|
selected_ids_set(SelectionKind::SOUNDS, added);
|
||||||
focused_id_set(SelectionKind::SOUNDS, *added.rbegin());
|
focused_id_set(SelectionKind::SOUNDS, *added.rbegin());
|
||||||
@@ -1174,22 +1166,22 @@ namespace anm2ed
|
|||||||
std::set<int> added{};
|
std::set<int> added{};
|
||||||
edit_apply(
|
edit_apply(
|
||||||
EDIT_ADD_LIBRARY,
|
EDIT_ADD_LIBRARY,
|
||||||
[&](model::Model& model)
|
[&](Model& model)
|
||||||
{
|
{
|
||||||
auto& libraries = model.content.libraries;
|
auto& libraries = model.content.libraries;
|
||||||
for (auto& path : paths)
|
for (auto& path : paths)
|
||||||
if (!path.empty())
|
if (!path.empty())
|
||||||
{
|
{
|
||||||
auto& library = libraries.emplace_back(model::Library{
|
auto& library = libraries.emplace_back(Library{
|
||||||
.id = model::item_next_id_get(libraries),
|
.id = item_next_id_get(libraries),
|
||||||
.path = path::backslash_replace(path::make_relative(path::backslash_handle(path), directory_get()))});
|
.path = path_backslash_replace(path_make_relative(path_backslash_handle(path), directory_get()))});
|
||||||
added.insert(library.id);
|
added.insert(library.id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (added.empty()) return;
|
if (added.empty()) return;
|
||||||
for (auto id : added)
|
for (auto id : added)
|
||||||
toast_log(Level::INFO, TOAST_LIBRARY_INITIALIZED, id,
|
toast_log(Level::INFO, TOAST_LIBRARY_INITIALIZED, id,
|
||||||
path::to_utf8(model::item_get(model.content.libraries, id)->path));
|
path_to_utf8(item_get(model.content.libraries, id)->path));
|
||||||
selected_ids_set(SelectionKind::LIBRARIES, added);
|
selected_ids_set(SelectionKind::LIBRARIES, added);
|
||||||
focused_id_set(SelectionKind::LIBRARIES, *added.rbegin());
|
focused_id_set(SelectionKind::LIBRARIES, *added.rbegin());
|
||||||
}
|
}
|
||||||
@@ -1197,7 +1189,7 @@ namespace anm2ed
|
|||||||
void Document::undo()
|
void Document::undo()
|
||||||
{
|
{
|
||||||
if (!snapshots.undo()) return;
|
if (!snapshots.undo()) return;
|
||||||
document::frame_time_sync(*this);
|
frame_time_sync(*this);
|
||||||
toast_log(Level::INFO, TOAST_UNDO, message);
|
toast_log(Level::INFO, TOAST_UNDO, message);
|
||||||
change();
|
change();
|
||||||
}
|
}
|
||||||
@@ -1205,11 +1197,10 @@ namespace anm2ed
|
|||||||
void Document::redo()
|
void Document::redo()
|
||||||
{
|
{
|
||||||
if (!snapshots.redo()) return;
|
if (!snapshots.redo()) return;
|
||||||
document::frame_time_sync(*this);
|
frame_time_sync(*this);
|
||||||
toast_log(Level::INFO, TOAST_REDO, message);
|
toast_log(Level::INFO, TOAST_REDO, message);
|
||||||
change();
|
change();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Document::is_able_to_undo() { return !snapshots.undoStack.is_empty(); }
|
bool Document::is_able_to_undo() { return !snapshots.undoStack.is_empty(); }
|
||||||
bool Document::is_able_to_redo() { return !snapshots.redoStack.is_empty(); }
|
bool Document::is_able_to_redo() { return !snapshots.redoStack.is_empty(); }
|
||||||
}
|
|
||||||
+30
-33
@@ -20,8 +20,6 @@
|
|||||||
|
|
||||||
#include "shader.h"
|
#include "shader.h"
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
class Manager;
|
class Manager;
|
||||||
struct Command;
|
struct Command;
|
||||||
|
|
||||||
@@ -35,9 +33,9 @@ namespace anm2ed
|
|||||||
// A linked .anm2, loaded read-only: its document, its spritesheets' images and its sounds.
|
// A linked .anm2, loaded read-only: its document, its spritesheets' images and its sounds.
|
||||||
struct LibraryData
|
struct LibraryData
|
||||||
{
|
{
|
||||||
model::Model model{};
|
Model model{};
|
||||||
std::map<int, resource::Image> images{};
|
std::map<int, Image> images{};
|
||||||
std::map<int, resource::AudioData> sounds{};
|
std::map<int, AudioData> sounds{};
|
||||||
std::filesystem::file_time_type writeTime{};
|
std::filesystem::file_time_type writeTime{};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -59,8 +57,8 @@ namespace anm2ed
|
|||||||
std::filesystem::path path{};
|
std::filesystem::path path{};
|
||||||
uint64_t tabId{};
|
uint64_t tabId{};
|
||||||
Snapshots snapshots{};
|
Snapshots snapshots{};
|
||||||
resource::AssetStore assets{};
|
AssetStore assets{};
|
||||||
std::map<int, resource::Image> textureDrafts{};
|
std::map<int, Image> textureDrafts{};
|
||||||
int changeAllFramePropertiesRegionId{-1};
|
int changeAllFramePropertiesRegionId{-1};
|
||||||
int changeAllFramePropertiesShaderId{-1};
|
int changeAllFramePropertiesShaderId{-1};
|
||||||
|
|
||||||
@@ -89,13 +87,13 @@ namespace anm2ed
|
|||||||
std::unordered_map<int, std::filesystem::path> soundPaths{};
|
std::unordered_map<int, std::filesystem::path> soundPaths{};
|
||||||
std::map<int, std::filesystem::path> shaderVertexPaths{};
|
std::map<int, std::filesystem::path> shaderVertexPaths{};
|
||||||
std::map<int, std::filesystem::path> shaderFragmentPaths{};
|
std::map<int, std::filesystem::path> shaderFragmentPaths{};
|
||||||
std::map<int, resource::Shader> shaders{};
|
std::map<int, ShaderProgram> shaders{};
|
||||||
// Libraries by absolute path, and what each (document, library id) points at (nullptr is this document).
|
// Libraries by absolute path, and what each (document, library id) points at (nullptr is this document).
|
||||||
std::map<std::filesystem::path, LibraryData> libraries{};
|
std::map<std::filesystem::path, LibraryData> libraries{};
|
||||||
std::map<std::pair<const model::Model*, int>, const LibraryData*> libraryLinks{};
|
std::map<std::pair<const Model*, int>, const LibraryData*> libraryLinks{};
|
||||||
std::uint64_t librariesRevision{}; // counts library loads, for anything drawn from them
|
std::uint64_t librariesRevision{}; // counts library loads, for anything drawn from them
|
||||||
// Vector spritesheets drawn again for zooms past 100%, by (image uid, power-of-two level).
|
// Vector spritesheets drawn again for zooms past 100%, by (image uid, power-of-two level).
|
||||||
mutable std::map<std::pair<std::uint64_t, int>, resource::Image> vectorImages{};
|
mutable std::map<std::pair<std::uint64_t, int>, Image> vectorImages{};
|
||||||
bool isAnimationPreviewSet{false};
|
bool isAnimationPreviewSet{false};
|
||||||
bool isSpritesheetEditorSet{false};
|
bool isSpritesheetEditorSet{false};
|
||||||
};
|
};
|
||||||
@@ -123,7 +121,7 @@ namespace anm2ed
|
|||||||
#undef X
|
#undef X
|
||||||
std::string& message = current.message;
|
std::string& message = current.message;
|
||||||
EditTarget editTarget{EditTarget::NONE};
|
EditTarget editTarget{EditTarget::NONE};
|
||||||
model::UidIndex index{};
|
UidIndex index{};
|
||||||
|
|
||||||
Document(const std::filesystem::path&, bool = false, std::string* = nullptr);
|
Document(const std::filesystem::path&, bool = false, std::string* = nullptr);
|
||||||
Document(const Document&) = delete;
|
Document(const Document&) = delete;
|
||||||
@@ -137,21 +135,21 @@ namespace anm2ed
|
|||||||
bool texture_reload(int);
|
bool texture_reload(int);
|
||||||
bool sound_reload(int);
|
bool sound_reload(int);
|
||||||
bool shader_reload(int, std::string* = nullptr);
|
bool shader_reload(int, std::string* = nullptr);
|
||||||
const resource::Image* texture_get(int) const;
|
const Image* texture_get(int) const;
|
||||||
resource::Image* texture_edit(int);
|
Image* texture_edit(int);
|
||||||
void texture_set(int, resource::Image);
|
void texture_set(int, Image);
|
||||||
const resource::AudioData* sound_get(int) const;
|
const AudioData* sound_get(int) const;
|
||||||
std::vector<const resource::AudioData*> sounds_get() const;
|
std::vector<const AudioData*> sounds_get() const;
|
||||||
std::vector<const resource::AudioData*> trigger_sounds_get(const model::Animation&, int, int = -1) const;
|
std::vector<const AudioData*> trigger_sounds_get(const Animation&, int, int = -1) const;
|
||||||
void sound_set(int, resource::AudioData);
|
void sound_set(int, AudioData);
|
||||||
resource::Shader* shader_get(int);
|
ShaderProgram* shader_get(int);
|
||||||
std::filesystem::path library_path_get(int) const;
|
std::filesystem::path library_path_get(int) const;
|
||||||
const LibraryData* library_get(const model::Model&, int) const;
|
const LibraryData* library_get(const Model&, int) const;
|
||||||
model::LibraryGet library_resolver_get() const;
|
LibraryGet library_resolver_get() const;
|
||||||
edit::SpritesheetPathGet spritesheet_path_resolver_get() const;
|
SpritesheetPathGet spritesheet_path_resolver_get() const;
|
||||||
std::vector<std::string> animation_names_get(int) const;
|
std::vector<std::string> animation_names_get(int) const;
|
||||||
const resource::Image* draw_image_get(const model::Draw&, float = 1.0f) const;
|
const Image* draw_image_get(const Draw&, float = 1.0f) const;
|
||||||
const resource::Image* vector_image_get(const resource::Image*, float) const;
|
const Image* vector_image_get(const Image*, float) const;
|
||||||
void libraries_sync();
|
void libraries_sync();
|
||||||
bool libraries_reload();
|
bool libraries_reload();
|
||||||
void library_reload(int);
|
void library_reload(int);
|
||||||
@@ -162,15 +160,15 @@ namespace anm2ed
|
|||||||
void clean();
|
void clean();
|
||||||
void change();
|
void change();
|
||||||
void edit_begin(StringType);
|
void edit_begin(StringType);
|
||||||
edit::Uids edit_run(StringType, const std::function<edit::Uids(model::Model&)>&);
|
Uids edit_run(StringType, const std::function<Uids(Model&)>&);
|
||||||
|
|
||||||
// Snapshots for undo, runs the operation on the model, then commits; void operations select nothing.
|
// Snapshots for undo, runs the operation on the model, then commits; void operations select nothing.
|
||||||
template <class Operation> edit::Uids edit_apply(StringType label, Operation&& operation)
|
template <class Operation> Uids edit_apply(StringType label, Operation&& operation)
|
||||||
{
|
{
|
||||||
return edit_run(label,
|
return edit_run(label,
|
||||||
[&](model::Model& model) -> edit::Uids
|
[&](Model& model) -> Uids
|
||||||
{
|
{
|
||||||
if constexpr (std::is_void_v<std::invoke_result_t<Operation&, model::Model&>>)
|
if constexpr (std::is_void_v<std::invoke_result_t<Operation&, Model&>>)
|
||||||
{
|
{
|
||||||
operation(model);
|
operation(model);
|
||||||
return {};
|
return {};
|
||||||
@@ -179,9 +177,9 @@ namespace anm2ed
|
|||||||
return operation(model);
|
return operation(model);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
std::vector<Reference> references_get(const edit::Uids&) const;
|
std::vector<Reference> references_get(const Uids&) const;
|
||||||
bool is_dirty() const;
|
bool is_dirty() const;
|
||||||
bool is_layer_animation_missing(const model::Layer&) const;
|
bool is_layer_animation_missing(const Layer&) const;
|
||||||
bool is_autosave_dirty();
|
bool is_autosave_dirty();
|
||||||
std::filesystem::path directory_get() const;
|
std::filesystem::path directory_get() const;
|
||||||
std::filesystem::path filename_get() const;
|
std::filesystem::path filename_get() const;
|
||||||
@@ -195,7 +193,7 @@ namespace anm2ed
|
|||||||
std::set<int> spritesheets_changed_get();
|
std::set<int> spritesheets_changed_get();
|
||||||
void spritesheets_reload(const std::set<int>&);
|
void spritesheets_reload(const std::set<int>&);
|
||||||
void spritesheets_vector_convert(const std::set<int>&);
|
void spritesheets_vector_convert(const std::set<int>&);
|
||||||
std::filesystem::path spritesheet_autosave_path_get(const model::Spritesheet&);
|
std::filesystem::path spritesheet_autosave_path_get(const Spritesheet&);
|
||||||
std::set<int> spritesheets_autosave_dirty_get();
|
std::set<int> spritesheets_autosave_dirty_get();
|
||||||
void spritesheets_autosave_restore();
|
void spritesheets_autosave_restore();
|
||||||
void spritesheets_autosave_clear();
|
void spritesheets_autosave_clear();
|
||||||
@@ -209,7 +207,7 @@ namespace anm2ed
|
|||||||
void focused_id_set(SelectionKind, int);
|
void focused_id_set(SelectionKind, int);
|
||||||
void selected_clear(SelectionKind);
|
void selected_clear(SelectionKind);
|
||||||
Choices choices_get(SelectionKind, int = -1) const;
|
Choices choices_get(SelectionKind, int = -1) const;
|
||||||
void frames_select(const edit::Uids&);
|
void frames_select(const Uids&);
|
||||||
void frame_select(Reference);
|
void frame_select(Reference);
|
||||||
void frame_toggle(Reference);
|
void frame_toggle(Reference);
|
||||||
bool frames_range_select(Reference, Reference, bool);
|
bool frames_range_select(Reference, Reference, bool);
|
||||||
@@ -238,4 +236,3 @@ namespace anm2ed
|
|||||||
bool is_able_to_undo();
|
bool is_able_to_undo();
|
||||||
bool is_able_to_redo();
|
bool is_able_to_redo();
|
||||||
};
|
};
|
||||||
}
|
|
||||||
+16
-21
@@ -2,10 +2,6 @@
|
|||||||
|
|
||||||
#include "model/xml.h"
|
#include "model/xml.h"
|
||||||
|
|
||||||
using namespace anm2ed::model;
|
|
||||||
|
|
||||||
namespace anm2ed::edit
|
|
||||||
{
|
|
||||||
constexpr std::string_view ANIMATION_MERGED_SUFFIX = " (Merged)";
|
constexpr std::string_view ANIMATION_MERGED_SUFFIX = " (Merged)";
|
||||||
|
|
||||||
using AnimationPointer = std::shared_ptr<const Animation>;
|
using AnimationPointer = std::shared_ptr<const Animation>;
|
||||||
@@ -33,7 +29,7 @@ namespace anm2ed::edit
|
|||||||
std::vector<AnimationGroup> groups{};
|
std::vector<AnimationGroup> groups{};
|
||||||
};
|
};
|
||||||
|
|
||||||
AnimationsTaken animations_take(Model& model, const std::set<int>& indices, const std::set<int>& groupIds)
|
static AnimationsTaken animations_take(Model& model, const std::set<int>& indices, const std::set<int>& groupIds)
|
||||||
{
|
{
|
||||||
AnimationsTaken taken{};
|
AnimationsTaken taken{};
|
||||||
int index{};
|
int index{};
|
||||||
@@ -73,7 +69,7 @@ namespace anm2ed::edit
|
|||||||
int position{-1};
|
int position{-1};
|
||||||
};
|
};
|
||||||
|
|
||||||
AnimationPlace animation_place_get(Model& model, std::uint64_t uid)
|
static AnimationPlace animation_place_get(Model& model, std::uint64_t uid)
|
||||||
{
|
{
|
||||||
auto& entries = model.animations.entries;
|
auto& entries = model.animations.entries;
|
||||||
for (int i = 0; i < (int)entries.size(); ++i)
|
for (int i = 0; i < (int)entries.size(); ++i)
|
||||||
@@ -90,7 +86,7 @@ namespace anm2ed::edit
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
int animation_group_entry_get(const Model& model, int groupId)
|
static int animation_group_entry_get(const Model& model, int groupId)
|
||||||
{
|
{
|
||||||
auto& entries = model.animations.entries;
|
auto& entries = model.animations.entries;
|
||||||
for (int i = 0; i < (int)entries.size(); ++i)
|
for (int i = 0; i < (int)entries.size(); ++i)
|
||||||
@@ -98,14 +94,14 @@ namespace anm2ed::edit
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
AnimationGroup* animation_group_find(Model& model, int groupId)
|
static AnimationGroup* animation_group_find(Model& model, int groupId)
|
||||||
{
|
{
|
||||||
auto entry = animation_group_entry_get(model, groupId);
|
auto entry = animation_group_entry_get(model, groupId);
|
||||||
return entry == -1 ? nullptr : &std::get<AnimationGroup>(model.animations.entries[entry]);
|
return entry == -1 ? nullptr : &std::get<AnimationGroup>(model.animations.entries[entry]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inserts animations before the animation at a flat index (or at the end), inside `groupId` when given.
|
// Inserts animations before the animation at a flat index (or at the end), inside `groupId` when given.
|
||||||
void animations_insert(Model& model, int index, int groupId, std::vector<AnimationPointer> animations)
|
static void animations_insert(Model& model, int index, int groupId, std::vector<AnimationPointer> animations)
|
||||||
{
|
{
|
||||||
auto before = model.animation_get(index);
|
auto before = model.animation_get(index);
|
||||||
auto place = before ? animation_place_get(model, before->uid) : AnimationPlace{};
|
auto place = before ? animation_place_get(model, before->uid) : AnimationPlace{};
|
||||||
@@ -135,7 +131,7 @@ namespace anm2ed::edit
|
|||||||
}
|
}
|
||||||
|
|
||||||
// An empty copy of a track list: same tracks and groups, no frames.
|
// An empty copy of a track list: same tracks and groups, no frames.
|
||||||
std::vector<TrackEntry> track_entries_shell_get(const std::vector<TrackEntry>& entries)
|
static std::vector<TrackEntry> track_entries_shell_get(const std::vector<TrackEntry>& entries)
|
||||||
{
|
{
|
||||||
std::vector<TrackEntry> shell{};
|
std::vector<TrackEntry> shell{};
|
||||||
auto track_shell_get = [](const Track& track)
|
auto track_shell_get = [](const Track& track)
|
||||||
@@ -287,20 +283,20 @@ namespace anm2ed::edit
|
|||||||
return uids;
|
return uids;
|
||||||
}
|
}
|
||||||
|
|
||||||
void track_merge(Track& destination, const Track& source, types::merge::Type type)
|
static void track_merge(Track& destination, const Track& source, Merge type)
|
||||||
{
|
{
|
||||||
std::vector<Frame> frames{};
|
std::vector<Frame> frames{};
|
||||||
for (const auto& frame : source.frames)
|
for (const auto& frame : source.frames)
|
||||||
frames.push_back(frame_clone(frame));
|
frames.push_back(frame_clone(frame));
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case types::merge::APPEND:
|
case MERGE_APPEND:
|
||||||
destination.frames.insert(destination.frames.end(), frames.begin(), frames.end());
|
destination.frames.insert(destination.frames.end(), frames.begin(), frames.end());
|
||||||
break;
|
break;
|
||||||
case types::merge::PREPEND:
|
case MERGE_PREPEND:
|
||||||
destination.frames.insert(destination.frames.begin(), frames.begin(), frames.end());
|
destination.frames.insert(destination.frames.begin(), frames.begin(), frames.end());
|
||||||
break;
|
break;
|
||||||
case types::merge::REPLACE:
|
case MERGE_REPLACE:
|
||||||
if (destination.frames.size() < frames.size()) destination.frames.resize(frames.size());
|
if (destination.frames.size() < frames.size()) destination.frames.resize(frames.size());
|
||||||
std::ranges::copy(frames, destination.frames.begin());
|
std::ranges::copy(frames, destination.frames.begin());
|
||||||
break;
|
break;
|
||||||
@@ -311,8 +307,8 @@ namespace anm2ed::edit
|
|||||||
|
|
||||||
// Merges a source animation's layer or null tracks: groups match by name (else are added), tracks match by id
|
// Merges a source animation's layer or null tracks: groups match by name (else are added), tracks match by id
|
||||||
// within their group (else are added).
|
// within their group (else are added).
|
||||||
void track_entries_merge(std::vector<TrackEntry>& destination, const std::vector<TrackEntry>& source,
|
static void track_entries_merge(std::vector<TrackEntry>& destination, const std::vector<TrackEntry>& source,
|
||||||
types::merge::Type type)
|
Merge type)
|
||||||
{
|
{
|
||||||
std::map<int, int> groupRemap{};
|
std::map<int, int> groupRemap{};
|
||||||
std::set<int> matchedGroupIds{};
|
std::set<int> matchedGroupIds{};
|
||||||
@@ -378,7 +374,7 @@ namespace anm2ed::edit
|
|||||||
|
|
||||||
// Merges source animations into the target (frames appended, prepended, replacing or ignored), optionally deleting
|
// Merges source animations into the target (frames appended, prepended, replacing or ignored), optionally deleting
|
||||||
// the sources; `ungroupIds` dissolves groups afterwards. Returns the merged animation's uid.
|
// the sources; `ungroupIds` dissolves groups afterwards. Returns the merged animation's uid.
|
||||||
Uids animations_merge(Model& model, int target, std::set<int> sources, types::merge::Type type, bool isDeleteAfter,
|
Uids animations_merge(Model& model, int target, std::set<int> sources, Merge type, bool isDeleteAfter,
|
||||||
const std::set<int>& ungroupIds)
|
const std::set<int>& ungroupIds)
|
||||||
{
|
{
|
||||||
if (!model.animation_get(target)) return {};
|
if (!model.animation_get(target)) return {};
|
||||||
@@ -396,13 +392,13 @@ namespace anm2ed::edit
|
|||||||
if (!source) continue;
|
if (!source) continue;
|
||||||
auto sourceCopy = *source;
|
auto sourceCopy = *source;
|
||||||
auto& destination = *model.animation_edit(target);
|
auto& destination = *model.animation_edit(target);
|
||||||
if (type == types::merge::APPEND)
|
if (type == MERGE_APPEND)
|
||||||
for (auto& trigger : sourceCopy.triggers.frames)
|
for (auto& trigger : sourceCopy.triggers.frames)
|
||||||
trigger.atFrame += length;
|
trigger.atFrame += length;
|
||||||
if (type == types::merge::PREPEND)
|
if (type == MERGE_PREPEND)
|
||||||
for (auto& trigger : destination.triggers.frames)
|
for (auto& trigger : destination.triggers.frames)
|
||||||
trigger.atFrame += sourceCopy.frameNum;
|
trigger.atFrame += sourceCopy.frameNum;
|
||||||
if (type == types::merge::APPEND || type == types::merge::PREPEND) length += sourceCopy.frameNum;
|
if (type == MERGE_APPEND || type == MERGE_PREPEND) length += sourceCopy.frameNum;
|
||||||
track_merge(destination.root, sourceCopy.root, type);
|
track_merge(destination.root, sourceCopy.root, type);
|
||||||
track_entries_merge(destination.layers, sourceCopy.layers, type);
|
track_entries_merge(destination.layers, sourceCopy.layers, type);
|
||||||
track_entries_merge(destination.nulls, sourceCopy.nulls, type);
|
track_entries_merge(destination.nulls, sourceCopy.nulls, type);
|
||||||
@@ -428,4 +424,3 @@ namespace anm2ed::edit
|
|||||||
animation_groups_remove(model, ungroupIds);
|
animation_groups_remove(model, ungroupIds);
|
||||||
return {uid};
|
return {uid};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -6,10 +6,6 @@
|
|||||||
#include "model/frames.h"
|
#include "model/frames.h"
|
||||||
#include "model/xml.h"
|
#include "model/xml.h"
|
||||||
|
|
||||||
using namespace anm2ed::model;
|
|
||||||
|
|
||||||
namespace anm2ed::edit
|
|
||||||
{
|
|
||||||
std::string region_name_get(const std::string& format, int number)
|
std::string region_name_get(const std::string& format, int number)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -22,14 +18,14 @@ namespace anm2ed::edit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_region_matched(const Region& region, const Frame& frame)
|
static bool is_region_matched(const Region& region, const Frame& frame)
|
||||||
{
|
{
|
||||||
return glm::ivec2(region.crop) == glm::ivec2(frame.crop) && glm::ivec2(region.size) == glm::ivec2(frame.size) &&
|
return glm::ivec2(region.crop) == glm::ivec2(frame.crop) && glm::ivec2(region.size) == glm::ivec2(frame.size) &&
|
||||||
glm::ivec2(region.pivot) == glm::ivec2(frame.pivot);
|
glm::ivec2(region.pivot) == glm::ivec2(frame.pivot);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Every frame of every layer track whose layer has a spritesheet, with that spritesheet's id.
|
// Every frame of every layer track whose layer has a spritesheet, with that spritesheet's id.
|
||||||
template <class Callback> void layer_frames_each(Model& model, int animationIndex, Callback&& callback)
|
template <class Callback> static void layer_frames_each(Model& model, int animationIndex, Callback&& callback)
|
||||||
{
|
{
|
||||||
auto animation = model.animation_get(animationIndex);
|
auto animation = model.animation_get(animationIndex);
|
||||||
if (!animation) return;
|
if (!animation) return;
|
||||||
@@ -545,4 +541,3 @@ namespace anm2ed::edit
|
|||||||
defaultAnimationName.empty() ? source.animations.defaultAnimation : defaultAnimationName;
|
defaultAnimationName.empty() ? source.animations.defaultAnimation : defaultAnimationName;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
+43
-46
@@ -14,10 +14,8 @@
|
|||||||
|
|
||||||
// Document edits as plain functions of the model. Each returns the uids of the elements it created or changed that
|
// Document edits as plain functions of the model. Each returns the uids of the elements it created or changed that
|
||||||
// the caller may want to select (the first one is the focus); selection itself stays with the UI.
|
// the caller may want to select (the first one is the focus); selection itself stays with the UI.
|
||||||
namespace anm2ed::edit
|
|
||||||
{
|
|
||||||
using Uids = std::vector<std::uint64_t>;
|
using Uids = std::vector<std::uint64_t>;
|
||||||
using ImageGet = std::function<const resource::Image*(int)>;
|
using ImageGet = std::function<const Image*(int)>;
|
||||||
|
|
||||||
struct RowTarget
|
struct RowTarget
|
||||||
{
|
{
|
||||||
@@ -90,59 +88,58 @@ namespace anm2ed::edit
|
|||||||
};
|
};
|
||||||
|
|
||||||
bool is_frame_property_valid(FrameProperty, ItemType);
|
bool is_frame_property_valid(FrameProperty, ItemType);
|
||||||
void frame_property_copy(model::Frame&, const model::Frame&, FrameProperty);
|
void frame_property_copy(Frame&, const Frame&, FrameProperty);
|
||||||
Uids frames_property_set(model::Model&, const std::set<Reference>&, FrameProperty, const model::Frame&);
|
Uids frames_property_set(Model&, const std::set<Reference>&, FrameProperty, const Frame&);
|
||||||
|
|
||||||
std::map<Reference, std::set<int>> frames_by_track_get(const std::set<Reference>&);
|
std::map<Reference, std::set<int>> frames_by_track_get(const std::set<Reference>&);
|
||||||
|
|
||||||
Uids frame_insert(model::Model&, Reference, int);
|
Uids frame_insert(Model&, Reference, int);
|
||||||
Uids frames_delete(model::Model&, const std::set<Reference>&);
|
Uids frames_delete(Model&, const std::set<Reference>&);
|
||||||
Uids frames_duplicate(model::Model&, const std::set<Reference>&, Reference);
|
Uids frames_duplicate(Model&, const std::set<Reference>&, Reference);
|
||||||
Uids frames_reverse(model::Model&, const std::set<Reference>&);
|
Uids frames_reverse(Model&, const std::set<Reference>&);
|
||||||
Uids frames_bake(model::Model&, const std::set<Reference>&, int, bool, bool);
|
Uids frames_bake(Model&, const std::set<Reference>&, int, bool, bool);
|
||||||
Uids frame_split(model::Model&, Reference, int);
|
Uids frame_split(Model&, Reference, int);
|
||||||
Uids frames_split(model::Model&, const std::set<Reference>&, int);
|
Uids frames_split(Model&, const std::set<Reference>&, int);
|
||||||
Uids frames_move(model::Model&, const std::set<Reference>&, Reference, int);
|
Uids frames_move(Model&, const std::set<Reference>&, Reference, int);
|
||||||
Uids frame_durations_set(model::Model&, const std::map<Reference, int>&);
|
Uids frame_durations_set(Model&, const std::map<Reference, int>&);
|
||||||
Uids trigger_at_frame_set(model::Model&, Reference, int);
|
Uids trigger_at_frame_set(Model&, Reference, int);
|
||||||
Uids frames_paste(model::Model&, Reference, const std::set<Reference>&, const std::string&, int, std::string*);
|
Uids frames_paste(Model&, Reference, const std::set<Reference>&, const std::string&, int, std::string*);
|
||||||
Uids root_bake_into(model::Model&, const std::set<Reference>&, const std::set<Reference>&, RootBakeOptions);
|
Uids root_bake_into(Model&, const std::set<Reference>&, const std::set<Reference>&, RootBakeOptions);
|
||||||
|
|
||||||
Uids items_remove(model::Model&, int, const std::map<int, std::set<int>>&, const std::map<int, std::set<int>>&);
|
Uids items_remove(Model&, int, const std::map<int, std::set<int>>&, const std::map<int, std::set<int>>&);
|
||||||
Uids items_group(model::Model&, int, int, const std::set<int>&, const std::string&);
|
Uids items_group(Model&, int, int, const std::set<int>&, const std::string&);
|
||||||
Uids items_move(model::Model&, int, int, const std::set<int>&, const std::set<int>&, RowTarget, bool, bool);
|
Uids items_move(Model&, int, int, const std::set<int>&, const std::set<int>&, RowTarget, bool, bool);
|
||||||
Uids animation_length_fit(model::Model&, int);
|
Uids animation_length_fit(Model&, int);
|
||||||
int item_add(model::Model&, ItemType, int, int, model::Layer, model::Null, int, types::destination::Type);
|
int item_add(Model&, ItemType, int, int, Layer, Null, int, Destination);
|
||||||
|
|
||||||
std::set<int> animation_group_ids_get(const model::Model&);
|
std::set<int> animation_group_ids_get(const Model&);
|
||||||
std::set<int> animation_group_indices_get(const model::Model&, int);
|
std::set<int> animation_group_indices_get(const Model&, int);
|
||||||
void animation_groups_remove(model::Model&, const std::set<int>&);
|
void animation_groups_remove(Model&, const std::set<int>&);
|
||||||
Uids animation_add(model::Model&, int, int, int, const std::string&);
|
Uids animation_add(Model&, int, int, int, const std::string&);
|
||||||
Uids animations_remove(model::Model&, const std::set<int>&, const std::set<int>&);
|
Uids animations_remove(Model&, const std::set<int>&, const std::set<int>&);
|
||||||
Uids animations_move(model::Model&, const std::set<int>&, const std::set<int>&, AnimationTarget);
|
Uids animations_move(Model&, const std::set<int>&, const std::set<int>&, AnimationTarget);
|
||||||
Uids animations_group(model::Model&, const std::set<int>&, const std::string&);
|
Uids animations_group(Model&, const std::set<int>&, const std::string&);
|
||||||
Uids animations_paste(model::Model&, const std::string&, int, int, std::set<int>&, std::string*);
|
Uids animations_paste(Model&, const std::string&, int, int, std::set<int>&, std::string*);
|
||||||
Uids animations_merge(model::Model&, int, std::set<int>, types::merge::Type, bool, const std::set<int>&);
|
Uids animations_merge(Model&, int, std::set<int>, Merge, bool, const std::set<int>&);
|
||||||
|
|
||||||
std::string region_name_get(const std::string&, int);
|
std::string region_name_get(const std::string&, int);
|
||||||
Uids regions_generate(model::Model&, const std::set<int>&, const std::set<Reference>&, const std::string&,
|
Uids regions_generate(Model&, const std::set<int>&, const std::set<Reference>&, const std::string&,
|
||||||
RegionFrameMapping);
|
RegionFrameMapping);
|
||||||
Uids regions_scan(model::Model&);
|
Uids regions_scan(Model&);
|
||||||
Uids region_frames_sync(model::Model&);
|
Uids region_frames_sync(Model&);
|
||||||
Uids regions_paste(model::Model&, int, const std::string&, int, std::string*);
|
Uids regions_paste(Model&, int, const std::string&, int, std::string*);
|
||||||
Uids animation_grid_generate(model::Model&, const std::vector<Reference>&, const GridOptions&);
|
Uids animation_grid_generate(Model&, const std::vector<Reference>&, const GridOptions&);
|
||||||
Uids frames_change_apply(model::Model&, const ChangeTargets&, FrameChange, ChangeType);
|
Uids frames_change_apply(Model&, const ChangeTargets&, FrameChange, ChangeType);
|
||||||
bool regions_trim(model::Model&, int, const std::set<int>&, const resource::Image&);
|
bool regions_trim(Model&, int, const std::set<int>&, const Image&);
|
||||||
std::optional<resource::Image> spritesheet_pack(model::Model&, int, const resource::Image&, int);
|
std::optional<Image> spritesheet_pack(Model&, int, const Image&, int);
|
||||||
std::optional<resource::Image> spritesheets_merge(model::Model&, const std::set<int>&, const ImageGet&, bool, bool,
|
std::optional<Image> spritesheets_merge(Model&, const std::set<int>&, const ImageGet&, bool, bool,
|
||||||
bool, Origin);
|
bool, Origin);
|
||||||
|
|
||||||
// Where a spritesheet path of a document (this one, or a library) points, from this document.
|
// Where a spritesheet path of a document (this one, or a library) points, from this document.
|
||||||
using SpritesheetPathGet = std::function<std::filesystem::path(const model::Model&, const std::filesystem::path&)>;
|
using SpritesheetPathGet = std::function<std::filesystem::path(const Model&, const std::filesystem::path&)>;
|
||||||
model::Model animation_layers_flatten(model::Model, const model::LibraryGet&, const SpritesheetPathGet&,
|
Model animation_layers_flatten(Model, const LibraryGet&, const SpritesheetPathGet&,
|
||||||
const std::set<int>& = {});
|
const std::set<int>& = {});
|
||||||
Uids content_remove(model::Model&, ElementType, const std::set<int>&, int, const model::LibraryGet&,
|
Uids content_remove(Model&, ElementType, const std::set<int>&, int, const LibraryGet&,
|
||||||
const SpritesheetPathGet&);
|
const SpritesheetPathGet&);
|
||||||
model::Model isaac_bridge(model::Model);
|
Model isaac_bridge(Model);
|
||||||
bool file_merge(model::Model&, const std::filesystem::path&, const std::filesystem::path&, FileMergePreset);
|
bool file_merge(Model&, const std::filesystem::path&, const std::filesystem::path&, FileMergePreset);
|
||||||
}
|
|
||||||
@@ -7,14 +7,9 @@
|
|||||||
#include "math_util.h"
|
#include "math_util.h"
|
||||||
#include "model/frames.h"
|
#include "model/frames.h"
|
||||||
|
|
||||||
using namespace anm2ed::model;
|
|
||||||
using namespace anm2ed::util;
|
|
||||||
|
|
||||||
namespace anm2ed::edit
|
|
||||||
{
|
|
||||||
// A draw as a plain layer frame of one frame: its transform (parents included) taken apart into position, scale and
|
// A draw as a plain layer frame of one frame: its transform (parents included) taken apart into position, scale and
|
||||||
// rotation. Skew has no place in a plain frame, and is dropped.
|
// rotation. Skew has no place in a plain frame, and is dropped.
|
||||||
Frame draw_frame_bake(const Draw& draw)
|
static Frame draw_frame_bake(const Draw& draw)
|
||||||
{
|
{
|
||||||
auto frame = draw.frame;
|
auto frame = draw.frame;
|
||||||
auto size = glm::max(frame.size, glm::vec2(1.0f));
|
auto size = glm::max(frame.size, glm::vec2(1.0f));
|
||||||
@@ -24,7 +19,7 @@ namespace anm2ed::edit
|
|||||||
auto scaleX = glm::length(column0);
|
auto scaleX = glm::length(column0);
|
||||||
auto determinant = column0.x * column1.y - column0.y * column1.x;
|
auto determinant = column0.x * column1.y - column0.y * column1.x;
|
||||||
frame.position = glm::vec2(model * glm::vec4(frame.pivot / size, 0.0f, 1.0f));
|
frame.position = glm::vec2(model * glm::vec4(frame.pivot / size, 0.0f, 1.0f));
|
||||||
frame.scale = math::unit_to_percent(glm::vec2(scaleX, scaleX > 0.0f ? determinant / scaleX : 0.0f));
|
frame.scale = unit_to_percent(glm::vec2(scaleX, scaleX > 0.0f ? determinant / scaleX : 0.0f));
|
||||||
frame.rotation = glm::degrees(std::atan2(column0.y, column0.x));
|
frame.rotation = glm::degrees(std::atan2(column0.y, column0.x));
|
||||||
frame.skew = {};
|
frame.skew = {};
|
||||||
frame.depth = 0;
|
frame.depth = 0;
|
||||||
@@ -35,7 +30,7 @@ namespace anm2ed::edit
|
|||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_frame_baked_equal(Frame a, const Frame& b)
|
static bool is_frame_baked_equal(Frame a, const Frame& b)
|
||||||
{
|
{
|
||||||
a.uid = b.uid;
|
a.uid = b.uid;
|
||||||
a.duration = b.duration;
|
a.duration = b.duration;
|
||||||
@@ -163,4 +158,3 @@ namespace anm2ed::edit
|
|||||||
std::erase_if(content.layers, is_flattened);
|
std::erase_if(content.layers, is_flattened);
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
+1
-7
@@ -7,11 +7,6 @@
|
|||||||
#include "model/frames.h"
|
#include "model/frames.h"
|
||||||
#include "model/xml.h"
|
#include "model/xml.h"
|
||||||
|
|
||||||
using namespace anm2ed::util;
|
|
||||||
using namespace anm2ed::model;
|
|
||||||
|
|
||||||
namespace anm2ed::edit
|
|
||||||
{
|
|
||||||
std::map<Reference, std::set<int>> frames_by_track_get(const std::set<Reference>& frames)
|
std::map<Reference, std::set<int>> frames_by_track_get(const std::set<Reference>& frames)
|
||||||
{
|
{
|
||||||
std::map<Reference, std::set<int>> result{};
|
std::map<Reference, std::set<int>> result{};
|
||||||
@@ -23,7 +18,7 @@ namespace anm2ed::edit
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uids frames_uids_get(const Track& track, int start, int count)
|
static Uids frames_uids_get(const Track& track, int start, int count)
|
||||||
{
|
{
|
||||||
Uids uids{};
|
Uids uids{};
|
||||||
for (int i = std::max(start, 0); i < std::min(start + count, (int)track.frames.size()); ++i)
|
for (int i = std::max(start, 0); i < std::min(start + count, (int)track.frames.size()); ++i)
|
||||||
@@ -446,4 +441,3 @@ namespace anm2ed::edit
|
|||||||
model.track_edit(rootReference)->frames = std::move(rewritten);
|
model.track_edit(rootReference)->frames = std::move(rewritten);
|
||||||
return uids;
|
return uids;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
+3
-9
@@ -7,15 +7,10 @@
|
|||||||
#include "math_util.h"
|
#include "math_util.h"
|
||||||
#include "model/frames.h"
|
#include "model/frames.h"
|
||||||
|
|
||||||
using namespace anm2ed::model;
|
|
||||||
using namespace anm2ed::util;
|
|
||||||
|
|
||||||
namespace anm2ed::edit
|
|
||||||
{
|
|
||||||
// An alpha offset joins the alpha tint: exact on opaque pixels, which the offset can only fade.
|
// An alpha offset joins the alpha tint: exact on opaque pixels, which the offset can only fade.
|
||||||
void alpha_offsets_bridge(Model& model)
|
static void alpha_offsets_bridge(Model& model)
|
||||||
{
|
{
|
||||||
auto is_offset = [](const Frame& frame) { return math::float_to_uint8(frame.colorOffset.a) != 0; };
|
auto is_offset = [](const Frame& frame) { return float_to_uint8(frame.colorOffset.a) != 0; };
|
||||||
for (int i = 0; i < model.animations_count_get(); ++i)
|
for (int i = 0; i < model.animations_count_get(); ++i)
|
||||||
{
|
{
|
||||||
auto isUsed = false;
|
auto isUsed = false;
|
||||||
@@ -38,7 +33,7 @@ namespace anm2ed::edit
|
|||||||
// A layer frame's depth becomes a copy of its layer, named for the depth, standing where the editor draws it (the
|
// A layer frame's depth becomes a copy of its layer, named for the depth, standing where the editor draws it (the
|
||||||
// layer at the copy's place + depth, past the layer already there), and showing only the frames at that depth; the
|
// layer at the copy's place + depth, past the layer already there), and showing only the frames at that depth; the
|
||||||
// layer itself shows the rest. Groups can't stand apart in the game, so their roots go into their tracks first.
|
// layer itself shows the rest. Groups can't stand apart in the game, so their roots go into their tracks first.
|
||||||
void depths_bridge(Model& model)
|
static void depths_bridge(Model& model)
|
||||||
{
|
{
|
||||||
auto& content = model.content;
|
auto& content = model.content;
|
||||||
std::map<std::pair<int, int>, int> copyIds{};
|
std::map<std::pair<int, int>, int> copyIds{};
|
||||||
@@ -117,4 +112,3 @@ namespace anm2ed::edit
|
|||||||
depths_bridge(model);
|
depths_bridge(model);
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -9,13 +9,7 @@
|
|||||||
#include "pack.h"
|
#include "pack.h"
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
|
|
||||||
using namespace anm2ed::model;
|
|
||||||
using namespace anm2ed::resource;
|
|
||||||
using namespace anm2ed::util;
|
|
||||||
|
|
||||||
// Spritesheet pixel edits: the model changes in place, and a new image is returned for the document to store.
|
// Spritesheet pixel edits: the model changes in place, and a new image is returned for the document to store.
|
||||||
namespace anm2ed::edit
|
|
||||||
{
|
|
||||||
bool regions_trim(Model& model, int spritesheetId, const std::set<int>& ids, const Image& source)
|
bool regions_trim(Model& model, int spritesheetId, const std::set<int>& ids, const Image& source)
|
||||||
{
|
{
|
||||||
auto spritesheet = item_get(model.content.spritesheets, spritesheetId);
|
auto spritesheet = item_get(model.content.spritesheets, spritesheetId);
|
||||||
@@ -35,9 +29,9 @@ namespace anm2ed::edit
|
|||||||
for (int y = minPoint.y; y < maxPoint.y; ++y)
|
for (int y = minPoint.y; y < maxPoint.y; ++y)
|
||||||
for (int x = minPoint.x; x < maxPoint.x; ++x)
|
for (int x = minPoint.x; x < maxPoint.x; ++x)
|
||||||
{
|
{
|
||||||
auto index = ((std::size_t)y * source.size.x + x) * image::CHANNELS;
|
auto index = ((std::size_t)y * source.size.x + x) * IMAGE_CHANNELS;
|
||||||
if (index + image::CHANNELS > source.pixels.size()) continue;
|
if (index + IMAGE_CHANNELS > source.pixels.size()) continue;
|
||||||
if (std::all_of(source.pixels.begin() + index, source.pixels.begin() + index + image::CHANNELS,
|
if (std::all_of(source.pixels.begin() + index, source.pixels.begin() + index + IMAGE_CHANNELS,
|
||||||
[](auto channel) { return channel == 0; }))
|
[](auto channel) { return channel == 0; }))
|
||||||
continue;
|
continue;
|
||||||
contentMin = glm::min(contentMin, glm::ivec2(x, y));
|
contentMin = glm::min(contentMin, glm::ivec2(x, y));
|
||||||
@@ -100,7 +94,7 @@ namespace anm2ed::edit
|
|||||||
|
|
||||||
glm::ivec2 packedSize{};
|
glm::ivec2 packedSize{};
|
||||||
std::vector<glm::ivec2> positions{};
|
std::vector<glm::ivec2> positions{};
|
||||||
if (!util::pack::rects_pack(sizes, packedSize, positions) || packedSize.x <= 0 || packedSize.y <= 0) return {};
|
if (!rects_pack(sizes, packedSize, positions) || packedSize.x <= 0 || packedSize.y <= 0) return {};
|
||||||
|
|
||||||
std::vector<ImagePart> parts{};
|
std::vector<ImagePart> parts{};
|
||||||
for (int i = 0; i < (int)items.size(); ++i)
|
for (int i = 0; i < (int)items.size(); ++i)
|
||||||
@@ -132,7 +126,7 @@ namespace anm2ed::edit
|
|||||||
auto source = item_get(model.content.spritesheets, sourceId);
|
auto source = item_get(model.content.spritesheets, sourceId);
|
||||||
Region region{};
|
Region region{};
|
||||||
region.id = item_next_id_get(base->regions);
|
region.id = item_next_id_get(base->regions);
|
||||||
auto stem = path::to_utf8(source->path.stem());
|
auto stem = path_to_utf8(source->path.stem());
|
||||||
region.name = stem.empty() ? std::format("#{}", sourceId) : stem;
|
region.name = stem.empty() ? std::format("#{}", sourceId) : stem;
|
||||||
region.crop = crop;
|
region.crop = crop;
|
||||||
region.size = size;
|
region.size = size;
|
||||||
@@ -157,7 +151,7 @@ namespace anm2ed::edit
|
|||||||
{
|
{
|
||||||
auto sourceRegionId = sourceRegion.id;
|
auto sourceRegionId = sourceRegion.id;
|
||||||
sourceRegion.id = item_next_id_get(base->regions);
|
sourceRegion.id = item_next_id_get(base->regions);
|
||||||
sourceRegion.uid = util::uid_next();
|
sourceRegion.uid = uid_next();
|
||||||
sourceRegion.crop += offset;
|
sourceRegion.crop += offset;
|
||||||
base->regions.push_back(sourceRegion);
|
base->regions.push_back(sourceRegion);
|
||||||
regionIdMap[id][sourceRegionId] = sourceRegion.id;
|
regionIdMap[id][sourceRegionId] = sourceRegion.id;
|
||||||
@@ -185,10 +179,9 @@ namespace anm2ed::edit
|
|||||||
});
|
});
|
||||||
|
|
||||||
auto isVector = std::ranges::any_of(parts, [](const ImagePart& part) { return part.image->is_vector(); });
|
auto isVector = std::ranges::any_of(parts, [](const ImagePart& part) { return part.image->is_vector(); });
|
||||||
if (isVector != path::is_extension(base->path, image::SVG_EXTENSION))
|
if (isVector != is_path_extension(base->path, SVG_EXTENSION))
|
||||||
base->path.replace_extension(isVector ? image::SVG_EXTENSION : image::PNG_EXTENSION);
|
base->path.replace_extension(isVector ? SVG_EXTENSION : PNG_EXTENSION);
|
||||||
std::erase_if(model.content.spritesheets, [&](const Spritesheet& spritesheet)
|
std::erase_if(model.content.spritesheets, [&](const Spritesheet& spritesheet)
|
||||||
{ return spritesheet.id != baseId && ids.contains(spritesheet.id); });
|
{ return spritesheet.id != baseId && ids.contains(spritesheet.id); });
|
||||||
return Image::compose(parts, mergedSize, isVector);
|
return Image::compose(parts, mergedSize, isVector);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
+3
-8
@@ -1,10 +1,6 @@
|
|||||||
#include "edit/edit.h"
|
#include "edit/edit.h"
|
||||||
|
|
||||||
using namespace anm2ed::model;
|
static std::vector<TrackEntry>* track_entries_edit(Model& model, int animationIndex, int type)
|
||||||
|
|
||||||
namespace anm2ed::edit
|
|
||||||
{
|
|
||||||
std::vector<TrackEntry>* track_entries_edit(Model& model, int animationIndex, int type)
|
|
||||||
{
|
{
|
||||||
if (type != LAYER && type != NULL_) return nullptr;
|
if (type != LAYER && type != NULL_) return nullptr;
|
||||||
auto animation = model.animation_edit(animationIndex);
|
auto animation = model.animation_edit(animationIndex);
|
||||||
@@ -161,7 +157,7 @@ namespace anm2ed::edit
|
|||||||
// Adds a layer or null (or updates the one with the item's id) and gives it a track in one or every animation.
|
// Adds a layer or null (or updates the one with the item's id) and gives it a track in one or every animation.
|
||||||
// Adds track `id` (a new item, from `layer` or `null`, at -1) to an animation or all of them.
|
// Adds track `id` (a new item, from `layer` or `null`, at -1) to an animation or all of them.
|
||||||
int item_add(Model& model, ItemType type, int animationIndex, int id, Layer layer, Null null, int insertBeforeId,
|
int item_add(Model& model, ItemType type, int animationIndex, int id, Layer layer, Null null, int insertBeforeId,
|
||||||
types::destination::Type destination)
|
Destination destination)
|
||||||
{
|
{
|
||||||
auto& content = model.content;
|
auto& content = model.content;
|
||||||
auto item_insert = [&](auto& items, auto item)
|
auto item_insert = [&](auto& items, auto item)
|
||||||
@@ -192,11 +188,10 @@ namespace anm2ed::edit
|
|||||||
entries.insert(insertBeforeId == -1 ? entries.end() : before, Track{.type = type, .id = id});
|
entries.insert(insertBeforeId == -1 ? entries.end() : before, Track{.type = type, .id = id});
|
||||||
};
|
};
|
||||||
|
|
||||||
if (destination == types::destination::ALL)
|
if (destination == DESTINATION_ALL)
|
||||||
for (int i = 0; i < model.animations_count_get(); ++i)
|
for (int i = 0; i < model.animations_count_get(); ++i)
|
||||||
add(i);
|
add(i);
|
||||||
else if (model.animation_get(animationIndex))
|
else if (model.animation_get(animationIndex))
|
||||||
add(animationIndex);
|
add(animationIndex);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
+2
-8
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
namespace anm2ed::util
|
|
||||||
{
|
|
||||||
File::File(const std::filesystem::path& path, const char* mode) { open(path, mode); }
|
File::File(const std::filesystem::path& path, const char* mode) { open(path, mode); }
|
||||||
|
|
||||||
File::~File() { close(); }
|
File::~File() { close(); }
|
||||||
@@ -42,9 +40,7 @@ namespace anm2ed::util
|
|||||||
|
|
||||||
File::operator bool() const { return handle != nullptr; }
|
File::operator bool() const { return handle != nullptr; }
|
||||||
|
|
||||||
namespace file
|
bool file_text_load(const std::filesystem::path& path, std::string* output, const char* mode)
|
||||||
{
|
|
||||||
bool read_to_string(const std::filesystem::path& path, std::string* output, const char* mode)
|
|
||||||
{
|
{
|
||||||
if (!output) return false;
|
if (!output) return false;
|
||||||
|
|
||||||
@@ -61,12 +57,10 @@ namespace anm2ed::util
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool write_string(const std::filesystem::path& path, std::string_view data, const char* mode)
|
bool file_text_save(const std::filesystem::path& path, std::string_view data, const char* mode)
|
||||||
{
|
{
|
||||||
File file(path, mode);
|
File file(path, mode);
|
||||||
if (!file) return false;
|
if (!file) return false;
|
||||||
|
|
||||||
return std::fwrite(data.data(), 1, data.size(), file.get()) == data.size();
|
return std::fwrite(data.data(), 1, data.size(), file.get()) == data.size();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
+2
-8
@@ -4,8 +4,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
namespace anm2ed::util
|
|
||||||
{
|
|
||||||
class File
|
class File
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -22,9 +20,5 @@ namespace anm2ed::util
|
|||||||
FILE* handle{};
|
FILE* handle{};
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace file
|
bool file_text_load(const std::filesystem::path&, std::string*, const char* mode = "rb");
|
||||||
{
|
bool file_text_save(const std::filesystem::path&, std::string_view, const char* mode = "wb");
|
||||||
bool read_to_string(const std::filesystem::path&, std::string*, const char* mode = "rb");
|
|
||||||
bool write_string(const std::filesystem::path&, std::string_view, const char* mode = "wb");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
#include "font.h"
|
#include "font.h"
|
||||||
|
|
||||||
namespace anm2ed::resource
|
|
||||||
{
|
|
||||||
Font::Font() = default;
|
Font::Font() = default;
|
||||||
|
|
||||||
Font::Font(void* data, size_t length, int size)
|
Font::Font(void* data, size_t length, int size)
|
||||||
@@ -52,4 +50,3 @@ namespace anm2ed::resource
|
|||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
+9
-15
@@ -3,25 +3,20 @@
|
|||||||
#include <imgui/imgui.h>
|
#include <imgui/imgui.h>
|
||||||
#include "embed.h"
|
#include "embed.h"
|
||||||
|
|
||||||
namespace anm2ed::resource::font
|
constexpr auto FONT_SIZE = 16;
|
||||||
{
|
constexpr auto FONT_SIZE_LARGE = 32;
|
||||||
constexpr auto SIZE = 16;
|
|
||||||
constexpr auto SIZE_LARGE = 32;
|
|
||||||
|
|
||||||
enum Type
|
enum FontStyle
|
||||||
{
|
{
|
||||||
REGULAR,
|
FONT_REGULAR,
|
||||||
ITALICS,
|
FONT_ITALICS,
|
||||||
BOLD,
|
FONT_BOLD,
|
||||||
BOLD_ITALICS,
|
FONT_BOLD_ITALICS,
|
||||||
COUNT
|
FONT_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr const Embed* FONTS[COUNT] = {&FONT_REGULAR_TTF, &FONT_ITALICS_TTF, &FONT_BOLD_TTF, &FONT_BOLD_ITALICS_TTF};
|
constexpr const Embed* FONTS[FONT_COUNT] = {&FONT_REGULAR_TTF, &FONT_ITALICS_TTF, &FONT_BOLD_TTF, &FONT_BOLD_ITALICS_TTF};
|
||||||
}
|
|
||||||
|
|
||||||
namespace anm2ed::resource
|
|
||||||
{
|
|
||||||
class Font
|
class Font
|
||||||
{
|
{
|
||||||
ImFont* pointer{};
|
ImFont* pointer{};
|
||||||
@@ -36,4 +31,3 @@ namespace anm2ed::resource
|
|||||||
ImFont* get();
|
ImFont* get();
|
||||||
Font& operator=(Font&&) noexcept;
|
Font& operator=(Font&&) noexcept;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
+1
-5
@@ -2,11 +2,8 @@
|
|||||||
|
|
||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
|
|
||||||
using namespace anm2ed::resource;
|
|
||||||
using namespace glm;
|
using namespace glm;
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
Framebuffer::Framebuffer()
|
Framebuffer::Framebuffer()
|
||||||
{
|
{
|
||||||
glGenFramebuffers(1, &fbo);
|
glGenFramebuffers(1, &fbo);
|
||||||
@@ -60,7 +57,7 @@ namespace anm2ed
|
|||||||
|
|
||||||
std::vector<uint8_t> Framebuffer::pixels_get() const
|
std::vector<uint8_t> Framebuffer::pixels_get() const
|
||||||
{
|
{
|
||||||
auto count = size.x * size.y * image::CHANNELS;
|
auto count = size.x * size.y * IMAGE_CHANNELS;
|
||||||
std::vector<uint8_t> pixels(count);
|
std::vector<uint8_t> pixels(count);
|
||||||
|
|
||||||
glReadBuffer(GL_COLOR_ATTACHMENT0);
|
glReadBuffer(GL_COLOR_ATTACHMENT0);
|
||||||
@@ -85,4 +82,3 @@ namespace anm2ed
|
|||||||
void Framebuffer::viewport_set() const { glViewport(0, 0, size.x, size.y); }
|
void Framebuffer::viewport_set() const { glViewport(0, 0, size.x, size.y); }
|
||||||
void Framebuffer::bind() const { glBindFramebuffer(GL_FRAMEBUFFER, fbo); }
|
void Framebuffer::bind() const { glBindFramebuffer(GL_FRAMEBUFFER, fbo); }
|
||||||
void Framebuffer::unbind() const { glBindFramebuffer(GL_FRAMEBUFFER, 0); }
|
void Framebuffer::unbind() const { glBindFramebuffer(GL_FRAMEBUFFER, 0); }
|
||||||
}
|
|
||||||
@@ -3,8 +3,6 @@
|
|||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
class Framebuffer
|
class Framebuffer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -35,4 +33,3 @@ namespace anm2ed
|
|||||||
void bind() const;
|
void bind() const;
|
||||||
void unbind() const;
|
void unbind() const;
|
||||||
};
|
};
|
||||||
};
|
|
||||||
+8
-11
@@ -2,9 +2,7 @@
|
|||||||
|
|
||||||
#include "embed.h"
|
#include "embed.h"
|
||||||
|
|
||||||
namespace anm2ed::resource::friends
|
struct FriendInfo
|
||||||
{
|
|
||||||
struct Info
|
|
||||||
{
|
{
|
||||||
const char* name{};
|
const char* name{};
|
||||||
const Embed* png{};
|
const Embed* png{};
|
||||||
@@ -12,22 +10,21 @@ namespace anm2ed::resource::friends
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define FRIENDS_LIST \
|
#define FRIENDS_LIST \
|
||||||
X(MEAT_BOY, "Meat Boy", FRIENDS_MEAT_BOY) \
|
X(FRIEND_MEAT_BOY, "Meat Boy", FRIENDS_MEAT_BOY) \
|
||||||
X(ISAAC, "Isaac", FRIENDS_ISAAC) \
|
X(FRIEND_ISAAC, "Isaac", FRIENDS_ISAAC) \
|
||||||
X(STACY, "Stacy", FRIENDS_STACY) \
|
X(FRIEND_STACY, "Stacy", FRIENDS_STACY) \
|
||||||
X(ASH, "Ash", FRIENDS_ASH)
|
X(FRIEND_ASH, "Ash", FRIENDS_ASH)
|
||||||
|
|
||||||
enum Type
|
enum Friend
|
||||||
{
|
{
|
||||||
#define X(symbol, name, embed) symbol,
|
#define X(symbol, name, embed) symbol,
|
||||||
FRIENDS_LIST
|
FRIENDS_LIST
|
||||||
#undef X
|
#undef X
|
||||||
COUNT
|
FRIEND_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr Info FRIENDS[COUNT] = {
|
constexpr FriendInfo FRIENDS[FRIEND_COUNT] = {
|
||||||
#define X(symbol, name, embed) {name, &embed##_PNG, &embed##_ANM2},
|
#define X(symbol, name, embed) {name, &embed##_PNG, &embed##_ANM2},
|
||||||
FRIENDS_LIST
|
FRIENDS_LIST
|
||||||
#undef X
|
#undef X
|
||||||
};
|
};
|
||||||
}
|
|
||||||
+54
-57
@@ -2,78 +2,75 @@
|
|||||||
#include "embed.h"
|
#include "embed.h"
|
||||||
#include <glm/ext/vector_int2.hpp>
|
#include <glm/ext/vector_int2.hpp>
|
||||||
|
|
||||||
namespace anm2ed::resource::icon
|
constexpr auto ICON_SIZE_SMALL = glm::ivec2(64, 64);
|
||||||
{
|
constexpr auto ICON_SIZE_NORMAL = glm::ivec2(128, 128);
|
||||||
constexpr auto SIZE_SMALL = glm::ivec2(64, 64);
|
constexpr auto ICON_SIZE_LARGE = glm::ivec2(256, 256);
|
||||||
constexpr auto SIZE_NORMAL = glm::ivec2(128, 128);
|
constexpr auto ICON_SIZE_HUGE = glm::ivec2(512, 512);
|
||||||
constexpr auto SIZE_LARGE = glm::ivec2(256, 256);
|
|
||||||
constexpr auto SIZE_HUGE = glm::ivec2(512, 512);
|
|
||||||
|
|
||||||
#define SVG_LIST \
|
#define SVG_LIST \
|
||||||
X(NONE, &ICON_NONE_SVG, SIZE_SMALL) \
|
X(ICON_NONE, &ICON_NONE_SVG, ICON_SIZE_SMALL) \
|
||||||
X(FILE, &ICON_FILE_SVG, SIZE_NORMAL) \
|
X(ICON_FILE, &ICON_FILE_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(FOLDER, &ICON_FOLDER_SVG, SIZE_NORMAL) \
|
X(ICON_FOLDER, &ICON_FOLDER_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(FOLDER_OPEN, &ICON_FOLDER_OPEN_SVG, SIZE_NORMAL) \
|
X(ICON_FOLDER_OPEN, &ICON_FOLDER_OPEN_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(CLOSE, &ICON_CLOSE_SVG, SIZE_NORMAL) \
|
X(ICON_CLOSE, &ICON_CLOSE_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(ROOT, &ICON_ROOT_SVG, SIZE_NORMAL) \
|
X(ICON_ROOT, &ICON_ROOT_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(LAYER, &ICON_LAYER_SVG, SIZE_NORMAL) \
|
X(ICON_LAYER, &ICON_LAYER_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(NULL_, &ICON_NULL_SVG, SIZE_NORMAL) \
|
X(ICON_NULL, &ICON_NULL_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(SOUND, &ICON_SOUND_SVG, SIZE_NORMAL) \
|
X(ICON_SOUND, &ICON_SOUND_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(SHADER, &ICON_SHADER_SVG, SIZE_NORMAL) \
|
X(ICON_SHADER, &ICON_SHADER_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(TRIGGERS, &ICON_TRIGGERS_SVG, SIZE_NORMAL) \
|
X(ICON_TRIGGERS, &ICON_TRIGGERS_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(VISIBLE, &ICON_VISIBLE_SVG, SIZE_NORMAL) \
|
X(ICON_VISIBLE, &ICON_VISIBLE_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(INVISIBLE, &ICON_INVISIBLE_SVG, SIZE_NORMAL) \
|
X(ICON_INVISIBLE, &ICON_INVISIBLE_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(SHOW_RECT, &ICON_SHOW_RECT_SVG, SIZE_NORMAL) \
|
X(ICON_SHOW_RECT, &ICON_SHOW_RECT_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(HIDE_RECT, &ICON_HIDE_RECT_SVG, SIZE_NORMAL) \
|
X(ICON_HIDE_RECT, &ICON_HIDE_RECT_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(SHOW_UNUSED, &ICON_SHOW_UNUSED_SVG, SIZE_NORMAL) \
|
X(ICON_SHOW_UNUSED, &ICON_SHOW_UNUSED_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(HIDE_UNUSED, &ICON_HIDE_UNUSED_SVG, SIZE_NORMAL) \
|
X(ICON_HIDE_UNUSED, &ICON_HIDE_UNUSED_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(SHOW_LAYERS, &ICON_SHOW_LAYERS_SVG, SIZE_NORMAL) \
|
X(ICON_SHOW_LAYERS, &ICON_SHOW_LAYERS_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(HIDE_LAYERS, &ICON_HIDE_LAYERS_SVG, SIZE_NORMAL) \
|
X(ICON_HIDE_LAYERS, &ICON_HIDE_LAYERS_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(OVER, &ICON_OVER_SVG, SIZE_NORMAL) \
|
X(ICON_OVER, &ICON_OVER_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(UNDER, &ICON_UNDER_SVG, SIZE_NORMAL) \
|
X(ICON_UNDER, &ICON_UNDER_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(PAN, &ICON_PAN_SVG, SIZE_NORMAL) \
|
X(ICON_PAN, &ICON_PAN_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(MOVE, &ICON_MOVE_SVG, SIZE_NORMAL) \
|
X(ICON_MOVE, &ICON_MOVE_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(ROTATE, &ICON_ROTATE_SVG, SIZE_NORMAL) \
|
X(ICON_ROTATE, &ICON_ROTATE_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(SCALE, &ICON_SCALE_SVG, SIZE_NORMAL) \
|
X(ICON_SCALE, &ICON_SCALE_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(SKEW, &ICON_SKEW_SVG, SIZE_NORMAL) \
|
X(ICON_SKEW, &ICON_SKEW_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(CROP, &ICON_CROP_SVG, SIZE_NORMAL) \
|
X(ICON_CROP, &ICON_CROP_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(DRAW, &ICON_DRAW_SVG, SIZE_NORMAL) \
|
X(ICON_DRAW, &ICON_DRAW_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(ERASE, &ICON_ERASE_SVG, SIZE_NORMAL) \
|
X(ICON_ERASE, &ICON_ERASE_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(COLOR_PICKER, &ICON_COLOR_PICKER_SVG, SIZE_NORMAL) \
|
X(ICON_COLOR_PICKER, &ICON_COLOR_PICKER_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(UNDO, &ICON_UNDO_SVG, SIZE_NORMAL) \
|
X(ICON_UNDO, &ICON_UNDO_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(REDO, &ICON_REDO_SVG, SIZE_NORMAL) \
|
X(ICON_REDO, &ICON_REDO_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(ANIMATION, &ICON_ANIMATION_SVG, SIZE_NORMAL) \
|
X(ICON_ANIMATION, &ICON_ANIMATION_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(SPRITESHEET, &ICON_SPRITESHEET_SVG, SIZE_NORMAL) \
|
X(ICON_SPRITESHEET, &ICON_SPRITESHEET_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(EVENT, &ICON_EVENT_SVG, SIZE_NORMAL) \
|
X(ICON_EVENT, &ICON_EVENT_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(INTERPOLATED, &ICON_INTERPOLATED_SVG, SIZE_NORMAL) \
|
X(ICON_INTERPOLATED, &ICON_INTERPOLATED_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(UNINTERPOLATED, &ICON_UNINTERPOLATED_SVG, SIZE_NORMAL) \
|
X(ICON_UNINTERPOLATED, &ICON_UNINTERPOLATED_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(EASE_IN, &ICON_EASE_IN_SVG, SIZE_NORMAL) \
|
X(ICON_EASE_IN, &ICON_EASE_IN_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(EASE_OUT, &ICON_EASE_OUT_SVG, SIZE_NORMAL) \
|
X(ICON_EASE_OUT, &ICON_EASE_OUT_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(EASE_IN_OUT, &ICON_EASE_IN_OUT_SVG, SIZE_NORMAL) \
|
X(ICON_EASE_IN_OUT, &ICON_EASE_IN_OUT_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(TRIGGER, &ICON_TRIGGER_SVG, SIZE_NORMAL) \
|
X(ICON_TRIGGER, &ICON_TRIGGER_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(PLAYHEAD, &ICON_PLAYHEAD_SVG, SIZE_NORMAL) \
|
X(ICON_PLAYHEAD, &ICON_PLAYHEAD_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(PIVOT, &ICON_PIVOT_SVG, SIZE_NORMAL) \
|
X(ICON_PIVOT, &ICON_PIVOT_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(POINT, &ICON_UNINTERPOLATED_SVG, SIZE_NORMAL) \
|
X(ICON_POINT, &ICON_UNINTERPOLATED_SVG, ICON_SIZE_NORMAL) \
|
||||||
X(TARGET, &ICON_TARGET_SVG, SIZE_HUGE) \
|
X(ICON_TARGET, &ICON_TARGET_SVG, ICON_SIZE_HUGE) \
|
||||||
X(TARGET_ALT, &ICON_TARGET_ALT_SVG, SIZE_HUGE)
|
X(ICON_TARGET_ALT, &ICON_TARGET_ALT_SVG, ICON_SIZE_HUGE)
|
||||||
|
|
||||||
enum Type
|
enum Icon
|
||||||
{
|
{
|
||||||
#define X(name, data, size) name,
|
#define X(name, data, size) name,
|
||||||
SVG_LIST
|
SVG_LIST
|
||||||
#undef X
|
#undef X
|
||||||
COUNT
|
ICON_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Info
|
struct IconInfo
|
||||||
{
|
{
|
||||||
const Embed* svg{};
|
const Embed* svg{};
|
||||||
glm::ivec2 size{};
|
glm::ivec2 size{};
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr Info ICONS[COUNT] = {
|
constexpr IconInfo ICONS[ICON_COUNT] = {
|
||||||
#define X(name, data, size) {data, size},
|
#define X(name, data, size) {data, size},
|
||||||
SVG_LIST
|
SVG_LIST
|
||||||
#undef X
|
#undef X
|
||||||
};
|
};
|
||||||
}
|
|
||||||
+24
-30
@@ -36,13 +36,8 @@
|
|||||||
#include "path.h"
|
#include "path.h"
|
||||||
#include "uid.h"
|
#include "uid.h"
|
||||||
|
|
||||||
using namespace anm2ed::resource::image;
|
|
||||||
using namespace anm2ed::util::math;
|
|
||||||
using namespace anm2ed::util;
|
|
||||||
using namespace glm;
|
using namespace glm;
|
||||||
|
|
||||||
namespace anm2ed::resource
|
|
||||||
{
|
|
||||||
constexpr std::size_t BASE64_GROUP_BYTES = 3;
|
constexpr std::size_t BASE64_GROUP_BYTES = 3;
|
||||||
constexpr int BASE64_DIGIT_BITS = 6;
|
constexpr int BASE64_DIGIT_BITS = 6;
|
||||||
constexpr std::uint32_t BASE64_DIGIT_MASK = 0x3F;
|
constexpr std::uint32_t BASE64_DIGIT_MASK = 0x3F;
|
||||||
@@ -70,13 +65,13 @@ namespace anm2ed::resource
|
|||||||
// Closes the hairline seams an SVG's anti-aliasing leaves where two shapes meet: a partly covered pixel with opaque
|
// Closes the hairline seams an SVG's anti-aliasing leaves where two shapes meet: a partly covered pixel with opaque
|
||||||
// pixels on both sides of it (along any axis, within SEAM_REACH) takes their color over its own and becomes opaque.
|
// pixels on both sides of it (along any axis, within SEAM_REACH) takes their color over its own and becomes opaque.
|
||||||
// Outer edges, with transparency on one side, keep their anti-aliasing.
|
// Outer edges, with transparency on one side, keep their anti-aliasing.
|
||||||
void seams_fill(Image& image)
|
static void seams_fill(Image& image)
|
||||||
{
|
{
|
||||||
constexpr glm::ivec2 AXES[] = {{1, 0}, {0, 1}, {1, 1}, {1, -1}};
|
constexpr glm::ivec2 AXES[] = {{1, 0}, {0, 1}, {1, 1}, {1, -1}};
|
||||||
// Coverage as drawn (filling only ever raises it, and only on partly covered pixels, whose colors no check reads).
|
// Coverage as drawn (filling only ever raises it, and only on partly covered pixels, whose colors no check reads).
|
||||||
std::vector<uint8_t> alphas((std::size_t)image.size.x * image.size.y);
|
std::vector<uint8_t> alphas((std::size_t)image.size.x * image.size.y);
|
||||||
for (std::size_t i = 0; i < alphas.size(); ++i)
|
for (std::size_t i = 0; i < alphas.size(); ++i)
|
||||||
alphas[i] = image.pixels[i * CHANNELS + ALPHA];
|
alphas[i] = image.pixels[i * IMAGE_CHANNELS + ALPHA];
|
||||||
auto index_get = [&](glm::ivec2 point) { return (std::size_t)point.y * image.size.x + point.x; };
|
auto index_get = [&](glm::ivec2 point) { return (std::size_t)point.y * image.size.x + point.x; };
|
||||||
auto opaque_get = [&](glm::ivec2 point, glm::ivec2 step) -> const uint8_t*
|
auto opaque_get = [&](glm::ivec2 point, glm::ivec2 step) -> const uint8_t*
|
||||||
{
|
{
|
||||||
@@ -86,7 +81,7 @@ namespace anm2ed::resource
|
|||||||
if (glm::any(glm::lessThan(neighbor, glm::ivec2(0))) || glm::any(glm::greaterThanEqual(neighbor, image.size)))
|
if (glm::any(glm::lessThan(neighbor, glm::ivec2(0))) || glm::any(glm::greaterThanEqual(neighbor, image.size)))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
if (alphas[index_get(neighbor)] >= SEAM_OPAQUE_ALPHA)
|
if (alphas[index_get(neighbor)] >= SEAM_OPAQUE_ALPHA)
|
||||||
return image.pixels.data() + index_get(neighbor) * CHANNELS;
|
return image.pixels.data() + index_get(neighbor) * IMAGE_CHANNELS;
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
};
|
};
|
||||||
@@ -101,7 +96,7 @@ namespace anm2ed::resource
|
|||||||
auto before = opaque_get({x, y}, -axis);
|
auto before = opaque_get({x, y}, -axis);
|
||||||
auto after = before ? opaque_get({x, y}, axis) : nullptr;
|
auto after = before ? opaque_get({x, y}, axis) : nullptr;
|
||||||
if (!after) continue;
|
if (!after) continue;
|
||||||
auto pixel = image.pixels.data() + index_get({x, y}) * CHANNELS;
|
auto pixel = image.pixels.data() + index_get({x, y}) * IMAGE_CHANNELS;
|
||||||
auto coverage = alpha / (float)UINT8_MAX;
|
auto coverage = alpha / (float)UINT8_MAX;
|
||||||
for (int channel = 0; channel < ALPHA; ++channel)
|
for (int channel = 0; channel < ALPHA; ++channel)
|
||||||
pixel[channel] = (uint8_t)std::round(pixel[channel] * coverage +
|
pixel[channel] = (uint8_t)std::round(pixel[channel] * coverage +
|
||||||
@@ -113,7 +108,7 @@ namespace anm2ed::resource
|
|||||||
}
|
}
|
||||||
|
|
||||||
// An SVG drawn at about `scale` pixels per unit (exactly, after rounding to whole pixels); nothing if it won't parse.
|
// An SVG drawn at about `scale` pixels per unit (exactly, after rounding to whole pixels); nothing if it won't parse.
|
||||||
Image svg_render(std::shared_ptr<const std::string> svg, float scale)
|
static Image svg_render(std::shared_ptr<const std::string> svg, float scale)
|
||||||
{
|
{
|
||||||
auto document = svg ? lunasvg::Document::loadFromData(*svg) : nullptr;
|
auto document = svg ? lunasvg::Document::loadFromData(*svg) : nullptr;
|
||||||
if (!document || document->width() <= 0.0f) return {};
|
if (!document || document->width() <= 0.0f) return {};
|
||||||
@@ -130,7 +125,7 @@ namespace anm2ed::resource
|
|||||||
|
|
||||||
Image Image::vector_render(float scale) const { return svg_render(svg, scale); }
|
Image Image::vector_render(float scale) const { return svg_render(svg, scale); }
|
||||||
|
|
||||||
size_t Image::pixel_size_get() const { return size.x * size.y * CHANNELS; }
|
size_t Image::pixel_size_get() const { return size.x * size.y * IMAGE_CHANNELS; }
|
||||||
|
|
||||||
Image::Image(const uint8_t* data, ivec2 size, bool isLinear) : isLinear(isLinear)
|
Image::Image(const uint8_t* data, ivec2 size, bool isLinear) : isLinear(isLinear)
|
||||||
{
|
{
|
||||||
@@ -147,7 +142,7 @@ namespace anm2ed::resource
|
|||||||
auto sizeInt = static_cast<int>(pngSize);
|
auto sizeInt = static_cast<int>(pngSize);
|
||||||
if (sizeInt <= 0) return;
|
if (sizeInt <= 0) return;
|
||||||
|
|
||||||
if (auto data = stbi_load_from_memory(pngData, sizeInt, &size.x, &size.y, nullptr, CHANNELS); data)
|
if (auto data = stbi_load_from_memory(pngData, sizeInt, &size.x, &size.y, nullptr, IMAGE_CHANNELS); data)
|
||||||
{
|
{
|
||||||
*this = Image(data, size);
|
*this = Image(data, size);
|
||||||
stbi_image_free((void*)data);
|
stbi_image_free((void*)data);
|
||||||
@@ -158,7 +153,7 @@ namespace anm2ed::resource
|
|||||||
Image::Image(const std::filesystem::path& path)
|
Image::Image(const std::filesystem::path& path)
|
||||||
{
|
{
|
||||||
auto text = std::make_shared<std::string>();
|
auto text = std::make_shared<std::string>();
|
||||||
if (!file::read_to_string(path, text.get())) return;
|
if (!file_text_load(path, text.get())) return;
|
||||||
*this = Image((const unsigned char*)text->data(), text->size());
|
*this = Image((const unsigned char*)text->data(), text->size());
|
||||||
if (!is_valid()) *this = svg_render(std::move(text), 1.0f);
|
if (!is_valid()) *this = svg_render(std::move(text), 1.0f);
|
||||||
}
|
}
|
||||||
@@ -177,13 +172,13 @@ namespace anm2ed::resource
|
|||||||
{
|
{
|
||||||
auto write_func = [](void* context, void* bytes, int count)
|
auto write_func = [](void* context, void* bytes, int count)
|
||||||
{ fwrite(bytes, 1, count, static_cast<FILE*>(context)); };
|
{ fwrite(bytes, 1, count, static_cast<FILE*>(context)); };
|
||||||
return stbi_write_png_to_func(write_func, handle, size.x, size.y, CHANNELS, data, size.x * CHANNELS) != 0;
|
return stbi_write_png_to_func(write_func, handle, size.x, size.y, IMAGE_CHANNELS, data, size.x * IMAGE_CHANNELS) != 0;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copies a size-sized block between images; pixels outside either image are skipped.
|
// Copies a size-sized block between images; pixels outside either image are skipped.
|
||||||
void pixels_copy(const Image& from, glm::ivec2 fromMin, Image& to, glm::ivec2 toMin, glm::ivec2 size)
|
static void pixels_copy(const Image& from, glm::ivec2 fromMin, Image& to, glm::ivec2 toMin, glm::ivec2 size)
|
||||||
{
|
{
|
||||||
for (int y = 0; y < size.y; ++y)
|
for (int y = 0; y < size.y; ++y)
|
||||||
for (int x = 0; x < size.x; ++x)
|
for (int x = 0; x < size.x; ++x)
|
||||||
@@ -193,9 +188,9 @@ namespace anm2ed::resource
|
|||||||
if (glm::any(glm::lessThan(source, glm::ivec2(0))) || glm::any(glm::greaterThanEqual(source, from.size)) ||
|
if (glm::any(glm::lessThan(source, glm::ivec2(0))) || glm::any(glm::greaterThanEqual(source, from.size)) ||
|
||||||
glm::any(glm::lessThan(target, glm::ivec2(0))) || glm::any(glm::greaterThanEqual(target, to.size)))
|
glm::any(glm::lessThan(target, glm::ivec2(0))) || glm::any(glm::greaterThanEqual(target, to.size)))
|
||||||
continue;
|
continue;
|
||||||
std::copy_n(from.pixels.data() + ((std::size_t)source.y * from.size.x + source.x) * image::CHANNELS,
|
std::copy_n(from.pixels.data() + ((std::size_t)source.y * from.size.x + source.x) * IMAGE_CHANNELS,
|
||||||
image::CHANNELS,
|
IMAGE_CHANNELS,
|
||||||
to.pixels.data() + ((std::size_t)target.y * to.size.x + target.x) * image::CHANNELS);
|
to.pixels.data() + ((std::size_t)target.y * to.size.x + target.x) * IMAGE_CHANNELS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,13 +201,13 @@ namespace anm2ed::resource
|
|||||||
{
|
{
|
||||||
Image region{};
|
Image region{};
|
||||||
region.size = regionSize;
|
region.size = regionSize;
|
||||||
region.pixels.assign((std::size_t)regionSize.x * regionSize.y * image::CHANNELS, 0);
|
region.pixels.assign((std::size_t)regionSize.x * regionSize.y * IMAGE_CHANNELS, 0);
|
||||||
pixels_copy(*this, min, region, {}, regionSize);
|
pixels_copy(*this, min, region, {}, regionSize);
|
||||||
return region;
|
return region;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Base64 of bytes, for an image embedded in an SVG.
|
// Base64 of bytes, for an image embedded in an SVG.
|
||||||
std::string base64_get(const std::vector<uint8_t>& bytes)
|
static std::string base64_get(const std::vector<uint8_t>& bytes)
|
||||||
{
|
{
|
||||||
std::string text{};
|
std::string text{};
|
||||||
for (std::size_t i = 0; i < bytes.size(); i += BASE64_GROUP_BYTES)
|
for (std::size_t i = 0; i < bytes.size(); i += BASE64_GROUP_BYTES)
|
||||||
@@ -230,7 +225,7 @@ namespace anm2ed::resource
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sets an attribute, adding it when the element doesn't have it yet.
|
// Sets an attribute, adding it when the element doesn't have it yet.
|
||||||
template <class T> void attribute_set(pugi::xml_node element, const char* name, const T& value)
|
template <class T> static void attribute_set(pugi::xml_node element, const char* name, const T& value)
|
||||||
{
|
{
|
||||||
auto attribute = element.attribute(name);
|
auto attribute = element.attribute(name);
|
||||||
(attribute ? attribute : element.append_attribute(name)).set_value(value);
|
(attribute ? attribute : element.append_attribute(name)).set_value(value);
|
||||||
@@ -239,7 +234,7 @@ namespace anm2ed::resource
|
|||||||
// An image as one SVG definition: a vector one as a symbol of its drawing (its ids prefixed with `id`, so
|
// An image as one SVG definition: a vector one as a symbol of its drawing (its ids prefixed with `id`, so
|
||||||
// several drawings can share a document), a raster one as an embedded PNG. Either draws at the image's size in
|
// several drawings can share a document), a raster one as an embedded PNG. Either draws at the image's size in
|
||||||
// SVG units.
|
// SVG units.
|
||||||
void svg_definition_add(pugi::xml_node root, pugi::xml_node defs, const Image& image, const std::string& id)
|
static void svg_definition_add(pugi::xml_node root, pugi::xml_node defs, const Image& image, const std::string& id)
|
||||||
{
|
{
|
||||||
if (!image.is_vector())
|
if (!image.is_vector())
|
||||||
{
|
{
|
||||||
@@ -250,7 +245,7 @@ namespace anm2ed::resource
|
|||||||
static_cast<std::vector<uint8_t>*>(context)->insert(static_cast<std::vector<uint8_t>*>(context)->end(),
|
static_cast<std::vector<uint8_t>*>(context)->insert(static_cast<std::vector<uint8_t>*>(context)->end(),
|
||||||
(uint8_t*)data, (uint8_t*)data + count);
|
(uint8_t*)data, (uint8_t*)data + count);
|
||||||
},
|
},
|
||||||
&png, image.size.x, image.size.y, CHANNELS, image.pixels.data(), image.size.x * CHANNELS);
|
&png, image.size.x, image.size.y, IMAGE_CHANNELS, image.pixels.data(), image.size.x * IMAGE_CHANNELS);
|
||||||
auto element = defs.append_child("image");
|
auto element = defs.append_child("image");
|
||||||
element.append_attribute("id") = id.c_str();
|
element.append_attribute("id") = id.c_str();
|
||||||
element.append_attribute("width") = image.size.x;
|
element.append_attribute("width") = image.size.x;
|
||||||
@@ -335,7 +330,7 @@ namespace anm2ed::resource
|
|||||||
{
|
{
|
||||||
if (!isVector)
|
if (!isVector)
|
||||||
{
|
{
|
||||||
std::vector<uint8_t> pixels((std::size_t)size.x * size.y * CHANNELS, 0);
|
std::vector<uint8_t> pixels((std::size_t)size.x * size.y * IMAGE_CHANNELS, 0);
|
||||||
Image composed(pixels.data(), size);
|
Image composed(pixels.data(), size);
|
||||||
for (const auto& part : parts)
|
for (const auto& part : parts)
|
||||||
composed.paste(part.image->region_get(part.source, part.size), part.destination);
|
composed.paste(part.image->region_get(part.source, part.size), part.destination);
|
||||||
@@ -382,19 +377,19 @@ namespace anm2ed::resource
|
|||||||
// Writes a vector image as its SVG (unless the path asks for a PNG), and any other as a PNG.
|
// Writes a vector image as its SVG (unless the path asks for a PNG), and any other as a PNG.
|
||||||
bool Image::write(const std::filesystem::path& path) const
|
bool Image::write(const std::filesystem::path& path) const
|
||||||
{
|
{
|
||||||
if (is_vector() && !path::is_extension(path, PNG_EXTENSION)) return file::write_string(path, *svg);
|
if (is_vector() && !is_path_extension(path, PNG_EXTENSION)) return file_text_save(path, *svg);
|
||||||
return write_png(path);
|
return write_png(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 Image::pixel_read(vec2 position) const
|
vec4 Image::pixel_read(vec2 position) const
|
||||||
{
|
{
|
||||||
if (pixels.size() < CHANNELS || size.x <= 0 || size.y <= 0) return vec4(0.0f);
|
if (pixels.size() < IMAGE_CHANNELS || size.x <= 0 || size.y <= 0) return vec4(0.0f);
|
||||||
|
|
||||||
int x = glm::clamp((int)(position.x), 0, size.x - 1);
|
int x = glm::clamp((int)(position.x), 0, size.x - 1);
|
||||||
int y = glm::clamp((int)(position.y), 0, size.y - 1);
|
int y = glm::clamp((int)(position.y), 0, size.y - 1);
|
||||||
|
|
||||||
auto index = ((size_t)(y) * (size_t)(size.x) + (size_t)(x)) * CHANNELS;
|
auto index = ((size_t)(y) * (size_t)(size.x) + (size_t)(x)) * IMAGE_CHANNELS;
|
||||||
if (index + CHANNELS > pixels.size()) return vec4(0.0f);
|
if (index + IMAGE_CHANNELS > pixels.size()) return vec4(0.0f);
|
||||||
|
|
||||||
vec4 color{uint8_to_float(pixels[index + 0]), uint8_to_float(pixels[index + 1]), uint8_to_float(pixels[index + 2]),
|
vec4 color{uint8_to_float(pixels[index + 0]), uint8_to_float(pixels[index + 1]), uint8_to_float(pixels[index + 2]),
|
||||||
uint8_to_float(pixels[index + 3])};
|
uint8_to_float(pixels[index + 3])};
|
||||||
@@ -411,7 +406,7 @@ namespace anm2ed::resource
|
|||||||
(uint8)float_to_uint8(color.a)};
|
(uint8)float_to_uint8(color.a)};
|
||||||
|
|
||||||
if (pixels.size() != pixel_size_get()) return;
|
if (pixels.size() != pixel_size_get()) return;
|
||||||
size_t idx = (position.y * size.x + position.x) * CHANNELS;
|
size_t idx = (position.y * size.x + position.x) * IMAGE_CHANNELS;
|
||||||
memcpy(&pixels[idx], rgba8, 4);
|
memcpy(&pixels[idx], rgba8, 4);
|
||||||
uid = uid_next();
|
uid = uid_next();
|
||||||
}
|
}
|
||||||
@@ -448,4 +443,3 @@ namespace anm2ed::resource
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
+1
-7
@@ -9,15 +9,10 @@
|
|||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
namespace anm2ed::resource::image
|
constexpr auto IMAGE_CHANNELS = 4;
|
||||||
{
|
|
||||||
constexpr auto CHANNELS = 4;
|
|
||||||
constexpr auto SVG_EXTENSION = "svg";
|
constexpr auto SVG_EXTENSION = "svg";
|
||||||
constexpr auto PNG_EXTENSION = "png";
|
constexpr auto PNG_EXTENSION = "png";
|
||||||
}
|
|
||||||
|
|
||||||
namespace anm2ed::resource
|
|
||||||
{
|
|
||||||
class Image;
|
class Image;
|
||||||
|
|
||||||
// A block of an image placed at `destination`, for composing images.
|
// A block of an image placed at `destination`, for composing images.
|
||||||
@@ -61,4 +56,3 @@ namespace anm2ed::resource
|
|||||||
void pixel_set(glm::ivec2, glm::vec4);
|
void pixel_set(glm::ivec2, glm::vec4);
|
||||||
void pixel_line(glm::ivec2, glm::ivec2, glm::vec4);
|
void pixel_line(glm::ivec2, glm::ivec2, glm::vec4);
|
||||||
};
|
};
|
||||||
}
|
|
||||||
+7
-13
@@ -24,11 +24,6 @@
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace anm2ed::types;
|
|
||||||
using namespace anm2ed::util;
|
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
constexpr auto WINDOW_4K_SIZE = glm::ivec2(3840, 2160);
|
constexpr auto WINDOW_4K_SIZE = glm::ivec2(3840, 2160);
|
||||||
constexpr auto UI_SCALE_4K_DEFAULT = 150.0f;
|
constexpr auto UI_SCALE_4K_DEFAULT = 150.0f;
|
||||||
constexpr auto WINDOW_DEFAULT_SIZE_MULTIPLIER = 0.90f;
|
constexpr auto WINDOW_DEFAULT_SIZE_MULTIPLIER = 0.90f;
|
||||||
@@ -44,7 +39,7 @@ namespace anm2ed
|
|||||||
constexpr int SOCKET_ERROR_ADDRESS_IN_USE = EADDRINUSE;
|
constexpr int SOCKET_ERROR_ADDRESS_IN_USE = EADDRINUSE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool socket_paths_send(Socket& socket, const std::vector<std::string>& paths)
|
static bool socket_paths_send(Socket& socket, const std::vector<std::string>& paths)
|
||||||
{
|
{
|
||||||
uint32_t count = htonl(static_cast<uint32_t>(paths.size()));
|
uint32_t count = htonl(static_cast<uint32_t>(paths.size()));
|
||||||
if (!socket.send(&count, sizeof(count))) return false;
|
if (!socket.send(&count, sizeof(count))) return false;
|
||||||
@@ -59,7 +54,7 @@ namespace anm2ed
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> socket_paths_receive(Socket& socket)
|
static std::vector<std::string> socket_paths_receive(Socket& socket)
|
||||||
{
|
{
|
||||||
uint32_t count{};
|
uint32_t count{};
|
||||||
if (!socket.receive(&count, sizeof(count))) return {};
|
if (!socket.receive(&count, sizeof(count))) return {};
|
||||||
@@ -84,7 +79,7 @@ namespace anm2ed
|
|||||||
return paths;
|
return paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::filesystem::path Loader::settings_path() { return sdl::preferences_directory_get() / "settings.ini"; }
|
std::filesystem::path Loader::settings_path() { return preferences_directory_get() / "settings.ini"; }
|
||||||
|
|
||||||
Loader::Loader(int argc, const char** argv)
|
Loader::Loader(int argc, const char** argv)
|
||||||
{
|
{
|
||||||
@@ -226,7 +221,7 @@ namespace anm2ed
|
|||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
glDisable(GL_LINE_SMOOTH);
|
glDisable(GL_LINE_SMOOTH);
|
||||||
|
|
||||||
math::random_seed_set();
|
random_seed_set();
|
||||||
|
|
||||||
IMGUI_CHECKVERSION();
|
IMGUI_CHECKVERSION();
|
||||||
if (!ImGui::CreateContext())
|
if (!ImGui::CreateContext())
|
||||||
@@ -238,7 +233,7 @@ namespace anm2ed
|
|||||||
|
|
||||||
logger.info("Initialized Dear ImGui");
|
logger.info("Initialized Dear ImGui");
|
||||||
|
|
||||||
imgui::theme_set((imgui::theme::Type)settings.theme);
|
theme_set((Theme)settings.theme);
|
||||||
|
|
||||||
ImGui_ImplSDL3_InitForOpenGL(window, glContext);
|
ImGui_ImplSDL3_InitForOpenGL(window, glContext);
|
||||||
ImGui_ImplOpenGL3_Init("#version 330");
|
ImGui_ImplOpenGL3_Init("#version 330");
|
||||||
@@ -250,7 +245,7 @@ namespace anm2ed
|
|||||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
||||||
io.KeyRepeatDelay = settings.keyboardRepeatDelay;
|
io.KeyRepeatDelay = settings.keyboardRepeatDelay;
|
||||||
io.KeyRepeatRate = settings.keyboardRepeatRate;
|
io.KeyRepeatRate = settings.keyboardRepeatRate;
|
||||||
ImGui::GetStyle().FontScaleMain = math::percent_to_unit(settings.uiScale);
|
ImGui::GetStyle().FontScaleMain = percent_to_unit(settings.uiScale);
|
||||||
io.ConfigWindowsMoveFromTitleBarOnly = true;
|
io.ConfigWindowsMoveFromTitleBarOnly = true;
|
||||||
|
|
||||||
if (auto imguiData = Settings::imgui_data_load(settings_path()); !imguiData.empty())
|
if (auto imguiData = Settings::imgui_data_load(settings_path()); !imguiData.empty())
|
||||||
@@ -319,7 +314,7 @@ namespace anm2ed
|
|||||||
if (ImGui::GetCurrentContext())
|
if (ImGui::GetCurrentContext())
|
||||||
{
|
{
|
||||||
settings.save(settings_path(), ImGui::SaveIniSettingsToMemory(nullptr));
|
settings.save(settings_path(), ImGui::SaveIniSettingsToMemory(nullptr));
|
||||||
resource::texture::garbage_collect();
|
texture_garbage_collect();
|
||||||
|
|
||||||
ImGui_ImplSDL3_Shutdown();
|
ImGui_ImplSDL3_Shutdown();
|
||||||
ImGui_ImplOpenGL3_Shutdown();
|
ImGui_ImplOpenGL3_Shutdown();
|
||||||
@@ -335,4 +330,3 @@ namespace anm2ed
|
|||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -10,8 +10,6 @@
|
|||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
class Loader
|
class Loader
|
||||||
{
|
{
|
||||||
std::filesystem::path settings_path();
|
std::filesystem::path settings_path();
|
||||||
@@ -30,4 +28,3 @@ namespace anm2ed
|
|||||||
Loader(int, const char**);
|
Loader(int, const char**);
|
||||||
~Loader();
|
~Loader();
|
||||||
};
|
};
|
||||||
}
|
|
||||||
+1
-7
@@ -3,8 +3,6 @@
|
|||||||
#include <format>
|
#include <format>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
#define SELECT_ENGLISH(symbol, english, spanish, russian, chinese, korean) english,
|
#define SELECT_ENGLISH(symbol, english, spanish, russian, chinese, korean) english,
|
||||||
#define SELECT_SPANISH(symbol, english, spanish, russian, chinese, korean) spanish,
|
#define SELECT_SPANISH(symbol, english, spanish, russian, chinese, korean) spanish,
|
||||||
#define SELECT_RUSSIAN(symbol, english, spanish, russian, chinese, korean) russian,
|
#define SELECT_RUSSIAN(symbol, english, spanish, russian, chinese, korean) russian,
|
||||||
@@ -914,15 +912,11 @@ namespace anm2ed
|
|||||||
return LANGUAGE_STRING_COLLECTIONS[useLanguage][type];
|
return LANGUAGE_STRING_COLLECTIONS[useLanguage][type];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
inline anm2ed::Localizer localize;
|
inline Localizer localize;
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
// A localized format string filled with arguments.
|
// A localized format string filled with arguments.
|
||||||
template <class... Args> std::string localize_format(StringType format, Args... args)
|
template <class... Args> std::string localize_format(StringType format, Args... args)
|
||||||
{
|
{
|
||||||
return std::vformat(localize.get(format), std::make_format_args(args...));
|
return std::vformat(localize.get(format), std::make_format_args(args...));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
+18
-26
@@ -21,12 +21,6 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace anm2ed::util;
|
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
namespace log
|
|
||||||
{
|
|
||||||
constexpr auto SESSION_LIMIT = 10;
|
constexpr auto SESSION_LIMIT = 10;
|
||||||
constexpr std::uintmax_t DIRECTORY_SIZE_LIMIT = 100ull * 1024ull * 1024ull;
|
constexpr std::uintmax_t DIRECTORY_SIZE_LIMIT = 100ull * 1024ull * 1024ull;
|
||||||
constexpr std::uintmax_t SESSION_SIZE_LIMIT = 25ull * 1024ull * 1024ull;
|
constexpr std::uintmax_t SESSION_SIZE_LIMIT = 25ull * 1024ull * 1024ull;
|
||||||
@@ -38,7 +32,7 @@ namespace anm2ed
|
|||||||
std::uintmax_t size{};
|
std::uintmax_t size{};
|
||||||
};
|
};
|
||||||
|
|
||||||
std::uint32_t process_id_get()
|
static std::uint32_t process_id_get()
|
||||||
{
|
{
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
return (std::uint32_t)_getpid();
|
return (std::uint32_t)_getpid();
|
||||||
@@ -47,13 +41,13 @@ namespace anm2ed
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
std::filesystem::path session_path_get(const std::filesystem::path& directory)
|
static std::filesystem::path session_path_get(const std::filesystem::path& directory)
|
||||||
{
|
{
|
||||||
auto name = std::format("anm2ed_{}_{}.log", time::get("%Y-%m-%d_%H-%M-%S"), process_id_get());
|
auto name = std::format("anm2ed_{}_{}.log", timestamp_get("%Y-%m-%d_%H-%M-%S"), process_id_get());
|
||||||
return directory / "logs" / path::from_utf8(name);
|
return directory / "logs" / path_from_utf8(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<SessionFile> session_files_get(const std::filesystem::path& directory,
|
static std::vector<SessionFile> session_files_get(const std::filesystem::path& directory,
|
||||||
const std::filesystem::path& currentPath)
|
const std::filesystem::path& currentPath)
|
||||||
{
|
{
|
||||||
std::vector<SessionFile> files{};
|
std::vector<SessionFile> files{};
|
||||||
@@ -82,14 +76,14 @@ namespace anm2ed
|
|||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
void session_file_remove(const SessionFile& file, std::uintmax_t& totalSize)
|
static void session_file_remove(const SessionFile& file, std::uintmax_t& totalSize)
|
||||||
{
|
{
|
||||||
std::error_code ec{};
|
std::error_code ec{};
|
||||||
std::filesystem::remove(file.path, ec);
|
std::filesystem::remove(file.path, ec);
|
||||||
if (!ec && totalSize >= file.size) totalSize -= file.size;
|
if (!ec && totalSize >= file.size) totalSize -= file.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sessions_prune(const std::filesystem::path& directory, const std::filesystem::path& currentPath)
|
static void sessions_prune(const std::filesystem::path& directory, const std::filesystem::path& currentPath)
|
||||||
{
|
{
|
||||||
auto files = session_files_get(directory, currentPath);
|
auto files = session_files_get(directory, currentPath);
|
||||||
std::sort(files.begin(), files.end(),
|
std::sort(files.begin(), files.end(),
|
||||||
@@ -112,7 +106,7 @@ namespace anm2ed
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void legacy_log_remove(const std::filesystem::path& currentPath)
|
static void legacy_log_remove(const std::filesystem::path& currentPath)
|
||||||
{
|
{
|
||||||
auto directory = currentPath.parent_path().parent_path();
|
auto directory = currentPath.parent_path().parent_path();
|
||||||
if (directory.empty()) return;
|
if (directory.empty()) return;
|
||||||
@@ -123,7 +117,6 @@ namespace anm2ed
|
|||||||
std::error_code ec{};
|
std::error_code ec{};
|
||||||
std::filesystem::remove(legacyPath, ec);
|
std::filesystem::remove(legacyPath, ec);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void Logger::write_raw(const std::string& message)
|
void Logger::write_raw(const std::string& message)
|
||||||
{
|
{
|
||||||
@@ -140,18 +133,18 @@ namespace anm2ed
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto lineSize = (std::uintmax_t)message.size() + 1;
|
auto lineSize = (std::uintmax_t)message.size() + 1;
|
||||||
auto isLineWithinLimit = logSize <= log::SESSION_SIZE_LIMIT && lineSize <= log::SESSION_SIZE_LIMIT - logSize;
|
auto isLineWithinLimit = logSize <= SESSION_SIZE_LIMIT && lineSize <= SESSION_SIZE_LIMIT - logSize;
|
||||||
if (isLineWithinLimit)
|
if (isLineWithinLimit)
|
||||||
{
|
{
|
||||||
auto line = message + '\n';
|
auto line = message + '\n';
|
||||||
if (file::write_string(logPath, line, "ab")) logSize += line.size();
|
if (file_text_save(logPath, line, "ab")) logSize += line.size();
|
||||||
}
|
}
|
||||||
else if (!isLogLimitReached)
|
else if (!isLogLimitReached)
|
||||||
{
|
{
|
||||||
std::string line =
|
std::string line =
|
||||||
"[WARNING] Session log size limit reached; suppressing further file logs for this session.\n";
|
"[WARNING] Session log size limit reached; suppressing further file logs for this session.\n";
|
||||||
if (logSize + line.size() <= log::SESSION_SIZE_LIMIT)
|
if (logSize + line.size() <= SESSION_SIZE_LIMIT)
|
||||||
if (file::write_string(logPath, line, "ab")) logSize += line.size();
|
if (file_text_save(logPath, line, "ab")) logSize += line.size();
|
||||||
isLogLimitReached = true;
|
isLogLimitReached = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -163,7 +156,7 @@ namespace anm2ed
|
|||||||
|
|
||||||
void Logger::write(const Level level, const std::string& message)
|
void Logger::write(const Level level, const std::string& message)
|
||||||
{
|
{
|
||||||
std::string formatted = std::format("{} {} {}", LEVEL_STRINGS[level], time::get("(%d-%B-%Y %I:%M:%S)"), message);
|
std::string formatted = std::format("{} {} {}", LEVEL_STRINGS[level], timestamp_get("(%d-%B-%Y %I:%M:%S)"), message);
|
||||||
write_raw(formatted);
|
write_raw(formatted);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,11 +269,11 @@ namespace anm2ed
|
|||||||
std::error_code ec{};
|
std::error_code ec{};
|
||||||
auto directory = logPath.parent_path();
|
auto directory = logPath.parent_path();
|
||||||
if (!directory.empty()) std::filesystem::create_directories(directory, ec);
|
if (!directory.empty()) std::filesystem::create_directories(directory, ec);
|
||||||
log::legacy_log_remove(logPath);
|
legacy_log_remove(logPath);
|
||||||
log::sessions_prune(directory, logPath);
|
sessions_prune(directory, logPath);
|
||||||
logSize = std::filesystem::file_size(logPath, ec);
|
logSize = std::filesystem::file_size(logPath, ec);
|
||||||
if (ec) logSize = 0;
|
if (ec) logSize = 0;
|
||||||
isLogLimitReached = logSize >= log::SESSION_SIZE_LIMIT;
|
isLogLimitReached = logSize >= SESSION_SIZE_LIMIT;
|
||||||
}
|
}
|
||||||
stderr_redirect_start();
|
stderr_redirect_start();
|
||||||
}
|
}
|
||||||
@@ -289,7 +282,7 @@ namespace anm2ed
|
|||||||
|
|
||||||
void Logger::session_open(const std::filesystem::path& directory)
|
void Logger::session_open(const std::filesystem::path& directory)
|
||||||
{
|
{
|
||||||
open(log::session_path_get(directory));
|
open(session_path_get(directory));
|
||||||
info(std::format("Initializing {}", localize.get(LABEL_APPLICATION_NAME, ENGLISH)));
|
info(std::format("Initializing {}", localize.get(LABEL_APPLICATION_NAME, ENGLISH)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,6 +312,5 @@ namespace anm2ed
|
|||||||
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
anm2ed::Logger logger;
|
Logger logger;
|
||||||
@@ -8,8 +8,6 @@
|
|||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
#if defined(INFO)
|
#if defined(INFO)
|
||||||
#undef INFO
|
#undef INFO
|
||||||
#endif
|
#endif
|
||||||
@@ -77,6 +75,4 @@ namespace anm2ed
|
|||||||
|
|
||||||
int log_exceptions(const std::function<int()>&);
|
int log_exceptions(const std::function<int()>&);
|
||||||
|
|
||||||
}
|
extern Logger logger;
|
||||||
|
|
||||||
extern anm2ed::Logger logger;
|
|
||||||
+9
-15
@@ -15,8 +15,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
namespace anm2ed::main
|
|
||||||
{
|
|
||||||
struct CommandLineArguments
|
struct CommandLineArguments
|
||||||
{
|
{
|
||||||
std::vector<std::string> strings{};
|
std::vector<std::string> strings{};
|
||||||
@@ -57,14 +55,11 @@ namespace anm2ed::main
|
|||||||
|
|
||||||
return arguments;
|
return arguments;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace anm2ed
|
static int application_run(int argc, const char** argv)
|
||||||
{
|
|
||||||
int application_run(int argc, const char** argv)
|
|
||||||
{
|
{
|
||||||
if (cli::is_cli(argc, argv))
|
if (is_cli(argc, argv))
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
// A GUI-subsystem build has no console of its own; print to the one it was started from.
|
// A GUI-subsystem build has no console of its own; print to the one it was started from.
|
||||||
@@ -74,10 +69,10 @@ namespace anm2ed
|
|||||||
freopen("CONOUT$", "w", stderr);
|
freopen("CONOUT$", "w", stderr);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return cli::run(argc, argv);
|
return cli_run(argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.session_open(util::sdl::preferences_directory_get());
|
logger.session_open(preferences_directory_get());
|
||||||
return log_exceptions(
|
return log_exceptions(
|
||||||
[&]()
|
[&]()
|
||||||
{
|
{
|
||||||
@@ -93,22 +88,21 @@ namespace anm2ed
|
|||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, const char** argv)
|
int main(int argc, const char** argv)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
auto arguments = anm2ed::main::command_line_arguments_get();
|
auto arguments = command_line_arguments_get();
|
||||||
if (!arguments.pointers.empty())
|
if (!arguments.pointers.empty())
|
||||||
return anm2ed::application_run((int)arguments.pointers.size(), arguments.pointers.data());
|
return application_run((int)arguments.pointers.size(), arguments.pointers.data());
|
||||||
#endif
|
#endif
|
||||||
return anm2ed::application_run(argc, argv);
|
return application_run(argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
|
int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
|
||||||
{
|
{
|
||||||
auto arguments = anm2ed::main::command_line_arguments_get();
|
auto arguments = command_line_arguments_get();
|
||||||
return anm2ed::application_run((int)arguments.pointers.size(), arguments.pointers.data());
|
return application_run((int)arguments.pointers.size(), arguments.pointers.data());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
+29
-35
@@ -16,61 +16,56 @@
|
|||||||
#include "ui/shortcut.h"
|
#include "ui/shortcut.h"
|
||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
|
|
||||||
using namespace anm2ed::types;
|
|
||||||
using namespace anm2ed::util;
|
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
constexpr std::size_t RECENT_LIMIT = 10;
|
constexpr std::size_t RECENT_LIMIT = 10;
|
||||||
|
|
||||||
void ensure_parent_directory_exists(const std::filesystem::path& path)
|
static void ensure_parent_directory_exists(const std::filesystem::path& path)
|
||||||
{
|
{
|
||||||
auto parent = path.parent_path();
|
auto parent = path.parent_path();
|
||||||
if (parent.empty()) return;
|
if (parent.empty()) return;
|
||||||
std::error_code ec{};
|
std::error_code ec{};
|
||||||
std::filesystem::create_directories(parent, ec);
|
std::filesystem::create_directories(parent, ec);
|
||||||
if (ec) logger.warning(std::format("Could not create directory for {}: {}", path::to_utf8(path), ec.message()));
|
if (ec) logger.warning(std::format("Could not create directory for {}: {}", path_to_utf8(path), ec.message()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void autosave_file_remove(const std::filesystem::path& path)
|
static void autosave_file_remove(const std::filesystem::path& path)
|
||||||
{
|
{
|
||||||
if (path.empty()) return;
|
if (path.empty()) return;
|
||||||
|
|
||||||
std::error_code ec{};
|
std::error_code ec{};
|
||||||
std::filesystem::remove(path, ec);
|
std::filesystem::remove(path, ec);
|
||||||
if (ec) logger.warning(std::format("Could not remove autosave file {}: {}", path::to_utf8(path), ec.message()));
|
if (ec) logger.warning(std::format("Could not remove autosave file {}: {}", path_to_utf8(path), ec.message()));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::filesystem::path> path_list_load(const std::filesystem::path& path, std::string_view name)
|
static std::vector<std::filesystem::path> path_list_load(const std::filesystem::path& path, std::string_view name)
|
||||||
{
|
{
|
||||||
std::string fileData{};
|
std::string fileData{};
|
||||||
if (!file::read_to_string(path, &fileData, "rb"))
|
if (!file_text_load(path, &fileData, "rb"))
|
||||||
{
|
{
|
||||||
logger.warning(std::format("Could not load {} from: {}. Skipping...", name, path::to_utf8(path)));
|
logger.warning(std::format("Could not load {} from: {}. Skipping...", name, path_to_utf8(path)));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
logger.info(std::format("Loading {} from: {}", name, path::to_utf8(path)));
|
logger.info(std::format("Loading {} from: {}", name, path_to_utf8(path)));
|
||||||
|
|
||||||
std::vector<std::filesystem::path> result{};
|
std::vector<std::filesystem::path> result{};
|
||||||
std::istringstream file(fileData);
|
std::istringstream file(fileData);
|
||||||
for (std::string line{}; std::getline(file, line);)
|
for (std::string line{}; std::getline(file, line);)
|
||||||
{
|
{
|
||||||
if (!line.empty() && line.back() == '\r') line.pop_back();
|
if (!line.empty() && line.back() == '\r') line.pop_back();
|
||||||
auto entry = path::from_utf8(line);
|
auto entry = path_from_utf8(line);
|
||||||
if (!line.empty() && std::ranges::find(result, entry) == result.end()) result.push_back(entry);
|
if (!line.empty() && std::ranges::find(result, entry) == result.end()) result.push_back(entry);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void path_list_save(const std::filesystem::path& path, const std::vector<std::filesystem::path>& entries,
|
static void path_list_save(const std::filesystem::path& path, const std::vector<std::filesystem::path>& entries,
|
||||||
std::string_view name)
|
std::string_view name)
|
||||||
{
|
{
|
||||||
ensure_parent_directory_exists(path);
|
ensure_parent_directory_exists(path);
|
||||||
std::ostringstream file{};
|
std::ostringstream file{};
|
||||||
for (auto& entry : entries)
|
for (auto& entry : entries)
|
||||||
file << path::to_utf8(entry) << '\n';
|
file << path_to_utf8(entry) << '\n';
|
||||||
if (!file::write_string(path, file.str(), "wb"))
|
if (!file_text_save(path, file.str(), "wb"))
|
||||||
logger.warning(std::format("Could not write {} to: {}. Skipping...", name, path::to_utf8(path)));
|
logger.warning(std::format("Could not write {} to: {}. Skipping...", name, path_to_utf8(path)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::selection_history_push(int index)
|
void Manager::selection_history_push(int index)
|
||||||
@@ -100,8 +95,8 @@ namespace anm2ed
|
|||||||
if (documents.empty()) selectionHistory.clear();
|
if (documents.empty()) selectionHistory.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::filesystem::path Manager::recent_files_path_get() { return sdl::preferences_directory_get() / "recent.txt"; }
|
std::filesystem::path Manager::recent_files_path_get() { return preferences_directory_get() / "recent.txt"; }
|
||||||
std::filesystem::path Manager::autosave_path_get() { return sdl::preferences_directory_get() / "autosave.txt"; }
|
std::filesystem::path Manager::autosave_path_get() { return preferences_directory_get() / "autosave.txt"; }
|
||||||
|
|
||||||
Manager::Manager()
|
Manager::Manager()
|
||||||
{
|
{
|
||||||
@@ -109,7 +104,7 @@ namespace anm2ed
|
|||||||
autosave_files_load();
|
autosave_files_load();
|
||||||
}
|
}
|
||||||
|
|
||||||
Document* Manager::get(int index) { return vector::find(documents, index > -1 ? index : selected); }
|
Document* Manager::get(int index) { return vector_find(documents, index > -1 ? index : selected); }
|
||||||
|
|
||||||
void Manager::command_push(Command command)
|
void Manager::command_push(Command command)
|
||||||
{
|
{
|
||||||
@@ -137,7 +132,7 @@ namespace anm2ed
|
|||||||
{
|
{
|
||||||
std::string errorString{};
|
std::string errorString{};
|
||||||
documents.emplace_back(path, isNew, &errorString);
|
documents.emplace_back(path, isNew, &errorString);
|
||||||
auto pathString = path::to_utf8(path);
|
auto pathString = path_to_utf8(path);
|
||||||
|
|
||||||
auto& document = documents.back();
|
auto& document = documents.back();
|
||||||
if (!document.is_valid())
|
if (!document.is_valid())
|
||||||
@@ -216,7 +211,7 @@ namespace anm2ed
|
|||||||
|
|
||||||
void Manager::close(int index)
|
void Manager::close(int index)
|
||||||
{
|
{
|
||||||
if (!vector::in_bounds(documents, index)) return;
|
if (!is_vector_in_bounds(documents, index)) return;
|
||||||
|
|
||||||
documents.erase(documents.begin() + index);
|
documents.erase(documents.begin() + index);
|
||||||
selection_history_cleanup(index);
|
selection_history_cleanup(index);
|
||||||
@@ -290,11 +285,11 @@ namespace anm2ed
|
|||||||
auto parent = get(index);
|
auto parent = get(index);
|
||||||
auto animation = parent ? parent->model.animation_get(layerTrack.animationIndex) : nullptr;
|
auto animation = parent ? parent->model.animation_get(layerTrack.animationIndex) : nullptr;
|
||||||
auto track = parent ? parent->model.track_get(layerTrack) : nullptr;
|
auto track = parent ? parent->model.track_get(layerTrack) : nullptr;
|
||||||
auto layer = parent ? model::item_get(parent->model.content.layers, layerTrack.itemID) : nullptr;
|
auto layer = parent ? item_get(parent->model.content.layers, layerTrack.itemID) : nullptr;
|
||||||
if (!animation || !track || !layer || !layer->is_animation()) return;
|
if (!animation || !track || !layer || !layer->is_animation()) return;
|
||||||
auto time = parent->frameTime > -1 && !parent->playback.isPlaying ? parent->frameTime : parent->playback.time;
|
auto time = parent->frameTime > -1 && !parent->playback.isPlaying ? parent->frameTime : parent->playback.time;
|
||||||
auto [childModel, childAnimation] =
|
auto [childModel, childAnimation] =
|
||||||
model::child_get(parent->model, *layer, model::frame_generate(*track, time), parent->library_resolver_get());
|
child_get(parent->model, *layer, frame_generate(*track, time), parent->library_resolver_get());
|
||||||
if (!childAnimation) return;
|
if (!childAnimation) return;
|
||||||
|
|
||||||
auto steps = parent->childSteps;
|
auto steps = parent->childSteps;
|
||||||
@@ -304,7 +299,7 @@ namespace anm2ed
|
|||||||
.layer = layerTrack,
|
.layer = layerTrack,
|
||||||
.animationName = animation->name,
|
.animationName = animation->name,
|
||||||
.layerName = layer->name});
|
.layerName = layer->name});
|
||||||
auto childTime = model::child_time_get(*track, time, childAnimation->frameNum, layer->id);
|
auto childTime = child_time_get(*track, time, childAnimation->frameNum, layer->id);
|
||||||
auto childName = childAnimation->name;
|
auto childName = childAnimation->name;
|
||||||
parent->playback.isPlaying = false;
|
parent->playback.isPlaying = false;
|
||||||
auto targetIndex = index;
|
auto targetIndex = index;
|
||||||
@@ -354,8 +349,8 @@ namespace anm2ed
|
|||||||
if (!document || (type != ElementType::LAYER_ELEMENT && type != ElementType::NULL_ELEMENT)) return;
|
if (!document || (type != ElementType::LAYER_ELEMENT && type != ElementType::NULL_ELEMENT)) return;
|
||||||
auto isLayer = type == ElementType::LAYER_ELEMENT;
|
auto isLayer = type == ElementType::LAYER_ELEMENT;
|
||||||
auto& content = document->model.content;
|
auto& content = document->model.content;
|
||||||
auto layer = isLayer ? model::item_get(content.layers, id) : nullptr;
|
auto layer = isLayer ? item_get(content.layers, id) : nullptr;
|
||||||
auto null = isLayer ? nullptr : model::item_get(content.nulls, id);
|
auto null = isLayer ? nullptr : item_get(content.nulls, id);
|
||||||
if (id != -1 && !layer && !null) return;
|
if (id != -1 && !layer && !null) return;
|
||||||
itemEdit = layer ? ItemEdit{.id = id,
|
itemEdit = layer ? ItemEdit{.id = id,
|
||||||
.name = layer->name,
|
.name = layer->name,
|
||||||
@@ -388,7 +383,7 @@ namespace anm2ed
|
|||||||
std::vector<std::filesystem::path> ordered;
|
std::vector<std::filesystem::path> ordered;
|
||||||
ordered.reserve(orderedEntries.size());
|
ordered.reserve(orderedEntries.size());
|
||||||
for (const auto& [pathString, _] : orderedEntries)
|
for (const auto& [pathString, _] : orderedEntries)
|
||||||
ordered.emplace_back(path::from_utf8(pathString));
|
ordered.emplace_back(path_from_utf8(pathString));
|
||||||
return ordered;
|
return ordered;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -398,11 +393,11 @@ namespace anm2ed
|
|||||||
std::error_code ec{};
|
std::error_code ec{};
|
||||||
if (!std::filesystem::exists(path, ec))
|
if (!std::filesystem::exists(path, ec))
|
||||||
{
|
{
|
||||||
logger.warning(std::format("Skipping missing recent file: {}", path::to_utf8(path)));
|
logger.warning(std::format("Skipping missing recent file: {}", path_to_utf8(path)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
recentFiles[path::to_utf8(path)] = ++recentFilesCounter;
|
recentFiles[path_to_utf8(path)] = ++recentFilesCounter;
|
||||||
recent_files_trim();
|
recent_files_trim();
|
||||||
recent_files_write();
|
recent_files_write();
|
||||||
}
|
}
|
||||||
@@ -416,9 +411,9 @@ namespace anm2ed
|
|||||||
{
|
{
|
||||||
std::error_code ec{};
|
std::error_code ec{};
|
||||||
if (std::filesystem::exists(*it, ec))
|
if (std::filesystem::exists(*it, ec))
|
||||||
recentFiles[path::to_utf8(*it)] = ++recentFilesCounter;
|
recentFiles[path_to_utf8(*it)] = ++recentFilesCounter;
|
||||||
else
|
else
|
||||||
logger.warning(std::format("Skipping missing recent file: {}", path::to_utf8(*it)));
|
logger.warning(std::format("Skipping missing recent file: {}", path_to_utf8(*it)));
|
||||||
}
|
}
|
||||||
recent_files_trim();
|
recent_files_trim();
|
||||||
}
|
}
|
||||||
@@ -472,8 +467,7 @@ namespace anm2ed
|
|||||||
{
|
{
|
||||||
saveOptions = {.isJson = settings.fileIsJson};
|
saveOptions = {.isJson = settings.fileIsJson};
|
||||||
for (int i = 0; i < SHORTCUT_COUNT; i++)
|
for (int i = 0; i < SHORTCUT_COUNT; i++)
|
||||||
chords[i] = imgui::string_to_chord(settings.*SHORTCUT_MEMBERS[i]);
|
chords[i] = string_to_chord(settings.*SHORTCUT_MEMBERS[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Manager::~Manager() = default;
|
Manager::~Manager() = default;
|
||||||
}
|
|
||||||
+10
-13
@@ -13,8 +13,6 @@
|
|||||||
#include "localization.h"
|
#include "localization.h"
|
||||||
#include "ui/popup.h"
|
#include "ui/popup.h"
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
constexpr auto FILE_LABEL_FORMAT = "{} [{}]";
|
constexpr auto FILE_LABEL_FORMAT = "{} [{}]";
|
||||||
|
|
||||||
class Manager;
|
class Manager;
|
||||||
@@ -57,10 +55,10 @@ namespace anm2ed
|
|||||||
std::vector<std::filesystem::path> anm2DragDropPaths{};
|
std::vector<std::filesystem::path> anm2DragDropPaths{};
|
||||||
bool isAnm2DragDrop{};
|
bool isAnm2DragDrop{};
|
||||||
int anm2DragDropMergePreset{FILE_MERGE_PRESET_MERGE_BY_NAME};
|
int anm2DragDropMergePreset{FILE_MERGE_PRESET_MERGE_BY_NAME};
|
||||||
imgui::PopupHelper anm2DragDropPopup{
|
PopupHelper anm2DragDropPopup{
|
||||||
imgui::PopupHelper(LABEL_MANAGER_ANM2_DRAG_DROP, imgui::POPUP_NORMAL, imgui::POPUP_BY_CURSOR)};
|
PopupHelper(LABEL_MANAGER_ANM2_DRAG_DROP, POPUP_NORMAL, POPUP_BY_CURSOR)};
|
||||||
imgui::PopupHelper anm2DragDropMergePopup{
|
PopupHelper anm2DragDropMergePopup{
|
||||||
imgui::PopupHelper(LABEL_DOCUMENTS_MERGE_INTO_CURRENT, imgui::POPUP_SMALL_NO_HEIGHT)};
|
PopupHelper(LABEL_DOCUMENTS_MERGE_INTO_CURRENT, POPUP_SMALL_NO_HEIGHT)};
|
||||||
|
|
||||||
std::filesystem::path spritesheetDragDropPath{};
|
std::filesystem::path spritesheetDragDropPath{};
|
||||||
bool isSpritesheetDragDrop{};
|
bool isSpritesheetDragDrop{};
|
||||||
@@ -75,16 +73,16 @@ namespace anm2ed
|
|||||||
int libraryId{-1};
|
int libraryId{-1};
|
||||||
std::string animation{};
|
std::string animation{};
|
||||||
} itemEdit{};
|
} itemEdit{};
|
||||||
imgui::PopupHelper itemPropertiesPopups[2]{
|
PopupHelper itemPropertiesPopups[2]{
|
||||||
imgui::PopupHelper(LABEL_MANAGER_LAYER_PROPERTIES, imgui::POPUP_SMALL_NO_HEIGHT),
|
PopupHelper(LABEL_MANAGER_LAYER_PROPERTIES, POPUP_SMALL_NO_HEIGHT),
|
||||||
imgui::PopupHelper(LABEL_MANAGER_NULL_PROPERTIES, imgui::POPUP_SMALL_NO_HEIGHT)};
|
PopupHelper(LABEL_MANAGER_NULL_PROPERTIES, POPUP_SMALL_NO_HEIGHT)};
|
||||||
|
|
||||||
model::Region makeRegion{};
|
Region makeRegion{};
|
||||||
int makeRegionSpritesheetId{-1};
|
int makeRegionSpritesheetId{-1};
|
||||||
bool isMakeRegionRequested{};
|
bool isMakeRegionRequested{};
|
||||||
|
|
||||||
imgui::PopupHelper progressPopup{
|
PopupHelper progressPopup{
|
||||||
imgui::PopupHelper(LABEL_MANAGER_RENDERING_PROGRESS, imgui::POPUP_SMALL_NO_HEIGHT)};
|
PopupHelper(LABEL_MANAGER_RENDERING_PROGRESS, POPUP_SMALL_NO_HEIGHT)};
|
||||||
|
|
||||||
std::vector<int> selectionHistory{};
|
std::vector<int> selectionHistory{};
|
||||||
|
|
||||||
@@ -122,4 +120,3 @@ namespace anm2ed
|
|||||||
|
|
||||||
void settings_apply(Settings&);
|
void settings_apply(Settings&);
|
||||||
};
|
};
|
||||||
}
|
|
||||||
+3
-6
@@ -6,8 +6,6 @@
|
|||||||
|
|
||||||
using namespace glm;
|
using namespace glm;
|
||||||
|
|
||||||
namespace anm2ed::util::math
|
|
||||||
{
|
|
||||||
constexpr auto FLOAT_FORMAT_MAX_DECIMALS = 7;
|
constexpr auto FLOAT_FORMAT_MAX_DECIMALS = 7;
|
||||||
constexpr auto FLOAT_FORMAT_EPSILON = 1e-7f;
|
constexpr auto FLOAT_FORMAT_EPSILON = 1e-7f;
|
||||||
constexpr float FLOAT_FORMAT_POW10[] = {1.f, 10.f, 100.f, 1000.f, 10000.f, 100000.f, 1000000.f, 10000000.f};
|
constexpr float FLOAT_FORMAT_POW10[] = {1.f, 10.f, 100.f, 1000.f, 10000.f, 100000.f, 1000000.f, 10000000.f};
|
||||||
@@ -41,7 +39,7 @@ namespace anm2ed::util::math
|
|||||||
return formatString.c_str();
|
return formatString.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
mat4 skew_get(vec2 skew)
|
static mat4 skew_get(vec2 skew)
|
||||||
{
|
{
|
||||||
mat4 result(1.0f);
|
mat4 result(1.0f);
|
||||||
result[1][0] = skew.x;
|
result[1][0] = skew.x;
|
||||||
@@ -85,7 +83,6 @@ namespace anm2ed::util::math
|
|||||||
return glm::translate(mat4(1.0f), vec3(position, 0.0f)) * local;
|
return glm::translate(mat4(1.0f), vec3(position, 0.0f)) * local;
|
||||||
}
|
}
|
||||||
|
|
||||||
float random() { return (float)rand() / RAND_MAX; }
|
float random_unit_get() { return (float)rand() / RAND_MAX; }
|
||||||
float random_in_range(float min, float max) { return min + random() * (max - min); }
|
float random_in_range(float min, float max) { return min + random_unit_get() * (max - min); }
|
||||||
void random_seed_set() { srand(std::time(nullptr)); }
|
void random_seed_set() { srand(std::time(nullptr)); }
|
||||||
}
|
|
||||||
+1
-4
@@ -3,8 +3,6 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include <glm/glm/mat4x4.hpp>
|
#include <glm/glm/mat4x4.hpp>
|
||||||
|
|
||||||
namespace anm2ed::util::math
|
|
||||||
{
|
|
||||||
template <typename T> constexpr T percent_to_unit(T value) { return value / 100.0f; }
|
template <typename T> constexpr T percent_to_unit(T value) { return value / 100.0f; }
|
||||||
|
|
||||||
template <typename T> constexpr T unit_to_percent(T value) { return value * 100.0f; }
|
template <typename T> constexpr T unit_to_percent(T value) { return value * 100.0f; }
|
||||||
@@ -30,7 +28,6 @@ namespace anm2ed::util::math
|
|||||||
glm::mat4 quad_model_parent_get(glm::vec2 = {}, glm::vec2 = {}, glm::vec2 = glm::vec2(1.0f), float = {},
|
glm::mat4 quad_model_parent_get(glm::vec2 = {}, glm::vec2 = {}, glm::vec2 = glm::vec2(1.0f), float = {},
|
||||||
glm::vec2 = {});
|
glm::vec2 = {});
|
||||||
|
|
||||||
float random();
|
float random_unit_get();
|
||||||
float random_in_range(float min, float max);
|
float random_in_range(float min, float max);
|
||||||
void random_seed_set();
|
void random_seed_set();
|
||||||
}
|
|
||||||
+1
-7
@@ -44,8 +44,6 @@
|
|||||||
X(FRAME, "Frame") \
|
X(FRAME, "Frame") \
|
||||||
X(TRIGGER, "Trigger")
|
X(TRIGGER, "Trigger")
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
enum class ElementType
|
enum class ElementType
|
||||||
{
|
{
|
||||||
#define X(symbol, tag) symbol,
|
#define X(symbol, tag) symbol,
|
||||||
@@ -165,10 +163,7 @@ namespace anm2ed
|
|||||||
constexpr Flags SERIALIZE_ANM2ED_DEFAULT =
|
constexpr Flags SERIALIZE_ANM2ED_DEFAULT =
|
||||||
SERIALIZE_GROUPS | SERIALIZE_REGIONS | SERIALIZE_SOUNDS | SERIALIZE_NESTED_GROUPS | SERIALIZE_EXTENSIONS;
|
SERIALIZE_GROUPS | SERIALIZE_REGIONS | SERIALIZE_SOUNDS | SERIALIZE_NESTED_GROUPS | SERIALIZE_EXTENSIONS;
|
||||||
|
|
||||||
namespace model
|
|
||||||
{
|
|
||||||
class Model;
|
class Model;
|
||||||
}
|
|
||||||
|
|
||||||
// How a document saves: the game's copy with the editor's embedded, or the editor's own JSON; `gameModel` is the
|
// How a document saves: the game's copy with the editor's embedded, or the editor's own JSON; `gameModel` is the
|
||||||
// game's copy when it differs from the document (animation layers flattened).
|
// game's copy when it differs from the document (animation layers flattened).
|
||||||
@@ -176,7 +171,7 @@ namespace anm2ed
|
|||||||
{
|
{
|
||||||
bool isJson{}; // the editor's own JSON document instead
|
bool isJson{}; // the editor's own JSON document instead
|
||||||
bool isPixelBaked{true}; // what the game can't draw is baked into a spritesheet beside the file
|
bool isPixelBaked{true}; // what the game can't draw is baked into a spritesheet beside the file
|
||||||
const model::Model* gameModel{};
|
const Model* gameModel{};
|
||||||
};
|
};
|
||||||
|
|
||||||
#define FRAME_CHANGE_SCALARS \
|
#define FRAME_CHANGE_SCALARS \
|
||||||
@@ -256,4 +251,3 @@ namespace anm2ed
|
|||||||
return value < 0.5f ? (2.0f * value * value) : (1.0f - std::pow(-2.0f * value + 2.0f, 2.0f) * 0.5f);
|
return value < 0.5f ? (2.0f * value * value) : (1.0f - std::pow(-2.0f * value + 2.0f, 2.0f) * 0.5f);
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
+8
-13
@@ -6,25 +6,21 @@
|
|||||||
#include "model/frames.h"
|
#include "model/frames.h"
|
||||||
#include "math_util.h"
|
#include "math_util.h"
|
||||||
|
|
||||||
using namespace anm2ed::util;
|
|
||||||
|
|
||||||
namespace anm2ed::model
|
|
||||||
{
|
|
||||||
constexpr unsigned RANDOM_MULTIPLIER_A = 73856093u;
|
constexpr unsigned RANDOM_MULTIPLIER_A = 73856093u;
|
||||||
constexpr unsigned RANDOM_MULTIPLIER_B = 19349663u;
|
constexpr unsigned RANDOM_MULTIPLIER_B = 19349663u;
|
||||||
|
|
||||||
glm::mat4 draw_quad_model_get(const Draw& draw)
|
glm::mat4 draw_quad_model_get(const Draw& draw)
|
||||||
{
|
{
|
||||||
auto& frame = draw.frame;
|
auto& frame = draw.frame;
|
||||||
return math::quad_model_get(frame.size, frame.position, frame.pivot, math::percent_to_unit(frame.scale),
|
return quad_model_get(frame.size, frame.position, frame.pivot, percent_to_unit(frame.scale),
|
||||||
frame.rotation, math::percent_to_unit(frame.skew));
|
frame.rotation, percent_to_unit(frame.skew));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Where an animation layer's frame puts its child: the frame's transform, with its pivot as the child's origin.
|
// Where an animation layer's frame puts its child: the frame's transform, with its pivot as the child's origin.
|
||||||
glm::mat4 frame_child_model_get(const Frame& frame)
|
glm::mat4 frame_child_model_get(const Frame& frame)
|
||||||
{
|
{
|
||||||
return math::quad_model_get(glm::vec2(1.0f), frame.position, frame.pivot, math::percent_to_unit(frame.scale),
|
return quad_model_get(glm::vec2(1.0f), frame.position, frame.pivot, percent_to_unit(frame.scale),
|
||||||
frame.rotation, math::percent_to_unit(frame.skew));
|
frame.rotation, percent_to_unit(frame.skew));
|
||||||
}
|
}
|
||||||
|
|
||||||
// How many canvas pixels one spritesheet pixel of a layer draw covers (along its longer axis).
|
// How many canvas pixels one spritesheet pixel of a layer draw covers (along its longer axis).
|
||||||
@@ -36,7 +32,7 @@ namespace anm2ed::model
|
|||||||
}
|
}
|
||||||
|
|
||||||
// When an item is drawn: now, and for each sample its time if the track has a frame there.
|
// When an item is drawn: now, and for each sample its time if the track has a frame there.
|
||||||
std::vector<std::pair<int, float>> draw_times_get(const Animation& animation, const Track& track,
|
static std::vector<std::pair<int, float>> draw_times_get(const Animation& animation, const Track& track,
|
||||||
const DrawOptions& options)
|
const DrawOptions& options)
|
||||||
{
|
{
|
||||||
std::vector<std::pair<int, float>> times{};
|
std::vector<std::pair<int, float>> times{};
|
||||||
@@ -59,7 +55,7 @@ namespace anm2ed::model
|
|||||||
}
|
}
|
||||||
|
|
||||||
// A keyframe's start frame in its child animation; a random start is fixed per layer and keyframe.
|
// A keyframe's start frame in its child animation; a random start is fixed per layer and keyframe.
|
||||||
float child_start_get(const Frame& frame, int length, int seed, int index)
|
static float child_start_get(const Frame& frame, int length, int seed, int index)
|
||||||
{
|
{
|
||||||
if (!frame.isChildStartRandom) return (float)frame.childStart;
|
if (!frame.isChildStartRandom) return (float)frame.childStart;
|
||||||
return (float)((((unsigned)seed * RANDOM_MULTIPLIER_A) ^ ((unsigned)index * RANDOM_MULTIPLIER_B)) %
|
return (float)((((unsigned)seed * RANDOM_MULTIPLIER_A) ^ ((unsigned)index * RANDOM_MULTIPLIER_B)) %
|
||||||
@@ -105,7 +101,7 @@ namespace anm2ed::model
|
|||||||
return {childModel, childAnimation};
|
return {childModel, childAnimation};
|
||||||
}
|
}
|
||||||
|
|
||||||
void animation_triggers_add(std::vector<TriggerFire>& fires, const Model& model, const Animation& animation, int time,
|
static void animation_triggers_add(std::vector<TriggerFire>& fires, const Model& model, const Animation& animation, int time,
|
||||||
const LibraryGet& library_get, std::vector<const Animation*>& playing, int layerId = -1)
|
const LibraryGet& library_get, std::vector<const Animation*>& playing, int layerId = -1)
|
||||||
{
|
{
|
||||||
if (animation.triggers.isVisible)
|
if (animation.triggers.isVisible)
|
||||||
@@ -169,7 +165,7 @@ namespace anm2ed::model
|
|||||||
}
|
}
|
||||||
|
|
||||||
// `playing` holds the animations being drawn into one another, so an animation never draws itself.
|
// `playing` holds the animations being drawn into one another, so an animation never draws itself.
|
||||||
std::vector<Draw> animation_draws_get(const Model& model, const Animation& animation, const DrawOptions& options,
|
static std::vector<Draw> animation_draws_get(const Model& model, const Animation& animation, const DrawOptions& options,
|
||||||
std::vector<const Animation*>& playing)
|
std::vector<const Animation*>& playing)
|
||||||
{
|
{
|
||||||
std::vector<Draw> draws{};
|
std::vector<Draw> draws{};
|
||||||
@@ -287,4 +283,3 @@ namespace anm2ed::model
|
|||||||
std::vector<const Animation*> playing{&animation};
|
std::vector<const Animation*> playing{&animation};
|
||||||
return animation_draws_get(model, animation, options, playing);
|
return animation_draws_get(model, animation, options, playing);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -7,8 +7,6 @@
|
|||||||
#include "model/model.h"
|
#include "model/model.h"
|
||||||
|
|
||||||
// What an animation draws at a time, as plain data: every canvas (preview, render, about) draws from this list.
|
// What an animation draws at a time, as plain data: every canvas (preview, render, about) draws from this list.
|
||||||
namespace anm2ed::model
|
|
||||||
{
|
|
||||||
enum class DrawType
|
enum class DrawType
|
||||||
{
|
{
|
||||||
ROOT,
|
ROOT,
|
||||||
@@ -70,4 +68,3 @@ namespace anm2ed::model
|
|||||||
float draw_scale_get(const Draw&);
|
float draw_scale_get(const Draw&);
|
||||||
std::vector<Draw> animation_draws_get(const Model&, const Animation&, const DrawOptions&);
|
std::vector<Draw> animation_draws_get(const Model&, const Animation&, const DrawOptions&);
|
||||||
std::vector<TriggerFire> animation_triggers_get(const Model&, const Animation&, int, const LibraryGet& = {});
|
std::vector<TriggerFire> animation_triggers_get(const Model&, const Animation&, int, const LibraryGet& = {});
|
||||||
}
|
|
||||||
@@ -6,10 +6,6 @@
|
|||||||
#include "model/draw.h"
|
#include "model/draw.h"
|
||||||
#include "math_util.h"
|
#include "math_util.h"
|
||||||
|
|
||||||
using namespace anm2ed::util;
|
|
||||||
|
|
||||||
namespace anm2ed::model
|
|
||||||
{
|
|
||||||
void frame_mix(Frame& frame, const Frame& next, float amount)
|
void frame_mix(Frame& frame, const Frame& next, float amount)
|
||||||
{
|
{
|
||||||
frame.rotation = glm::mix(frame.rotation, next.rotation, amount);
|
frame.rotation = glm::mix(frame.rotation, next.rotation, amount);
|
||||||
@@ -42,14 +38,14 @@ namespace anm2ed::model
|
|||||||
|
|
||||||
glm::mat4 frame_parent_model_get(const Frame& frame)
|
glm::mat4 frame_parent_model_get(const Frame& frame)
|
||||||
{
|
{
|
||||||
return math::quad_model_parent_get(frame.position, {}, math::percent_to_unit(frame.scale), frame.rotation,
|
return quad_model_parent_get(frame.position, {}, percent_to_unit(frame.scale), frame.rotation,
|
||||||
math::percent_to_unit(frame.skew));
|
percent_to_unit(frame.skew));
|
||||||
}
|
}
|
||||||
|
|
||||||
void frame_root_transform_apply(Frame& frame, const Frame& rootFrame, bool isRoundScale, bool isRoundRotation,
|
void frame_root_transform_apply(Frame& frame, const Frame& rootFrame, bool isRoundScale, bool isRoundRotation,
|
||||||
bool isUseRootPivot)
|
bool isUseRootPivot)
|
||||||
{
|
{
|
||||||
auto rootScale = math::percent_to_unit(rootFrame.scale);
|
auto rootScale = percent_to_unit(rootFrame.scale);
|
||||||
auto pivot = isUseRootPivot ? rootFrame.position : glm::vec2();
|
auto pivot = isUseRootPivot ? rootFrame.position : glm::vec2();
|
||||||
auto offset = (frame.position - pivot) * rootScale;
|
auto offset = (frame.position - pivot) * rootScale;
|
||||||
auto radians = glm::radians(rootFrame.rotation);
|
auto radians = glm::radians(rootFrame.rotation);
|
||||||
@@ -261,4 +257,3 @@ namespace anm2ed::model
|
|||||||
if (!isAny) return glm::vec4(-1.0f);
|
if (!isAny) return glm::vec4(-1.0f);
|
||||||
return {min.x, min.y, max.x - min.x, max.y - min.y};
|
return {min.x, min.y, max.x - min.x, max.y - min.y};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -5,8 +5,6 @@
|
|||||||
|
|
||||||
#include "model/draw.h"
|
#include "model/draw.h"
|
||||||
|
|
||||||
namespace anm2ed::model
|
|
||||||
{
|
|
||||||
void frame_mix(Frame&, const Frame&, float);
|
void frame_mix(Frame&, const Frame&, float);
|
||||||
std::vector<Frame> frame_bake_split(const Frame&, const Frame&, int, bool, bool);
|
std::vector<Frame> frame_bake_split(const Frame&, const Frame&, int, bool, bool);
|
||||||
glm::mat4 frame_parent_model_get(const Frame&);
|
glm::mat4 frame_parent_model_get(const Frame&);
|
||||||
@@ -21,4 +19,3 @@ namespace anm2ed::model
|
|||||||
void frames_sort_by_at_frame(Track&);
|
void frames_sort_by_at_frame(Track&);
|
||||||
void frames_change(Track&, FrameChange, ItemType, ChangeType, const std::set<int>&, bool isAnimationLayer = false);
|
void frames_change(Track&, FrameChange, ItemType, ChangeType, const std::set<int>&, bool isAnimationLayer = false);
|
||||||
glm::vec4 animation_rect(const Model&, const Animation&, bool, const LibraryGet& = {});
|
glm::vec4 animation_rect(const Model&, const Animation&, bool, const LibraryGet& = {});
|
||||||
}
|
|
||||||
+23
-27
@@ -13,10 +13,7 @@
|
|||||||
#include "model/xml.h"
|
#include "model/xml.h"
|
||||||
|
|
||||||
using namespace simdjson;
|
using namespace simdjson;
|
||||||
using namespace anm2ed::util;
|
|
||||||
|
|
||||||
namespace anm2ed::model
|
|
||||||
{
|
|
||||||
constexpr std::string_view INDENT = " ";
|
constexpr std::string_view INDENT = " ";
|
||||||
constexpr std::size_t LINE_WIDTH_MAX = 100;
|
constexpr std::size_t LINE_WIDTH_MAX = 100;
|
||||||
constexpr std::string_view WHITESPACE = " \t\r\n";
|
constexpr std::string_view WHITESPACE = " \t\r\n";
|
||||||
@@ -38,26 +35,26 @@ namespace anm2ed::model
|
|||||||
return start != std::string_view::npos && text[start] == '{';
|
return start != std::string_view::npos && text[start] == '{';
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Items> int index_get(const Items& items, int id)
|
template <class Items> static int index_get(const Items& items, int id)
|
||||||
{
|
{
|
||||||
auto it = std::ranges::find(items, id, &std::ranges::range_value_t<Items>::id);
|
auto it = std::ranges::find(items, id, &std::ranges::range_value_t<Items>::id);
|
||||||
return it == items.end() ? -1 : (int)(it - items.begin());
|
return it == items.end() ? -1 : (int)(it - items.begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::ivec4 color_to_bytes(const glm::vec4& color)
|
static glm::ivec4 color_to_bytes(const glm::vec4& color)
|
||||||
{
|
{
|
||||||
return {math::float_to_uint8(color.r), math::float_to_uint8(color.g), math::float_to_uint8(color.b),
|
return {float_to_uint8(color.r), float_to_uint8(color.g), float_to_uint8(color.b),
|
||||||
math::float_to_uint8(color.a)};
|
float_to_uint8(color.a)};
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec4 color_from_bytes(const glm::ivec4& bytes)
|
static glm::vec4 color_from_bytes(const glm::ivec4& bytes)
|
||||||
{
|
{
|
||||||
return {math::uint8_to_float(bytes.r), math::uint8_to_float(bytes.g), math::uint8_to_float(bytes.b),
|
return {uint8_to_float(bytes.r), uint8_to_float(bytes.g), uint8_to_float(bytes.b),
|
||||||
math::uint8_to_float(bytes.a)};
|
uint8_to_float(bytes.a)};
|
||||||
}
|
}
|
||||||
|
|
||||||
// The editor keeps dates as "MM/DD/YYYY hh:mm:ss AM"; JSON has them as ISO 8601. Anything else is kept as it is.
|
// The editor keeps dates as "MM/DD/YYYY hh:mm:ss AM"; JSON has them as ISO 8601. Anything else is kept as it is.
|
||||||
std::string date_to_iso(const std::string& date)
|
static std::string date_to_iso(const std::string& date)
|
||||||
{
|
{
|
||||||
int month{}, day{}, year{}, hour{}, minute{}, second{};
|
int month{}, day{}, year{}, hour{}, minute{}, second{};
|
||||||
char meridiem[DATE_MERIDIEM_SIZE]{};
|
char meridiem[DATE_MERIDIEM_SIZE]{};
|
||||||
@@ -68,7 +65,7 @@ namespace anm2ed::model
|
|||||||
return std::format("{:04}-{:02}-{:02}T{:02}:{:02}:{:02}", year, month, day, hour, minute, second);
|
return std::format("{:04}-{:02}-{:02}T{:02}:{:02}:{:02}", year, month, day, hour, minute, second);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string date_from_iso(const std::string& date)
|
static std::string date_from_iso(const std::string& date)
|
||||||
{
|
{
|
||||||
int year{}, month{}, day{}, hour{}, minute{}, second{};
|
int year{}, month{}, day{}, hour{}, minute{}, second{};
|
||||||
if (std::sscanf(date.c_str(), "%d-%d-%dT%d:%d:%d", &year, &month, &day, &hour, &minute, &second) != DATE_FIELDS)
|
if (std::sscanf(date.c_str(), "%d-%d-%dT%d:%d:%d", &year, &month, &day, &hour, &minute, &second) != DATE_FIELDS)
|
||||||
@@ -78,7 +75,7 @@ namespace anm2ed::model
|
|||||||
hour < HOURS_HALF_DAY ? "AM" : "PM");
|
hour < HOURS_HALF_DAY ? "AM" : "PM");
|
||||||
}
|
}
|
||||||
|
|
||||||
void line_break(std::string& text, int depth)
|
static void line_break(std::string& text, int depth)
|
||||||
{
|
{
|
||||||
text += '\n';
|
text += '\n';
|
||||||
for (int i = 0; i < depth; ++i)
|
for (int i = 0; i < depth; ++i)
|
||||||
@@ -161,7 +158,7 @@ namespace anm2ed::model
|
|||||||
void value(int value) { number(value); }
|
void value(int value) { number(value); }
|
||||||
void value(float value) { number(value); }
|
void value(float value) { number(value); }
|
||||||
void value(const std::string& value) { this->value(std::string_view(value)); }
|
void value(const std::string& value) { this->value(std::string_view(value)); }
|
||||||
void value(const std::filesystem::path& value) { this->value(path::to_utf8(value)); }
|
void value(const std::filesystem::path& value) { this->value(path_to_utf8(value)); }
|
||||||
|
|
||||||
void value(std::string_view value)
|
void value(std::string_view value)
|
||||||
{
|
{
|
||||||
@@ -277,7 +274,7 @@ namespace anm2ed::model
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Each returns what it expected when the value is the wrong kind (and leaves the value as it was).
|
// Each returns what it expected when the value is the wrong kind (and leaves the value as it was).
|
||||||
std::string_view value_read(dom::element element, bool& value)
|
static std::string_view value_read(dom::element element, bool& value)
|
||||||
{
|
{
|
||||||
bool read{};
|
bool read{};
|
||||||
if (element.get(read)) return "true or false";
|
if (element.get(read)) return "true or false";
|
||||||
@@ -295,7 +292,7 @@ namespace anm2ed::model
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string_view value_read(dom::element element, std::string& value)
|
static std::string_view value_read(dom::element element, std::string& value)
|
||||||
{
|
{
|
||||||
std::string_view read{};
|
std::string_view read{};
|
||||||
if (element.get(read)) return "a string";
|
if (element.get(read)) return "a string";
|
||||||
@@ -303,11 +300,11 @@ namespace anm2ed::model
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string_view value_read(dom::element element, std::filesystem::path& value)
|
static std::string_view value_read(dom::element element, std::filesystem::path& value)
|
||||||
{
|
{
|
||||||
std::string read{};
|
std::string read{};
|
||||||
auto expected = value_read(element, read);
|
auto expected = value_read(element, read);
|
||||||
if (expected.empty()) value = path::from_utf8(read);
|
if (expected.empty()) value = path_from_utf8(read);
|
||||||
return expected;
|
return expected;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -325,7 +322,7 @@ namespace anm2ed::model
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> std::string_view value_read(dom::element element, std::vector<T>& value)
|
template <class T> static std::string_view value_read(dom::element element, std::vector<T>& value)
|
||||||
{
|
{
|
||||||
dom::array array{};
|
dom::array array{};
|
||||||
if (element.get(array)) return "an array";
|
if (element.get(array)) return "an array";
|
||||||
@@ -478,7 +475,7 @@ namespace anm2ed::model
|
|||||||
|
|
||||||
// Each part of the document is described once; with a JsonWriter it is written, with a JsonReader read.
|
// Each part of the document is described once; with a JsonWriter it is written, with a JsonReader read.
|
||||||
|
|
||||||
template <class Io, class F> void frame_io(Io& io, F& frame, ItemType type, const std::vector<Region>& regions)
|
template <class Io, class F> static void frame_io(Io& io, F& frame, ItemType type, const std::vector<Region>& regions)
|
||||||
{
|
{
|
||||||
static const Frame FRAME_DEFAULT{};
|
static const Frame FRAME_DEFAULT{};
|
||||||
auto& content = io.model.content;
|
auto& content = io.model.content;
|
||||||
@@ -530,7 +527,7 @@ namespace anm2ed::model
|
|||||||
io.list(name, frames, [&](auto& frameIo, auto& frame) { frame_io(frameIo, frame, type, regions); }, true, false);
|
io.list(name, frames, [&](auto& frameIo, auto& frame) { frame_io(frameIo, frame, type, regions); }, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Io, class T> void track_io(Io& io, T& track, ItemType type)
|
template <class Io, class T> static void track_io(Io& io, T& track, ItemType type)
|
||||||
{
|
{
|
||||||
auto isLayer = type == ItemType::LAYER;
|
auto isLayer = type == ItemType::LAYER;
|
||||||
if constexpr (Io::IS_READING) track.type = type;
|
if constexpr (Io::IS_READING) track.type = type;
|
||||||
@@ -548,7 +545,7 @@ namespace anm2ed::model
|
|||||||
}
|
}
|
||||||
|
|
||||||
// A group is an entry with a "group" name, its root and its own tracks.
|
// A group is an entry with a "group" name, its root and its own tracks.
|
||||||
template <class Io, class Entries> void entries_io(Io& io, std::string_view name, Entries& entries, ItemType type)
|
template <class Io, class Entries> static void entries_io(Io& io, std::string_view name, Entries& entries, ItemType type)
|
||||||
{
|
{
|
||||||
io.list(
|
io.list(
|
||||||
name, entries,
|
name, entries,
|
||||||
@@ -581,7 +578,7 @@ namespace anm2ed::model
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Io, class A> void animation_io(Io& io, A& animation)
|
template <class Io, class A> static void animation_io(Io& io, A& animation)
|
||||||
{
|
{
|
||||||
io.field("length", animation.frameNum, 1);
|
io.field("length", animation.frameNum, 1);
|
||||||
io.field("loop", animation.isLoop, true);
|
io.field("loop", animation.isLoop, true);
|
||||||
@@ -596,7 +593,7 @@ namespace anm2ed::model
|
|||||||
|
|
||||||
// Animations (and groups, which hold an "animations" object) are keyed by name; a repeated name is renumbered.
|
// Animations (and groups, which hold an "animations" object) are keyed by name; a repeated name is renumbered.
|
||||||
// Animation names are unique document-wide (default names one); a group's only among the top-level keys.
|
// Animation names are unique document-wide (default names one); a group's only among the top-level keys.
|
||||||
void animations_write(JsonWriter& io, const Model& model)
|
static void animations_write(JsonWriter& io, const Model& model)
|
||||||
{
|
{
|
||||||
std::set<std::string> animationNames{};
|
std::set<std::string> animationNames{};
|
||||||
std::set<std::string> keys{};
|
std::set<std::string> keys{};
|
||||||
@@ -649,7 +646,7 @@ namespace anm2ed::model
|
|||||||
false);
|
false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void animations_read(JsonReader& io, Model& model)
|
static void animations_read(JsonReader& io, Model& model)
|
||||||
{
|
{
|
||||||
auto animation_read = [&](std::string_view name, JsonReader& animationIo)
|
auto animation_read = [&](std::string_view name, JsonReader& animationIo)
|
||||||
{
|
{
|
||||||
@@ -694,7 +691,7 @@ namespace anm2ed::model
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Content comes before animations, which read it (and anything named comes before what names it).
|
// Content comes before animations, which read it (and anything named comes before what names it).
|
||||||
template <class Io, class M> void model_io(Io& io, M& model)
|
template <class Io, class M> static void model_io(Io& io, M& model)
|
||||||
{
|
{
|
||||||
auto& content = model.content;
|
auto& content = model.content;
|
||||||
io.object(
|
io.object(
|
||||||
@@ -818,4 +815,3 @@ namespace anm2ed::model
|
|||||||
if (issues.size() > ISSUES_SHOWN_MAX) *errorString += std::format("\n({} more)", issues.size() - ISSUES_SHOWN_MAX);
|
if (issues.size() > ISSUES_SHOWN_MAX) *errorString += std::format("\n({} more)", issues.size() - ISSUES_SHOWN_MAX);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -7,9 +7,6 @@
|
|||||||
|
|
||||||
// The editor's own JSON document: content items in arrays (an item's index is its id), animations keyed by their
|
// The editor's own JSON document: content items in arrays (an item's index is its id), animations keyed by their
|
||||||
// unique name, and every value left out when it is the default. Unknown XML (extras) is not kept.
|
// unique name, and every value left out when it is the default. Unknown XML (extras) is not kept.
|
||||||
namespace anm2ed::model
|
|
||||||
{
|
|
||||||
bool is_json(std::string_view);
|
bool is_json(std::string_view);
|
||||||
std::string model_to_json(const Model&);
|
std::string model_to_json(const Model&);
|
||||||
bool model_from_json(Model&, std::string_view, std::string* = nullptr);
|
bool model_from_json(Model&, std::string_view, std::string* = nullptr);
|
||||||
}
|
|
||||||
+13
-18
@@ -6,12 +6,8 @@
|
|||||||
#include "image.h"
|
#include "image.h"
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
|
|
||||||
using namespace anm2ed::util;
|
|
||||||
|
|
||||||
namespace anm2ed::model
|
|
||||||
{
|
|
||||||
// The slot holding the animation at a flat index (animations inside groups count in order), or nullptr.
|
// The slot holding the animation at a flat index (animations inside groups count in order), or nullptr.
|
||||||
template <class Entries> auto animation_slot_get(Entries& entries, int index) -> decltype(&std::get<0>(entries[0]))
|
template <class Entries> static auto animation_slot_get(Entries& entries, int index) -> decltype(&std::get<0>(entries[0]))
|
||||||
{
|
{
|
||||||
if (index < 0) return nullptr;
|
if (index < 0) return nullptr;
|
||||||
for (auto& entry : entries)
|
for (auto& entry : entries)
|
||||||
@@ -67,7 +63,7 @@ namespace anm2ed::model
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Self> auto animation_group_find(Self& self, int index)
|
template <class Self> static auto animation_group_find(Self& self, int index)
|
||||||
{
|
{
|
||||||
using Group = std::conditional_t<std::is_const_v<Self>, const AnimationGroup, AnimationGroup>;
|
using Group = std::conditional_t<std::is_const_v<Self>, const AnimationGroup, AnimationGroup>;
|
||||||
Group* result{};
|
Group* result{};
|
||||||
@@ -95,7 +91,7 @@ namespace anm2ed::model
|
|||||||
return group ? group->id : -1;
|
return group ? group->id : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class A> auto animation_track_group_find(A& animation, int groupType, int groupId)
|
template <class A> static auto animation_track_group_find(A& animation, int groupType, int groupId)
|
||||||
{
|
{
|
||||||
using Group = std::conditional_t<std::is_const_v<A>, const TrackGroup, TrackGroup>;
|
using Group = std::conditional_t<std::is_const_v<A>, const TrackGroup, TrackGroup>;
|
||||||
Group* result{};
|
Group* result{};
|
||||||
@@ -120,7 +116,7 @@ namespace anm2ed::model
|
|||||||
|
|
||||||
// A track by item type and id; a group root when the item is ROOT with a group, and grouped tracks only match their
|
// A track by item type and id; a group root when the item is ROOT with a group, and grouped tracks only match their
|
||||||
// own group when one is given.
|
// own group when one is given.
|
||||||
template <class A> auto animation_track_find(A& animation, int itemType, int id, int groupType, int groupId)
|
template <class A> static auto animation_track_find(A& animation, int itemType, int id, int groupType, int groupId)
|
||||||
{
|
{
|
||||||
using T = std::conditional_t<std::is_const_v<A>, const Track, Track>;
|
using T = std::conditional_t<std::is_const_v<A>, const Track, Track>;
|
||||||
T* result{};
|
T* result{};
|
||||||
@@ -214,7 +210,7 @@ namespace anm2ed::model
|
|||||||
return resolved;
|
return resolved;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Items> std::set<int> unused_ids_get(const Items& items, const std::set<int>& used)
|
template <class Items> static std::set<int> unused_ids_get(const Items& items, const std::set<int>& used)
|
||||||
{
|
{
|
||||||
std::set<int> unused{};
|
std::set<int> unused{};
|
||||||
for (const auto& item : items)
|
for (const auto& item : items)
|
||||||
@@ -334,7 +330,7 @@ namespace anm2ed::model
|
|||||||
return handle.frame ? handle.frame : handle.item ? handle.item : handle.animation;
|
return handle.frame ? handle.frame : handle.item ? handle.item : handle.animation;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Callback> void animation_uids_each(Animation& animation, Callback&& callback)
|
template <class Callback> static void animation_uids_each(Animation& animation, Callback&& callback)
|
||||||
{
|
{
|
||||||
callback(animation.uid);
|
callback(animation.uid);
|
||||||
for (auto* entries : {&animation.layers, &animation.nulls})
|
for (auto* entries : {&animation.layers, &animation.nulls})
|
||||||
@@ -354,7 +350,7 @@ namespace anm2ed::model
|
|||||||
std::unordered_set<std::uint64_t> seen{};
|
std::unordered_set<std::uint64_t> seen{};
|
||||||
auto repair = [&](std::uint64_t& uid)
|
auto repair = [&](std::uint64_t& uid)
|
||||||
{
|
{
|
||||||
if (!uid || !seen.insert(uid).second) uid = util::uid_next();
|
if (!uid || !seen.insert(uid).second) uid = uid_next();
|
||||||
};
|
};
|
||||||
|
|
||||||
for (int i = 0; i < animations_count_get(); ++i)
|
for (int i = 0; i < animations_count_get(); ++i)
|
||||||
@@ -395,7 +391,7 @@ namespace anm2ed::model
|
|||||||
std::set<int> ids{};
|
std::set<int> ids{};
|
||||||
for (const auto& layer : model.content.layers)
|
for (const auto& layer : model.content.layers)
|
||||||
if (auto spritesheet = item_get(model.content.spritesheets, layer.spritesheetId);
|
if (auto spritesheet = item_get(model.content.spritesheets, layer.spritesheetId);
|
||||||
spritesheet && !layer.is_animation() && path::is_extension(spritesheet->path, resource::image::SVG_EXTENSION))
|
spritesheet && !layer.is_animation() && is_path_extension(spritesheet->path, SVG_EXTENSION))
|
||||||
ids.insert(spritesheet->id);
|
ids.insert(spritesheet->id);
|
||||||
return ids;
|
return ids;
|
||||||
}
|
}
|
||||||
@@ -428,25 +424,25 @@ namespace anm2ed::model
|
|||||||
|
|
||||||
Frame frame_clone(Frame frame)
|
Frame frame_clone(Frame frame)
|
||||||
{
|
{
|
||||||
frame.uid = util::uid_next();
|
frame.uid = uid_next();
|
||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
Track track_clone(Track track)
|
Track track_clone(Track track)
|
||||||
{
|
{
|
||||||
track.uid = util::uid_next();
|
track.uid = uid_next();
|
||||||
for (auto& frame : track.frames)
|
for (auto& frame : track.frames)
|
||||||
frame.uid = util::uid_next();
|
frame.uid = uid_next();
|
||||||
return track;
|
return track;
|
||||||
}
|
}
|
||||||
|
|
||||||
Animation animation_clone(Animation animation)
|
Animation animation_clone(Animation animation)
|
||||||
{
|
{
|
||||||
animation_uids_each(animation, [](std::uint64_t& uid) { uid = util::uid_next(); });
|
animation_uids_each(animation, [](std::uint64_t& uid) { uid = uid_next(); });
|
||||||
return animation;
|
return animation;
|
||||||
}
|
}
|
||||||
|
|
||||||
void track_locations_add(std::unordered_map<std::uint64_t, UidIndex::Location>& locations, const Track& track,
|
static void track_locations_add(std::unordered_map<std::uint64_t, UidIndex::Location>& locations, const Track& track,
|
||||||
Reference reference)
|
Reference reference)
|
||||||
{
|
{
|
||||||
constexpr ElementType TRACK_TYPES[] = {ElementType::UNKNOWN, ElementType::ROOT_ANIMATION,
|
constexpr ElementType TRACK_TYPES[] = {ElementType::UNKNOWN, ElementType::ROOT_ANIMATION,
|
||||||
@@ -529,4 +525,3 @@ namespace anm2ed::model
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
+14
-17
@@ -15,8 +15,6 @@
|
|||||||
#include "uid.h"
|
#include "uid.h"
|
||||||
|
|
||||||
// The typed document model. XML exists only in model/xml.cpp; everything else edits and reads these structs.
|
// The typed document model. XML exists only in model/xml.cpp; everything else edits and reads these structs.
|
||||||
namespace anm2ed::model
|
|
||||||
{
|
|
||||||
// An XML element the editor does not understand, kept verbatim so it survives a save.
|
// An XML element the editor does not understand, kept verbatim so it survives a save.
|
||||||
struct XmlNode
|
struct XmlNode
|
||||||
{
|
{
|
||||||
@@ -41,7 +39,7 @@ namespace anm2ed::model
|
|||||||
// A keyframe; on a triggers track the same struct is a trigger (atFrame, eventIds, soundIds).
|
// A keyframe; on a triggers track the same struct is a trigger (atFrame, eventIds, soundIds).
|
||||||
struct Frame
|
struct Frame
|
||||||
{
|
{
|
||||||
std::uint64_t uid{util::uid_next()};
|
std::uint64_t uid{uid_next()};
|
||||||
glm::vec2 crop{};
|
glm::vec2 crop{};
|
||||||
glm::vec2 size{};
|
glm::vec2 size{};
|
||||||
glm::vec2 pivot{};
|
glm::vec2 pivot{};
|
||||||
@@ -49,7 +47,7 @@ namespace anm2ed::model
|
|||||||
glm::vec2 scale{100.0f, 100.0f};
|
glm::vec2 scale{100.0f, 100.0f};
|
||||||
glm::vec2 skew{};
|
glm::vec2 skew{};
|
||||||
float rotation{};
|
float rotation{};
|
||||||
glm::vec4 tint{types::color::WHITE};
|
glm::vec4 tint{COLOR_WHITE};
|
||||||
glm::vec4 colorOffset{};
|
glm::vec4 colorOffset{};
|
||||||
int duration{1};
|
int duration{1};
|
||||||
bool isVisible{true};
|
bool isVisible{true};
|
||||||
@@ -74,7 +72,7 @@ namespace anm2ed::model
|
|||||||
|
|
||||||
struct Track
|
struct Track
|
||||||
{
|
{
|
||||||
std::uint64_t uid{util::uid_next()};
|
std::uint64_t uid{uid_next()};
|
||||||
ItemType type{ItemType::LAYER};
|
ItemType type{ItemType::LAYER};
|
||||||
int id{-1};
|
int id{-1};
|
||||||
bool isVisible{true};
|
bool isVisible{true};
|
||||||
@@ -86,7 +84,7 @@ namespace anm2ed::model
|
|||||||
|
|
||||||
struct TrackGroup
|
struct TrackGroup
|
||||||
{
|
{
|
||||||
std::uint64_t uid{util::uid_next()};
|
std::uint64_t uid{uid_next()};
|
||||||
int id{-1};
|
int id{-1};
|
||||||
std::string name{};
|
std::string name{};
|
||||||
bool isExpanded{true};
|
bool isExpanded{true};
|
||||||
@@ -102,7 +100,7 @@ namespace anm2ed::model
|
|||||||
|
|
||||||
struct Animation
|
struct Animation
|
||||||
{
|
{
|
||||||
std::uint64_t uid{util::uid_next()};
|
std::uint64_t uid{uid_next()};
|
||||||
std::string name{};
|
std::string name{};
|
||||||
int frameNum{1};
|
int frameNum{1};
|
||||||
bool isLoop{true};
|
bool isLoop{true};
|
||||||
@@ -124,7 +122,7 @@ namespace anm2ed::model
|
|||||||
|
|
||||||
struct AnimationGroup
|
struct AnimationGroup
|
||||||
{
|
{
|
||||||
std::uint64_t uid{util::uid_next()};
|
std::uint64_t uid{uid_next()};
|
||||||
int id{-1};
|
int id{-1};
|
||||||
std::string name{};
|
std::string name{};
|
||||||
bool isExpanded{true};
|
bool isExpanded{true};
|
||||||
@@ -139,7 +137,7 @@ namespace anm2ed::model
|
|||||||
|
|
||||||
struct Region
|
struct Region
|
||||||
{
|
{
|
||||||
std::uint64_t uid{util::uid_next()};
|
std::uint64_t uid{uid_next()};
|
||||||
int id{-1};
|
int id{-1};
|
||||||
std::string name{};
|
std::string name{};
|
||||||
glm::vec2 crop{};
|
glm::vec2 crop{};
|
||||||
@@ -153,7 +151,7 @@ namespace anm2ed::model
|
|||||||
|
|
||||||
struct Spritesheet
|
struct Spritesheet
|
||||||
{
|
{
|
||||||
std::uint64_t uid{util::uid_next()};
|
std::uint64_t uid{uid_next()};
|
||||||
int id{-1};
|
int id{-1};
|
||||||
std::filesystem::path path{};
|
std::filesystem::path path{};
|
||||||
std::vector<Region> regions{};
|
std::vector<Region> regions{};
|
||||||
@@ -185,7 +183,7 @@ namespace anm2ed::model
|
|||||||
|
|
||||||
struct Shader
|
struct Shader
|
||||||
{
|
{
|
||||||
std::uint64_t uid{util::uid_next()};
|
std::uint64_t uid{uid_next()};
|
||||||
int id{-1};
|
int id{-1};
|
||||||
std::string name{};
|
std::string name{};
|
||||||
std::filesystem::path vertex{};
|
std::filesystem::path vertex{};
|
||||||
@@ -198,7 +196,7 @@ namespace anm2ed::model
|
|||||||
|
|
||||||
struct Layer
|
struct Layer
|
||||||
{
|
{
|
||||||
std::uint64_t uid{util::uid_next()};
|
std::uint64_t uid{uid_next()};
|
||||||
int id{-1};
|
int id{-1};
|
||||||
std::string name{};
|
std::string name{};
|
||||||
int spritesheetId{};
|
int spritesheetId{};
|
||||||
@@ -215,7 +213,7 @@ namespace anm2ed::model
|
|||||||
// Another .anm2 whose animations this one's layers can play.
|
// Another .anm2 whose animations this one's layers can play.
|
||||||
struct Library
|
struct Library
|
||||||
{
|
{
|
||||||
std::uint64_t uid{util::uid_next()};
|
std::uint64_t uid{uid_next()};
|
||||||
int id{-1};
|
int id{-1};
|
||||||
std::filesystem::path path{};
|
std::filesystem::path path{};
|
||||||
Extras extras{};
|
Extras extras{};
|
||||||
@@ -225,7 +223,7 @@ namespace anm2ed::model
|
|||||||
|
|
||||||
struct Null
|
struct Null
|
||||||
{
|
{
|
||||||
std::uint64_t uid{util::uid_next()};
|
std::uint64_t uid{uid_next()};
|
||||||
int id{-1};
|
int id{-1};
|
||||||
std::string name{};
|
std::string name{};
|
||||||
bool isShowRect{};
|
bool isShowRect{};
|
||||||
@@ -236,7 +234,7 @@ namespace anm2ed::model
|
|||||||
|
|
||||||
struct Event
|
struct Event
|
||||||
{
|
{
|
||||||
std::uint64_t uid{util::uid_next()};
|
std::uint64_t uid{uid_next()};
|
||||||
int id{-1};
|
int id{-1};
|
||||||
std::string name{};
|
std::string name{};
|
||||||
Extras extras{};
|
Extras extras{};
|
||||||
@@ -246,7 +244,7 @@ namespace anm2ed::model
|
|||||||
|
|
||||||
struct Sound
|
struct Sound
|
||||||
{
|
{
|
||||||
std::uint64_t uid{util::uid_next()};
|
std::uint64_t uid{uid_next()};
|
||||||
int id{-1};
|
int id{-1};
|
||||||
std::filesystem::path path{};
|
std::filesystem::path path{};
|
||||||
Extras extras{};
|
Extras extras{};
|
||||||
@@ -420,4 +418,3 @@ namespace anm2ed::model
|
|||||||
Animation animation_clone(Animation);
|
Animation animation_clone(Animation);
|
||||||
Frame frame_clone(Frame);
|
Frame frame_clone(Frame);
|
||||||
Track track_clone(Track);
|
Track track_clone(Track);
|
||||||
}
|
|
||||||
+91
-96
@@ -19,10 +19,6 @@
|
|||||||
#include "path.h"
|
#include "path.h"
|
||||||
#include "timestamp.h"
|
#include "timestamp.h"
|
||||||
|
|
||||||
using namespace anm2ed::util;
|
|
||||||
|
|
||||||
namespace anm2ed::model
|
|
||||||
{
|
|
||||||
constexpr std::string_view ELEMENT_TAGS[] = {
|
constexpr std::string_view ELEMENT_TAGS[] = {
|
||||||
#define X(symbol, tag) tag,
|
#define X(symbol, tag) tag,
|
||||||
ANM2_ELEMENT_TYPES
|
ANM2_ELEMENT_TYPES
|
||||||
@@ -68,15 +64,15 @@ namespace anm2ed::model
|
|||||||
constexpr std::uint64_t HASH_PRIME = 1099511628211ull;
|
constexpr std::uint64_t HASH_PRIME = 1099511628211ull;
|
||||||
constexpr Flags CLIPBOARD_FLAGS = SERIALIZE_EDITOR_DEFAULT;
|
constexpr Flags CLIPBOARD_FLAGS = SERIALIZE_EDITOR_DEFAULT;
|
||||||
|
|
||||||
const char* tag_get(ElementType type) { return ELEMENT_TAGS[(int)type].data(); }
|
static const char* tag_get(ElementType type) { return ELEMENT_TAGS[(int)type].data(); }
|
||||||
|
|
||||||
ElementType type_get(pugi::xml_node element)
|
static ElementType type_get(pugi::xml_node element)
|
||||||
{
|
{
|
||||||
auto it = std::ranges::find(ELEMENT_TAGS, std::string_view(element.name()));
|
auto it = std::ranges::find(ELEMENT_TAGS, std::string_view(element.name()));
|
||||||
return it == std::end(ELEMENT_TAGS) ? ElementType::UNKNOWN : (ElementType)(it - std::begin(ELEMENT_TAGS));
|
return it == std::end(ELEMENT_TAGS) ? ElementType::UNKNOWN : (ElementType)(it - std::begin(ELEMENT_TAGS));
|
||||||
}
|
}
|
||||||
|
|
||||||
ElementType track_element_type_get(ItemType type)
|
static ElementType track_element_type_get(ItemType type)
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
@@ -95,27 +91,27 @@ namespace anm2ed::model
|
|||||||
|
|
||||||
// Numbers and booleans read as tinyxml2 (which older builds used) reads them: "%d" and "%f" on the leading text,
|
// Numbers and booleans read as tinyxml2 (which older builds used) reads them: "%d" and "%f" on the leading text,
|
||||||
// and booleans as a number or true/false.
|
// and booleans as a number or true/false.
|
||||||
const char* attribute_get(pugi::xml_node element, const char* name)
|
static const char* attribute_get(pugi::xml_node element, const char* name)
|
||||||
{
|
{
|
||||||
auto attribute = element.attribute(name);
|
auto attribute = element.attribute(name);
|
||||||
return attribute ? attribute.value() : nullptr;
|
return attribute ? attribute.value() : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_int_read(const char* text, int& value) { return text && std::sscanf(text, "%d", &value) == 1; }
|
static bool is_int_read(const char* text, int& value) { return text && std::sscanf(text, "%d", &value) == 1; }
|
||||||
|
|
||||||
int int_get(pugi::xml_node element, const char* name, int value = -1)
|
static int int_get(pugi::xml_node element, const char* name, int value = -1)
|
||||||
{
|
{
|
||||||
is_int_read(attribute_get(element, name), value);
|
is_int_read(attribute_get(element, name), value);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
float float_get(pugi::xml_node element, const char* name, float value = 0.0f)
|
static float float_get(pugi::xml_node element, const char* name, float value = 0.0f)
|
||||||
{
|
{
|
||||||
if (auto text = attribute_get(element, name)) std::sscanf(text, "%f", &value);
|
if (auto text = attribute_get(element, name)) std::sscanf(text, "%f", &value);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bool_get(pugi::xml_node element, const char* name, bool value)
|
static bool bool_get(pugi::xml_node element, const char* name, bool value)
|
||||||
{
|
{
|
||||||
auto text = attribute_get(element, name);
|
auto text = attribute_get(element, name);
|
||||||
if (int number{}; is_int_read(text, number)) return number != 0;
|
if (int number{}; is_int_read(text, number)) return number != 0;
|
||||||
@@ -125,32 +121,32 @@ namespace anm2ed::model
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string string_get(pugi::xml_node element, const char* name, std::string value = {})
|
static std::string string_get(pugi::xml_node element, const char* name, std::string value = {})
|
||||||
{
|
{
|
||||||
if (auto attribute = attribute_get(element, name)) value = attribute;
|
if (auto attribute = attribute_get(element, name)) value = attribute;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::filesystem::path path_get(pugi::xml_node element, const char* name)
|
static std::filesystem::path path_get(pugi::xml_node element, const char* name)
|
||||||
{
|
{
|
||||||
auto attribute = attribute_get(element, name);
|
auto attribute = attribute_get(element, name);
|
||||||
return attribute ? path::from_utf8(attribute) : std::filesystem::path{};
|
return attribute ? path_from_utf8(attribute) : std::filesystem::path{};
|
||||||
}
|
}
|
||||||
|
|
||||||
float color_get(pugi::xml_node element, const char* name, float value)
|
static float color_get(pugi::xml_node element, const char* name, float value)
|
||||||
{
|
{
|
||||||
if (int color{}; is_int_read(attribute_get(element, name), color)) value = math::uint8_to_float(color);
|
if (int color{}; is_int_read(attribute_get(element, name), color)) value = uint8_to_float(color);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// An element's text: its first child, when that is text.
|
// An element's text: its first child, when that is text.
|
||||||
const char* text_get(pugi::xml_node element)
|
static const char* text_get(pugi::xml_node element)
|
||||||
{
|
{
|
||||||
auto first = element.first_child();
|
auto first = element.first_child();
|
||||||
return first.type() == pugi::node_pcdata || first.type() == pugi::node_cdata ? first.value() : nullptr;
|
return first.type() == pugi::node_pcdata || first.type() == pugi::node_cdata ? first.value() : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Interpolation interpolation_read(pugi::xml_node element, const char* name)
|
static Interpolation interpolation_read(pugi::xml_node element, const char* name)
|
||||||
{
|
{
|
||||||
auto value = attribute_get(element, name);
|
auto value = attribute_get(element, name);
|
||||||
if (!value) return Interpolation::NONE;
|
if (!value) return Interpolation::NONE;
|
||||||
@@ -159,7 +155,7 @@ namespace anm2ed::model
|
|||||||
return bool_get(element, name, false) ? Interpolation::LINEAR : Interpolation::NONE;
|
return bool_get(element, name, false) ? Interpolation::LINEAR : Interpolation::NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
pugi::xml_node element_next(pugi::xml_node node)
|
static pugi::xml_node element_next(pugi::xml_node node)
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
node = node.next_sibling();
|
node = node.next_sibling();
|
||||||
@@ -167,14 +163,14 @@ namespace anm2ed::model
|
|||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
pugi::xml_node element_first(pugi::xml_node parent)
|
static pugi::xml_node element_first(pugi::xml_node parent)
|
||||||
{
|
{
|
||||||
auto child = parent.first_child();
|
auto child = parent.first_child();
|
||||||
return !child || child.type() == pugi::node_element ? child : element_next(child);
|
return !child || child.type() == pugi::node_element ? child : element_next(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shader elements are only read where they belong; one anywhere else is dropped.
|
// Shader elements are only read where they belong; one anywhere else is dropped.
|
||||||
bool is_child_kept(pugi::xml_node parent, pugi::xml_node child)
|
static bool is_child_kept(pugi::xml_node parent, pugi::xml_node child)
|
||||||
{
|
{
|
||||||
std::string_view tag = child.name();
|
std::string_view tag = child.name();
|
||||||
if (tag == LEGACY_OVERLAY_TAG || tag == SOURCE_DOCUMENT_TAG) return false;
|
if (tag == LEGACY_OVERLAY_TAG || tag == SOURCE_DOCUMENT_TAG) return false;
|
||||||
@@ -195,7 +191,7 @@ namespace anm2ed::model
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Child elements with their position, skipping legacy Overlay, nested SourceDocument copies and misplaced shaders.
|
// Child elements with their position, skipping legacy Overlay, nested SourceDocument copies and misplaced shaders.
|
||||||
template <class Callback> void children_each(pugi::xml_node parent, Callback&& callback)
|
template <class Callback> static void children_each(pugi::xml_node parent, Callback&& callback)
|
||||||
{
|
{
|
||||||
int position{};
|
int position{};
|
||||||
for (auto child : parent.children())
|
for (auto child : parent.children())
|
||||||
@@ -204,7 +200,7 @@ namespace anm2ed::model
|
|||||||
}
|
}
|
||||||
|
|
||||||
// A repeated attribute keeps its first position and last value.
|
// A repeated attribute keeps its first position and last value.
|
||||||
void attribute_read(std::vector<std::pair<std::string, std::string>>& attributes, pugi::xml_attribute attribute)
|
static void attribute_read(std::vector<std::pair<std::string, std::string>>& attributes, pugi::xml_attribute attribute)
|
||||||
{
|
{
|
||||||
auto existing = std::ranges::find(attributes, std::string_view(attribute.name()),
|
auto existing = std::ranges::find(attributes, std::string_view(attribute.name()),
|
||||||
[](const auto& pair) { return std::string_view(pair.first); });
|
[](const auto& pair) { return std::string_view(pair.first); });
|
||||||
@@ -214,7 +210,7 @@ namespace anm2ed::model
|
|||||||
attributes.emplace_back(attribute.name(), attribute.value());
|
attributes.emplace_back(attribute.name(), attribute.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlNode node_read(pugi::xml_node element)
|
static XmlNode node_read(pugi::xml_node element)
|
||||||
{
|
{
|
||||||
XmlNode node{.tag = element.name()};
|
XmlNode node{.tag = element.name()};
|
||||||
for (auto attribute : element.attributes())
|
for (auto attribute : element.attributes())
|
||||||
@@ -224,7 +220,7 @@ namespace anm2ed::model
|
|||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
Extras extras_read(pugi::xml_node element)
|
static Extras extras_read(pugi::xml_node element)
|
||||||
{
|
{
|
||||||
Extras extras{};
|
Extras extras{};
|
||||||
for (auto attribute : element.attributes())
|
for (auto attribute : element.attributes())
|
||||||
@@ -234,12 +230,12 @@ namespace anm2ed::model
|
|||||||
return extras;
|
return extras;
|
||||||
}
|
}
|
||||||
|
|
||||||
void extras_child_add(Extras& extras, pugi::xml_node child, int position)
|
static void extras_child_add(Extras& extras, pugi::xml_node child, int position)
|
||||||
{
|
{
|
||||||
extras.children.emplace_back(position, node_read(child));
|
extras.children.emplace_back(position, node_read(child));
|
||||||
}
|
}
|
||||||
|
|
||||||
Frame frame_read(pugi::xml_node element)
|
static Frame frame_read(pugi::xml_node element)
|
||||||
{
|
{
|
||||||
Frame frame{};
|
Frame frame{};
|
||||||
frame.crop = {float_get(element, "XCrop"), float_get(element, "YCrop")};
|
frame.crop = {float_get(element, "XCrop"), float_get(element, "YCrop")};
|
||||||
@@ -292,7 +288,7 @@ namespace anm2ed::model
|
|||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
Track track_read(pugi::xml_node element, ItemType type)
|
static Track track_read(pugi::xml_node element, ItemType type)
|
||||||
{
|
{
|
||||||
Track track{.type = type, .isVisible = bool_get(element, "Visible", true), .extras = extras_read(element)};
|
Track track{.type = type, .isVisible = bool_get(element, "Visible", true), .extras = extras_read(element)};
|
||||||
if (type == ItemType::LAYER) track.id = int_get(element, "LayerId");
|
if (type == ItemType::LAYER) track.id = int_get(element, "LayerId");
|
||||||
@@ -340,12 +336,12 @@ namespace anm2ed::model
|
|||||||
using TrackItem = ContainerItem<Track, TrackGroup>;
|
using TrackItem = ContainerItem<Track, TrackGroup>;
|
||||||
using AnimationItem = ContainerItem<std::shared_ptr<const Animation>, AnimationGroup>;
|
using AnimationItem = ContainerItem<std::shared_ptr<const Animation>, AnimationGroup>;
|
||||||
|
|
||||||
auto& group_children_get(TrackGroup& group) { return group.tracks; }
|
static auto& group_children_get(TrackGroup& group) { return group.tracks; }
|
||||||
auto& group_children_get(AnimationGroup& group) { return group.animations; }
|
static auto& group_children_get(AnimationGroup& group) { return group.animations; }
|
||||||
|
|
||||||
// Groups become entries followed by their children: nested children move out after their group, and a child joins a
|
// Groups become entries followed by their children: nested children move out after their group, and a child joins a
|
||||||
// group seen before it. Unknown XML becomes extras at its position.
|
// group seen before it. Unknown XML becomes extras at its position.
|
||||||
template <class Entry, class Item> std::vector<Entry> entries_build(std::vector<Item> items, Extras& extras)
|
template <class Entry, class Item> static std::vector<Entry> entries_build(std::vector<Item> items, Extras& extras)
|
||||||
{
|
{
|
||||||
int nextGroupId{};
|
int nextGroupId{};
|
||||||
for (const auto& item : items)
|
for (const auto& item : items)
|
||||||
@@ -387,7 +383,7 @@ namespace anm2ed::model
|
|||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
TrackItem track_group_item_read(pugi::xml_node element, ItemType type)
|
static TrackItem track_group_item_read(pugi::xml_node element, ItemType type)
|
||||||
{
|
{
|
||||||
TrackItem item{.group = TrackGroup{.id = int_get(element, "Id"),
|
TrackItem item{.group = TrackGroup{.id = int_get(element, "Id"),
|
||||||
.name = string_get(element, "Name"),
|
.name = string_get(element, "Name"),
|
||||||
@@ -419,7 +415,7 @@ namespace anm2ed::model
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<TrackItem> track_items_read(pugi::xml_node container, ItemType type)
|
static std::vector<TrackItem> track_items_read(pugi::xml_node container, ItemType type)
|
||||||
{
|
{
|
||||||
std::vector<TrackItem> items{};
|
std::vector<TrackItem> items{};
|
||||||
children_each(container,
|
children_each(container,
|
||||||
@@ -437,7 +433,7 @@ namespace anm2ed::model
|
|||||||
|
|
||||||
// Track groups as any version wrote them: legacy *AnimationGroups metadata is placed back at its Index, and a group
|
// Track groups as any version wrote them: legacy *AnimationGroups metadata is placed back at its Index, and a group
|
||||||
// whose tracks were written baked (FrameRestore) gets its original root and tracks back.
|
// whose tracks were written baked (FrameRestore) gets its original root and tracks back.
|
||||||
std::vector<TrackEntry> track_entries_build(std::vector<TrackItem> items, std::vector<TrackItem> legacyGroups,
|
static std::vector<TrackEntry> track_entries_build(std::vector<TrackItem> items, std::vector<TrackItem> legacyGroups,
|
||||||
Extras& extras)
|
Extras& extras)
|
||||||
{
|
{
|
||||||
if (!legacyGroups.empty())
|
if (!legacyGroups.empty())
|
||||||
@@ -476,7 +472,7 @@ namespace anm2ed::model
|
|||||||
return entries_build<TrackEntry>(std::move(items), extras);
|
return entries_build<TrackEntry>(std::move(items), extras);
|
||||||
}
|
}
|
||||||
|
|
||||||
Animation animation_read(pugi::xml_node element)
|
static Animation animation_read(pugi::xml_node element)
|
||||||
{
|
{
|
||||||
Animation animation{.name = string_get(element, "Name"),
|
Animation animation{.name = string_get(element, "Name"),
|
||||||
.frameNum = int_get(element, "FrameNum", 1),
|
.frameNum = int_get(element, "FrameNum", 1),
|
||||||
@@ -541,7 +537,7 @@ namespace anm2ed::model
|
|||||||
return animation;
|
return animation;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<AnimationEntry> animation_entries_read(pugi::xml_node parent, Extras& extras)
|
static std::vector<AnimationEntry> animation_entries_read(pugi::xml_node parent, Extras& extras)
|
||||||
{
|
{
|
||||||
std::vector<AnimationItem> items{};
|
std::vector<AnimationItem> items{};
|
||||||
children_each(parent,
|
children_each(parent,
|
||||||
@@ -572,7 +568,7 @@ namespace anm2ed::model
|
|||||||
return entries_build<AnimationEntry>(std::move(items), extras);
|
return entries_build<AnimationEntry>(std::move(items), extras);
|
||||||
}
|
}
|
||||||
|
|
||||||
Region region_read(pugi::xml_node element)
|
static Region region_read(pugi::xml_node element)
|
||||||
{
|
{
|
||||||
Region region{.id = int_get(element, "Id"),
|
Region region{.id = int_get(element, "Id"),
|
||||||
.name = string_get(element, "Name"),
|
.name = string_get(element, "Name"),
|
||||||
@@ -588,7 +584,7 @@ namespace anm2ed::model
|
|||||||
return region;
|
return region;
|
||||||
}
|
}
|
||||||
|
|
||||||
Spritesheet spritesheet_read(pugi::xml_node element)
|
static Spritesheet spritesheet_read(pugi::xml_node element)
|
||||||
{
|
{
|
||||||
Spritesheet spritesheet{
|
Spritesheet spritesheet{
|
||||||
.id = int_get(element, "Id"), .path = path_get(element, "Path"), .extras = extras_read(element)};
|
.id = int_get(element, "Id"), .path = path_get(element, "Path"), .extras = extras_read(element)};
|
||||||
@@ -603,7 +599,7 @@ namespace anm2ed::model
|
|||||||
return spritesheet;
|
return spritesheet;
|
||||||
}
|
}
|
||||||
|
|
||||||
Shader shader_read(pugi::xml_node element)
|
static Shader shader_read(pugi::xml_node element)
|
||||||
{
|
{
|
||||||
Shader shader{.id = int_get(element, "Id"),
|
Shader shader{.id = int_get(element, "Id"),
|
||||||
.name = string_get(element, "Name"),
|
.name = string_get(element, "Name"),
|
||||||
@@ -633,7 +629,7 @@ namespace anm2ed::model
|
|||||||
return shader;
|
return shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Item> Item item_read(pugi::xml_node);
|
template <class Item> static Item item_read(pugi::xml_node);
|
||||||
template <> Spritesheet item_read(pugi::xml_node element) { return spritesheet_read(element); }
|
template <> Spritesheet item_read(pugi::xml_node element) { return spritesheet_read(element); }
|
||||||
template <> Region item_read(pugi::xml_node element) { return region_read(element); }
|
template <> Region item_read(pugi::xml_node element) { return region_read(element); }
|
||||||
template <> Shader item_read(pugi::xml_node element) { return shader_read(element); }
|
template <> Shader item_read(pugi::xml_node element) { return shader_read(element); }
|
||||||
@@ -676,7 +672,7 @@ namespace anm2ed::model
|
|||||||
template <> constexpr ElementType ITEM_TYPE<Sound>{ElementType::SOUND_ELEMENT};
|
template <> constexpr ElementType ITEM_TYPE<Sound>{ElementType::SOUND_ELEMENT};
|
||||||
template <> constexpr ElementType ITEM_TYPE<Library>{ElementType::LIBRARY};
|
template <> constexpr ElementType ITEM_TYPE<Library>{ElementType::LIBRARY};
|
||||||
|
|
||||||
template <class Item> std::vector<Item> items_read(pugi::xml_node container, Content& content, ElementType type)
|
template <class Item> static std::vector<Item> items_read(pugi::xml_node container, Content& content, ElementType type)
|
||||||
{
|
{
|
||||||
std::vector<Item> items{};
|
std::vector<Item> items{};
|
||||||
auto extras = extras_read(container);
|
auto extras = extras_read(container);
|
||||||
@@ -692,7 +688,7 @@ namespace anm2ed::model
|
|||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
Content content_read(pugi::xml_node element)
|
static Content content_read(pugi::xml_node element)
|
||||||
{
|
{
|
||||||
Content content{.layout = {}, .extras = extras_read(element)};
|
Content content{.layout = {}, .extras = extras_read(element)};
|
||||||
children_each(element,
|
children_each(element,
|
||||||
@@ -719,7 +715,7 @@ namespace anm2ed::model
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Gives every item a unique, non-negative id; the first holder of a duplicated id keeps it.
|
// Gives every item a unique, non-negative id; the first holder of a duplicated id keeps it.
|
||||||
template <class Items> void ids_repair(Items& items)
|
template <class Items> static void ids_repair(Items& items)
|
||||||
{
|
{
|
||||||
std::set<int> usedIds{};
|
std::set<int> usedIds{};
|
||||||
for (const auto& item : items)
|
for (const auto& item : items)
|
||||||
@@ -737,7 +733,7 @@ namespace anm2ed::model
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_region_matched(const Region& region, const Frame& frame)
|
static bool is_region_matched(const Region& region, const Frame& frame)
|
||||||
{
|
{
|
||||||
return glm::ivec2(region.crop) == glm::ivec2(frame.crop) && glm::ivec2(region.size) == glm::ivec2(frame.size) &&
|
return glm::ivec2(region.crop) == glm::ivec2(frame.crop) && glm::ivec2(region.size) == glm::ivec2(frame.size) &&
|
||||||
glm::ivec2(region.pivot) == glm::ivec2(frame.pivot);
|
glm::ivec2(region.pivot) == glm::ivec2(frame.pivot);
|
||||||
@@ -799,7 +795,7 @@ namespace anm2ed::model
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Model model_read(pugi::xml_node element)
|
static Model model_read(pugi::xml_node element)
|
||||||
{
|
{
|
||||||
Model model{.layout = {}, .extras = extras_read(element)};
|
Model model{.layout = {}, .extras = extras_read(element)};
|
||||||
children_each(element,
|
children_each(element,
|
||||||
@@ -862,13 +858,13 @@ namespace anm2ed::model
|
|||||||
bool is(Flag flag) const { return has_flag(flags, flag); }
|
bool is(Flag flag) const { return has_flag(flags, flag); }
|
||||||
};
|
};
|
||||||
|
|
||||||
int id_map_get(const std::map<int, int>& ids, int id)
|
static int id_map_get(const std::map<int, int>& ids, int id)
|
||||||
{
|
{
|
||||||
auto it = ids.find(id);
|
auto it = ids.find(id);
|
||||||
return it == ids.end() ? -1 : it->second;
|
return it == ids.end() ? -1 : it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_float_whole(double value)
|
static bool is_float_whole(double value)
|
||||||
{
|
{
|
||||||
return std::abs(value) < FLOAT_WHOLE_MAX && value == std::trunc(value) && !(value == 0 && std::signbit(value));
|
return std::abs(value) < FLOAT_WHOLE_MAX && value == std::trunc(value) && !(value == 0 && std::signbit(value));
|
||||||
}
|
}
|
||||||
@@ -1061,13 +1057,13 @@ namespace anm2ed::model
|
|||||||
|
|
||||||
// Unknown XML goes back where it was read: attributes after the known ones, then text, and (through Children)
|
// Unknown XML goes back where it was read: attributes after the known ones, then text, and (through Children)
|
||||||
// children at their recorded positions among the known ones.
|
// children at their recorded positions among the known ones.
|
||||||
void extras_attributes_write(Sink& sink, const Extras& extras)
|
static void extras_attributes_write(Sink& sink, const Extras& extras)
|
||||||
{
|
{
|
||||||
for (const auto& [name, value] : extras.attributes)
|
for (const auto& [name, value] : extras.attributes)
|
||||||
sink.attribute_text(name, value);
|
sink.attribute_text(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void extras_write(Sink& sink, const Extras& extras)
|
static void extras_write(Sink& sink, const Extras& extras)
|
||||||
{
|
{
|
||||||
extras_attributes_write(sink, extras);
|
extras_attributes_write(sink, extras);
|
||||||
sink.text_add(extras.text);
|
sink.text_add(extras.text);
|
||||||
@@ -1104,14 +1100,14 @@ namespace anm2ed::model
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void element_close(Sink& sink, const Extras& extras) { Children{sink, extras}.close(); }
|
static void element_close(Sink& sink, const Extras& extras) { Children{sink, extras}.close(); }
|
||||||
|
|
||||||
void path_add(Sink& sink, const char* name, const std::filesystem::path& value)
|
static void path_add(Sink& sink, const char* name, const std::filesystem::path& value)
|
||||||
{
|
{
|
||||||
if (!value.empty()) sink.attribute(name, path::to_utf8(value));
|
if (!value.empty()) sink.attribute(name, path_to_utf8(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
void interpolation_add(Sink& sink, const char* name, Interpolation interpolation)
|
static void interpolation_add(Sink& sink, const char* name, Interpolation interpolation)
|
||||||
{
|
{
|
||||||
if (interpolation == Interpolation::NONE || interpolation == Interpolation::LINEAR)
|
if (interpolation == Interpolation::NONE || interpolation == Interpolation::LINEAR)
|
||||||
sink.attribute(name, interpolation == Interpolation::LINEAR);
|
sink.attribute(name, interpolation == Interpolation::LINEAR);
|
||||||
@@ -1119,18 +1115,18 @@ namespace anm2ed::model
|
|||||||
sink.attribute(name, INTERPOLATION_VALUES[(int)interpolation]);
|
sink.attribute(name, INTERPOLATION_VALUES[(int)interpolation]);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_group_id_written(const Writer& writer)
|
static bool is_group_id_written(const Writer& writer)
|
||||||
{
|
{
|
||||||
return writer.is(SERIALIZE_GROUPS) && !writer.is(SERIALIZE_NESTED_GROUPS);
|
return writer.is(SERIALIZE_GROUPS) && !writer.is(SERIALIZE_NESTED_GROUPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_special_interpolation(Interpolation interpolation)
|
static bool is_special_interpolation(Interpolation interpolation)
|
||||||
{
|
{
|
||||||
return interpolation != Interpolation::NONE && interpolation != Interpolation::LINEAR;
|
return interpolation != Interpolation::NONE && interpolation != Interpolation::LINEAR;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A whole document's frames use renumbered shader and region ids; a layer frame on a region takes its rectangle.
|
// A whole document's frames use renumbered shader and region ids; a layer frame on a region takes its rectangle.
|
||||||
Frame frame_normalize(const Writer& writer, Frame frame, const Track* layerTrack)
|
static Frame frame_normalize(const Writer& writer, Frame frame, const Track* layerTrack)
|
||||||
{
|
{
|
||||||
if (!writer.model) return frame;
|
if (!writer.model) return frame;
|
||||||
if (frame.shaderId != -1) frame.shaderId = id_map_get(writer.shaderIds, frame.shaderId);
|
if (frame.shaderId != -1) frame.shaderId = id_map_get(writer.shaderIds, frame.shaderId);
|
||||||
@@ -1157,7 +1153,7 @@ namespace anm2ed::model
|
|||||||
int delay{};
|
int delay{};
|
||||||
};
|
};
|
||||||
|
|
||||||
void frame_write(Sink& sink, const Writer& writer, const Frame& frame, ItemType type, FrameBake bake = {})
|
static void frame_write(Sink& sink, const Writer& writer, const Frame& frame, ItemType type, FrameBake bake = {})
|
||||||
{
|
{
|
||||||
if (type == ItemType::TRIGGER)
|
if (type == ItemType::TRIGGER)
|
||||||
{
|
{
|
||||||
@@ -1214,13 +1210,13 @@ namespace anm2ed::model
|
|||||||
}
|
}
|
||||||
auto isPurged = writer.is(SERIALIZE_PURGE_DEFAULT_COLORS);
|
auto isPurged = writer.is(SERIALIZE_PURGE_DEFAULT_COLORS);
|
||||||
for (int i = 0; i < (int)std::size(TINT_ATTRIBUTES); ++i)
|
for (int i = 0; i < (int)std::size(TINT_ATTRIBUTES); ++i)
|
||||||
if (auto tint = math::float_to_uint8(frame.tint[i]); !isPurged || tint != math::float_to_uint8(1.0f))
|
if (auto tint = float_to_uint8(frame.tint[i]); !isPurged || tint != float_to_uint8(1.0f))
|
||||||
sink.attribute(TINT_ATTRIBUTES[i], tint);
|
sink.attribute(TINT_ATTRIBUTES[i], tint);
|
||||||
for (int i = 0; i < (int)std::size(OFFSET_ATTRIBUTES); ++i)
|
for (int i = 0; i < (int)std::size(OFFSET_ATTRIBUTES); ++i)
|
||||||
if (auto offset = math::float_to_uint8(frame.colorOffset[i]); !isPurged || offset != 0)
|
if (auto offset = float_to_uint8(frame.colorOffset[i]); !isPurged || offset != 0)
|
||||||
sink.attribute(OFFSET_ATTRIBUTES[i], offset);
|
sink.attribute(OFFSET_ATTRIBUTES[i], offset);
|
||||||
if (writer.is(SERIALIZE_EXTENSIONS) && math::float_to_uint8(frame.colorOffset.a) != 0)
|
if (writer.is(SERIALIZE_EXTENSIONS) && float_to_uint8(frame.colorOffset.a) != 0)
|
||||||
sink.attribute("AlphaOffset", math::float_to_uint8(frame.colorOffset.a));
|
sink.attribute("AlphaOffset", float_to_uint8(frame.colorOffset.a));
|
||||||
sink.attribute("Rotation", frame.rotation);
|
sink.attribute("Rotation", frame.rotation);
|
||||||
interpolation_add(sink, "Interpolated", frame.interpolation);
|
interpolation_add(sink, "Interpolated", frame.interpolation);
|
||||||
if (writer.is(SERIALIZE_EXTENSIONS) && frame.shaderId != -1) sink.attribute("ShaderId", frame.shaderId);
|
if (writer.is(SERIALIZE_EXTENSIONS) && frame.shaderId != -1) sink.attribute("ShaderId", frame.shaderId);
|
||||||
@@ -1247,7 +1243,7 @@ namespace anm2ed::model
|
|||||||
}
|
}
|
||||||
|
|
||||||
// A backup (FrameRestore) track keeps its frames' region ids as they are.
|
// A backup (FrameRestore) track keeps its frames' region ids as they are.
|
||||||
void track_write(Sink& sink, const Writer& writer, const Track& track, int groupId = -1, bool isBackup = false)
|
static void track_write(Sink& sink, const Writer& writer, const Track& track, int groupId = -1, bool isBackup = false)
|
||||||
{
|
{
|
||||||
sink.open(tag_get(track_element_type_get(track.type)));
|
sink.open(tag_get(track_element_type_get(track.type)));
|
||||||
if (track.type == ItemType::LAYER || track.type == ItemType::NULL_)
|
if (track.type == ItemType::LAYER || track.type == ItemType::NULL_)
|
||||||
@@ -1317,7 +1313,7 @@ namespace anm2ed::model
|
|||||||
std::optional<int> ownGroupId{};
|
std::optional<int> ownGroupId{};
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class Group> ContainerChild group_child_make(Sink& sink, const Writer& writer, const Group& group)
|
template <class Group> static ContainerChild group_child_make(Sink& sink, const Writer& writer, const Group& group)
|
||||||
{
|
{
|
||||||
return {.write = [&](std::optional<int> index, const std::function<void()>& members)
|
return {.write = [&](std::optional<int> index, const std::function<void()>& members)
|
||||||
{ group_write(sink, writer, group, index, members); },
|
{ group_write(sink, writer, group, index, members); },
|
||||||
@@ -1326,7 +1322,7 @@ namespace anm2ed::model
|
|||||||
|
|
||||||
// Children are laid out flat (a group, then its children) and reshaped for the flags: nested into their groups, or,
|
// Children are laid out flat (a group, then its children) and reshaped for the flags: nested into their groups, or,
|
||||||
// in a track container, moved to a *AnimationGroups sibling (`groupsType`) that records each group's position.
|
// in a track container, moved to a *AnimationGroups sibling (`groupsType`) that records each group's position.
|
||||||
void container_write(Sink& sink, const Writer& writer, std::vector<ContainerChild> flat, const Extras& extras,
|
static void container_write(Sink& sink, const Writer& writer, std::vector<ContainerChild> flat, const Extras& extras,
|
||||||
ElementType groupsType = ElementType::UNKNOWN)
|
ElementType groupsType = ElementType::UNKNOWN)
|
||||||
{
|
{
|
||||||
extras_write(sink, extras);
|
extras_write(sink, extras);
|
||||||
@@ -1377,7 +1373,7 @@ namespace anm2ed::model
|
|||||||
sink.close();
|
sink.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void track_entries_write(Sink& sink, const Writer& writer, const std::vector<TrackEntry>& entries, ElementType type,
|
static void track_entries_write(Sink& sink, const Writer& writer, const std::vector<TrackEntry>& entries, ElementType type,
|
||||||
const Extras& extras)
|
const Extras& extras)
|
||||||
{
|
{
|
||||||
std::vector<ContainerChild> flat{};
|
std::vector<ContainerChild> flat{};
|
||||||
@@ -1403,7 +1399,7 @@ namespace anm2ed::model
|
|||||||
: ElementType::NULL_ANIMATION_GROUPS);
|
: ElementType::NULL_ANIMATION_GROUPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_frame_transform_default(const Frame& frame)
|
static bool is_frame_transform_default(const Frame& frame)
|
||||||
{
|
{
|
||||||
Frame base{};
|
Frame base{};
|
||||||
return frame.position == base.position && frame.scale == base.scale && frame.rotation == base.rotation &&
|
return frame.position == base.position && frame.scale == base.scale && frame.rotation == base.rotation &&
|
||||||
@@ -1430,7 +1426,7 @@ namespace anm2ed::model
|
|||||||
issues.skewFrames += frame.skew != glm::vec2();
|
issues.skewFrames += frame.skew != glm::vec2();
|
||||||
issues.shaderFrames += frame.shaderId != -1;
|
issues.shaderFrames += frame.shaderId != -1;
|
||||||
issues.depthFrames += track.type == ItemType::LAYER && frame.depth != 0;
|
issues.depthFrames += track.type == ItemType::LAYER && frame.depth != 0;
|
||||||
issues.alphaOffsetFrames += math::float_to_uint8(frame.colorOffset.a) != 0;
|
issues.alphaOffsetFrames += float_to_uint8(frame.colorOffset.a) != 0;
|
||||||
issues.blurFrames += track.type == ItemType::LAYER && frame.blur != 0.0f;
|
issues.blurFrames += track.type == ItemType::LAYER && frame.blur != 0.0f;
|
||||||
issues.extraEvents += track.type == ItemType::TRIGGER ? std::max((int)frame.eventIds.size() - 1, 0) : 0;
|
issues.extraEvents += track.type == ItemType::TRIGGER ? std::max((int)frame.eventIds.size() - 1, 0) : 0;
|
||||||
issues.triggerSounds += track.type == ItemType::TRIGGER &&
|
issues.triggerSounds += track.type == ItemType::TRIGGER &&
|
||||||
@@ -1443,7 +1439,7 @@ namespace anm2ed::model
|
|||||||
|
|
||||||
// The game's copy: group roots baked into their tracks (originals kept in a FrameRestore node the editor reads
|
// The game's copy: group roots baked into their tracks (originals kept in a FrameRestore node the editor reads
|
||||||
// back), and interpolation flattened into single-step frames.
|
// back), and interpolation flattened into single-step frames.
|
||||||
Animation animation_bake(const Writer& writer, Animation animation)
|
static Animation animation_bake(const Writer& writer, Animation animation)
|
||||||
{
|
{
|
||||||
if (writer.is(SERIALIZE_BAKE_GROUP_FRAMES))
|
if (writer.is(SERIALIZE_BAKE_GROUP_FRAMES))
|
||||||
for (auto* entries : {&animation.layers, &animation.nulls})
|
for (auto* entries : {&animation.layers, &animation.nulls})
|
||||||
@@ -1480,7 +1476,7 @@ namespace anm2ed::model
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Known children in their recorded order; a part with content that was never in the file is appended.
|
// Known children in their recorded order; a part with content that was never in the file is appended.
|
||||||
std::vector<ElementType> layout_get(std::vector<ElementType> layout,
|
static std::vector<ElementType> layout_get(std::vector<ElementType> layout,
|
||||||
std::initializer_list<std::pair<ElementType, bool>> parts)
|
std::initializer_list<std::pair<ElementType, bool>> parts)
|
||||||
{
|
{
|
||||||
for (auto [type, isContent] : parts)
|
for (auto [type, isContent] : parts)
|
||||||
@@ -1488,7 +1484,7 @@ namespace anm2ed::model
|
|||||||
return layout;
|
return layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
void animation_write(Sink& sink, const Writer& writer, const Animation& source, int groupId = -1)
|
static void animation_write(Sink& sink, const Writer& writer, const Animation& source, int groupId = -1)
|
||||||
{
|
{
|
||||||
auto isBaked = writer.model &&
|
auto isBaked = writer.model &&
|
||||||
(writer.is(SERIALIZE_BAKE_GROUP_FRAMES) || writer.is(SERIALIZE_FLATTEN_SPECIAL_INTERPOLATED_FRAMES));
|
(writer.is(SERIALIZE_BAKE_GROUP_FRAMES) || writer.is(SERIALIZE_FLATTEN_SPECIAL_INTERPOLATED_FRAMES));
|
||||||
@@ -1522,7 +1518,7 @@ namespace anm2ed::model
|
|||||||
children.close();
|
children.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void animations_write(Sink& sink, const Writer& writer, const Animations& animations)
|
static void animations_write(Sink& sink, const Writer& writer, const Animations& animations)
|
||||||
{
|
{
|
||||||
std::vector<ContainerChild> flat{};
|
std::vector<ContainerChild> flat{};
|
||||||
auto animation_child_make = [&](const Animation& animation, int groupId)
|
auto animation_child_make = [&](const Animation& animation, int groupId)
|
||||||
@@ -1546,7 +1542,7 @@ namespace anm2ed::model
|
|||||||
container_write(sink, writer, std::move(flat), animations.extras);
|
container_write(sink, writer, std::move(flat), animations.extras);
|
||||||
}
|
}
|
||||||
|
|
||||||
void item_write(Sink& sink, const Writer&, const Region& region, int id)
|
static void item_write(Sink& sink, const Writer&, const Region& region, int id)
|
||||||
{
|
{
|
||||||
sink.open(tag_get(ElementType::REGION));
|
sink.open(tag_get(ElementType::REGION));
|
||||||
sink.attribute("Id", id);
|
sink.attribute("Id", id);
|
||||||
@@ -1566,7 +1562,7 @@ namespace anm2ed::model
|
|||||||
element_close(sink, region.extras);
|
element_close(sink, region.extras);
|
||||||
}
|
}
|
||||||
|
|
||||||
void item_write(Sink& sink, const Writer& writer, const Spritesheet& spritesheet, int id)
|
static void item_write(Sink& sink, const Writer& writer, const Spritesheet& spritesheet, int id)
|
||||||
{
|
{
|
||||||
sink.open(tag_get(ElementType::SPRITESHEET));
|
sink.open(tag_get(ElementType::SPRITESHEET));
|
||||||
sink.attribute("Id", id);
|
sink.attribute("Id", id);
|
||||||
@@ -1582,13 +1578,13 @@ namespace anm2ed::model
|
|||||||
children.close();
|
children.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void binding_value_add(Sink& sink, const std::string& binding, const std::string& value)
|
static void binding_value_add(Sink& sink, const std::string& binding, const std::string& value)
|
||||||
{
|
{
|
||||||
if (!binding.empty()) sink.attribute("Binding", binding);
|
if (!binding.empty()) sink.attribute("Binding", binding);
|
||||||
if (!value.empty()) sink.attribute("Value", value);
|
if (!value.empty()) sink.attribute("Value", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void item_write(Sink& sink, const Writer&, const Shader& shader, int id)
|
static void item_write(Sink& sink, const Writer&, const Shader& shader, int id)
|
||||||
{
|
{
|
||||||
sink.open(tag_get(ElementType::SHADER));
|
sink.open(tag_get(ElementType::SHADER));
|
||||||
sink.attribute("Id", id);
|
sink.attribute("Id", id);
|
||||||
@@ -1619,7 +1615,7 @@ namespace anm2ed::model
|
|||||||
children.close();
|
children.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void item_write(Sink& sink, const Writer& writer, const Layer& layer, int id)
|
static void item_write(Sink& sink, const Writer& writer, const Layer& layer, int id)
|
||||||
{
|
{
|
||||||
sink.open(tag_get(ElementType::LAYER_ELEMENT));
|
sink.open(tag_get(ElementType::LAYER_ELEMENT));
|
||||||
sink.attribute("Id", id);
|
sink.attribute("Id", id);
|
||||||
@@ -1634,7 +1630,7 @@ namespace anm2ed::model
|
|||||||
element_close(sink, layer.extras);
|
element_close(sink, layer.extras);
|
||||||
}
|
}
|
||||||
|
|
||||||
void item_write(Sink& sink, const Writer&, const Null& null, int id)
|
static void item_write(Sink& sink, const Writer&, const Null& null, int id)
|
||||||
{
|
{
|
||||||
sink.open(tag_get(ElementType::NULL_ELEMENT));
|
sink.open(tag_get(ElementType::NULL_ELEMENT));
|
||||||
sink.attribute("Id", id);
|
sink.attribute("Id", id);
|
||||||
@@ -1644,7 +1640,7 @@ namespace anm2ed::model
|
|||||||
element_close(sink, null.extras);
|
element_close(sink, null.extras);
|
||||||
}
|
}
|
||||||
|
|
||||||
void item_write(Sink& sink, const Writer&, const Event& event, int id)
|
static void item_write(Sink& sink, const Writer&, const Event& event, int id)
|
||||||
{
|
{
|
||||||
sink.open(tag_get(ElementType::EVENT_ELEMENT));
|
sink.open(tag_get(ElementType::EVENT_ELEMENT));
|
||||||
sink.attribute("Id", id);
|
sink.attribute("Id", id);
|
||||||
@@ -1654,7 +1650,7 @@ namespace anm2ed::model
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sounds and libraries are a path.
|
// Sounds and libraries are a path.
|
||||||
template <class Item> void item_path_write(Sink& sink, const Item& item, ElementType type, int id)
|
template <class Item> static void item_path_write(Sink& sink, const Item& item, ElementType type, int id)
|
||||||
{
|
{
|
||||||
sink.open(tag_get(type));
|
sink.open(tag_get(type));
|
||||||
sink.attribute("Id", id);
|
sink.attribute("Id", id);
|
||||||
@@ -1663,18 +1659,18 @@ namespace anm2ed::model
|
|||||||
element_close(sink, item.extras);
|
element_close(sink, item.extras);
|
||||||
}
|
}
|
||||||
|
|
||||||
void item_write(Sink& sink, const Writer&, const Sound& sound, int id)
|
static void item_write(Sink& sink, const Writer&, const Sound& sound, int id)
|
||||||
{
|
{
|
||||||
item_path_write(sink, sound, ElementType::SOUND_ELEMENT, id);
|
item_path_write(sink, sound, ElementType::SOUND_ELEMENT, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void item_write(Sink& sink, const Writer&, const Library& library, int id)
|
static void item_write(Sink& sink, const Writer&, const Library& library, int id)
|
||||||
{
|
{
|
||||||
item_path_write(sink, library, ElementType::LIBRARY, id);
|
item_path_write(sink, library, ElementType::LIBRARY, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// A content container's unknown XML (a file may repeat a container; its parts are merged in order).
|
// A content container's unknown XML (a file may repeat a container; its parts are merged in order).
|
||||||
Extras container_extras_get(const Content& content, ElementType type)
|
static Extras container_extras_get(const Content& content, ElementType type)
|
||||||
{
|
{
|
||||||
Extras merged{};
|
Extras merged{};
|
||||||
for (const auto& [extrasType, extras] : content.containerExtras)
|
for (const auto& [extrasType, extras] : content.containerExtras)
|
||||||
@@ -1703,7 +1699,7 @@ namespace anm2ed::model
|
|||||||
children.close();
|
children.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void content_write(Sink& sink, const Writer& writer, const Content& content)
|
static void content_write(Sink& sink, const Writer& writer, const Content& content)
|
||||||
{
|
{
|
||||||
sink.open(tag_get(ElementType::CONTENT));
|
sink.open(tag_get(ElementType::CONTENT));
|
||||||
extras_write(sink, content.extras);
|
extras_write(sink, content.extras);
|
||||||
@@ -1738,7 +1734,7 @@ namespace anm2ed::model
|
|||||||
}
|
}
|
||||||
|
|
||||||
// A whole document; `inner` writes anything after its children (the SourceDocument copy) and `tag` renames it.
|
// A whole document; `inner` writes anything after its children (the SourceDocument copy) and `tag` renames it.
|
||||||
void model_write(Sink& sink, const Model& model, Flags flags, const std::function<void()>& inner = {},
|
static void model_write(Sink& sink, const Model& model, Flags flags, const std::function<void()>& inner = {},
|
||||||
std::string_view tag = {})
|
std::string_view tag = {})
|
||||||
{
|
{
|
||||||
Writer writer(flags, &model);
|
Writer writer(flags, &model);
|
||||||
@@ -1771,7 +1767,7 @@ namespace anm2ed::model
|
|||||||
|
|
||||||
// A save is the game's document with the editor's own copy embedded as SourceDocument; neither writes tints of 255
|
// A save is the game's document with the editor's own copy embedded as SourceDocument; neither writes tints of 255
|
||||||
// or color offsets of 0, which readers assume.
|
// or color offsets of 0, which readers assume.
|
||||||
void document_write(Sink& sink, const Model& model, Options options)
|
static void document_write(Sink& sink, const Model& model, Options options)
|
||||||
{
|
{
|
||||||
model_write(
|
model_write(
|
||||||
sink, options.gameModel ? *options.gameModel : model, SERIALIZE_ISAAC_DEFAULT | SERIALIZE_PURGE_DEFAULT_COLORS,
|
sink, options.gameModel ? *options.gameModel : model, SERIALIZE_ISAAC_DEFAULT | SERIALIZE_PURGE_DEFAULT_COLORS,
|
||||||
@@ -1782,14 +1778,14 @@ namespace anm2ed::model
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The text of whatever `write` sends to a sink.
|
// The text of whatever `write` sends to a sink.
|
||||||
template <class Write> std::string text_get(Write&& write)
|
template <class Write> static std::string text_get(Write&& write)
|
||||||
{
|
{
|
||||||
Sink sink{};
|
Sink sink{};
|
||||||
write(sink);
|
write(sink);
|
||||||
return std::move(sink.text);
|
return std::move(sink.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool model_invalid_set(Model& model)
|
static bool model_invalid_set(Model& model)
|
||||||
{
|
{
|
||||||
model = model_make();
|
model = model_make();
|
||||||
model.isValid = false;
|
model.isValid = false;
|
||||||
@@ -1797,7 +1793,7 @@ namespace anm2ed::model
|
|||||||
}
|
}
|
||||||
|
|
||||||
// A parse error says where it is: "Error parsing element name (line 12)".
|
// A parse error says where it is: "Error parsing element name (line 12)".
|
||||||
bool document_parse(pugi::xml_document& document, std::string_view text, std::string* errorString)
|
static bool document_parse(pugi::xml_document& document, std::string_view text, std::string* errorString)
|
||||||
{
|
{
|
||||||
auto result = document.load_buffer(text.data(), text.size());
|
auto result = document.load_buffer(text.data(), text.size());
|
||||||
if (result) return true;
|
if (result) return true;
|
||||||
@@ -1807,7 +1803,7 @@ namespace anm2ed::model
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool document_load(Model& model, std::string_view text, std::string* errorString)
|
static bool document_load(Model& model, std::string_view text, std::string* errorString)
|
||||||
{
|
{
|
||||||
pugi::xml_document document{};
|
pugi::xml_document document{};
|
||||||
if (!document_parse(document, text, errorString)) return model_invalid_set(model);
|
if (!document_parse(document, text, errorString)) return model_invalid_set(model);
|
||||||
@@ -1826,14 +1822,14 @@ namespace anm2ed::model
|
|||||||
Model model_make()
|
Model model_make()
|
||||||
{
|
{
|
||||||
Model model{};
|
Model model{};
|
||||||
model.info.createdOn = time::get(CREATED_ON_FORMAT);
|
model.info.createdOn = timestamp_get(CREATED_ON_FORMAT);
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool model_load(Model& model, const std::filesystem::path& path, std::string* errorString)
|
bool model_load(Model& model, const std::filesystem::path& path, std::string* errorString)
|
||||||
{
|
{
|
||||||
std::string text{};
|
std::string text{};
|
||||||
if (file::read_to_string(path, &text)) return model_load_string(model, text, errorString);
|
if (file_text_load(path, &text)) return model_load_string(model, text, errorString);
|
||||||
if (errorString) *errorString = "File not found.";
|
if (errorString) *errorString = "File not found.";
|
||||||
return model_invalid_set(model);
|
return model_invalid_set(model);
|
||||||
}
|
}
|
||||||
@@ -1914,12 +1910,12 @@ namespace anm2ed::model
|
|||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Item> std::string item_to_string(const Item& item)
|
template <class Item> static std::string item_to_string(const Item& item)
|
||||||
{
|
{
|
||||||
return text_get([&](Sink& sink) { item_write(sink, Writer(CLIPBOARD_FLAGS), item, item.id); });
|
return text_get([&](Sink& sink) { item_write(sink, Writer(CLIPBOARD_FLAGS), item, item.id); });
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Item> std::vector<Item> items_from_string(const std::string& text, std::string* errorString)
|
template <class Item> static std::vector<Item> items_from_string(const std::string& text, std::string* errorString)
|
||||||
{
|
{
|
||||||
pugi::xml_document document{};
|
pugi::xml_document document{};
|
||||||
if (!document_parse(document, text, errorString)) return {};
|
if (!document_parse(document, text, errorString)) return {};
|
||||||
@@ -1928,7 +1924,7 @@ namespace anm2ed::model
|
|||||||
for (auto element : document.children(tag))
|
for (auto element : document.children(tag))
|
||||||
{
|
{
|
||||||
auto item = item_read<Item>(element);
|
auto item = item_read<Item>(element);
|
||||||
if constexpr (requires { item.path; }) item.path = path::backslash_handle(item.path);
|
if constexpr (requires { item.path; }) item.path = path_backslash_handle(item.path);
|
||||||
items.push_back(std::move(item));
|
items.push_back(std::move(item));
|
||||||
}
|
}
|
||||||
if (items.empty() && errorString) *errorString = std::format("No valid {}(s).", tag);
|
if (items.empty() && errorString) *errorString = std::format("No valid {}(s).", tag);
|
||||||
@@ -1947,4 +1943,3 @@ namespace anm2ed::model
|
|||||||
X(Sound)
|
X(Sound)
|
||||||
X(Library)
|
X(Library)
|
||||||
#undef X
|
#undef X
|
||||||
}
|
|
||||||
@@ -6,8 +6,6 @@
|
|||||||
#include "model/model.h"
|
#include "model/model.h"
|
||||||
|
|
||||||
// The only place the model meets XML: reading and writing documents (with the SourceDocument copy) and clipboard text.
|
// The only place the model meets XML: reading and writing documents (with the SourceDocument copy) and clipboard text.
|
||||||
namespace anm2ed::model
|
|
||||||
{
|
|
||||||
// What the game's copy of a save can't keep as it is: how many of each.
|
// What the game's copy of a save can't keep as it is: how many of each.
|
||||||
struct IsaacIssues
|
struct IsaacIssues
|
||||||
{
|
{
|
||||||
@@ -44,4 +42,3 @@ namespace anm2ed::model
|
|||||||
|
|
||||||
template <class Item> std::string item_to_string(const Item&);
|
template <class Item> std::string item_to_string(const Item&);
|
||||||
template <class Item> std::vector<Item> items_from_string(const std::string&, std::string* = nullptr);
|
template <class Item> std::vector<Item> items_from_string(const std::string&, std::string* = nullptr);
|
||||||
}
|
|
||||||
+5
-8
@@ -5,8 +5,6 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
namespace anm2ed::util::pack
|
|
||||||
{
|
|
||||||
constexpr int WIDTH_CANDIDATES_MAX = 512;
|
constexpr int WIDTH_CANDIDATES_MAX = 512;
|
||||||
|
|
||||||
struct Rect
|
struct Rect
|
||||||
@@ -17,17 +15,17 @@ namespace anm2ed::util::pack
|
|||||||
int h{};
|
int h{};
|
||||||
};
|
};
|
||||||
|
|
||||||
bool is_rect_intersecting(const Rect& a, const Rect& b)
|
static bool is_rect_intersecting(const Rect& a, const Rect& b)
|
||||||
{
|
{
|
||||||
return !(b.x >= a.x + a.w || b.x + b.w <= a.x || b.y >= a.y + a.h || b.y + b.h <= a.y);
|
return !(b.x >= a.x + a.w || b.x + b.w <= a.x || b.y >= a.y + a.h || b.y + b.h <= a.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_rect_contained(const Rect& a, const Rect& b)
|
static bool is_rect_contained(const Rect& a, const Rect& b)
|
||||||
{
|
{
|
||||||
return b.x >= a.x && b.y >= a.y && b.x + b.w <= a.x + a.w && b.y + b.h <= a.y + a.h;
|
return b.x >= a.x && b.y >= a.y && b.x + b.w <= a.x + a.w && b.y + b.h <= a.y + a.h;
|
||||||
}
|
}
|
||||||
|
|
||||||
void free_rects_split(std::vector<Rect>& freeRects, const Rect& used)
|
static void free_rects_split(std::vector<Rect>& freeRects, const Rect& used)
|
||||||
{
|
{
|
||||||
std::vector<Rect> next{};
|
std::vector<Rect> next{};
|
||||||
next.reserve(freeRects.size() * 2);
|
next.reserve(freeRects.size() * 2);
|
||||||
@@ -48,7 +46,7 @@ namespace anm2ed::util::pack
|
|||||||
freeRects = std::move(next);
|
freeRects = std::move(next);
|
||||||
}
|
}
|
||||||
|
|
||||||
void free_rects_prune(std::vector<Rect>& freeRects)
|
static void free_rects_prune(std::vector<Rect>& freeRects)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < (int)freeRects.size(); ++i)
|
for (int i = 0; i < (int)freeRects.size(); ++i)
|
||||||
{
|
{
|
||||||
@@ -72,7 +70,7 @@ namespace anm2ed::util::pack
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool rect_insert(std::vector<Rect>& freeRects, glm::ivec2 size, Rect& result)
|
static bool rect_insert(std::vector<Rect>& freeRects, glm::ivec2 size, Rect& result)
|
||||||
{
|
{
|
||||||
int bestShort = std::numeric_limits<int>::max();
|
int bestShort = std::numeric_limits<int>::max();
|
||||||
int bestLong = std::numeric_limits<int>::max();
|
int bestLong = std::numeric_limits<int>::max();
|
||||||
@@ -147,4 +145,3 @@ namespace anm2ed::util::pack
|
|||||||
|
|
||||||
return bestArea != std::numeric_limits<int>::max();
|
return bestArea != std::numeric_limits<int>::max();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -4,7 +4,4 @@
|
|||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
namespace anm2ed::util::pack
|
|
||||||
{
|
|
||||||
bool rects_pack(const std::vector<glm::ivec2>&, glm::ivec2&, std::vector<glm::ivec2>&);
|
bool rects_pack(const std::vector<glm::ivec2>&, glm::ivec2&, std::vector<glm::ivec2>&);
|
||||||
}
|
|
||||||
+26
-29
@@ -6,9 +6,7 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
namespace anm2ed::util::path
|
template <typename CharT> static CharT to_lower_char(CharT character)
|
||||||
{
|
|
||||||
template <typename CharT> CharT to_lower_char(CharT character)
|
|
||||||
{
|
{
|
||||||
if constexpr (std::is_same_v<CharT, wchar_t>)
|
if constexpr (std::is_same_v<CharT, wchar_t>)
|
||||||
return static_cast<CharT>(std::towlower(static_cast<wint_t>(character)));
|
return static_cast<CharT>(std::towlower(static_cast<wint_t>(character)));
|
||||||
@@ -16,7 +14,7 @@ namespace anm2ed::util::path
|
|||||||
return static_cast<CharT>(std::tolower(static_cast<unsigned char>(character)));
|
return static_cast<CharT>(std::tolower(static_cast<unsigned char>(character)));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::filesystem::path to_lower(const std::filesystem::path& path)
|
std::filesystem::path path_to_lower(const std::filesystem::path& path)
|
||||||
{
|
{
|
||||||
auto native = path.native();
|
auto native = path.native();
|
||||||
for (auto& character : native)
|
for (auto& character : native)
|
||||||
@@ -24,7 +22,7 @@ namespace anm2ed::util::path
|
|||||||
return std::filesystem::path(native);
|
return std::filesystem::path(native);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::filesystem::path backslash_replace(const std::filesystem::path& path)
|
std::filesystem::path path_backslash_replace(const std::filesystem::path& path)
|
||||||
{
|
{
|
||||||
auto native = path.native();
|
auto native = path.native();
|
||||||
constexpr auto backslash = static_cast<std::filesystem::path::value_type>('\\');
|
constexpr auto backslash = static_cast<std::filesystem::path::value_type>('\\');
|
||||||
@@ -34,33 +32,33 @@ namespace anm2ed::util::path
|
|||||||
return std::filesystem::path(native);
|
return std::filesystem::path(native);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string to_utf8(const std::filesystem::path& path)
|
std::string path_to_utf8(const std::filesystem::path& path)
|
||||||
{
|
{
|
||||||
auto u8 = path.u8string();
|
auto u8 = path.u8string();
|
||||||
return std::string(u8.begin(), u8.end());
|
return std::string(u8.begin(), u8.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::filesystem::path from_utf8(const std::string& utf8)
|
std::filesystem::path path_from_utf8(const std::string& utf8)
|
||||||
{
|
{
|
||||||
return std::filesystem::path(std::u8string(utf8.begin(), utf8.end()));
|
return std::filesystem::path(std::u8string(utf8.begin(), utf8.end()));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_exist(const std::filesystem::path& path)
|
bool is_path_exist(const std::filesystem::path& path)
|
||||||
{
|
{
|
||||||
if (path.empty()) return false;
|
if (path.empty()) return false;
|
||||||
std::error_code errorCode;
|
std::error_code errorCode;
|
||||||
return std::filesystem::exists(path, errorCode) && ((void)std::filesystem::status(path, errorCode), !errorCode);
|
return std::filesystem::exists(path, errorCode) && ((void)std::filesystem::status(path, errorCode), !errorCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_extension(const std::filesystem::path& path, const std::string& extension)
|
bool is_path_extension(const std::filesystem::path& path, const std::string& extension)
|
||||||
{
|
{
|
||||||
if (path.empty()) return false;
|
if (path.empty()) return false;
|
||||||
auto extensionUtf8 = to_utf8(std::filesystem::path(path).extension());
|
auto extensionUtf8 = path_to_utf8(std::filesystem::path(path).extension());
|
||||||
std::transform(extensionUtf8.begin(), extensionUtf8.end(), extensionUtf8.begin(), ::tolower);
|
std::transform(extensionUtf8.begin(), extensionUtf8.end(), extensionUtf8.begin(), ::tolower);
|
||||||
return extensionUtf8 == ("." + extension);
|
return extensionUtf8 == ("." + extension);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_executable(const std::filesystem::path& path)
|
bool is_path_executable(const std::filesystem::path& path)
|
||||||
{
|
{
|
||||||
if (path.empty()) return false;
|
if (path.empty()) return false;
|
||||||
|
|
||||||
@@ -71,7 +69,7 @@ namespace anm2ed::util::path
|
|||||||
if (!std::filesystem::is_regular_file(status)) return false;
|
if (!std::filesystem::is_regular_file(status)) return false;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
auto extension = to_lower(path.extension());
|
auto extension = path_to_lower(path.extension());
|
||||||
if (extension != ".exe" && extension != ".bat" && extension != ".cmd") return false;
|
if (extension != ".exe" && extension != ".bat" && extension != ".cmd") return false;
|
||||||
#else
|
#else
|
||||||
auto permissions = status.permissions();
|
auto permissions = status.permissions();
|
||||||
@@ -83,17 +81,17 @@ namespace anm2ed::util::path
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ensure_directory(const std::filesystem::path& path)
|
bool path_ensure_directory(const std::filesystem::path& path)
|
||||||
{
|
{
|
||||||
if (path.empty()) return false;
|
if (path.empty()) return false;
|
||||||
|
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
if (std::filesystem::create_directories(path, ec)) return true;
|
if (std::filesystem::create_directories(path, ec)) return true;
|
||||||
|
|
||||||
return is_exist(path.parent_path());
|
return is_path_exist(path.parent_path());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::filesystem::path make_relative(const std::filesystem::path& path)
|
std::filesystem::path path_make_relative(const std::filesystem::path& path)
|
||||||
{
|
{
|
||||||
if (path.empty()) return path;
|
if (path.empty()) return path;
|
||||||
if (!path.is_absolute()) return path;
|
if (!path.is_absolute()) return path;
|
||||||
@@ -104,7 +102,7 @@ namespace anm2ed::util::path
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::filesystem::path make_relative(const std::filesystem::path& path, const std::filesystem::path& base)
|
std::filesystem::path path_make_relative(const std::filesystem::path& path, const std::filesystem::path& base)
|
||||||
{
|
{
|
||||||
if (path.empty()) return path;
|
if (path.empty()) return path;
|
||||||
if (base.empty() || !path.is_absolute()) return path;
|
if (base.empty() || !path.is_absolute()) return path;
|
||||||
@@ -115,25 +113,25 @@ namespace anm2ed::util::path
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::filesystem::path backslash_handle(const std::filesystem::path& path)
|
std::filesystem::path path_backslash_handle(const std::filesystem::path& path)
|
||||||
{
|
{
|
||||||
auto newPath = path;
|
auto newPath = path;
|
||||||
if (is_exist(newPath)) return newPath;
|
if (is_path_exist(newPath)) return newPath;
|
||||||
|
|
||||||
newPath = backslash_replace(newPath);
|
newPath = path_backslash_replace(newPath);
|
||||||
return newPath;
|
return newPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::filesystem::path case_insensitive_find(const std::filesystem::path& path)
|
std::filesystem::path path_case_insensitive_find(const std::filesystem::path& path)
|
||||||
{
|
{
|
||||||
auto handledPath = backslash_handle(path);
|
auto handledPath = path_backslash_handle(path);
|
||||||
if (is_exist(handledPath)) return handledPath;
|
if (is_path_exist(handledPath)) return handledPath;
|
||||||
|
|
||||||
auto resolvedPath = handledPath.root_path();
|
auto resolvedPath = handledPath.root_path();
|
||||||
for (const auto& part : handledPath.relative_path())
|
for (const auto& part : handledPath.relative_path())
|
||||||
{
|
{
|
||||||
auto candidate = resolvedPath / part;
|
auto candidate = resolvedPath / part;
|
||||||
if (is_exist(candidate))
|
if (is_path_exist(candidate))
|
||||||
{
|
{
|
||||||
resolvedPath = candidate;
|
resolvedPath = candidate;
|
||||||
continue;
|
continue;
|
||||||
@@ -144,11 +142,11 @@ namespace anm2ed::util::path
|
|||||||
bool isFound{};
|
bool isFound{};
|
||||||
if (std::filesystem::is_directory(parent, ec))
|
if (std::filesystem::is_directory(parent, ec))
|
||||||
{
|
{
|
||||||
auto partLower = to_lower(part);
|
auto partLower = path_to_lower(part);
|
||||||
std::filesystem::directory_iterator it(parent, ec);
|
std::filesystem::directory_iterator it(parent, ec);
|
||||||
std::filesystem::directory_iterator end{};
|
std::filesystem::directory_iterator end{};
|
||||||
for (; !ec && it != end; it.increment(ec))
|
for (; !ec && it != end; it.increment(ec))
|
||||||
if (to_lower(it->path().filename()) == partLower)
|
if (path_to_lower(it->path().filename()) == partLower)
|
||||||
{
|
{
|
||||||
resolvedPath /= it->path().filename();
|
resolvedPath /= it->path().filename();
|
||||||
isFound = true;
|
isFound = true;
|
||||||
@@ -159,11 +157,10 @@ namespace anm2ed::util::path
|
|||||||
if (!isFound) resolvedPath = candidate;
|
if (!isFound) resolvedPath = candidate;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_exist(resolvedPath)) return resolvedPath;
|
if (is_path_exist(resolvedPath)) return resolvedPath;
|
||||||
|
|
||||||
auto lowerPath = to_lower(handledPath);
|
auto lowerPath = path_to_lower(handledPath);
|
||||||
if (is_exist(lowerPath)) return lowerPath;
|
if (is_path_exist(lowerPath)) return lowerPath;
|
||||||
|
|
||||||
return handledPath;
|
return handledPath;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
+12
-15
@@ -3,21 +3,18 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace anm2ed::util::path
|
std::filesystem::path path_to_lower(const std::filesystem::path&);
|
||||||
{
|
std::filesystem::path path_backslash_replace(const std::filesystem::path&);
|
||||||
std::filesystem::path to_lower(const std::filesystem::path&);
|
std::string path_to_utf8(const std::filesystem::path&);
|
||||||
std::filesystem::path backslash_replace(const std::filesystem::path&);
|
std::filesystem::path path_from_utf8(const std::string&);
|
||||||
std::string to_utf8(const std::filesystem::path&);
|
std::filesystem::path path_make_relative(const std::filesystem::path&);
|
||||||
std::filesystem::path from_utf8(const std::string&);
|
std::filesystem::path path_make_relative(const std::filesystem::path&, const std::filesystem::path&);
|
||||||
std::filesystem::path make_relative(const std::filesystem::path&);
|
|
||||||
std::filesystem::path make_relative(const std::filesystem::path&, const std::filesystem::path&);
|
|
||||||
|
|
||||||
bool is_exist(const std::filesystem::path&);
|
bool is_path_exist(const std::filesystem::path&);
|
||||||
bool is_executable(const std::filesystem::path&);
|
bool is_path_executable(const std::filesystem::path&);
|
||||||
bool is_extension(const std::filesystem::path&, const std::string&);
|
bool is_path_extension(const std::filesystem::path&, const std::string&);
|
||||||
|
|
||||||
bool ensure_directory(const std::filesystem::path&);
|
bool path_ensure_directory(const std::filesystem::path&);
|
||||||
|
|
||||||
std::filesystem::path backslash_handle(const std::filesystem::path&);
|
std::filesystem::path path_backslash_handle(const std::filesystem::path&);
|
||||||
std::filesystem::path case_insensitive_find(const std::filesystem::path&);
|
std::filesystem::path path_case_insensitive_find(const std::filesystem::path&);
|
||||||
}
|
|
||||||
@@ -4,8 +4,6 @@
|
|||||||
|
|
||||||
#include <glm/common.hpp>
|
#include <glm/common.hpp>
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
void Playback::toggle()
|
void Playback::toggle()
|
||||||
{
|
{
|
||||||
if (isFinished) time = 0.0f;
|
if (isFinished) time = 0.0f;
|
||||||
@@ -56,4 +54,3 @@ namespace anm2ed
|
|||||||
clamp(length);
|
clamp(length);
|
||||||
timing_reset();
|
timing_reset();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
class Playback
|
class Playback
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -19,4 +17,3 @@ namespace anm2ed
|
|||||||
private:
|
private:
|
||||||
float tickAccumulator{};
|
float tickAccumulator{};
|
||||||
};
|
};
|
||||||
}
|
|
||||||
+93
-103
@@ -28,26 +28,20 @@
|
|||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
#include "ui/toast.h"
|
#include "ui/toast.h"
|
||||||
|
|
||||||
using namespace anm2ed::imgui;
|
|
||||||
using namespace anm2ed::resource;
|
|
||||||
using namespace anm2ed::util;
|
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
bool animation_render(const std::filesystem::path& ffmpegPath, const std::filesystem::path& path,
|
bool animation_render(const std::filesystem::path& ffmpegPath, const std::filesystem::path& path,
|
||||||
const std::vector<std::filesystem::path>& framePaths, AudioStream& audioStream,
|
const std::vector<std::filesystem::path>& framePaths, AudioStream& audioStream,
|
||||||
render::Type type, int fps)
|
RenderType type, int fps)
|
||||||
{
|
{
|
||||||
if (framePaths.empty() || ffmpegPath.empty() || path.empty()) return false;
|
if (framePaths.empty() || ffmpegPath.empty() || path.empty()) return false;
|
||||||
fps = std::max(fps, 1);
|
fps = std::max(fps, 1);
|
||||||
|
|
||||||
auto pathString = path::to_utf8(path);
|
auto pathString = path_to_utf8(path);
|
||||||
auto ffmpegPathString = path::to_utf8(ffmpegPath);
|
auto ffmpegPathString = path_to_utf8(ffmpegPath);
|
||||||
auto loggerPath = logger.path();
|
auto loggerPath = logger.path();
|
||||||
auto loggerPathString = path::to_utf8(loggerPath);
|
auto loggerPathString = path_to_utf8(loggerPath);
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
auto ffmpegTempPath = loggerPath.parent_path() / "ffmpeg_log.temp.txt";
|
auto ffmpegTempPath = loggerPath.parent_path() / "ffmpeg_log.temp.txt";
|
||||||
auto ffmpegTempPathString = path::to_utf8(ffmpegTempPath);
|
auto ffmpegTempPathString = path_to_utf8(ffmpegTempPath);
|
||||||
std::error_code ffmpegTempError;
|
std::error_code ffmpegTempError;
|
||||||
std::filesystem::remove(ffmpegTempPath, ffmpegTempError);
|
std::filesystem::remove(ffmpegTempPath, ffmpegTempError);
|
||||||
#endif
|
#endif
|
||||||
@@ -68,16 +62,16 @@ namespace anm2ed
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (type != render::GIF && !audioStream.stream.empty() && audioStream.spec.freq > 0 &&
|
if (type != RENDER_GIF && !audioStream.stream.empty() && audioStream.spec.freq > 0 &&
|
||||||
audioStream.spec.channels > 0)
|
audioStream.spec.channels > 0)
|
||||||
{
|
{
|
||||||
auto tempFilenameUtf8 =
|
auto tempFilenameUtf8 =
|
||||||
std::format("anm2ed_audio_{}_{}.f32", std::hash<std::string>{}(pathString), SDL_GetTicks());
|
std::format("anm2ed_audio_{}_{}.f32", std::hash<std::string>{}(pathString), SDL_GetTicks());
|
||||||
audioPath = temporaryDirectory / path::from_utf8(tempFilenameUtf8);
|
audioPath = temporaryDirectory / path_from_utf8(tempFilenameUtf8);
|
||||||
|
|
||||||
auto data = (const char*)audioStream.stream.data();
|
auto data = (const char*)audioStream.stream.data();
|
||||||
auto byteCount = audioStream.stream.size() * sizeof(float);
|
auto byteCount = audioStream.stream.size() * sizeof(float);
|
||||||
if (file::write_string(audioPath, std::string_view(data, byteCount), "wb"))
|
if (file_text_save(audioPath, std::string_view(data, byteCount), "wb"))
|
||||||
{
|
{
|
||||||
auto sampleRate = std::max(audioStream.spec.freq, 1);
|
auto sampleRate = std::max(audioStream.spec.freq, 1);
|
||||||
auto channels = std::max(audioStream.spec.channels, 1);
|
auto channels = std::max(audioStream.spec.channels, 1);
|
||||||
@@ -88,17 +82,17 @@ namespace anm2ed
|
|||||||
audioDurationFilter += std::format("apad,atrim=duration={:.9f}", expectedDurationSeconds);
|
audioDurationFilter += std::format("apad,atrim=duration={:.9f}", expectedDurationSeconds);
|
||||||
|
|
||||||
audioInputArguments =
|
audioInputArguments =
|
||||||
std::format("-f f32le -ar {0} -ac {1} -i \"{2}\"", sampleRate, channels, path::to_utf8(audioPath));
|
std::format("-f f32le -ar {0} -ac {1} -i \"{2}\"", sampleRate, channels, path_to_utf8(audioPath));
|
||||||
|
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case render::WEBM:
|
case RENDER_WEBM:
|
||||||
audioOutputArguments = "-c:a libopus -b:a 160k -shortest";
|
audioOutputArguments = "-c:a libopus -b:a 160k -shortest";
|
||||||
break;
|
break;
|
||||||
case render::OGV:
|
case RENDER_OGV:
|
||||||
audioOutputArguments = "-c:a libvorbis -q:a 4 -shortest";
|
audioOutputArguments = "-c:a libvorbis -q:a 4 -shortest";
|
||||||
break;
|
break;
|
||||||
case render::MP4:
|
case RENDER_MP4:
|
||||||
audioOutputArguments = "-c:a aac -b:a 192k -shortest";
|
audioOutputArguments = "-c:a aac -b:a 192k -shortest";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -115,8 +109,8 @@ namespace anm2ed
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto framePattern = temporaryDirectory / path::from_utf8("frame_%06d.png");
|
auto framePattern = temporaryDirectory / path_from_utf8("frame_%06d.png");
|
||||||
auto framePatternString = path::to_utf8(framePattern);
|
auto framePatternString = path_to_utf8(framePattern);
|
||||||
command =
|
command =
|
||||||
std::format("\"{0}\" -y -framerate {1} -start_number 0 -i \"{2}\"", ffmpegPathString, fps, framePatternString);
|
std::format("\"{0}\" -y -framerate {1} -start_number 0 -i \"{2}\"", ffmpegPathString, fps, framePatternString);
|
||||||
|
|
||||||
@@ -125,23 +119,23 @@ namespace anm2ed
|
|||||||
|
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case render::GIF:
|
case RENDER_GIF:
|
||||||
command += " -lavfi \"split[s0][s1];[s0]palettegen=stats_mode=full:reserve_transparent=1[p];"
|
command += " -lavfi \"split[s0][s1];[s0]palettegen=stats_mode=full:reserve_transparent=1[p];"
|
||||||
"[s1][p]paletteuse=dither=floyd_steinberg:alpha_threshold=128\""
|
"[s1][p]paletteuse=dither=floyd_steinberg:alpha_threshold=128\""
|
||||||
" -loop 0";
|
" -loop 0";
|
||||||
command += std::format(" \"{}\"", pathString);
|
command += std::format(" \"{}\"", pathString);
|
||||||
break;
|
break;
|
||||||
case render::WEBM:
|
case RENDER_WEBM:
|
||||||
command += " -c:v libvpx-vp9 -crf 30 -b:v 0 -pix_fmt yuva420p -row-mt 1 -threads 0 -speed 2 -auto-alt-ref 0";
|
command += " -c:v libvpx-vp9 -crf 30 -b:v 0 -pix_fmt yuva420p -row-mt 1 -threads 0 -speed 2 -auto-alt-ref 0";
|
||||||
if (!audioOutputArguments.empty()) command += " " + audioOutputArguments;
|
if (!audioOutputArguments.empty()) command += " " + audioOutputArguments;
|
||||||
command += std::format(" \"{}\"", pathString);
|
command += std::format(" \"{}\"", pathString);
|
||||||
break;
|
break;
|
||||||
case render::OGV:
|
case RENDER_OGV:
|
||||||
command += " -vf \"format=yuv420p,scale=trunc(iw/2)*2:trunc(ih/2)*2\" -c:v libtheora -q:v 7";
|
command += " -vf \"format=yuv420p,scale=trunc(iw/2)*2:trunc(ih/2)*2\" -c:v libtheora -q:v 7";
|
||||||
if (!audioOutputArguments.empty()) command += " " + audioOutputArguments;
|
if (!audioOutputArguments.empty()) command += " " + audioOutputArguments;
|
||||||
command += std::format(" \"{}\"", pathString);
|
command += std::format(" \"{}\"", pathString);
|
||||||
break;
|
break;
|
||||||
case render::MP4:
|
case RENDER_MP4:
|
||||||
command += " -vf \"format=yuv420p,scale=trunc(iw/2)*2:trunc(ih/2)*2\" -c:v libx265 -crf 20 -preset slow"
|
command += " -vf \"format=yuv420p,scale=trunc(iw/2)*2:trunc(ih/2)*2\" -c:v libx265 -crf 20 -preset slow"
|
||||||
" -tag:v hvc1 -movflags +faststart";
|
" -tag:v hvc1 -movflags +faststart";
|
||||||
if (!audioOutputArguments.empty()) command += " " + audioOutputArguments;
|
if (!audioOutputArguments.empty()) command += " " + audioOutputArguments;
|
||||||
@@ -182,24 +176,21 @@ namespace anm2ed
|
|||||||
audio_remove();
|
audio_remove();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
namespace anm2ed::render
|
|
||||||
{
|
|
||||||
constexpr int TEMP_DIRECTORY_ATTEMPTS = 1000;
|
constexpr int TEMP_DIRECTORY_ATTEMPTS = 1000;
|
||||||
constexpr glm::vec4 BOUNDS_DEFAULT = {-32.0f, -32.0f, 64.0f, 64.0f};
|
constexpr glm::vec4 BOUNDS_DEFAULT = {-32.0f, -32.0f, 64.0f, 64.0f};
|
||||||
constexpr int ALPHA_OPAQUE = 255;
|
constexpr int ALPHA_OPAQUE = 255;
|
||||||
constexpr float CHANNEL_MAX = 255.0f;
|
constexpr float CHANNEL_MAX = 255.0f;
|
||||||
|
|
||||||
std::filesystem::path frame_filename_get(const std::filesystem::path& format, int index, Type type)
|
static std::filesystem::path frame_filename_get(const std::filesystem::path& format, int index, RenderType type)
|
||||||
{
|
{
|
||||||
auto fallback = path::from_utf8(std::format("frame_{:06}.png", index));
|
auto fallback = path_from_utf8(std::format("frame_{:06}.png", index));
|
||||||
if (type != PNGS) return fallback;
|
if (type != RENDER_PNGS) return fallback;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto filename = path::from_utf8(std::vformat(path::to_utf8(format), std::make_format_args(index))).filename();
|
auto filename = path_from_utf8(std::vformat(path_to_utf8(format), std::make_format_args(index))).filename();
|
||||||
if (filename.empty()) return fallback;
|
if (filename.empty()) return fallback;
|
||||||
if (filename.extension().empty()) filename.replace_extension(EXTENSIONS[SPRITESHEET]);
|
if (filename.extension().empty()) filename.replace_extension(RENDER_EXTENSIONS[RENDER_SPRITESHEET]);
|
||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
@@ -209,10 +200,10 @@ namespace anm2ed::render
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PNG sequences go straight to their folder; other outputs collect frames in a temporary folder beside the output.
|
// PNG sequences go straight to their folder; other outputs collect frames in a temporary folder beside the output.
|
||||||
std::filesystem::path frames_directory_create(const RecorderOptions& options)
|
static std::filesystem::path frames_directory_create(const RecorderOptions& options)
|
||||||
{
|
{
|
||||||
std::error_code ec{};
|
std::error_code ec{};
|
||||||
if (options.type == PNGS)
|
if (options.type == RENDER_PNGS)
|
||||||
{
|
{
|
||||||
std::filesystem::create_directories(options.path, ec);
|
std::filesystem::create_directories(options.path, ec);
|
||||||
return options.path;
|
return options.path;
|
||||||
@@ -225,7 +216,7 @@ namespace anm2ed::render
|
|||||||
.count();
|
.count();
|
||||||
for (int suffix = 0; suffix < TEMP_DIRECTORY_ATTEMPTS; ++suffix)
|
for (int suffix = 0; suffix < TEMP_DIRECTORY_ATTEMPTS; ++suffix)
|
||||||
{
|
{
|
||||||
auto temporary = directory / path::from_utf8(std::format(".anm2ed_render_tmp_{}_{}", timestamp, suffix));
|
auto temporary = directory / path_from_utf8(std::format(".anm2ed_render_tmp_{}_{}", timestamp, suffix));
|
||||||
if (std::filesystem::create_directories(temporary, ec)) return temporary;
|
if (std::filesystem::create_directories(temporary, ec)) return temporary;
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
@@ -234,7 +225,7 @@ namespace anm2ed::render
|
|||||||
// Rendered pixels are premultiplied; outputs on a transparent background want straight alpha.
|
// Rendered pixels are premultiplied; outputs on a transparent background want straight alpha.
|
||||||
void pixels_unpremultiply(std::vector<uint8_t>& pixels)
|
void pixels_unpremultiply(std::vector<uint8_t>& pixels)
|
||||||
{
|
{
|
||||||
for (std::size_t index = 0; index + 3 < pixels.size(); index += image::CHANNELS)
|
for (std::size_t index = 0; index + 3 < pixels.size(); index += IMAGE_CHANNELS)
|
||||||
{
|
{
|
||||||
auto alpha = pixels[index + 3];
|
auto alpha = pixels[index + 3];
|
||||||
if (alpha == ALPHA_OPAQUE) continue;
|
if (alpha == ALPHA_OPAQUE) continue;
|
||||||
@@ -246,15 +237,15 @@ namespace anm2ed::render
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sounds_detach(const Document& document, MIX_Mixer* mixer)
|
static void sounds_detach(const Document& document, MIX_Mixer* mixer)
|
||||||
{
|
{
|
||||||
for (auto sound : document.sounds_get())
|
for (auto sound : document.sounds_get())
|
||||||
audio::track_detach(*sound, mixer);
|
audio_track_detach(*sound, mixer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mixes each frame's trigger sounds into one stream at the render frame rate.
|
// Mixes each frame's trigger sounds into one stream at the render frame rate.
|
||||||
bool audio_stream_generate(AudioStream& audioStream, const Document& document,
|
static bool audio_stream_generate(AudioStream& audioStream, const Document& document,
|
||||||
const std::vector<std::vector<const resource::AudioData*>>& frameSounds, int fps)
|
const std::vector<std::vector<const AudioData*>>& frameSounds, int fps)
|
||||||
{
|
{
|
||||||
audioStream.stream.clear();
|
audioStream.stream.clear();
|
||||||
if (frameSounds.empty() || fps <= 0) return true;
|
if (frameSounds.empty() || fps <= 0) return true;
|
||||||
@@ -272,7 +263,7 @@ namespace anm2ed::render
|
|||||||
for (const auto& sounds : frameSounds)
|
for (const auto& sounds : frameSounds)
|
||||||
{
|
{
|
||||||
for (auto sound : sounds)
|
for (auto sound : sounds)
|
||||||
audio::play(*sound, false, mixer);
|
audio_play(*sound, false, mixer);
|
||||||
accumulator += framesPerStep;
|
accumulator += framesPerStep;
|
||||||
auto sampleFrames = std::max((int)std::floor(accumulator), 1);
|
auto sampleFrames = std::max((int)std::floor(accumulator), 1);
|
||||||
accumulator -= (double)sampleFrames;
|
accumulator -= (double)sampleFrames;
|
||||||
@@ -313,14 +304,14 @@ namespace anm2ed::render
|
|||||||
|
|
||||||
bool HeadlessGL::is_valid() const { return context != nullptr; }
|
bool HeadlessGL::is_valid() const { return context != nullptr; }
|
||||||
|
|
||||||
glm::vec4 animation_bounds_get(const Document& document, const model::Animation& animation, bool isRootTransform)
|
glm::vec4 animation_bounds_get(const Document& document, const Animation& animation, bool isRootTransform)
|
||||||
{
|
{
|
||||||
auto bounds = model::animation_rect(document.model, animation, isRootTransform, document.library_resolver_get());
|
auto bounds = animation_rect(document.model, animation, isRootTransform, document.library_resolver_get());
|
||||||
return bounds != glm::vec4(-1.0f) ? bounds : BOUNDS_DEFAULT;
|
return bounds != glm::vec4(-1.0f) ? bounds : BOUNDS_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<uint8_t> animation_frame_render(Canvas& canvas, Shader& shader, Document& document,
|
std::vector<uint8_t> animation_frame_render(Canvas& canvas, ShaderProgram& shader, Document& document,
|
||||||
const model::Animation& animation, float time, glm::vec4 bounds,
|
const Animation& animation, float time, glm::vec4 bounds,
|
||||||
float scale, glm::vec4 background, bool isRootTransform)
|
float scale, glm::vec4 background, bool isRootTransform)
|
||||||
{
|
{
|
||||||
canvas.size_set(glm::vec2(glm::max(glm::ivec2(glm::ceil(glm::vec2(bounds.z, bounds.w) * scale)), glm::ivec2(1))));
|
canvas.size_set(glm::vec2(glm::max(glm::ivec2(glm::ceil(glm::vec2(bounds.z, bounds.w) * scale)), glm::ivec2(1))));
|
||||||
@@ -334,7 +325,7 @@ namespace anm2ed::render
|
|||||||
shader, document.model, animation,
|
shader, document.model, animation,
|
||||||
{.time = time, .isRootTransform = isRootTransform, .library_get = document.library_resolver_get()},
|
{.time = time, .isRootTransform = isRootTransform, .library_get = document.library_resolver_get()},
|
||||||
canvas.transform_get(zoom, pan),
|
canvas.transform_get(zoom, pan),
|
||||||
[&](const model::Draw& draw) { return document.draw_image_get(draw, scale * model::draw_scale_get(draw)); },
|
[&](const Draw& draw) { return document.draw_image_get(draw, scale * draw_scale_get(draw)); },
|
||||||
[&](int id) { return document.shader_get(id); });
|
[&](int id) { return document.shader_get(id); });
|
||||||
auto pixels = canvas.pixels_get();
|
auto pixels = canvas.pixels_get();
|
||||||
canvas.unbind();
|
canvas.unbind();
|
||||||
@@ -361,7 +352,7 @@ namespace anm2ed::render
|
|||||||
bool Recorder::is_sound_frame() const { return (int)std::floor(time_get()) != soundTime; }
|
bool Recorder::is_sound_frame() const { return (int)std::floor(time_get()) != soundTime; }
|
||||||
|
|
||||||
bool Recorder::frame_capture(std::vector<uint8_t> pixels, glm::ivec2 size,
|
bool Recorder::frame_capture(std::vector<uint8_t> pixels, glm::ivec2 size,
|
||||||
std::vector<const resource::AudioData*> frameSounds)
|
std::vector<const AudioData*> frameSounds)
|
||||||
{
|
{
|
||||||
soundTime = (int)std::floor(time_get());
|
soundTime = (int)std::floor(time_get());
|
||||||
sounds.push_back(std::move(frameSounds));
|
sounds.push_back(std::move(frameSounds));
|
||||||
@@ -375,11 +366,11 @@ namespace anm2ed::render
|
|||||||
|
|
||||||
void Recorder::finish(const Document& document, AudioStream& audioStream)
|
void Recorder::finish(const Document& document, AudioStream& audioStream)
|
||||||
{
|
{
|
||||||
auto pathString = path::to_utf8(options.path);
|
auto pathString = path_to_utf8(options.path);
|
||||||
if (options.type == PNGS)
|
if (options.type == RENDER_PNGS)
|
||||||
toast_log(frames.empty() ? Level::ERROR : Level::INFO,
|
toast_log(frames.empty() ? Level::ERROR : Level::INFO,
|
||||||
frames.empty() ? TOAST_EXPORT_RENDERED_FRAMES_FAILED : TOAST_EXPORT_RENDERED_FRAMES, pathString);
|
frames.empty() ? TOAST_EXPORT_RENDERED_FRAMES_FAILED : TOAST_EXPORT_RENDERED_FRAMES, pathString);
|
||||||
else if (options.type == SPRITESHEET)
|
else if (options.type == RENDER_SPRITESHEET)
|
||||||
{
|
{
|
||||||
auto layout = spritesheet_layout_get(options.rows, options.columns, (int)frames.size());
|
auto layout = spritesheet_layout_get(options.rows, options.columns, (int)frames.size());
|
||||||
auto first = frames.empty() ? Image{} : Image(frames.front());
|
auto first = frames.empty() ? Image{} : Image(frames.front());
|
||||||
@@ -391,7 +382,7 @@ namespace anm2ed::render
|
|||||||
{
|
{
|
||||||
Image sheet{};
|
Image sheet{};
|
||||||
sheet.size = first.size * glm::ivec2(layout.columns, layout.rows);
|
sheet.size = first.size * glm::ivec2(layout.columns, layout.rows);
|
||||||
sheet.pixels.resize((std::size_t)sheet.size.x * sheet.size.y * image::CHANNELS);
|
sheet.pixels.resize((std::size_t)sheet.size.x * sheet.size.y * IMAGE_CHANNELS);
|
||||||
for (int i = 0; i < (int)frames.size() && i < layout.rows * layout.columns; ++i)
|
for (int i = 0; i < (int)frames.size() && i < layout.rows * layout.columns; ++i)
|
||||||
if (auto frame = Image(frames[i]); frame.size == first.size)
|
if (auto frame = Image(frames[i]); frame.size == first.size)
|
||||||
sheet.paste(frame, first.size * glm::ivec2(i % layout.columns, i / layout.columns));
|
sheet.paste(frame, first.size * glm::ivec2(i % layout.columns, i / layout.columns));
|
||||||
@@ -403,7 +394,7 @@ namespace anm2ed::render
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
audioStream.stream.clear();
|
audioStream.stream.clear();
|
||||||
if (options.isSound && options.type != GIF && !audio_stream_generate(audioStream, document, sounds, options.fps))
|
if (options.isSound && options.type != RENDER_GIF && !audio_stream_generate(audioStream, document, sounds, options.fps))
|
||||||
{
|
{
|
||||||
toasts.push(localize.get(TOAST_EXPORT_RENDERED_ANIMATION_FAILED));
|
toasts.push(localize.get(TOAST_EXPORT_RENDERED_ANIMATION_FAILED));
|
||||||
logger.error("Failed to generate deterministic render audio stream; exporting without audio.");
|
logger.error("Failed to generate deterministic render audio stream; exporting without audio.");
|
||||||
@@ -420,15 +411,15 @@ namespace anm2ed::render
|
|||||||
void Recorder::cancel()
|
void Recorder::cancel()
|
||||||
{
|
{
|
||||||
std::error_code ec{};
|
std::error_code ec{};
|
||||||
if (options.type != PNGS && !directory.empty()) std::filesystem::remove_all(directory, ec);
|
if (options.type != RENDER_PNGS && !directory.empty()) std::filesystem::remove_all(directory, ec);
|
||||||
directory.clear();
|
directory.clear();
|
||||||
frames.clear();
|
frames.clear();
|
||||||
sounds.clear();
|
sounds.clear();
|
||||||
index = count = 0;
|
index = count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool animation_record(const RecorderOptions& recorderOptions, Canvas& canvas, Shader& shader, Document& document,
|
bool animation_record(const RecorderOptions& recorderOptions, Canvas& canvas, ShaderProgram& shader, Document& document,
|
||||||
const model::Animation& animation, glm::vec4 bounds, float scale, glm::vec4 background,
|
const Animation& animation, glm::vec4 bounds, float scale, glm::vec4 background,
|
||||||
bool isRootTransform)
|
bool isRootTransform)
|
||||||
{
|
{
|
||||||
auto options = recorderOptions;
|
auto options = recorderOptions;
|
||||||
@@ -445,7 +436,7 @@ namespace anm2ed::render
|
|||||||
}
|
}
|
||||||
AudioStream audioStream(nullptr);
|
AudioStream audioStream(nullptr);
|
||||||
recorder.finish(document, audioStream);
|
recorder.finish(document, audioStream);
|
||||||
return path::is_exist(options.path);
|
return is_path_exist(options.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr float BAKE_MARGIN = 1.0f;
|
constexpr float BAKE_MARGIN = 1.0f;
|
||||||
@@ -453,12 +444,12 @@ namespace anm2ed::render
|
|||||||
|
|
||||||
// A layer draw alone at canvas pixels, cut to what it can cover (its blur's reach too): its image (straight alpha) and
|
// A layer draw alone at canvas pixels, cut to what it can cover (its blur's reach too): its image (straight alpha) and
|
||||||
// the canvas position of the image's top-left. Its tint and color offset go into the pixels only when `isColored`.
|
// the canvas position of the image's top-left. Its tint and color offset go into the pixels only when `isColored`.
|
||||||
std::optional<std::pair<Image, glm::vec2>> draw_bake(Canvas& canvas, Shader& shader, Document& document,
|
static std::optional<std::pair<Image, glm::vec2>> draw_bake(Canvas& canvas, ShaderProgram& shader, Document& document,
|
||||||
const model::Draw& draw, bool isColored)
|
const Draw& draw, bool isColored)
|
||||||
{
|
{
|
||||||
auto image = document.draw_image_get(draw, model::draw_scale_get(draw));
|
auto image = document.draw_image_get(draw, draw_scale_get(draw));
|
||||||
if (!image || !image->is_valid() || draw.frame.size == glm::vec2()) return {};
|
if (!image || !image->is_valid() || draw.frame.size == glm::vec2()) return {};
|
||||||
auto quad = draw.parent * model::draw_quad_model_get(draw);
|
auto quad = draw.parent * draw_quad_model_get(draw);
|
||||||
glm::vec2 low{std::numeric_limits<float>::max()};
|
glm::vec2 low{std::numeric_limits<float>::max()};
|
||||||
glm::vec2 high{std::numeric_limits<float>::lowest()};
|
glm::vec2 high{std::numeric_limits<float>::lowest()};
|
||||||
for (auto corner : {glm::vec2(0.0f), glm::vec2(1.0f, 0.0f), glm::vec2(0.0f, 1.0f), glm::vec2(1.0f)})
|
for (auto corner : {glm::vec2(0.0f), glm::vec2(1.0f, 0.0f), glm::vec2(0.0f, 1.0f), glm::vec2(1.0f)})
|
||||||
@@ -480,7 +471,7 @@ namespace anm2ed::render
|
|||||||
canvas.viewport_set();
|
canvas.viewport_set();
|
||||||
canvas.clear(glm::vec4(0.0f));
|
canvas.clear(glm::vec4(0.0f));
|
||||||
auto custom = document.shader_get(draw.frame.shaderId);
|
auto custom = document.shader_get(draw.frame.shaderId);
|
||||||
canvas.layer_render(custom ? *custom : shader, texture::id_get(*image), image->unit_size_get(),
|
canvas.layer_render(custom ? *custom : shader, texture_id_get(*image), image->unit_size_get(),
|
||||||
canvas.transform_get(zoom, pan), draw, isColored ? draw.frame.tint : glm::vec4(1.0f),
|
canvas.transform_get(zoom, pan), draw, isColored ? draw.frame.tint : glm::vec4(1.0f),
|
||||||
isColored ? draw.frame.colorOffset : glm::vec4(0.0f));
|
isColored ? draw.frame.colorOffset : glm::vec4(0.0f));
|
||||||
auto pixels = canvas.pixels_get();
|
auto pixels = canvas.pixels_get();
|
||||||
@@ -493,33 +484,33 @@ namespace anm2ed::render
|
|||||||
// layer frame under a skewed root or group root, which then goes into the images (the root becomes plain). A layer has one spritesheet in the game, so baked frames stand on a copy of their layer
|
// layer frame under a skewed root or group root, which then goes into the images (the root becomes plain). A layer has one spritesheet in the game, so baked frames stand on a copy of their layer
|
||||||
// ("name (baked)") right after it, one frame per step, while the layer hides them. The images (each once) are packed
|
// ("name (baked)") right after it, one frame per step, while the layer hides them. The images (each once) are packed
|
||||||
// into one spritesheet written to `path`, beside the document; when it can't be, `result` keeps its frames.
|
// into one spritesheet written to `path`, beside the document; when it can't be, `result` keeps its frames.
|
||||||
void frames_bake(Document& document, model::Model& result, const std::filesystem::path& path)
|
void frames_bake(Document& document, Model& result, const std::filesystem::path& path)
|
||||||
{
|
{
|
||||||
auto game = result;
|
auto game = result;
|
||||||
auto is_baked = [](const model::Frame& frame)
|
auto is_baked = [](const Frame& frame)
|
||||||
{ return frame.skew != glm::vec2() || frame.blur > 0.0f || frame.shaderId != -1; };
|
{ return frame.skew != glm::vec2() || frame.blur > 0.0f || frame.shaderId != -1; };
|
||||||
auto is_skewed = [](const model::Track& root)
|
auto is_skewed = [](const Track& root)
|
||||||
{ return std::ranges::any_of(root.frames, [](const model::Frame& frame) { return frame.skew != glm::vec2(); }); };
|
{ return std::ranges::any_of(root.frames, [](const Frame& frame) { return frame.skew != glm::vec2(); }); };
|
||||||
|
|
||||||
std::vector<int> indices{};
|
std::vector<int> indices{};
|
||||||
for (int i = 0; i < game.animations_count_get(); ++i)
|
for (int i = 0; i < game.animations_count_get(); ++i)
|
||||||
{
|
{
|
||||||
auto& animation = *game.animation_get(i);
|
auto& animation = *game.animation_get(i);
|
||||||
auto isNeeded = is_skewed(animation.root);
|
auto isNeeded = is_skewed(animation.root);
|
||||||
model::tracks_each(
|
tracks_each(
|
||||||
animation.layers, [&](const model::Track& track, const model::TrackGroup* group)
|
animation.layers, [&](const Track& track, const TrackGroup* group)
|
||||||
{ isNeeded |= (group && is_skewed(group->root)) || std::ranges::any_of(track.frames, is_baked); });
|
{ isNeeded |= (group && is_skewed(group->root)) || std::ranges::any_of(track.frames, is_baked); });
|
||||||
if (isNeeded) indices.push_back(i);
|
if (isNeeded) indices.push_back(i);
|
||||||
}
|
}
|
||||||
auto pathUtf8 = path::to_utf8(path);
|
auto pathUtf8 = path_to_utf8(path);
|
||||||
if (indices.empty()) return;
|
if (indices.empty()) return;
|
||||||
if (!SDL_GL_GetCurrentContext()) return toast_log(Level::WARNING, TOAST_BAKE_NO_OPENGL, pathUtf8);
|
if (!SDL_GL_GetCurrentContext()) return toast_log(Level::WARNING, TOAST_BAKE_NO_OPENGL, pathUtf8);
|
||||||
|
|
||||||
auto& textureInfo = shader::SHADERS[shader::TEXTURE];
|
auto& textureInfo = SHADERS[SHADER_TEXTURE];
|
||||||
Shader shader(textureInfo.vertex, textureInfo.fragment);
|
ShaderProgram shader(textureInfo.vertex, textureInfo.fragment);
|
||||||
Canvas canvas(glm::vec2(1.0f));
|
Canvas canvas(glm::vec2(1.0f));
|
||||||
auto& content = game.content;
|
auto& content = game.content;
|
||||||
auto spritesheetId = model::item_next_id_get(content.spritesheets);
|
auto spritesheetId = item_next_id_get(content.spritesheets);
|
||||||
|
|
||||||
std::vector<Image> images{};
|
std::vector<Image> images{};
|
||||||
std::map<std::size_t, std::vector<int>> imageHashes{};
|
std::map<std::size_t, std::vector<int>> imageHashes{};
|
||||||
@@ -538,15 +529,15 @@ namespace anm2ed::render
|
|||||||
{
|
{
|
||||||
auto [it, isNew] = bakedLayerIds.try_emplace(layerId);
|
auto [it, isNew] = bakedLayerIds.try_emplace(layerId);
|
||||||
if (!isNew) return it->second;
|
if (!isNew) return it->second;
|
||||||
auto layer = model::item_get(content.layers, layerId);
|
auto layer = item_get(content.layers, layerId);
|
||||||
it->second = model::item_next_id_get(content.layers);
|
it->second = item_next_id_get(content.layers);
|
||||||
content.layers.push_back({.id = it->second,
|
content.layers.push_back({.id = it->second,
|
||||||
.name = (layer ? layer->name : std::string{}) + " (baked)",
|
.name = (layer ? layer->name : std::string{}) + " (baked)",
|
||||||
.spritesheetId = spritesheetId});
|
.spritesheetId = spritesheetId});
|
||||||
return it->second;
|
return it->second;
|
||||||
};
|
};
|
||||||
// Steps alike join into one frame.
|
// Steps alike join into one frame.
|
||||||
auto step_add = [](model::Track& track, model::Frame frame)
|
auto step_add = [](Track& track, Frame frame)
|
||||||
{
|
{
|
||||||
frame.duration = FRAME_DURATION_MIN;
|
frame.duration = FRAME_DURATION_MIN;
|
||||||
frame.interpolation = Interpolation::NONE;
|
frame.interpolation = Interpolation::NONE;
|
||||||
@@ -565,21 +556,21 @@ namespace anm2ed::render
|
|||||||
auto& animation = *game.animation_edit(index);
|
auto& animation = *game.animation_edit(index);
|
||||||
auto isRootFolded = is_skewed(animation.root);
|
auto isRootFolded = is_skewed(animation.root);
|
||||||
// A layer track's baked copy, the track left with the rest; nothing when no frame of it bakes.
|
// A layer track's baked copy, the track left with the rest; nothing when no frame of it bakes.
|
||||||
auto track_bake = [&](model::Track& track, const model::Track* groupRoot) -> std::optional<model::Track>
|
auto track_bake = [&](Track& track, const Track* groupRoot) -> std::optional<Track>
|
||||||
{
|
{
|
||||||
auto isForced = isRootFolded || groupRoot;
|
auto isForced = isRootFolded || groupRoot;
|
||||||
auto layer = model::item_get(content.layers, track.id);
|
auto layer = item_get(content.layers, track.id);
|
||||||
if (!layer || (!isForced && std::ranges::none_of(track.frames, is_baked))) return {};
|
if (!layer || (!isForced && std::ranges::none_of(track.frames, is_baked))) return {};
|
||||||
model::Track plain{track};
|
Track plain{track};
|
||||||
plain.frames.clear();
|
plain.frames.clear();
|
||||||
model::Track baked{.type = ItemType::LAYER, .id = -1, .isVisible = track.isVisible};
|
Track baked{.type = ItemType::LAYER, .id = -1, .isVisible = track.isVisible};
|
||||||
auto isBaked = false;
|
auto isBaked = false;
|
||||||
auto length = std::max(model::track_length_get(track), animation.frameNum);
|
auto length = std::max(track_length_get(track), animation.frameNum);
|
||||||
for (int time = 0; time < length; ++time)
|
for (int time = 0; time < length; ++time)
|
||||||
{
|
{
|
||||||
auto frame = model::frame_generate(track, (float)time);
|
auto frame = frame_generate(track, (float)time);
|
||||||
std::optional<std::pair<Image, glm::vec2>> bakedImage{};
|
std::optional<std::pair<Image, glm::vec2>> bakedImage{};
|
||||||
model::Draw draw{.type = model::DrawType::LAYER,
|
Draw draw{.type = DrawType::LAYER,
|
||||||
.id = track.id,
|
.id = track.id,
|
||||||
.time = (float)time,
|
.time = (float)time,
|
||||||
.frame = frame,
|
.frame = frame,
|
||||||
@@ -588,11 +579,11 @@ namespace anm2ed::render
|
|||||||
if (frame.isVisible && (isForced || is_baked(frame)))
|
if (frame.isVisible && (isForced || is_baked(frame)))
|
||||||
{
|
{
|
||||||
for (auto* root :
|
for (auto* root :
|
||||||
std::initializer_list<const model::Track*>{isRootFolded ? &animation.root : nullptr, groupRoot})
|
std::initializer_list<const Track*>{isRootFolded ? &animation.root : nullptr, groupRoot})
|
||||||
if (root)
|
if (root)
|
||||||
{
|
{
|
||||||
auto rootFrame = model::frame_generate(*root, (float)time);
|
auto rootFrame = frame_generate(*root, (float)time);
|
||||||
draw.parent *= model::frame_parent_model_get(rootFrame);
|
draw.parent *= frame_parent_model_get(rootFrame);
|
||||||
draw.frame.tint *= rootFrame.tint;
|
draw.frame.tint *= rootFrame.tint;
|
||||||
draw.frame.colorOffset += rootFrame.colorOffset;
|
draw.frame.colorOffset += rootFrame.colorOffset;
|
||||||
}
|
}
|
||||||
@@ -601,7 +592,7 @@ namespace anm2ed::render
|
|||||||
if (!bakedImage)
|
if (!bakedImage)
|
||||||
{
|
{
|
||||||
step_add(plain, frame);
|
step_add(plain, frame);
|
||||||
step_add(baked, model::Frame{.isVisible = false});
|
step_add(baked, Frame{.isVisible = false});
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// The image stands where it was drawn, its region found once the images are packed (kept in regionId).
|
// The image stands where it was drawn, its region found once the images are packed (kept in regionId).
|
||||||
@@ -615,14 +606,14 @@ namespace anm2ed::render
|
|||||||
step.size = glm::vec2(bakedImage->first.size);
|
step.size = glm::vec2(bakedImage->first.size);
|
||||||
step.pivot = {};
|
step.pivot = {};
|
||||||
step.position = bakedImage->second;
|
step.position = bakedImage->second;
|
||||||
step.scale = model::Frame{}.scale;
|
step.scale = Frame{}.scale;
|
||||||
step.skew = {};
|
step.skew = {};
|
||||||
step.rotation = 0.0f;
|
step.rotation = 0.0f;
|
||||||
step.blur = 0.0f;
|
step.blur = 0.0f;
|
||||||
step.shaderId = -1;
|
step.shaderId = -1;
|
||||||
step.regionId = image_index_get(std::move(bakedImage->first));
|
step.regionId = image_index_get(std::move(bakedImage->first));
|
||||||
step_add(baked, step);
|
step_add(baked, step);
|
||||||
step_add(plain, model::Frame{.isVisible = false});
|
step_add(plain, Frame{.isVisible = false});
|
||||||
isBaked = true;
|
isBaked = true;
|
||||||
}
|
}
|
||||||
if (!isBaked) return {};
|
if (!isBaked) return {};
|
||||||
@@ -631,9 +622,9 @@ namespace anm2ed::render
|
|||||||
return baked;
|
return baked;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<model::TrackEntry> entries{};
|
std::vector<TrackEntry> entries{};
|
||||||
for (auto& entry : animation.layers)
|
for (auto& entry : animation.layers)
|
||||||
if (auto track = std::get_if<model::Track>(&entry))
|
if (auto track = std::get_if<Track>(&entry))
|
||||||
{
|
{
|
||||||
auto baked = track_bake(*track, nullptr);
|
auto baked = track_bake(*track, nullptr);
|
||||||
entries.emplace_back(std::move(*track));
|
entries.emplace_back(std::move(*track));
|
||||||
@@ -641,9 +632,9 @@ namespace anm2ed::render
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto group = std::get<model::TrackGroup>(entry);
|
auto group = std::get<TrackGroup>(entry);
|
||||||
auto isGroupFolded = is_skewed(group.root);
|
auto isGroupFolded = is_skewed(group.root);
|
||||||
std::vector<model::Track> tracks{};
|
std::vector<Track> tracks{};
|
||||||
for (auto& groupTrack : group.tracks)
|
for (auto& groupTrack : group.tracks)
|
||||||
{
|
{
|
||||||
auto baked = track_bake(groupTrack, isGroupFolded ? &group.root : nullptr);
|
auto baked = track_bake(groupTrack, isGroupFolded ? &group.root : nullptr);
|
||||||
@@ -651,7 +642,7 @@ namespace anm2ed::render
|
|||||||
if (baked) tracks.push_back(std::move(*baked));
|
if (baked) tracks.push_back(std::move(*baked));
|
||||||
}
|
}
|
||||||
group.tracks = std::move(tracks);
|
group.tracks = std::move(tracks);
|
||||||
if (isGroupFolded) group.root = model::TrackGroup{}.root;
|
if (isGroupFolded) group.root = TrackGroup{}.root;
|
||||||
entries.emplace_back(std::move(group));
|
entries.emplace_back(std::move(group));
|
||||||
}
|
}
|
||||||
animation.layers = std::move(entries);
|
animation.layers = std::move(entries);
|
||||||
@@ -659,19 +650,19 @@ namespace anm2ed::render
|
|||||||
// A folded root's transform goes into the nulls too (their group roots first), and the root becomes plain.
|
// A folded root's transform goes into the nulls too (their group roots first), and the root becomes plain.
|
||||||
if (!isRootFolded) continue;
|
if (!isRootFolded) continue;
|
||||||
for (auto& entry : animation.nulls)
|
for (auto& entry : animation.nulls)
|
||||||
if (auto track = std::get_if<model::Track>(&entry))
|
if (auto track = std::get_if<Track>(&entry))
|
||||||
model::track_group_root_bake(*track, animation.root, animation.frameNum);
|
track_group_root_bake(*track, animation.root, animation.frameNum);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto& group = std::get<model::TrackGroup>(entry);
|
auto& group = std::get<TrackGroup>(entry);
|
||||||
for (auto& groupTrack : group.tracks)
|
for (auto& groupTrack : group.tracks)
|
||||||
{
|
{
|
||||||
model::track_group_root_bake(groupTrack, group.root, animation.frameNum);
|
track_group_root_bake(groupTrack, group.root, animation.frameNum);
|
||||||
model::track_group_root_bake(groupTrack, animation.root, animation.frameNum);
|
track_group_root_bake(groupTrack, animation.root, animation.frameNum);
|
||||||
}
|
}
|
||||||
group.root = model::TrackGroup{}.root;
|
group.root = TrackGroup{}.root;
|
||||||
}
|
}
|
||||||
animation.root = model::Animation{}.root;
|
animation.root = Animation{}.root;
|
||||||
}
|
}
|
||||||
if (images.empty()) return;
|
if (images.empty()) return;
|
||||||
|
|
||||||
@@ -680,7 +671,7 @@ namespace anm2ed::render
|
|||||||
sizes.push_back(image.size);
|
sizes.push_back(image.size);
|
||||||
glm::ivec2 packedSize{};
|
glm::ivec2 packedSize{};
|
||||||
std::vector<glm::ivec2> positions{};
|
std::vector<glm::ivec2> positions{};
|
||||||
pack::rects_pack(sizes, packedSize, positions);
|
rects_pack(sizes, packedSize, positions);
|
||||||
std::vector<ImagePart> parts{};
|
std::vector<ImagePart> parts{};
|
||||||
for (int i = 0; i < (int)images.size(); ++i)
|
for (int i = 0; i < (int)images.size(); ++i)
|
||||||
parts.push_back({.image = &images[i], .size = images[i].size, .destination = positions[i]});
|
parts.push_back({.image = &images[i], .size = images[i].size, .destination = positions[i]});
|
||||||
@@ -694,8 +685,8 @@ namespace anm2ed::render
|
|||||||
for (auto [layerId, bakedId] : bakedLayerIds)
|
for (auto [layerId, bakedId] : bakedLayerIds)
|
||||||
bakedIds.insert(bakedId);
|
bakedIds.insert(bakedId);
|
||||||
for (auto index : indices)
|
for (auto index : indices)
|
||||||
model::tracks_each(game.animation_edit(index)->layers,
|
tracks_each(game.animation_edit(index)->layers,
|
||||||
[&](model::Track& track, auto*)
|
[&](Track& track, auto*)
|
||||||
{
|
{
|
||||||
if (!bakedIds.contains(track.id)) return;
|
if (!bakedIds.contains(track.id)) return;
|
||||||
for (auto& frame : track.frames)
|
for (auto& frame : track.frames)
|
||||||
@@ -707,4 +698,3 @@ namespace anm2ed::render
|
|||||||
});
|
});
|
||||||
result = std::move(game);
|
result = std::move(game);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
+19
-34
@@ -12,39 +12,28 @@
|
|||||||
struct SDL_Window;
|
struct SDL_Window;
|
||||||
struct SDL_GLContextState;
|
struct SDL_GLContextState;
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
class Canvas;
|
class Canvas;
|
||||||
class Document;
|
class Document;
|
||||||
}
|
|
||||||
|
|
||||||
namespace anm2ed::model
|
|
||||||
{
|
|
||||||
struct Animation;
|
struct Animation;
|
||||||
class Model;
|
class Model;
|
||||||
}
|
|
||||||
|
|
||||||
namespace anm2ed::resource
|
class ShaderProgram;
|
||||||
{
|
|
||||||
class Shader;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace anm2ed::render
|
|
||||||
{
|
|
||||||
#define RENDER_LIST \
|
#define RENDER_LIST \
|
||||||
X(PNGS, "PNGs", "") \
|
X(RENDER_PNGS, "PNGs", "") \
|
||||||
X(SPRITESHEET, "Spritesheet (PNG)", ".png") \
|
X(RENDER_SPRITESHEET, "Spritesheet (PNG)", ".png") \
|
||||||
X(GIF, "GIF", ".gif") \
|
X(RENDER_GIF, "GIF", ".gif") \
|
||||||
X(WEBM, "WebM", ".webm") \
|
X(RENDER_WEBM, "WebM", ".webm") \
|
||||||
X(OGV, "OGV", ".ogv") \
|
X(RENDER_OGV, "OGV", ".ogv") \
|
||||||
X(MP4, "MP4", ".mp4")
|
X(RENDER_MP4, "MP4", ".mp4")
|
||||||
|
|
||||||
enum Type
|
enum RenderType
|
||||||
{
|
{
|
||||||
#define X(symbol, string, extension) symbol,
|
#define X(symbol, string, extension) symbol,
|
||||||
RENDER_LIST
|
RENDER_LIST
|
||||||
#undef X
|
#undef X
|
||||||
COUNT
|
RENDER_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
enum FpsMode
|
enum FpsMode
|
||||||
@@ -54,13 +43,13 @@ namespace anm2ed::render
|
|||||||
FPS_COUNT
|
FPS_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr const char* STRINGS[] = {
|
constexpr const char* RENDER_STRINGS[] = {
|
||||||
#define X(symbol, string, extension) string,
|
#define X(symbol, string, extension) string,
|
||||||
RENDER_LIST
|
RENDER_LIST
|
||||||
#undef X
|
#undef X
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr const char* EXTENSIONS[] = {
|
constexpr const char* RENDER_EXTENSIONS[] = {
|
||||||
#define X(symbol, string, extension) extension,
|
#define X(symbol, string, extension) extension,
|
||||||
RENDER_LIST
|
RENDER_LIST
|
||||||
#undef X
|
#undef X
|
||||||
@@ -140,16 +129,16 @@ namespace anm2ed::render
|
|||||||
};
|
};
|
||||||
|
|
||||||
// The area an animation covers over all its frames (or a default one when it draws nothing).
|
// The area an animation covers over all its frames (or a default one when it draws nothing).
|
||||||
glm::vec4 animation_bounds_get(const Document&, const model::Animation&, bool);
|
glm::vec4 animation_bounds_get(const Document&, const Animation&, bool);
|
||||||
// One frame drawn over `bounds` at `scale`, as premultiplied RGBA rows from the top.
|
// One frame drawn over `bounds` at `scale`, as premultiplied RGBA rows from the top.
|
||||||
std::vector<uint8_t> animation_frame_render(Canvas&, resource::Shader&, Document&, const model::Animation&, float,
|
std::vector<uint8_t> animation_frame_render(Canvas&, ShaderProgram&, Document&, const Animation&, float,
|
||||||
glm::vec4, float, glm::vec4, bool);
|
glm::vec4, float, glm::vec4, bool);
|
||||||
void pixels_unpremultiply(std::vector<uint8_t>&);
|
void pixels_unpremultiply(std::vector<uint8_t>&);
|
||||||
void frames_bake(Document&, model::Model&, const std::filesystem::path&);
|
void frames_bake(Document&, Model&, const std::filesystem::path&);
|
||||||
|
|
||||||
struct RecorderOptions
|
struct RecorderOptions
|
||||||
{
|
{
|
||||||
Type type{};
|
RenderType type{};
|
||||||
std::filesystem::path path{};
|
std::filesystem::path path{};
|
||||||
std::filesystem::path format{};
|
std::filesystem::path format{};
|
||||||
std::filesystem::path ffmpegPath{};
|
std::filesystem::path ffmpegPath{};
|
||||||
@@ -177,26 +166,22 @@ namespace anm2ed::render
|
|||||||
bool is_done() const;
|
bool is_done() const;
|
||||||
float time_get() const;
|
float time_get() const;
|
||||||
bool is_sound_frame() const;
|
bool is_sound_frame() const;
|
||||||
bool frame_capture(std::vector<uint8_t>, glm::ivec2, std::vector<const resource::AudioData*> = {});
|
bool frame_capture(std::vector<uint8_t>, glm::ivec2, std::vector<const AudioData*> = {});
|
||||||
void finish(const Document&, AudioStream&);
|
void finish(const Document&, AudioStream&);
|
||||||
void cancel();
|
void cancel();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::filesystem::path directory{};
|
std::filesystem::path directory{};
|
||||||
std::vector<std::filesystem::path> frames{};
|
std::vector<std::filesystem::path> frames{};
|
||||||
std::vector<std::vector<const resource::AudioData*>> sounds{};
|
std::vector<std::vector<const AudioData*>> sounds{};
|
||||||
int soundTime{-1};
|
int soundTime{-1};
|
||||||
};
|
};
|
||||||
|
|
||||||
// Records a whole animation with these options (bounded and isolated), each frame drawn as animation_frame_render
|
// Records a whole animation with these options (bounded and isolated), each frame drawn as animation_frame_render
|
||||||
// draws it; false when a frame or the output can't be written.
|
// draws it; false when a frame or the output can't be written.
|
||||||
bool animation_record(const RecorderOptions&, Canvas&, resource::Shader&, Document&, const model::Animation&,
|
bool animation_record(const RecorderOptions&, Canvas&, ShaderProgram&, Document&, const Animation&,
|
||||||
glm::vec4, float, glm::vec4, bool);
|
glm::vec4, float, glm::vec4, bool);
|
||||||
}
|
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
std::filesystem::path ffmpeg_log_path();
|
std::filesystem::path ffmpeg_log_path();
|
||||||
bool animation_render(const std::filesystem::path&, const std::filesystem::path&,
|
bool animation_render(const std::filesystem::path&, const std::filesystem::path&,
|
||||||
const std::vector<std::filesystem::path>&, AudioStream&, render::Type, int);
|
const std::vector<std::filesystem::path>&, AudioStream&, RenderType, int);
|
||||||
}
|
|
||||||
+13
-18
@@ -4,8 +4,6 @@
|
|||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
using namespace anm2ed::resource;
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
static constexpr const char* CHINESE_FALLBACK = "C:\\Windows\\Fonts\\msyh.ttc";
|
static constexpr const char* CHINESE_FALLBACK = "C:\\Windows\\Fonts\\msyh.ttc";
|
||||||
static constexpr const char* KOREAN_FALLBACK = "C:\\Windows\\Fonts\\malgun.ttf";
|
static constexpr const char* KOREAN_FALLBACK = "C:\\Windows\\Fonts\\malgun.ttf";
|
||||||
@@ -18,8 +16,6 @@ static constexpr int CHINESE_FALLBACK_NUMBER = 2;
|
|||||||
static constexpr int KOREAN_FALLBACK_NUMBER = 1;
|
static constexpr int KOREAN_FALLBACK_NUMBER = 1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
Resources::Resources()
|
Resources::Resources()
|
||||||
{
|
{
|
||||||
auto isKoreanFallback = std::filesystem::exists(KOREAN_FALLBACK);
|
auto isKoreanFallback = std::filesystem::exists(KOREAN_FALLBACK);
|
||||||
@@ -28,29 +24,29 @@ namespace anm2ed
|
|||||||
if (!isKoreanFallback) logger.error(std::format("Failed to load Korean fallback font: {}", KOREAN_FALLBACK));
|
if (!isKoreanFallback) logger.error(std::format("Failed to load Korean fallback font: {}", KOREAN_FALLBACK));
|
||||||
if (!isChineseFallback) logger.error(std::format("Failed to load Chinese fallback font: {}", CHINESE_FALLBACK));
|
if (!isChineseFallback) logger.error(std::format("Failed to load Chinese fallback font: {}", CHINESE_FALLBACK));
|
||||||
|
|
||||||
for (auto [i, fontInfo] : std::views::enumerate(font::FONTS))
|
for (auto [i, fontInfo] : std::views::enumerate(FONTS))
|
||||||
{
|
{
|
||||||
fonts[i] = Font((void*)fontInfo->data, fontInfo->size, font::SIZE);
|
fonts[i] = Font((void*)fontInfo->data, fontInfo->size, FONT_SIZE);
|
||||||
if (isKoreanFallback)
|
if (isKoreanFallback)
|
||||||
fonts[i].append(KOREAN_FALLBACK, font::SIZE, KOREAN_FALLBACK_NUMBER);
|
fonts[i].append(KOREAN_FALLBACK, FONT_SIZE, KOREAN_FALLBACK_NUMBER);
|
||||||
else
|
else
|
||||||
fonts[i].append((void*)FONT_KOREAN_TTF.data, FONT_KOREAN_TTF.size, font::SIZE);
|
fonts[i].append((void*)FONT_KOREAN_TTF.data, FONT_KOREAN_TTF.size, FONT_SIZE);
|
||||||
if (isChineseFallback)
|
if (isChineseFallback)
|
||||||
fonts[i].append(CHINESE_FALLBACK, font::SIZE, CHINESE_FALLBACK_NUMBER);
|
fonts[i].append(CHINESE_FALLBACK, FONT_SIZE, CHINESE_FALLBACK_NUMBER);
|
||||||
else
|
else
|
||||||
fonts[i].append((void*)FONT_CHINESE_TTF.data, FONT_CHINESE_TTF.size, font::SIZE);
|
fonts[i].append((void*)FONT_CHINESE_TTF.data, FONT_CHINESE_TTF.size, FONT_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto [i, iconInfo] : std::views::enumerate(icon::ICONS))
|
for (auto [i, iconInfo] : std::views::enumerate(ICONS))
|
||||||
icons[i] = texture::svg_load((const char*)iconInfo.svg->data, iconInfo.svg->size, iconInfo.size);
|
icons[i] = texture_svg_load((const char*)iconInfo.svg->data, iconInfo.svg->size, iconInfo.size);
|
||||||
|
|
||||||
for (auto [i, shaderInfo] : std::views::enumerate(shader::SHADERS))
|
for (auto [i, shaderInfo] : std::views::enumerate(SHADERS))
|
||||||
shaders[i] = Shader(shaderInfo.vertex, shaderInfo.fragment);
|
shaders[i] = ShaderProgram(shaderInfo.vertex, shaderInfo.fragment);
|
||||||
};
|
};
|
||||||
|
|
||||||
GLuint Resources::icon_id_get(int icon) { return texture::id_get(icons[icon]); }
|
GLuint Resources::icon_id_get(int icon) { return texture_id_get(icons[icon]); }
|
||||||
|
|
||||||
resource::AudioData& Resources::music_track()
|
AudioData& Resources::music_track()
|
||||||
{
|
{
|
||||||
if (!isMusicLoaded)
|
if (!isMusicLoaded)
|
||||||
{
|
{
|
||||||
@@ -60,5 +56,4 @@ namespace anm2ed
|
|||||||
return music;
|
return music;
|
||||||
}
|
}
|
||||||
|
|
||||||
resource::AudioData* Resources::music_track_if_loaded() { return isMusicLoaded ? &music : nullptr; }
|
AudioData* Resources::music_track_if_loaded() { return isMusicLoaded ? &music : nullptr; }
|
||||||
}
|
|
||||||
+6
-9
@@ -8,22 +8,19 @@
|
|||||||
#include "shader.h"
|
#include "shader.h"
|
||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
class Resources
|
class Resources
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
resource::Font fonts[resource::font::COUNT]{};
|
Font fonts[FONT_COUNT]{};
|
||||||
resource::Image icons[resource::icon::COUNT]{};
|
Image icons[ICON_COUNT]{};
|
||||||
resource::Shader shaders[resource::shader::COUNT]{};
|
ShaderProgram shaders[SHADER_COUNT]{};
|
||||||
resource::AudioData music{};
|
AudioData music{};
|
||||||
|
|
||||||
Resources();
|
Resources();
|
||||||
GLuint icon_id_get(int);
|
GLuint icon_id_get(int);
|
||||||
resource::AudioData& music_track();
|
AudioData& music_track();
|
||||||
resource::AudioData* music_track_if_loaded();
|
AudioData* music_track_if_loaded();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool isMusicLoaded{false};
|
bool isMusicLoaded{false};
|
||||||
};
|
};
|
||||||
}
|
|
||||||
+1
-4
@@ -5,14 +5,11 @@
|
|||||||
|
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
|
|
||||||
namespace anm2ed::util::sdl
|
|
||||||
{
|
|
||||||
std::filesystem::path preferences_directory_get()
|
std::filesystem::path preferences_directory_get()
|
||||||
{
|
{
|
||||||
auto sdlPath = SDL_GetPrefPath(nullptr, "anm2ed");
|
auto sdlPath = SDL_GetPrefPath(nullptr, "anm2ed");
|
||||||
if (!sdlPath) return {};
|
if (!sdlPath) return {};
|
||||||
auto filePath = path::from_utf8(sdlPath);
|
auto filePath = path_from_utf8(sdlPath);
|
||||||
SDL_free(sdlPath);
|
SDL_free(sdlPath);
|
||||||
return filePath;
|
return filePath;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -2,7 +2,4 @@
|
|||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
||||||
namespace anm2ed::util::sdl
|
|
||||||
{
|
|
||||||
std::filesystem::path preferences_directory_get();
|
std::filesystem::path preferences_directory_get();
|
||||||
}
|
|
||||||
+12
-15
@@ -1,8 +1,6 @@
|
|||||||
#include "selection.h"
|
#include "selection.h"
|
||||||
|
|
||||||
namespace anm2ed
|
std::set<Reference> selection_references_get(const Selection& selection, const UidIndex& index,
|
||||||
{
|
|
||||||
std::set<Reference> selection_references_get(const Selection& selection, const model::UidIndex& index,
|
|
||||||
SelectionKind kind)
|
SelectionKind kind)
|
||||||
{
|
{
|
||||||
std::set<Reference> references{};
|
std::set<Reference> references{};
|
||||||
@@ -12,12 +10,12 @@ namespace anm2ed
|
|||||||
return references;
|
return references;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::uint64_t handle_uid_get(Handle handle)
|
static std::uint64_t handle_uid_get(Handle handle)
|
||||||
{
|
{
|
||||||
return handle.frame ? handle.frame : handle.item ? handle.item : handle.animation;
|
return handle.frame ? handle.frame : handle.item ? handle.item : handle.animation;
|
||||||
}
|
}
|
||||||
|
|
||||||
void selection_references_set(Selection& selection, const model::Model& model, SelectionKind kind,
|
void selection_references_set(Selection& selection, const Model& model, SelectionKind kind,
|
||||||
const std::set<Reference>& references)
|
const std::set<Reference>& references)
|
||||||
{
|
{
|
||||||
auto& uids = selection.uids[kind];
|
auto& uids = selection.uids[kind];
|
||||||
@@ -27,20 +25,20 @@ namespace anm2ed
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The most specific part of the focus that still exists.
|
// The most specific part of the focus that still exists.
|
||||||
Reference selection_focus_get(const Selection& selection, const model::UidIndex& index)
|
Reference selection_focus_get(const Selection& selection, const UidIndex& index)
|
||||||
{
|
{
|
||||||
for (auto uid : {selection.focus.frame, selection.focus.item, selection.focus.animation})
|
for (auto uid : {selection.focus.frame, selection.focus.item, selection.focus.animation})
|
||||||
if (auto reference = index.reference_get(uid)) return *reference;
|
if (auto reference = index.reference_get(uid)) return *reference;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void selection_focus_set(Selection& selection, const model::Model& model, Reference reference)
|
void selection_focus_set(Selection& selection, const Model& model, Reference reference)
|
||||||
{
|
{
|
||||||
selection.focus = model.handle_get(reference);
|
selection.focus = model.handle_get(reference);
|
||||||
}
|
}
|
||||||
|
|
||||||
// (id, uid) of every content item a kind selects from.
|
// (id, uid) of every content item a kind selects from.
|
||||||
std::vector<std::pair<int, std::uint64_t>> content_keys_get(const Selection& selection, const model::Model& model,
|
static std::vector<std::pair<int, std::uint64_t>> content_keys_get(const Selection& selection, const Model& model,
|
||||||
SelectionKind kind)
|
SelectionKind kind)
|
||||||
{
|
{
|
||||||
std::vector<std::pair<int, std::uint64_t>> keys{};
|
std::vector<std::pair<int, std::uint64_t>> keys{};
|
||||||
@@ -58,13 +56,13 @@ namespace anm2ed
|
|||||||
if (kind == SelectionKind::SOUNDS) add(content.sounds);
|
if (kind == SelectionKind::SOUNDS) add(content.sounds);
|
||||||
if (kind == SelectionKind::LIBRARIES) add(content.libraries);
|
if (kind == SelectionKind::LIBRARIES) add(content.libraries);
|
||||||
if (kind == SelectionKind::REGIONS)
|
if (kind == SelectionKind::REGIONS)
|
||||||
if (auto spritesheet = model::item_get(content.spritesheets,
|
if (auto spritesheet = item_get(content.spritesheets,
|
||||||
selection_focus_id_get(selection, model, SelectionKind::SPRITESHEETS)))
|
selection_focus_id_get(selection, model, SelectionKind::SPRITESHEETS)))
|
||||||
add(spritesheet->regions);
|
add(spritesheet->regions);
|
||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<int> selection_ids_get(const Selection& selection, const model::Model& model, SelectionKind kind)
|
std::set<int> selection_ids_get(const Selection& selection, const Model& model, SelectionKind kind)
|
||||||
{
|
{
|
||||||
std::set<int> ids{};
|
std::set<int> ids{};
|
||||||
auto uids = selection.uids.find(kind);
|
auto uids = selection.uids.find(kind);
|
||||||
@@ -74,7 +72,7 @@ namespace anm2ed
|
|||||||
return ids;
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
void selection_ids_set(Selection& selection, const model::Model& model, SelectionKind kind, const std::set<int>& ids)
|
void selection_ids_set(Selection& selection, const Model& model, SelectionKind kind, const std::set<int>& ids)
|
||||||
{
|
{
|
||||||
auto& uids = selection.uids[kind];
|
auto& uids = selection.uids[kind];
|
||||||
uids.clear();
|
uids.clear();
|
||||||
@@ -82,7 +80,7 @@ namespace anm2ed
|
|||||||
if (ids.contains(id)) uids.insert(uid);
|
if (ids.contains(id)) uids.insert(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
int selection_focus_id_get(const Selection& selection, const model::Model& model, SelectionKind kind)
|
int selection_focus_id_get(const Selection& selection, const Model& model, SelectionKind kind)
|
||||||
{
|
{
|
||||||
auto focus = selection.focuses.find(kind);
|
auto focus = selection.focuses.find(kind);
|
||||||
if (focus == selection.focuses.end()) return -1;
|
if (focus == selection.focuses.end()) return -1;
|
||||||
@@ -91,7 +89,7 @@ namespace anm2ed
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void selection_focus_id_set(Selection& selection, const model::Model& model, SelectionKind kind, int id)
|
void selection_focus_id_set(Selection& selection, const Model& model, SelectionKind kind, int id)
|
||||||
{
|
{
|
||||||
selection.focuses.erase(kind);
|
selection.focuses.erase(kind);
|
||||||
for (auto [itemId, uid] : content_keys_get(selection, model, kind))
|
for (auto [itemId, uid] : content_keys_get(selection, model, kind))
|
||||||
@@ -104,7 +102,7 @@ namespace anm2ed
|
|||||||
|
|
||||||
// After an edit: drops uids that no longer exist, and moves a focus whose element was removed to its nearest
|
// After an edit: drops uids that no longer exist, and moves a focus whose element was removed to its nearest
|
||||||
// survivor (a frame at the same index of its track, the animation's root track, or the nearest animation).
|
// survivor (a frame at the same index of its track, the animation's root track, or the nearest animation).
|
||||||
void selection_follow(Selection& selection, const model::Model& model, const model::UidIndex& index, Reference before)
|
void selection_follow(Selection& selection, const Model& model, const UidIndex& index, Reference before)
|
||||||
{
|
{
|
||||||
for (auto& [kind, uids] : selection.uids)
|
for (auto& [kind, uids] : selection.uids)
|
||||||
if (kind < SelectionKind::SPRITESHEETS)
|
if (kind < SelectionKind::SPRITESHEETS)
|
||||||
@@ -133,4 +131,3 @@ namespace anm2ed
|
|||||||
|
|
||||||
selection_focus_set(selection, model, reference);
|
selection_focus_set(selection, model, reference);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
+9
-12
@@ -5,8 +5,6 @@
|
|||||||
|
|
||||||
#include "model/model.h"
|
#include "model/model.h"
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
enum class SelectionKind
|
enum class SelectionKind
|
||||||
{
|
{
|
||||||
ANIMATIONS,
|
ANIMATIONS,
|
||||||
@@ -35,15 +33,14 @@ namespace anm2ed
|
|||||||
bool operator==(const Selection&) const = default;
|
bool operator==(const Selection&) const = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::set<Reference> selection_references_get(const Selection&, const model::UidIndex&, SelectionKind);
|
std::set<Reference> selection_references_get(const Selection&, const UidIndex&, SelectionKind);
|
||||||
void selection_references_set(Selection&, const model::Model&, SelectionKind, const std::set<Reference>&);
|
void selection_references_set(Selection&, const Model&, SelectionKind, const std::set<Reference>&);
|
||||||
Reference selection_focus_get(const Selection&, const model::UidIndex&);
|
Reference selection_focus_get(const Selection&, const UidIndex&);
|
||||||
void selection_focus_set(Selection&, const model::Model&, Reference);
|
void selection_focus_set(Selection&, const Model&, Reference);
|
||||||
// Content items (spritesheets, regions of the focused spritesheet, shaders, layers, ...) are selected by uid and
|
// Content items (spritesheets, regions of the focused spritesheet, shaders, layers, ...) are selected by uid and
|
||||||
// read back as ids.
|
// read back as ids.
|
||||||
std::set<int> selection_ids_get(const Selection&, const model::Model&, SelectionKind);
|
std::set<int> selection_ids_get(const Selection&, const Model&, SelectionKind);
|
||||||
void selection_ids_set(Selection&, const model::Model&, SelectionKind, const std::set<int>&);
|
void selection_ids_set(Selection&, const Model&, SelectionKind, const std::set<int>&);
|
||||||
int selection_focus_id_get(const Selection&, const model::Model&, SelectionKind);
|
int selection_focus_id_get(const Selection&, const Model&, SelectionKind);
|
||||||
void selection_focus_id_set(Selection&, const model::Model&, SelectionKind, int);
|
void selection_focus_id_set(Selection&, const Model&, SelectionKind, int);
|
||||||
void selection_follow(Selection&, const model::Model&, const model::UidIndex&, Reference);
|
void selection_follow(Selection&, const Model&, const UidIndex&, Reference);
|
||||||
}
|
|
||||||
+11
-17
@@ -9,11 +9,8 @@
|
|||||||
#include "math_util.h"
|
#include "math_util.h"
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
|
|
||||||
using namespace anm2ed::util;
|
|
||||||
using namespace glm;
|
using namespace glm;
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
constexpr std::string_view SETTINGS_SHEAR = "Shear";
|
constexpr std::string_view SETTINGS_SHEAR = "Shear";
|
||||||
|
|
||||||
constexpr const char* COMPONENT_SUFFIXES_XY[] = {"X", "Y"};
|
constexpr const char* COMPONENT_SUFFIXES_XY[] = {"X", "Y"};
|
||||||
@@ -26,7 +23,7 @@ namespace anm2ed
|
|||||||
value[0];
|
value[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
const char* const* component_suffixes_get(std::string_view type)
|
static const char* const* component_suffixes_get(std::string_view type)
|
||||||
{
|
{
|
||||||
if (type.ends_with("_WH")) return COMPONENT_SUFFIXES_WH;
|
if (type.ends_with("_WH")) return COMPONENT_SUFFIXES_WH;
|
||||||
if (type.starts_with("VEC3") || type.starts_with("VEC4")) return COMPONENT_SUFFIXES_RGBA;
|
if (type.starts_with("VEC3") || type.starts_with("VEC4")) return COMPONENT_SUFFIXES_RGBA;
|
||||||
@@ -181,15 +178,13 @@ DockSpace ID=0x123F8F08 Window=0x6D581B32 Pos=8,62 Size=1902,991
|
|||||||
DockNode ID=0x0000000C Parent=0x0000000A SizeRef=459,250 Selected=0xC1986EE2
|
DockNode ID=0x0000000C Parent=0x0000000A SizeRef=459,250 Selected=0xC1986EE2
|
||||||
DockNode ID=0x00000016 Parent=0x123F8F08 SizeRef=1902,329 Selected=0x597925B7
|
DockNode ID=0x00000016 Parent=0x123F8F08 SizeRef=1902,329 Selected=0x597925B7
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
)";
|
)";
|
||||||
|
|
||||||
Settings::Settings(const std::filesystem::path& path)
|
Settings::Settings(const std::filesystem::path& path)
|
||||||
{
|
{
|
||||||
auto pathUtf8 = path::to_utf8(path);
|
auto pathUtf8 = path_to_utf8(path);
|
||||||
if (path::is_exist(path))
|
if (is_path_exist(path))
|
||||||
logger.info(std::format("Using settings from: {}", pathUtf8));
|
logger.info(std::format("Using settings from: {}", pathUtf8));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -199,7 +194,7 @@ DockSpace ID=0x123F8F08 Window=0x6D581B32 Pos=8,62 Size=1902,991
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string fileData{};
|
std::string fileData{};
|
||||||
if (!file::read_to_string(path, &fileData, "rb"))
|
if (!file_text_load(path, &fileData, "rb"))
|
||||||
{
|
{
|
||||||
logger.error(std::format("Failed to open settings file: {}", pathUtf8));
|
logger.error(std::format("Failed to open settings file: {}", pathUtf8));
|
||||||
return;
|
return;
|
||||||
@@ -228,7 +223,7 @@ DockSpace ID=0x123F8F08 Window=0x6D581B32 Pos=8,62 Size=1902,991
|
|||||||
{
|
{
|
||||||
std::string value;
|
std::string value;
|
||||||
std::getline(ss, value);
|
std::getline(ss, value);
|
||||||
dest = path::from_utf8(value);
|
dest = path_from_utf8(value);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -282,14 +277,14 @@ DockSpace ID=0x123F8F08 Window=0x6D581B32 Pos=8,62 Size=1902,991
|
|||||||
// Scales were once saved as multipliers; a value below the minimum percent is one, and is converted.
|
// Scales were once saved as multipliers; a value below the minimum percent is one, and is converted.
|
||||||
for (auto [scale, min, max] : {std::tuple{&uiScale, UI_SCALE_MIN, UI_SCALE_MAX},
|
for (auto [scale, min, max] : {std::tuple{&uiScale, UI_SCALE_MIN, UI_SCALE_MAX},
|
||||||
std::tuple{&renderScale, RENDER_SCALE_MIN, RENDER_SCALE_MAX}})
|
std::tuple{&renderScale, RENDER_SCALE_MIN, RENDER_SCALE_MAX}})
|
||||||
*scale = std::clamp(*scale < min ? math::unit_to_percent(*scale) : *scale, min, max);
|
*scale = std::clamp(*scale < min ? unit_to_percent(*scale) : *scale, min, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Settings::imgui_data_load(const std::filesystem::path& path)
|
std::string Settings::imgui_data_load(const std::filesystem::path& path)
|
||||||
{
|
{
|
||||||
auto pathUtf8 = path::to_utf8(path);
|
auto pathUtf8 = path_to_utf8(path);
|
||||||
std::string fileData{};
|
std::string fileData{};
|
||||||
if (!file::read_to_string(path, &fileData, "rb"))
|
if (!file_text_load(path, &fileData, "rb"))
|
||||||
{
|
{
|
||||||
logger.error(
|
logger.error(
|
||||||
std::format("Failed to open settings file for Dear ImGui data: {}; using Dear ImGui defaults", pathUtf8));
|
std::format("Failed to open settings file for Dear ImGui data: {}; using Dear ImGui defaults", pathUtf8));
|
||||||
@@ -333,7 +328,7 @@ DockSpace ID=0x123F8F08 Window=0x6D581B32 Pos=8,62 Size=1902,991
|
|||||||
|
|
||||||
void Settings::save(const std::filesystem::path& path, const std::string& imguiData)
|
void Settings::save(const std::filesystem::path& path, const std::string& imguiData)
|
||||||
{
|
{
|
||||||
auto pathUtf8 = path::to_utf8(path);
|
auto pathUtf8 = path_to_utf8(path);
|
||||||
logger.info(std::format("Saving settings to: {}", pathUtf8));
|
logger.info(std::format("Saving settings to: {}", pathUtf8));
|
||||||
std::ostringstream file{};
|
std::ostringstream file{};
|
||||||
|
|
||||||
@@ -346,7 +341,7 @@ DockSpace ID=0x123F8F08 Window=0x6D581B32 Pos=8,62 Size=1902,991
|
|||||||
if constexpr (std::is_same_v<T, bool>)
|
if constexpr (std::is_same_v<T, bool>)
|
||||||
file << key << "=" << (value ? "true" : "false") << "\n";
|
file << key << "=" << (value ? "true" : "false") << "\n";
|
||||||
else if constexpr (std::is_same_v<T, std::filesystem::path>)
|
else if constexpr (std::is_same_v<T, std::filesystem::path>)
|
||||||
file << key << "=" << path::to_utf8(value) << "\n";
|
file << key << "=" << path_to_utf8(value) << "\n";
|
||||||
else
|
else
|
||||||
file << key << "=" << value << "\n";
|
file << key << "=" << value << "\n";
|
||||||
};
|
};
|
||||||
@@ -377,11 +372,10 @@ DockSpace ID=0x123F8F08 Window=0x6D581B32 Pos=8,62 Size=1902,991
|
|||||||
logger.error(std::format("Failed while writing settings file: {}", pathUtf8));
|
logger.error(std::format("Failed while writing settings file: {}", pathUtf8));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!file::write_string(path, file.str(), "wb"))
|
if (!file_text_save(path, file.str(), "wb"))
|
||||||
{
|
{
|
||||||
logger.error(std::format("Failed to save settings file: {}", pathUtf8));
|
logger.error(std::format("Failed to save settings file: {}", pathUtf8));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logger.info(std::format("Saved settings to: {}", pathUtf8));
|
logger.info(std::format("Saved settings to: {}", pathUtf8));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
+9
-12
@@ -11,8 +11,6 @@
|
|||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "ui/theme.h"
|
#include "ui/theme.h"
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
constexpr auto FFMPEG_PATH_DEFAULT = "C:\\ffmpeg\\bin\\ffmpeg.exe";
|
constexpr auto FFMPEG_PATH_DEFAULT = "C:\\ffmpeg\\bin\\ffmpeg.exe";
|
||||||
#else
|
#else
|
||||||
@@ -58,7 +56,7 @@ namespace anm2ed
|
|||||||
X(IS_VSYNC, isVsync, STRING_UNDEFINED, BOOL, true) \
|
X(IS_VSYNC, isVsync, STRING_UNDEFINED, BOOL, true) \
|
||||||
X(IS_DETACHABLE_WINDOWS, isDetachableWindows, STRING_UNDEFINED, BOOL, true) \
|
X(IS_DETACHABLE_WINDOWS, isDetachableWindows, STRING_UNDEFINED, BOOL, true) \
|
||||||
X(UI_SCALE, uiScale, STRING_UNDEFINED, FLOAT, 100.0f) \
|
X(UI_SCALE, uiScale, STRING_UNDEFINED, FLOAT, 100.0f) \
|
||||||
X(THEME, theme, STRING_UNDEFINED, INT, imgui::theme::DARK) \
|
X(THEME, theme, STRING_UNDEFINED, INT, THEME_DARK) \
|
||||||
X(LANGUAGE, language, STRING_UNDEFINED, INT, ENGLISH) \
|
X(LANGUAGE, language, STRING_UNDEFINED, INT, ENGLISH) \
|
||||||
\
|
\
|
||||||
X(FILE_IS_AUTOSAVE, fileIsAutosave, STRING_UNDEFINED, BOOL, true) \
|
X(FILE_IS_AUTOSAVE, fileIsAutosave, STRING_UNDEFINED, BOOL, true) \
|
||||||
@@ -149,7 +147,7 @@ namespace anm2ed
|
|||||||
X(PREVIEW_IS_ALT_ICONS, previewIsAltIcons, STRING_UNDEFINED, BOOL, false) \
|
X(PREVIEW_IS_ALT_ICONS, previewIsAltIcons, STRING_UNDEFINED, BOOL, false) \
|
||||||
X(PREVIEW_IS_TRANSPARENT, animationPreviewTransparent, STRING_UNDEFINED, BOOL, false) \
|
X(PREVIEW_IS_TRANSPARENT, animationPreviewTransparent, STRING_UNDEFINED, BOOL, false) \
|
||||||
X(PREVIEW_OVERLAY_TRANSPARENCY, previewOverlayTransparency, STRING_UNDEFINED, FLOAT, 100.0f) \
|
X(PREVIEW_OVERLAY_TRANSPARENCY, previewOverlayTransparency, STRING_UNDEFINED, FLOAT, 100.0f) \
|
||||||
X(PREVIEW_OVERLAY_DRAW_ORDER, previewOverlayDrawOrder, STRING_UNDEFINED, INT, types::overlay_draw_order::OVER) \
|
X(PREVIEW_OVERLAY_DRAW_ORDER, previewOverlayDrawOrder, STRING_UNDEFINED, INT, OVERLAY_OVER) \
|
||||||
X(PREVIEW_START_ZOOM, previewStartZoom, STRING_UNDEFINED, FLOAT, 200.0f) \
|
X(PREVIEW_START_ZOOM, previewStartZoom, STRING_UNDEFINED, FLOAT, 200.0f) \
|
||||||
X(PREVIEW_GRID_SIZE, previewGridSize, STRING_UNDEFINED, IVEC2, {32, 32}) \
|
X(PREVIEW_GRID_SIZE, previewGridSize, STRING_UNDEFINED, IVEC2, {32, 32}) \
|
||||||
X(PREVIEW_GRID_OFFSET, previewGridOffset, STRING_UNDEFINED, IVEC2, {}) \
|
X(PREVIEW_GRID_OFFSET, previewGridOffset, STRING_UNDEFINED, IVEC2, {}) \
|
||||||
@@ -199,8 +197,8 @@ namespace anm2ed
|
|||||||
X(BAKE_IS_USE_ROOT_PIVOT, bakeIsUseRootPivot, STRING_UNDEFINED, BOOL, true) \
|
X(BAKE_IS_USE_ROOT_PIVOT, bakeIsUseRootPivot, STRING_UNDEFINED, BOOL, true) \
|
||||||
\
|
\
|
||||||
X(TIMELINE_ADD_ITEM_TYPE, timelineAddItemType, STRING_UNDEFINED, INT, LAYER) \
|
X(TIMELINE_ADD_ITEM_TYPE, timelineAddItemType, STRING_UNDEFINED, INT, LAYER) \
|
||||||
X(TIMELINE_ADD_ITEM_DESTINATION, timelineAddItemDestination, STRING_UNDEFINED, INT, types::destination::ALL) \
|
X(TIMELINE_ADD_ITEM_DESTINATION, timelineAddItemDestination, STRING_UNDEFINED, INT, DESTINATION_ALL) \
|
||||||
X(TIMELINE_ADD_ITEM_SOURCE, timelineAddItemSource, STRING_UNDEFINED, INT, types::source::NEW) \
|
X(TIMELINE_ADD_ITEM_SOURCE, timelineAddItemSource, STRING_UNDEFINED, INT, SOURCE_NEW) \
|
||||||
X(TIMELINE_IS_SHOW_UNUSED, timelineIsShowUnused, STRING_UNDEFINED, BOOL, true) \
|
X(TIMELINE_IS_SHOW_UNUSED, timelineIsShowUnused, STRING_UNDEFINED, BOOL, true) \
|
||||||
X(TIMELINE_IS_ONLY_SHOW_LAYERS, timelineIsOnlyShowLayers, STRING_UNDEFINED, BOOL, false) \
|
X(TIMELINE_IS_ONLY_SHOW_LAYERS, timelineIsOnlyShowLayers, STRING_UNDEFINED, BOOL, false) \
|
||||||
X(TIMELINE_IS_SOUND, timelineIsSound, STRING_UNDEFINED, BOOL, true) \
|
X(TIMELINE_IS_SOUND, timelineIsSound, STRING_UNDEFINED, BOOL, true) \
|
||||||
@@ -208,16 +206,16 @@ namespace anm2ed
|
|||||||
X(ONIONSKIN_IS_ENABLED, onionskinIsEnabled, STRING_UNDEFINED, BOOL, false) \
|
X(ONIONSKIN_IS_ENABLED, onionskinIsEnabled, STRING_UNDEFINED, BOOL, false) \
|
||||||
X(ONIONSKIN_BEFORE_COUNT, onionskinBeforeCount, STRING_UNDEFINED, INT, 0) \
|
X(ONIONSKIN_BEFORE_COUNT, onionskinBeforeCount, STRING_UNDEFINED, INT, 0) \
|
||||||
X(ONIONSKIN_AFTER_COUNT, onionskinAfterCount, STRING_UNDEFINED, INT, 0) \
|
X(ONIONSKIN_AFTER_COUNT, onionskinAfterCount, STRING_UNDEFINED, INT, 0) \
|
||||||
X(ONIONSKIN_BEFORE_COLOR, onionskinBeforeColor, STRING_UNDEFINED, VEC3, types::color::RED) \
|
X(ONIONSKIN_BEFORE_COLOR, onionskinBeforeColor, STRING_UNDEFINED, VEC3, COLOR_RED) \
|
||||||
X(ONIONSKIN_AFTER_COLOR, onionskinAfterColor, STRING_UNDEFINED, VEC3, types::color::BLUE) \
|
X(ONIONSKIN_AFTER_COLOR, onionskinAfterColor, STRING_UNDEFINED, VEC3, COLOR_BLUE) \
|
||||||
X(ONIONSKIN_MODE, onionskinMode, STRING_UNDEFINED, INT, (int)types::OnionskinMode::TIME) \
|
X(ONIONSKIN_MODE, onionskinMode, STRING_UNDEFINED, INT, (int)OnionskinMode::TIME) \
|
||||||
X(ONIONSKIN_IS_PIVOT_PATH, onionskinIsPivotPath, STRING_UNDEFINED, BOOL, false) \
|
X(ONIONSKIN_IS_PIVOT_PATH, onionskinIsPivotPath, STRING_UNDEFINED, BOOL, false) \
|
||||||
X(ONIONSKIN_IS_ONLY_SELECTED, onionskinIsOnlySelected, STRING_UNDEFINED, BOOL, false) \
|
X(ONIONSKIN_IS_ONLY_SELECTED, onionskinIsOnlySelected, STRING_UNDEFINED, BOOL, false) \
|
||||||
\
|
\
|
||||||
X(TOOL, tool, STRING_UNDEFINED, INT, 0) \
|
X(TOOL, tool, STRING_UNDEFINED, INT, 0) \
|
||||||
X(TOOL_COLOR, toolColor, STRING_UNDEFINED, VEC4, {1.0, 1.0, 1.0, 1.0}) \
|
X(TOOL_COLOR, toolColor, STRING_UNDEFINED, VEC4, {1.0, 1.0, 1.0, 1.0}) \
|
||||||
\
|
\
|
||||||
X(RENDER_TYPE, renderType, STRING_UNDEFINED, INT, render::GIF) \
|
X(RENDER_TYPE, renderType, STRING_UNDEFINED, INT, RENDER_GIF) \
|
||||||
X(RENDER_PATH, renderPath, STRING_UNDEFINED, PATH, OUTPUT_PATH_DEFAULT) \
|
X(RENDER_PATH, renderPath, STRING_UNDEFINED, PATH, OUTPUT_PATH_DEFAULT) \
|
||||||
X(RENDER_ROWS, renderRows, STRING_UNDEFINED, INT, 0) \
|
X(RENDER_ROWS, renderRows, STRING_UNDEFINED, INT, 0) \
|
||||||
X(RENDER_COLUMNS, renderColumns, STRING_UNDEFINED, INT, 0) \
|
X(RENDER_COLUMNS, renderColumns, STRING_UNDEFINED, INT, 0) \
|
||||||
@@ -225,7 +223,7 @@ namespace anm2ed
|
|||||||
X(RENDER_IS_USE_ANIMATION_BOUNDS, renderIsUseAnimationBounds, STRING_UNDEFINED, BOOL, true) \
|
X(RENDER_IS_USE_ANIMATION_BOUNDS, renderIsUseAnimationBounds, STRING_UNDEFINED, BOOL, true) \
|
||||||
X(RENDER_IS_USE_ISOLATED_ANIMATION, renderIsUseIsolatedAnimation, STRING_UNDEFINED, BOOL, false) \
|
X(RENDER_IS_USE_ISOLATED_ANIMATION, renderIsUseIsolatedAnimation, STRING_UNDEFINED, BOOL, false) \
|
||||||
X(RENDER_SCALE, renderScale, STRING_UNDEFINED, FLOAT, 100.0f) \
|
X(RENDER_SCALE, renderScale, STRING_UNDEFINED, FLOAT, 100.0f) \
|
||||||
X(RENDER_FPS_MODE, renderFpsMode, STRING_UNDEFINED, INT, render::FPS_ANIMATION) \
|
X(RENDER_FPS_MODE, renderFpsMode, STRING_UNDEFINED, INT, FPS_ANIMATION) \
|
||||||
X(RENDER_FFMPEG_PATH, renderFFmpegPath, STRING_UNDEFINED, PATH, FFMPEG_PATH_DEFAULT)
|
X(RENDER_FFMPEG_PATH, renderFFmpegPath, STRING_UNDEFINED, PATH, FFMPEG_PATH_DEFAULT)
|
||||||
|
|
||||||
#define SETTINGS_SHORTCUTS \
|
#define SETTINGS_SHORTCUTS \
|
||||||
@@ -365,4 +363,3 @@ namespace anm2ed
|
|||||||
SETTINGS_WINDOWS
|
SETTINGS_WINDOWS
|
||||||
#undef X
|
#undef X
|
||||||
};
|
};
|
||||||
}
|
|
||||||
+36
-42
@@ -9,8 +9,6 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "model/model.h"
|
#include "model/model.h"
|
||||||
|
|
||||||
namespace anm2ed::resource::shader
|
|
||||||
{
|
|
||||||
#define SHADER_GLES_WORD_REPLACEMENTS \
|
#define SHADER_GLES_WORD_REPLACEMENTS \
|
||||||
X("texture2D", "texture") \
|
X("texture2D", "texture") \
|
||||||
X("gl_FragColor", "fragColor")
|
X("gl_FragColor", "fragColor")
|
||||||
@@ -49,9 +47,9 @@ namespace anm2ed::resource::shader
|
|||||||
#undef X
|
#undef X
|
||||||
};
|
};
|
||||||
|
|
||||||
bool is_shader_identifier(char character) { return std::isalnum((unsigned char)character) || character == '_'; }
|
static bool is_shader_identifier(char character) { return std::isalnum((unsigned char)character) || character == '_'; }
|
||||||
|
|
||||||
std::string shader_text_replace(std::string string, std::string_view from, std::string_view to)
|
static std::string shader_text_replace(std::string string, std::string_view from, std::string_view to)
|
||||||
{
|
{
|
||||||
if (from.empty()) return string;
|
if (from.empty()) return string;
|
||||||
std::size_t position{};
|
std::size_t position{};
|
||||||
@@ -63,7 +61,7 @@ namespace anm2ed::resource::shader
|
|||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string shader_word_replace(std::string string, std::string_view from, std::string_view to)
|
static std::string shader_word_replace(std::string string, std::string_view from, std::string_view to)
|
||||||
{
|
{
|
||||||
if (from.empty()) return string;
|
if (from.empty()) return string;
|
||||||
|
|
||||||
@@ -84,7 +82,7 @@ namespace anm2ed::resource::shader
|
|||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string shader_space_collapse(std::string_view string)
|
static std::string shader_space_collapse(std::string_view string)
|
||||||
{
|
{
|
||||||
std::string out{};
|
std::string out{};
|
||||||
bool isSpace{};
|
bool isSpace{};
|
||||||
@@ -103,7 +101,7 @@ namespace anm2ed::resource::shader
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string shader_trim_get(std::string_view line)
|
static std::string shader_trim_get(std::string_view line)
|
||||||
{
|
{
|
||||||
std::size_t begin{};
|
std::size_t begin{};
|
||||||
while (begin < line.size() && std::isspace((unsigned char)line[begin]))
|
while (begin < line.size() && std::isspace((unsigned char)line[begin]))
|
||||||
@@ -116,7 +114,7 @@ namespace anm2ed::resource::shader
|
|||||||
return std::string(line.substr(begin, end - begin));
|
return std::string(line.substr(begin, end - begin));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_shader_word_present(std::string_view string, std::string_view word)
|
static bool is_shader_word_present(std::string_view string, std::string_view word)
|
||||||
{
|
{
|
||||||
std::size_t position{};
|
std::size_t position{};
|
||||||
while ((position = string.find(word, position)) != std::string_view::npos)
|
while ((position = string.find(word, position)) != std::string_view::npos)
|
||||||
@@ -130,7 +128,7 @@ namespace anm2ed::resource::shader
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_shader_line_skipped(std::string_view line)
|
static bool is_shader_line_skipped(std::string_view line)
|
||||||
{
|
{
|
||||||
auto normalized = shader_space_collapse(shader_trim_get(line));
|
auto normalized = shader_space_collapse(shader_trim_get(line));
|
||||||
if (normalized.starts_with("#version")) return true;
|
if (normalized.starts_with("#version")) return true;
|
||||||
@@ -143,7 +141,7 @@ namespace anm2ed::resource::shader
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string shader_precision_erase(std::string line)
|
static std::string shader_precision_erase(std::string line)
|
||||||
{
|
{
|
||||||
line = shader_word_replace(std::move(line), "lowp", "");
|
line = shader_word_replace(std::move(line), "lowp", "");
|
||||||
line = shader_word_replace(std::move(line), "mediump", "");
|
line = shader_word_replace(std::move(line), "mediump", "");
|
||||||
@@ -151,7 +149,7 @@ namespace anm2ed::resource::shader
|
|||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string shader_line_convert(std::string line, ShaderStage stage)
|
static std::string shader_line_convert(std::string line, ShaderStage stage)
|
||||||
{
|
{
|
||||||
line = shader_precision_erase(std::move(line));
|
line = shader_precision_erase(std::move(line));
|
||||||
line = shader_word_replace(std::move(line), "attribute", "in");
|
line = shader_word_replace(std::move(line), "attribute", "in");
|
||||||
@@ -162,20 +160,20 @@ namespace anm2ed::resource::shader
|
|||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string shader_fragment_declarations_get(std::string_view body)
|
static std::string shader_fragment_declarations_get(std::string_view body)
|
||||||
{
|
{
|
||||||
if (!is_shader_word_present(body, "fragColor")) return {};
|
if (!is_shader_word_present(body, "fragColor")) return {};
|
||||||
if (body.find("out vec4 fragColor") != std::string_view::npos) return {};
|
if (body.find("out vec4 fragColor") != std::string_view::npos) return {};
|
||||||
return "out vec4 fragColor;\n";
|
return "out vec4 fragColor;\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string uniform_name_clean_get(std::string name)
|
static std::string uniform_name_clean_get(std::string name)
|
||||||
{
|
{
|
||||||
if (name.ends_with("[0]")) name.erase(name.size() - 3);
|
if (name.ends_with("[0]")) name.erase(name.size() - 3);
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string uniform_float_string_get(float value) { return std::format("{:.6g}", value); }
|
static std::string uniform_float_string_get(float value) { return std::format("{:.6g}", value); }
|
||||||
|
|
||||||
UniformBinding uniform_binding_auto_get(std::string_view name, UniformValueType type)
|
UniformBinding uniform_binding_auto_get(std::string_view name, UniformValueType type)
|
||||||
{
|
{
|
||||||
@@ -244,16 +242,16 @@ namespace anm2ed::resource::shader
|
|||||||
|
|
||||||
bool is_uniform_value_vector(UniformValueType type) { return UNIFORM_VALUE_TYPE_INFOS[type].componentCount > 0; }
|
bool is_uniform_value_vector(UniformValueType type) { return UNIFORM_VALUE_TYPE_INFOS[type].componentCount > 0; }
|
||||||
|
|
||||||
bool is_component_binding_valid(UniformBinding binding)
|
static bool is_component_binding_valid(UniformBinding binding)
|
||||||
{
|
{
|
||||||
return binding == UNIFORM_BINDING_MANUAL || binding == UNIFORM_BINDING_PLAYBACK_TIME;
|
return binding == UNIFORM_BINDING_MANUAL || binding == UNIFORM_BINDING_PLAYBACK_TIME;
|
||||||
}
|
}
|
||||||
|
|
||||||
void uniform_configs_apply(const model::Shader& shader, std::vector<Uniform>& uniforms)
|
void uniform_configs_apply(const Shader& shader, std::vector<ShaderUniform>& uniforms)
|
||||||
{
|
{
|
||||||
for (auto& uniform : uniforms)
|
for (auto& uniform : uniforms)
|
||||||
{
|
{
|
||||||
auto config = std::ranges::find(shader.uniforms, uniform.name, &model::Uniform::name);
|
auto config = std::ranges::find(shader.uniforms, uniform.name, &Uniform::name);
|
||||||
if (config == shader.uniforms.end()) continue;
|
if (config == shader.uniforms.end()) continue;
|
||||||
|
|
||||||
if (auto binding = uniform_binding_get(config->binding);
|
if (auto binding = uniform_binding_get(config->binding);
|
||||||
@@ -262,7 +260,7 @@ namespace anm2ed::resource::shader
|
|||||||
if (!config->value.empty()) uniform_value_parse(uniform, config->value);
|
if (!config->value.empty()) uniform_value_parse(uniform, config->value);
|
||||||
for (int index = 0; index < (int)uniform.components.size(); ++index)
|
for (int index = 0; index < (int)uniform.components.size(); ++index)
|
||||||
{
|
{
|
||||||
auto component = std::ranges::find(config->components, index, &model::Component::index);
|
auto component = std::ranges::find(config->components, index, &Component::index);
|
||||||
if (component == config->components.end()) continue;
|
if (component == config->components.end()) continue;
|
||||||
if (auto binding = uniform_binding_get(component->binding);
|
if (auto binding = uniform_binding_get(component->binding);
|
||||||
!component->binding.empty() && is_component_binding_valid(binding))
|
!component->binding.empty() && is_component_binding_valid(binding))
|
||||||
@@ -273,18 +271,18 @@ namespace anm2ed::resource::shader
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Drops saved uniform settings the compiled shader no longer has or cannot use.
|
// Drops saved uniform settings the compiled shader no longer has or cannot use.
|
||||||
bool uniform_configs_trim(model::Shader& shader, const std::vector<Uniform>& uniforms)
|
bool uniform_configs_trim(Shader& shader, const std::vector<ShaderUniform>& uniforms)
|
||||||
{
|
{
|
||||||
bool isChanged = std::erase_if(shader.uniforms,
|
bool isChanged = std::erase_if(shader.uniforms,
|
||||||
[&](const model::Uniform& config)
|
[&](const Uniform& config)
|
||||||
{
|
{
|
||||||
return std::ranges::none_of(uniforms, [&](const Uniform& uniform)
|
return std::ranges::none_of(uniforms, [&](const ShaderUniform& uniform)
|
||||||
{ return uniform.name == config.name; });
|
{ return uniform.name == config.name; });
|
||||||
}) > 0;
|
}) > 0;
|
||||||
|
|
||||||
for (auto& config : shader.uniforms)
|
for (auto& config : shader.uniforms)
|
||||||
{
|
{
|
||||||
auto& uniform = *std::ranges::find(uniforms, config.name, &Uniform::name);
|
auto& uniform = *std::ranges::find(uniforms, config.name, &ShaderUniform::name);
|
||||||
if (!config.binding.empty() && !is_uniform_binding_valid(uniform_binding_get(config.binding), uniform.valueType))
|
if (!config.binding.empty() && !is_uniform_binding_valid(uniform_binding_get(config.binding), uniform.valueType))
|
||||||
{
|
{
|
||||||
config.binding.clear();
|
config.binding.clear();
|
||||||
@@ -294,7 +292,7 @@ namespace anm2ed::resource::shader
|
|||||||
auto componentCount = UNIFORM_VALUE_TYPE_INFOS[uniform.valueType].componentCount;
|
auto componentCount = UNIFORM_VALUE_TYPE_INFOS[uniform.valueType].componentCount;
|
||||||
auto isComponents = uniform_binding_get(config.binding) == UNIFORM_BINDING_COMPONENTS;
|
auto isComponents = uniform_binding_get(config.binding) == UNIFORM_BINDING_COMPONENTS;
|
||||||
isChanged |=
|
isChanged |=
|
||||||
std::erase_if(config.components, [&](const model::Component& component)
|
std::erase_if(config.components, [&](const Component& component)
|
||||||
{ return !isComponents || component.index < 0 || component.index >= componentCount; }) > 0;
|
{ return !isComponents || component.index < 0 || component.index >= componentCount; }) > 0;
|
||||||
|
|
||||||
for (auto& component : config.components)
|
for (auto& component : config.components)
|
||||||
@@ -308,9 +306,9 @@ namespace anm2ed::resource::shader
|
|||||||
return isChanged;
|
return isChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
void uniform_config_save(model::Shader& shader, const Uniform& uniform)
|
void uniform_config_save(Shader& shader, const ShaderUniform& uniform)
|
||||||
{
|
{
|
||||||
auto config = std::ranges::find(shader.uniforms, uniform.name, &model::Uniform::name);
|
auto config = std::ranges::find(shader.uniforms, uniform.name, &Uniform::name);
|
||||||
if (config == shader.uniforms.end()) config = shader.uniforms.insert(shader.uniforms.end(), {.name = uniform.name});
|
if (config == shader.uniforms.end()) config = shader.uniforms.insert(shader.uniforms.end(), {.name = uniform.name});
|
||||||
|
|
||||||
config->binding = std::string(uniform_binding_value_get(uniform.binding));
|
config->binding = std::string(uniform_binding_value_get(uniform.binding));
|
||||||
@@ -349,7 +347,7 @@ namespace anm2ed::resource::shader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void uniform_value_parse(Uniform& uniform, std::string_view value)
|
void uniform_value_parse(ShaderUniform& uniform, std::string_view value)
|
||||||
{
|
{
|
||||||
if (value.empty()) return;
|
if (value.empty()) return;
|
||||||
|
|
||||||
@@ -367,7 +365,7 @@ namespace anm2ed::resource::shader
|
|||||||
uniform.components[3].value = uniform.value.w;
|
uniform.components[3].value = uniform.value.w;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string uniform_value_string_get(const Uniform& uniform)
|
std::string uniform_value_string_get(const ShaderUniform& uniform)
|
||||||
{
|
{
|
||||||
switch (uniform.valueType)
|
switch (uniform.valueType)
|
||||||
{
|
{
|
||||||
@@ -391,14 +389,14 @@ namespace anm2ed::resource::shader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Uniform> uniforms_get(GLuint id)
|
static std::vector<ShaderUniform> uniforms_get(GLuint id)
|
||||||
{
|
{
|
||||||
GLint count{};
|
GLint count{};
|
||||||
GLint maxLength{};
|
GLint maxLength{};
|
||||||
glGetProgramiv(id, GL_ACTIVE_UNIFORMS, &count);
|
glGetProgramiv(id, GL_ACTIVE_UNIFORMS, &count);
|
||||||
glGetProgramiv(id, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxLength);
|
glGetProgramiv(id, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxLength);
|
||||||
|
|
||||||
std::vector<Uniform> uniforms{};
|
std::vector<ShaderUniform> uniforms{};
|
||||||
if (count <= 0 || maxLength <= 0) return uniforms;
|
if (count <= 0 || maxLength <= 0) return uniforms;
|
||||||
|
|
||||||
std::string name((std::size_t)maxLength, '\0');
|
std::string name((std::size_t)maxLength, '\0');
|
||||||
@@ -412,7 +410,7 @@ namespace anm2ed::resource::shader
|
|||||||
auto uniformName = uniform_name_clean_get(std::string(name.data(), (std::size_t)length));
|
auto uniformName = uniform_name_clean_get(std::string(name.data(), (std::size_t)length));
|
||||||
auto valueType = uniform_value_type_get(type);
|
auto valueType = uniform_value_type_get(type);
|
||||||
|
|
||||||
Uniform uniform{};
|
ShaderUniform uniform{};
|
||||||
uniform.name = uniformName;
|
uniform.name = uniformName;
|
||||||
uniform.location = glGetUniformLocation(id, uniformName.c_str());
|
uniform.location = glGetUniformLocation(id, uniformName.c_str());
|
||||||
uniform.glType = type;
|
uniform.glType = type;
|
||||||
@@ -453,10 +451,7 @@ namespace anm2ed::resource::shader
|
|||||||
std::string gles_fragment_convert(std::string_view source) { return gles_convert(source, SHADER_STAGE_FRAGMENT); }
|
std::string gles_fragment_convert(std::string_view source) { return gles_convert(source, SHADER_STAGE_FRAGMENT); }
|
||||||
|
|
||||||
std::string gles_vertex_convert(std::string_view source) { return gles_convert(source, SHADER_STAGE_VERTEX); }
|
std::string gles_vertex_convert(std::string_view source) { return gles_convert(source, SHADER_STAGE_VERTEX); }
|
||||||
}
|
|
||||||
|
|
||||||
namespace anm2ed::resource
|
|
||||||
{
|
|
||||||
ShaderCompileResult shader_compile(const char* vertex, const char* fragment)
|
ShaderCompileResult shader_compile(const char* vertex, const char* fragment)
|
||||||
{
|
{
|
||||||
ShaderCompileResult result{};
|
ShaderCompileResult result{};
|
||||||
@@ -493,7 +488,7 @@ namespace anm2ed::resource
|
|||||||
glAttachShader(result.id, vertexHandle);
|
glAttachShader(result.id, vertexHandle);
|
||||||
glAttachShader(result.id, fragmentHandle);
|
glAttachShader(result.id, fragmentHandle);
|
||||||
|
|
||||||
for (const auto& alias : shader::ATTRIBUTE_ALIASES)
|
for (const auto& alias : ATTRIBUTE_ALIASES)
|
||||||
glBindAttribLocation(result.id, alias.index, alias.name);
|
glBindAttribLocation(result.id, alias.index, alias.name);
|
||||||
|
|
||||||
glLinkProgram(result.id);
|
glLinkProgram(result.id);
|
||||||
@@ -511,7 +506,7 @@ namespace anm2ed::resource
|
|||||||
result.output += std::format("Shader link log:\n{}\n", linkLog.c_str());
|
result.output += std::format("Shader link log:\n{}\n", linkLog.c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
result.uniforms = shader::uniforms_get(result.id);
|
result.uniforms = uniforms_get(result.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
glDeleteShader(vertexHandle);
|
glDeleteShader(vertexHandle);
|
||||||
@@ -526,9 +521,9 @@ namespace anm2ed::resource
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Shader::Shader() = default;
|
ShaderProgram::ShaderProgram() = default;
|
||||||
|
|
||||||
Shader::Shader(const char* vertex, const char* fragment)
|
ShaderProgram::ShaderProgram(const char* vertex, const char* fragment)
|
||||||
{
|
{
|
||||||
auto result = shader_compile(vertex, fragment);
|
auto result = shader_compile(vertex, fragment);
|
||||||
id = result.id;
|
id = result.id;
|
||||||
@@ -536,9 +531,9 @@ namespace anm2ed::resource
|
|||||||
if (!result.output.empty()) logger.error(result.output);
|
if (!result.output.empty()) logger.error(result.output);
|
||||||
}
|
}
|
||||||
|
|
||||||
Shader::Shader(Shader&& other) noexcept { *this = std::move(other); }
|
ShaderProgram::ShaderProgram(ShaderProgram&& other) noexcept { *this = std::move(other); }
|
||||||
|
|
||||||
Shader& Shader::operator=(Shader&& other) noexcept
|
ShaderProgram& ShaderProgram::operator=(ShaderProgram&& other) noexcept
|
||||||
{
|
{
|
||||||
if (this != &other)
|
if (this != &other)
|
||||||
{
|
{
|
||||||
@@ -550,10 +545,9 @@ namespace anm2ed::resource
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Shader::~Shader()
|
ShaderProgram::~ShaderProgram()
|
||||||
{
|
{
|
||||||
if (is_valid()) glDeleteProgram(id);
|
if (is_valid()) glDeleteProgram(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Shader::is_valid() const { return id != 0; }
|
bool ShaderProgram::is_valid() const { return id != 0; }
|
||||||
}
|
|
||||||
+22
-31
@@ -8,14 +8,9 @@
|
|||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace anm2ed::model
|
|
||||||
{
|
|
||||||
struct Shader;
|
struct Shader;
|
||||||
}
|
|
||||||
|
|
||||||
namespace anm2ed::resource::shader
|
struct ShaderInfo
|
||||||
{
|
|
||||||
struct Info
|
|
||||||
{
|
{
|
||||||
const char* vertex;
|
const char* vertex;
|
||||||
const char* fragment;
|
const char* fragment;
|
||||||
@@ -355,7 +350,7 @@ namespace anm2ed::resource::shader
|
|||||||
#undef X
|
#undef X
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Uniform
|
struct ShaderUniform
|
||||||
{
|
{
|
||||||
struct Component
|
struct Component
|
||||||
{
|
{
|
||||||
@@ -382,24 +377,24 @@ namespace anm2ed::resource::shader
|
|||||||
|
|
||||||
enum ShaderType
|
enum ShaderType
|
||||||
{
|
{
|
||||||
LINE,
|
SHADER_LINE,
|
||||||
DASHED,
|
SHADER_DASHED,
|
||||||
TEXTURE,
|
SHADER_TEXTURE,
|
||||||
AXIS,
|
SHADER_AXIS,
|
||||||
GRID,
|
SHADER_GRID,
|
||||||
COUNT
|
SHADER_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
const Info SHADERS[COUNT] = {{VERTEX, FRAGMENT},
|
const ShaderInfo SHADERS[SHADER_COUNT] = {{VERTEX, FRAGMENT},
|
||||||
{DASHED_VERTEX, DASHED_FRAGMENT},
|
{DASHED_VERTEX, DASHED_FRAGMENT},
|
||||||
{VERTEX, TEXTURE_FRAGMENT},
|
{VERTEX, TEXTURE_FRAGMENT},
|
||||||
{AXIS_VERTEX, FRAGMENT},
|
{AXIS_VERTEX, FRAGMENT},
|
||||||
{GRID_VERTEX, GRID_FRAGMENT}};
|
{GRID_VERTEX, GRID_FRAGMENT}};
|
||||||
|
|
||||||
UniformBinding uniform_binding_auto_get(std::string_view, UniformValueType);
|
UniformBinding uniform_binding_auto_get(std::string_view, UniformValueType);
|
||||||
void uniform_configs_apply(const model::Shader&, std::vector<Uniform>&);
|
void uniform_configs_apply(const Shader&, std::vector<ShaderUniform>&);
|
||||||
bool uniform_configs_trim(model::Shader&, const std::vector<Uniform>&);
|
bool uniform_configs_trim(Shader&, const std::vector<ShaderUniform>&);
|
||||||
void uniform_config_save(model::Shader&, const Uniform&);
|
void uniform_config_save(Shader&, const ShaderUniform&);
|
||||||
UniformBinding uniform_binding_get(std::string_view);
|
UniformBinding uniform_binding_get(std::string_view);
|
||||||
std::string_view uniform_binding_value_get(UniformBinding);
|
std::string_view uniform_binding_value_get(UniformBinding);
|
||||||
std::string_view uniform_binding_label_get(UniformBinding);
|
std::string_view uniform_binding_label_get(UniformBinding);
|
||||||
@@ -408,37 +403,33 @@ namespace anm2ed::resource::shader
|
|||||||
bool is_uniform_value_editable(UniformValueType);
|
bool is_uniform_value_editable(UniformValueType);
|
||||||
bool is_uniform_value_vector(UniformValueType);
|
bool is_uniform_value_vector(UniformValueType);
|
||||||
bool is_uniform_binding_valid(UniformBinding, UniformValueType);
|
bool is_uniform_binding_valid(UniformBinding, UniformValueType);
|
||||||
void uniform_value_parse(Uniform&, std::string_view);
|
void uniform_value_parse(ShaderUniform&, std::string_view);
|
||||||
std::string uniform_value_string_get(const Uniform&);
|
std::string uniform_value_string_get(const ShaderUniform&);
|
||||||
std::string gles_convert(std::string_view, ShaderStage);
|
std::string gles_convert(std::string_view, ShaderStage);
|
||||||
std::string gles_fragment_convert(std::string_view);
|
std::string gles_fragment_convert(std::string_view);
|
||||||
std::string gles_vertex_convert(std::string_view);
|
std::string gles_vertex_convert(std::string_view);
|
||||||
}
|
|
||||||
|
|
||||||
namespace anm2ed::resource
|
|
||||||
{
|
|
||||||
struct ShaderCompileResult
|
struct ShaderCompileResult
|
||||||
{
|
{
|
||||||
GLuint id{};
|
GLuint id{};
|
||||||
std::string output{};
|
std::string output{};
|
||||||
std::vector<shader::Uniform> uniforms{};
|
std::vector<ShaderUniform> uniforms{};
|
||||||
bool isCompiled{};
|
bool isCompiled{};
|
||||||
bool isLinked{};
|
bool isLinked{};
|
||||||
};
|
};
|
||||||
|
|
||||||
ShaderCompileResult shader_compile(const char*, const char*);
|
ShaderCompileResult shader_compile(const char*, const char*);
|
||||||
|
|
||||||
class Shader
|
class ShaderProgram
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GLuint id{};
|
GLuint id{};
|
||||||
std::vector<shader::Uniform> uniforms{};
|
std::vector<ShaderUniform> uniforms{};
|
||||||
|
|
||||||
Shader();
|
ShaderProgram();
|
||||||
Shader(const char*, const char*);
|
ShaderProgram(const char*, const char*);
|
||||||
Shader(Shader&&) noexcept;
|
ShaderProgram(ShaderProgram&&) noexcept;
|
||||||
Shader& operator=(Shader&&) noexcept;
|
ShaderProgram& operator=(ShaderProgram&&) noexcept;
|
||||||
~Shader();
|
~ShaderProgram();
|
||||||
bool is_valid() const;
|
bool is_valid() const;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
+20
-26
@@ -2,21 +2,19 @@
|
|||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
namespace anm2ed::snapshots
|
template <typename T> static bool is_value_equal(const T& left, const T& right) { return left == right; }
|
||||||
{
|
|
||||||
template <typename T> bool is_value_equal(const T& left, const T& right) { return left == right; }
|
|
||||||
|
|
||||||
bool is_value_equal(const model::Model& left, const model::Model& right)
|
static bool is_value_equal(const Model& left, const Model& right)
|
||||||
{
|
{
|
||||||
return model::is_model_equal(left, right);
|
return is_model_equal(left, right);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_value_equal(const Playback& left, const Playback& right)
|
static bool is_value_equal(const Playback& left, const Playback& right)
|
||||||
{
|
{
|
||||||
return left.time == right.time && left.isPlaying == right.isPlaying && left.isFinished == right.isFinished;
|
return left.time == right.time && left.isPlaying == right.isPlaying && left.isFinished == right.isFinished;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_step_empty(const SnapshotStep& step)
|
static bool is_step_empty(const SnapshotStep& step)
|
||||||
{
|
{
|
||||||
#define X(type, name) \
|
#define X(type, name) \
|
||||||
if (!is_value_equal(step.before.name, step.after.name)) return false;
|
if (!is_value_equal(step.before.name, step.after.name)) return false;
|
||||||
@@ -25,7 +23,7 @@ namespace anm2ed::snapshots
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void step_apply(Snapshot& current, const SnapshotStep& step, bool isUndo)
|
static void step_apply(Snapshot& current, const SnapshotStep& step, bool isUndo)
|
||||||
{
|
{
|
||||||
const auto& target = isUndo ? step.before : step.after;
|
const auto& target = isUndo ? step.before : step.after;
|
||||||
#define X(type, name) \
|
#define X(type, name) \
|
||||||
@@ -35,21 +33,18 @@ namespace anm2ed::snapshots
|
|||||||
current.message = step.after.message;
|
current.message = step.after.message;
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference focus_get(const Snapshot& snapshot)
|
static Reference focus_get(const Snapshot& snapshot)
|
||||||
{
|
{
|
||||||
return selection_focus_get(snapshot.selection, model::UidIndex(snapshot.model));
|
return selection_focus_get(snapshot.selection, UidIndex(snapshot.model));
|
||||||
}
|
}
|
||||||
|
|
||||||
void selection_follow(Snapshot& snapshot, Reference before)
|
static void selection_follow(Snapshot& snapshot, Reference before)
|
||||||
{
|
{
|
||||||
snapshot.model.uids_repair();
|
snapshot.model.uids_repair();
|
||||||
::anm2ed::selection_follow(snapshot.selection, snapshot.model, model::UidIndex(snapshot.model), before);
|
selection_follow(snapshot.selection, snapshot.model, UidIndex(snapshot.model), before);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
namespace anm2ed
|
int SnapshotStack::maxSize = SNAPSHOT_MAX;
|
||||||
{
|
|
||||||
int SnapshotStack::maxSize = snapshots::MAX;
|
|
||||||
|
|
||||||
bool SnapshotStack::is_empty() { return stack.empty(); }
|
bool SnapshotStack::is_empty() { return stack.empty(); }
|
||||||
std::size_t SnapshotStack::size() const { return stack.size(); }
|
std::size_t SnapshotStack::size() const { return stack.size(); }
|
||||||
@@ -82,17 +77,17 @@ namespace anm2ed
|
|||||||
void Snapshots::push(const std::string& message)
|
void Snapshots::push(const std::string& message)
|
||||||
{
|
{
|
||||||
if (pending || pendingFocus) commit();
|
if (pending || pendingFocus) commit();
|
||||||
pendingFocus = snapshots::focus_get(current);
|
pendingFocus = focus_get(current);
|
||||||
current.message = message;
|
current.message = message;
|
||||||
pending = current;
|
pending = current;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Snapshots::commit()
|
void Snapshots::commit()
|
||||||
{
|
{
|
||||||
if (pendingFocus) snapshots::selection_follow(current, *std::exchange(pendingFocus, std::nullopt));
|
if (pendingFocus) selection_follow(current, *std::exchange(pendingFocus, std::nullopt));
|
||||||
if (!pending) return;
|
if (!pending) return;
|
||||||
SnapshotStep step{std::move(*std::exchange(pending, std::nullopt)), current};
|
SnapshotStep step{std::move(*std::exchange(pending, std::nullopt)), current};
|
||||||
if (snapshots::is_step_empty(step)) return;
|
if (is_step_empty(step)) return;
|
||||||
undoStack.push(std::move(step));
|
undoStack.push(std::move(step));
|
||||||
redoStack.clear();
|
redoStack.clear();
|
||||||
}
|
}
|
||||||
@@ -103,9 +98,9 @@ namespace anm2ed
|
|||||||
pendingFocus.reset();
|
pendingFocus.reset();
|
||||||
auto step = undoStack.pop();
|
auto step = undoStack.pop();
|
||||||
if (!step) return false;
|
if (!step) return false;
|
||||||
auto focus = snapshots::focus_get(current);
|
auto focus = focus_get(current);
|
||||||
snapshots::step_apply(current, *step, true);
|
step_apply(current, *step, true);
|
||||||
snapshots::selection_follow(current, focus);
|
selection_follow(current, focus);
|
||||||
redoStack.push(std::move(*step));
|
redoStack.push(std::move(*step));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -116,9 +111,9 @@ namespace anm2ed
|
|||||||
pendingFocus.reset();
|
pendingFocus.reset();
|
||||||
auto step = redoStack.pop();
|
auto step = redoStack.pop();
|
||||||
if (!step) return false;
|
if (!step) return false;
|
||||||
auto focus = snapshots::focus_get(current);
|
auto focus = focus_get(current);
|
||||||
snapshots::step_apply(current, *step, false);
|
step_apply(current, *step, false);
|
||||||
snapshots::selection_follow(current, focus);
|
selection_follow(current, focus);
|
||||||
undoStack.push(std::move(*step));
|
undoStack.push(std::move(*step));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -136,4 +131,3 @@ namespace anm2ed
|
|||||||
undoStack.trim_to_limit();
|
undoStack.trim_to_limit();
|
||||||
redoStack.trim_to_limit();
|
redoStack.trim_to_limit();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
+4
-10
@@ -9,18 +9,13 @@
|
|||||||
#include "playback.h"
|
#include "playback.h"
|
||||||
#include "selection.h"
|
#include "selection.h"
|
||||||
|
|
||||||
namespace anm2ed::snapshots
|
constexpr auto SNAPSHOT_ACTION = "Action";
|
||||||
{
|
constexpr auto SNAPSHOT_MAX = 20;
|
||||||
constexpr auto ACTION = "Action";
|
|
||||||
constexpr auto MAX = 20;
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
using AssetKeys = std::map<int, std::uint64_t>;
|
using AssetKeys = std::map<int, std::uint64_t>;
|
||||||
|
|
||||||
#define SNAPSHOT_STEP_STATE_FIELDS \
|
#define SNAPSHOT_STEP_STATE_FIELDS \
|
||||||
X(model::Model, model) \
|
X(Model, model) \
|
||||||
X(Playback, playback) \
|
X(Playback, playback) \
|
||||||
X(Selection, selection) \
|
X(Selection, selection) \
|
||||||
X(float, frameTime) \
|
X(float, frameTime) \
|
||||||
@@ -33,7 +28,7 @@ namespace anm2ed
|
|||||||
#define X(type, name) type name{};
|
#define X(type, name) type name{};
|
||||||
SNAPSHOT_STEP_STATE_FIELDS
|
SNAPSHOT_STEP_STATE_FIELDS
|
||||||
#undef X
|
#undef X
|
||||||
std::string message = snapshots::ACTION;
|
std::string message = SNAPSHOT_ACTION;
|
||||||
};
|
};
|
||||||
|
|
||||||
// One undoable edit: the state before and after it; undo/redo restore only the fields the edit changed.
|
// One undoable edit: the state before and after it; undo/redo restore only the fields the edit changed.
|
||||||
@@ -76,4 +71,3 @@ namespace anm2ed
|
|||||||
void reset();
|
void reset();
|
||||||
void apply_limit();
|
void apply_limit();
|
||||||
};
|
};
|
||||||
}
|
|
||||||
+1
-4
@@ -3,8 +3,6 @@
|
|||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <climits>
|
#include <climits>
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
struct WSAInitializer
|
struct WSAInitializer
|
||||||
{
|
{
|
||||||
@@ -19,7 +17,7 @@ namespace anm2ed
|
|||||||
WSAInitializer initializer{};
|
WSAInitializer initializer{};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int socket_last_error()
|
static int socket_last_error()
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
return WSAGetLastError();
|
return WSAGetLastError();
|
||||||
@@ -262,4 +260,3 @@ namespace anm2ed
|
|||||||
bool Socket::is_valid() const { return handle != SOCKET_INVALID; }
|
bool Socket::is_valid() const { return handle != SOCKET_INVALID; }
|
||||||
|
|
||||||
int Socket::last_error() const { return lastError; }
|
int Socket::last_error() const { return lastError; }
|
||||||
}
|
|
||||||
@@ -17,8 +17,6 @@ using socket_handle = int;
|
|||||||
constexpr socket_handle SOCKET_INVALID = -1;
|
constexpr socket_handle SOCKET_INVALID = -1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
enum SocketRole
|
enum SocketRole
|
||||||
{
|
{
|
||||||
SERVER,
|
SERVER,
|
||||||
@@ -60,4 +58,3 @@ namespace anm2ed
|
|||||||
bool is_valid() const;
|
bool is_valid() const;
|
||||||
int last_error() const;
|
int last_error() const;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
+12
-19
@@ -15,12 +15,6 @@
|
|||||||
#include "ui/toast.h"
|
#include "ui/toast.h"
|
||||||
#include "ui/shortcut.h"
|
#include "ui/shortcut.h"
|
||||||
|
|
||||||
using namespace anm2ed::imgui;
|
|
||||||
using namespace anm2ed::util;
|
|
||||||
using namespace anm2ed::types;
|
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
constexpr auto UPDATE_RATE = 120;
|
constexpr auto UPDATE_RATE = 120;
|
||||||
constexpr auto UPDATE_INTERVAL = (1000 / UPDATE_RATE);
|
constexpr auto UPDATE_INTERVAL = (1000 / UPDATE_RATE);
|
||||||
|
|
||||||
@@ -29,7 +23,7 @@ namespace anm2ed
|
|||||||
dialog = Dialog(window);
|
dialog = Dialog(window);
|
||||||
|
|
||||||
for (const auto& argument : arguments)
|
for (const auto& argument : arguments)
|
||||||
manager.open(path::from_utf8(argument));
|
manager.open(path_from_utf8(argument));
|
||||||
|
|
||||||
manager.settings_apply(settings);
|
manager.settings_apply(settings);
|
||||||
}
|
}
|
||||||
@@ -77,8 +71,8 @@ namespace anm2ed
|
|||||||
{
|
{
|
||||||
std::string droppedFile = event.drop.data ? event.drop.data : "";
|
std::string droppedFile = event.drop.data ? event.drop.data : "";
|
||||||
if (droppedFile.empty()) break;
|
if (droppedFile.empty()) break;
|
||||||
auto droppedPath = path::from_utf8(droppedFile);
|
auto droppedPath = path_from_utf8(droppedFile);
|
||||||
if (path::is_extension(droppedPath, "anm2"))
|
if (is_path_extension(droppedPath, "anm2"))
|
||||||
{
|
{
|
||||||
if (manager.documents.empty())
|
if (manager.documents.empty())
|
||||||
manager.open(droppedPath);
|
manager.open(droppedPath);
|
||||||
@@ -91,12 +85,12 @@ namespace anm2ed
|
|||||||
}
|
}
|
||||||
SDL_FlashWindow(window, SDL_FLASH_UNTIL_FOCUSED);
|
SDL_FlashWindow(window, SDL_FLASH_UNTIL_FOCUSED);
|
||||||
}
|
}
|
||||||
else if (path::is_extension(droppedPath, resource::image::PNG_EXTENSION) ||
|
else if (is_path_extension(droppedPath, PNG_EXTENSION) ||
|
||||||
path::is_extension(droppedPath, resource::image::SVG_EXTENSION))
|
is_path_extension(droppedPath, SVG_EXTENSION))
|
||||||
{
|
{
|
||||||
spritesheetDropPaths.push_back(droppedPath);
|
spritesheetDropPaths.push_back(droppedPath);
|
||||||
}
|
}
|
||||||
else if (path::is_extension(droppedPath, "wav") || path::is_extension(droppedPath, "ogg"))
|
else if (is_path_extension(droppedPath, "wav") || is_path_extension(droppedPath, "ogg"))
|
||||||
{
|
{
|
||||||
soundDropPaths.push_back(droppedPath);
|
soundDropPaths.push_back(droppedPath);
|
||||||
}
|
}
|
||||||
@@ -139,8 +133,8 @@ namespace anm2ed
|
|||||||
std::string droppedFile = event.user.data1 ? static_cast<const char*>(event.user.data1) : "";
|
std::string droppedFile = event.user.data1 ? static_cast<const char*>(event.user.data1) : "";
|
||||||
if (event.user.data1) SDL_free(event.user.data1);
|
if (event.user.data1) SDL_free(event.user.data1);
|
||||||
if (droppedFile.empty()) break;
|
if (droppedFile.empty()) break;
|
||||||
auto droppedPath = path::from_utf8(droppedFile);
|
auto droppedPath = path_from_utf8(droppedFile);
|
||||||
if (path::is_extension(droppedPath, "anm2"))
|
if (is_path_extension(droppedPath, "anm2"))
|
||||||
{
|
{
|
||||||
manager.open(droppedPath);
|
manager.open(droppedPath);
|
||||||
SDL_FlashWindow(window, SDL_FLASH_UNTIL_FOCUSED);
|
SDL_FlashWindow(window, SDL_FLASH_UNTIL_FOCUSED);
|
||||||
@@ -188,12 +182,12 @@ namespace anm2ed
|
|||||||
if (!dockspace.is_canvas_focused_get())
|
if (!dockspace.is_canvas_focused_get())
|
||||||
{
|
{
|
||||||
float uiScaleDelta{};
|
float uiScaleDelta{};
|
||||||
if (imgui::shortcut(manager.chords[SHORTCUT_ZOOM_IN], shortcut::GLOBAL)) uiScaleDelta += UI_SCALE_STEP;
|
if (shortcut(manager.chords[SHORTCUT_ZOOM_IN], SCOPE_GLOBAL)) uiScaleDelta += UI_SCALE_STEP;
|
||||||
if (imgui::shortcut(manager.chords[SHORTCUT_ZOOM_OUT], shortcut::GLOBAL)) uiScaleDelta -= UI_SCALE_STEP;
|
if (shortcut(manager.chords[SHORTCUT_ZOOM_OUT], SCOPE_GLOBAL)) uiScaleDelta -= UI_SCALE_STEP;
|
||||||
if (uiScaleDelta != 0.0f)
|
if (uiScaleDelta != 0.0f)
|
||||||
{
|
{
|
||||||
settings.uiScale = std::clamp(settings.uiScale + uiScaleDelta, UI_SCALE_MIN, UI_SCALE_MAX);
|
settings.uiScale = std::clamp(settings.uiScale + uiScaleDelta, UI_SCALE_MIN, UI_SCALE_MAX);
|
||||||
ImGui::GetStyle().FontScaleMain = math::percent_to_unit(settings.uiScale);
|
ImGui::GetStyle().FontScaleMain = percent_to_unit(settings.uiScale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,7 +218,7 @@ namespace anm2ed
|
|||||||
}
|
}
|
||||||
|
|
||||||
SDL_GL_SwapWindow(window);
|
SDL_GL_SwapWindow(window);
|
||||||
resource::texture::garbage_collect();
|
texture_garbage_collect();
|
||||||
SDL_GL_SetSwapInterval(settings.isVsync);
|
SDL_GL_SetSwapInterval(settings.isVsync);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,4 +259,3 @@ namespace anm2ed
|
|||||||
|
|
||||||
SDL_Delay(1);
|
SDL_Delay(1);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
+3
-6
@@ -7,8 +7,6 @@
|
|||||||
|
|
||||||
#include "ui/dockspace.h"
|
#include "ui/dockspace.h"
|
||||||
|
|
||||||
namespace anm2ed
|
|
||||||
{
|
|
||||||
class State
|
class State
|
||||||
{
|
{
|
||||||
void tick(Settings&, float);
|
void tick(Settings&, float);
|
||||||
@@ -23,9 +21,9 @@ namespace anm2ed
|
|||||||
Dialog dialog;
|
Dialog dialog;
|
||||||
Clipboard clipboard;
|
Clipboard clipboard;
|
||||||
|
|
||||||
imgui::Taskbar taskbar;
|
Taskbar taskbar;
|
||||||
imgui::Documents documents;
|
Documents documents;
|
||||||
imgui::Dockspace dockspace;
|
Dockspace dockspace;
|
||||||
|
|
||||||
uint64_t previousTick{};
|
uint64_t previousTick{};
|
||||||
uint64_t previousUpdate{};
|
uint64_t previousUpdate{};
|
||||||
@@ -38,4 +36,3 @@ namespace anm2ed
|
|||||||
|
|
||||||
void loop(SDL_Window*&, Settings&);
|
void loop(SDL_Window*&, Settings&);
|
||||||
};
|
};
|
||||||
};
|
|
||||||
@@ -5,8 +5,6 @@
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace anm2ed::util
|
|
||||||
{
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
std::wstring utf8_to_wstring(const char* text)
|
std::wstring utf8_to_wstring(const char* text)
|
||||||
{
|
{
|
||||||
@@ -71,4 +69,3 @@ namespace anm2ed::util
|
|||||||
FILE* Process::get() const { return pipe; }
|
FILE* Process::get() const { return pipe; }
|
||||||
|
|
||||||
Process::operator bool() const { return pipe != nullptr; }
|
Process::operator bool() const { return pipe != nullptr; }
|
||||||
}
|
|
||||||
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace anm2ed::util
|
|
||||||
{
|
|
||||||
class Process
|
class Process
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -21,4 +19,3 @@ namespace anm2ed::util
|
|||||||
private:
|
private:
|
||||||
FILE* pipe{};
|
FILE* pipe{};
|
||||||
};
|
};
|
||||||
}
|
|
||||||
+5
-8
@@ -5,17 +5,15 @@
|
|||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
namespace anm2ed::resource::texture
|
struct TextureEntry
|
||||||
{
|
|
||||||
struct Entry
|
|
||||||
{
|
{
|
||||||
GLuint id{};
|
GLuint id{};
|
||||||
bool isUsed{};
|
bool isUsed{};
|
||||||
};
|
};
|
||||||
|
|
||||||
std::unordered_map<std::uint64_t, Entry> entries{};
|
static std::unordered_map<std::uint64_t, TextureEntry> entries{};
|
||||||
|
|
||||||
GLuint id_get(const Image& image)
|
GLuint texture_id_get(const Image& image)
|
||||||
{
|
{
|
||||||
if (!image.is_valid()) return 0;
|
if (!image.is_valid()) return 0;
|
||||||
|
|
||||||
@@ -38,7 +36,7 @@ namespace anm2ed::resource::texture
|
|||||||
return entry.id;
|
return entry.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void garbage_collect()
|
void texture_garbage_collect()
|
||||||
{
|
{
|
||||||
std::erase_if(entries,
|
std::erase_if(entries,
|
||||||
[](auto& pair)
|
[](auto& pair)
|
||||||
@@ -49,7 +47,7 @@ namespace anm2ed::resource::texture
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Image svg_load(const char* data, size_t length, glm::ivec2 size)
|
Image texture_svg_load(const char* data, size_t length, glm::ivec2 size)
|
||||||
{
|
{
|
||||||
auto document = data ? lunasvg::Document::loadFromData(data, length) : nullptr;
|
auto document = data ? lunasvg::Document::loadFromData(data, length) : nullptr;
|
||||||
if (!document) return {};
|
if (!document) return {};
|
||||||
@@ -57,4 +55,3 @@ namespace anm2ed::resource::texture
|
|||||||
if (bitmap.width() == 0 || bitmap.height() == 0) return {};
|
if (bitmap.width() == 0 || bitmap.height() == 0) return {};
|
||||||
return Image(bitmap.data(), size, true);
|
return Image(bitmap.data(), size, true);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
+3
-6
@@ -5,9 +5,6 @@
|
|||||||
#include "image.h"
|
#include "image.h"
|
||||||
|
|
||||||
// GPU copies of Images, uploaded on first use and evicted when a frame passes without them being drawn.
|
// GPU copies of Images, uploaded on first use and evicted when a frame passes without them being drawn.
|
||||||
namespace anm2ed::resource::texture
|
GLuint texture_id_get(const Image&);
|
||||||
{
|
void texture_garbage_collect();
|
||||||
GLuint id_get(const Image&);
|
Image texture_svg_load(const char*, size_t, glm::ivec2);
|
||||||
void garbage_collect();
|
|
||||||
Image svg_load(const char*, size_t, glm::ivec2);
|
|
||||||
}
|
|
||||||
+1
-4
@@ -5,9 +5,7 @@
|
|||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
namespace anm2ed::util::time
|
std::string timestamp_get(const char* format)
|
||||||
{
|
|
||||||
std::string get(const char* format)
|
|
||||||
{
|
{
|
||||||
auto now = std::chrono::system_clock::now();
|
auto now = std::chrono::system_clock::now();
|
||||||
auto time = std::chrono::system_clock::to_time_t(now);
|
auto time = std::chrono::system_clock::to_time_t(now);
|
||||||
@@ -16,4 +14,3 @@ namespace anm2ed::util::time
|
|||||||
timeString << std::put_time(&localTime, format);
|
timeString << std::put_time(&localTime, format);
|
||||||
return timeString.str();
|
return timeString.str();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
+2
-5
@@ -2,9 +2,6 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace anm2ed::util::time
|
constexpr auto SECOND_MINUTES = 60;
|
||||||
{
|
|
||||||
constexpr auto SECOND_M = 60;
|
|
||||||
|
|
||||||
std::string get(const char*);
|
std::string timestamp_get(const char*);
|
||||||
}
|
|
||||||
+34
-37
@@ -6,74 +6,71 @@
|
|||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "localization.h"
|
#include "localization.h"
|
||||||
|
|
||||||
namespace anm2ed::tool
|
enum Tool
|
||||||
{
|
|
||||||
enum Type
|
|
||||||
{
|
{
|
||||||
PAN,
|
TOOL_PAN,
|
||||||
MOVE,
|
TOOL_MOVE,
|
||||||
ROTATE,
|
TOOL_ROTATE,
|
||||||
SCALE,
|
TOOL_SCALE,
|
||||||
SKEW,
|
TOOL_SKEW,
|
||||||
CROP,
|
TOOL_CROP,
|
||||||
DRAW,
|
TOOL_DRAW,
|
||||||
ERASE,
|
TOOL_ERASE,
|
||||||
COLOR_PICKER,
|
TOOL_COLOR_PICKER,
|
||||||
UNDO,
|
TOOL_UNDO,
|
||||||
REDO,
|
TOOL_REDO,
|
||||||
COLOR,
|
TOOL_COLOR,
|
||||||
COUNT
|
TOOL_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
enum AreaType
|
enum ToolArea
|
||||||
{
|
{
|
||||||
ANIMATION_PREVIEW,
|
TOOL_AREA_ANIMATION_PREVIEW,
|
||||||
SPRITESHEET_EDITOR,
|
TOOL_AREA_SPRITESHEET_EDITOR,
|
||||||
ALL
|
TOOL_AREA_ALL
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Info
|
struct ToolInfo
|
||||||
{
|
{
|
||||||
ImGuiMouseCursor cursor{ImGuiMouseCursor_None};
|
ImGuiMouseCursor cursor{ImGuiMouseCursor_None};
|
||||||
resource::icon::Type icon{};
|
Icon icon{};
|
||||||
ShortcutType shortcut{};
|
ShortcutType shortcut{};
|
||||||
AreaType areaType;
|
ToolArea areaType;
|
||||||
const char* label{};
|
const char* label{};
|
||||||
StringType tooltip{};
|
StringType tooltip{};
|
||||||
bool isFrameRequired{};
|
bool isFrameRequired{};
|
||||||
bool isSpritesheetRequired{};
|
bool isSpritesheetRequired{};
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr Info INFO[] = {
|
constexpr ToolInfo TOOLS[] = {
|
||||||
{ImGuiMouseCursor_Hand, resource::icon::PAN, SHORTCUT_PAN, ALL, "##Pan", TOOLTIP_TOOL_PAN},
|
{ImGuiMouseCursor_Hand, ICON_PAN, SHORTCUT_PAN, TOOL_AREA_ALL, "##Pan", TOOLTIP_TOOL_PAN},
|
||||||
|
|
||||||
{ImGuiMouseCursor_ResizeAll, resource::icon::MOVE, SHORTCUT_MOVE, ALL, "##Move", TOOLTIP_TOOL_MOVE, true},
|
{ImGuiMouseCursor_ResizeAll, ICON_MOVE, SHORTCUT_MOVE, TOOL_AREA_ALL, "##Move", TOOLTIP_TOOL_MOVE, true},
|
||||||
|
|
||||||
{ImGuiMouseCursor_Arrow, resource::icon::ROTATE, SHORTCUT_ROTATE, ANIMATION_PREVIEW, "##Rotate",
|
{ImGuiMouseCursor_Arrow, ICON_ROTATE, SHORTCUT_ROTATE, TOOL_AREA_ANIMATION_PREVIEW, "##Rotate",
|
||||||
TOOLTIP_TOOL_ROTATE, true},
|
TOOLTIP_TOOL_ROTATE, true},
|
||||||
|
|
||||||
{ImGuiMouseCursor_ResizeNESW, resource::icon::SCALE, SHORTCUT_SCALE, ANIMATION_PREVIEW, "##Scale",
|
{ImGuiMouseCursor_ResizeNESW, ICON_SCALE, SHORTCUT_SCALE, TOOL_AREA_ANIMATION_PREVIEW, "##Scale",
|
||||||
TOOLTIP_TOOL_SCALE, true},
|
TOOLTIP_TOOL_SCALE, true},
|
||||||
|
|
||||||
{ImGuiMouseCursor_ResizeNESW, resource::icon::SKEW, SHORTCUT_SKEW, ANIMATION_PREVIEW, "##Skew", TOOLTIP_TOOL_SKEW,
|
{ImGuiMouseCursor_ResizeNESW, ICON_SKEW, SHORTCUT_SKEW, TOOL_AREA_ANIMATION_PREVIEW, "##Skew", TOOLTIP_TOOL_SKEW,
|
||||||
true},
|
true},
|
||||||
|
|
||||||
{ImGuiMouseCursor_Arrow, resource::icon::CROP, SHORTCUT_CROP, SPRITESHEET_EDITOR, "##Crop", TOOLTIP_TOOL_CROP,
|
{ImGuiMouseCursor_Arrow, ICON_CROP, SHORTCUT_CROP, TOOL_AREA_SPRITESHEET_EDITOR, "##Crop", TOOLTIP_TOOL_CROP,
|
||||||
true},
|
true},
|
||||||
|
|
||||||
{ImGuiMouseCursor_Arrow, resource::icon::DRAW, SHORTCUT_DRAW, SPRITESHEET_EDITOR, "##Draw", TOOLTIP_TOOL_DRAW,
|
{ImGuiMouseCursor_Arrow, ICON_DRAW, SHORTCUT_DRAW, TOOL_AREA_SPRITESHEET_EDITOR, "##Draw", TOOLTIP_TOOL_DRAW,
|
||||||
false, true},
|
false, true},
|
||||||
|
|
||||||
{ImGuiMouseCursor_Arrow, resource::icon::ERASE, SHORTCUT_ERASE, SPRITESHEET_EDITOR, "##Erase", TOOLTIP_TOOL_ERASE,
|
{ImGuiMouseCursor_Arrow, ICON_ERASE, SHORTCUT_ERASE, TOOL_AREA_SPRITESHEET_EDITOR, "##Erase", TOOLTIP_TOOL_ERASE,
|
||||||
false, true},
|
false, true},
|
||||||
|
|
||||||
{ImGuiMouseCursor_Arrow, resource::icon::COLOR_PICKER, SHORTCUT_COLOR_PICKER, SPRITESHEET_EDITOR,
|
{ImGuiMouseCursor_Arrow, ICON_COLOR_PICKER, SHORTCUT_COLOR_PICKER, TOOL_AREA_SPRITESHEET_EDITOR,
|
||||||
"##Color Picker", TOOLTIP_TOOL_COLOR_PICKER, false, true},
|
"##Color Picker", TOOLTIP_TOOL_COLOR_PICKER, false, true},
|
||||||
|
|
||||||
{ImGuiMouseCursor_None, resource::icon::UNDO, SHORTCUT_UNDO, ALL, "##Undo", TOOLTIP_TOOL_UNDO},
|
{ImGuiMouseCursor_None, ICON_UNDO, SHORTCUT_UNDO, TOOL_AREA_ALL, "##Undo", TOOLTIP_TOOL_UNDO},
|
||||||
|
|
||||||
{ImGuiMouseCursor_None, resource::icon::REDO, SHORTCUT_REDO, ALL, "##Redo", TOOLTIP_TOOL_REDO},
|
{ImGuiMouseCursor_None, ICON_REDO, SHORTCUT_REDO, TOOL_AREA_ALL, "##Redo", TOOLTIP_TOOL_REDO},
|
||||||
|
|
||||||
{ImGuiMouseCursor_None, resource::icon::NONE, SHORTCUT_COLOR, ALL, "##Color", TOOLTIP_TOOL_COLOR},
|
{ImGuiMouseCursor_None, ICON_NONE, SHORTCUT_COLOR, TOOL_AREA_ALL, "##Color", TOOLTIP_TOOL_COLOR},
|
||||||
};
|
};
|
||||||
}
|
|
||||||
+31
-55
@@ -2,81 +2,58 @@
|
|||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
namespace anm2ed::types::shortcut
|
enum ShortcutScope
|
||||||
{
|
|
||||||
enum Type
|
|
||||||
{
|
{
|
||||||
FOCUSED,
|
SCOPE_FOCUSED,
|
||||||
GLOBAL,
|
SCOPE_GLOBAL,
|
||||||
FOCUSED_SET,
|
SCOPE_FOCUSED_SET,
|
||||||
GLOBAL_SET
|
SCOPE_GLOBAL_SET
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
namespace anm2ed::types::destination
|
enum Destination
|
||||||
{
|
|
||||||
enum Type
|
|
||||||
{
|
{
|
||||||
ALL,
|
DESTINATION_ALL,
|
||||||
THIS
|
DESTINATION_THIS
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
namespace anm2ed::types::source
|
enum Source
|
||||||
{
|
|
||||||
enum Type
|
|
||||||
{
|
{
|
||||||
NEW,
|
SOURCE_NEW,
|
||||||
EXISTING
|
SOURCE_EXISTING
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
namespace anm2ed::types::overlay_draw_order
|
enum OverlayDrawOrder
|
||||||
{
|
|
||||||
enum Type
|
|
||||||
{
|
{
|
||||||
OVER,
|
OVERLAY_OVER,
|
||||||
UNDER
|
OVERLAY_UNDER
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
namespace anm2ed::types::merge
|
enum Merge
|
||||||
{
|
|
||||||
enum Type
|
|
||||||
{
|
{
|
||||||
PREPEND,
|
MERGE_PREPEND,
|
||||||
APPEND,
|
MERGE_APPEND,
|
||||||
REPLACE,
|
MERGE_REPLACE,
|
||||||
IGNORE
|
MERGE_IGNORE
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
namespace anm2ed::types::edit_state
|
enum EditState
|
||||||
{
|
|
||||||
enum Type
|
|
||||||
{
|
{
|
||||||
NONE,
|
EDIT_STATE_NONE,
|
||||||
START,
|
EDIT_STATE_START,
|
||||||
DURING,
|
EDIT_STATE_DURING,
|
||||||
END,
|
EDIT_STATE_END,
|
||||||
COMPLETE
|
EDIT_STATE_COMPLETE
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
namespace anm2ed::types::color
|
|
||||||
{
|
|
||||||
using namespace glm;
|
using namespace glm;
|
||||||
|
|
||||||
constexpr auto WHITE = vec4(1.0);
|
constexpr auto COLOR_WHITE = vec4(1.0);
|
||||||
constexpr auto BLACK = vec4(0.0, 0.0, 0.0, 1.0);
|
constexpr auto COLOR_BLACK = vec4(0.0, 0.0, 0.0, 1.0);
|
||||||
constexpr auto RED = vec4(1.0, 0.0, 0.0, 1.0);
|
constexpr auto COLOR_RED = vec4(1.0, 0.0, 0.0, 1.0);
|
||||||
constexpr auto GREEN = vec4(0.0, 1.0, 0.0, 1.0);
|
constexpr auto COLOR_GREEN = vec4(0.0, 1.0, 0.0, 1.0);
|
||||||
constexpr auto BLUE = vec4(0.0, 0.0, 1.0, 1.0);
|
constexpr auto COLOR_BLUE = vec4(0.0, 0.0, 1.0, 1.0);
|
||||||
constexpr auto PINK = vec4(1.0, 0.0, 1.0, 1.0);
|
constexpr auto COLOR_PINK = vec4(1.0, 0.0, 1.0, 1.0);
|
||||||
}
|
|
||||||
|
|
||||||
namespace anm2ed::types
|
|
||||||
{
|
|
||||||
enum class OnionskinMode
|
enum class OnionskinMode
|
||||||
{
|
{
|
||||||
TIME,
|
TIME,
|
||||||
@@ -84,4 +61,3 @@ namespace anm2ed::types
|
|||||||
};
|
};
|
||||||
|
|
||||||
constexpr auto ID_NONE = -1;
|
constexpr auto ID_NONE = -1;
|
||||||
}
|
|
||||||
+41
-46
@@ -19,12 +19,8 @@
|
|||||||
#include "localization.h"
|
#include "localization.h"
|
||||||
#include "ui/draw.h"
|
#include "ui/draw.h"
|
||||||
|
|
||||||
using namespace anm2ed::resource;
|
|
||||||
using namespace anm2ed::util;
|
|
||||||
using namespace glm;
|
using namespace glm;
|
||||||
|
|
||||||
namespace anm2ed::imgui::wizard
|
|
||||||
{
|
|
||||||
// The credits roll, after the original editor's About box: lengths are its pixels (for 14 px text), at its 30 Hz.
|
// The credits roll, after the original editor's About box: lengths are its pixels (for 14 px text), at its 30 Hz.
|
||||||
enum RollEffect
|
enum RollEffect
|
||||||
{
|
{
|
||||||
@@ -65,42 +61,42 @@ namespace anm2ed::imgui::wizard
|
|||||||
static constexpr float FRIEND_HEIGHT_RATIO = 47.0f / 183.0f;
|
static constexpr float FRIEND_HEIGHT_RATIO = 47.0f / 183.0f;
|
||||||
static constexpr float FRIEND_PADDING_RATIO = 0.15f;
|
static constexpr float FRIEND_PADDING_RATIO = 0.15f;
|
||||||
static constexpr float TITLE_SCALE = 2.0f;
|
static constexpr float TITLE_SCALE = 2.0f;
|
||||||
static constexpr int FRIEND_ORDER_LEFT[] = {resource::friends::MEAT_BOY, resource::friends::ISAAC};
|
static constexpr int FRIEND_ORDER_LEFT[] = {FRIEND_MEAT_BOY, FRIEND_ISAAC};
|
||||||
static constexpr int FRIEND_ORDER_RIGHT[] = {resource::friends::STACY, resource::friends::ASH};
|
static constexpr int FRIEND_ORDER_RIGHT[] = {FRIEND_STACY, FRIEND_ASH};
|
||||||
|
|
||||||
static constexpr About::Credit CREDITS[] = {
|
static constexpr About::Credit CREDITS[] = {
|
||||||
{"Anm2Ed", font::BOLD},
|
{"Anm2Ed", FONT_BOLD},
|
||||||
{"License: GPLv3"},
|
{"License: GPLv3"},
|
||||||
{""},
|
{""},
|
||||||
{"Design/Programming", font::BOLD},
|
{"Design/Programming", FONT_BOLD},
|
||||||
{"Shweet"},
|
{"Shweet"},
|
||||||
{"OpenAI Codex"},
|
{"OpenAI Codex"},
|
||||||
{"Claude Code"},
|
{"Claude Code"},
|
||||||
{""},
|
{""},
|
||||||
{"Additional Help", font::BOLD},
|
{"Additional Help", FONT_BOLD},
|
||||||
{"im-tem"},
|
{"im-tem"},
|
||||||
{""},
|
{""},
|
||||||
{"Localization", font::BOLD},
|
{"Localization", FONT_BOLD},
|
||||||
{"Gabriel Asencio (Spanish (Latin America))"},
|
{"Gabriel Asencio (Spanish (Latin America))"},
|
||||||
{"ExtremeThreat (Russian)"},
|
{"ExtremeThreat (Russian)"},
|
||||||
{"CxRedix (Chinese)"},
|
{"CxRedix (Chinese)"},
|
||||||
{"sawalk/사왈이 (Korean)"},
|
{"sawalk/사왈이 (Korean)"},
|
||||||
{""},
|
{""},
|
||||||
{"Based on the work of", font::BOLD},
|
{"Based on the work of", FONT_BOLD},
|
||||||
{"Adrian Gavrilita"},
|
{"Adrian Gavrilita"},
|
||||||
{"Simon Parzer"},
|
{"Simon Parzer"},
|
||||||
{"Matt Kapuszczak"},
|
{"Matt Kapuszczak"},
|
||||||
{""},
|
{""},
|
||||||
{"Music", font::BOLD},
|
{"Music", FONT_BOLD},
|
||||||
{"Soundbin"},
|
{"Soundbin"},
|
||||||
{"\"Digital Antidepressant\""},
|
{"\"Digital Antidepressant\""},
|
||||||
{"https://www.newgrounds.com/audio/listen/1565433"},
|
{"https://www.newgrounds.com/audio/listen/1565433"},
|
||||||
{"License: CC0"},
|
{"License: CC0"},
|
||||||
{""},
|
{""},
|
||||||
{"Dancing Characters", font::BOLD},
|
{"Dancing Characters", FONT_BOLD},
|
||||||
{"Shweet"},
|
{"Shweet"},
|
||||||
{""},
|
{""},
|
||||||
{"Libraries", font::BOLD},
|
{"Libraries", FONT_BOLD},
|
||||||
{"Dear ImGui"},
|
{"Dear ImGui"},
|
||||||
{"https://github.com/ocornut/imgui"},
|
{"https://github.com/ocornut/imgui"},
|
||||||
{"License: MIT"},
|
{"License: MIT"},
|
||||||
@@ -129,17 +125,17 @@ namespace anm2ed::imgui::wizard
|
|||||||
{"https://github.com/sammycage/lunasvg"},
|
{"https://github.com/sammycage/lunasvg"},
|
||||||
{"License: MIT"},
|
{"License: MIT"},
|
||||||
{""},
|
{""},
|
||||||
{"Icons", font::BOLD},
|
{"Icons", FONT_BOLD},
|
||||||
{"Remix Icons"},
|
{"Remix Icons"},
|
||||||
{"remixicon.com"},
|
{"remixicon.com"},
|
||||||
{"License: Apache"},
|
{"License: Apache"},
|
||||||
{""},
|
{""},
|
||||||
{"Font", font::BOLD},
|
{"Font", FONT_BOLD},
|
||||||
{"Noto Sans"},
|
{"Noto Sans"},
|
||||||
{"https://fonts.google.com/noto/specimen/Noto+Sans"},
|
{"https://fonts.google.com/noto/specimen/Noto+Sans"},
|
||||||
{"License: OFL"},
|
{"License: OFL"},
|
||||||
{""},
|
{""},
|
||||||
{"Special Thanks", font::BOLD},
|
{"Special Thanks", FONT_BOLD},
|
||||||
{"Edmund McMillen"},
|
{"Edmund McMillen"},
|
||||||
{"Florian Himsl"},
|
{"Florian Himsl"},
|
||||||
{"Tyrone Rodriguez"},
|
{"Tyrone Rodriguez"},
|
||||||
@@ -161,7 +157,7 @@ namespace anm2ed::imgui::wizard
|
|||||||
};
|
};
|
||||||
static constexpr auto CREDIT_COUNT = (int)(sizeof(CREDITS) / sizeof(About::Credit));
|
static constexpr auto CREDIT_COUNT = (int)(sizeof(CREDITS) / sizeof(About::Credit));
|
||||||
|
|
||||||
const model::Animation* friend_animation_get(const About::FriendState& state)
|
static const Animation* friend_animation_get(const About::FriendState& state)
|
||||||
{
|
{
|
||||||
auto animations = state.model.animations_get();
|
auto animations = state.model.animations_get();
|
||||||
for (auto [index, animation] : animations)
|
for (auto [index, animation] : animations)
|
||||||
@@ -169,7 +165,7 @@ namespace anm2ed::imgui::wizard
|
|||||||
return animations.empty() ? nullptr : animations.front().second;
|
return animations.empty() ? nullptr : animations.front().second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void friend_state_load(About::FriendState& state, const resource::friends::Info& info)
|
static void friend_state_load(About::FriendState& state, const FriendInfo& info)
|
||||||
{
|
{
|
||||||
if (!state.canvas)
|
if (!state.canvas)
|
||||||
{
|
{
|
||||||
@@ -177,7 +173,7 @@ namespace anm2ed::imgui::wizard
|
|||||||
state.canvas->filter = GL_NEAREST;
|
state.canvas->filter = GL_NEAREST;
|
||||||
}
|
}
|
||||||
|
|
||||||
state.model = model::Model{};
|
state.model = Model{};
|
||||||
state.textures.clear();
|
state.textures.clear();
|
||||||
state.rect = vec4(-1.0f);
|
state.rect = vec4(-1.0f);
|
||||||
state.time = 0.0f;
|
state.time = 0.0f;
|
||||||
@@ -185,7 +181,7 @@ namespace anm2ed::imgui::wizard
|
|||||||
state.isLoaded = false;
|
state.isLoaded = false;
|
||||||
|
|
||||||
std::string errorString{};
|
std::string errorString{};
|
||||||
if (!model::model_load_string(state.model, std::string_view((const char*)info.anm2->data, info.anm2->size), &errorString))
|
if (!model_load_string(state.model, std::string_view((const char*)info.anm2->data, info.anm2->size), &errorString))
|
||||||
{
|
{
|
||||||
logger.error(std::format("Unable to load friend animation {}: {}", info.name, errorString));
|
logger.error(std::format("Unable to load friend animation {}: {}", info.name, errorString));
|
||||||
return;
|
return;
|
||||||
@@ -194,7 +190,7 @@ namespace anm2ed::imgui::wizard
|
|||||||
if (state.model.info.fps > 0) state.fps = (float)state.model.info.fps;
|
if (state.model.info.fps > 0) state.fps = (float)state.model.info.fps;
|
||||||
|
|
||||||
for (auto& spritesheet : state.model.content.spritesheets)
|
for (auto& spritesheet : state.model.content.spritesheets)
|
||||||
state.textures[spritesheet.id] = resource::Image(info.png->data, info.png->size);
|
state.textures[spritesheet.id] = Image(info.png->data, info.png->size);
|
||||||
|
|
||||||
auto animation = friend_animation_get(state);
|
auto animation = friend_animation_get(state);
|
||||||
if (!animation)
|
if (!animation)
|
||||||
@@ -203,11 +199,11 @@ namespace anm2ed::imgui::wizard
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
state.rect = model::animation_rect(state.model, *animation, true);
|
state.rect = animation_rect(state.model, *animation, true);
|
||||||
state.isLoaded = state.rect != vec4(-1.0f) && !state.textures.empty();
|
state.isLoaded = state.rect != vec4(-1.0f) && !state.textures.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void friend_state_tick(About::FriendState& state, float delta)
|
static void friend_state_tick(About::FriendState& state, float delta)
|
||||||
{
|
{
|
||||||
if (!state.isLoaded) return;
|
if (!state.isLoaded) return;
|
||||||
|
|
||||||
@@ -218,7 +214,7 @@ namespace anm2ed::imgui::wizard
|
|||||||
if (state.time < 0.0f) state.time += (float)animation->frameNum;
|
if (state.time < 0.0f) state.time += (float)animation->frameNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImVec2 friend_size_get(const About::FriendState& state, float height)
|
static ImVec2 friend_size_get(const About::FriendState& state, float height)
|
||||||
{
|
{
|
||||||
auto width = height;
|
auto width = height;
|
||||||
if (state.rect.w > 0.0f && state.rect.z > 0.0f) width = height * (state.rect.z / state.rect.w);
|
if (state.rect.w > 0.0f && state.rect.z > 0.0f) width = height * (state.rect.z / state.rect.w);
|
||||||
@@ -226,7 +222,7 @@ namespace anm2ed::imgui::wizard
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The animation's bounds with some room around them.
|
// The animation's bounds with some room around them.
|
||||||
vec4 friend_rect_get(const About::FriendState& state)
|
static vec4 friend_rect_get(const About::FriendState& state)
|
||||||
{
|
{
|
||||||
auto rect = state.rect;
|
auto rect = state.rect;
|
||||||
auto padding = std::max(2.0f, std::max(rect.z, rect.w) * FRIEND_PADDING_RATIO);
|
auto padding = std::max(2.0f, std::max(rect.z, rect.w) * FRIEND_PADDING_RATIO);
|
||||||
@@ -234,7 +230,7 @@ namespace anm2ed::imgui::wizard
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Rendered 1:1 into its canvas, which is drawn scaled up with nearest filtering so the pixels stay sharp.
|
// Rendered 1:1 into its canvas, which is drawn scaled up with nearest filtering so the pixels stay sharp.
|
||||||
void friend_canvas_draw(About::FriendState& state, Resources& resources)
|
static void friend_canvas_draw(About::FriendState& state, Resources& resources)
|
||||||
{
|
{
|
||||||
if (!state.isLoaded || !state.canvas) return;
|
if (!state.isLoaded || !state.canvas) return;
|
||||||
|
|
||||||
@@ -255,9 +251,9 @@ namespace anm2ed::imgui::wizard
|
|||||||
vec2 pan{};
|
vec2 pan{};
|
||||||
state.canvas->set_to_rect(zoom, pan, rect);
|
state.canvas->set_to_rect(zoom, pan, rect);
|
||||||
|
|
||||||
state.canvas->layers_render(resources.shaders[shader::TEXTURE], state.model, *animation,
|
state.canvas->layers_render(resources.shaders[SHADER_TEXTURE], state.model, *animation,
|
||||||
{.time = state.time, .isRootTransform = true}, state.canvas->transform_get(zoom, pan),
|
{.time = state.time, .isRootTransform = true}, state.canvas->transform_get(zoom, pan),
|
||||||
[&](const model::Draw& draw)
|
[&](const Draw& draw)
|
||||||
{
|
{
|
||||||
auto texture = state.textures.find(draw.spritesheetId);
|
auto texture = state.textures.find(draw.spritesheetId);
|
||||||
return texture == state.textures.end() ? nullptr : &texture->second;
|
return texture == state.textures.end() ? nullptr : &texture->second;
|
||||||
@@ -267,13 +263,13 @@ namespace anm2ed::imgui::wizard
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The application name, as large as fits its row.
|
// The application name, as large as fits its row.
|
||||||
void title_draw(About& about, Resources& resources, const char* title, float width)
|
static void title_draw(About& about, Resources& resources, const char* title, float width)
|
||||||
{
|
{
|
||||||
auto font = resources.fonts[font::BOLD].get();
|
auto font = resources.fonts[FONT_BOLD].get();
|
||||||
auto fontSize = (float)font::SIZE_LARGE * TITLE_SCALE;
|
auto fontSize = (float)FONT_SIZE_LARGE * TITLE_SCALE;
|
||||||
fontSize *= std::min(1.0f, width / font->CalcTextSizeA(fontSize, FLT_MAX, 0.0f, title).x);
|
fontSize *= std::min(1.0f, width / font->CalcTextSizeA(fontSize, FLT_MAX, 0.0f, title).x);
|
||||||
auto textSize = font->CalcTextSizeA(fontSize, FLT_MAX, 0.0f, title);
|
auto textSize = font->CalcTextSizeA(fontSize, FLT_MAX, 0.0f, title);
|
||||||
auto rowHeight = (float)font::SIZE_LARGE * TITLE_SCALE;
|
auto rowHeight = (float)FONT_SIZE_LARGE * TITLE_SCALE;
|
||||||
auto min = ImGui::GetCursorScreenPos();
|
auto min = ImGui::GetCursorScreenPos();
|
||||||
auto color = about.roll.titleColor ? about.roll.titleColor : ImGui::GetColorU32(ImGuiCol_Text);
|
auto color = about.roll.titleColor ? about.roll.titleColor : ImGui::GetColorU32(ImGuiCol_Text);
|
||||||
ImGui::GetWindowDrawList()->AddText(
|
ImGui::GetWindowDrawList()->AddText(
|
||||||
@@ -283,7 +279,7 @@ namespace anm2ed::imgui::wizard
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The dancing characters stand in the credits box's bottom corners, inside the volume bars.
|
// The dancing characters stand in the credits box's bottom corners, inside the volume bars.
|
||||||
void friends_draw(About& about, Resources& resources, ImDrawList* drawList, ImVec2 min, ImVec2 max, float inset)
|
static void friends_draw(About& about, Resources& resources, ImDrawList* drawList, ImVec2 min, ImVec2 max, float inset)
|
||||||
{
|
{
|
||||||
auto height = (max.y - min.y) * FRIEND_HEIGHT_RATIO;
|
auto height = (max.y - min.y) * FRIEND_HEIGHT_RATIO;
|
||||||
auto row_draw = [&](std::span<const int> indices, float left)
|
auto row_draw = [&](std::span<const int> indices, float left)
|
||||||
@@ -307,9 +303,9 @@ namespace anm2ed::imgui::wizard
|
|||||||
}
|
}
|
||||||
|
|
||||||
// One tick: the credits scroll up (a new pass, and effect, once they are gone) and the bars follow the music.
|
// One tick: the credits scroll up (a new pass, and effect, once they are gone) and the bars follow the music.
|
||||||
void roll_tick(About::RollState& roll, Resources& resources, float boxHeight, float textHeight)
|
static void roll_tick(About::RollState& roll, Resources& resources, float boxHeight, float textHeight)
|
||||||
{
|
{
|
||||||
auto levels = audio::levels_get(resources.music_track());
|
auto levels = audio_levels_get(resources.music_track());
|
||||||
roll.levelPeak = std::max({roll.levelPeak * BAR_LEVEL_DECAY, levels.x, levels.y, BAR_LEVEL_FLOOR});
|
roll.levelPeak = std::max({roll.levelPeak * BAR_LEVEL_DECAY, levels.x, levels.y, BAR_LEVEL_FLOOR});
|
||||||
levels *= boxHeight / roll.levelPeak;
|
levels *= boxHeight / roll.levelPeak;
|
||||||
roll.scroll -= ROLL_SCROLL_STEP;
|
roll.scroll -= ROLL_SCROLL_STEP;
|
||||||
@@ -344,7 +340,7 @@ namespace anm2ed::imgui::wizard
|
|||||||
if (roll.history.size() > ROLL_HISTORY_MAX) roll.history.pop_back();
|
if (roll.history.size() > ROLL_HISTORY_MAX) roll.history.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImU32 color_weighted_get(ImU32 color, float weight)
|
static ImU32 color_weighted_get(ImU32 color, float weight)
|
||||||
{
|
{
|
||||||
auto value = ImGui::ColorConvertU32ToFloat4(color);
|
auto value = ImGui::ColorConvertU32ToFloat4(color);
|
||||||
value.w *= weight;
|
value.w *= weight;
|
||||||
@@ -352,7 +348,7 @@ namespace anm2ed::imgui::wizard
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The credits as one tick drew them; `weight` fades the copies that linger as trails.
|
// The credits as one tick drew them; `weight` fades the copies that linger as trails.
|
||||||
void roll_text_draw(ImDrawList* drawList, Resources& resources, const About::RollFrame& frame, ImVec2 min, ImVec2 max,
|
static void roll_text_draw(ImDrawList* drawList, Resources& resources, const About::RollFrame& frame, ImVec2 min, ImVec2 max,
|
||||||
float scale, float lineHeight, float weight)
|
float scale, float lineHeight, float weight)
|
||||||
{
|
{
|
||||||
auto centerX = (min.x + max.x) * 0.5f;
|
auto centerX = (min.x + max.x) * 0.5f;
|
||||||
@@ -366,7 +362,7 @@ namespace anm2ed::imgui::wizard
|
|||||||
auto x = centerX - font->CalcTextSizeA(lineHeight, FLT_MAX, 0.0f, credit.string).x * 0.5f + frame.offsetX * scale;
|
auto x = centerX - font->CalcTextSizeA(lineHeight, FLT_MAX, 0.0f, credit.string).x * 0.5f + frame.offsetX * scale;
|
||||||
if (frame.effect == EFFECT_WAVE)
|
if (frame.effect == EFFECT_WAVE)
|
||||||
x += std::round(std::sin((y - min.y) / scale * ROLL_WAVE_FREQUENCY) * ROLL_WAVE_AMPLITUDE) * scale;
|
x += std::round(std::sin((y - min.y) / scale * ROLL_WAVE_FREQUENCY) * ROLL_WAVE_AMPLITUDE) * scale;
|
||||||
auto color = credit.font == font::BOLD ? ROLL_HEADER_COLOR : ROLL_NAME_COLOR;
|
auto color = credit.font == FONT_BOLD ? ROLL_HEADER_COLOR : ROLL_NAME_COLOR;
|
||||||
|
|
||||||
auto vertexStart = drawList->VtxBuffer.Size;
|
auto vertexStart = drawList->VtxBuffer.Size;
|
||||||
drawList->AddText(font, lineHeight, ImVec2(x, y), color_weighted_get(color, weight), credit.string);
|
drawList->AddText(font, lineHeight, ImVec2(x, y), color_weighted_get(color, weight), credit.string);
|
||||||
@@ -377,7 +373,7 @@ namespace anm2ed::imgui::wizard
|
|||||||
}
|
}
|
||||||
|
|
||||||
// A volume bar's color at a height: red at the bottom into the tick's color at its gradient height.
|
// A volume bar's color at a height: red at the bottom into the tick's color at its gradient height.
|
||||||
ImU32 bar_color_get(const About::RollFrame& frame, float height, float weight)
|
static ImU32 bar_color_get(const About::RollFrame& frame, float height, float weight)
|
||||||
{
|
{
|
||||||
auto color = ImLerp(ImGui::ColorConvertU32ToFloat4(BAR_BASE_COLOR),
|
auto color = ImLerp(ImGui::ColorConvertU32ToFloat4(BAR_BASE_COLOR),
|
||||||
ImGui::ColorConvertU32ToFloat4(frame.gradientColor), height / frame.gradientHeight);
|
ImGui::ColorConvertU32ToFloat4(frame.gradientColor), height / frame.gradientHeight);
|
||||||
@@ -386,7 +382,7 @@ namespace anm2ed::imgui::wizard
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The left and right volume bars; older, taller bars show above newer ones, fading as they age.
|
// The left and right volume bars; older, taller bars show above newer ones, fading as they age.
|
||||||
void roll_bars_draw(ImDrawList* drawList, const std::deque<About::RollFrame>& history, ImVec2 min, ImVec2 max,
|
static void roll_bars_draw(ImDrawList* drawList, const std::deque<About::RollFrame>& history, ImVec2 min, ImVec2 max,
|
||||||
float scale)
|
float scale)
|
||||||
{
|
{
|
||||||
auto width = BAR_WIDTH * scale;
|
auto width = BAR_WIDTH * scale;
|
||||||
@@ -412,7 +408,7 @@ namespace anm2ed::imgui::wizard
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void roll_draw(About& about, Resources& resources, ImVec2 min, ImVec2 size)
|
static void roll_draw(About& about, Resources& resources, ImVec2 min, ImVec2 size)
|
||||||
{
|
{
|
||||||
auto& roll = about.roll;
|
auto& roll = about.roll;
|
||||||
auto max = ImVec2(min.x + size.x, min.y + size.y);
|
auto max = ImVec2(min.x + size.x, min.y + size.y);
|
||||||
@@ -458,11 +454,11 @@ namespace anm2ed::imgui::wizard
|
|||||||
|
|
||||||
void About::reset(Resources& resources)
|
void About::reset(Resources& resources)
|
||||||
{
|
{
|
||||||
resource::audio::play(resources.music_track(), true);
|
audio_play(resources.music_track(), true);
|
||||||
roll = {};
|
roll = {};
|
||||||
|
|
||||||
for (int i = 0; i < resource::friends::COUNT; ++i)
|
for (int i = 0; i < FRIEND_COUNT; ++i)
|
||||||
friend_state_load(friendStates[i], resource::friends::FRIENDS[i]);
|
friend_state_load(friendStates[i], FRIENDS[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void About::update(Resources& resources)
|
void About::update(Resources& resources)
|
||||||
@@ -479,4 +475,3 @@ namespace anm2ed::imgui::wizard
|
|||||||
auto rollSize = ImGui::GetContentRegionAvail();
|
auto rollSize = ImGui::GetContentRegionAvail();
|
||||||
if (rollSize.x > 0.0f && rollSize.y > 0.0f) roll_draw(*this, resources, ImGui::GetCursorScreenPos(), rollSize);
|
if (rollSize.x > 0.0f && rollSize.y > 0.0f) roll_draw(*this, resources, ImGui::GetCursorScreenPos(), rollSize);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
+4
-7
@@ -13,15 +13,13 @@
|
|||||||
#include "friends.h"
|
#include "friends.h"
|
||||||
#include "resources.h"
|
#include "resources.h"
|
||||||
|
|
||||||
namespace anm2ed::imgui::wizard
|
|
||||||
{
|
|
||||||
class About
|
class About
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
struct Credit
|
struct Credit
|
||||||
{
|
{
|
||||||
const char* string{};
|
const char* string{};
|
||||||
resource::font::Type font{resource::font::REGULAR};
|
FontStyle font{FONT_REGULAR};
|
||||||
};
|
};
|
||||||
|
|
||||||
// One 30 Hz tick of the credits roll, after the original editor's About box. Lengths are in its pixels (for
|
// One 30 Hz tick of the credits roll, after the original editor's About box. Lengths are in its pixels (for
|
||||||
@@ -53,9 +51,9 @@ namespace anm2ed::imgui::wizard
|
|||||||
|
|
||||||
struct FriendState
|
struct FriendState
|
||||||
{
|
{
|
||||||
model::Model model{};
|
Model model{};
|
||||||
std::unique_ptr<Canvas> canvas{};
|
std::unique_ptr<Canvas> canvas{};
|
||||||
std::unordered_map<int, resource::Image> textures{};
|
std::unordered_map<int, Image> textures{};
|
||||||
glm::vec4 rect{-1.0f};
|
glm::vec4 rect{-1.0f};
|
||||||
float time{};
|
float time{};
|
||||||
float fps{30.0f};
|
float fps{30.0f};
|
||||||
@@ -63,10 +61,9 @@ namespace anm2ed::imgui::wizard
|
|||||||
};
|
};
|
||||||
|
|
||||||
RollState roll{};
|
RollState roll{};
|
||||||
std::array<FriendState, resource::friends::COUNT> friendStates{};
|
std::array<FriendState, FRIEND_COUNT> friendStates{};
|
||||||
|
|
||||||
void reset(Resources& resources);
|
void reset(Resources& resources);
|
||||||
void update(Resources& resources);
|
void update(Resources& resources);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
|
||||||
+5
-8
@@ -5,17 +5,15 @@
|
|||||||
#include "ui/layout.h"
|
#include "ui/layout.h"
|
||||||
#include "ui/shortcut.h"
|
#include "ui/shortcut.h"
|
||||||
|
|
||||||
namespace anm2ed::imgui
|
static bool is_action_shortcut_valid(int shortcutType) { return shortcutType >= 0 && shortcutType < SHORTCUT_COUNT; }
|
||||||
{
|
|
||||||
bool is_action_shortcut_valid(int shortcutType) { return shortcutType >= 0 && shortcutType < SHORTCUT_COUNT; }
|
|
||||||
|
|
||||||
std::string action_shortcut_text_get(const Action& action, Settings& settings)
|
static std::string action_shortcut_text_get(const Action& action, Settings& settings)
|
||||||
{
|
{
|
||||||
if (!is_action_shortcut_valid(action.shortcut)) return {};
|
if (!is_action_shortcut_valid(action.shortcut)) return {};
|
||||||
return settings.*SHORTCUT_MEMBERS[action.shortcut];
|
return settings.*SHORTCUT_MEMBERS[action.shortcut];
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGuiKeyChord action_chord_get(const Action& action, Manager& manager)
|
static ImGuiKeyChord action_chord_get(const Action& action, Manager& manager)
|
||||||
{
|
{
|
||||||
if (!is_action_shortcut_valid(action.shortcut)) return ImGuiKey_None;
|
if (!is_action_shortcut_valid(action.shortcut)) return ImGuiKey_None;
|
||||||
return manager.chords[action.shortcut];
|
return manager.chords[action.shortcut];
|
||||||
@@ -55,7 +53,7 @@ namespace anm2ed::imgui
|
|||||||
{ manager.command_push({manager.selected, [](Manager&, Document& document) { document.redo(); }}); });
|
{ manager.command_push({manager.selected, [](Manager&, Document& document) { document.redo(); }}); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void action_items_menu_draw(std::vector<Action>& items, Settings& settings)
|
static void action_items_menu_draw(std::vector<Action>& items, Settings& settings)
|
||||||
{
|
{
|
||||||
bool isPreviousSeparator{};
|
bool isPreviousSeparator{};
|
||||||
for (auto& action : items)
|
for (auto& action : items)
|
||||||
@@ -111,7 +109,7 @@ namespace anm2ed::imgui
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void actions_shortcuts_update(Actions& actions, Manager& manager, types::shortcut::Type shortcutType)
|
void actions_shortcuts_update(Actions& actions, Manager& manager, ShortcutScope shortcutType)
|
||||||
{
|
{
|
||||||
for (auto& action : actions.items)
|
for (auto& action : actions.items)
|
||||||
{
|
{
|
||||||
@@ -140,4 +138,3 @@ namespace anm2ed::imgui
|
|||||||
}
|
}
|
||||||
isSameLine = true;
|
isSameLine = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
+1
-4
@@ -8,8 +8,6 @@
|
|||||||
#include "manager.h"
|
#include "manager.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
namespace anm2ed::imgui
|
|
||||||
{
|
|
||||||
#define ACTIONS(X) \
|
#define ACTIONS(X) \
|
||||||
X(ACTION_UNDO, SHORTCUT_STRING_UNDO, SHORTCUT_UNDO) \
|
X(ACTION_UNDO, SHORTCUT_STRING_UNDO, SHORTCUT_UNDO) \
|
||||||
X(ACTION_REDO, SHORTCUT_STRING_REDO, SHORTCUT_REDO) \
|
X(ACTION_REDO, SHORTCUT_STRING_REDO, SHORTCUT_REDO) \
|
||||||
@@ -91,6 +89,5 @@ namespace anm2ed::imgui
|
|||||||
bool actions_context_window_draw(const char*, Actions&, Settings&, ImGuiPopupFlags = ImGuiPopupFlags_MouseButtonRight,
|
bool actions_context_window_draw(const char*, Actions&, Settings&, ImGuiPopupFlags = ImGuiPopupFlags_MouseButtonRight,
|
||||||
ImGuiHoveredFlags = ImGuiHoveredFlags_None);
|
ImGuiHoveredFlags = ImGuiHoveredFlags_None);
|
||||||
bool actions_popup_draw(const char*, Actions&, Settings&);
|
bool actions_popup_draw(const char*, Actions&, Settings&);
|
||||||
void actions_shortcuts_update(Actions&, Manager&, types::shortcut::Type = types::shortcut::FOCUSED);
|
void actions_shortcuts_update(Actions&, Manager&, ShortcutScope = SCOPE_FOCUSED);
|
||||||
void action_button_draw(Action&, Manager&, Settings&, ImVec2, bool&);
|
void action_button_draw(Action&, Manager&, Settings&, ImVec2, bool&);
|
||||||
}
|
|
||||||
@@ -30,14 +30,8 @@
|
|||||||
#include "ui/shortcut.h"
|
#include "ui/shortcut.h"
|
||||||
#include "ui/timeline.h"
|
#include "ui/timeline.h"
|
||||||
|
|
||||||
using namespace anm2ed::types;
|
|
||||||
using namespace anm2ed::util;
|
|
||||||
using namespace anm2ed::resource;
|
|
||||||
using namespace anm2ed::resource::image;
|
|
||||||
using namespace glm;
|
using namespace glm;
|
||||||
|
|
||||||
namespace anm2ed::imgui
|
|
||||||
{
|
|
||||||
constexpr auto NULL_RECT_COLOR = vec4(0.0f, 0.0f, 1.0f, 0.90f);
|
constexpr auto NULL_RECT_COLOR = vec4(0.0f, 0.0f, 1.0f, 0.90f);
|
||||||
constexpr auto SELECTED_LAYER_BORDER_COLOR = vec4(1.0f, 0.1059f, 0.5882f, 1.0f);
|
constexpr auto SELECTED_LAYER_BORDER_COLOR = vec4(1.0f, 0.1059f, 0.5882f, 1.0f);
|
||||||
constexpr auto TARGET_SIZE = vec2(32, 32);
|
constexpr auto TARGET_SIZE = vec2(32, 32);
|
||||||
@@ -52,13 +46,13 @@ namespace anm2ed::imgui
|
|||||||
std::string label{};
|
std::string label{};
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<OverlayAnimationOption> overlay_animation_options_get(Manager& manager)
|
static std::vector<OverlayAnimationOption> overlay_animation_options_get(Manager& manager)
|
||||||
{
|
{
|
||||||
std::vector<OverlayAnimationOption> options{{.label = std::string(localize.get(BASIC_NONE))}};
|
std::vector<OverlayAnimationOption> options{{.label = std::string(localize.get(BASIC_NONE))}};
|
||||||
|
|
||||||
for (auto& document : manager.documents)
|
for (auto& document : manager.documents)
|
||||||
{
|
{
|
||||||
auto documentLabel = path::to_utf8(document.filename_get());
|
auto documentLabel = path_to_utf8(document.filename_get());
|
||||||
for (auto [animationIndex, animation] : document.model.animations_get())
|
for (auto [animationIndex, animation] : document.model.animations_get())
|
||||||
{
|
{
|
||||||
auto label = std::format("{} ({})", animation->name, documentLabel);
|
auto label = std::format("{} ({})", animation->name, documentLabel);
|
||||||
@@ -69,7 +63,7 @@ namespace anm2ed::imgui
|
|||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<const char*> overlay_animation_option_labels_get(std::vector<OverlayAnimationOption>& options)
|
static std::vector<const char*> overlay_animation_option_labels_get(std::vector<OverlayAnimationOption>& options)
|
||||||
{
|
{
|
||||||
std::vector<const char*> labels{};
|
std::vector<const char*> labels{};
|
||||||
labels.reserve(options.size());
|
labels.reserve(options.size());
|
||||||
@@ -78,7 +72,7 @@ namespace anm2ed::imgui
|
|||||||
return labels;
|
return labels;
|
||||||
}
|
}
|
||||||
|
|
||||||
int overlay_animation_option_index_get(const Document& document, const std::vector<OverlayAnimationOption>& options)
|
static int overlay_animation_option_index_get(const Document& document, const std::vector<OverlayAnimationOption>& options)
|
||||||
{
|
{
|
||||||
if (document.overlayIndex == -1) return 0;
|
if (document.overlayIndex == -1) return 0;
|
||||||
auto documentId = document.overlayDocumentId ? document.overlayDocumentId : document.tabId;
|
auto documentId = document.overlayDocumentId ? document.overlayDocumentId : document.tabId;
|
||||||
@@ -87,7 +81,7 @@ namespace anm2ed::imgui
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Document* overlay_animation_document_get(Manager& manager, const Document& document)
|
static Document* overlay_animation_document_get(Manager& manager, const Document& document)
|
||||||
{
|
{
|
||||||
if (document.overlayIndex == -1) return nullptr;
|
if (document.overlayIndex == -1) return nullptr;
|
||||||
auto documentId = document.overlayDocumentId ? document.overlayDocumentId : document.tabId;
|
auto documentId = document.overlayDocumentId ? document.overlayDocumentId : document.tabId;
|
||||||
@@ -96,7 +90,7 @@ namespace anm2ed::imgui
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<vec4> animation_rects_merge(std::optional<vec4> rect, vec4 next)
|
static std::optional<vec4> animation_rects_merge(std::optional<vec4> rect, vec4 next)
|
||||||
{
|
{
|
||||||
if (next == vec4(-1.0f)) return rect;
|
if (next == vec4(-1.0f)) return rect;
|
||||||
if (!rect) return next;
|
if (!rect) return next;
|
||||||
@@ -106,19 +100,19 @@ namespace anm2ed::imgui
|
|||||||
return vec4(minPoint, maxPoint - minPoint);
|
return vec4(minPoint, maxPoint - minPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<vec4> animation_render_rect_get(Manager& manager, Document& document, const model::Animation* animation,
|
static std::optional<vec4> animation_render_rect_get(Manager& manager, Document& document, const Animation* animation,
|
||||||
bool isRootTransform)
|
bool isRootTransform)
|
||||||
{
|
{
|
||||||
std::optional<vec4> rect{};
|
std::optional<vec4> rect{};
|
||||||
|
|
||||||
if (animation)
|
if (animation)
|
||||||
rect = animation_rects_merge(
|
rect = animation_rects_merge(
|
||||||
rect, model::animation_rect(document.model, *animation, isRootTransform, document.library_resolver_get()));
|
rect, animation_rect(document.model, *animation, isRootTransform, document.library_resolver_get()));
|
||||||
|
|
||||||
if (auto overlayDocument = overlay_animation_document_get(manager, document))
|
if (auto overlayDocument = overlay_animation_document_get(manager, document))
|
||||||
if (auto overlayAnimation = overlayDocument->model.animation_get(document.overlayIndex))
|
if (auto overlayAnimation = overlayDocument->model.animation_get(document.overlayIndex))
|
||||||
rect = animation_rects_merge(rect,
|
rect = animation_rects_merge(rect,
|
||||||
model::animation_rect(overlayDocument->model, *overlayAnimation, isRootTransform,
|
animation_rect(overlayDocument->model, *overlayAnimation, isRootTransform,
|
||||||
overlayDocument->library_resolver_get()));
|
overlayDocument->library_resolver_get()));
|
||||||
|
|
||||||
return rect;
|
return rect;
|
||||||
@@ -134,7 +128,7 @@ namespace anm2ed::imgui
|
|||||||
auto stop_all_sounds = [&]()
|
auto stop_all_sounds = [&]()
|
||||||
{
|
{
|
||||||
for (auto sound : document.sounds_get())
|
for (auto sound : document.sounds_get())
|
||||||
audio::stop(*sound, mixer);
|
audio_stop(*sound, mixer);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (manager.isRecording)
|
if (manager.isRecording)
|
||||||
@@ -163,7 +157,7 @@ namespace anm2ed::imgui
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto fps = std::max(model.info.fps, 1);
|
auto fps = std::max(model.info.fps, 1);
|
||||||
auto range = model::animation_play_range_get(*animation);
|
auto range = animation_play_range_get(*animation);
|
||||||
if (!wasPlaybackPlaying) soundFrame = (int)std::floor(playback.time) - 1;
|
if (!wasPlaybackPlaying) soundFrame = (int)std::floor(playback.time) - 1;
|
||||||
playback.tick(fps, range.x, range.y, (animation->isLoop || settings.playbackIsLoop) && !manager.isRecording,
|
playback.tick(fps, range.x, range.y, (animation->isLoop || settings.playbackIsLoop) && !manager.isRecording,
|
||||||
deltaSeconds);
|
deltaSeconds);
|
||||||
@@ -175,7 +169,7 @@ namespace anm2ed::imgui
|
|||||||
soundFrame = soundFrame + 1 >= range.y || soundFrame + 1 < range.x ? range.x : soundFrame + 1;
|
soundFrame = soundFrame + 1 >= range.y || soundFrame + 1 < range.x ? range.x : soundFrame + 1;
|
||||||
if (manager.isRecording || !isSound) continue;
|
if (manager.isRecording || !isSound) continue;
|
||||||
for (auto sound : document.trigger_sounds_get(*animation, soundFrame))
|
for (auto sound : document.trigger_sounds_get(*animation, soundFrame))
|
||||||
audio::play(*sound, false, mixer);
|
audio_play(*sound, false, mixer);
|
||||||
}
|
}
|
||||||
|
|
||||||
frameTime = playback.time;
|
frameTime = playback.time;
|
||||||
@@ -197,18 +191,18 @@ namespace anm2ed::imgui
|
|||||||
|
|
||||||
// Starts a render from the render settings; a bounded render frames the animation (and overlay) at the render scale.
|
// Starts a render from the render settings; a bounded render frames the animation (and overlay) at the render scale.
|
||||||
void AnimationPreview::recording_start(Manager& manager, Settings& settings, Document& document,
|
void AnimationPreview::recording_start(Manager& manager, Settings& settings, Document& document,
|
||||||
const model::Animation* animation)
|
const Animation* animation)
|
||||||
{
|
{
|
||||||
auto animationFps = std::max(document.model.info.fps, 1);
|
auto animationFps = std::max(document.model.info.fps, 1);
|
||||||
render::RecorderOptions options{
|
RecorderOptions options{
|
||||||
.type = (render::Type)settings.renderType,
|
.type = (RenderType)settings.renderType,
|
||||||
.path = settings.renderPath,
|
.path = settings.renderPath,
|
||||||
.format = settings.renderFormat,
|
.format = settings.renderFormat,
|
||||||
.ffmpegPath = settings.renderFFmpegPath,
|
.ffmpegPath = settings.renderFFmpegPath,
|
||||||
.start = manager.recordingStart,
|
.start = manager.recordingStart,
|
||||||
.end = manager.recordingEnd,
|
.end = manager.recordingEnd,
|
||||||
.animationFps = animationFps,
|
.animationFps = animationFps,
|
||||||
.fps = render::fps_get(settings.renderFpsMode, animationFps, settings.playbackTickRate),
|
.fps = fps_get(settings.renderFpsMode, animationFps, settings.playbackTickRate),
|
||||||
.rows = settings.renderRows,
|
.rows = settings.renderRows,
|
||||||
.columns = settings.renderColumns,
|
.columns = settings.renderColumns,
|
||||||
.isSound = settings.timelineIsSound,
|
.isSound = settings.timelineIsSound,
|
||||||
@@ -221,7 +215,7 @@ namespace anm2ed::imgui
|
|||||||
recordPan = document.previewPan;
|
recordPan = document.previewPan;
|
||||||
if (auto rect = animation_render_rect_get(manager, document, animation, settings.previewIsRootTransform))
|
if (auto rect = animation_render_rect_get(manager, document, animation, settings.previewIsRootTransform))
|
||||||
{
|
{
|
||||||
recordSize = glm::vec2(rect->z, rect->w) * math::percent_to_unit(settings.renderScale);
|
recordSize = glm::vec2(rect->z, rect->w) * percent_to_unit(settings.renderScale);
|
||||||
auto previousSize = size;
|
auto previousSize = size;
|
||||||
size = recordSize;
|
size = recordSize;
|
||||||
set_to_rect(recordZoom, recordPan, *rect);
|
set_to_rect(recordZoom, recordPan, *rect);
|
||||||
@@ -233,7 +227,7 @@ namespace anm2ed::imgui
|
|||||||
manager.isRecording = true;
|
manager.isRecording = true;
|
||||||
if (!recorder.start(options))
|
if (!recorder.start(options))
|
||||||
{
|
{
|
||||||
toast_log(Level::ERROR, TOAST_EXPORT_RENDERED_ANIMATION_FAILED, path::to_utf8(options.path));
|
toast_log(Level::ERROR, TOAST_EXPORT_RENDERED_ANIMATION_FAILED, path_to_utf8(options.path));
|
||||||
return recording_stop(manager, document);
|
return recording_stop(manager, document);
|
||||||
}
|
}
|
||||||
document.playback.isPlaying = true;
|
document.playback.isPlaying = true;
|
||||||
@@ -271,19 +265,19 @@ namespace anm2ed::imgui
|
|||||||
auto& isBorder = settings.previewIsBorder;
|
auto& isBorder = settings.previewIsBorder;
|
||||||
auto& tool = settings.tool;
|
auto& tool = settings.tool;
|
||||||
auto& isOnlyShowLayers = settings.timelineIsOnlyShowLayers;
|
auto& isOnlyShowLayers = settings.timelineIsOnlyShowLayers;
|
||||||
auto& shaderLine = resources.shaders[shader::LINE];
|
auto& shaderLine = resources.shaders[SHADER_LINE];
|
||||||
bool isLightTheme = settings.theme == theme::LIGHT;
|
bool isLightTheme = settings.theme == THEME_LIGHT;
|
||||||
auto& shaderAxes = resources.shaders[shader::AXIS];
|
auto& shaderAxes = resources.shaders[SHADER_AXIS];
|
||||||
auto& shaderGrid = resources.shaders[shader::GRID];
|
auto& shaderGrid = resources.shaders[SHADER_GRID];
|
||||||
auto& shaderTexture = resources.shaders[shader::TEXTURE];
|
auto& shaderTexture = resources.shaders[SHADER_TEXTURE];
|
||||||
auto& shaderDashed = resources.shaders[shader::DASHED];
|
auto& shaderDashed = resources.shaders[SHADER_DASHED];
|
||||||
auto center_view = [&]() { pan = vec2(); };
|
auto center_view = [&]() { pan = vec2(); };
|
||||||
|
|
||||||
auto fit_view = [&]()
|
auto fit_view = [&]()
|
||||||
{
|
{
|
||||||
if (animation)
|
if (animation)
|
||||||
set_to_rect(zoom, pan,
|
set_to_rect(zoom, pan,
|
||||||
model::animation_rect(model, *animation, isRootTransform, document.library_resolver_get()));
|
animation_rect(model, *animation, isRootTransform, document.library_resolver_get()));
|
||||||
};
|
};
|
||||||
|
|
||||||
manager.isAbleToRecord = false;
|
manager.isAbleToRecord = false;
|
||||||
@@ -367,7 +361,7 @@ namespace anm2ed::imgui
|
|||||||
}
|
}
|
||||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_OVERLAY));
|
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_OVERLAY));
|
||||||
|
|
||||||
overlayDrawOrder = glm::clamp(overlayDrawOrder, (int)overlay_draw_order::OVER, (int)overlay_draw_order::UNDER);
|
overlayDrawOrder = glm::clamp(overlayDrawOrder, (int)OVERLAY_OVER, (int)OVERLAY_UNDER);
|
||||||
overlayTransparency = glm::clamp(overlayTransparency, 0.0f, 100.0f);
|
overlayTransparency = glm::clamp(overlayTransparency, 0.0f, 100.0f);
|
||||||
auto orderIconSize = icon_size_get();
|
auto orderIconSize = icon_size_get();
|
||||||
auto orderButtonWidth = orderIconSize.x + ImGui::GetStyle().FramePadding.x * 2.0f;
|
auto orderButtonWidth = orderIconSize.x + ImGui::GetStyle().FramePadding.x * 2.0f;
|
||||||
@@ -382,13 +376,13 @@ namespace anm2ed::imgui
|
|||||||
overlayTransparency = glm::clamp(overlayTransparency, 0.0f, 100.0f);
|
overlayTransparency = glm::clamp(overlayTransparency, 0.0f, 100.0f);
|
||||||
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
radio_button_icon("##Overlay Over", &overlayDrawOrder, overlay_draw_order::OVER,
|
radio_button_icon("##Overlay Over", &overlayDrawOrder, OVERLAY_OVER,
|
||||||
resources.icon_id_get(icon::OVER), orderIconSize, overlayIconTint);
|
resources.icon_id_get(ICON_OVER), orderIconSize, overlayIconTint);
|
||||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_OVERLAY_OVER));
|
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_OVERLAY_OVER));
|
||||||
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
radio_button_icon("##Overlay Under", &overlayDrawOrder, overlay_draw_order::UNDER,
|
radio_button_icon("##Overlay Under", &overlayDrawOrder, OVERLAY_UNDER,
|
||||||
resources.icon_id_get(icon::UNDER), orderIconSize, overlayIconTint);
|
resources.icon_id_get(ICON_UNDER), orderIconSize, overlayIconTint);
|
||||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_OVERLAY_UNDER));
|
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_OVERLAY_UNDER));
|
||||||
}
|
}
|
||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
@@ -476,17 +470,17 @@ namespace anm2ed::imgui
|
|||||||
|
|
||||||
auto frame = selectedFrameReferences.empty() ? nullptr : model.frame_get(editReference);
|
auto frame = selectedFrameReferences.empty() ? nullptr : model.frame_get(editReference);
|
||||||
auto selectedNull =
|
auto selectedNull =
|
||||||
editReference.itemType == NULL_ ? model::item_get(model.content.nulls, editReference.itemID) : nullptr;
|
editReference.itemType == NULL_ ? item_get(model.content.nulls, editReference.itemID) : nullptr;
|
||||||
bool isSelectedNullRect = selectedNull && selectedNull->isShowRect;
|
bool isSelectedNullRect = selectedNull && selectedNull->isShowRect;
|
||||||
auto null_rect_top_left = [](const model::Frame& frame) { return frame.position - (frame.scale * 0.5f); };
|
auto null_rect_top_left = [](const Frame& frame) { return frame.position - (frame.scale * 0.5f); };
|
||||||
|
|
||||||
auto useTool = (tool::Type)tool;
|
auto useTool = (Tool)tool;
|
||||||
if (input.isMiddleDown) useTool = tool::PAN;
|
if (input.isMiddleDown) useTool = TOOL_PAN;
|
||||||
if (tool == tool::MOVE && input.isRightDown) useTool = tool::SCALE;
|
if (tool == TOOL_MOVE && input.isRightDown) useTool = TOOL_SCALE;
|
||||||
if (tool == tool::SCALE && input.isRightDown) useTool = tool::MOVE;
|
if (tool == TOOL_SCALE && input.isRightDown) useTool = TOOL_MOVE;
|
||||||
|
|
||||||
// A tool swapped in by the right button is driven by the right button.
|
// A tool swapped in by the right button is driven by the right button.
|
||||||
auto isSwapped = useTool != tool && useTool != tool::PAN;
|
auto isSwapped = useTool != tool && useTool != TOOL_PAN;
|
||||||
auto isToolClicked = isSwapped ? input.isRightClicked : input.isLeftClicked;
|
auto isToolClicked = isSwapped ? input.isRightClicked : input.isLeftClicked;
|
||||||
auto isToolDown = isSwapped ? input.isRightDown : input.isLeftDown;
|
auto isToolDown = isSwapped ? input.isRightDown : input.isLeftDown;
|
||||||
auto isToolReleased = isSwapped ? input.isRightReleased : input.isLeftReleased;
|
auto isToolReleased = isSwapped ? input.isRightReleased : input.isLeftReleased;
|
||||||
@@ -508,14 +502,14 @@ namespace anm2ed::imgui
|
|||||||
.scaleY = rectSize.y - frame->scale.y});
|
.scaleY = rectSize.y - frame->scale.y});
|
||||||
};
|
};
|
||||||
|
|
||||||
tool_cursor_update(useTool, tool::ANIMATION_PREVIEW, frame != nullptr, true,
|
tool_cursor_update(useTool, TOOL_AREA_ANIMATION_PREVIEW, frame != nullptr, true,
|
||||||
input.isLeftDown || input.isRightDown || input.isMiddleDown || input.isArrowDown,
|
input.isLeftDown || input.isRightDown || input.isMiddleDown || input.isArrowDown,
|
||||||
TEXT_SELECT_FRAME);
|
TEXT_SELECT_FRAME);
|
||||||
if (useTool != tool::MOVE) isMoveDragging = false;
|
if (useTool != TOOL_MOVE) isMoveDragging = false;
|
||||||
if (useTool == tool::PAN && (input.isLeftDown || input.isRightDown || input.isMiddleDown))
|
if (useTool == TOOL_PAN && (input.isLeftDown || input.isRightDown || input.isMiddleDown))
|
||||||
pan += input.mouseDelta;
|
pan += input.mouseDelta;
|
||||||
|
|
||||||
if (frame && useTool == tool::MOVE)
|
if (frame && useTool == TOOL_MOVE)
|
||||||
{
|
{
|
||||||
if (isBegin) edit_begin_push(manager, EDIT_FRAME_POSITION);
|
if (isBegin) edit_begin_push(manager, EDIT_FRAME_POSITION);
|
||||||
if (isToolClicked)
|
if (isToolClicked)
|
||||||
@@ -535,7 +529,7 @@ namespace anm2ed::imgui
|
|||||||
if (isEnd) document_change_push(manager);
|
if (isEnd) document_change_push(manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (frame && useTool == tool::SCALE)
|
if (frame && useTool == TOOL_SCALE)
|
||||||
{
|
{
|
||||||
if (isBegin) edit_begin_push(manager, EDIT_FRAME_SCALE);
|
if (isBegin) edit_begin_push(manager, EDIT_FRAME_SCALE);
|
||||||
if (isToolClicked && isSelectedNullRect) nullRectScaleAnchor = null_rect_top_left(*frame);
|
if (isToolClicked && isSelectedNullRect) nullRectScaleAnchor = null_rect_top_left(*frame);
|
||||||
@@ -569,7 +563,7 @@ namespace anm2ed::imgui
|
|||||||
if (isEnd) document_change_push(manager);
|
if (isEnd) document_change_push(manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (frame && useTool == tool::ROTATE)
|
if (frame && useTool == TOOL_ROTATE)
|
||||||
{
|
{
|
||||||
if (isBegin) edit_begin_push(manager, EDIT_FRAME_ROTATION);
|
if (isBegin) edit_begin_push(manager, EDIT_FRAME_ROTATION);
|
||||||
if (isToolDown) frames_change({.rotation = input.mouseDelta.x});
|
if (isToolDown) frames_change({.rotation = input.mouseDelta.x});
|
||||||
@@ -579,7 +573,7 @@ namespace anm2ed::imgui
|
|||||||
if (isEnd) document_change_push(manager);
|
if (isEnd) document_change_push(manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (frame && useTool == tool::SKEW)
|
if (frame && useTool == TOOL_SKEW)
|
||||||
{
|
{
|
||||||
if (isBegin) edit_begin_push(manager, EDIT_FRAME_SKEW);
|
if (isBegin) edit_begin_push(manager, EDIT_FRAME_SKEW);
|
||||||
if (isToolDown)
|
if (isToolDown)
|
||||||
@@ -608,7 +602,7 @@ namespace anm2ed::imgui
|
|||||||
auto baseTransform = transform_get(viewZoom, viewPan);
|
auto baseTransform = transform_get(viewZoom, viewPan);
|
||||||
auto frameTime = document.frameTime > -1 && !playback.isPlaying ? document.frameTime : playback.time;
|
auto frameTime = document.frameTime > -1 && !playback.isPlaying ? document.frameTime : playback.time;
|
||||||
|
|
||||||
model::DrawOptions drawOptions{.time = frameTime,
|
DrawOptions drawOptions{.time = frameTime,
|
||||||
.isRootTransform = isRootTransform,
|
.isRootTransform = isRootTransform,
|
||||||
.isIndexSampled = settings.onionskinMode == (int)OnionskinMode::INDEX};
|
.isIndexSampled = settings.onionskinMode == (int)OnionskinMode::INDEX};
|
||||||
std::vector<vec3> sampleColors{};
|
std::vector<vec3> sampleColors{};
|
||||||
@@ -641,16 +635,16 @@ namespace anm2ed::imgui
|
|||||||
};
|
};
|
||||||
|
|
||||||
// The item the reference points at: the root (or a group's root), a layer or a null.
|
// The item the reference points at: the root (or a group's root), a layer or a null.
|
||||||
auto is_draw_selected = [&](const model::Draw& draw)
|
auto is_draw_selected = [&](const Draw& draw)
|
||||||
{
|
{
|
||||||
switch (draw.type)
|
switch (draw.type)
|
||||||
{
|
{
|
||||||
case model::DrawType::ROOT:
|
case DrawType::ROOT:
|
||||||
return referenceItemType == ItemType::ROOT && reference.groupId == -1;
|
return referenceItemType == ItemType::ROOT && reference.groupId == -1;
|
||||||
case model::DrawType::GROUP_ROOT:
|
case DrawType::GROUP_ROOT:
|
||||||
return referenceItemType == ItemType::ROOT && reference.groupType == draw.groupType &&
|
return referenceItemType == ItemType::ROOT && reference.groupType == draw.groupType &&
|
||||||
reference.groupId == draw.id;
|
reference.groupId == draw.id;
|
||||||
case model::DrawType::LAYER:
|
case DrawType::LAYER:
|
||||||
return referenceItemType == ItemType::LAYER && reference.itemID == draw.id;
|
return referenceItemType == ItemType::LAYER && reference.itemID == draw.id;
|
||||||
default:
|
default:
|
||||||
return referenceItemType == ItemType::NULL_ && reference.itemID == draw.id;
|
return referenceItemType == ItemType::NULL_ && reference.itemID == draw.id;
|
||||||
@@ -661,18 +655,18 @@ namespace anm2ed::imgui
|
|||||||
// Draws an animation's draw list; onion-skin samples are tinted and faded, `alphaOffset` fades the overlay. A
|
// Draws an animation's draw list; onion-skin samples are tinted and faded, `alphaOffset` fades the overlay. A
|
||||||
// parent around a stepped-into child is drawn in the child's space (`scene`), its layers only, without the
|
// parent around a stepped-into child is drawn in the child's space (`scene`), its layers only, without the
|
||||||
// animation layer playing the child (`skipLayerId`).
|
// animation layer playing the child (`skipLayerId`).
|
||||||
auto render = [&](Document& sampleDocument, const model::Animation& sampleAnimation, float alphaOffset,
|
auto render = [&](Document& sampleDocument, const Animation& sampleAnimation, float alphaOffset,
|
||||||
const model::DrawOptions& options, const mat4& scene = mat4(1.0f), int skipLayerId = -1)
|
const DrawOptions& options, const mat4& scene = mat4(1.0f), int skipLayerId = -1)
|
||||||
{
|
{
|
||||||
auto isActiveDocument = &sampleDocument == &document && skipLayerId == -1;
|
auto isActiveDocument = &sampleDocument == &document && skipLayerId == -1;
|
||||||
auto isParent = skipLayerId != -1;
|
auto isParent = skipLayerId != -1;
|
||||||
auto& sampleModel = sampleDocument.model;
|
auto& sampleModel = sampleDocument.model;
|
||||||
auto targetIcon = resources.icon_id_get(isAltIcons && !isIsolated ? icon::TARGET_ALT : icon::TARGET);
|
auto targetIcon = resources.icon_id_get(isAltIcons && !isIsolated ? ICON_TARGET_ALT : ICON_TARGET);
|
||||||
auto sampleOptions = options;
|
auto sampleOptions = options;
|
||||||
sampleOptions.library_get = sampleDocument.library_resolver_get();
|
sampleOptions.library_get = sampleDocument.library_resolver_get();
|
||||||
for (const auto& draw : model::animation_draws_get(sampleModel, sampleAnimation, sampleOptions))
|
for (const auto& draw : animation_draws_get(sampleModel, sampleAnimation, sampleOptions))
|
||||||
{
|
{
|
||||||
if (isParent && (draw.type != model::DrawType::LAYER || draw.id == skipLayerId)) continue;
|
if (isParent && (draw.type != DrawType::LAYER || draw.id == skipLayerId)) continue;
|
||||||
auto isOnion = draw.sample != -1;
|
auto isOnion = draw.sample != -1;
|
||||||
if (isOnion && isOnlySelected && !(isActiveDocument && is_draw_selected(draw))) continue;
|
if (isOnion && isOnlySelected && !(isActiveDocument && is_draw_selected(draw))) continue;
|
||||||
auto sampleColor = isOnion ? sampleColors[draw.sample] : vec3();
|
auto sampleColor = isOnion ? sampleColors[draw.sample] : vec3();
|
||||||
@@ -682,60 +676,60 @@ namespace anm2ed::imgui
|
|||||||
auto transform = baseTransform * scene * draw.parent;
|
auto transform = baseTransform * scene * draw.parent;
|
||||||
auto marker_model_get = [&](vec2 markerSize)
|
auto marker_model_get = [&](vec2 markerSize)
|
||||||
{
|
{
|
||||||
return math::quad_model_get(markerSize, frame.position, markerSize * 0.5f,
|
return quad_model_get(markerSize, frame.position, markerSize * 0.5f,
|
||||||
math::percent_to_unit(frame.scale), frame.rotation,
|
percent_to_unit(frame.scale), frame.rotation,
|
||||||
math::percent_to_unit(frame.skew));
|
percent_to_unit(frame.skew));
|
||||||
};
|
};
|
||||||
|
|
||||||
if (draw.type == model::DrawType::ROOT || draw.type == model::DrawType::GROUP_ROOT)
|
if (draw.type == DrawType::ROOT || draw.type == DrawType::GROUP_ROOT)
|
||||||
{
|
{
|
||||||
if (isViewOnlyLayers) continue;
|
if (isViewOnlyLayers) continue;
|
||||||
auto isSelected = isActiveDocument && draw.type == model::DrawType::GROUP_ROOT &&
|
auto isSelected = isActiveDocument && draw.type == DrawType::GROUP_ROOT &&
|
||||||
referenceItemType == ItemType::ROOT && reference.groupType == draw.groupType &&
|
referenceItemType == ItemType::ROOT && reference.groupType == draw.groupType &&
|
||||||
reference.groupId == draw.id;
|
reference.groupId == draw.id;
|
||||||
auto color = isOnion ? vec4(sampleColor, sampleAlpha)
|
auto color = isOnion ? vec4(sampleColor, sampleAlpha)
|
||||||
: draw.type == model::DrawType::ROOT ? color::GREEN
|
: draw.type == DrawType::ROOT ? COLOR_GREEN
|
||||||
: isSelected ? color::RED
|
: isSelected ? COLOR_RED
|
||||||
: ROOT_COLOR;
|
: ROOT_COLOR;
|
||||||
auto markerModel = isRootTransform ? math::quad_model_get(TARGET_SIZE, {}, TARGET_SIZE * 0.5f)
|
auto markerModel = isRootTransform ? quad_model_get(TARGET_SIZE, {}, TARGET_SIZE * 0.5f)
|
||||||
: marker_model_get(TARGET_SIZE);
|
: marker_model_get(TARGET_SIZE);
|
||||||
texture_render(shaderTexture, targetIcon, transform * markerModel, color);
|
texture_render(shaderTexture, targetIcon, transform * markerModel, color);
|
||||||
}
|
}
|
||||||
else if (draw.type == model::DrawType::LAYER)
|
else if (draw.type == DrawType::LAYER)
|
||||||
{
|
{
|
||||||
auto layerTexture =
|
auto layerTexture =
|
||||||
sampleDocument.draw_image_get(draw, math::percent_to_unit(viewZoom) * model::draw_scale_get(draw));
|
sampleDocument.draw_image_get(draw, percent_to_unit(viewZoom) * draw_scale_get(draw));
|
||||||
if (!layerTexture || !layerTexture->is_valid() || layerTexture->size.x <= 0 || layerTexture->size.y <= 0)
|
if (!layerTexture || !layerTexture->is_valid() || layerTexture->size.x <= 0 || layerTexture->size.y <= 0)
|
||||||
continue;
|
continue;
|
||||||
auto textureSize = layerTexture->unit_size_get();
|
auto textureSize = layerTexture->unit_size_get();
|
||||||
auto layerModel = model::draw_quad_model_get(draw);
|
auto layerModel = draw_quad_model_get(draw);
|
||||||
auto layerTransform = transform * layerModel;
|
auto layerTransform = transform * layerModel;
|
||||||
auto tint = frame.tint;
|
auto tint = frame.tint;
|
||||||
tint.a = std::max(0.0f, tint.a - (alphaOffset + sampleAlpha));
|
tint.a = std::max(0.0f, tint.a - (alphaOffset + sampleAlpha));
|
||||||
auto customShader = sampleDocument.shader_get(frame.shaderId);
|
auto customShader = sampleDocument.shader_get(frame.shaderId);
|
||||||
layer_render(customShader ? *customShader : shaderTexture, resource::texture::id_get(*layerTexture),
|
layer_render(customShader ? *customShader : shaderTexture, texture_id_get(*layerTexture),
|
||||||
textureSize, baseTransform * scene, draw, tint, frame.colorOffset + vec4(sampleColor, 0.0f));
|
textureSize, baseTransform * scene, draw, tint, frame.colorOffset + vec4(sampleColor, 0.0f));
|
||||||
if (isParent) continue;
|
if (isParent) continue;
|
||||||
|
|
||||||
auto color = isOnion ? onionColor
|
auto color = isOnion ? onionColor
|
||||||
: isActiveDocument && is_layer_selected(draw.id) ? SELECTED_LAYER_BORDER_COLOR
|
: isActiveDocument && is_layer_selected(draw.id) ? SELECTED_LAYER_BORDER_COLOR
|
||||||
: color::RED;
|
: COLOR_RED;
|
||||||
if (isBorder && !isIsolated) rect_render(shaderLine, layerTransform, layerModel, color);
|
if (isBorder && !isIsolated) rect_render(shaderLine, layerTransform, layerModel, color);
|
||||||
if (isPivots && !isIsolated)
|
if (isPivots && !isIsolated)
|
||||||
texture_render(shaderTexture, resources.icon_id_get(icon::PIVOT),
|
texture_render(shaderTexture, resources.icon_id_get(ICON_PIVOT),
|
||||||
transform * marker_model_get(PIVOT_SIZE), color);
|
transform * marker_model_get(PIVOT_SIZE), color);
|
||||||
}
|
}
|
||||||
else if (!isViewOnlyLayers)
|
else if (!isViewOnlyLayers)
|
||||||
{
|
{
|
||||||
auto isShowRect = model::item_get(sampleModel.content.nulls, draw.id)->isShowRect;
|
auto isShowRect = item_get(sampleModel.content.nulls, draw.id)->isShowRect;
|
||||||
auto isSelected = isActiveDocument && draw.id == reference.itemID && referenceItemType == ItemType::NULL_;
|
auto isSelected = isActiveDocument && draw.id == reference.itemID && referenceItemType == ItemType::NULL_;
|
||||||
auto color = isOnion ? onionColor : isSelected ? color::RED : NULL_RECT_COLOR;
|
auto color = isOnion ? onionColor : isSelected ? COLOR_RED : NULL_RECT_COLOR;
|
||||||
auto markerSize = isShowRect ? POINT_SIZE : TARGET_SIZE;
|
auto markerSize = isShowRect ? POINT_SIZE : TARGET_SIZE;
|
||||||
texture_render(shaderTexture, isShowRect ? resources.icon_id_get(icon::POINT) : targetIcon,
|
texture_render(shaderTexture, isShowRect ? resources.icon_id_get(ICON_POINT) : targetIcon,
|
||||||
transform * marker_model_get(markerSize), color);
|
transform * marker_model_get(markerSize), color);
|
||||||
if (!isShowRect) continue;
|
if (!isShowRect) continue;
|
||||||
auto rectModel = math::quad_model_get(frame.scale, frame.position, frame.scale * 0.5f, vec2(1.0f),
|
auto rectModel = quad_model_get(frame.scale, frame.position, frame.scale * 0.5f, vec2(1.0f),
|
||||||
frame.rotation, math::percent_to_unit(frame.skew));
|
frame.rotation, percent_to_unit(frame.skew));
|
||||||
rect_render(shaderLine, transform * rectModel, rectModel, color);
|
rect_render(shaderLine, transform * rectModel, rectModel, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -747,7 +741,7 @@ namespace anm2ed::imgui
|
|||||||
{
|
{
|
||||||
if (auto overlayDocument = isIsolated ? nullptr : overlay_animation_document_get(manager, document))
|
if (auto overlayDocument = isIsolated ? nullptr : overlay_animation_document_get(manager, document))
|
||||||
if (auto overlayAnimation = overlayDocument->model.animation_get(overlayIndex))
|
if (auto overlayAnimation = overlayDocument->model.animation_get(overlayIndex))
|
||||||
render(*overlayDocument, *overlayAnimation, 1.0f - math::percent_to_unit(overlayTransparency),
|
render(*overlayDocument, *overlayAnimation, 1.0f - percent_to_unit(overlayTransparency),
|
||||||
drawOptions);
|
drawOptions);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -759,7 +753,7 @@ namespace anm2ed::imgui
|
|||||||
auto parentIndex = manager.tab_index_get(step.tabId);
|
auto parentIndex = manager.tab_index_get(step.tabId);
|
||||||
auto parentDocument = parentIndex == -1 ? nullptr : manager.get(parentIndex);
|
auto parentDocument = parentIndex == -1 ? nullptr : manager.get(parentIndex);
|
||||||
auto parentAnimation = parentDocument ? parentDocument->model.animation_get(step.animationIndex) : nullptr;
|
auto parentAnimation = parentDocument ? parentDocument->model.animation_get(step.animationIndex) : nullptr;
|
||||||
auto placement = parentAnimation ? model::layer_child_transform_get(*parentAnimation, step.layer.itemID,
|
auto placement = parentAnimation ? layer_child_transform_get(*parentAnimation, step.layer.itemID,
|
||||||
step.frameTime, isRootTransform)
|
step.frameTime, isRootTransform)
|
||||||
: std::nullopt;
|
: std::nullopt;
|
||||||
if (placement && glm::determinant(*placement) != 0.0f)
|
if (placement && glm::determinant(*placement) != 0.0f)
|
||||||
@@ -768,9 +762,9 @@ namespace anm2ed::imgui
|
|||||||
step.layer.itemID);
|
step.layer.itemID);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (overlayDrawOrder == overlay_draw_order::UNDER) overlay_render();
|
if (overlayDrawOrder == OVERLAY_UNDER) overlay_render();
|
||||||
render(document, *animation, 0.0f, drawOptions);
|
render(document, *animation, 0.0f, drawOptions);
|
||||||
if (overlayDrawOrder == overlay_draw_order::OVER) overlay_render();
|
if (overlayDrawOrder == OVERLAY_OVER) overlay_render();
|
||||||
|
|
||||||
if (settings.onionskinIsEnabled && settings.onionskinIsPivotPath && !isIsolated)
|
if (settings.onionskinIsEnabled && settings.onionskinIsPivotPath && !isIsolated)
|
||||||
{
|
{
|
||||||
@@ -780,7 +774,7 @@ namespace anm2ed::imgui
|
|||||||
pivotPathsKey = key;
|
pivotPathsKey = key;
|
||||||
pivotPaths.clear();
|
pivotPaths.clear();
|
||||||
for (int time = 0; time < animation->frameNum; ++time)
|
for (int time = 0; time < animation->frameNum; ++time)
|
||||||
for (const auto& draw : model::animation_draws_get(model, *animation,
|
for (const auto& draw : animation_draws_get(model, *animation,
|
||||||
{.time = (float)time,
|
{.time = (float)time,
|
||||||
.isRootTransform = isRootTransform,
|
.isRootTransform = isRootTransform,
|
||||||
.library_get = document.library_resolver_get()}))
|
.library_get = document.library_resolver_get()}))
|
||||||
@@ -796,16 +790,16 @@ namespace anm2ed::imgui
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto pointIcon = resources.icon_id_get(icon::POINT);
|
auto pointIcon = resources.icon_id_get(ICON_POINT);
|
||||||
for (const auto& path : pivotPaths)
|
for (const auto& path : pivotPaths)
|
||||||
{
|
{
|
||||||
if (isOnlySelected && !is_draw_selected(path.item)) continue;
|
if (isOnlySelected && !is_draw_selected(path.item)) continue;
|
||||||
for (std::size_t i = 0; i < path.points.size(); ++i)
|
for (std::size_t i = 0; i < path.points.size(); ++i)
|
||||||
{
|
{
|
||||||
if (i > 0) line_render(shaderDashed, baseTransform, path.points[i - 1], path.points[i], color::RED);
|
if (i > 0) line_render(shaderDashed, baseTransform, path.points[i - 1], path.points[i], COLOR_RED);
|
||||||
texture_render(shaderTexture, pointIcon,
|
texture_render(shaderTexture, pointIcon,
|
||||||
baseTransform * math::quad_model_get(POINT_SIZE, path.points[i], POINT_SIZE * 0.5f),
|
baseTransform * quad_model_get(POINT_SIZE, path.points[i], POINT_SIZE * 0.5f),
|
||||||
color::RED);
|
COLOR_RED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -815,10 +809,10 @@ namespace anm2ed::imgui
|
|||||||
{
|
{
|
||||||
auto sounds = settings.timelineIsSound && animation && recorder.is_sound_frame()
|
auto sounds = settings.timelineIsSound && animation && recorder.is_sound_frame()
|
||||||
? document.trigger_sounds_get(*animation, (int)frameTime, recorder.index)
|
? document.trigger_sounds_get(*animation, (int)frameTime, recorder.index)
|
||||||
: std::vector<const resource::AudioData*>{};
|
: std::vector<const AudioData*>{};
|
||||||
if (!recorder.frame_capture(pixels_get(), size, sounds))
|
if (!recorder.frame_capture(pixels_get(), size, sounds))
|
||||||
{
|
{
|
||||||
toast_log(Level::ERROR, TOAST_EXPORT_RENDERED_ANIMATION_FAILED, path::to_utf8(recorder.options.path));
|
toast_log(Level::ERROR, TOAST_EXPORT_RENDERED_ANIMATION_FAILED, path_to_utf8(recorder.options.path));
|
||||||
recorder.cancel();
|
recorder.cancel();
|
||||||
recording_stop(manager, document);
|
recording_stop(manager, document);
|
||||||
}
|
}
|
||||||
@@ -837,9 +831,9 @@ namespace anm2ed::imgui
|
|||||||
std::string names{};
|
std::string names{};
|
||||||
if (animation && !isOnlyShowLayers && !manager.isRecording)
|
if (animation && !isOnlyShowLayers && !manager.isRecording)
|
||||||
for (const auto& [source, trigger, layerId] :
|
for (const auto& [source, trigger, layerId] :
|
||||||
model::animation_triggers_get(model, *animation, (int)frameTime, document.library_resolver_get()))
|
animation_triggers_get(model, *animation, (int)frameTime, document.library_resolver_get()))
|
||||||
for (auto eventId : trigger.eventIds)
|
for (auto eventId : trigger.eventIds)
|
||||||
if (auto event = model::item_get(source->content.events, eventId))
|
if (auto event = item_get(source->content.events, eventId))
|
||||||
names += (names.empty() ? "" : ", ") + event->name;
|
names += (names.empty() ? "" : ", ") + event->name;
|
||||||
if (!names.empty())
|
if (!names.empty())
|
||||||
{
|
{
|
||||||
@@ -849,7 +843,7 @@ namespace anm2ed::imgui
|
|||||||
auto textPos = to_imvec2(to_vec2(cursorScreenPos) + to_vec2(ImGui::GetStyle().WindowPadding));
|
auto textPos = to_imvec2(to_vec2(cursorScreenPos) + to_vec2(ImGui::GetStyle().WindowPadding));
|
||||||
|
|
||||||
drawList->PushClipRect(clipMin, clipMax);
|
drawList->PushClipRect(clipMin, clipMax);
|
||||||
ImGui::PushFont(resources.fonts[font::BOLD].get(), font::SIZE_LARGE);
|
ImGui::PushFont(resources.fonts[FONT_BOLD].get(), FONT_SIZE_LARGE);
|
||||||
auto triggerTextColor = isLightTheme ? TRIGGER_TEXT_COLOR_LIGHT : TRIGGER_TEXT_COLOR_DARK;
|
auto triggerTextColor = isLightTheme ? TRIGGER_TEXT_COLOR_LIGHT : TRIGGER_TEXT_COLOR_DARK;
|
||||||
drawList->AddText(textPos, ImGui::GetColorU32(triggerTextColor), names.c_str());
|
drawList->AddText(textPos, ImGui::GetColorU32(triggerTextColor), names.c_str());
|
||||||
ImGui::PopFont();
|
ImGui::PopFont();
|
||||||
@@ -857,7 +851,7 @@ namespace anm2ed::imgui
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tool == tool::PAN)
|
if (tool == TOOL_PAN)
|
||||||
view_context_menu_draw("##Animation Preview Context Menu", manager, settings, document, zoom, pan, center_view,
|
view_context_menu_draw("##Animation Preview Context Menu", manager, settings, document, zoom, pan, center_view,
|
||||||
fit_view, animation != nullptr);
|
fit_view, animation != nullptr);
|
||||||
|
|
||||||
@@ -889,4 +883,3 @@ namespace anm2ed::imgui
|
|||||||
settings.previewStartZoom = zoom;
|
settings.previewStartZoom = zoom;
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -11,8 +11,6 @@
|
|||||||
#include "resources.h"
|
#include "resources.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
namespace anm2ed::imgui
|
|
||||||
{
|
|
||||||
class AnimationPreview : public CanvasView
|
class AnimationPreview : public CanvasView
|
||||||
{
|
{
|
||||||
MIX_Mixer* mixer = MIX_CreateMixerDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, nullptr);
|
MIX_Mixer* mixer = MIX_CreateMixerDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, nullptr);
|
||||||
@@ -22,7 +20,7 @@ namespace anm2ed::imgui
|
|||||||
bool isMoveDragging{};
|
bool isMoveDragging{};
|
||||||
glm::vec2 moveOffset{};
|
glm::vec2 moveOffset{};
|
||||||
glm::vec2 nullRectScaleAnchor{};
|
glm::vec2 nullRectScaleAnchor{};
|
||||||
render::Recorder recorder{};
|
Recorder recorder{};
|
||||||
glm::vec2 recordSize{};
|
glm::vec2 recordSize{};
|
||||||
glm::vec2 recordPan{};
|
glm::vec2 recordPan{};
|
||||||
float recordZoom{};
|
float recordZoom{};
|
||||||
@@ -30,17 +28,16 @@ namespace anm2ed::imgui
|
|||||||
// Where each item's pivot is at every frame of the animation, kept until the document or view changes.
|
// Where each item's pivot is at every frame of the animation, kept until the document or view changes.
|
||||||
struct PivotPath
|
struct PivotPath
|
||||||
{
|
{
|
||||||
model::Draw item{};
|
Draw item{};
|
||||||
std::vector<glm::vec2> points{};
|
std::vector<glm::vec2> points{};
|
||||||
};
|
};
|
||||||
std::vector<PivotPath> pivotPaths{};
|
std::vector<PivotPath> pivotPaths{};
|
||||||
std::tuple<std::uint64_t, std::uint64_t, int, bool> pivotPathsKey{};
|
std::tuple<std::uint64_t, std::uint64_t, int, bool> pivotPathsKey{};
|
||||||
|
|
||||||
void recording_start(Manager&, Settings&, Document&, const model::Animation*);
|
void recording_start(Manager&, Settings&, Document&, const Animation*);
|
||||||
void recording_stop(Manager&, Document&);
|
void recording_stop(Manager&, Document&);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void tick(Manager&, Settings&, float);
|
void tick(Manager&, Settings&, float);
|
||||||
void update(Manager&, Settings&, Resources&);
|
void update(Manager&, Settings&, Resources&);
|
||||||
};
|
};
|
||||||
}
|
|
||||||
+72
-78
@@ -9,11 +9,6 @@
|
|||||||
#include "ui/shortcut.h"
|
#include "ui/shortcut.h"
|
||||||
#include "ui/tree.h"
|
#include "ui/tree.h"
|
||||||
|
|
||||||
using namespace anm2ed::resource;
|
|
||||||
using namespace anm2ed::types;
|
|
||||||
|
|
||||||
namespace anm2ed::imgui
|
|
||||||
{
|
|
||||||
constexpr const char* ANIMATION_DRAG_DROP = "Animation Drag Drop";
|
constexpr const char* ANIMATION_DRAG_DROP = "Animation Drag Drop";
|
||||||
constexpr float DROP_ZONE_FRACTION = 1.0f / 3.0f;
|
constexpr float DROP_ZONE_FRACTION = 1.0f / 3.0f;
|
||||||
constexpr int MERGE_OPTIONS_ROWS = 2;
|
constexpr int MERGE_OPTIONS_ROWS = 2;
|
||||||
@@ -45,68 +40,68 @@ namespace anm2ed::imgui
|
|||||||
{
|
{
|
||||||
std::set<int> selection{};
|
std::set<int> selection{};
|
||||||
int reference{-1};
|
int reference{-1};
|
||||||
merge::Type type{};
|
Merge type{};
|
||||||
bool isDeleteAnimationsAfter{};
|
bool isDeleteAnimationsAfter{};
|
||||||
};
|
};
|
||||||
|
|
||||||
// Calls back for each top-level entry: (animation index, animation) for loose animations, (index, group) for groups.
|
// Calls back for each top-level entry: (animation index, animation) for loose animations, (index, group) for groups.
|
||||||
template <class Callback> void animation_entries_each(const model::Model& model, Callback&& callback)
|
template <class Callback> static void animation_entries_each(const Model& model, Callback&& callback)
|
||||||
{
|
{
|
||||||
int index{};
|
int index{};
|
||||||
for (const auto& entry : model.animations.entries)
|
for (const auto& entry : model.animations.entries)
|
||||||
if (auto animation = std::get_if<std::shared_ptr<const model::Animation>>(&entry))
|
if (auto animation = std::get_if<std::shared_ptr<const Animation>>(&entry))
|
||||||
callback(index++, animation->get(), (const model::AnimationGroup*)nullptr);
|
callback(index++, animation->get(), (const AnimationGroup*)nullptr);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto& group = std::get<model::AnimationGroup>(entry);
|
auto& group = std::get<AnimationGroup>(entry);
|
||||||
callback(index, (const model::Animation*)nullptr, &group);
|
callback(index, (const Animation*)nullptr, &group);
|
||||||
index += (int)group.animations.size();
|
index += (int)group.animations.size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The flat index of a group's first animation.
|
// The flat index of a group's first animation.
|
||||||
int animation_group_first_index_get(const model::Model& model, int groupId)
|
static int animation_group_first_index_get(const Model& model, int groupId)
|
||||||
{
|
{
|
||||||
int first{-1};
|
int first{-1};
|
||||||
animation_entries_each(model,
|
animation_entries_each(model,
|
||||||
[&](int index, auto*, const model::AnimationGroup* group)
|
[&](int index, auto*, const AnimationGroup* group)
|
||||||
{
|
{
|
||||||
if (group && group->id == groupId) first = index;
|
if (group && group->id == groupId) first = index;
|
||||||
});
|
});
|
||||||
return first;
|
return first;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<int> animation_groups_selected_get(const Document& document)
|
static std::set<int> animation_groups_selected_get(const Document& document)
|
||||||
{
|
{
|
||||||
std::set<int> groupIds{};
|
std::set<int> groupIds{};
|
||||||
auto uids = document.selection.uids.find(SelectionKind::ANIMATION_GROUPS);
|
auto uids = document.selection.uids.find(SelectionKind::ANIMATION_GROUPS);
|
||||||
if (uids == document.selection.uids.end()) return groupIds;
|
if (uids == document.selection.uids.end()) return groupIds;
|
||||||
for (const auto& entry : document.model.animations.entries)
|
for (const auto& entry : document.model.animations.entries)
|
||||||
if (auto group = std::get_if<model::AnimationGroup>(&entry); group && uids->second.contains(group->uid))
|
if (auto group = std::get_if<AnimationGroup>(&entry); group && uids->second.contains(group->uid))
|
||||||
groupIds.insert(group->id);
|
groupIds.insert(group->id);
|
||||||
return groupIds;
|
return groupIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
void animations_selection_set(Document& document, const std::set<int>& indices, const std::set<int>& groupIds)
|
static void animations_selection_set(Document& document, const std::set<int>& indices, const std::set<int>& groupIds)
|
||||||
{
|
{
|
||||||
document.animations_selected_set(indices);
|
document.animations_selected_set(indices);
|
||||||
auto& groupUids = document.selection.uids[SelectionKind::ANIMATION_GROUPS];
|
auto& groupUids = document.selection.uids[SelectionKind::ANIMATION_GROUPS];
|
||||||
groupUids.clear();
|
groupUids.clear();
|
||||||
for (const auto& entry : document.model.animations.entries)
|
for (const auto& entry : document.model.animations.entries)
|
||||||
if (auto group = std::get_if<model::AnimationGroup>(&entry); group && groupIds.contains(group->id))
|
if (auto group = std::get_if<AnimationGroup>(&entry); group && groupIds.contains(group->id))
|
||||||
groupUids.insert(group->uid);
|
groupUids.insert(group->uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Selected animations plus every animation of a selected group.
|
// Selected animations plus every animation of a selected group.
|
||||||
std::set<int> animation_selected_indices_get(const Document& document)
|
static std::set<int> animation_selected_indices_get(const Document& document)
|
||||||
{
|
{
|
||||||
auto result = document.animations_selected_get();
|
auto result = document.animations_selected_get();
|
||||||
for (auto groupId : animation_groups_selected_get(document))
|
for (auto groupId : animation_groups_selected_get(document))
|
||||||
result.merge(edit::animation_group_indices_get(document.model, groupId));
|
result.merge(animation_group_indices_get(document.model, groupId));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<int> animation_groupable_indices_get(const Document& document)
|
static std::vector<int> animation_groupable_indices_get(const Document& document)
|
||||||
{
|
{
|
||||||
std::vector<int> result{};
|
std::vector<int> result{};
|
||||||
for (auto index : document.animations_selected_get())
|
for (auto index : document.animations_selected_get())
|
||||||
@@ -117,19 +112,19 @@ namespace anm2ed::imgui
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<int> animation_merge_indices_get(const Document& document, const std::set<int>& keys, int reference)
|
static std::set<int> animation_merge_indices_get(const Document& document, const std::set<int>& keys, int reference)
|
||||||
{
|
{
|
||||||
std::set<int> result{};
|
std::set<int> result{};
|
||||||
for (auto key : keys)
|
for (auto key : keys)
|
||||||
if (!is_group_key(key))
|
if (!is_group_key(key))
|
||||||
result.insert(key);
|
result.insert(key);
|
||||||
else
|
else
|
||||||
result.merge(edit::animation_group_indices_get(document.model, group_id_from_key_get(key)));
|
result.merge(animation_group_indices_get(document.model, group_id_from_key_get(key)));
|
||||||
result.erase(reference);
|
result.erase(reference);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void animation_overlay_reset(Document& document, const std::set<int>& indices)
|
static void animation_overlay_reset(Document& document, const std::set<int>& indices)
|
||||||
{
|
{
|
||||||
auto isOverlayDocument = document.overlayDocumentId == 0 || document.overlayDocumentId == document.tabId;
|
auto isOverlayDocument = document.overlayDocumentId == 0 || document.overlayDocumentId == document.tabId;
|
||||||
if (!isOverlayDocument || !indices.contains(document.overlayIndex)) return;
|
if (!isOverlayDocument || !indices.contains(document.overlayIndex)) return;
|
||||||
@@ -137,19 +132,19 @@ namespace anm2ed::imgui
|
|||||||
document.overlayDocumentId = 0;
|
document.overlayDocumentId = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void animations_erase(Document& document, const std::set<int>& indices, const std::set<int>& groupIds,
|
static void animations_erase(Document& document, const std::set<int>& indices, const std::set<int>& groupIds,
|
||||||
StringType label)
|
StringType label)
|
||||||
{
|
{
|
||||||
document.edit_apply(label,
|
document.edit_apply(label,
|
||||||
[&](model::Model& model)
|
[&](Model& model)
|
||||||
{
|
{
|
||||||
animation_overlay_reset(document, indices);
|
animation_overlay_reset(document, indices);
|
||||||
animations_selection_set(document, {}, {});
|
animations_selection_set(document, {}, {});
|
||||||
return edit::animations_remove(model, indices, groupIds);
|
return animations_remove(model, indices, groupIds);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<int> animation_indices_get(Document& document, const edit::Uids& uids)
|
static std::set<int> animation_indices_get(Document& document, const Uids& uids)
|
||||||
{
|
{
|
||||||
std::set<int> indices{};
|
std::set<int> indices{};
|
||||||
for (auto reference : document.references_get(uids))
|
for (auto reference : document.references_get(uids))
|
||||||
@@ -157,33 +152,33 @@ namespace anm2ed::imgui
|
|||||||
return indices;
|
return indices;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string animation_clipboard_text_get(const Document& document)
|
static std::string animation_clipboard_text_get(const Document& document)
|
||||||
{
|
{
|
||||||
std::string clipboardText{};
|
std::string clipboardText{};
|
||||||
auto& model = document.model;
|
auto& model = document.model;
|
||||||
auto groupIds = animation_groups_selected_get(document);
|
auto groupIds = animation_groups_selected_get(document);
|
||||||
auto selection = document.animations_selected_get();
|
auto selection = document.animations_selected_get();
|
||||||
for (const auto& entry : model.animations.entries)
|
for (const auto& entry : model.animations.entries)
|
||||||
if (auto group = std::get_if<model::AnimationGroup>(&entry); group && groupIds.contains(group->id))
|
if (auto group = std::get_if<AnimationGroup>(&entry); group && groupIds.contains(group->id))
|
||||||
clipboardText += model::animation_group_to_string(*group);
|
clipboardText += animation_group_to_string(*group);
|
||||||
for (int i = 0; i < model.animations_count_get(); ++i)
|
for (int i = 0; i < model.animations_count_get(); ++i)
|
||||||
{
|
{
|
||||||
auto groupId = model.animation_group_id_get(i);
|
auto groupId = model.animation_group_id_get(i);
|
||||||
if (selection.contains(i) || groupIds.contains(groupId))
|
if (selection.contains(i) || groupIds.contains(groupId))
|
||||||
clipboardText += model::animation_to_string(*model.animation_get(i), groupId);
|
clipboardText += animation_to_string(*model.animation_get(i), groupId);
|
||||||
}
|
}
|
||||||
return clipboardText;
|
return clipboardText;
|
||||||
}
|
}
|
||||||
|
|
||||||
void animations_insert(PanelState& state, Document& document, const std::string& text, int start, int targetGroupId,
|
static void animations_insert(PanelState& state, Document& document, const std::string& text, int start, int targetGroupId,
|
||||||
StringType edit)
|
StringType edit)
|
||||||
{
|
{
|
||||||
std::set<int> groupIds{};
|
std::set<int> groupIds{};
|
||||||
std::string errorString{};
|
std::string errorString{};
|
||||||
document.edit_apply(edit,
|
document.edit_apply(edit,
|
||||||
[&](model::Model& model)
|
[&](Model& model)
|
||||||
{
|
{
|
||||||
auto uids = edit::animations_paste(model, text, start, targetGroupId, groupIds, &errorString);
|
auto uids = animations_paste(model, text, start, targetGroupId, groupIds, &errorString);
|
||||||
if (uids.empty()) return uids;
|
if (uids.empty()) return uids;
|
||||||
auto indices = animation_indices_get(document, uids);
|
auto indices = animation_indices_get(document, uids);
|
||||||
animations_selection_set(document, groupIds.empty() ? indices : std::set<int>{}, groupIds);
|
animations_selection_set(document, groupIds.empty() ? indices : std::set<int>{}, groupIds);
|
||||||
@@ -199,13 +194,13 @@ namespace anm2ed::imgui
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Merges into options.reference; without a merge-popup selection, the selected animations merge into the first.
|
// Merges into options.reference; without a merge-popup selection, the selected animations merge into the first.
|
||||||
int animations_merge(Document& document, const AnimationMergeOptions& options)
|
static int animations_merge(Document& document, const AnimationMergeOptions& options)
|
||||||
{
|
{
|
||||||
auto isQuick = options.selection.empty();
|
auto isQuick = options.selection.empty();
|
||||||
auto target = options.reference;
|
auto target = options.reference;
|
||||||
auto sources = isQuick ? animation_selected_indices_get(document)
|
auto sources = isQuick ? animation_selected_indices_get(document)
|
||||||
: animation_merge_indices_get(document, options.selection, target);
|
: animation_merge_indices_get(document, options.selection, target);
|
||||||
auto type = isQuick ? merge::APPEND : options.type;
|
auto type = isQuick ? MERGE_APPEND : options.type;
|
||||||
auto isDeleteAfter = isQuick || options.isDeleteAnimationsAfter;
|
auto isDeleteAfter = isQuick || options.isDeleteAnimationsAfter;
|
||||||
auto ungroupIds = isQuick ? animation_groups_selected_get(document) : std::set<int>{};
|
auto ungroupIds = isQuick ? animation_groups_selected_get(document) : std::set<int>{};
|
||||||
|
|
||||||
@@ -223,10 +218,10 @@ namespace anm2ed::imgui
|
|||||||
|
|
||||||
int merged{-1};
|
int merged{-1};
|
||||||
document.edit_apply(EDIT_MERGE_ANIMATIONS,
|
document.edit_apply(EDIT_MERGE_ANIMATIONS,
|
||||||
[&](model::Model& model)
|
[&](Model& model)
|
||||||
{
|
{
|
||||||
animation_overlay_reset(document, sources);
|
animation_overlay_reset(document, sources);
|
||||||
auto uids = edit::animations_merge(model, target, sources, type, isDeleteAfter, ungroupIds);
|
auto uids = animations_merge(model, target, sources, type, isDeleteAfter, ungroupIds);
|
||||||
auto indices = animation_indices_get(document, uids);
|
auto indices = animation_indices_get(document, uids);
|
||||||
if (indices.empty()) return uids;
|
if (indices.empty()) return uids;
|
||||||
merged = *indices.begin();
|
merged = *indices.begin();
|
||||||
@@ -237,7 +232,7 @@ namespace anm2ed::imgui
|
|||||||
return merged;
|
return merged;
|
||||||
}
|
}
|
||||||
|
|
||||||
AnimationDropZone animation_drop_zone_get(ImVec2 min, ImVec2 max)
|
static AnimationDropZone animation_drop_zone_get(ImVec2 min, ImVec2 max)
|
||||||
{
|
{
|
||||||
auto zoneHeight = (max.y - min.y) * DROP_ZONE_FRACTION;
|
auto zoneHeight = (max.y - min.y) * DROP_ZONE_FRACTION;
|
||||||
auto mouseY = ImGui::GetIO().MousePos.y;
|
auto mouseY = ImGui::GetIO().MousePos.y;
|
||||||
@@ -246,8 +241,8 @@ namespace anm2ed::imgui
|
|||||||
return AnimationDropZone::INSIDE;
|
return AnimationDropZone::INSIDE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void animation_move_command_push(const Panel& panel, std::vector<AnimationDragDropItem> items,
|
static void animation_move_command_push(const Panel& panel, std::vector<AnimationDragDropItem> items,
|
||||||
edit::AnimationTarget target)
|
AnimationTarget target)
|
||||||
{
|
{
|
||||||
if (items.empty()) return;
|
if (items.empty()) return;
|
||||||
command_push(panel,
|
command_push(panel,
|
||||||
@@ -258,9 +253,9 @@ namespace anm2ed::imgui
|
|||||||
for (auto item : items)
|
for (auto item : items)
|
||||||
(item.isGroup ? groupIds : indices).insert(item.id);
|
(item.isGroup ? groupIds : indices).insert(item.id);
|
||||||
document.edit_apply(EDIT_MOVE_ANIMATIONS,
|
document.edit_apply(EDIT_MOVE_ANIMATIONS,
|
||||||
[&](model::Model& model)
|
[&](Model& model)
|
||||||
{
|
{
|
||||||
auto uids = edit::animations_move(model, indices, groupIds, target);
|
auto uids = animations_move(model, indices, groupIds, target);
|
||||||
if (uids.empty() && groupIds.empty()) return;
|
if (uids.empty() && groupIds.empty()) return;
|
||||||
animations_selection_set(document, animation_indices_get(document, uids),
|
animations_selection_set(document, animation_indices_get(document, uids),
|
||||||
groupIds);
|
groupIds);
|
||||||
@@ -268,7 +263,7 @@ namespace anm2ed::imgui
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void animation_drag_drop_source_update(const Document& document, AnimationDragDropItem fallback)
|
static void animation_drag_drop_source_update(const Document& document, AnimationDragDropItem fallback)
|
||||||
{
|
{
|
||||||
if (!ImGui::BeginDragDropSource(DRAG_DROP_SOURCE_FLAGS)) return;
|
if (!ImGui::BeginDragDropSource(DRAG_DROP_SOURCE_FLAGS)) return;
|
||||||
|
|
||||||
@@ -288,7 +283,7 @@ namespace anm2ed::imgui
|
|||||||
ImGui::EndDragDropSource();
|
ImGui::EndDragDropSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<AnimationDragDropItem> animation_drag_drop_target_items_get()
|
static std::vector<AnimationDragDropItem> animation_drag_drop_target_items_get()
|
||||||
{
|
{
|
||||||
auto payload = ImGui::AcceptDragDropPayload(ANIMATION_DRAG_DROP, ImGuiDragDropFlags_AcceptBeforeDelivery |
|
auto payload = ImGui::AcceptDragDropPayload(ANIMATION_DRAG_DROP, ImGuiDragDropFlags_AcceptBeforeDelivery |
|
||||||
ImGuiDragDropFlags_AcceptNoDrawDefaultRect);
|
ImGuiDragDropFlags_AcceptNoDrawDefaultRect);
|
||||||
@@ -297,7 +292,7 @@ namespace anm2ed::imgui
|
|||||||
return {items, items + payload->DataSize / sizeof(AnimationDragDropItem)};
|
return {items, items + payload->DataSize / sizeof(AnimationDragDropItem)};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool animation_group_drag_drop_update(const Panel& panel, int groupId, ImVec2 itemMin, ImVec2 itemMax)
|
static bool animation_group_drag_drop_update(const Panel& panel, int groupId, ImVec2 itemMin, ImVec2 itemMax)
|
||||||
{
|
{
|
||||||
if (!ImGui::BeginDragDropTarget()) return false;
|
if (!ImGui::BeginDragDropTarget()) return false;
|
||||||
auto items = animation_drag_drop_target_items_get();
|
auto items = animation_drag_drop_target_items_get();
|
||||||
@@ -322,7 +317,7 @@ namespace anm2ed::imgui
|
|||||||
return isDelivered;
|
return isDelivered;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool animation_row_drag_drop_update(const Panel& panel, int index)
|
static bool animation_row_drag_drop_update(const Panel& panel, int index)
|
||||||
{
|
{
|
||||||
animation_drag_drop_source_update(panel.document, {false, index});
|
animation_drag_drop_source_update(panel.document, {false, index});
|
||||||
if (!ImGui::BeginDragDropTarget()) return false;
|
if (!ImGui::BeginDragDropTarget()) return false;
|
||||||
@@ -342,7 +337,7 @@ namespace anm2ed::imgui
|
|||||||
return isDelivered;
|
return isDelivered;
|
||||||
}
|
}
|
||||||
|
|
||||||
void animation_group_set_push(const Panel& panel, int groupId, StringType edit, std::optional<std::string> name,
|
static void animation_group_set_push(const Panel& panel, int groupId, StringType edit, std::optional<std::string> name,
|
||||||
std::optional<bool> isExpanded)
|
std::optional<bool> isExpanded)
|
||||||
{
|
{
|
||||||
command_push(panel,
|
command_push(panel,
|
||||||
@@ -354,7 +349,7 @@ namespace anm2ed::imgui
|
|||||||
isExpanded.value_or(group->isExpanded) == group->isExpanded))
|
isExpanded.value_or(group->isExpanded) == group->isExpanded))
|
||||||
return;
|
return;
|
||||||
document.edit_apply(edit,
|
document.edit_apply(edit,
|
||||||
[&](model::Model& model)
|
[&](Model& model)
|
||||||
{
|
{
|
||||||
auto group = model.animation_group_edit(first);
|
auto group = model.animation_group_edit(first);
|
||||||
group->name = name.value_or(group->name);
|
group->name = name.value_or(group->name);
|
||||||
@@ -364,8 +359,8 @@ namespace anm2ed::imgui
|
|||||||
}
|
}
|
||||||
|
|
||||||
// A group's tree node (renamable, a drop target) and, when expanded, its animations' rows.
|
// A group's tree node (renamable, a drop target) and, when expanded, its animations' rows.
|
||||||
bool animation_group_draw(Panel& panel, std::set<int>& selection, std::set<int>& groupSelection, int& focus,
|
static bool animation_group_draw(Panel& panel, std::set<int>& selection, std::set<int>& groupSelection, int& focus,
|
||||||
const ListRows& rows, const model::AnimationGroup& group, int firstIndex, int arrowKey)
|
const ListRows& rows, const AnimationGroup& group, int firstIndex, int arrowKey)
|
||||||
{
|
{
|
||||||
auto& state = panel.state;
|
auto& state = panel.state;
|
||||||
auto key = group_key_get(group.id);
|
auto key = group_key_get(group.id);
|
||||||
@@ -435,7 +430,7 @@ namespace anm2ed::imgui
|
|||||||
return isRowsDone;
|
return isRowsDone;
|
||||||
}
|
}
|
||||||
|
|
||||||
void animations_merge_popup_update(Panel& panel, AnimationsPanel& animations)
|
static void animations_merge_popup_update(Panel& panel, AnimationsPanel& animations)
|
||||||
{
|
{
|
||||||
auto& [manager, settings, resources, dialog, clipboard, document, state] = panel;
|
auto& [manager, settings, resources, dialog, clipboard, document, state] = panel;
|
||||||
auto& popup = animations.mergePopup;
|
auto& popup = animations.mergePopup;
|
||||||
@@ -451,13 +446,13 @@ namespace anm2ed::imgui
|
|||||||
std::string label{};
|
std::string label{};
|
||||||
};
|
};
|
||||||
std::vector<AnimationMergeCandidate> candidates{};
|
std::vector<AnimationMergeCandidate> candidates{};
|
||||||
auto candidate_animation_push = [&](const model::Animation& animation, int animationIndex, bool isGrouped)
|
auto candidate_animation_push = [&](const Animation& animation, int animationIndex, bool isGrouped)
|
||||||
{
|
{
|
||||||
if (animationIndex != mergeReference)
|
if (animationIndex != mergeReference)
|
||||||
candidates.push_back({animationIndex, isGrouped ? std::format(" {}", animation.name) : animation.name});
|
candidates.push_back({animationIndex, isGrouped ? std::format(" {}", animation.name) : animation.name});
|
||||||
};
|
};
|
||||||
animation_entries_each(document.model,
|
animation_entries_each(document.model,
|
||||||
[&](int index, const model::Animation* animation, const model::AnimationGroup* group)
|
[&](int index, const Animation* animation, const AnimationGroup* group)
|
||||||
{
|
{
|
||||||
if (animation) return candidate_animation_push(*animation, index, false);
|
if (animation) return candidate_animation_push(*animation, index, false);
|
||||||
auto isReferenceOnly = group->animations.size() == 1 && index == mergeReference;
|
auto isReferenceOnly = group->animations.size() == 1 && index == mergeReference;
|
||||||
@@ -500,15 +495,15 @@ namespace anm2ed::imgui
|
|||||||
auto size = ImVec2(optionsSize.x * MERGE_OPTIONS_HALF, optionsSize.y - ImGui::GetStyle().WindowPadding.y * 2);
|
auto size = ImVec2(optionsSize.x * MERGE_OPTIONS_HALF, optionsSize.y - ImGui::GetStyle().WindowPadding.y * 2);
|
||||||
if (ImGui::BeginChild("##Merge Options 1", size))
|
if (ImGui::BeginChild("##Merge Options 1", size))
|
||||||
{
|
{
|
||||||
ImGui::RadioButton(localize.get(LABEL_APPEND_FRAMES), &settings.mergeType, merge::APPEND);
|
ImGui::RadioButton(localize.get(LABEL_APPEND_FRAMES), &settings.mergeType, MERGE_APPEND);
|
||||||
ImGui::RadioButton(localize.get(LABEL_PREPEND_FRAMES), &settings.mergeType, merge::PREPEND);
|
ImGui::RadioButton(localize.get(LABEL_PREPEND_FRAMES), &settings.mergeType, MERGE_PREPEND);
|
||||||
}
|
}
|
||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if (ImGui::BeginChild("##Merge Options 2", size))
|
if (ImGui::BeginChild("##Merge Options 2", size))
|
||||||
{
|
{
|
||||||
ImGui::RadioButton(localize.get(LABEL_REPLACE_FRAMES), &settings.mergeType, merge::REPLACE);
|
ImGui::RadioButton(localize.get(LABEL_REPLACE_FRAMES), &settings.mergeType, MERGE_REPLACE);
|
||||||
ImGui::RadioButton(localize.get(LABEL_IGNORE_FRAMES), &settings.mergeType, merge::IGNORE);
|
ImGui::RadioButton(localize.get(LABEL_IGNORE_FRAMES), &settings.mergeType, MERGE_IGNORE);
|
||||||
}
|
}
|
||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
}
|
}
|
||||||
@@ -525,7 +520,7 @@ namespace anm2ed::imgui
|
|||||||
command_push(panel,
|
command_push(panel,
|
||||||
[options = AnimationMergeOptions{.selection = mergeSelection,
|
[options = AnimationMergeOptions{.selection = mergeSelection,
|
||||||
.reference = mergeReference,
|
.reference = mergeReference,
|
||||||
.type = (merge::Type)settings.mergeType,
|
.type = (Merge)settings.mergeType,
|
||||||
.isDeleteAnimationsAfter = settings.mergeIsDeleteAnimationsAfter}](
|
.isDeleteAnimationsAfter = settings.mergeIsDeleteAnimationsAfter}](
|
||||||
Document& document) { animations_merge(document, options); });
|
Document& document) { animations_merge(document, options); });
|
||||||
if (result != PopupButton::NONE)
|
if (result != PopupButton::NONE)
|
||||||
@@ -546,7 +541,7 @@ namespace anm2ed::imgui
|
|||||||
{
|
{
|
||||||
auto selection = document.animations_selected_get();
|
auto selection = document.animations_selected_get();
|
||||||
auto groupSelection = animation_groups_selected_get(document);
|
auto groupSelection = animation_groups_selected_get(document);
|
||||||
auto groupIds = edit::animation_group_ids_get(model);
|
auto groupIds = animation_group_ids_get(model);
|
||||||
auto count = model.animations_count_get();
|
auto count = model.animations_count_get();
|
||||||
auto isItemSelected = [&]() { return !selection.empty() || !groupSelection.empty(); };
|
auto isItemSelected = [&]() { return !selection.empty() || !groupSelection.empty(); };
|
||||||
// A single selected group is where adds and pastes go.
|
// A single selected group is where adds and pastes go.
|
||||||
@@ -556,7 +551,7 @@ namespace anm2ed::imgui
|
|||||||
};
|
};
|
||||||
auto group_end_get = [&](int groupId)
|
auto group_end_get = [&](int groupId)
|
||||||
{
|
{
|
||||||
auto indices = groupId != -1 ? edit::animation_group_indices_get(model, groupId) : std::set<int>{};
|
auto indices = groupId != -1 ? animation_group_indices_get(model, groupId) : std::set<int>{};
|
||||||
return indices.empty() ? count : std::min(*indices.rbegin() + 1, count);
|
return indices.empty() ? count : std::min(*indices.rbegin() + 1, count);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -574,9 +569,9 @@ namespace anm2ed::imgui
|
|||||||
[&state, index, groupId](Document& document)
|
[&state, index, groupId](Document& document)
|
||||||
{
|
{
|
||||||
document.edit_apply(EDIT_ADD_ANIMATION,
|
document.edit_apply(EDIT_ADD_ANIMATION,
|
||||||
[&](model::Model& model)
|
[&](Model& model)
|
||||||
{
|
{
|
||||||
auto uids = edit::animation_add(
|
auto uids = animation_add(
|
||||||
model, index, groupId, document.reference_get().animationIndex,
|
model, index, groupId, document.reference_get().animationIndex,
|
||||||
localize.get(TEXT_NEW_ANIMATION));
|
localize.get(TEXT_NEW_ANIMATION));
|
||||||
animations_selection_set(document, {index}, {});
|
animations_selection_set(document, {index}, {});
|
||||||
@@ -622,12 +617,12 @@ namespace anm2ed::imgui
|
|||||||
command_push(panel,
|
command_push(panel,
|
||||||
[&state, targets = std::set<int>(targets.begin(), targets.end())](Document& document)
|
[&state, targets = std::set<int>(targets.begin(), targets.end())](Document& document)
|
||||||
{
|
{
|
||||||
auto groupIds = edit::animation_group_ids_get(document.model);
|
auto groupIds = animation_group_ids_get(document.model);
|
||||||
auto groupId = groupIds.empty() ? 0 : *groupIds.rbegin() + 1;
|
auto groupId = groupIds.empty() ? 0 : *groupIds.rbegin() + 1;
|
||||||
document.edit_apply(EDIT_GROUP_ITEMS,
|
document.edit_apply(EDIT_GROUP_ITEMS,
|
||||||
[&](model::Model& model)
|
[&](Model& model)
|
||||||
{
|
{
|
||||||
auto uids = edit::animations_group(model, targets,
|
auto uids = animations_group(model, targets,
|
||||||
localize.get(TEXT_NEW_GROUP));
|
localize.get(TEXT_NEW_GROUP));
|
||||||
animations_selection_set(document, targets, {groupId});
|
animations_selection_set(document, targets, {groupId});
|
||||||
document.reference_set({*targets.begin()});
|
document.reference_set({*targets.begin()});
|
||||||
@@ -657,7 +652,7 @@ namespace anm2ed::imgui
|
|||||||
{
|
{
|
||||||
auto animation = document.model.animation_get(index);
|
auto animation = document.model.animation_get(index);
|
||||||
if (!animation) return;
|
if (!animation) return;
|
||||||
document.edit_apply(EDIT_DEFAULT_ANIMATION, [name = animation->name](model::Model& model)
|
document.edit_apply(EDIT_DEFAULT_ANIMATION, [name = animation->name](Model& model)
|
||||||
{ model.animations.defaultAnimation = name; });
|
{ model.animations.defaultAnimation = name; });
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -702,7 +697,7 @@ namespace anm2ed::imgui
|
|||||||
[index, name](Document& document)
|
[index, name](Document& document)
|
||||||
{
|
{
|
||||||
document.edit_apply(SNAPSHOT_RENAME_ANIMATION,
|
document.edit_apply(SNAPSHOT_RENAME_ANIMATION,
|
||||||
[&](model::Model& model)
|
[&](Model& model)
|
||||||
{
|
{
|
||||||
auto animation = model.animation_edit(index);
|
auto animation = model.animation_edit(index);
|
||||||
if (!animation) return;
|
if (!animation) return;
|
||||||
@@ -718,10 +713,10 @@ namespace anm2ed::imgui
|
|||||||
auto animation = model.animation_get(index);
|
auto animation = model.animation_get(index);
|
||||||
auto isDefault = animation && model.animations.defaultAnimation == animation->name;
|
auto isDefault = animation && model.animations.defaultAnimation == animation->name;
|
||||||
auto isFocused = document.reference_get().animationIndex == index;
|
auto isFocused = document.reference_get().animationIndex == index;
|
||||||
return isDefault && isFocused ? font::BOLD_ITALICS
|
return isDefault && isFocused ? FONT_BOLD_ITALICS
|
||||||
: isDefault ? font::BOLD
|
: isDefault ? FONT_BOLD
|
||||||
: isFocused ? font::ITALICS
|
: isFocused ? FONT_ITALICS
|
||||||
: font::REGULAR;
|
: FONT_REGULAR;
|
||||||
},
|
},
|
||||||
.tooltip_draw =
|
.tooltip_draw =
|
||||||
[&](int index)
|
[&](int index)
|
||||||
@@ -730,7 +725,7 @@ namespace anm2ed::imgui
|
|||||||
tooltip_name_draw(resources, animation.name);
|
tooltip_name_draw(resources, animation.name);
|
||||||
if (model.animations.defaultAnimation == animation.name)
|
if (model.animations.defaultAnimation == animation.name)
|
||||||
{
|
{
|
||||||
ImGui::PushFont(resources.fonts[font::ITALICS].get(), font::SIZE);
|
ImGui::PushFont(resources.fonts[FONT_ITALICS].get(), FONT_SIZE);
|
||||||
ImGui::TextUnformatted(localize.get(BASIC_DEFAULT));
|
ImGui::TextUnformatted(localize.get(BASIC_DEFAULT));
|
||||||
ImGui::PopFont();
|
ImGui::PopFont();
|
||||||
}
|
}
|
||||||
@@ -759,7 +754,7 @@ namespace anm2ed::imgui
|
|||||||
for (int i = 0; i < count; ++i)
|
for (int i = 0; i < count; ++i)
|
||||||
state.keys.push_back(i);
|
state.keys.push_back(i);
|
||||||
animation_entries_each(model,
|
animation_entries_each(model,
|
||||||
[&](int index, const model::Animation* animation, const model::AnimationGroup* group)
|
[&](int index, const Animation* animation, const AnimationGroup* group)
|
||||||
{
|
{
|
||||||
if (animation) visibleKeys.push_back(index);
|
if (animation) visibleKeys.push_back(index);
|
||||||
if (group && group->isExpanded)
|
if (group && group->isExpanded)
|
||||||
@@ -771,7 +766,7 @@ namespace anm2ed::imgui
|
|||||||
auto arrowKey = list_select_begin(panel, selection, focus, rows, visibleKeys);
|
auto arrowKey = list_select_begin(panel, selection, focus, rows, visibleKeys);
|
||||||
auto isRowsDone = false;
|
auto isRowsDone = false;
|
||||||
animation_entries_each(model,
|
animation_entries_each(model,
|
||||||
[&](int index, const model::Animation* animation, const model::AnimationGroup* group)
|
[&](int index, const Animation* animation, const AnimationGroup* group)
|
||||||
{
|
{
|
||||||
if (isRowsDone) return;
|
if (isRowsDone) return;
|
||||||
if (group)
|
if (group)
|
||||||
@@ -789,8 +784,8 @@ namespace anm2ed::imgui
|
|||||||
|
|
||||||
animations_merge_popup_update(panel, animations);
|
animations_merge_popup_update(panel, animations);
|
||||||
|
|
||||||
auto isNext = shortcut(manager.chords[SHORTCUT_NEXT_ANIMATION], shortcut::GLOBAL);
|
auto isNext = shortcut(manager.chords[SHORTCUT_NEXT_ANIMATION], SCOPE_GLOBAL);
|
||||||
auto isPrevious = shortcut(manager.chords[SHORTCUT_PREVIOUS_ANIMATION], shortcut::GLOBAL);
|
auto isPrevious = shortcut(manager.chords[SHORTCUT_PREVIOUS_ANIMATION], SCOPE_GLOBAL);
|
||||||
auto count = model.animations_count_get();
|
auto count = model.animations_count_get();
|
||||||
if ((!isPrevious && !isNext) || count <= 0) return;
|
if ((!isPrevious && !isNext) || count <= 0) return;
|
||||||
auto reference = document.reference_get();
|
auto reference = document.reference_get();
|
||||||
@@ -799,4 +794,3 @@ namespace anm2ed::imgui
|
|||||||
animations_selection_set(document, {reference.animationIndex}, animation_groups_selected_get(document));
|
animations_selection_set(document, {reference.animationIndex}, animation_groups_selected_get(document));
|
||||||
state.scrollId = reference.animationIndex;
|
state.scrollId = reference.animationIndex;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -5,11 +5,6 @@
|
|||||||
#include "path.h"
|
#include "path.h"
|
||||||
#include "ui/layout.h"
|
#include "ui/layout.h"
|
||||||
|
|
||||||
using namespace anm2ed::resource;
|
|
||||||
using namespace anm2ed::util;
|
|
||||||
|
|
||||||
namespace anm2ed::imgui
|
|
||||||
{
|
|
||||||
void AutosaveRestore::update(Manager& manager)
|
void AutosaveRestore::update(Manager& manager)
|
||||||
{
|
{
|
||||||
if (!isInitialized)
|
if (!isInitialized)
|
||||||
@@ -32,7 +27,7 @@ namespace anm2ed::imgui
|
|||||||
{
|
{
|
||||||
for (auto& file : manager.autosaveFiles)
|
for (auto& file : manager.autosaveFiles)
|
||||||
{
|
{
|
||||||
auto label = std::format(FILE_LABEL_FORMAT, path::to_utf8(file.filename()), path::to_utf8(file));
|
auto label = std::format(FILE_LABEL_FORMAT, path_to_utf8(file.filename()), path_to_utf8(file));
|
||||||
ImGui::TextUnformatted(label.c_str());
|
ImGui::TextUnformatted(label.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -59,4 +54,3 @@ namespace anm2ed::imgui
|
|||||||
ImGui::EndPopup();
|
ImGui::EndPopup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -3,15 +3,12 @@
|
|||||||
#include "manager.h"
|
#include "manager.h"
|
||||||
#include "localization.h"
|
#include "localization.h"
|
||||||
|
|
||||||
namespace anm2ed::imgui
|
|
||||||
{
|
|
||||||
class AutosaveRestore
|
class AutosaveRestore
|
||||||
{
|
{
|
||||||
PopupHelper popup{PopupHelper(LABEL_WELCOME_RESTORE_POPUP, imgui::POPUP_SMALL_NO_HEIGHT)};
|
PopupHelper popup{PopupHelper(LABEL_WELCOME_RESTORE_POPUP, POPUP_SMALL_NO_HEIGHT)};
|
||||||
bool isInitialized{};
|
bool isInitialized{};
|
||||||
bool isRestoreAvailable{};
|
bool isRestoreAvailable{};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void update(Manager&);
|
void update(Manager&);
|
||||||
};
|
};
|
||||||
}
|
|
||||||
+8
-13
@@ -8,12 +8,8 @@
|
|||||||
#include "ui/layout.h"
|
#include "ui/layout.h"
|
||||||
#include "ui/shortcut.h"
|
#include "ui/shortcut.h"
|
||||||
|
|
||||||
using namespace anm2ed::types;
|
|
||||||
using namespace anm2ed::util;
|
|
||||||
using namespace glm;
|
using namespace glm;
|
||||||
|
|
||||||
namespace anm2ed::imgui
|
|
||||||
{
|
|
||||||
CanvasInput canvas_input_get(Manager& manager, bool isFocused)
|
CanvasInput canvas_input_get(Manager& manager, bool isFocused)
|
||||||
{
|
{
|
||||||
auto key_axis_get = [](ImGuiKey negative, ImGuiKey positive)
|
auto key_axis_get = [](ImGuiKey negative, ImGuiKey positive)
|
||||||
@@ -40,8 +36,8 @@ namespace anm2ed::imgui
|
|||||||
.isRightDown = ImGui::IsMouseDown(ImGuiMouseButton_Right),
|
.isRightDown = ImGui::IsMouseDown(ImGuiMouseButton_Right),
|
||||||
.isRightReleased = ImGui::IsMouseReleased(ImGuiMouseButton_Right),
|
.isRightReleased = ImGui::IsMouseReleased(ImGuiMouseButton_Right),
|
||||||
.isMiddleDown = ImGui::IsMouseDown(ImGuiMouseButton_Middle),
|
.isMiddleDown = ImGui::IsMouseDown(ImGuiMouseButton_Middle),
|
||||||
.isZoomIn = isFocused && shortcut(manager.chords[SHORTCUT_ZOOM_IN], shortcut::GLOBAL),
|
.isZoomIn = isFocused && shortcut(manager.chords[SHORTCUT_ZOOM_IN], SCOPE_GLOBAL),
|
||||||
.isZoomOut = isFocused && shortcut(manager.chords[SHORTCUT_ZOOM_OUT], shortcut::GLOBAL),
|
.isZoomOut = isFocused && shortcut(manager.chords[SHORTCUT_ZOOM_OUT], SCOPE_GLOBAL),
|
||||||
.isMod = isMod};
|
.isMod = isMod};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +60,7 @@ namespace anm2ed::imgui
|
|||||||
void frames_change_push(Manager& manager, const std::set<Reference>& frames, FrameChange change, ChangeType type)
|
void frames_change_push(Manager& manager, const std::set<Reference>& frames, FrameChange change, ChangeType type)
|
||||||
{
|
{
|
||||||
manager.command_push({manager.selected, [=](Manager&, Document& document)
|
manager.command_push({manager.selected, [=](Manager&, Document& document)
|
||||||
{ edit::frames_change_apply(document.model, {.references = frames}, change, type); }});
|
{ frames_change_apply(document.model, {.references = frames}, change, type); }});
|
||||||
}
|
}
|
||||||
|
|
||||||
// The rectangle spanned by two corners, grown outward to the grid when snapping, in whole pixels.
|
// The rectangle spanned by two corners, grown outward to the grid when snapping, in whole pixels.
|
||||||
@@ -93,19 +89,19 @@ namespace anm2ed::imgui
|
|||||||
|
|
||||||
// The tool's cursor, or a not-allowed cursor and (while in use) why: the tool belongs to the other canvas, or needs
|
// The tool's cursor, or a not-allowed cursor and (while in use) why: the tool belongs to the other canvas, or needs
|
||||||
// a spritesheet or a frame first.
|
// a spritesheet or a frame first.
|
||||||
void tool_cursor_update(tool::Type type, tool::AreaType area, bool isFrameAvailable, bool isSpritesheetAvailable,
|
void tool_cursor_update(Tool type, ToolArea area, bool isFrameAvailable, bool isSpritesheetAvailable,
|
||||||
bool isUsing, StringType frameHint)
|
bool isUsing, StringType frameHint)
|
||||||
{
|
{
|
||||||
auto& info = tool::INFO[type];
|
auto& info = TOOLS[type];
|
||||||
auto isAreaAllowed = info.areaType == tool::ALL || info.areaType == area;
|
auto isAreaAllowed = info.areaType == TOOL_AREA_ALL || info.areaType == area;
|
||||||
auto isFrameMissing = info.isFrameRequired && !isFrameAvailable;
|
auto isFrameMissing = info.isFrameRequired && !isFrameAvailable;
|
||||||
auto isSpritesheetMissing = info.isSpritesheetRequired && !isSpritesheetAvailable;
|
auto isSpritesheetMissing = info.isSpritesheetRequired && !isSpritesheetAvailable;
|
||||||
auto isAvailable = isAreaAllowed && !isFrameMissing && !isSpritesheetMissing;
|
auto isAvailable = isAreaAllowed && !isFrameMissing && !isSpritesheetMissing;
|
||||||
ImGui::SetMouseCursor(isAvailable ? info.cursor : ImGuiMouseCursor_NotAllowed);
|
ImGui::SetMouseCursor(isAvailable ? info.cursor : ImGuiMouseCursor_NotAllowed);
|
||||||
ImGui::SetKeyboardFocusHere();
|
ImGui::SetKeyboardFocusHere();
|
||||||
if (!isUsing || type == tool::PAN || isAvailable) return;
|
if (!isUsing || type == TOOL_PAN || isAvailable) return;
|
||||||
auto hint = !isAreaAllowed
|
auto hint = !isAreaAllowed
|
||||||
? (area == tool::ANIMATION_PREVIEW ? TEXT_TOOL_SPRITESHEET_EDITOR : TEXT_TOOL_ANIMATION_PREVIEW)
|
? (area == TOOL_AREA_ANIMATION_PREVIEW ? TEXT_TOOL_SPRITESHEET_EDITOR : TEXT_TOOL_ANIMATION_PREVIEW)
|
||||||
: isSpritesheetMissing ? TEXT_SELECT_SPRITESHEET
|
: isSpritesheetMissing ? TEXT_SELECT_SPRITESHEET
|
||||||
: frameHint;
|
: frameHint;
|
||||||
tooltip_lines_draw({localize.get(hint)});
|
tooltip_lines_draw({localize.get(hint)});
|
||||||
@@ -198,4 +194,3 @@ namespace anm2ed::imgui
|
|||||||
actions.add(ACTION_ZOOM_OUT, []() { return true; }, [&]() { zoom_center_step(-ZOOM_LEVEL_STEP); });
|
actions.add(ACTION_ZOOM_OUT, []() { return true; }, [&]() { zoom_center_step(-ZOOM_LEVEL_STEP); });
|
||||||
actions_context_window_draw(label, actions, settings);
|
actions_context_window_draw(label, actions, settings);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -13,8 +13,6 @@
|
|||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "tool.h"
|
#include "tool.h"
|
||||||
|
|
||||||
namespace anm2ed::imgui
|
|
||||||
{
|
|
||||||
// One frame of canvas input. `arrow` is the arrow keys pressed this frame (with key repeat), x right and y down.
|
// One frame of canvas input. `arrow` is the arrow keys pressed this frame (with key repeat), x right and y down.
|
||||||
struct CanvasInput
|
struct CanvasInput
|
||||||
{
|
{
|
||||||
@@ -44,7 +42,7 @@ namespace anm2ed::imgui
|
|||||||
void frames_change_push(Manager&, const std::set<Reference>&, FrameChange, ChangeType = ChangeType::ADJUST);
|
void frames_change_push(Manager&, const std::set<Reference>&, FrameChange, ChangeType = ChangeType::ADJUST);
|
||||||
std::pair<glm::vec2, glm::vec2> rect_snap(glm::vec2, glm::vec2, bool, glm::ivec2, glm::ivec2);
|
std::pair<glm::vec2, glm::vec2> rect_snap(glm::vec2, glm::vec2, bool, glm::ivec2, glm::ivec2);
|
||||||
void tooltip_lines_draw(std::initializer_list<std::string>);
|
void tooltip_lines_draw(std::initializer_list<std::string>);
|
||||||
void tool_cursor_update(tool::Type, tool::AreaType, bool, bool, bool, StringType);
|
void tool_cursor_update(Tool, ToolArea, bool, bool, bool, StringType);
|
||||||
|
|
||||||
class CanvasView : public Canvas
|
class CanvasView : public Canvas
|
||||||
{
|
{
|
||||||
@@ -69,4 +67,3 @@ namespace anm2ed::imgui
|
|||||||
CanvasView();
|
CanvasView();
|
||||||
bool is_focused_get() const;
|
bool is_focused_get() const;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
Loaded 100 of 174 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user