Action manager for undo action of keyboard arrow keys

This commit is contained in:
brunoherbelin
2021-03-16 21:29:38 +01:00
parent 8bd74ec725
commit ca0058c741
7 changed files with 83 additions and 25 deletions

View File

@@ -1036,13 +1036,23 @@ void GeometryView::arrow (glm::vec2 movement)
glm::vec3 gl_delta = gl_Position_to - gl_Position_from;
Group *sourceNode = s->group(mode_);
static glm::vec3 alt_move_ = sourceNode->translation_;
if (UserInterface::manager().altModifier()) {
sourceNode->translation_ += glm::vec3(movement.x, -movement.y, 0.f) * 0.1f;
sourceNode->translation_.x = ROUND(sourceNode->translation_.x, 10.f);
sourceNode->translation_.y = ROUND(sourceNode->translation_.y, 10.f);
alt_move_ += gl_delta * ARROWS_MOVEMENT_FACTOR;
sourceNode->translation_.x = ROUND(alt_move_.x, 10.f);
sourceNode->translation_.y = ROUND(alt_move_.y, 10.f);
}
else
else {
sourceNode->translation_ += gl_delta * ARROWS_MOVEMENT_FACTOR;
alt_move_ = sourceNode->translation_;
}
// store action in history
std::ostringstream info;
info << "Position " << std::fixed << std::setprecision(3) << sourceNode->translation_.x;
info << ", " << sourceNode->translation_.y ;
current_action_ = s->name() + ": " + info.str();
current_id_ = s->id();
// request update
s->touch();

View File

@@ -9,6 +9,7 @@
#include "ImGuiToolkit.h"
#include <string>
#include <sstream>
#include <iomanip>
#include "Mixer.h"
@@ -101,7 +102,7 @@ void LayerView::draw()
if (candidate_flatten_group){
if (ImGui::Selectable( ICON_FA_DOWNLOAD " Flatten" )) {
Mixer::manager().groupSelection();
// Action::manager().store(std::string("Selection Flatten."), Mixer::selection().front()->id());
Action::manager().store(std::string("Selection Flatten."), Mixer::selection().front()->id());
}
}
else {
@@ -315,13 +316,28 @@ void LayerView::arrow (glm::vec2 movement)
glm::vec3 gl_Position_from = Rendering::manager().unProject(glm::vec2(0.f), scene.root()->transform_);
glm::vec3 gl_Position_to = Rendering::manager().unProject(glm::vec2(movement.x-movement.y, 0.f), scene.root()->transform_);
glm::vec3 gl_delta = gl_Position_to - gl_Position_from;
if (UserInterface::manager().altModifier())
gl_delta *= 10.f;
Group *sourceNode = s->group(mode_);
glm::vec3 dest_translation = sourceNode->translation_ + gl_delta * ARROWS_MOVEMENT_FACTOR;
glm::vec3 dest_translation = sourceNode->translation_;
static glm::vec3 alt_move_ = sourceNode->translation_;
if (UserInterface::manager().altModifier()) {
alt_move_ += gl_delta * ARROWS_MOVEMENT_FACTOR;
dest_translation.x = ROUND(alt_move_.x, 10.f);
dest_translation.y = ROUND(alt_move_.y, 10.f);
}
else {
dest_translation += gl_delta * ARROWS_MOVEMENT_FACTOR;
alt_move_ = dest_translation;
}
setDepth( s, MAX( -dest_translation.x, 0.f) );
// store action in history
std::ostringstream info;
info << "Depth " << std::fixed << std::setprecision(2) << s->depth() << " ";
current_action_ = s->name() + ": " + info.str();
current_id_ = s->id();
// request update
s->touch();
}

View File

@@ -473,13 +473,27 @@ void MixingView::arrow (glm::vec2 movement)
glm::vec3 gl_delta = gl_Position_to - gl_Position_from;
Group *sourceNode = s->group(mode_);
static glm::vec3 alt_move_ = sourceNode->translation_;
if (UserInterface::manager().altModifier()) {
sourceNode->translation_ += glm::vec3(movement.x, -movement.y, 0.f) * 0.1f;
sourceNode->translation_.x = ROUND(sourceNode->translation_.x, 10.f);
sourceNode->translation_.y = ROUND(sourceNode->translation_.y, 10.f);
alt_move_ += gl_delta * ARROWS_MOVEMENT_FACTOR;
sourceNode->translation_.x = ROUND(alt_move_.x, 10.f);
sourceNode->translation_.y = ROUND(alt_move_.y, 10.f);
}
else {
sourceNode->translation_ += gl_delta * ARROWS_MOVEMENT_FACTOR;
alt_move_ = sourceNode->translation_;
}
// store action in history
std::ostringstream info;
if (s->active()) {
info << "Alpha " << std::fixed << std::setprecision(3) << s->blendingShader()->color.a << " ";
info << ( (s->blendingShader()->color.a > 0.f) ? ICON_FA_EYE : ICON_FA_EYE_SLASH);
}
else
sourceNode->translation_ += gl_delta * ARROWS_MOVEMENT_FACTOR;
info << "Inactive " << ICON_FA_SNOWFLAKE;
current_action_ = s->name() + ": " + info.str();
current_id_ = s->id();
// request update
s->touch();

View File

@@ -378,10 +378,11 @@ void SessionLoader::visit(Node &n)
void SessionLoader::visit(MediaPlayer &n)
{
XMLElement* mediaplayerNode = xmlCurrent_->FirstChildElement("MediaPlayer");
if (mediaplayerNode) {
uint64_t id__ = -1;
mediaplayerNode->QueryUnsigned64Attribute("id", &id__);
if (mediaplayerNode) {
// timeline
XMLElement *timelineelement = mediaplayerNode->FirstChildElement("Timeline");
if (timelineelement) {

View File

@@ -1317,13 +1317,23 @@ void TextureView::arrow (glm::vec2 movement)
glm::vec3 gl_delta = gl_Position_to - gl_Position_from;
Group *sourceNode = s->group(mode_);
static glm::vec3 alt_move_ = sourceNode->translation_;
if (UserInterface::manager().altModifier()) {
sourceNode->translation_ += glm::vec3(movement.x, -movement.y, 0.f) * 0.1f;
sourceNode->translation_.x = ROUND(sourceNode->translation_.x, 10.f);
sourceNode->translation_.y = ROUND(sourceNode->translation_.y, 10.f);
alt_move_ += gl_delta * ARROWS_MOVEMENT_FACTOR;
sourceNode->translation_.x = ROUND(alt_move_.x, 10.f);
sourceNode->translation_.y = ROUND(alt_move_.y, 10.f);
}
else
else {
sourceNode->translation_ += gl_delta * ARROWS_MOVEMENT_FACTOR;
alt_move_ = sourceNode->translation_;
}
// store action in history
std::ostringstream info;
info << "Texture Shift " << std::fixed << std::setprecision(3) << sourceNode->translation_.x;
info << ", " << sourceNode->translation_.y ;
current_action_ = s->name() + ": " + info.str();
current_id_ = s->id();
// request update
s->touch();
@@ -1331,14 +1341,14 @@ void TextureView::arrow (glm::vec2 movement)
else if (edit_source_) {
if (edit_source_->maskShader()->mode == MaskShader::PAINT) {
if (mask_cursor_paint_ > 0) {
glm::vec2 b = 0.05f * movement;
glm::vec2 b = 0.02f * movement;
Settings::application.brush.x = CLAMP(Settings::application.brush.x+b.x, BRUSH_MIN_SIZE, BRUSH_MAX_SIZE);
Settings::application.brush.y = CLAMP(Settings::application.brush.y+b.y, BRUSH_MIN_PRESS, BRUSH_MAX_PRESS);
}
}
else if (edit_source_->maskShader()->mode == MaskShader::SHAPE) {
if (mask_cursor_shape_ > 0) {
float b = -0.05 * movement.y;
float b = -0.02f * movement.y;
edit_source_->maskShader()->blur = CLAMP(edit_source_->maskShader()->blur+b, SHAPE_MIN_BLUR, SHAPE_MAX_BLUR);
edit_source_->touch();
}

View File

@@ -394,14 +394,21 @@ void UserInterface::handleKeyboard()
Mixer::manager().setCurrentNext();
}
// arrow keys to act on current view
else if (ImGui::IsKeyPressed( GLFW_KEY_LEFT ))
else if (ImGui::IsKeyDown( GLFW_KEY_LEFT ))
Mixer::manager().view()->arrow( glm::vec2(-1.f, 0.f) );
else if (ImGui::IsKeyPressed( GLFW_KEY_RIGHT ))
else if (ImGui::IsKeyDown( GLFW_KEY_RIGHT ))
Mixer::manager().view()->arrow( glm::vec2(+1.f, 0.f) );
else if (ImGui::IsKeyPressed( GLFW_KEY_UP ))
if (ImGui::IsKeyDown( GLFW_KEY_UP ))
Mixer::manager().view()->arrow( glm::vec2(0.f, -1.f) );
else if (ImGui::IsKeyPressed( GLFW_KEY_DOWN ))
else if (ImGui::IsKeyDown( GLFW_KEY_DOWN ))
Mixer::manager().view()->arrow( glm::vec2(0.f, 1.f) );
if (ImGui::IsKeyReleased( GLFW_KEY_LEFT ) ||
ImGui::IsKeyReleased( GLFW_KEY_RIGHT ) ||
ImGui::IsKeyReleased( GLFW_KEY_UP ) ||
ImGui::IsKeyReleased( GLFW_KEY_DOWN ) ){
Mixer::manager().view()->terminate();
}
}
}

View File

@@ -58,7 +58,7 @@
#define TRANSITION_DEFAULT_SCALE 5.0f
#define TRANSITION_MIN_DURATION 0.2f
#define TRANSITION_MAX_DURATION 10.f
#define ARROWS_MOVEMENT_FACTOR 5.f
#define ARROWS_MOVEMENT_FACTOR 4.f
#define IMGUI_TITLE_MAINWINDOW ICON_FA_CIRCLE_NOTCH " vimix"
#define IMGUI_TITLE_MEDIAPLAYER ICON_FA_FILM " Player"