2 * Copyright (C) 2009 Sony Computer Entertainment Inc.
3 * Copyright 2009 Sony Corp.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #if defined(HAVE_CONFIG_H)
28 #include "talloc/talloc.h"
32 static void nc_scr_status_clear(struct nc_scr *scr)
34 mvwhline(scr->main_ncw, LINES - nc_scr_pos_status, 0, ' ', COLS);
37 static void nc_scr_status_draw(struct nc_scr *scr)
39 mvwaddnstr(scr->main_ncw, LINES - nc_scr_pos_status, 1,
40 scr->frame.status, COLS);
43 int nc_scr_post(struct nc_scr *scr)
46 return scr->post(scr);
50 int nc_scr_unpost(struct nc_scr *scr)
53 return scr->unpost(scr);
57 void nc_scr_frame_draw(struct nc_scr *scr)
59 int ltitle_len, rtitle_len, help_len;
61 DBGS("ltitle '%s'\n", scr->frame.ltitle);
62 DBGS("rtitle '%s'\n", scr->frame.rtitle);
63 DBGS("help '%s'\n", scr->frame.help);
64 DBGS("status '%s'\n", scr->frame.status);
66 ltitle_len = strlen(scr->frame.ltitle);
67 rtitle_len = scr->frame.rtitle ? strlen(scr->frame.rtitle) : 0;
69 /* if both ltitle and rtitle don't fit, trim rtitle */
70 if (ltitle_len + rtitle_len + nc_scr_pos_lrtitle_space > COLS - 2)
71 rtitle_len = COLS - 2 - ltitle_len - nc_scr_pos_lrtitle_space;
73 mvwaddstr(scr->main_ncw, nc_scr_pos_title, 1, scr->frame.ltitle);
74 mvwaddnstr(scr->main_ncw, nc_scr_pos_title, COLS - rtitle_len - 1,
75 scr->frame.rtitle, rtitle_len);
76 mvwhline(scr->main_ncw, nc_scr_pos_title_sep, 1, ACS_HLINE, COLS - 2);
78 mvwhline(scr->main_ncw, LINES - nc_scr_pos_help_sep, 1, ACS_HLINE,
80 help_len = 1 + strlen(scr->frame.help);
82 mvwhline(scr->main_ncw, LINES - nc_scr_pos_help, help_len, ' ',
84 mvwaddstr(scr->main_ncw, LINES - nc_scr_pos_help, 1, scr->frame.help);
85 nc_scr_status_draw(scr);
88 void nc_scr_status_free(struct nc_scr *scr)
90 talloc_free(scr->frame.status);
91 scr->frame.status = NULL;
92 nc_scr_status_clear(scr);
96 * nc_scr_status_printf - Set the text of the scr status using sprintf.
97 * @scr: The scr to opperate on.
98 * @text: The status text.
100 * The caller is reponsible for calling scr_draw() to update the display.
103 void nc_scr_status_printf(struct nc_scr *scr, const char *format, ...)
107 nc_scr_status_free(scr);
109 va_start(ap, format);
110 scr->frame.status = talloc_vasprintf(scr, format, ap);
113 nc_scr_status_draw(scr);
114 wrefresh(scr->main_ncw);
117 int nc_scr_init(struct nc_scr *scr, enum pb_nc_sig sig, int begin_x,
119 void (*process_key)(struct nc_scr *, int),
120 int (*post)(struct nc_scr *),
121 int (*unpost)(struct nc_scr *),
122 void (*resize)(struct nc_scr *))
125 scr->ui_ctx = ui_ctx;
126 scr->process_key = process_key;
128 scr->unpost = unpost;
129 scr->resize = resize;
131 scr->main_ncw = newwin(LINES, COLS, 0, 0);
133 scr->sub_ncw = derwin(scr->main_ncw,
134 LINES - nc_scr_frame_lines,
135 COLS - nc_scr_frame_cols - begin_x,
139 assert(scr->main_ncw);
140 assert(scr->sub_ncw);
142 return scr->main_ncw && scr->sub_ncw;