C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
ui_notcurses_draw.c File Reference

NotCurses UI backend — drawing functions. More...

#include "ui_backend.h"
#include "ui_notcurses_internal.h"
#include <notcurses/notcurses.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for ui_notcurses_draw.c:

Go to the source code of this file.

Macros

#define _GNU_SOURCE
#define _XOPEN_SOURCE_EXTENDED   1

Functions

int mk_chimera (UiCell *cell, char c)
int ui_draw_ch (UiSurface *s, uint w, char c)
int ui_draw_ch_yx (UiSurface *s, uint w, uint y, uint x, char c)
int ui_draw_text (UiSurface *s, uint w, uint y, uint x, const char *text)
int ui_draw_text_fill (UiSurface *s, uint w, uint y, uint x, const char *text, int m)
int ui_draw_text_n (UiSurface *s, uint w, uint y, uint x, const char *text, int m)
int ui_mvwadd_wch (UiSurface *s, uint w, uint y, uint x, const UiCell *cell)
int ui_mvwadd_wchnstr (UiSurface *s, uint w, uint y, uint x, const UiCell *cell, uint m)
int ui_mvwadd_wchstr (UiSurface *s, uint w, uint y, uint x, const UiCell *cell)
int ui_mvwaddch (UiSurface *s, uint w, uint y, uint x, const char c)
int ui_mvwaddnstr (UiSurface *s, uint w, uint y, uint x, const char *text, int m)
int ui_mvwaddnwstr (UiSurface *s, uint w, uint y, uint x, const wchar_t *wstr, int m)
int ui_mvwaddstr (UiSurface *s, uint w, uint y, uint x, const char *text)
int ui_mvwaddstr_fill (UiSurface *s, uint w, uint y, uint x, const char *text, int m)
int ui_mvwaddwstr (UiSurface *s, uint w, uint y, uint x, const wchar_t *wstr)
void ui_restore_wins ()
int ui_wadd_wch (UiSurface *s, uint w, const UiCell *cell)
int ui_wadd_wchnstr (UiSurface *s, uint w, const UiCell *cell, uint m)
int ui_wadd_wchstr (UiSurface *s, uint w, const UiCell *cell)
int ui_waddnstr (UiSurface *s, uint w, const char *text, int m)
int ui_waddnwstr (UiSurface *s, uint w, const wchar_t *wstr, int m)
int ui_waddstr (UiSurface *s, uint w, const char *text)
int ui_waddwstr (UiSurface *s, uint w, const wchar_t *wstr)
int ui_wclrtobot (UiSurface *s, uint w)
int ui_wclrtoeol (UiSurface *s, uint w)

Detailed Description

NotCurses UI backend — drawing functions.

Implements the drawing operations declared in ui_backend.h using the NotCurses API.

Definition in file ui_notcurses_draw.c.

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE

Definition at line 8 of file ui_notcurses_draw.c.

◆ _XOPEN_SOURCE_EXTENDED

#define _XOPEN_SOURCE_EXTENDED   1

Definition at line 9 of file ui_notcurses_draw.c.

Function Documentation

◆ mk_chimera()

int mk_chimera ( UiCell * cell,
char c )

Definition at line 52 of file ui_notcurses_draw.c.

52 {
53 cell->gcluster = c;
54 cell->gcluster_backstop = 0;
55 cell->stylemask = bkgd_cell.stylemask;
56 cell->channels = bkgd_cell.channels;
57 return 0;
58}
UiCell bkgd_cell

References bkgd_cell, nccell::channels, nccell::gcluster, nccell::gcluster_backstop, and nccell::stylemask.

◆ ui_draw_ch()

int ui_draw_ch ( UiSurface * s,
uint w,
char c )

Definition at line 59 of file ui_notcurses_draw.c.

59 {
60 if (!s || !c)
61 return -1;
63 ncplane_putc_yx(s->mplane[w], -1, -1, &cell);
64 return 0;
65}
#define DEFAULT_INITIALIZER(c)
Definition ui_backend.h:279
struct ncplane * mplane[SUB_SFC_MAX]
Definition nccell.h:3

◆ ui_draw_ch_yx()

int ui_draw_ch_yx ( UiSurface * s,
uint w,
uint y,
uint x,
char c )

Definition at line 66 of file ui_notcurses_draw.c.

66 {
67 if (!s || !c)
68 return -1;
70 ncplane_putc_yx(s->mplane[w], y, x, &cell);
71 return 0;
72}

Referenced by menu_cmd_processor().

Here is the caller graph for this function:

◆ ui_draw_text()

int ui_draw_text ( UiSurface * s,
uint w,
uint y,
uint x,
const char * text )

Definition at line 73 of file ui_notcurses_draw.c.

73 {
74 if (!s || !text)
75 return -1;
76 ncplane_putstr_yx(s->mplane[w], y, x, text);
77 return 0;
78}

Referenced by action_disposition(), answer_yn(), display_error(), and Perror().

Here is the caller graph for this function:

◆ ui_draw_text_fill()

int ui_draw_text_fill ( UiSurface * s,
uint w,
uint y,
uint x,
const char * text,
int m )

Definition at line 85 of file ui_notcurses_draw.c.

85 {
86 if (!s || !text)
87 return -1;
88 char tmp_str[MAXLEN];
89 strncpy(tmp_str, text, m);
90 int l = strlen(text);
91 for (int i = l; i < m; i++) {
92 tmp_str[i] = ' ';
93 }
94 tmp_str[m] = '\0';
95 ncplane_putnstr_yx(s->mplane[w], y, x, m, tmp_str);
96 ui_render();
97 return 0;
98}
void ui_render()
Definition ui_ncurses.c:800
#define MAXLEN
Definition curskeys.c:15

References ui_render().

Referenced by menu_cmd_processor(), and menu_engine().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ui_draw_text_n()

int ui_draw_text_n ( UiSurface * s,
uint w,
uint y,
uint x,
const char * text,
int m )

Definition at line 79 of file ui_notcurses_draw.c.

79 {
80 if (!s || !text)
81 return -1;
82 ncplane_putnstr_yx(s->mplane[w], y, x, m, text);
83 return 0;
84}

◆ ui_mvwadd_wch()

int ui_mvwadd_wch ( UiSurface * s,
uint w,
uint y,
uint x,
const UiCell * cell )

Definition at line 208 of file ui_notcurses_draw.c.

208 {
209 if (!s)
210 return -1;
211 ncplane_putc_yx(s->mplane[w], y, x, cell);
212 return 0;
213}

Referenced by display_form(), and get_cmd_char().

Here is the caller graph for this function:

◆ ui_mvwadd_wchnstr()

int ui_mvwadd_wchnstr ( UiSurface * s,
uint w,
uint y,
uint x,
const UiCell * cell,
uint m )

Definition at line 240 of file ui_notcurses_draw.c.

240 {
241 if (!s)
242 return -1;
243 ui_wmove(s, w, y, x);
244 uint cols = 0;
245 while (cell->gcluster != 0 && cols < m) {
246 ncplane_putc(s->mplane[w], cell++);
247 cols += cell->width;
248 }
249 return 0;
250}
int ui_wmove(UiSurface *s, uint w, uint y, uint x)
Definition ui_ncurses.c:732

References nccell::gcluster, ui_wmove(), and nccell::width.

Referenced by border_draw(), border_title(), border_ysplit(), border_ysplit_text(), deselect_object(), form_display_accept_field(), form_display_field(), form_display_fields(), get_cmd_arg(), get_cmd_char(), picker(), remove_right_angle(), reverse_object(), toggle_object(), unreverse_object(), and view_cmd_processor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ui_mvwadd_wchstr()

int ui_mvwadd_wchstr ( UiSurface * s,
uint w,
uint y,
uint x,
const UiCell * cell )

Definition at line 221 of file ui_notcurses_draw.c.

221 {
222 if (!s)
223 return -1;
224 ui_wmove(s, w, y, x);
225 while (cell->gcluster != 0)
226 ncplane_putc(s->mplane[w], cell++);
227 return 0;
228}

References nccell::gcluster, and ui_wmove().

Referenced by display_chyron(), display_field(), display_line(), and form_display_fields().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ui_mvwaddch()

int ui_mvwaddch ( UiSurface * s,
uint w,
uint y,
uint x,
const char c )

Definition at line 100 of file ui_notcurses_draw.c.

100 {
101 if (!s || !c)
102 return -1;
103 ui_wmove(s, w, y, x);
104 nccell cell = DEFAULT_INITIALIZER(c);
105 ncplane_putc_yx(s->mplane[w], -1, -1, &cell);
106 return 0;
107}

References ui_wmove().

Referenced by get_cmd_char(), and menu_engine().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ui_mvwaddnstr()

int ui_mvwaddnstr ( UiSurface * s,
uint w,
uint y,
uint x,
const char * text,
int m )

Definition at line 126 of file ui_notcurses_draw.c.

126 {
127 if (!s || !text)
128 return -1;
129 ncplane_putnstr_yx(s->mplane[w], y, x, m, text);
130 return 0;
131}

◆ ui_mvwaddnwstr()

int ui_mvwaddnwstr ( UiSurface * s,
uint w,
uint y,
uint x,
const wchar_t * wstr,
int m )

Definition at line 182 of file ui_notcurses_draw.c.

182 {
183 if (!s || !wstr)
184 return -1;
185 int cols = 0;
186 int width;
187 while (*wstr != L'\0') {
188 width = wcwidth(*wstr);
189 if (width < 0)
190 width = 0;
191 if (cols + width > m)
192 break;
193 ncplane_putwc_yx(s->mplane[w], y, x++, *wstr++);
194 cols += wcwidth(*wstr);
195 }
196 return 0;
197}

Referenced by border_title(), and border_ysplit_text().

Here is the caller graph for this function:

◆ ui_mvwaddstr()

int ui_mvwaddstr ( UiSurface * s,
uint w,
uint y,
uint x,
const char * text )

Definition at line 120 of file ui_notcurses_draw.c.

120 {
121 if (!s || !text)
122 return -1;
123 ncplane_putstr_yx(s->mplane[w], y, x, text);
124 return 0;
125}

Referenced by cf_accept(), display_form(), display_line(), display_pick_page(), display_prompt(), display_split_line(), notcurses_input(), pick_engine(), picker(), and popup_ckeys().

Here is the caller graph for this function:

◆ ui_mvwaddstr_fill()

int ui_mvwaddstr_fill ( UiSurface * s,
uint w,
uint y,
uint x,
const char * text,
int m )

Definition at line 132 of file ui_notcurses_draw.c.

132 {
133 if (!s || !text)
134 return -1;
135 int l = strlen(text);
136 if (l <= m) {
137 char *tmp_str = (char *)malloc(m + 1);
138 if (!tmp_str)
139 return -1;
140 strcpy(tmp_str, text);
141 for (int i = l; i < (int)m; i++) {
142 tmp_str[i] = ' ';
143 }
144 tmp_str[m] = '\0';
145 ncplane_putnstr_yx(s->mplane[w], y, x, m, tmp_str);
146 free(tmp_str);
147 }
148 return 0;
149}

Referenced by display_pick_page(), picker(), reverse_object(), and unreverse_object().

Here is the caller graph for this function:

◆ ui_mvwaddwstr()

int ui_mvwaddwstr ( UiSurface * s,
uint w,
uint y,
uint x,
const wchar_t * wstr )

Definition at line 160 of file ui_notcurses_draw.c.

160 {
161 if (!s || !wstr)
162 return -1;
163 while (*wstr != L'\0')
164 ncplane_putwc_yx(s->mplane[w], y, x++, *wstr++);
165 return 0;
166}

◆ ui_restore_wins()

void ui_restore_wins ( )

Definition at line 255 of file ui_notcurses_draw.c.

255 {
256 // for (int s = 0; s <= sfc_ptr; s++) {
257 // for (int w = 0; w < 8; w++)
258 // if (ui_surface[s]->mplane[w] != nullptr)
259 // // touchwin(ui_surface[s]->mplane[w]);
260 // }
261 // ui_render(ui);
262}

References sfc_ptr, SUB_SFC_MAX, ui_render(), and ui_surface.

Referenced by enter_file_spec(), exec_objects(), fork_exec(), form_exec_receiver(), full_screen_shell(), menu_cmd_processor(), menu_engine(), view_cmd_processor(), view_init_input(), and write_view_buffer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ui_wadd_wch()

int ui_wadd_wch ( UiSurface * s,
uint w,
const UiCell * cell )

Definition at line 202 of file ui_notcurses_draw.c.

202 {
203 if (!s)
204 return -1;
205 ncplane_putc(s->mplane[w], cell);
206 return 0;
207}

◆ ui_wadd_wchnstr()

int ui_wadd_wchnstr ( UiSurface * s,
uint w,
const UiCell * cell,
uint m )

Definition at line 229 of file ui_notcurses_draw.c.

229 {
230 if (!s)
231 return -1;
232 uint cols = 0;
233 while (cell->gcluster != 0 && cols < m) {
234 ncplane_putc(s->mplane[w], cell++);
235 cols += cell->width;
236 }
237 return 0;
238}

References nccell::gcluster, and nccell::width.

Referenced by display_split_line().

Here is the caller graph for this function:

◆ ui_wadd_wchstr()

int ui_wadd_wchstr ( UiSurface * s,
uint w,
const UiCell * cell )

Definition at line 214 of file ui_notcurses_draw.c.

214 {
215 if (!s)
216 return -1;
217 while (cell->gcluster != 0)
218 ncplane_putc(s->mplane[w], cell++);
219 return 0;
220}

References nccell::gcluster.

◆ ui_waddnstr()

int ui_waddnstr ( UiSurface * s,
uint w,
const char * text,
int m )

Definition at line 114 of file ui_notcurses_draw.c.

114 {
115 if (!s || !text)
116 return -1;
117 ncplane_putnstr(s->mplane[w], m, text);
118 return 0;
119}

◆ ui_waddnwstr()

int ui_waddnwstr ( UiSurface * s,
uint w,
const wchar_t * wstr,
int m )

Definition at line 167 of file ui_notcurses_draw.c.

167 {
168 if (!s || !wstr)
169 return -1;
170 int cols = 0;
171 int width;
172 while (*wstr != L'\0') {
173 width = wcwidth(*wstr);
174 if (width < 0)
175 width = 0;
176 if (cols + width > m)
177 break;
178 ncplane_putwc_yx(s->mplane[w], -1, -1, *wstr++);
179 }
180 return 0;
181}

◆ ui_waddstr()

int ui_waddstr ( UiSurface * s,
uint w,
const char * text )

Definition at line 108 of file ui_notcurses_draw.c.

108 {
109 if (!s || !text)
110 return -1;
111 ncplane_putstr(s->mplane[w], text);
112 return 0;
113}

Referenced by display_prompt(), and get_cmd_arg().

Here is the caller graph for this function:

◆ ui_waddwstr()

int ui_waddwstr ( UiSurface * s,
uint w,
const wchar_t * wstr )

Definition at line 153 of file ui_notcurses_draw.c.

153 {
154 if (!s || !wstr)
155 return -1;
156 while (*wstr != L'\0')
157 ncplane_putwc_yx(s->mplane[w], -1, -1, *wstr++);
158 return 0;
159}

◆ ui_wclrtobot()

int ui_wclrtobot ( UiSurface * s,
uint w )

Definition at line 34 of file ui_notcurses_draw.c.

34 {
35 if (!s)
36 return -1;
37 uint y, x, ylen, xlen, maxy, maxx;
38 ncplane_cursor_yx(s->mplane[w], &y, &x);
39 ncplane_dim_yx(s->mplane[w], &maxy, &maxx);
40 xlen = maxx - x;
41 ylen = 1;
42 ncplane_erase_region(s->mplane[w], y, x, ylen, xlen);
43 ylen = maxy - y - 1;
44 xlen = maxx;
45 ncplane_erase_region(s->mplane[w], y + 1, x = 0, ylen, maxx);
46 return 0;
47}

Referenced by display_line_eod(), scroll_down(), scroll_up(), and search().

Here is the caller graph for this function:

◆ ui_wclrtoeol()

int ui_wclrtoeol ( UiSurface * s,
uint w )

Definition at line 22 of file ui_notcurses_draw.c.

22 {
23 if (!s)
24 return -1;
25 uint y, x, ylen, xlen, maxy, maxx;
26 ncplane_cursor_yx(s->mplane[w], &y, &x);
27 ncplane_dim_yx(s->mplane[w], &maxy, &maxx);
28 xlen = maxx - x;
29 ylen = 1;
30 ncplane_erase_region(s->mplane[w], y, x, ylen, xlen);
31 return 0;
32}

Referenced by cf_accept(), display_chyron(), display_line(), display_prompt(), display_split_line(), form_post(), get_cmd_arg(), get_cmd_char(), notcurses_input(), pick_engine(), and picker().

Here is the caller graph for this function: