Canvas windows, settings and manager: share view code and list I/O
- CanvasView base holds checker pan sync, zoom step, grid panel, view buttons and view context menu - frame_parent_model_get replaces five root/group transform compositions - Canvas builds VAOs through one helper, unifies uniform setters and frees the texture VAO/VBO/EBO (leak fix) - Settings load/save loop over component suffix tables; unused settings Type enum removed - Manager shares one path-list load/save for recent and autosave files - Anonymous namespaces removed per project style Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a4638a422d
commit
ec72a30ce0
16 files changed
+314
-570
No files matched your search
@@ -43,8 +43,7 @@ namespace anm2ed
|
|||||||
if (isRootTransform && root)
|
if (isRootTransform && root)
|
||||||
{
|
{
|
||||||
auto rootFrame = frame_generate(*root, t);
|
auto rootFrame = frame_generate(*root, t);
|
||||||
transform *= math::quad_model_parent_get(rootFrame.position, {}, math::percent_to_unit(rootFrame.scale),
|
transform *= frame_parent_model_get(rootFrame);
|
||||||
rootFrame.rotation, math::percent_to_unit(rootFrame.shear));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto layerAnimations = child_first_get(animation, ElementType::LAYER_ANIMATIONS);
|
auto layerAnimations = child_first_get(animation, ElementType::LAYER_ANIMATIONS);
|
||||||
@@ -61,9 +60,7 @@ namespace anm2ed
|
|||||||
if (auto groupRoot = child_first_get(*group, ElementType::ROOT_ANIMATION))
|
if (auto groupRoot = child_first_get(*group, ElementType::ROOT_ANIMATION))
|
||||||
{
|
{
|
||||||
auto groupRootFrame = frame_generate(*groupRoot, t);
|
auto groupRootFrame = frame_generate(*groupRoot, t);
|
||||||
itemTransform *= math::quad_model_parent_get(
|
itemTransform *= frame_parent_model_get(groupRootFrame);
|
||||||
groupRootFrame.position, {}, math::percent_to_unit(groupRootFrame.scale),
|
|
||||||
groupRootFrame.rotation, math::percent_to_unit(groupRootFrame.shear));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto frame = frame_effective(layerAnimation.layerId, frame_generate(layerAnimation, t));
|
auto frame = frame_effective(layerAnimation.layerId, frame_generate(layerAnimation, t));
|
||||||
|
|||||||
@@ -523,6 +523,7 @@ namespace anm2ed
|
|||||||
float interpolation_factor(Interpolation, float);
|
float interpolation_factor(Interpolation, float);
|
||||||
void frame_mix(Element&, const Element&, float);
|
void frame_mix(Element&, const Element&, float);
|
||||||
Element frame_generate(const Element&, float);
|
Element frame_generate(const Element&, float);
|
||||||
|
glm::mat4 frame_parent_model_get(const Element&);
|
||||||
int frame_index_from_at_frame_get(const Element&, int);
|
int frame_index_from_at_frame_get(const Element&, int);
|
||||||
int frame_index_from_time_get(const Element&, float);
|
int frame_index_from_time_get(const Element&, float);
|
||||||
float frame_time_from_index_get(const Element&, int);
|
float frame_time_from_index_get(const Element&, int);
|
||||||
|
|||||||
@@ -40,6 +40,12 @@ namespace anm2ed
|
|||||||
return frames;
|
return frames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glm::mat4 frame_parent_model_get(const Element& frame)
|
||||||
|
{
|
||||||
|
return math::quad_model_parent_get(frame.position, {}, math::percent_to_unit(frame.scale), frame.rotation,
|
||||||
|
math::percent_to_unit(frame.shear));
|
||||||
|
}
|
||||||
|
|
||||||
Element frame_generate(const Element& track, float time)
|
Element frame_generate(const Element& track, float time)
|
||||||
{
|
{
|
||||||
auto frame = element_make(track_frame_type_get(track));
|
auto frame = element_make(track_frame_type_get(track));
|
||||||
|
|||||||
+80
-168
@@ -25,86 +25,51 @@ namespace anm2ed
|
|||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void vertex_array_make(GLuint& vao, GLuint& vbo, const void* data, GLsizeiptr size, GLenum usage,
|
||||||
|
std::initializer_list<int> attributeSizes)
|
||||||
|
{
|
||||||
|
glGenVertexArrays(1, &vao);
|
||||||
|
glGenBuffers(1, &vbo);
|
||||||
|
glBindVertexArray(vao);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, size, data, usage);
|
||||||
|
|
||||||
|
auto stride = 0;
|
||||||
|
for (auto attributeSize : attributeSizes)
|
||||||
|
stride += attributeSize;
|
||||||
|
auto offset = 0;
|
||||||
|
auto index = 0;
|
||||||
|
for (auto attributeSize : attributeSizes)
|
||||||
|
{
|
||||||
|
glEnableVertexAttribArray(index);
|
||||||
|
glVertexAttribPointer(index++, attributeSize, GL_FLOAT, GL_FALSE, stride * sizeof(float),
|
||||||
|
(void*)(offset * sizeof(float)));
|
||||||
|
offset += attributeSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Canvas::Canvas() = default;
|
Canvas::Canvas() = default;
|
||||||
|
|
||||||
Canvas::Canvas(vec2 size)
|
Canvas::Canvas(vec2 size)
|
||||||
{
|
{
|
||||||
Framebuffer::size_set(size);
|
Framebuffer::size_set(size);
|
||||||
|
vertex_array_make(axisVAO, axisVBO, AXIS_VERTICES, sizeof(AXIS_VERTICES), GL_STATIC_DRAW, {2});
|
||||||
// Axis
|
vertex_array_make(gridVAO, gridVBO, GRID_VERTICES, sizeof(GRID_VERTICES), GL_STATIC_DRAW, {2, 2});
|
||||||
glGenVertexArrays(1, &axisVAO);
|
vertex_array_make(rectVAO, rectVBO, RECT_VERTICES, sizeof(RECT_VERTICES), GL_STATIC_DRAW, {2});
|
||||||
glGenBuffers(1, &axisVBO);
|
vertex_array_make(textureVAO, textureVBO, nullptr, sizeof(TEXTURE_VERTICES), GL_DYNAMIC_DRAW, {2, 2});
|
||||||
|
|
||||||
glBindVertexArray(axisVAO);
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, axisVBO);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(AXIS_VERTICES), AXIS_VERTICES, GL_STATIC_DRAW);
|
|
||||||
|
|
||||||
glEnableVertexAttribArray(0);
|
|
||||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), (void*)0);
|
|
||||||
|
|
||||||
// Grid
|
|
||||||
glGenVertexArrays(1, &gridVAO);
|
|
||||||
glBindVertexArray(gridVAO);
|
|
||||||
|
|
||||||
glGenBuffers(1, &gridVBO);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, gridVBO);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(GRID_VERTICES), GRID_VERTICES, GL_STATIC_DRAW);
|
|
||||||
|
|
||||||
glEnableVertexAttribArray(0);
|
|
||||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, (void*)0);
|
|
||||||
|
|
||||||
glEnableVertexAttribArray(1);
|
|
||||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, (void*)(sizeof(float) * 2));
|
|
||||||
|
|
||||||
glBindVertexArray(0);
|
|
||||||
|
|
||||||
// Rect
|
|
||||||
glGenVertexArrays(1, &rectVAO);
|
|
||||||
glGenBuffers(1, &rectVBO);
|
|
||||||
|
|
||||||
glBindVertexArray(rectVAO);
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, rectVBO);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(RECT_VERTICES), RECT_VERTICES, GL_STATIC_DRAW);
|
|
||||||
|
|
||||||
glEnableVertexAttribArray(0);
|
|
||||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), (void*)0);
|
|
||||||
|
|
||||||
// Texture
|
|
||||||
glGenVertexArrays(1, &textureVAO);
|
|
||||||
glGenBuffers(1, &textureVBO);
|
|
||||||
glGenBuffers(1, &textureEBO);
|
glGenBuffers(1, &textureEBO);
|
||||||
|
|
||||||
glBindVertexArray(textureVAO);
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, textureVBO);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 4 * 4, nullptr, GL_DYNAMIC_DRAW);
|
|
||||||
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, textureEBO);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, textureEBO);
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(TEXTURE_INDICES), TEXTURE_INDICES, GL_DYNAMIC_DRAW);
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(TEXTURE_INDICES), TEXTURE_INDICES, GL_DYNAMIC_DRAW);
|
||||||
|
|
||||||
glEnableVertexAttribArray(0);
|
|
||||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)0);
|
|
||||||
|
|
||||||
glEnableVertexAttribArray(1);
|
|
||||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)(2 * sizeof(float)));
|
|
||||||
|
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Canvas::~Canvas()
|
Canvas::~Canvas()
|
||||||
{
|
{
|
||||||
if (!Framebuffer::is_valid()) return;
|
if (!Framebuffer::is_valid()) return;
|
||||||
|
for (auto vao : {axisVAO, gridVAO, rectVAO, textureVAO})
|
||||||
glDeleteVertexArrays(1, &axisVAO);
|
glDeleteVertexArrays(1, &vao);
|
||||||
glDeleteBuffers(1, &axisVBO);
|
for (auto buffer : {axisVBO, gridVBO, rectVBO, textureVBO, textureEBO})
|
||||||
|
glDeleteBuffers(1, &buffer);
|
||||||
glDeleteVertexArrays(1, &gridVAO);
|
|
||||||
glDeleteBuffers(1, &gridVBO);
|
|
||||||
|
|
||||||
glDeleteVertexArrays(1, &rectVAO);
|
|
||||||
glDeleteBuffers(1, &rectVBO);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mat4 Canvas::transform_get(float zoom, vec2 pan) const
|
mat4 Canvas::transform_get(float zoom, vec2 pan) const
|
||||||
@@ -165,68 +130,30 @@ namespace anm2ed
|
|||||||
canvas_blend_straight_set();
|
canvas_blend_straight_set();
|
||||||
}
|
}
|
||||||
|
|
||||||
void texture_uniform_vec4_set(const shader::Uniform& uniform, vec4 value)
|
void texture_uniform_set(const shader::Uniform& uniform, vec4 value)
|
||||||
{
|
{
|
||||||
if (uniform.location == -1) return;
|
if (uniform.valueType == shader::UNIFORM_VALUE_INT || uniform.valueType == shader::UNIFORM_VALUE_SAMPLER2D)
|
||||||
|
return glUniform1i(uniform.location, uniform.intValue);
|
||||||
switch (uniform.valueType)
|
switch (shader::UNIFORM_VALUE_TYPE_INFOS[uniform.valueType].componentCount)
|
||||||
{
|
{
|
||||||
case shader::UNIFORM_VALUE_FLOAT:
|
case 2:
|
||||||
glUniform1f(uniform.location, value.x);
|
return glUniform2fv(uniform.location, 1, value_ptr(value));
|
||||||
break;
|
case 3:
|
||||||
case shader::UNIFORM_VALUE_VEC2:
|
return glUniform3fv(uniform.location, 1, value_ptr(value));
|
||||||
glUniform2fv(uniform.location, 1, value_ptr(value));
|
case 4:
|
||||||
break;
|
return glUniform4fv(uniform.location, 1, value_ptr(value));
|
||||||
case shader::UNIFORM_VALUE_VEC3:
|
|
||||||
glUniform3fv(uniform.location, 1, value_ptr(value));
|
|
||||||
break;
|
|
||||||
case shader::UNIFORM_VALUE_VEC4:
|
|
||||||
glUniform4fv(uniform.location, 1, value_ptr(value));
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
if (uniform.valueType == shader::UNIFORM_VALUE_FLOAT) glUniform1f(uniform.location, value.x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void texture_uniform_manual_set(const shader::Uniform& uniform)
|
vec4 texture_uniform_components_get(const shader::Uniform& uniform, float playbackTime)
|
||||||
{
|
{
|
||||||
if (uniform.location == -1) return;
|
vec4 result{};
|
||||||
|
for (int i = 0; i < (int)uniform.components.size(); ++i)
|
||||||
switch (uniform.valueType)
|
result[i] = uniform.components[i].binding == shader::UNIFORM_BINDING_PLAYBACK_TIME ? playbackTime
|
||||||
{
|
: uniform.components[i].value;
|
||||||
case shader::UNIFORM_VALUE_FLOAT:
|
return result;
|
||||||
glUniform1f(uniform.location, uniform.value.x);
|
|
||||||
break;
|
|
||||||
case shader::UNIFORM_VALUE_INT:
|
|
||||||
case shader::UNIFORM_VALUE_SAMPLER2D:
|
|
||||||
glUniform1i(uniform.location, uniform.intValue);
|
|
||||||
break;
|
|
||||||
case shader::UNIFORM_VALUE_VEC2:
|
|
||||||
glUniform2fv(uniform.location, 1, value_ptr(uniform.value));
|
|
||||||
break;
|
|
||||||
case shader::UNIFORM_VALUE_VEC3:
|
|
||||||
glUniform3fv(uniform.location, 1, value_ptr(uniform.value));
|
|
||||||
break;
|
|
||||||
case shader::UNIFORM_VALUE_VEC4:
|
|
||||||
glUniform4fv(uniform.location, 1, value_ptr(uniform.value));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float texture_uniform_component_value_get(const shader::Uniform::Component& component, float playbackTime)
|
|
||||||
{
|
|
||||||
if (component.binding == shader::UNIFORM_BINDING_PLAYBACK_TIME) return playbackTime;
|
|
||||||
return component.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec4 texture_uniform_component_vec4_get(const shader::Uniform& uniform, float playbackTime)
|
|
||||||
{
|
|
||||||
return {texture_uniform_component_value_get(uniform.components[0], playbackTime),
|
|
||||||
texture_uniform_component_value_get(uniform.components[1], playbackTime),
|
|
||||||
texture_uniform_component_value_get(uniform.components[2], playbackTime),
|
|
||||||
texture_uniform_component_value_get(uniform.components[3], playbackTime)};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void texture_uniforms_set(Shader& shader, mat4 transform, vec4 tint, vec3 colorOffset, vec2 textureSize,
|
void texture_uniforms_set(Shader& shader, mat4 transform, vec4 tint, vec3 colorOffset, vec2 textureSize,
|
||||||
@@ -255,22 +182,22 @@ namespace anm2ed
|
|||||||
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 shader::UNIFORM_BINDING_FRAME_TINT:
|
||||||
texture_uniform_vec4_set(uniform, tint);
|
texture_uniform_set(uniform, tint);
|
||||||
break;
|
break;
|
||||||
case shader::UNIFORM_BINDING_COLOR_OFFSET:
|
case shader::UNIFORM_BINDING_COLOR_OFFSET:
|
||||||
texture_uniform_vec4_set(uniform, vec4(colorOffset, 0.0f));
|
texture_uniform_set(uniform, vec4(colorOffset, 0.0f));
|
||||||
break;
|
break;
|
||||||
case shader::UNIFORM_BINDING_TEXTURE_SIZE:
|
case shader::UNIFORM_BINDING_TEXTURE_SIZE:
|
||||||
texture_uniform_vec4_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 shader::UNIFORM_BINDING_PLAYBACK_TIME:
|
||||||
texture_uniform_vec4_set(uniform, vec4(playbackTime));
|
texture_uniform_set(uniform, vec4(playbackTime));
|
||||||
break;
|
break;
|
||||||
case shader::UNIFORM_BINDING_COMPONENTS:
|
case shader::UNIFORM_BINDING_COMPONENTS:
|
||||||
texture_uniform_vec4_set(uniform, texture_uniform_component_vec4_get(uniform, playbackTime));
|
texture_uniform_set(uniform, texture_uniform_components_get(uniform, playbackTime));
|
||||||
break;
|
break;
|
||||||
case shader::UNIFORM_BINDING_MANUAL:
|
case shader::UNIFORM_BINDING_MANUAL:
|
||||||
texture_uniform_manual_set(uniform);
|
texture_uniform_set(uniform, uniform.value);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -306,62 +233,47 @@ namespace anm2ed
|
|||||||
canvas_blend_straight_set();
|
canvas_blend_straight_set();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::rect_render(Shader& shader, const mat4& transform, const mat4& model, vec4 color, float dashLength,
|
void rect_begin(Shader& shader, const mat4& transform, const mat4& model, vec4 color)
|
||||||
float dashGap, float dashOffset) const
|
|
||||||
{
|
{
|
||||||
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, shader::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, shader::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, shader::UNIFORM_COLOR), 1, value_ptr(color));
|
||||||
|
}
|
||||||
|
|
||||||
auto origin = model * vec4(0.0f, 0.0f, 0.0f, 1.0f);
|
void rect_end(GLuint vao, GLenum mode)
|
||||||
auto edgeX = model * vec4(1.0f, 0.0f, 0.0f, 1.0f);
|
{
|
||||||
auto edgeY = model * vec4(0.0f, 1.0f, 0.0f, 1.0f);
|
glBindVertexArray(vao);
|
||||||
|
glDrawArrays(mode, 0, 4);
|
||||||
auto axisX = vec2(edgeX - origin);
|
|
||||||
auto axisY = vec2(edgeY - origin);
|
|
||||||
|
|
||||||
if (auto location = glGetUniformLocation(shader.id, shader::UNIFORM_AXIS_X); location != -1)
|
|
||||||
glUniform2fv(location, 1, value_ptr(axisX));
|
|
||||||
if (auto location = glGetUniformLocation(shader.id, shader::UNIFORM_AXIS_Y); location != -1)
|
|
||||||
glUniform2fv(location, 1, value_ptr(axisY));
|
|
||||||
|
|
||||||
if (auto location = glGetUniformLocation(shader.id, shader::UNIFORM_DASH_LENGTH); location != -1)
|
|
||||||
glUniform1f(location, dashLength);
|
|
||||||
if (auto location = glGetUniformLocation(shader.id, shader::UNIFORM_DASH_GAP); location != -1)
|
|
||||||
glUniform1f(location, dashGap);
|
|
||||||
if (auto location = glGetUniformLocation(shader.id, shader::UNIFORM_DASH_OFFSET); location != -1)
|
|
||||||
glUniform1f(location, dashOffset);
|
|
||||||
|
|
||||||
glBindVertexArray(rectVAO);
|
|
||||||
glDrawArrays(GL_LINE_LOOP, 0, 4);
|
|
||||||
|
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
glUseProgram(0);
|
glUseProgram(0);
|
||||||
canvas_blend_straight_set();
|
canvas_blend_straight_set();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Canvas::rect_render(Shader& shader, const mat4& transform, const mat4& model, vec4 color, float dashLength,
|
||||||
|
float dashGap, float dashOffset) const
|
||||||
|
{
|
||||||
|
rect_begin(shader, transform, model, color);
|
||||||
|
|
||||||
|
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)},
|
||||||
|
std::pair{shader::UNIFORM_AXIS_Y, vec4(0.0f, 1.0f, 0.0f, 1.0f)}})
|
||||||
|
if (auto location = glGetUniformLocation(shader.id, name); location != -1)
|
||||||
|
glUniform2fv(location, 1, value_ptr(vec2(model * axis - origin)));
|
||||||
|
for (auto [name, value] :
|
||||||
|
{std::pair{shader::UNIFORM_DASH_LENGTH, dashLength}, std::pair{shader::UNIFORM_DASH_GAP, dashGap},
|
||||||
|
std::pair{shader::UNIFORM_DASH_OFFSET, dashOffset}})
|
||||||
|
if (auto location = glGetUniformLocation(shader.id, name); location != -1) glUniform1f(location, value);
|
||||||
|
|
||||||
|
rect_end(rectVAO, GL_LINE_LOOP);
|
||||||
|
}
|
||||||
|
|
||||||
void Canvas::rect_fill_render(Shader& shader, const mat4& transform, const mat4& model, vec4 color) const
|
void Canvas::rect_fill_render(Shader& shader, const mat4& transform, const mat4& model, vec4 color) const
|
||||||
{
|
{
|
||||||
canvas_blend_premultiplied_set();
|
rect_begin(shader, transform, model, color);
|
||||||
|
rect_end(rectVAO, GL_TRIANGLE_FAN);
|
||||||
glUseProgram(shader.id);
|
|
||||||
|
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shader.id, shader::UNIFORM_TRANSFORM), 1, GL_FALSE, value_ptr(transform));
|
|
||||||
if (auto location = glGetUniformLocation(shader.id, shader::UNIFORM_MODEL); location != -1)
|
|
||||||
glUniformMatrix4fv(location, 1, GL_FALSE, value_ptr(model));
|
|
||||||
glUniform4fv(glGetUniformLocation(shader.id, shader::UNIFORM_COLOR), 1, value_ptr(color));
|
|
||||||
|
|
||||||
glBindVertexArray(rectVAO);
|
|
||||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
|
||||||
|
|
||||||
glBindVertexArray(0);
|
|
||||||
glUseProgram(0);
|
|
||||||
canvas_blend_straight_set();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float Canvas::zoom_level_get(float zoom, int levelDelta) const
|
float Canvas::zoom_level_get(float zoom, int levelDelta) const
|
||||||
|
|||||||
@@ -42,8 +42,6 @@ namespace anm2ed::imgui
|
|||||||
constexpr auto POINT_SIZE = vec2(4, 4);
|
constexpr auto POINT_SIZE = vec2(4, 4);
|
||||||
constexpr auto TRIGGER_TEXT_COLOR_DARK = ImVec4(1.0f, 1.0f, 1.0f, 0.5f);
|
constexpr auto TRIGGER_TEXT_COLOR_DARK = ImVec4(1.0f, 1.0f, 1.0f, 0.5f);
|
||||||
constexpr auto TRIGGER_TEXT_COLOR_LIGHT = ImVec4(0.0f, 0.0f, 0.0f, 0.5f);
|
constexpr auto TRIGGER_TEXT_COLOR_LIGHT = ImVec4(0.0f, 0.0f, 0.0f, 0.5f);
|
||||||
namespace
|
|
||||||
{
|
|
||||||
struct OverlayAnimationOption
|
struct OverlayAnimationOption
|
||||||
{
|
{
|
||||||
uint64_t documentId{};
|
uint64_t documentId{};
|
||||||
@@ -256,11 +254,6 @@ namespace anm2ed::imgui
|
|||||||
MIX_DestroyMixer(mixer);
|
MIX_DestroyMixer(mixer);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
AnimationPreview::AnimationPreview() : Canvas(vec2()) {}
|
|
||||||
|
|
||||||
bool AnimationPreview::is_focused_get() const { return isFocused; }
|
|
||||||
|
|
||||||
void AnimationPreview::tick(Manager& manager, Settings& settings, float deltaSeconds)
|
void AnimationPreview::tick(Manager& manager, Settings& settings, float deltaSeconds)
|
||||||
{
|
{
|
||||||
@@ -487,33 +480,6 @@ namespace anm2ed::imgui
|
|||||||
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 reset_checker_pan = [&]()
|
|
||||||
{
|
|
||||||
checkerPan = pan;
|
|
||||||
checkerSyncPan = pan;
|
|
||||||
checkerSyncZoom = zoom;
|
|
||||||
isCheckerPanInitialized = true;
|
|
||||||
hasPendingZoomPanAdjust = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
auto sync_checker_pan = [&]()
|
|
||||||
{
|
|
||||||
if (!isCheckerPanInitialized)
|
|
||||||
{
|
|
||||||
reset_checker_pan();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pan != checkerSyncPan || zoom != checkerSyncZoom)
|
|
||||||
{
|
|
||||||
bool ignorePanDelta = hasPendingZoomPanAdjust && zoom != checkerSyncZoom;
|
|
||||||
if (!ignorePanDelta) checkerPan += pan - checkerSyncPan;
|
|
||||||
checkerSyncPan = pan;
|
|
||||||
checkerSyncZoom = zoom;
|
|
||||||
if (ignorePanDelta) hasPendingZoomPanAdjust = false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
auto center_view = [&]() { pan = vec2(); };
|
auto center_view = [&]() { pan = vec2(); };
|
||||||
|
|
||||||
auto fit_view = [&]()
|
auto fit_view = [&]()
|
||||||
@@ -521,17 +487,6 @@ namespace anm2ed::imgui
|
|||||||
if (animation) set_to_rect(zoom, pan, anm2.animation_rect(*animation, isRootTransform));
|
if (animation) set_to_rect(zoom, pan, anm2.animation_rect(*animation, isRootTransform));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto zoom_adjust = [&](int levelDelta)
|
|
||||||
{
|
|
||||||
auto focus = position_translate(zoom, pan, size * 0.5f);
|
|
||||||
auto previousZoom = zoom;
|
|
||||||
zoom_level_adjust(zoom, pan, focus, levelDelta);
|
|
||||||
if (zoom != previousZoom) hasPendingZoomPanAdjust = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
auto zoom_in = [&]() { zoom_adjust(ZOOM_LEVEL_STEP); };
|
|
||||||
auto zoom_out = [&]() { zoom_adjust(-ZOOM_LEVEL_STEP); };
|
|
||||||
|
|
||||||
manager.isAbleToRecord = false;
|
manager.isAbleToRecord = false;
|
||||||
|
|
||||||
if (ImGui::Begin(localize.get(LABEL_ANIMATION_PREVIEW_WINDOW), &settings.windowIsAnimationPreview))
|
if (ImGui::Begin(localize.get(LABEL_ANIMATION_PREVIEW_WINDOW), &settings.windowIsAnimationPreview))
|
||||||
@@ -542,21 +497,7 @@ namespace anm2ed::imgui
|
|||||||
auto childSize = ImVec2(row_widget_width_get(4),
|
auto childSize = ImVec2(row_widget_width_get(4),
|
||||||
(ImGui::GetTextLineHeightWithSpacing() * 4) + (ImGui::GetStyle().WindowPadding.y * 2));
|
(ImGui::GetTextLineHeightWithSpacing() * 4) + (ImGui::GetStyle().WindowPadding.y * 2));
|
||||||
|
|
||||||
if (ImGui::BeginChild("##Grid Child", childSize, true, ImGuiWindowFlags_HorizontalScrollbar))
|
grid_child_draw(childSize, isGrid, gridColor, gridSize, gridOffset);
|
||||||
{
|
|
||||||
ImGui::Checkbox(localize.get(BASIC_GRID), &isGrid);
|
|
||||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_GRID_VISIBILITY));
|
|
||||||
ImGui::SameLine();
|
|
||||||
ImGui::ColorEdit4(localize.get(BASIC_COLOR), value_ptr(gridColor), ImGuiColorEditFlags_NoInputs);
|
|
||||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_GRID_COLOR));
|
|
||||||
|
|
||||||
input_int2_range(localize.get(BASIC_SIZE), gridSize, ivec2(GRID_SIZE_MIN), ivec2(GRID_SIZE_MAX));
|
|
||||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_GRID_SIZE));
|
|
||||||
|
|
||||||
input_int2_range(localize.get(BASIC_OFFSET), gridOffset, ivec2(GRID_OFFSET_MIN), ivec2(GRID_OFFSET_MAX));
|
|
||||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_GRID_OFFSET));
|
|
||||||
}
|
|
||||||
ImGui::EndChild();
|
|
||||||
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
|
||||||
@@ -565,17 +506,7 @@ namespace anm2ed::imgui
|
|||||||
ImGui::InputFloat(localize.get(BASIC_ZOOM), &zoom, 0.0f, 0.0f, "%.0f%%");
|
ImGui::InputFloat(localize.get(BASIC_ZOOM), &zoom, 0.0f, 0.0f, "%.0f%%");
|
||||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_PREVIEW_ZOOM));
|
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_PREVIEW_ZOOM));
|
||||||
|
|
||||||
auto widgetSize = widget_size_with_row_get(2);
|
view_buttons_draw(manager, settings, center_view, fit_view);
|
||||||
|
|
||||||
shortcut(manager.chords[SHORTCUT_CENTER_VIEW]);
|
|
||||||
if (ImGui::Button(localize.get(LABEL_CENTER_VIEW), widgetSize)) center_view();
|
|
||||||
set_item_tooltip_shortcut(localize.get(TOOLTIP_CENTER_VIEW), settings.shortcutCenterView);
|
|
||||||
|
|
||||||
ImGui::SameLine();
|
|
||||||
|
|
||||||
shortcut(manager.chords[SHORTCUT_FIT]);
|
|
||||||
if (ImGui::Button(localize.get(LABEL_FIT), widgetSize)) fit_view();
|
|
||||||
set_item_tooltip_shortcut(localize.get(TOOLTIP_FIT), settings.shortcutFit);
|
|
||||||
|
|
||||||
auto readoutSize = ImVec2(row_widget_width_get(2), ImGui::GetTextLineHeightWithSpacing());
|
auto readoutSize = ImVec2(row_widget_width_get(2), ImGui::GetTextLineHeightWithSpacing());
|
||||||
auto mousePosInt = ivec2(mousePos);
|
auto mousePosInt = ivec2(mousePos);
|
||||||
@@ -903,9 +834,7 @@ namespace anm2ed::imgui
|
|||||||
if (isRootTransform && root)
|
if (isRootTransform && root)
|
||||||
{
|
{
|
||||||
auto rootFrame = frame_generate(*root, t);
|
auto rootFrame = frame_generate(*root, t);
|
||||||
sampleTransform *=
|
sampleTransform *= frame_parent_model_get(rootFrame);
|
||||||
math::quad_model_parent_get(rootFrame.position, {}, math::percent_to_unit(rootFrame.scale),
|
|
||||||
rootFrame.rotation, math::percent_to_unit(rootFrame.shear));
|
|
||||||
}
|
}
|
||||||
return sampleTransform;
|
return sampleTransform;
|
||||||
};
|
};
|
||||||
@@ -936,9 +865,7 @@ namespace anm2ed::imgui
|
|||||||
auto itemTransform = sampleTransform;
|
auto itemTransform = sampleTransform;
|
||||||
if (isRootTransform)
|
if (isRootTransform)
|
||||||
if (auto groupRootFrame = group_root_frame_get(container, track, t))
|
if (auto groupRootFrame = group_root_frame_get(container, track, t))
|
||||||
itemTransform *= math::quad_model_parent_get(
|
itemTransform *= frame_parent_model_get(*groupRootFrame);
|
||||||
groupRootFrame->position, {}, math::percent_to_unit(groupRootFrame->scale), groupRootFrame->rotation,
|
|
||||||
math::percent_to_unit(groupRootFrame->shear));
|
|
||||||
return itemTransform;
|
return itemTransform;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -981,9 +908,7 @@ namespace anm2ed::imgui
|
|||||||
if (isOnlyShowLayers || !rootFrame.isVisible || !groupRoot->isVisible) return;
|
if (isOnlyShowLayers || !rootFrame.isVisible || !groupRoot->isVisible) return;
|
||||||
|
|
||||||
auto itemTransform = sampleTransform;
|
auto itemTransform = sampleTransform;
|
||||||
if (isRootTransform)
|
if (isRootTransform) itemTransform *= frame_parent_model_get(rootFrame);
|
||||||
itemTransform *= math::quad_model_parent_get(rootFrame.position, {}, math::percent_to_unit(rootFrame.scale),
|
|
||||||
rootFrame.rotation, math::percent_to_unit(rootFrame.shear));
|
|
||||||
|
|
||||||
auto rootModel = isRootTransform
|
auto rootModel = isRootTransform
|
||||||
? math::quad_model_get(TARGET_SIZE, {}, TARGET_SIZE * 0.5f)
|
? math::quad_model_get(TARGET_SIZE, {}, TARGET_SIZE * 0.5f)
|
||||||
@@ -1270,7 +1195,7 @@ namespace anm2ed::imgui
|
|||||||
|
|
||||||
if (isTransparent)
|
if (isTransparent)
|
||||||
{
|
{
|
||||||
sync_checker_pan();
|
checker_pan_sync(zoom, pan);
|
||||||
render_checker_background(ImGui::GetWindowDrawList(), min, max, -size - checkerPan, CHECKER_SIZE);
|
render_checker_background(ImGui::GetWindowDrawList(), min, max, -size - checkerPan, CHECKER_SIZE);
|
||||||
}
|
}
|
||||||
image_premultiplied_draw(texture, to_imvec2(size));
|
image_premultiplied_draw(texture, to_imvec2(size));
|
||||||
@@ -1645,26 +1570,14 @@ namespace anm2ed::imgui
|
|||||||
|
|
||||||
if (mouseWheel != 0 || isZoomIn || isZoomOut)
|
if (mouseWheel != 0 || isZoomIn || isZoomOut)
|
||||||
{
|
{
|
||||||
auto previousZoom = zoom;
|
zoom_step(zoom, pan, vec2(mousePos), (mouseWheel > 0 || isZoomIn) ? ZOOM_LEVEL_STEP : -ZOOM_LEVEL_STEP);
|
||||||
zoom_level_adjust(zoom, pan, vec2(mousePos),
|
|
||||||
(mouseWheel > 0 || isZoomIn) ? ZOOM_LEVEL_STEP : -ZOOM_LEVEL_STEP);
|
|
||||||
if (zoom != previousZoom) hasPendingZoomPanAdjust = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tool == tool::PAN)
|
if (tool == tool::PAN)
|
||||||
{
|
view_context_menu_draw("##Animation Preview Context Menu", manager, settings, document, zoom, pan, center_view,
|
||||||
Actions actions{};
|
fit_view, animation != nullptr);
|
||||||
actions_undo_redo_add(actions, manager, document);
|
|
||||||
actions.separator();
|
|
||||||
actions.add(ACTION_CENTER_VIEW, []() { return true; }, center_view);
|
|
||||||
actions.add(ACTION_FIT_VIEW, [&]() { return animation; }, fit_view);
|
|
||||||
actions.separator();
|
|
||||||
actions.add(ACTION_ZOOM_IN, []() { return true; }, zoom_in);
|
|
||||||
actions.add(ACTION_ZOOM_OUT, []() { return true; }, zoom_out);
|
|
||||||
actions_context_window_draw("##Animation Preview Context Menu", actions, settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
manager.progressPopup.trigger();
|
manager.progressPopup.trigger();
|
||||||
|
|
||||||
@@ -1721,7 +1634,7 @@ namespace anm2ed::imgui
|
|||||||
{
|
{
|
||||||
center_view();
|
center_view();
|
||||||
zoom = settings.previewStartZoom;
|
zoom = settings.previewStartZoom;
|
||||||
reset_checker_pan();
|
checker_pan_reset(zoom, pan);
|
||||||
document.isAnimationPreviewSet = true;
|
document.isAnimationPreviewSet = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,19 +4,18 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
||||||
#include "audio_stream.hpp"
|
#include "audio_stream.hpp"
|
||||||
#include "canvas.hpp"
|
#include "canvas_view.hpp"
|
||||||
#include "manager.hpp"
|
#include "manager.hpp"
|
||||||
#include "resources.hpp"
|
#include "resources.hpp"
|
||||||
#include "settings.hpp"
|
#include "settings.hpp"
|
||||||
|
|
||||||
namespace anm2ed::imgui
|
namespace anm2ed::imgui
|
||||||
{
|
{
|
||||||
class AnimationPreview : public Canvas
|
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);
|
||||||
AudioStream audioStream = AudioStream(mixer);
|
AudioStream audioStream = AudioStream(mixer);
|
||||||
bool wasPlaybackPlaying{};
|
bool wasPlaybackPlaying{};
|
||||||
bool isFocused{};
|
|
||||||
bool isPreviewHovered{};
|
bool isPreviewHovered{};
|
||||||
bool isSizeTrySet{true};
|
bool isSizeTrySet{true};
|
||||||
Settings savedSettings{};
|
Settings savedSettings{};
|
||||||
@@ -24,12 +23,6 @@ namespace anm2ed::imgui
|
|||||||
glm::vec2 savedPan{};
|
glm::vec2 savedPan{};
|
||||||
int savedOverlayIndex{};
|
int savedOverlayIndex{};
|
||||||
uint64_t savedOverlayDocumentId{};
|
uint64_t savedOverlayDocumentId{};
|
||||||
glm::vec2 mousePos{};
|
|
||||||
glm::vec2 checkerPan{};
|
|
||||||
glm::vec2 checkerSyncPan{};
|
|
||||||
float checkerSyncZoom{};
|
|
||||||
bool isCheckerPanInitialized{};
|
|
||||||
bool hasPendingZoomPanAdjust{};
|
|
||||||
bool isMoveDragging{};
|
bool isMoveDragging{};
|
||||||
glm::vec2 moveOffset{};
|
glm::vec2 moveOffset{};
|
||||||
glm::vec2 nullRectScaleAnchor{};
|
glm::vec2 nullRectScaleAnchor{};
|
||||||
@@ -43,8 +36,6 @@ namespace anm2ed::imgui
|
|||||||
int renderFrameSoundTimePrev{-1};
|
int renderFrameSoundTimePrev{-1};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AnimationPreview();
|
|
||||||
bool is_focused_get() const;
|
|
||||||
void tick(Manager&, Settings&, float);
|
void tick(Manager&, Settings&, float);
|
||||||
void update(Manager&, Settings&, Resources&);
|
void update(Manager&, Settings&, Resources&);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,102 @@
|
|||||||
|
#include "canvas_view.hpp"
|
||||||
|
|
||||||
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
|
|
||||||
|
#include "actions.hpp"
|
||||||
|
#include "util/imgui/input.hpp"
|
||||||
|
#include "util/imgui/layout.hpp"
|
||||||
|
#include "util/imgui/shortcut.hpp"
|
||||||
|
#include "util/imgui/tooltip.hpp"
|
||||||
|
|
||||||
|
using namespace glm;
|
||||||
|
|
||||||
|
namespace anm2ed::imgui
|
||||||
|
{
|
||||||
|
CanvasView::CanvasView() : Canvas(vec2()) {}
|
||||||
|
|
||||||
|
bool CanvasView::is_focused_get() const { return isFocused; }
|
||||||
|
|
||||||
|
void CanvasView::checker_pan_reset(float zoom, vec2 pan)
|
||||||
|
{
|
||||||
|
checkerPan = pan;
|
||||||
|
checkerSyncPan = pan;
|
||||||
|
checkerSyncZoom = zoom;
|
||||||
|
isCheckerPanInitialized = true;
|
||||||
|
hasPendingZoomPanAdjust = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CanvasView::checker_pan_sync(float zoom, vec2 pan)
|
||||||
|
{
|
||||||
|
if (!isCheckerPanInitialized) return checker_pan_reset(zoom, pan);
|
||||||
|
if (pan == checkerSyncPan && zoom == checkerSyncZoom) return;
|
||||||
|
|
||||||
|
auto isPanDeltaIgnored = hasPendingZoomPanAdjust && zoom != checkerSyncZoom;
|
||||||
|
if (!isPanDeltaIgnored) checkerPan += pan - checkerSyncPan;
|
||||||
|
checkerSyncPan = pan;
|
||||||
|
checkerSyncZoom = zoom;
|
||||||
|
if (isPanDeltaIgnored) hasPendingZoomPanAdjust = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CanvasView::zoom_step(float& zoom, vec2& pan, vec2 focus, int levelDelta)
|
||||||
|
{
|
||||||
|
auto previousZoom = zoom;
|
||||||
|
zoom_level_adjust(zoom, pan, focus, levelDelta);
|
||||||
|
if (zoom != previousZoom) hasPendingZoomPanAdjust = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CanvasView::grid_child_draw(ImVec2 childSize, bool& isGrid, vec4& gridColor, ivec2& gridSize, ivec2& gridOffset,
|
||||||
|
bool* isGridSnap)
|
||||||
|
{
|
||||||
|
if (ImGui::BeginChild("##Grid Child", childSize, true, ImGuiWindowFlags_HorizontalScrollbar))
|
||||||
|
{
|
||||||
|
ImGui::Checkbox(localize.get(BASIC_GRID), &isGrid);
|
||||||
|
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_GRID_VISIBILITY));
|
||||||
|
if (isGridSnap)
|
||||||
|
{
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::Checkbox(localize.get(LABEL_SNAP), isGridSnap);
|
||||||
|
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_GRID_SNAP));
|
||||||
|
}
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::ColorEdit4(localize.get(BASIC_COLOR), value_ptr(gridColor), ImGuiColorEditFlags_NoInputs);
|
||||||
|
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_GRID_COLOR));
|
||||||
|
|
||||||
|
input_int2_range(localize.get(BASIC_SIZE), gridSize, ivec2(GRID_SIZE_MIN), ivec2(GRID_SIZE_MAX));
|
||||||
|
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_GRID_SIZE));
|
||||||
|
input_int2_range(localize.get(BASIC_OFFSET), gridOffset, ivec2(GRID_OFFSET_MIN), ivec2(GRID_OFFSET_MAX));
|
||||||
|
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_GRID_OFFSET));
|
||||||
|
}
|
||||||
|
ImGui::EndChild();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CanvasView::view_buttons_draw(Manager& manager, Settings& settings, const std::function<void()>& center,
|
||||||
|
const std::function<void()>& fit)
|
||||||
|
{
|
||||||
|
auto widgetSize = widget_size_with_row_get(2);
|
||||||
|
shortcut(manager.chords[SHORTCUT_CENTER_VIEW]);
|
||||||
|
if (ImGui::Button(localize.get(LABEL_CENTER_VIEW), widgetSize)) center();
|
||||||
|
set_item_tooltip_shortcut(localize.get(TOOLTIP_CENTER_VIEW), settings.shortcutCenterView);
|
||||||
|
ImGui::SameLine();
|
||||||
|
shortcut(manager.chords[SHORTCUT_FIT]);
|
||||||
|
if (ImGui::Button(localize.get(LABEL_FIT), widgetSize)) fit();
|
||||||
|
set_item_tooltip_shortcut(localize.get(TOOLTIP_FIT), settings.shortcutFit);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CanvasView::view_context_menu_draw(const char* label, Manager& manager, Settings& settings, Document& document,
|
||||||
|
float& zoom, vec2& pan, const std::function<void()>& center,
|
||||||
|
const std::function<void()>& fit, bool isFitEnabled)
|
||||||
|
{
|
||||||
|
auto zoom_center_step = [&](int levelDelta)
|
||||||
|
{ zoom_step(zoom, pan, position_translate(zoom, pan, size * 0.5f), levelDelta); };
|
||||||
|
|
||||||
|
Actions actions{};
|
||||||
|
actions_undo_redo_add(actions, manager, document);
|
||||||
|
actions.separator();
|
||||||
|
actions.add(ACTION_CENTER_VIEW, []() { return true; }, center);
|
||||||
|
actions.add(ACTION_FIT_VIEW, [isFitEnabled]() { return isFitEnabled; }, fit);
|
||||||
|
actions.separator();
|
||||||
|
actions.add(ACTION_ZOOM_IN, []() { 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
#include "canvas.hpp"
|
||||||
|
#include "manager.hpp"
|
||||||
|
#include "settings.hpp"
|
||||||
|
|
||||||
|
namespace anm2ed::imgui
|
||||||
|
{
|
||||||
|
class CanvasView : public Canvas
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
glm::vec2 mousePos{};
|
||||||
|
glm::vec2 checkerPan{};
|
||||||
|
glm::vec2 checkerSyncPan{};
|
||||||
|
float checkerSyncZoom{};
|
||||||
|
bool isCheckerPanInitialized{};
|
||||||
|
bool hasPendingZoomPanAdjust{};
|
||||||
|
bool isFocused{};
|
||||||
|
|
||||||
|
void checker_pan_reset(float, glm::vec2);
|
||||||
|
void checker_pan_sync(float, glm::vec2);
|
||||||
|
void zoom_step(float&, glm::vec2&, glm::vec2, int);
|
||||||
|
void grid_child_draw(ImVec2, bool&, glm::vec4&, glm::ivec2&, glm::ivec2&, bool* = nullptr);
|
||||||
|
void view_buttons_draw(Manager&, Settings&, const std::function<void()>&, const std::function<void()>&);
|
||||||
|
void view_context_menu_draw(const char*, Manager&, Settings&, Document&, float&, glm::vec2&,
|
||||||
|
const std::function<void()>&, const std::function<void()>&, bool);
|
||||||
|
|
||||||
|
public:
|
||||||
|
CanvasView();
|
||||||
|
bool is_focused_get() const;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -24,10 +24,6 @@ using namespace glm;
|
|||||||
|
|
||||||
namespace anm2ed::imgui
|
namespace anm2ed::imgui
|
||||||
{
|
{
|
||||||
SpritesheetEditor::SpritesheetEditor() : Canvas(vec2()) {}
|
|
||||||
|
|
||||||
bool SpritesheetEditor::is_focused_get() const { return isFocused; }
|
|
||||||
|
|
||||||
void SpritesheetEditor::update(Manager& manager, Settings& settings, Resources& resources)
|
void SpritesheetEditor::update(Manager& manager, Settings& settings, Resources& resources)
|
||||||
{
|
{
|
||||||
isFocused = false;
|
isFocused = false;
|
||||||
@@ -74,33 +70,6 @@ namespace anm2ed::imgui
|
|||||||
auto& regionReference = document.region.reference;
|
auto& regionReference = document.region.reference;
|
||||||
auto& regionSelection = document.region.selection;
|
auto& regionSelection = document.region.selection;
|
||||||
|
|
||||||
auto reset_checker_pan = [&]()
|
|
||||||
{
|
|
||||||
checkerPan = pan;
|
|
||||||
checkerSyncPan = pan;
|
|
||||||
checkerSyncZoom = zoom;
|
|
||||||
isCheckerPanInitialized = true;
|
|
||||||
hasPendingZoomPanAdjust = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
auto sync_checker_pan = [&]()
|
|
||||||
{
|
|
||||||
if (!isCheckerPanInitialized)
|
|
||||||
{
|
|
||||||
reset_checker_pan();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pan != checkerSyncPan || zoom != checkerSyncZoom)
|
|
||||||
{
|
|
||||||
bool ignorePanDelta = hasPendingZoomPanAdjust && zoom != checkerSyncZoom;
|
|
||||||
if (!ignorePanDelta) checkerPan += pan - checkerSyncPan;
|
|
||||||
checkerSyncPan = pan;
|
|
||||||
checkerSyncZoom = zoom;
|
|
||||||
if (ignorePanDelta) hasPendingZoomPanAdjust = false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
auto center_view = [&]() { pan = -size * 0.5f; };
|
auto center_view = [&]() { pan = -size * 0.5f; };
|
||||||
|
|
||||||
auto fit_view = [&]()
|
auto fit_view = [&]()
|
||||||
@@ -110,17 +79,6 @@ namespace anm2ed::imgui
|
|||||||
set_to_rect(zoom, pan, {0, 0, (float)fitTexture->size.x, (float)fitTexture->size.y});
|
set_to_rect(zoom, pan, {0, 0, (float)fitTexture->size.x, (float)fitTexture->size.y});
|
||||||
};
|
};
|
||||||
|
|
||||||
auto zoom_adjust = [&](int levelDelta)
|
|
||||||
{
|
|
||||||
auto focus = position_translate(zoom, pan, size * 0.5f);
|
|
||||||
auto previousZoom = zoom;
|
|
||||||
zoom_level_adjust(zoom, pan, focus, levelDelta);
|
|
||||||
if (zoom != previousZoom) hasPendingZoomPanAdjust = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
auto zoom_in = [&]() { zoom_adjust(ZOOM_LEVEL_STEP); };
|
|
||||||
auto zoom_out = [&]() { zoom_adjust(-ZOOM_LEVEL_STEP); };
|
|
||||||
|
|
||||||
auto region_get = [&](int id)
|
auto region_get = [&](int id)
|
||||||
{ return spritesheet ? child_id_get(*spritesheet, ElementType::REGION, id) : nullptr; };
|
{ return spritesheet ? child_id_get(*spritesheet, ElementType::REGION, id) : nullptr; };
|
||||||
|
|
||||||
@@ -131,24 +89,7 @@ namespace anm2ed::imgui
|
|||||||
auto childSize = ImVec2(imgui::row_widget_width_get(3),
|
auto childSize = ImVec2(imgui::row_widget_width_get(3),
|
||||||
(ImGui::GetTextLineHeightWithSpacing() * 4) + (ImGui::GetStyle().WindowPadding.y * 2));
|
(ImGui::GetTextLineHeightWithSpacing() * 4) + (ImGui::GetStyle().WindowPadding.y * 2));
|
||||||
|
|
||||||
if (ImGui::BeginChild("##Grid Child", childSize, true, ImGuiWindowFlags_HorizontalScrollbar))
|
grid_child_draw(childSize, isGrid, gridColor, gridSize, gridOffset, &isGridSnap);
|
||||||
{
|
|
||||||
ImGui::Checkbox(localize.get(BASIC_GRID), &isGrid);
|
|
||||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_GRID_VISIBILITY));
|
|
||||||
ImGui::SameLine();
|
|
||||||
ImGui::Checkbox(localize.get(LABEL_SNAP), &isGridSnap);
|
|
||||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_GRID_SNAP));
|
|
||||||
ImGui::SameLine();
|
|
||||||
ImGui::ColorEdit4(localize.get(BASIC_COLOR), value_ptr(gridColor), ImGuiColorEditFlags_NoInputs);
|
|
||||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_GRID_COLOR));
|
|
||||||
|
|
||||||
input_int2_range(localize.get(BASIC_SIZE), gridSize, ivec2(GRID_SIZE_MIN), ivec2(GRID_SIZE_MAX));
|
|
||||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_GRID_SIZE));
|
|
||||||
|
|
||||||
input_int2_range(localize.get(BASIC_OFFSET), gridOffset, ivec2(GRID_OFFSET_MIN), ivec2(GRID_OFFSET_MAX));
|
|
||||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_GRID_OFFSET));
|
|
||||||
}
|
|
||||||
ImGui::EndChild();
|
|
||||||
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
|
||||||
@@ -157,17 +98,7 @@ namespace anm2ed::imgui
|
|||||||
ImGui::InputFloat(localize.get(BASIC_ZOOM), &zoom, 0.0f, 0.0f, "%.0f%%");
|
ImGui::InputFloat(localize.get(BASIC_ZOOM), &zoom, 0.0f, 0.0f, "%.0f%%");
|
||||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_EDITOR_ZOOM));
|
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_EDITOR_ZOOM));
|
||||||
|
|
||||||
auto widgetSize = ImVec2(imgui::row_widget_width_get(2), 0);
|
view_buttons_draw(manager, settings, center_view, fit_view);
|
||||||
|
|
||||||
imgui::shortcut(manager.chords[SHORTCUT_CENTER_VIEW]);
|
|
||||||
if (ImGui::Button(localize.get(LABEL_CENTER_VIEW), widgetSize)) center_view();
|
|
||||||
imgui::set_item_tooltip_shortcut(localize.get(TOOLTIP_CENTER_VIEW), settings.shortcutCenterView);
|
|
||||||
|
|
||||||
ImGui::SameLine();
|
|
||||||
|
|
||||||
imgui::shortcut(manager.chords[SHORTCUT_FIT]);
|
|
||||||
if (ImGui::Button(localize.get(LABEL_FIT), widgetSize)) fit_view();
|
|
||||||
imgui::set_item_tooltip_shortcut(localize.get(TOOLTIP_FIT), settings.shortcutFit);
|
|
||||||
|
|
||||||
auto mousePosInt = ivec2(mousePos);
|
auto mousePosInt = ivec2(mousePos);
|
||||||
ImGui::TextUnformatted(
|
ImGui::TextUnformatted(
|
||||||
@@ -322,7 +253,7 @@ namespace anm2ed::imgui
|
|||||||
|
|
||||||
unbind();
|
unbind();
|
||||||
|
|
||||||
sync_checker_pan();
|
checker_pan_sync(zoom, pan);
|
||||||
if (isTransparent)
|
if (isTransparent)
|
||||||
render_checker_background(drawList, min, max, -size * 0.5f - checkerPan, CHECKER_SIZE);
|
render_checker_background(drawList, min, max, -size * 0.5f - checkerPan, CHECKER_SIZE);
|
||||||
else
|
else
|
||||||
@@ -1007,27 +938,14 @@ namespace anm2ed::imgui
|
|||||||
auto focus = mouseWheel != 0 ? vec2(mousePos) : vec2();
|
auto focus = mouseWheel != 0 ? vec2(mousePos) : vec2();
|
||||||
if (texture && mouseWheel == 0) focus = texture->size / 2;
|
if (texture && mouseWheel == 0) focus = texture->size / 2;
|
||||||
|
|
||||||
auto previousZoom = zoom;
|
zoom_step(zoom, pan, focus, (mouseWheel > 0 || isZoomIn) ? ZOOM_LEVEL_STEP : -ZOOM_LEVEL_STEP);
|
||||||
zoom_level_adjust(zoom, pan, focus, (mouseWheel > 0 || isZoomIn) ? ZOOM_LEVEL_STEP : -ZOOM_LEVEL_STEP);
|
|
||||||
if (zoom != previousZoom) hasPendingZoomPanAdjust = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tool == tool::PAN)
|
if (tool == tool::PAN)
|
||||||
{
|
view_context_menu_draw("##Spritesheet Editor Context Menu", manager, settings, document, zoom, pan, center_view,
|
||||||
Actions actions{};
|
fit_view, (baseTexture && baseTexture->is_valid()) || (texture && texture->is_valid()));
|
||||||
actions_undo_redo_add(actions, manager, document);
|
|
||||||
actions.separator();
|
|
||||||
actions.add(ACTION_CENTER_VIEW, []() { return true; }, center_view);
|
|
||||||
actions.add(
|
|
||||||
ACTION_FIT_VIEW,
|
|
||||||
[&]() { return (baseTexture && baseTexture->is_valid()) || (texture && texture->is_valid()); }, fit_view);
|
|
||||||
actions.separator();
|
|
||||||
actions.add(ACTION_ZOOM_IN, []() { return true; }, zoom_in);
|
|
||||||
actions.add(ACTION_ZOOM_OUT, []() { return true; }, zoom_out);
|
|
||||||
actions_context_window_draw("##Spritesheet Editor Context Menu", actions, settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!document.isSpritesheetEditorSet)
|
if (!document.isSpritesheetEditorSet)
|
||||||
{
|
{
|
||||||
@@ -1035,7 +953,7 @@ namespace anm2ed::imgui
|
|||||||
zoom = settings.editorStartZoom;
|
zoom = settings.editorStartZoom;
|
||||||
set();
|
set();
|
||||||
center_view();
|
center_view();
|
||||||
reset_checker_pan();
|
checker_pan_reset(zoom, pan);
|
||||||
document.isSpritesheetEditorSet = true;
|
document.isSpritesheetEditorSet = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,28 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "canvas.hpp"
|
#include "canvas_view.hpp"
|
||||||
#include "manager.hpp"
|
#include "manager.hpp"
|
||||||
#include "resources.hpp"
|
#include "resources.hpp"
|
||||||
#include "settings.hpp"
|
#include "settings.hpp"
|
||||||
|
|
||||||
namespace anm2ed::imgui
|
namespace anm2ed::imgui
|
||||||
{
|
{
|
||||||
class SpritesheetEditor : public Canvas
|
class SpritesheetEditor : public CanvasView
|
||||||
{
|
{
|
||||||
glm::vec2 mousePos{};
|
|
||||||
glm::vec2 previousMousePos{};
|
glm::vec2 previousMousePos{};
|
||||||
glm::vec2 cropAnchor{};
|
glm::vec2 cropAnchor{};
|
||||||
glm::vec2 checkerPan{};
|
|
||||||
glm::vec2 checkerSyncPan{};
|
|
||||||
float checkerSyncZoom{};
|
|
||||||
bool isCheckerPanInitialized{};
|
|
||||||
bool hasPendingZoomPanAdjust{};
|
|
||||||
bool isFocused{};
|
|
||||||
int hoveredRegionId{-1};
|
int hoveredRegionId{-1};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SpritesheetEditor();
|
|
||||||
bool is_focused_get() const;
|
|
||||||
void update(Manager&, Settings&, Resources&);
|
void update(Manager&, Settings&, Resources&);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
+41
-76
@@ -21,8 +21,6 @@ namespace anm2ed
|
|||||||
{
|
{
|
||||||
constexpr std::size_t RECENT_LIMIT = 10;
|
constexpr std::size_t RECENT_LIMIT = 10;
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
void ensure_parent_directory_exists(const std::filesystem::path& path)
|
void ensure_parent_directory_exists(const std::filesystem::path& path)
|
||||||
{
|
{
|
||||||
auto parent = path.parent_path();
|
auto parent = path.parent_path();
|
||||||
@@ -40,6 +38,37 @@ namespace anm2ed
|
|||||||
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)
|
||||||
|
{
|
||||||
|
std::string fileData{};
|
||||||
|
if (!file::read_to_string(path, &fileData, "rb"))
|
||||||
|
{
|
||||||
|
logger.warning(std::format("Could not load {} from: {}. Skipping...", name, path::to_utf8(path)));
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
logger.info(std::format("Loading {} from: {}", name, path::to_utf8(path)));
|
||||||
|
|
||||||
|
std::vector<std::filesystem::path> result{};
|
||||||
|
std::istringstream file(fileData);
|
||||||
|
for (std::string line{}; std::getline(file, line);)
|
||||||
|
{
|
||||||
|
if (!line.empty() && line.back() == '\r') line.pop_back();
|
||||||
|
auto entry = path::from_utf8(line);
|
||||||
|
if (!line.empty() && std::ranges::find(result, entry) == result.end()) result.push_back(entry);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void path_list_save(const std::filesystem::path& path, const std::vector<std::filesystem::path>& entries,
|
||||||
|
std::string_view name)
|
||||||
|
{
|
||||||
|
ensure_parent_directory_exists(path);
|
||||||
|
std::ostringstream file{};
|
||||||
|
for (auto& entry : entries)
|
||||||
|
file << path::to_utf8(entry) << '\n';
|
||||||
|
if (!file::write_string(path, file.str(), "wb"))
|
||||||
|
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)
|
||||||
@@ -276,58 +305,23 @@ namespace anm2ed
|
|||||||
|
|
||||||
void Manager::recent_files_load()
|
void Manager::recent_files_load()
|
||||||
{
|
{
|
||||||
auto path = recent_files_path_get();
|
|
||||||
|
|
||||||
std::string fileData{};
|
|
||||||
if (!file::read_to_string(path, &fileData, "rb"))
|
|
||||||
{
|
|
||||||
logger.warning(std::format("Could not load recent files from: {}. Skipping...", path::to_utf8(path)));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
std::istringstream file(fileData);
|
|
||||||
|
|
||||||
logger.info(std::format("Loading recent files from: {}", path::to_utf8(path)));
|
|
||||||
|
|
||||||
std::string line{};
|
|
||||||
std::vector<std::string> loaded{};
|
|
||||||
std::unordered_set<std::string> seen{};
|
|
||||||
|
|
||||||
while (std::getline(file, line))
|
|
||||||
{
|
|
||||||
if (line.empty()) continue;
|
|
||||||
if (!line.empty() && line.back() == '\r') line.pop_back();
|
|
||||||
auto entry = path::from_utf8(line);
|
|
||||||
std::error_code ec{};
|
|
||||||
if (!std::filesystem::exists(entry, ec))
|
|
||||||
{
|
|
||||||
logger.warning(std::format("Skipping missing recent file: {}", line));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
auto entryString = path::to_utf8(entry);
|
|
||||||
if (!seen.insert(entryString).second) continue;
|
|
||||||
loaded.emplace_back(std::move(entryString));
|
|
||||||
}
|
|
||||||
|
|
||||||
recentFiles.clear();
|
recentFiles.clear();
|
||||||
recentFilesCounter = 0;
|
recentFilesCounter = 0;
|
||||||
|
auto loaded = path_list_load(recent_files_path_get(), "recent files");
|
||||||
for (auto it = loaded.rbegin(); it != loaded.rend(); ++it)
|
for (auto it = loaded.rbegin(); it != loaded.rend(); ++it)
|
||||||
{
|
{
|
||||||
recentFiles[*it] = ++recentFilesCounter;
|
std::error_code ec{};
|
||||||
|
if (std::filesystem::exists(*it, ec))
|
||||||
|
recentFiles[path::to_utf8(*it)] = ++recentFilesCounter;
|
||||||
|
else
|
||||||
|
logger.warning(std::format("Skipping missing recent file: {}", path::to_utf8(*it)));
|
||||||
}
|
}
|
||||||
recent_files_trim();
|
recent_files_trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::recent_files_write()
|
void Manager::recent_files_write()
|
||||||
{
|
{
|
||||||
auto path = recent_files_path_get();
|
path_list_save(recent_files_path_get(), recent_files_ordered(), "recent files");
|
||||||
ensure_parent_directory_exists(path);
|
|
||||||
|
|
||||||
std::ostringstream file;
|
|
||||||
auto ordered = recent_files_ordered();
|
|
||||||
for (auto& entry : ordered)
|
|
||||||
file << path::to_utf8(entry) << '\n';
|
|
||||||
if (!file::write_string(path, file.str(), "wb"))
|
|
||||||
logger.warning(std::format("Could not write recent files to: {}. Skipping...", path::to_utf8(path)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::recent_files_clear()
|
void Manager::recent_files_clear()
|
||||||
@@ -352,40 +346,11 @@ namespace anm2ed
|
|||||||
|
|
||||||
void Manager::autosave_files_load()
|
void Manager::autosave_files_load()
|
||||||
{
|
{
|
||||||
auto path = autosave_path_get();
|
for (auto& entry : path_list_load(autosave_path_get(), "autosave files"))
|
||||||
|
if (std::ranges::find(autosaveFiles, entry) == autosaveFiles.end()) autosaveFiles.push_back(entry);
|
||||||
std::string fileData{};
|
|
||||||
if (!file::read_to_string(path, &fileData, "rb"))
|
|
||||||
{
|
|
||||||
logger.warning(std::format("Could not load autosave files from: {}. Skipping...", path::to_utf8(path)));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
std::istringstream file(fileData);
|
|
||||||
|
|
||||||
logger.info(std::format("Loading autosave files from: {}", path::to_utf8(path)));
|
|
||||||
|
|
||||||
std::string line{};
|
|
||||||
|
|
||||||
while (std::getline(file, line))
|
|
||||||
{
|
|
||||||
if (line.empty()) continue;
|
|
||||||
if (!line.empty() && line.back() == '\r') line.pop_back();
|
|
||||||
auto entry = path::from_utf8(line);
|
|
||||||
if (std::find(autosaveFiles.begin(), autosaveFiles.end(), entry) != autosaveFiles.end()) continue;
|
|
||||||
autosaveFiles.emplace_back(std::move(entry));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::autosave_files_write()
|
void Manager::autosave_files_write() { path_list_save(autosave_path_get(), autosaveFiles, "autosave files"); }
|
||||||
{
|
|
||||||
ensure_parent_directory_exists(autosave_path_get());
|
|
||||||
std::ostringstream autosaveWriteFile;
|
|
||||||
for (auto& path : autosaveFiles)
|
|
||||||
autosaveWriteFile << path::to_utf8(path) << "\n";
|
|
||||||
if (!file::write_string(autosave_path_get(), autosaveWriteFile.str(), "wb"))
|
|
||||||
logger.warning(
|
|
||||||
std::format("Could not write autosave files to: {}. Skipping...", path::to_utf8(autosave_path_get())));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Manager::autosave_files_clear(bool removeFiles)
|
void Manager::autosave_files_clear(bool removeFiles)
|
||||||
{
|
{
|
||||||
|
|||||||
+27
-97
@@ -11,6 +11,23 @@ using namespace glm;
|
|||||||
|
|
||||||
namespace anm2ed
|
namespace anm2ed
|
||||||
{
|
{
|
||||||
|
constexpr const char* COMPONENT_SUFFIXES_XY[] = {"X", "Y"};
|
||||||
|
constexpr const char* COMPONENT_SUFFIXES_WH[] = {"W", "H"};
|
||||||
|
constexpr const char* COMPONENT_SUFFIXES_RGBA[] = {"R", "G", "B", "A"};
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
concept GlmVector = requires(T value) {
|
||||||
|
T::length();
|
||||||
|
value[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
const char* const* component_suffixes_get(std::string_view type)
|
||||||
|
{
|
||||||
|
if (type.ends_with("_WH")) return COMPONENT_SUFFIXES_WH;
|
||||||
|
if (type.starts_with("VEC3") || type.starts_with("VEC4")) return COMPONENT_SUFFIXES_RGBA;
|
||||||
|
return COMPONENT_SUFFIXES_XY;
|
||||||
|
}
|
||||||
|
|
||||||
constexpr auto IMGUI_DEFAULT = R"(
|
constexpr auto IMGUI_DEFAULT = R"(
|
||||||
[Window][##DockSpace]
|
[Window][##DockSpace]
|
||||||
Pos=0,54
|
Pos=0,54
|
||||||
@@ -212,87 +229,21 @@ DockSpace ID=0x123F8F08 Window=0x6D581B32 Pos=8,62 Size=1902,991
|
|||||||
[&](const std::string& key, std::istringstream& ss, const std::string& name, auto& value, std::string_view type)
|
[&](const std::string& key, std::istringstream& ss, const std::string& name, auto& value, std::string_view type)
|
||||||
{
|
{
|
||||||
using T = std::decay_t<decltype(value)>;
|
using T = std::decay_t<decltype(value)>;
|
||||||
|
if constexpr (GlmVector<T>)
|
||||||
auto is_match = [&](const char* suffix) { return key == name + suffix; };
|
|
||||||
|
|
||||||
if constexpr (std::is_same_v<T, ivec2> || std::is_same_v<T, vec2>)
|
|
||||||
{
|
{
|
||||||
if (type.ends_with("_WH"))
|
auto suffixes = component_suffixes_get(type);
|
||||||
|
for (int i = 0; i < T::length(); ++i)
|
||||||
|
if (key == name + suffixes[i])
|
||||||
{
|
{
|
||||||
if (is_match("W"))
|
stream_assign(value[i], ss);
|
||||||
{
|
|
||||||
stream_assign(value.x, ss);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (is_match("H"))
|
|
||||||
{
|
|
||||||
stream_assign(value.y, ss);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else if (key == name)
|
||||||
{
|
|
||||||
if (is_match("X"))
|
|
||||||
{
|
|
||||||
stream_assign(value.x, ss);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (is_match("Y"))
|
|
||||||
{
|
|
||||||
stream_assign(value.y, ss);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if constexpr (std::is_same_v<T, vec3>)
|
|
||||||
{
|
|
||||||
if (is_match("R"))
|
|
||||||
{
|
|
||||||
stream_assign(value.x, ss);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (is_match("G"))
|
|
||||||
{
|
|
||||||
stream_assign(value.y, ss);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (is_match("B"))
|
|
||||||
{
|
|
||||||
stream_assign(value.z, ss);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if constexpr (std::is_same_v<T, vec4>)
|
|
||||||
{
|
|
||||||
if (is_match("R"))
|
|
||||||
{
|
|
||||||
stream_assign(value.x, ss);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (is_match("G"))
|
|
||||||
{
|
|
||||||
stream_assign(value.y, ss);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (is_match("B"))
|
|
||||||
{
|
|
||||||
stream_assign(value.z, ss);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (is_match("A"))
|
|
||||||
{
|
|
||||||
stream_assign(value.w, ss);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (key == name)
|
|
||||||
{
|
{
|
||||||
value_set(value, ss);
|
value_set(value, ss);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
@@ -313,7 +264,6 @@ DockSpace ID=0x123F8F08 Window=0x6D581B32 Pos=8,62 Size=1902,991
|
|||||||
SETTINGS_MEMBERS SETTINGS_SHORTCUTS SETTINGS_WINDOWS
|
SETTINGS_MEMBERS SETTINGS_SHORTCUTS SETTINGS_WINDOWS
|
||||||
#undef X
|
#undef X
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Options Settings::anm2_options_get() const
|
Options Settings::anm2_options_get() const
|
||||||
@@ -390,31 +340,11 @@ DockSpace ID=0x123F8F08 Window=0x6D581B32 Pos=8,62 Size=1902,991
|
|||||||
{
|
{
|
||||||
using T = std::decay_t<decltype(value)>;
|
using T = std::decay_t<decltype(value)>;
|
||||||
|
|
||||||
if constexpr (std::is_same_v<T, ivec2> || std::is_same_v<T, vec2>)
|
if constexpr (GlmVector<T>)
|
||||||
{
|
{
|
||||||
if (type.ends_with("_WH"))
|
auto suffixes = component_suffixes_get(type);
|
||||||
{
|
for (int i = 0; i < T::length(); ++i)
|
||||||
value_save(name + "W", value.x);
|
value_save(name + suffixes[i], value[i]);
|
||||||
value_save(name + "H", value.y);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
value_save(name + "X", value.x);
|
|
||||||
value_save(name + "Y", value.y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if constexpr (std::is_same_v<T, vec3>)
|
|
||||||
{
|
|
||||||
value_save(name + "R", value.x);
|
|
||||||
value_save(name + "G", value.y);
|
|
||||||
value_save(name + "B", value.z);
|
|
||||||
}
|
|
||||||
else if constexpr (std::is_same_v<T, vec4>)
|
|
||||||
{
|
|
||||||
value_save(name + "R", value.x);
|
|
||||||
value_save(name + "G", value.y);
|
|
||||||
value_save(name + "B", value.z);
|
|
||||||
value_save(name + "A", value.w);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
value_save(name, value);
|
value_save(name, value);
|
||||||
|
|||||||
@@ -42,13 +42,6 @@ namespace anm2ed
|
|||||||
X(VEC3, glm::vec3) \
|
X(VEC3, glm::vec3) \
|
||||||
X(VEC4, glm::vec4)
|
X(VEC4, glm::vec4)
|
||||||
|
|
||||||
enum Type
|
|
||||||
{
|
|
||||||
#define X(name, type) name,
|
|
||||||
SETTINGS_TYPES
|
|
||||||
#undef X
|
|
||||||
};
|
|
||||||
|
|
||||||
#define X(name, type) using TYPE_##name = type;
|
#define X(name, type) using TYPE_##name = type;
|
||||||
SETTINGS_TYPES
|
SETTINGS_TYPES
|
||||||
#undef X
|
#undef X
|
||||||
|
|||||||
@@ -4,8 +4,6 @@
|
|||||||
#include <climits>
|
#include <climits>
|
||||||
|
|
||||||
namespace anm2ed
|
namespace anm2ed
|
||||||
{
|
|
||||||
namespace
|
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
struct WSAInitializer
|
struct WSAInitializer
|
||||||
@@ -29,7 +27,6 @@ namespace anm2ed
|
|||||||
return errno;
|
return errno;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Socket::Socket() : handle(SOCKET_INVALID), role(CLIENT), lastError(0) {}
|
Socket::Socket() : handle(SOCKET_INVALID), role(CLIENT), lastError(0) {}
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,6 @@
|
|||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
namespace anm2ed::util::path
|
namespace anm2ed::util::path
|
||||||
{
|
|
||||||
namespace
|
|
||||||
{
|
{
|
||||||
template <typename CharT> CharT to_lower_char(CharT character)
|
template <typename CharT> CharT to_lower_char(CharT character)
|
||||||
{
|
{
|
||||||
@@ -17,7 +15,6 @@ namespace anm2ed::util::path
|
|||||||
else
|
else
|
||||||
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 to_lower(const std::filesystem::path& path)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,8 +8,6 @@
|
|||||||
namespace anm2ed::util
|
namespace anm2ed::util
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
namespace
|
|
||||||
{
|
|
||||||
std::wstring utf8_to_wstring(const char* text)
|
std::wstring utf8_to_wstring(const char* text)
|
||||||
{
|
{
|
||||||
if (!text) return {};
|
if (!text) return {};
|
||||||
@@ -19,7 +17,6 @@ namespace anm2ed::util
|
|||||||
MultiByteToWideChar(CP_UTF8, 0, text, -1, wide.data(), sizeRequired);
|
MultiByteToWideChar(CP_UTF8, 0, text, -1, wide.data(), sizeRequired);
|
||||||
return wide;
|
return wide;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Process::Process(const char* command, const char* mode) { open(command, mode); }
|
Process::Process(const char* command, const char* mode) { open(command, mode); }
|
||||||
|
|||||||
Reference in new issue
Block a user