2021-08-06 14:22:56 +02:00
|
|
|
#ifndef BWIDGETS_WIDGET_HPP
|
|
|
|
#define BWIDGETS_WIDGET_HPP
|
2021-06-03 19:14:02 +02:00
|
|
|
|
2021-08-10 23:48:19 +02:00
|
|
|
#include <memory>
|
|
|
|
|
2021-07-18 18:26:12 +02:00
|
|
|
#include <basic_widgets/core/renderer.hpp>
|
2021-07-20 15:20:46 +02:00
|
|
|
#include <basic_widgets/core/type/size.hpp>
|
2021-08-17 17:59:34 +02:00
|
|
|
#include <basic_widgets/w/feat/event_handler.hpp>
|
2021-06-03 19:14:02 +02:00
|
|
|
|
2021-07-18 18:26:12 +02:00
|
|
|
union SDL_Event;
|
2021-07-16 17:18:13 +02:00
|
|
|
|
2021-07-10 19:55:53 +02:00
|
|
|
struct SDL_Renderer;
|
|
|
|
|
2021-08-06 14:22:56 +02:00
|
|
|
namespace bwidgets
|
2021-06-03 19:14:02 +02:00
|
|
|
{
|
2021-08-17 17:59:34 +02:00
|
|
|
class Widget : public virtual EventHandler
|
2021-06-13 15:44:11 +02:00
|
|
|
{
|
2021-07-29 16:06:03 +02:00
|
|
|
public:
|
2021-08-23 23:50:14 +02:00
|
|
|
// Parent widget for bidirectional message passing between widgets.
|
2021-08-27 01:21:25 +02:00
|
|
|
// Currently not used by this lib.
|
2021-07-29 16:06:03 +02:00
|
|
|
Widget* parent;
|
|
|
|
|
2021-08-15 20:04:53 +02:00
|
|
|
explicit Widget(Widget* p = nullptr) noexcept : parent {p} {}
|
2021-08-06 14:22:56 +02:00
|
|
|
|
2021-08-23 23:50:14 +02:00
|
|
|
// Render widget on current renderer target.
|
2021-08-17 00:27:51 +02:00
|
|
|
virtual void render() = 0;
|
2021-08-23 23:50:14 +02:00
|
|
|
// Set widget renderer.
|
2021-08-17 00:27:51 +02:00
|
|
|
virtual void renderer(std::shared_ptr<Renderer>) = 0;
|
2021-08-23 23:50:14 +02:00
|
|
|
// Get prefered or minimal widget size.
|
2021-08-19 15:00:44 +02:00
|
|
|
[[nodiscard]] virtual auto size() const noexcept -> Size = 0;
|
2021-08-27 01:21:25 +02:00
|
|
|
// Set the viewport delimiting the widget rendering area and the origin
|
2021-08-23 23:50:14 +02:00
|
|
|
// for relative coordinates.
|
2021-08-17 00:27:51 +02:00
|
|
|
virtual void viewport(const SDL_Rect&) = 0;
|
2021-08-23 23:50:14 +02:00
|
|
|
// Get current viewport.
|
2021-08-17 00:27:51 +02:00
|
|
|
[[nodiscard]] virtual auto viewport() const -> const SDL_Rect& = 0;
|
2021-07-10 19:55:53 +02:00
|
|
|
};
|
|
|
|
}
|
2021-06-03 19:14:02 +02:00
|
|
|
|
|
|
|
#endif
|