2019-12-02 08:26:37 +00:00
|
|
|
#include "main.h"
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <iostream>
|
2020-01-13 22:55:54 +00:00
|
|
|
#include "internal.h"
|
|
|
|
|
2020-06-01 05:02:45 +00:00
|
|
|
auto pulser(struct notcurses* nc, struct ncplane* ncp __attribute__ ((unused)),
|
|
|
|
const struct timespec* ts __attribute__ ((unused)), void* curry) -> int {
|
2020-05-09 01:30:45 +00:00
|
|
|
auto pulsestart = static_cast<struct timespec*>(curry);
|
2020-01-13 22:55:54 +00:00
|
|
|
if(notcurses_render(nc)){
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
struct timespec now;
|
2020-05-19 07:32:09 +00:00
|
|
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
2020-01-17 14:30:53 +00:00
|
|
|
auto delta = timespec_to_ns(&now) - timespec_to_ns(pulsestart);
|
2020-06-17 23:39:37 +00:00
|
|
|
if(delta > 250000000){
|
2020-01-13 22:55:54 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2019-12-02 08:26:37 +00:00
|
|
|
|
2020-06-01 07:33:00 +00:00
|
|
|
auto fadeaborter(struct notcurses* nc, struct ncplane* ncp,
|
|
|
|
const struct timespec* ts, void* curry) -> int {
|
|
|
|
(void)nc;
|
|
|
|
(void)ncp;
|
|
|
|
(void)ts;
|
|
|
|
(void)curry;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
TEST_CASE("Fade") {
|
2020-06-16 03:58:43 +00:00
|
|
|
auto nc_ = testing_notcurses();
|
2020-05-17 11:57:21 +00:00
|
|
|
if(!nc_){
|
|
|
|
return;
|
|
|
|
}
|
2019-12-27 22:20:20 +00:00
|
|
|
struct ncplane* n_ = notcurses_stdplane(nc_);
|
|
|
|
REQUIRE(n_);
|
|
|
|
if(!notcurses_canfade(nc_)){
|
2020-05-22 07:31:03 +00:00
|
|
|
CHECK(0 == notcurses_stop(nc_));
|
2019-12-27 22:20:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
REQUIRE(0 == ncplane_cursor_move_yx(n_, 0, 0));
|
|
|
|
int dimy, dimx;
|
|
|
|
ncplane_dim_yx(n_, &dimy, &dimx);
|
|
|
|
cell c = CELL_TRIVIAL_INITIALIZER;
|
|
|
|
c.gcluster = '*';
|
2020-09-17 19:34:28 +00:00
|
|
|
cell_set_fg_rgb8(&c, 0xff, 0xff, 0xff);
|
2019-12-27 22:20:20 +00:00
|
|
|
unsigned rgb = 0xffffffu;
|
2020-04-06 03:06:21 +00:00
|
|
|
CHECK(!ncplane_set_scrolling(n_, true));
|
2019-12-27 22:20:20 +00:00
|
|
|
for(int y = 0 ; y < dimy ; ++y){
|
|
|
|
for(int x = 0 ; x < dimx ; ++x){
|
|
|
|
rgb -= 32;
|
|
|
|
if(rgb < 32){
|
|
|
|
rgb = 0xffffffu;
|
2019-12-02 08:26:37 +00:00
|
|
|
}
|
2020-09-17 19:34:28 +00:00
|
|
|
cell_set_fg_rgb(&c, rgb);
|
|
|
|
cell_set_bg_rgb8(&c, rgb & 0xff, (rgb >> 16u) & 0xff, (rgb >> 8u) & 0xff);
|
2019-12-27 22:20:20 +00:00
|
|
|
CHECK(0 < ncplane_putc(n_, &c));
|
2019-12-02 08:26:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
SUBCASE("FadeOut") {
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
struct timespec ts;
|
2020-03-07 23:36:49 +00:00
|
|
|
ts.tv_sec = 0;
|
2020-06-17 23:39:37 +00:00
|
|
|
ts.tv_nsec = 250000000;
|
2020-01-17 14:30:53 +00:00
|
|
|
CHECK(0 == ncplane_fadeout(n_, &ts, nullptr, nullptr));
|
2019-12-02 08:26:37 +00:00
|
|
|
}
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
SUBCASE("FadeIn") {
|
|
|
|
struct timespec ts;
|
2020-03-07 23:36:49 +00:00
|
|
|
ts.tv_sec = 0;
|
2020-06-17 23:39:37 +00:00
|
|
|
ts.tv_nsec = 250000000;
|
2020-01-17 14:30:53 +00:00
|
|
|
CHECK(0 == ncplane_fadein(n_, &ts, nullptr, nullptr));
|
2020-01-13 22:55:54 +00:00
|
|
|
}
|
|
|
|
|
2020-06-01 07:33:00 +00:00
|
|
|
SUBCASE("FadeOutAbort") {
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
struct timespec ts;
|
|
|
|
ts.tv_sec = 0;
|
2020-06-17 23:39:37 +00:00
|
|
|
ts.tv_nsec = 250000000;
|
2020-06-01 07:33:00 +00:00
|
|
|
CHECK(0 < ncplane_fadeout(n_, &ts, fadeaborter, nullptr));
|
|
|
|
}
|
|
|
|
|
|
|
|
SUBCASE("FadeInAbort") {
|
|
|
|
struct timespec ts;
|
|
|
|
ts.tv_sec = 0;
|
2020-06-17 23:39:37 +00:00
|
|
|
ts.tv_nsec = 250000000;
|
2020-06-01 07:33:00 +00:00
|
|
|
CHECK(0 < ncplane_fadein(n_, &ts, fadeaborter, nullptr));
|
|
|
|
}
|
|
|
|
|
2020-01-13 22:55:54 +00:00
|
|
|
SUBCASE("Pulse") {
|
|
|
|
struct timespec ts;
|
|
|
|
ts.tv_sec = 0;
|
2020-06-17 23:39:37 +00:00
|
|
|
ts.tv_nsec = 75000000;
|
2020-01-13 22:55:54 +00:00
|
|
|
ncplane_erase(n_);
|
2020-09-17 19:34:28 +00:00
|
|
|
ncplane_set_fg_rgb(n_, 0xffd700);
|
2020-01-13 22:55:54 +00:00
|
|
|
CHECK(0 < ncplane_printf_aligned(n_, dimy - 1, NCALIGN_CENTER, "pulllllllse"));
|
2020-01-17 14:30:53 +00:00
|
|
|
struct timespec pulsestart;
|
2020-05-19 07:32:09 +00:00
|
|
|
clock_gettime(CLOCK_MONOTONIC, &pulsestart);
|
2020-01-17 14:30:53 +00:00
|
|
|
CHECK(0 < ncplane_pulse(n_, &ts, pulser, &pulsestart));
|
2019-12-27 22:20:20 +00:00
|
|
|
}
|
2019-12-02 08:26:37 +00:00
|
|
|
|
2020-06-01 07:33:00 +00:00
|
|
|
// drive fadeout with the more flexible api
|
|
|
|
SUBCASE("FadeOutFlexible") {
|
2020-06-01 07:53:44 +00:00
|
|
|
auto nctx = ncfadectx_setup(n_);
|
2020-06-01 07:27:55 +00:00
|
|
|
REQUIRE(nctx);
|
|
|
|
auto maxiter = ncfadectx_iterations(nctx);
|
|
|
|
CHECK(0 < maxiter);
|
|
|
|
for(int i = 0 ; i < maxiter ; ++i){
|
|
|
|
CHECK(0 == ncplane_fadeout_iteration(n_, nctx, i, nullptr, nullptr));
|
|
|
|
}
|
|
|
|
ncfadectx_free(nctx);
|
|
|
|
}
|
|
|
|
|
2020-06-01 07:33:00 +00:00
|
|
|
SUBCASE("FadeOutFlexibleAbort") {
|
2020-06-01 07:53:44 +00:00
|
|
|
auto nctx = ncfadectx_setup(n_);
|
2020-06-01 07:33:00 +00:00
|
|
|
REQUIRE(nctx);
|
|
|
|
auto maxiter = ncfadectx_iterations(nctx);
|
|
|
|
CHECK(0 < maxiter);
|
|
|
|
for(int i = 0 ; i < maxiter ; ++i){
|
|
|
|
CHECK(0 < ncplane_fadeout_iteration(n_, nctx, i, fadeaborter, nullptr));
|
|
|
|
}
|
|
|
|
ncfadectx_free(nctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
// drive fadein with the more flexible api
|
|
|
|
SUBCASE("FadeInFlexible") {
|
2020-06-01 07:53:44 +00:00
|
|
|
auto nctx = ncfadectx_setup(n_);
|
2020-06-01 07:27:55 +00:00
|
|
|
REQUIRE(nctx);
|
|
|
|
auto maxiter = ncfadectx_iterations(nctx);
|
|
|
|
CHECK(0 < maxiter);
|
|
|
|
for(int i = 0 ; i < maxiter ; ++i){
|
|
|
|
CHECK(0 == ncplane_fadein_iteration(n_, nctx, i, nullptr, nullptr));
|
|
|
|
}
|
|
|
|
ncfadectx_free(nctx);
|
|
|
|
}
|
|
|
|
|
2020-06-01 07:33:00 +00:00
|
|
|
SUBCASE("FadeInFlexibleAbort") {
|
2020-06-01 07:53:44 +00:00
|
|
|
auto nctx = ncfadectx_setup(n_);
|
2020-06-01 07:33:00 +00:00
|
|
|
REQUIRE(nctx);
|
|
|
|
auto maxiter = ncfadectx_iterations(nctx);
|
|
|
|
CHECK(0 < maxiter);
|
|
|
|
for(int i = 0 ; i < maxiter ; ++i){
|
|
|
|
CHECK(0 < ncplane_fadein_iteration(n_, nctx, i, fadeaborter, nullptr));
|
|
|
|
}
|
|
|
|
ncfadectx_free(nctx);
|
|
|
|
}
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
CHECK(0 == notcurses_stop(nc_));
|
2019-12-02 08:26:37 +00:00
|
|
|
|
|
|
|
}
|