~strahinja/poe

ref: v1.4.7 poe/draw.h -rw-r--r-- 4.2 KiB
127f482cСтрахиња Радић po.c: Add licensing comment 9 months ago
                                                                                
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* See the file LICENSE for copyright and license details. */
#include <stddef.h>
#include <termios.h>
#include <unistd.h>
#include <wchar.h>

#define TB_OPT_V1_COMPAT
#include "termbox.h"

#define BORDER_NW  ((uint32_t)L'\u250c')
#define BORDER_NE  ((uint32_t)L'\u2510')
#define BORDER_SW  ((uint32_t)L'\u2514')
#define BORDER_SE  ((uint32_t)L'\u2518')
#define BORDER_VER ((uint32_t)L'\u2502')
#define BORDER_HOR ((uint32_t)L'\u2500')

#define EDIT_WIDTH    70
#define EDIT_HEIGHT   20
#define HELP_WIDTH    50
#define HELP_HEIGHT   22
#define SEARCH_WIDTH  20
#define SEARCH_HEIGHT 4
#define TAB_SIZE      8
#define MAXSEARCH     (512 + 1)

typedef enum { LEFT, CENTER, RIGHT } Alignment;

typedef enum { UNCHANGED, SET, CLEARED } FlagChange;

struct BufferLine {
	uint32_t* text;
	size_t length;
	uint16_t fg;
	uint16_t bg;
};

struct DrawState {
	char* error;
	char* prompt;
	char* filename;
	uint32_t* search;
	struct BufferLine* input_buffer; /* edit box */
	int input_column;
	int input_row;
	int input_first_shown_column;
	int input_first_shown_row;
	int input_rows_count;
	int input_display_column;
	FlagChange input_changed_fuzzy;
	int saved_column;
	struct BufferLine* info_buffer; /* information pane above
					 * edit box */
	int info_first_shown_column;
	int info_first_shown_row;
	int info_rows_count;
	int info_rows_maxlen;
	int help_width;
	int edit_width;
	int search_width;
	struct BufferLine* paste_buffer;
	int paste_rows_count;
	int search_column;
	int search_first_shown_column;
	int search_display_column;
	struct PoEntry* entries;
	long nplurals;
	void (*prompt_callback)(struct DrawState*, struct tb_event*);
	int running;
	int dirty;
	int dirty_before_edit;
	size_t fuzzy_before_edit;
	int in_prompt;
	int show_help;
	int show_edit;
	int edit_info_focused;
	int show_search;
	int maxx;
	int maxy;
	size_t msgid_number;
	size_t msgid_count;
	size_t msgid_size;
	size_t fuzzy_count;
	size_t untranslated_count;
	size_t obsolete_count;
	size_t real_msgid_count; /* msgid_count + obsolete_count */
	int msgstr_index;	 /* with msgstr[] */
	size_t first_shown_msgid;
};

struct Key {
	struct tb_event ev;
	int (*callback)(struct DrawState*);
};

struct StatusSegment {
	const char* format;
	void (*callback)(char*, size_t, const char*, const struct DrawState*);
	uint16_t fg;
	uint16_t bg;
	Alignment alignment;
};

extern struct PoEntry* entries;

void init_bufferline(struct BufferLine* bl);
void free_bufferline(struct BufferLine* bl);
void init_drawstate(struct DrawState* state, char* error, char* filename,
	char* prompt);
void free_drawstate(struct DrawState* state);
struct DrawState* set_nplurals(struct DrawState* state, struct PoEntry* entry);
size_t display_length(const struct DrawState* state, uint32_t* buffer,
	const size_t max_index);
size_t input_length(const struct DrawState* state, uint32_t* buffer,
	const size_t max_index);
int calculate_help_width(const struct DrawState* state);
int calculate_edit_width(const struct DrawState* state);
int calculate_search_width(const struct DrawState* state);
void draw_rect(const int startx, const int endx, const int starty,
	const int endy, const uint16_t fg, const uint16_t bg);
void draw_box(const int startx, const int endx, const int starty,
	const int endy, const uint16_t fg, const uint16_t bg);
const char* draw_string(const int x, const int y, const uint16_t fg,
	const uint16_t bg, const char* s, const int max_cols,
	const int fill_cols, const int padding_left, const int padding_right,
	const Alignment align, const int ds, const int fill,
	const uint32_t* srch, const uint16_t sfg, const uint16_t sbg);
void u32_draw_string(const int x, const int y, const uint16_t fg,
	const uint16_t bg, const uint32_t* s, const int max_cols,
	const int fill_cols, const int padding_left, const int padding_right,
	const Alignment align, const int ds, const int fill,
	const uint32_t* srch, const uint16_t sfg, const uint16_t sbg);
const struct DrawState* draw_help(const struct DrawState* state);
const struct DrawState* draw_editbox(const struct DrawState* state);
const struct DrawState* draw_search(const struct DrawState* state);
const struct DrawState* draw_status(const struct DrawState* state);
const struct DrawState* draw_list_visible(const struct DrawState* state);
const struct DrawState* draw(const struct DrawState* state);