1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-23 07:53:02 +01:00

simplify popup drawing

This commit is contained in:
Jfreegman 2014-03-09 01:02:54 -05:00
parent fe0641e981
commit d08feb2cc5
3 changed files with 10 additions and 16 deletions

View File

@ -262,10 +262,6 @@ static void del_friend_activate(ToxWindow *self, Tox *m, int f_num)
getmaxyx(self->window, y2, x2); getmaxyx(self->window, y2, x2);
self->popup = newwin(3, 22 + TOXIC_MAX_NAME_LENGTH, 8, 8); self->popup = newwin(3, 22 + TOXIC_MAX_NAME_LENGTH, 8, 8);
wattron(self->popup, A_BOLD);
box(self->popup, ACS_VLINE, ACS_HLINE);
wattroff(self->popup, A_BOLD);
pendingdelete.active = true; pendingdelete.active = true;
pendingdelete.num = f_num; pendingdelete.num = f_num;
} }
@ -283,17 +279,22 @@ static void del_friend_deactivate(ToxWindow *self, Tox *m, wint_t key)
refresh(); refresh();
} }
static void friendlist_onPopup(ToxWindow *self, Tox *m) static void draw_popup(ToxWindow *self, Tox *m)
{ {
if (self->popup == NULL) if (self->popup == NULL)
return; return;
wattron(self->popup, A_BOLD);
box(self->popup, ACS_VLINE, ACS_HLINE);
wattroff(self->popup, A_BOLD);
wmove(self->popup, 1, 1); wmove(self->popup, 1, 1);
wprintw(self->popup, "Delete contact "); wprintw(self->popup, "Delete contact ");
wattron(self->popup, A_BOLD); wattron(self->popup, A_BOLD);
wprintw(self->popup, "%s", friends[pendingdelete.num].name); wprintw(self->popup, "%s", friends[pendingdelete.num].name);
wattroff(self->popup, A_BOLD); wattroff(self->popup, A_BOLD);
wprintw(self->popup, "? y/n"); wprintw(self->popup, "? y/n");
wrefresh(self->popup); wrefresh(self->popup);
} }
@ -453,6 +454,7 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
self->x = x2; self->x = x2;
wrefresh(self->window); wrefresh(self->window);
draw_popup(self, m);
} }
void disable_chatwin(int f_num) void disable_chatwin(int f_num)
@ -473,7 +475,6 @@ ToxWindow new_friendlist(void)
ret.active = true; ret.active = true;
ret.onKey = &friendlist_onKey; ret.onKey = &friendlist_onKey;
ret.onPopup = &friendlist_onPopup;
ret.onDraw = &friendlist_onDraw; ret.onDraw = &friendlist_onDraw;
ret.onInit = &friendlist_onInit; ret.onInit = &friendlist_onInit;
ret.onFriendAdded = &friendlist_onFriendAdded; ret.onFriendAdded = &friendlist_onFriendAdded;

View File

@ -88,7 +88,6 @@ typedef struct ChatContext ChatContext;
struct ToxWindow { struct ToxWindow {
void(*onKey)(ToxWindow *, Tox *, wint_t); void(*onKey)(ToxWindow *, Tox *, wint_t);
void(*onDraw)(ToxWindow *, Tox *); void(*onDraw)(ToxWindow *, Tox *);
void(*onPopup)(ToxWindow *, Tox*);
void(*onInit)(ToxWindow *, Tox *); void(*onInit)(ToxWindow *, Tox *);
void(*onFriendRequest)(ToxWindow *, uint8_t *, uint8_t *, uint16_t); void(*onFriendRequest)(ToxWindow *, uint8_t *, uint8_t *, uint16_t);
void(*onFriendAdded)(ToxWindow *, Tox *, int, bool); void(*onFriendAdded)(ToxWindow *, Tox *, int, bool);

View File

@ -387,14 +387,8 @@ void draw_active_window(Tox *m)
wresize(a->window, LINES - 2, COLS); wresize(a->window, LINES - 2, COLS);
#endif #endif
/* ignore main window if popup is active */ a->onDraw(a, m);
if (a->popup) { wrefresh(a->window);
a->onPopup(a, m);
wrefresh(a->popup);
} else {
a->onDraw(a, m);
wrefresh(a->window);
}
/* Handle input */ /* Handle input */
#ifdef HAVE_WIDECHAR #ifdef HAVE_WIDECHAR
@ -403,7 +397,7 @@ void draw_active_window(Tox *m)
ch = getch(); ch = getch();
#endif #endif
if ((ch == T_KEY_NEXT || ch == T_KEY_PREV) && !a->popup) /* lock window if active popup */ if (ch == T_KEY_NEXT || ch == T_KEY_PREV)
set_next_window((int) ch); set_next_window((int) ch);
else if (ch != ERR) else if (ch != ERR)
a->onKey(a, m, ch); a->onKey(a, m, ch);