You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
113 lines
3.2 KiB
113 lines
3.2 KiB
// 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.
|
|
#ifndef FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP
|
|
#define FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP
|
|
|
|
#include <atomic> // for atomic
|
|
#include <ftxui/component/receiver.hpp> // for Receiver, Sender
|
|
#include <functional> // for function
|
|
#include <memory> // for shared_ptr
|
|
#include <string> // for string
|
|
#include <thread> // for thread
|
|
#include <variant> // for variant
|
|
|
|
#include <ftxui/component/animation.hpp> // for TimePoint
|
|
#include <ftxui/component/captured_mouse.hpp> // for CapturedMouse
|
|
#include <ftxui/component/event.hpp> // for Event
|
|
#include <ftxui/component/task.hpp> // for Task, Closure
|
|
#include <ftxui/screen/screen.hpp> // for Screen
|
|
|
|
using ftxui::Component, ftxui::Task, ftxui::Closure, ftxui::Event, ftxui::Sender, ftxui::Receiver;
|
|
|
|
namespace ftxui {
|
|
class ComponentBase;
|
|
struct Event;
|
|
|
|
using Component = std::shared_ptr<ComponentBase>;
|
|
class SFMLScreenPrivate;
|
|
}
|
|
|
|
class SFMLScreen : public ftxui::Screen {
|
|
public:
|
|
// Constructors:
|
|
static SFMLScreen FixedSize(int dimx, int dimy);
|
|
static SFMLScreen Fullscreen();
|
|
static SFMLScreen FitComponent();
|
|
static SFMLScreen TerminalOutput();
|
|
|
|
// Options. Must be called before Loop().
|
|
void TrackMouse(bool enable = true);
|
|
|
|
// Return the currently active screen, nullptr if none.
|
|
static SFMLScreen* Active();
|
|
|
|
// Start/Stop the main loop.
|
|
void Exit();
|
|
Closure ExitLoopClosure();
|
|
|
|
// Post tasks to be executed by the loop.
|
|
void Post(Task task);
|
|
void PostEvent(Event event);
|
|
void RequestAnimationFrame();
|
|
|
|
// Decorate a function. The outputted one will execute similarly to the
|
|
// inputted one, but with the currently active screen terminal hooks
|
|
// temporarily uninstalled.
|
|
ftxui::Closure WithRestoredIO(ftxui::Closure);
|
|
|
|
void ExitNow();
|
|
|
|
void Install();
|
|
void Uninstall();
|
|
|
|
void PreMain();
|
|
void PostMain();
|
|
|
|
bool HasQuitted();
|
|
void RunOnce(Component component);
|
|
void RunOnceBlocking(Component component);
|
|
|
|
void HandleTask(Component component, Task& task);
|
|
void Draw(Component component);
|
|
void ResetCursorPosition();
|
|
|
|
SFMLScreen* suspended_screen_ = nullptr;
|
|
enum class Dimension {
|
|
FitComponent,
|
|
Fixed,
|
|
Fullscreen,
|
|
TerminalOutput,
|
|
};
|
|
Dimension dimension_ = Dimension::Fixed;
|
|
bool use_alternative_screen_ = false;
|
|
|
|
SFMLScreen(int dimx,
|
|
int dimy,
|
|
Dimension dimension,
|
|
bool use_alternative_screen);
|
|
|
|
bool track_mouse_ = true;
|
|
|
|
Sender<Task> task_sender_;
|
|
Receiver<Task> task_receiver_;
|
|
|
|
std::string set_cursor_position;
|
|
std::string reset_cursor_position;
|
|
|
|
std::thread event_listener_;
|
|
std::thread animation_listener_;
|
|
bool animation_requested_ = false;
|
|
ftxui::animation::TimePoint previous_animation_time_;
|
|
|
|
int cursor_x_ = 1;
|
|
int cursor_y_ = 1;
|
|
|
|
bool mouse_captured = false;
|
|
bool previous_frame_resized_ = false;
|
|
|
|
bool frame_valid_ = false;
|
|
};
|
|
|
|
|
|
#endif /* end of include guard: FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP */
|
|
|