From 9b1a43c520050fef6a8c645b9fcd1a8f4fb7ad7b Mon Sep 17 00:00:00 2001 From: Scott Moreau Date: Tue, 27 Aug 2024 11:20:17 -0600 Subject: [PATCH] animate: Add zap animation (#2411) * Add zap animation * Swap x and y progressions for better effect This could also be made into an option. * Fix metadata * Remove unneeded line of code * zap: Add copyright header * zap: Add dedicated duration option * zap: Move transformer name variable within plugin namespace --- metadata/animate.xml | 13 +++++ plugins/animate/animate.cpp | 9 ++++ plugins/animate/zap.hpp | 105 ++++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 plugins/animate/zap.hpp diff --git a/metadata/animate.xml b/metadata/animate.xml index 385de9276..707e8e90b 100644 --- a/metadata/animate.xml +++ b/metadata/animate.xml @@ -25,6 +25,10 @@ fire <_name>Fire + + zap + <_name>Zap + + diff --git a/plugins/animate/animate.cpp b/plugins/animate/animate.cpp index a7a6bd285..f8de8d287 100644 --- a/plugins/animate/animate.cpp +++ b/plugins/animate/animate.cpp @@ -9,6 +9,7 @@ #include "system_fade.hpp" #include "basic_animations.hpp" #include "squeezimize.hpp" +#include "zap.hpp" #include "fire/fire.hpp" #include "unmapped-view-node.hpp" #include "wayfire/plugin.hpp" @@ -418,6 +419,10 @@ class wayfire_animation : public wf::plugin_interface_t, private wf::per_output_ { set_animation(ev->view, ANIMATION_TYPE_MAP, animation.duration, animation.animation_name); + } else if (animation.animation_name == "zap") + { + set_animation(ev->view, ANIMATION_TYPE_MAP, + animation.duration, animation.animation_name); } }; @@ -438,6 +443,10 @@ class wayfire_animation : public wf::plugin_interface_t, private wf::per_output_ { set_animation(ev->view, ANIMATION_TYPE_UNMAP, animation.duration, animation.animation_name); + } else if (animation.animation_name == "zap") + { + set_animation(ev->view, ANIMATION_TYPE_UNMAP, + animation.duration, animation.animation_name); } }; diff --git a/plugins/animate/zap.hpp b/plugins/animate/zap.hpp new file mode 100644 index 000000000..e5b5f2211 --- /dev/null +++ b/plugins/animate/zap.hpp @@ -0,0 +1,105 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2024 Scott Moreau + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "animate.hpp" +#include "wayfire/toplevel-view.hpp" +#include +#include +#include +#include +#include + + +wf::option_wrapper_t zap_duration{"animate/zap_duration"}; + +namespace wf +{ +namespace zap +{ +static const std::string zap_transformer_name = "zap-transformer"; +using namespace wf::animation; +class zap_animation_t : public duration_t +{ + public: + using duration_t::duration_t; +}; +class zap_animation : public animation_base +{ + wayfire_view view; + wf_animation_type type; + wf::zap::zap_animation_t progression; + + public: + + void init(wayfire_view view, wf::animation_description_t dur, wf_animation_type type) override + { + this->view = view; + this->type = type; + this->progression = + wf::zap::zap_animation_t(wf::create_option(zap_duration)); + + if (type & HIDING_ANIMATION) + { + this->progression.reverse(); + } + + this->progression.start(); + + auto tr = std::make_shared(view); + view->get_transformed_node()->add_transformer( + tr, wf::TRANSFORMER_HIGHLEVEL, zap_transformer_name); + } + + bool step() override + { + auto transform = view->get_transformed_node() + ->get_transformer(zap_transformer_name); + auto progress = this->progression.progress(); + auto progress_pt_one = std::clamp(progress, 0.0, 1.0 / 3.0) * 3.0; + auto progress_pt_two = (std::clamp(progress, 1.0 / 3.0, (1.0 / 3.0) * 2.0) - 1.0 / 3.0) * 3.0; + auto progress_pt_three = (std::clamp(progress, (1.0 / 3.0) * 2.0, 1.0) - (1.0 / 3.0) * 2.0) * 3.0; + transform->alpha = progress_pt_one; + transform->scale_x = 0.01 + progress_pt_two * 0.99; + transform->scale_y = 0.01 + progress_pt_three * 0.99; + + return progression.running(); + } + + void reverse() override + { + this->progression.reverse(); + } + + int get_direction() override + { + return this->progression.get_direction(); + } + + ~zap_animation() + { + view->get_transformed_node()->rem_transformer(zap_transformer_name); + } +}; +} +}