forked from mika314/texteditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
widget.hpp
79 lines (77 loc) · 2.09 KB
/
widget.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#pragma once
#include "paint_device.hpp"
#include "layoutable.hpp"
#include <SDL2/SDL.h>
#include <vector>
class KeyEvent;
class TextInputEvent;
class MouseEvent;
struct ResizeEvent;
class PaintEvent;
class Layout;
struct SDL_Window;
struct SDL_Renderer;
class Widget: public PaintDevice, public Layoutable
{
friend class Application;
public:
Widget(Widget *parent = nullptr);
virtual ~Widget();
virtual void resize(int width, int height);
int width() const;
void setWidth(int);
int height() const;
void setHeight(int);
int left() const;
virtual void setLeft(int);
int top() const;
virtual void setTop(int);
Widget *parent() const;
Widget *ancestor();
void setFocus();
void clearFocus();
bool hasFocus();
const std::vector<Widget *> &children() const;
Uint32 windowId() const;
virtual SDL_Renderer *renderer();
virtual int gLeft() const;
virtual int gTop() const;
void update();
void setLayout(Layout *);
Layout *layout();
const Layout *layout() const;
virtual int maxHeight() const;
virtual int minHeight() const;
virtual int maxWidth() const;
virtual int minWidth() const;
protected:
// some of following events handlers return bool, true means event handled and does not require handling from the parent object
virtual bool keyPressEvent(KeyEvent &);
virtual bool keyReleaseEvent(KeyEvent &);
virtual bool textInputEvent(TextInputEvent &);
virtual bool mouseDoubleClickEvent(MouseEvent &);
virtual bool mouseMoveEvent(MouseEvent &);
virtual bool mousePressEvent(MouseEvent &);
virtual bool mouseReleaseEvent(MouseEvent &);
virtual void paintEvent(PaintEvent &);
virtual void resizeEvent(ResizeEvent &);
private:
SDL_Window *window_;
Widget *parent_;
std::vector<Widget *> children_;
SDL_Renderer *renderer_;
SDL_Texture *texture_;
int width_;
int height_;
int left_;
int top_;
bool needRepaint_;
Layout *layout_;
void addChild(Widget *);
void removeChild(Widget *);
void internalPaint(PaintEvent &);
void updateWithoutRedraw();
Widget(const Widget &);
Widget &operator=(const Widget &);
bool needRepaint() const;
};