bwidgets/inc/basic_widgets/abstract/widget.hpp

44 lines
1.1 KiB
C++
Raw Normal View History

2021-06-03 19:14:02 +02:00
#ifndef WIDGET_HPP
#define WIDGET_HPP
2021-06-07 10:26:31 +02:00
#include <functional>
2021-06-03 19:14:02 +02:00
#include <SDL2/SDL.h>
class Widget
{
protected:
2021-06-16 18:09:14 +02:00
bool _focused = false;
2021-06-07 10:26:31 +02:00
bool _hovered = false;
bool _pushed = false;
2021-06-03 19:14:02 +02:00
SDL_Renderer* _renderer;
SDL_Rect _viewport {0, 0, 0, 0};
SDL_Rect _widget_area {0, 0, 0, 0};
2021-06-07 10:26:31 +02:00
2021-06-20 00:42:40 +02:00
virtual void _on_focus();
virtual void _on_focus_loss();
virtual void _on_key(const SDL_KeyboardEvent&);
2021-06-08 14:30:38 +02:00
virtual void _on_push(const SDL_MouseButtonEvent&);
virtual void _on_release(const SDL_MouseButtonEvent&);
2021-06-20 00:42:40 +02:00
virtual void _on_text_input(const SDL_TextInputEvent&);
2021-06-08 14:30:38 +02:00
virtual void _update_hover_state(const SDL_MouseMotionEvent&);
virtual void _update_widget_area();
2021-06-03 19:14:02 +02:00
public:
2021-06-07 10:26:31 +02:00
std::function<void (const SDL_MouseButtonEvent&)> click_handler = NULL;
2021-06-08 14:30:38 +02:00
Widget(SDL_Renderer*);
virtual ~Widget();
2021-06-13 15:44:11 +02:00
static inline int center(int available_size, int used_size)
{
return (available_size - used_size) / 2;
2021-06-13 15:44:11 +02:00
}
2021-06-08 14:30:38 +02:00
virtual void handle_event(const SDL_Event&);
virtual int height() const;
2021-06-08 14:30:38 +02:00
virtual void render();
virtual void viewport(SDL_Rect);
virtual int width() const;
2021-06-03 19:14:02 +02:00
};
#endif