2
3
4
5
6
7
9#define _XOPEN_SOURCE_EXTENDED 1
13#include <notcurses/notcurses.h>
19
20
22
23
24
25
29 uint y, x, ylen, xlen, maxy, maxx;
30 ncplane_cursor_yx(s->mplane[w], &y, &x);
31 ncplane_dim_yx(s->mplane[w], &maxy, &maxx);
34 ncplane_erase_region(s->mplane[w], y, x, ylen, xlen);
38
39
40
41
45 uint y, x, ylen, xlen, maxy, maxx;
46 ncplane_cursor_yx(s->mplane[w], &y, &x);
47 ncplane_dim_yx(s->mplane[w], &maxy, &maxx);
50 ncplane_erase_region(s->mplane[w], y, x, ylen, xlen);
53 ncplane_erase_region(s->mplane[w], y + 1, x = 0, ylen, maxx);
58
59
61
62
63
64
65
68 cell->gcluster_backstop = 0;
69 cell->stylemask = bkgd_cell.stylemask;
70 cell->channels = bkgd_cell.channels;
74
75
76
77
78
82 nccell cell = CELL_INITIALIZER(c, s->meta[w].bkgd_cell.stylemask, s->meta[w].bkgd_cell.channels);
83 ncplane_putc_yx(s->mplane[w], -1, -1, &cell);
87
88
89
90
91
92
93
97 nccell cell = CELL_INITIALIZER(c, s->meta[w].bkgd_cell.stylemask, s->meta[w].bkgd_cell.channels);
98 ncplane_putc_yx(s->mplane[w], y, x, &cell);
102
103
104
105
106
107
108
109int ui_draw_text(UiSurface *s, ss_t w, uint y, uint x,
const char *text) {
112 ncplane_putstr_yx(s->mplane[w], y, x, text);
116
117
118
119
120
121
122
123
124int ui_draw_text_n(UiSurface *s, ss_t w, uint y, uint x,
const char *text,
int m) {
127 ncplane_putnstr_yx(s->mplane[w], y, x, m, text);
131
132
133
134
135
136
137
138
143 strncpy(tmp_str, text, m);
144 int l = strlen(text);
145 for (
int i = l; i < m; i++) {
149 ncplane_putnstr_yx(s->mplane[w], y, x, m, tmp_str);
155
156
157
158
159
163 nccell cell = CELL_INITIALIZER(c, s->meta[w].bkgd_cell.stylemask, s->meta[w].bkgd_cell.channels);
164 ncplane_putc_yx(s->mplane[w], -1, -1, &cell);
168
169
170
171
172
173
174
175int ui_mvwaddch(UiSurface *s, ss_t w, uint y, uint x,
const char c) {
178 nccell cell = CELL_INITIALIZER(c, s->meta[w].bkgd_cell.stylemask, s->meta[w].bkgd_cell.channels);
179 ncplane_putc_yx(s->mplane[w], y, x, &cell);
183
184
185
186
187
191 ncplane_putstr(s->mplane[w], text);
195
196
197
198
199
200
204 ncplane_putnstr(s->mplane[w], m, text);
208
209
210
211
212
213
214
215int ui_mvwaddstr(UiSurface *s, ss_t w, uint y, uint x,
const char *text) {
218 ncplane_putstr_yx(s->mplane[w], y, x, text);
222
223
224
225
226
227
228
229
230int ui_mvwaddnstr(UiSurface *s, ss_t w, uint y, uint x,
const char *text,
int m) {
233 ncplane_putnstr_yx(s->mplane[w], y, x, m, text);
237
238
239
240
241
242
243
244
248 int l = strlen(text);
250 char *tmp_str = (
char *)malloc(m + 1);
253 strcpy(tmp_str, text);
254 for (
int i = l; i < (
int)m; i++) {
258 ncplane_putnstr_yx(s->mplane[w], y, x, m, tmp_str);
267
268
269
270
271
275 while (*wstr != L'\0')
276 ncplane_putwc_yx(s->mplane[w], -1, -1, *wstr++);
280
281
282
283
284
285int ui_mvwaddwstr(UiSurface *s, ss_t w, uint y, uint x,
const wchar_t *wstr) {
288 while (*wstr != L'\0')
289 ncplane_putwc_yx(s->mplane[w], y, x++, *wstr++);
293
294
295
296
297
298
299
305 while (*wstr != L'\0') {
306 width = wcwidth(*wstr);
309 if (cols + width > m)
311 ncplane_putwc_yx(s->mplane[w], -1, -1, *wstr++);
316
317
318
319
320
321
322
323
324int ui_mvwaddnwstr(UiSurface *s, ss_t w, uint y, uint x,
const wchar_t *wstr,
int m) {
329 while (*wstr != L'\0') {
330 width = wcwidth(*wstr);
333 if (cols + width > m)
335 ncplane_putwc_yx(s->mplane[w], y, x++, *wstr++);
336 cols += wcwidth(*wstr);
344
345
346
347
348
352 ncplane_putc(s->mplane[w], cell);
356
357
358
359
360
361
362
363int ui_mvwadd_wch(UiSurface *s, ss_t w, uint y, uint x,
const UiCell *cell) {
366 ncplane_putc_yx(s->mplane[w], y, x, cell);
371
372
373
374
375
379 while (cell->gcluster != 0) {
380 ncplane_putc(s->mplane[w], cell);
386
387
388
389
390
391
392
397 while (cell->gcluster != 0) {
398 ncplane_putc(s->mplane[w], cell);
404
405
406
407
408
409
414 while (cell->gcluster != 0 && cols < m) {
415 ncplane_putc(s->mplane[w], cell);
422
423
424
425
426
427
428
429
435 while (cell->gcluster != 0 && cols < m) {
436 ncplane_putc(s->mplane[w], cell);
443
444
454
455
457
458
459
460
461
462
463
464
465
466struct ncvisual *
ui_display_image(
struct notcurses *nc, UiMultiMedia *mm,
const char *image_file,
int y,
int x,
int begy,
int begx) {
467 struct ncplane *stdn = notcurses_stdplane(nc);
468 unsigned term_rows, term_cols;
469 ncplane_dim_yx(stdn, &term_rows, &term_cols);
470 mm
->ncv = ncvisual_from_file(image_file);
472 fprintf(stderr,
"Error: Could not load image file.\n");
476 if (ncvisual_geom(nc, mm
->ncv, NULL, &geom) < 0) {
477 ncvisual_destroy(mm
->ncv);
485 y = (
int)term_rows - begy;
487 x = (
int)term_cols - begx;
488 if (begy + y > (
int)term_rows)
489 y = (
int)term_rows - begy;
490 if (begx + x > (
int)term_cols)
491 x = (
int)term_cols - begx;
492 int max_rows = y - 2;
493 int max_cols = x - 2;
495 ncvisual_destroy(mm
->ncv);
498 struct ncvisual_options vopts_calc = {
499 .scaling = NCSCALE_SCALE_HIRES,
500 .blitter = NCBLIT_PIXEL,
502 struct ncplane_options nopts = {
508 struct ncplane *tmp_bound_plane = ncplane_create(stdn, &nopts);
509 if (!tmp_bound_plane) {
510 ncvisual_destroy(mm
->ncv);
513 vopts_calc.n = tmp_bound_plane;
514 if (ncvisual_geom(nc, mm
->ncv, &vopts_calc, &geom) < 0) {
515 ncplane_destroy(tmp_bound_plane);
516 ncvisual_destroy(mm
->ncv);
519 unsigned rows = geom.rcelly;
520 unsigned cols = geom.rcellx;
522 ncplane_destroy(tmp_bound_plane);
525 struct ncvisual_options vopts = {
526 .n = mm
->sfc->mplane[WIN],
527 .scaling = NCSCALE_SCALE_HIRES,
528 .blitter = NCBLIT_PIXEL,
530 ncvisual_blit(nc, mm
->ncv, &vopts);
531 notcurses_render(nc);
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_surface_addwin(UiSurface *s, ss_t w, uint p, uint lines, uint cols, uint y, uint x)
Add a new window to the specified UiSurface.
void ui_render()
Render the UI by updating panels and refreshing the display.
int ui_draw_text_n(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.
int ui_draw_text_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 space...
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_wmove(UiSurface *s, ss_t w, uint y, uint x)
Move the cursor to a specified position within a UiSurface.
void ui_restore_wins()
Restore the state of all windows in the UI. This function refreshes the standard screen and all surfa...
int ui_draw_ch(UiSurface *s, ss_t w, const char c)
Draw a character in a surface window.
UiSurface * ui_surface_box(UiSurface *parent, uint p, uint lines, uint cols, uint y, uint x, const char *title)
Create a new UI surface with a border box and optional title.
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.
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_waddstr(UiSurface *s, ss_t w, const char *text)
Draw a text string in a surface window.
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_waddwstr(UiSurface *s, ss_t w, const wchar_t *wstr)
Draw a wide-character string 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_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_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_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_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.
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_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_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 space...
int ui_wadd_wch(UiSurface *s, ss_t w, const UiCell *cell)
Draw a complex character in a surface window.
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_wadd_wchstr(UiSurface *s, ss_t w, const UiCell *cmplx_buf)
Draw a complex character string 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 mk_chimera(UiCell *cell, char c)
create a cell with specified character, using background cell style and channels
struct ncvisual * ui_display_image(struct notcurses *nc, UiMultiMedia *mm, const char *image_file, int y, int x, int begy, int begx)
display an image on the terminal using NotCurses
int ui_waddch(UiSurface *s, ss_t w, const char c)
on specified window, at current location, add character