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

NCurses UI backend — drawing functions. More...

#include "cm.h"
#include "ui_backend.h"
#include "ui_ncurses_internal.h"
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
Include dependency graph for ui_ncurses_draw.c:

Go to the source code of this file.

Macros

#define _XOPEN_SOURCE_EXTENDED   1

Functions

int ui_draw_ch (UiSurface *s, ss_t w, const char c)
 Draw a character in a surface window.
int ui_draw_ch_yx (UiSurface *s, ss_t w, uint y, uint x, const char c)
 Draw a character at a specific position in a surface window.
int ui_draw_text (UiSurface *s, ss_t w, uint y, uint x, const char *text)
 on specified window, move to y, x, add string
int ui_draw_text_fill (UiSurface *s, ss_t w, uint y, uint x, const char *text, int n)
 Draw a text string at a specific position in a surface window, filling the remaining space with spaces if the string is shorter than n.
int ui_draw_text_n (UiSurface *s, ss_t w, uint y, uint x, const char *text, int n)
 Draw a text string at a specific position in a surface window.
int ui_mvwadd_wch (UiSurface *s, ss_t w, uint y, uint x, const UiCell *cell)
 Draw a complex character at a specific position in a surface window.
int ui_mvwadd_wchnstr (UiSurface *s, ss_t w, uint y, uint x, const UiCell *cmplx_buf, uint n)
 Draw a complex character string at a specific position in a surface window, with a maximum length.
int ui_mvwadd_wchstr (UiSurface *s, ss_t w, uint y, uint x, const UiCell *cmplx_buf)
 Draw a complex character string at a specific position in a surface window.
int ui_mvwaddch (UiSurface *s, ss_t w, uint y, uint x, const char c)
 Draw a character in a surface window.
int ui_mvwaddnstr (UiSurface *s, ss_t w, uint y, uint x, const char *text, int m)
 Draw a text string at a specific position in a surface window, with a maximum length.
int ui_mvwaddnwstr (UiSurface *s, ss_t w, uint y, uint x, const wchar_t *wstr, int m)
 Draw a wide-character string at a specific position in a surface window, with a maximum length.
int ui_mvwaddstr (UiSurface *s, ss_t w, uint y, uint x, const char *text)
 Draw a text string at a specific position in a surface window.
int ui_mvwaddstr_fill (UiSurface *s, ss_t w, uint y, uint x, const char *str, int m)
 Draw a text string at a specific position in a surface window, filling the remaining space with spaces if the string is shorter than m.
int ui_mvwaddwstr (UiSurface *s, ss_t w, uint y, uint x, const wchar_t *wstr)
 Draw a wide-character string at a specific position in a surface window.
void ui_restore_wins ()
 Restore the state of all windows in the UI. This function refreshes the standard screen and all surface windows, ensuring that their contents are displayed correctly.
int ui_wadd_wch (UiSurface *s, ss_t w, const UiCell *cell)
 Draw a complex character in a surface window.
int ui_wadd_wchnstr (UiSurface *s, ss_t w, const UiCell *cmplx_buf, uint n)
 Draw a complex character string in a surface window, with a maximum length.
int ui_wadd_wchstr (UiSurface *s, ss_t w, const UiCell *cmplx_buf)
 Draw a complex character string in a surface window.
int ui_waddnstr (UiSurface *s, ss_t w, const char *text, int m)
 Draw a text string in a surface window, with a maximum length.
int ui_waddnwstr (UiSurface *s, ss_t w, const wchar_t *wstr, int m)
 Draw a wide-character string in a surface window, with a maximum length.
int ui_waddstr (UiSurface *s, ss_t w, const char *text)
 Draw a text string in a surface window.
int ui_waddwstr (UiSurface *s, ss_t w, const wchar_t *wstr)
 Draw a wide-character string in a surface window.
int ui_wclrtobot (UiSurface *s, ss_t w)
 Set the style of a surface window.
int ui_wclrtoeol (UiSurface *s, ss_t w)
 Clear to the end of the line in a surface window.

Detailed Description

NCurses UI backend — drawing functions.

Implements the drawing operations declared in ui_backend.h using the NCurses wide-character API.

Definition in file ui_ncurses_draw.c.

Macro Definition Documentation

◆ _XOPEN_SOURCE_EXTENDED

#define _XOPEN_SOURCE_EXTENDED   1

Definition at line 9 of file ui_ncurses_draw.c.

Function Documentation

◆ ui_draw_ch()

int ui_draw_ch ( UiSurface * s,
ss_t w,
const char c )

Draw a character in a surface window.

Parameters
sThe surface to modify.
wThe window index within the surface.
cThe character to draw.
Returns
0 on success, -1 on error.

Definition at line 53 of file ui_ncurses_draw.c.

53 {
54 if (!s)
55 return -1;
56 waddch(s->mwin[w], c);
57 return 0;
58}

◆ ui_draw_ch_yx()

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

Draw a character at a specific position in a surface window.

Parameters
sThe surface to modify.
wThe window index within the surface.
yThe y-coordinate (row) to draw the character.
xThe x-coordinate (column) to draw the character.
cThe character to draw.
Returns
0 on success, -1 on error.

Definition at line 67 of file ui_ncurses_draw.c.

67 {
68 if (!s)
69 return -1;
70 mvwaddch(s->mwin[w], y, x, c);
71 return 0;
72}

◆ ui_draw_text()

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

on specified window, move to y, x, add string

Parameters
ssurface
wwindow
yrow
xcolumn
textstring
Returns
0 on success, -1 on error

Definition at line 74 of file ui_ncurses_draw.c.

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

◆ ui_draw_text_fill()

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

Draw a text string at a specific position in a surface window, filling the remaining space with spaces if the string is shorter than n.

Parameters
sThe surface to modify.
wThe window index within the surface.
yThe y-coordinate (row) to draw the text.
xThe x-coordinate (column) to draw the text.
textThe text string to draw.
nThe number of characters to draw, padding with spaces if necessary.
Returns
0 on success, -1 on error.

Definition at line 103 of file ui_ncurses_draw.c.

103 {
104 if (!s || !text)
105 return -1;
106 uint l = strlen(text);
107 if (l < (uint)n) {
108 char *tmp_str = (char *)malloc(n + 1);
109 if (!tmp_str)
110 return -1;
111 strcpy(tmp_str, text);
112 for (int i = l; i < (int)n; i++) {
113 tmp_str[i] = ' ';
114 }
115 tmp_str[n] = '\0';
116 mvwaddstr(s->mwin[w], y, x, tmp_str);
117 free(tmp_str);
118 } else {
119 mvwaddnstr(s->mwin[w], y, x, text, (int)n);
120 }
121 return 0;
122}

◆ ui_draw_text_n()

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

Draw a text string at a specific position in a surface window.

Parameters
sThe surface to modify.
wThe window index within the surface.
yThe y-coordinate (row) to draw the text.
xThe x-coordinate (column) to draw the text.
textThe text string to draw.
Returns
0 on success, -1 on error.

Definition at line 88 of file ui_ncurses_draw.c.

88 {
89 if (!s || !text)
90 return -1;
91 mvwaddnstr(s->mwin[w], y, x, text, (int)n);
92 return 0;
93}

◆ ui_mvwadd_wch()

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

Draw a complex character at a specific position in a surface window.

on specified window, move to y, x, add cell

Parameters
sThe surface to modify.
wThe window index within the surface.
yThe y-coordinate (row) to draw the complex character.
xThe x-coordinate (column) to draw the complex character.
cellThe complex character (UiCell) to draw.
Returns
0 on success, -1 on error.
Parameters
ssurface
wwindow
yrow
xcolumn
cellcell string
Returns
0 on success, -1 on error

Definition at line 305 of file ui_ncurses_draw.c.

305 {
306 if (!s)
307 return -1;
308 mvwadd_wch(s->mwin[w], y, x, cell);
309 return 0;
310}

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,
ss_t w,
uint y,
uint x,
const UiCell * cell,
uint m )

Draw a complex character string at a specific position in a surface window, with a maximum length.

on specified window, move to y, x, add cell string, at most m columns

Parameters
sThe surface to modify.
wThe window index within the surface.
yThe y-coordinate (row) to draw the complex character string.
xThe x-coordinate (column) to draw the complex character string.
cmplx_bufThe complex character string (array of UiCell) to draw.
nThe maximum number of complex characters to draw from the complex character string.
Returns
0 on success, -1 on error.
Parameters
ssurface
wwindow
yrow
xcolumn
cellcell string
mmaximum number of columns to write
Returns
0 on success, -1 on error

Definition at line 359 of file ui_ncurses_draw.c.

359 {
360 if (!s || !cmplx_buf)
361 return -1;
362 mvwadd_wchnstr(s->mwin[w], y, x, cmplx_buf, n);
363 return 0;
364}

Referenced by 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(), ui_border_draw(), ui_border_title(), ui_border_ysplit(), ui_border_ysplit_text(), unreverse_object(), and view_cmd_processor().

Here is the caller graph for this function:

◆ ui_mvwadd_wchstr()

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

Draw a complex character string at a specific position in a surface window.

on specified window, move to y, x, add cell string

Parameters
sThe surface to modify.
wThe window index within the surface.
yThe y-coordinate (row) to draw the complex character string.
xThe x-coordinate (column) to draw the complex character string.
cmplx_bufThe complex character string (array of UiCell) to draw.
Returns
0 on success, -1 on error.
Parameters
ssurface
wwindow
yrow
xcolumn
cellcell string
Returns
0 on success, -1 on error

Definition at line 331 of file ui_ncurses_draw.c.

331 {
332 if (!s || !cmplx_buf)
333 return -1;
334 mvwadd_wchstr(s->mwin[w], y, x, cmplx_buf);
335 return 0;
336}

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

Here is the caller graph for this function:

◆ ui_mvwaddch()

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

Draw a character in a surface window.

on specified window, move to y, x, add character

Parameters
sThe surface to modify.
wThe window index within the surface.
cThe character to draw.
Returns
0 on success, -1 on error.
Parameters
ssurface
wwindow
yrow
xcolumn
ccharacter
Returns
0 on success, -1 on error

Definition at line 132 of file ui_ncurses_draw.c.

132 {
133 if (!s)
134 return -1;
135 mvwaddch(s->mwin[w], y, x, c);
136 return 0;
137}

Referenced by get_cmd_char(), and menu_engine().

Here is the caller graph for this function:

◆ ui_mvwaddnstr()

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

Draw a text string at a specific position in a surface window, with a maximum length.

on specified window, move to y, x, add string, at most m columns

Parameters
sThe surface to modify.
wThe window index within the surface.
yThe y-coordinate (row) to draw the text.
xThe x-coordinate (column) to draw the text.
textThe text string to draw.
mThe maximum number of characters to draw from the text string.
Returns
0 on success, -1 on error.
Parameters
ssurface
wwindow
yrow
xcolumn
textstring
mmaximum number of columns to write
Returns
0 on success, -1 on error

Definition at line 189 of file ui_ncurses_draw.c.

189 {
190 if (!s || !text)
191 return -1;
192 mvwaddnstr(s->mwin[w], y, x, text, m);
193 return 0;
194}

◆ ui_mvwaddnwstr()

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

Draw a wide-character string at a specific position in a surface window, with a maximum length.

on specified window, move to y, x, add string, at most m columns

Parameters
sThe surface to modify.
wThe window index within the surface.
yThe y-coordinate (row) to draw the wide-character string.
xThe x-coordinate (column) to draw the wide-character string.
wstrThe wide-character string to draw.
mThe maximum number of wide characters to draw from the wide-character string.
Returns
0 on success, -1 on error.
Parameters
ssurface
wwindow
yrow
xcolumn
wchar_tstring
mmaximum number of columns to write
Returns
0 on success, -1 on error

Definition at line 276 of file ui_ncurses_draw.c.

276 {
277 if (!s || !wstr)
278 return -1;
279 mvwaddnwstr(s->mwin[w], y, x, wstr, m);
280 return 0;
281}

Referenced by ui_border_title(), and ui_border_ysplit_text().

Here is the caller graph for this function:

◆ ui_mvwaddstr()

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

Draw a text string at a specific position in a surface window.

on specified window, move to y, x, add string

Parameters
sThe surface to modify.
wThe window index within the surface.
yThe y-coordinate (row) to draw the text.
xThe x-coordinate (column) to draw the text.
textThe text string to draw.
Returns
0 on success, -1 on error.
Parameters
ssurface
wwindow
yrow
xcolumn
textstring
Returns
0 on success, -1 on error

Definition at line 174 of file ui_ncurses_draw.c.

174 {
175 if (!s || !text)
176 return -1;
177 mvwaddstr(s->mwin[w], y, x, text);
178 return 0;
179}

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

Here is the caller graph for this function:

◆ ui_mvwaddstr_fill()

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

Draw a text string at a specific position in a surface window, filling the remaining space with spaces if the string is shorter than m.

on specified window, move to y, x, add string, at most m columns, fill with spaces if text is shorter than m

Parameters
sThe surface to modify.
wThe window index within the surface.
yThe y-coordinate (row) to draw the text.
xThe x-coordinate (column) to draw the text.
strThe text string to draw.
mThe number of characters to draw, padding with spaces if necessary.
Returns
0 on success, -1 on error.
Parameters
ssurface
wwindow
yrow
xcolumn
textstring
mmaximum number of columns to write
Returns
0 on success, -1 on error

Definition at line 204 of file ui_ncurses_draw.c.

204 {
205 char *d, *e;
206 uint maxy, maxx;
207 char tmp_str[MAXLEN];
208 getmaxyx(s->mwin[w], maxy, maxx);
209 y = min(y, maxy);
210 m = min(m, maxx);
211 m = min(m, (uint)MAXLEN - 1);
212 e = d = tmp_str;
213 e += m;
214 while (d < e) {
215 if (*str == '\0' || *str == '\n')
216 *d++ = ' ';
217 else
218 *d++ = *str++;
219 }
220 *d = '\0';
221 m = strlen(tmp_str);
222 mvwaddnstr(s->mwin[w], y, x, tmp_str, m);
223 return 0;
224}
#define min(x, y)
min macro evaluates two expressions, returning least result
Definition cm.h:104
#define MAXLEN
Definition curskeys.c:15

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,
ss_t w,
uint y,
uint x,
const wchar_t * wstr )

Draw a wide-character string at a specific position in a surface window.

on specified window, move to y, x, add wchar_t string

Parameters
sThe surface to modify.
wThe window index within the surface.
yThe y-coordinate (row) to draw the wide-character string.
xThe x-coordinate (column) to draw the wide-character string.
wstrThe wide-character string to draw.
Returns
0 on success, -1 on error.
Parameters
ssurface
wwindow
wchar_tstring
Returns
0 on success, -1 on error

Definition at line 248 of file ui_ncurses_draw.c.

248 {
249 if (!s || !wstr)
250 return -1;
251 mvwaddwstr(s->mwin[w], y, x, wstr);
252 return 0;
253}

◆ ui_restore_wins()

void ui_restore_wins ( )

Restore the state of all windows in the UI. This function refreshes the standard screen and all surface windows, ensuring that their contents are displayed correctly.

Definition at line 371 of file ui_ncurses_draw.c.

371 {
372 touchwin(stdscr);
373 for (int s = 0; s <= sfc_ptr; s++) {
374 for (ss_t w = BOX; w < SUB_SFC_MAX; w++)
375 if (ui_surface[s]->mwin[w] != nullptr)
376 touchwin(ui_surface[s]->mwin[w]);
377 }
378 ui_render();
379}
void ui_render()
Render the UI by updating panels and refreshing the display.
Definition ui_ncurses.c:884
ss_t
Definition ui_backend.h:45
@ SUB_SFC_MAX
Definition ui_backend.h:47
int sfc_ptr
Definition ui_ncurses.c:42
UiSurface * ui_surface[UI_SFC_MAX]
Definition ui_ncurses.c:40

◆ ui_wadd_wch()

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

Draw a complex character in a surface window.

on specified window, at current location, add cell

Parameters
sThe surface to modify.
wThe window index within the surface.
cellThe complex character (UiCell) to draw.
Returns
0 on success, -1 on error.
Parameters
ssurface
wwindow
cellcell string
Returns
0 on success, -1 on error

Definition at line 291 of file ui_ncurses_draw.c.

291 {
292 if (!s)
293 return -1;
294 wadd_wchnstr(s->mwin[w], cell, 1);
295 return 0;
296}

◆ ui_wadd_wchnstr()

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

Draw a complex character string in a surface window, with a maximum length.

on specified window, add cell string, at most m columns

Parameters
sThe surface to modify.
wThe window index within the surface.
cmplx_bufThe complex character string (array of UiCell) to draw.
nThe maximum number of complex characters to draw from the complex character string.
Returns
0 on success, -1 on error.
Parameters
ssurface
wwindow
cellcell string
mmaximum number of columns to write
Returns
0 on success, -1 on error

Definition at line 344 of file ui_ncurses_draw.c.

344 {
345 if (!s || !cmplx_buf)
346 return -1;
347 wadd_wchnstr(s->mwin[w], cmplx_buf, n);
348 return 0;
349}

Referenced by display_split_line().

Here is the caller graph for this function:

◆ ui_wadd_wchstr()

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

Draw a complex character string in a surface window.

on specified window, at current location, add cell string

Parameters
sThe surface to modify.
wThe window index within the surface.
cmplx_bufThe complex character string (array of UiCell) to draw.
Returns
0 on success, -1 on error.
Parameters
ssurface
wwindow
cellcell string
Returns
0 on success, -1 on error

Definition at line 317 of file ui_ncurses_draw.c.

317 {
318 if (!s || !cmplx_buf)
319 return -1;
320 wadd_wchstr(s->mwin[w], cmplx_buf);
321 return 0;
322}

◆ ui_waddnstr()

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

Draw a text string in a surface window, with a maximum length.

on specified window, at current location, add string, at most m columns

Parameters
sThe surface to modify.
wThe window index within the surface.
textThe text string to draw.
mThe maximum number of characters to draw from the text string.
Returns
0 on success, -1 on error.
Parameters
ssurface
wwindow
textstring
mmaximum number of columns to write
Returns
0 on success, -1 on error

Definition at line 160 of file ui_ncurses_draw.c.

160 {
161 if (!s || !text)
162 return -1;
163 waddnstr(s->mwin[w], text, m);
164 return 0;
165}

◆ ui_waddnwstr()

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

Draw a wide-character string in a surface window, with a maximum length.

on specified window, at current location, add wchar_t string, at most m columns

Parameters
sThe surface to modify.
wThe window index within the surface.
wstrThe wide-character string to draw.
mThe maximum number of wide characters to draw from the wide-character string.
Returns
0 on success, -1 on error.
Parameters
ssurface
wwindow
wchar_tstring
mmaximum number of columns to write
Returns
0 on success, -1 on error

Definition at line 261 of file ui_ncurses_draw.c.

261 {
262 if (!s || !wstr)
263 return -1;
264 waddnwstr(s->mwin[w], wstr, m);
265 return 0;
266}

◆ ui_waddstr()

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

Draw a text string in a surface window.

on specified window, at current location, add string

Parameters
sThe surface to modify.
wThe window index within the surface.
textThe text string to draw.
Returns
0 on success, -1 on error.
Parameters
ssurface
wwindow
textstring
Returns
0 on success, -1 on error

Definition at line 147 of file ui_ncurses_draw.c.

147 {
148 if (!s || !text)
149 return -1;
150 waddstr(s->mwin[w], text);
151 return 0;
152}

Referenced by display_prompt(), and get_cmd_arg().

Here is the caller graph for this function:

◆ ui_waddwstr()

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

Draw a wide-character string in a surface window.

on specified window, at current location, add wchar_t string

Parameters
sThe surface to modify.
wThe window index within the surface.
wstrThe wide-character string to draw.
Returns
0 on success, -1 on error.
Parameters
ssurface
wwindow
wchar_tstring
Returns
0 on success, -1 on error

Definition at line 234 of file ui_ncurses_draw.c.

234 {
235 if (!s || !wstr)
236 return -1;
237 waddwstr(s->mwin[w], wstr);
238 return 0;
239}

◆ ui_wclrtobot()

int ui_wclrtobot ( UiSurface * s,
ss_t w )

Set the style of a surface window.

Parameters
sThe surface to modify.
wThe window index within the surface.
styleThe style to apply (UiStyle).
Returns
0 on success, -1 on error.

Definition at line 27 of file ui_ncurses_draw.c.

27 {
28 if (!s)
29 return -1;
30 wclrtobot(s->mwin[w]);
31 return 0;
32}

◆ ui_wclrtoeol()

int ui_wclrtoeol ( UiSurface * s,
ss_t w )

Clear to the end of the line in a surface window.

Parameters
sThe surface to modify.
wThe window index within the surface.
Returns
0 on success, -1 on error.

Definition at line 38 of file ui_ncurses_draw.c.

38 {
39 if (!s)
40 return -1;
41 wclrtoeol(s->mwin[w]);
42 return 0;
43}