Skip to content

Commit

Permalink
duration: add function to enumerate all the available smoothing funct…
Browse files Browse the repository at this point in the history
…ions (#71)

This would be useful for WCM.
  • Loading branch information
ammen99 authored Jun 19, 2024
1 parent b0a8625 commit fd420e8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
4 changes: 3 additions & 1 deletion include/wayfire/util/duration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <wayfire/config/option.hpp>
#include <wayfire/config/option-types.hpp>
#include <functional>

#include <vector>

namespace wf
{
Expand All @@ -23,6 +23,8 @@ extern smooth_function linear;
extern smooth_function circle;
/** "sigmoid" smoothing function, i.e x -> 1.0 / (1 + exp(-12 * x + 6)) */
extern smooth_function sigmoid;

std::vector<std::string> get_available_smooth_functions();
}
}

Expand Down
29 changes: 20 additions & 9 deletions src/duration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,25 @@ smooth_function ease_out_elastic = [] (double x) -> double

return (a * std::pow(2, -10 * x) * std::sin((x * d - s) * (2 * std::acos(-1)) / p) + 1.0);
};

static const std::map<std::string, animation::smoothing::smooth_function> easing_map = {
{"linear", animation::smoothing::linear},
{"circle", animation::smoothing::circle},
{"sigmoid", animation::smoothing::sigmoid},
{"easeOutElastic", animation::smoothing::ease_out_elastic},
};

std::vector<std::string> get_available_smooth_functions()
{
std::vector<std::string> result;
for (auto& func : easing_map)
{
result.push_back(func.first);
}

return result;
}
} // namespace smoothing
}

namespace option_type
Expand Down Expand Up @@ -303,14 +321,7 @@ std::optional<animation_description_t> from_string<animation_description_t>(cons
result.easing_name = "circle";
}

static const std::map<std::string, animation::smoothing::smooth_function> easing_map = {
{"linear", animation::smoothing::linear},
{"circle", animation::smoothing::circle},
{"sigmoid", animation::smoothing::sigmoid},
{"easeOutElastic", animation::smoothing::ease_out_elastic},
};

if (!easing_map.count(result.easing_name))
if (!animation::smoothing::easing_map.count(result.easing_name))
{
return {};
}
Expand All @@ -322,7 +333,7 @@ std::optional<animation_description_t> from_string<animation_description_t>(cons
return {};
}

result.easing = easing_map.at(result.easing_name);
result.easing = animation::smoothing::easing_map.at(result.easing_name);
if (suffix == "s")
{
result.length_ms = N * 1000;
Expand Down

0 comments on commit fd420e8

Please sign in to comment.