#pragma once #include #include "neovision/view.h" #include "neovision/crt.h" #include "neovision/term.h" namespace neovision { /** * Main application class. * * Create a class derrived from this one to serve as your main application * class. * * Unless you're doing something weird, the Application class should be the * first thing you instantiate. * * Add views to the application for anything you want the application to render * using the Add() function. The application takes ownership of any views added * to it. * */ class Application: public View { wchar_t m_bgFillCharacter{L'░'}; int m_ttyFd{0}; InputParser m_inputParser; bool m_running{false}; std::shared_ptr m_selfPtr; Terminal m_terminal; void InitializeViews(); public: /** * @brief Default constructor. */ Application(); /** * @brief Destructor. */ virtual ~Application(); /** * @brief Initializes the application for use. * * You must call this before calling Run(). */ virtual void Initialize(); /** * @brief Starts the application. */ virtual void Run(); /** * @brief Terminates the application. */ virtual void Stop(); /** * @brief Get terminal. * * @return Returns a reference to the terminal instance. */ Terminal& Term(); protected: /** * @brief Mouse event. * * Triggers when a mouse event happens. * * @param[in] mouseData Mouse event data gets passed in here. */ virtual void OnMouse(const MouseEventData& mouseData); /** * @brief Key event. * * Triggers when a keyboard event happens. * * @param[in] keyData Received keyboard input. */ virtual void OnKey(const std::wstring& keyData); /** * @brief Application resize event. */ virtual void OnResize(const Vector2D&){}; friend class View; }; /** * @brief Global Application pointer. * * This gets assigned as soon as the Application class is instantiated. * * It's primary reason to exist is that some low-level ioctl callback functions * need to have access to the application, and the api does not allow for * passing parameters to the callback functions, which means, unfortunately, * that we have to rely on a global. That said- it's available for other use. */ extern std::weak_ptr TheApp; } // namespace neovision