2023-08-19 13:56:36 +02:00
|
|
|
// Copyright 2020 Arthur Sonzogni. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by the MIT license that can be found in
|
|
|
|
|
// the LICENSE file.
|
2021-05-09 20:32:27 +02:00
|
|
|
#include <memory> // for make_shared
|
|
|
|
|
#include <utility> // for move
|
|
|
|
|
|
2021-08-06 20:32:33 +02:00
|
|
|
#include "ftxui/dom/elements.hpp" // for Element, inverted
|
|
|
|
|
#include "ftxui/dom/node.hpp" // for Node
|
2021-05-09 20:32:27 +02:00
|
|
|
#include "ftxui/dom/node_decorator.hpp" // for NodeDecorator
|
|
|
|
|
#include "ftxui/screen/box.hpp" // for Box
|
|
|
|
|
#include "ftxui/screen/screen.hpp" // for Pixel, Screen
|
2018-10-09 19:06:03 +02:00
|
|
|
|
2019-01-12 15:00:08 +01:00
|
|
|
namespace ftxui {
|
2019-01-06 17:10:35 +01:00
|
|
|
|
2023-08-19 14:56:28 +02:00
|
|
|
namespace {
|
2018-10-12 09:23:37 +02:00
|
|
|
class Inverted : public NodeDecorator {
|
2018-10-09 19:06:03 +02:00
|
|
|
public:
|
2021-07-17 15:32:08 +05:30
|
|
|
using NodeDecorator::NodeDecorator;
|
2018-10-09 19:06:03 +02:00
|
|
|
|
|
|
|
|
void Render(Screen& screen) override {
|
|
|
|
|
Node::Render(screen);
|
2019-01-19 22:06:05 +01:00
|
|
|
for (int y = box_.y_min; y <= box_.y_max; ++y) {
|
|
|
|
|
for (int x = box_.x_min; x <= box_.x_max; ++x) {
|
2022-02-06 19:17:21 +01:00
|
|
|
screen.PixelAt(x, y).inverted ^= true;
|
2018-10-09 19:06:03 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2023-08-19 14:56:28 +02:00
|
|
|
} // namespace
|
2018-10-09 19:06:03 +02:00
|
|
|
|
2020-08-16 02:24:50 +02:00
|
|
|
/// @brief Add a filter that will invert the foreground and the background
|
|
|
|
|
/// colors.
|
|
|
|
|
/// @ingroup dom
|
2020-05-20 20:36:47 +02:00
|
|
|
Element inverted(Element child) {
|
2021-07-20 13:29:47 +05:30
|
|
|
return std::make_shared<Inverted>(std::move(child));
|
2018-10-09 19:06:03 +02:00
|
|
|
}
|
|
|
|
|
|
2020-02-11 21:44:55 +01:00
|
|
|
} // namespace ftxui
|