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
|
#ifndef RALEIGH_W_ENTRY_H
#define RALEIGH_W_ENTRY_H
#include <raleigh/widget.h>
#include <libfont/fonts.h>
namespace raleigh {
class entry : public widget {
public:
//default_text's data is copied, so it's okay if it changes or if the memory is freed
entry(uint32_t rows, uint32_t cols, const char *default_text="",
const char *font="fixed-10", _pixel_t bg=RGB(ff, ff, ff),
_pixel_t fg=RGB(00, 00, 00), _pixel_t border_color=RGB(00, 00, 00));
void notify_window_change() override;
void paint(_pixel_t *pixbuf, uint32_t pitch) override;
void handle_click(coord window_coords, enum mouse_packet::mouse_button click_type, bool up) override;
void notify_has_opaque_parent(widget *parent) override;
void handle_key(struct key_packet kp) override;
void on_focus() override;
void on_unfocus() override;
private:
uint32_t rows;
uint32_t cols;
_pixel_t bg;
_pixel_t fg;
_pixel_t border_color;
struct font_info *fi;
char *data;
//line_indices[end_y + 1] == end_d
uint32_t *line_indices;
uint32_t cur_y;
uint32_t cur_x;
uint32_t cur_d;
//the row of the last character
uint32_t end_y;
//the column after the last character
uint32_t end_x;
//the index of the null terminator
uint32_t end_d;
bool first_paint;
bool has_focus;
bool had_focus_last_paint;
bool text_changed_since_last_paint;
uint32_t cur_y_last_paint;
uint32_t cur_x_last_paint;
uint32_t cur_d_last_paint;
//uses cur_x, not cur_d; sets both
//will not modify cur_y
void ensure_cursor_in_line();
void paint_text(_pixel_t *pixbuf, uint32_t pitch);
//sets line_indices[from_y + 1 .. end_y + 1], end_y, end_x and end_d
void get_indices(uint32_t from_y, uint32_t from_x, uint32_t from_d);
//these four return true on success, and do not send a paint request to the window
bool cursor_left();
bool cursor_right();
bool cursor_up();
bool cursor_down();
};
}
#endif
|