Skip to content

Commit

Permalink
animate: Add zap animation (#2411)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
soreau committed Aug 27, 2024
1 parent 80d6bcc commit 9b1a43c
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 0 deletions.
13 changes: 13 additions & 0 deletions metadata/animate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
<value>fire</value>
<_name>Fire</_name>
</desc>
<desc>
<value>zap</value>
<_name>Zap</_name>
</desc>
</option>
<option name="close_animation" type="string">
<_short>Close animation</_short>
Expand All @@ -46,6 +50,10 @@
<value>fire</value>
<_name>Fire</_name>
</desc>
<desc>
<value>zap</value>
<_name>Zap</_name>
</desc>
</option>
<option name="minimize_animation" type="string">
<_short>Minimze animation</_short>
Expand Down Expand Up @@ -138,5 +146,10 @@
<_long>Sets the duration of the squeezimize animation in milliseconds.</_long>
<default>150ms linear</default>
</option>
<option name="zap_duration" type="animation">
<_short>Zap duration</_short>
<_long>Sets the duration for the zap animation in milliseconds.</_long>
<default>250ms linear</default>
</option>
</plugin>
</wayfire>
9 changes: 9 additions & 0 deletions plugins/animate/animate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -418,6 +419,10 @@ class wayfire_animation : public wf::plugin_interface_t, private wf::per_output_
{
set_animation<FireAnimation>(ev->view, ANIMATION_TYPE_MAP,
animation.duration, animation.animation_name);
} else if (animation.animation_name == "zap")
{
set_animation<wf::zap::zap_animation>(ev->view, ANIMATION_TYPE_MAP,
animation.duration, animation.animation_name);
}
};

Expand All @@ -438,6 +443,10 @@ class wayfire_animation : public wf::plugin_interface_t, private wf::per_output_
{
set_animation<FireAnimation>(ev->view, ANIMATION_TYPE_UNMAP,
animation.duration, animation.animation_name);
} else if (animation.animation_name == "zap")
{
set_animation<wf::zap::zap_animation>(ev->view, ANIMATION_TYPE_UNMAP,
animation.duration, animation.animation_name);
}
};

Expand Down
105 changes: 105 additions & 0 deletions plugins/animate/zap.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2024 Scott Moreau <oreaus@gmail.com>
*
* 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 <memory>
#include <wayfire/plugin.hpp>
#include <wayfire/opengl.hpp>
#include <wayfire/view-transform.hpp>
#include <wayfire/output.hpp>


wf::option_wrapper_t<wf::animation_description_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<wf::animation_description_t>(zap_duration));

if (type & HIDING_ANIMATION)
{
this->progression.reverse();
}

this->progression.start();

auto tr = std::make_shared<wf::scene::view_2d_transformer_t>(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<wf::scene::view_2d_transformer_t>(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);
}
};
}
}

0 comments on commit 9b1a43c

Please sign in to comment.