diff options
author | toni <toni@devlap.local> | 2015-11-16 20:07:03 +0100 |
---|---|---|
committer | toni <toni@devlap.local> | 2015-11-16 20:07:03 +0100 |
commit | 99dfc48c542ec59c9541faa33c8895bfa471089b (patch) | |
tree | 1bbe30ef83d50bc79fde1ff32d78d3f8b9836255 | |
parent | 7bd71541d76cd5f23b91981f6d0a19d490926356 (diff) |
- ui_nwindow.c renamed to better ui_txtwindow.c
- better ui_txtwindow.c
-rw-r--r-- | src/main.c | 1 | ||||
-rw-r--r-- | src/ui.c | 21 | ||||
-rw-r--r-- | src/ui.h | 10 | ||||
-rw-r--r-- | src/ui_elements.c | 26 | ||||
-rw-r--r-- | src/ui_ipc.h | 2 | ||||
-rw-r--r-- | src/ui_txtwindow.c (renamed from src/ui_nwindow.c) | 52 | ||||
-rw-r--r-- | src/ui_txtwindow.h (renamed from src/ui_nwindow.h) | 11 |
7 files changed, 91 insertions, 32 deletions
@@ -1,5 +1,6 @@ #include <stdio.h> #include <stdlib.h> +#include <unistd.h> #include <stdbool.h> #include <string.h> #include <unistd.h> @@ -19,7 +19,7 @@ #include "ui_ani.h" #include "ui_input.h" #include "ui_statusbar.h" -#include "ui_nwindow.h" +#include "ui_txtwindow.h" #include "status.h" #include "config.h" @@ -94,6 +94,18 @@ unregister_ui_elt(void *data) } } +unsigned int +ui_get_maxx(void) +{ + return max_x; +} + +unsigned int +ui_get_maxy(void) +{ + return max_y; +} + void ui_set_cur(unsigned int x, unsigned int y) { @@ -101,13 +113,13 @@ ui_set_cur(unsigned int x, unsigned int y) cur_y = y; } -int +unsigned int ui_get_curx(void) { return (cur_x); } -int +unsigned int ui_get_cury(void) { return (cur_y); @@ -235,7 +247,10 @@ init_ui(void) init_pair(1, COLOR_RED, COLOR_WHITE); init_pair(2, COLOR_WHITE, COLOR_BLACK); init_pair(3, COLOR_BLACK, COLOR_WHITE); + /* TXTwindow */ init_pair(4, COLOR_YELLOW, COLOR_RED); + init_pair(5, COLOR_WHITE, COLOR_CYAN); + /* EoF TXTwindow */ raw(); keypad(stdscr, TRUE); noecho(); @@ -48,13 +48,19 @@ register_ui_elt(struct ui_callbacks *cbs, void *data, WINDOW *wnd); void unregister_ui_elt(void *data); +unsigned int +ui_get_maxx(void); + +unsigned int +ui_get_maxy(void); + void ui_set_cur(unsigned int x, unsigned int y); -int +unsigned int ui_get_curx(void); -int +unsigned int ui_get_cury(void); int diff --git a/src/ui_elements.c b/src/ui_elements.c index b274529..e57c0de 100644 --- a/src/ui_elements.c +++ b/src/ui_elements.c @@ -1,5 +1,6 @@ #include <stdio.h> #include <stdlib.h> +#include <unistd.h> #include <string.h> #include "ui.h" @@ -7,7 +8,7 @@ #include "ui_ani.h" #include "ui_input.h" #include "ui_statusbar.h" -#include "ui_nwindow.h" +#include "ui_txtwindow.h" #include "ui_elements.h" #include "status.h" @@ -17,9 +18,7 @@ #define PASSWD_XRELPOS (unsigned int)(PASSWD_WIDTH / 2) - (PASSWD_WIDTH / 6) #define PASSWD_YRELPOS (unsigned int)(PASSWD_HEIGHT / 2) + 1 #define INFOWND_WIDTH 25 -#define INFOWND_HEIGHT 3 -#define INFOWND_XRELPOS (unsigned int)(INFOWND_WIDTH / 2) - (INFOWND_WIDTH / 6) -#define INFOWND_YRELPOS (unsigned int)(INFOWND_HEIGHT / 2) + 1 +#define INFOWND_HEIGHT 1 static struct input *pw_input; static struct anic *heartbeat; @@ -80,9 +79,14 @@ passwd_input_cb(WINDOW *wnd, void *data, int key) mq_passwd_send(a->input); clear_input(wnd, a); ui_ipc_msgrecv(MQ_IF, ipc_buf); + set_txtwindow_color(infownd, COLOR_PAIR(5), COLOR_PAIR(5)); set_txtwindow_title(infownd, "BUSY"); set_txtwindow_text(infownd, ipc_buf); set_txtwindow_active(infownd, true); + sleep(2); + ui_ipc_msgrecv(MQ_IF, ipc_buf); + set_txtwindow_color(infownd, COLOR_PAIR(4), COLOR_PAIR(4) | A_BOLD); + set_txtwindow_text(infownd, ipc_buf); break; case UIKEY_BACKSPACE: del_input(wnd, a); @@ -106,11 +110,17 @@ void init_ui_elements(WINDOW *wnd_main, unsigned int max_x, unsigned int max_y) { asprintf(&title, "/* %s-%s */", PKGNAME, VERSION); - pw_input = init_input((unsigned int)(max_x / 2)-PASSWD_XRELPOS, (unsigned int)(max_y / 2)-PASSWD_YRELPOS, PASSWD_WIDTH, "PASSWORD: ", IPC_MQSIZ, COLOR_PAIR(3), COLOR_PAIR(2)); + pw_input = init_input((unsigned int)(max_x / 2)-PASSWD_XRELPOS, + (unsigned int)(max_y / 2)-PASSWD_YRELPOS, + PASSWD_WIDTH, "PASSWORD: ", + IPC_MQSIZ, COLOR_PAIR(3), COLOR_PAIR(2)); heartbeat = init_anic_default(0, 0, A_BOLD | COLOR_PAIR(1), "[%c]"); - higher = init_statusbar(0, max_x, A_BOLD | COLOR_PAIR(3), higher_statusbar_update); - lower = init_statusbar(max_y - 1, max_x, COLOR_PAIR(3), lower_statusbar_update); - infownd = init_txtwindow((unsigned int)(max_x / 2)-INFOWND_XRELPOS, (unsigned int)(max_y / 2)-INFOWND_YRELPOS, INFOWND_WIDTH, INFOWND_HEIGHT, COLOR_PAIR(4), COLOR_PAIR(4) | A_BOLD, infownd_update); + higher = init_statusbar(0, max_x, A_BOLD | COLOR_PAIR(3), + higher_statusbar_update); + lower = init_statusbar(max_y - 1, max_x, COLOR_PAIR(3), + lower_statusbar_update); + infownd = init_txtwindow_centered(INFOWND_WIDTH, INFOWND_HEIGHT, + infownd_update); infownd->userptr = calloc(4, sizeof(char)); (*(char*)(infownd->userptr)) = '.'; diff --git a/src/ui_ipc.h b/src/ui_ipc.h index ec36f35..5ecfaa4 100644 --- a/src/ui_ipc.h +++ b/src/ui_ipc.h @@ -8,7 +8,7 @@ enum UI_IPC_SEM { - SEM_RD = 0, /* UI Init done? */ + SEM_RD = 0, /* UI Init done? */ SEM_UI, /* TUI active? */ SEM_IN, /* Textfield has input avail */ SEM_BS, /* Master process busy */ diff --git a/src/ui_nwindow.c b/src/ui_txtwindow.c index aa1812d..5852c32 100644 --- a/src/ui_nwindow.c +++ b/src/ui_txtwindow.c @@ -1,11 +1,11 @@ #include <stdlib.h> #include <string.h> -#include "ui_nwindow.h" +#include "ui_txtwindow.h" struct txtwindow * -init_txtwindow(unsigned int x, unsigned int y, unsigned int width, unsigned int height, chtype attrs, chtype text_attrs, window_func cb_update) +init_txtwindow(unsigned int x, unsigned int y, unsigned int width, unsigned int height, window_func cb_update) { struct txtwindow *a = calloc(1, sizeof(struct txtwindow)); @@ -17,12 +17,20 @@ init_txtwindow(unsigned int x, unsigned int y, unsigned int width, unsigned int a->title_len = INITIAL_TITLE_LEN; a->title = calloc(a->title_len+1, sizeof(char)); a->text = NULL; - a->attrs = attrs; - a->text_attrs = text_attrs; + a->attrs = 0; + a->text_attrs = 0; a->window_func = cb_update; return (a); } +struct txtwindow * +init_txtwindow_centered(unsigned int width, unsigned int height, window_func cb_update) +{ + unsigned int x = (ui_get_maxx()/2)-(width/2); + unsigned int y = (ui_get_maxy()/2)-(height/2); + return init_txtwindow(x, y, width, height, cb_update); +} + static void __free_text(struct txtwindow *a) { @@ -55,27 +63,28 @@ print_wnd(struct txtwindow *a) /* print window surface */ memset(tmp, ' ', a->width); tmp[a->width] = '\0'; - for (i = y-1; i < y+h+2; i++) + for (i = y-1; i < y+h+1; i++) mvprintw(i, x, tmp); /* print window border */ mvhline(y-2, x, 0, w); - mvhline(y+h+2, x, 0, w); + mvhline(y+h+1, x, 0, w); mvvline(y-1, x-1, 0, h+3); mvvline(y-1, x+w, 0, h+3); /* print window border edges */ mvaddch(y-2, x-1, ACS_ULCORNER); - mvaddch(y+2+h, x-1, ACS_LLCORNER); + mvaddch(y+1+h, x-1, ACS_LLCORNER); mvaddch(y-2, x+w, ACS_URCORNER); - mvaddch(y+2+h, x+w, ACS_LRCORNER); + mvaddch(y+1+h, x+w, ACS_LRCORNER); /* print window title */ attroff(a->attrs); attron(a->text_attrs); - mvprintw(y-2, (float)x+(float)(w/2)-(float)(a->title_len*2/3), "[ %s ]", a->title); + mvprintw(y-2, x+(w/2)-((a->title_len+4)/2), "[ %s ]", a->title); /* print windows text */ - i = 0; - while ( a->text && a->text[i] ) { - mvprintw(y+i, x, a->text[i]); - i++; + i = -1; + if (a->text) { + while ( a->text[++i] ) { + mvprintw(y+i, x+1, a->text[i]); + } } attroff(a->text_attrs); } @@ -118,21 +127,22 @@ __do_textcpy(char **p_dest, size_t sz_dest, const char *p_src, size_t sz_src) static char ** __do_textadjust(struct txtwindow *a, char *text) { - int i = 0, rows = (int)(strlen(text) / a->width)+1; - char **adj_text = calloc(rows+1, sizeof(char *)); + int i = 0, rows = (int)(strlen(text) / a->width); + char **adj_text = calloc(rows+2, sizeof(char *)); char *p_strtok, *tok; const char sep[] = "\n"; if (rows > a->height) goto error; p_strtok = strdup(text); - while ( (tok = strsep(&p_strtok, sep)) && rows-- >= 0 ) { + do { + tok = strsep(&p_strtok, sep); if (strlen(tok) > a->width) { strcpy(tok+a->width-3, "..."); *(tok+a->width) = '\0'; } adj_text[i] = tok; i++; - } + } while (rows > 0); return adj_text; error: free(adj_text); @@ -155,3 +165,11 @@ set_txtwindow_title(struct txtwindow *a, const char *title) { a->title_len = __do_textcpy(&a->title, a->title_len, title, strlen(title)); } + +void +set_txtwindow_color(struct txtwindow *a, chtype wnd, chtype txt) +{ + a->attrs = wnd; + a->text_attrs = txt; +} + diff --git a/src/ui_nwindow.h b/src/ui_txtwindow.h index 198481b..913cd99 100644 --- a/src/ui_nwindow.h +++ b/src/ui_txtwindow.h @@ -27,7 +27,10 @@ struct txtwindow { typedef int (*window_func)(WINDOW *, struct txtwindow *); struct txtwindow * -init_txtwindow(unsigned int, unsigned int y, unsigned int width, unsigned int height, chtype attrs, chtype text_attrs, window_func cb_update); +init_txtwindow(unsigned int x, unsigned int y, unsigned int width, unsigned int height, window_func cb_update); + +struct txtwindow * +init_txtwindow_centered(unsigned int width, unsigned int height, window_func cb_update); void free_txtwindow(struct txtwindow *a); @@ -41,4 +44,10 @@ set_txtwindow_text(struct txtwindow *a, char *text); void set_txtwindow_title(struct txtwindow *a, const char *title); +void +set_txtwindow_color(struct txtwindow *a, chtype wnd, chtype txt); + +void +set_txtwindow_pos(struct txtwindow *a, unsigned int x, unsigned int y); + #endif |