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
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 mvwaddstr(scr->main_ncw, LINES - nc_scr_pos_status, 1,
43 void nc_scr_frame_draw(struct nc_scr *scr)
45 int ltitle_len, rtitle_len;
47 DBGS("ltitle '%s'\n", scr->frame.ltitle);
48 DBGS("rtitle '%s'\n", scr->frame.rtitle);
49 DBGS("help '%s'\n", scr->frame.help);
50 DBGS("status '%s'\n", scr->frame.status);
52 ltitle_len = strlen(scr->frame.ltitle);
53 rtitle_len = scr->frame.rtitle ? strlen(scr->frame.rtitle) : 0;
55 /* if both ltitle and rtitle don't fit, trim rtitle */
56 if (ltitle_len + rtitle_len + nc_scr_pos_lrtitle_space > COLS - 2)
57 rtitle_len = COLS - 2 - ltitle_len - nc_scr_pos_lrtitle_space;
59 mvwaddstr(scr->main_ncw, nc_scr_pos_title, 1, scr->frame.ltitle);
60 mvwaddnstr(scr->main_ncw, nc_scr_pos_title, COLS - rtitle_len - 1,
61 scr->frame.rtitle, rtitle_len);
62 mvwhline(scr->main_ncw, nc_scr_pos_title_sep, 1, ACS_HLINE, COLS - 2);
64 mvwhline(scr->main_ncw, LINES - nc_scr_pos_help_sep, 1, ACS_HLINE,
66 mvwaddstr(scr->main_ncw, LINES - nc_scr_pos_help, 1, scr->frame.help);
67 nc_scr_status_draw(scr);
70 void nc_scr_status_free(struct nc_scr *scr)
72 talloc_free(scr->frame.status);
73 scr->frame.status = NULL;
74 nc_scr_status_clear(scr);
78 * nc_scr_status_printf - Set the text of the scr status using sprintf.
79 * @scr: The scr to opperate on.
80 * @text: The status text.
82 * The caller is reponsible for calling scr_draw() to update the display.
85 void nc_scr_status_printf(struct nc_scr *scr, const char *format, ...)
89 nc_scr_status_free(scr);
92 scr->frame.status = talloc_vasprintf(scr, format, ap);
95 nc_scr_status_draw(scr);
96 wrefresh(scr->main_ncw);
99 int nc_scr_init(struct nc_scr *scr, enum pb_nc_sig sig, int begin_x,
101 void (*process_key)(struct nc_scr *, int),
102 int (*post)(struct nc_scr *),
103 int (*unpost)(struct nc_scr *),
104 void (*resize)(struct nc_scr *))
107 scr->ui_ctx = ui_ctx;
108 scr->process_key = process_key;
110 scr->unpost = unpost;
111 scr->resize = resize;
113 scr->main_ncw = newwin(LINES, COLS, 0, 0);
115 scr->sub_ncw = derwin(scr->main_ncw,
116 LINES - nc_scr_frame_lines,
121 assert(scr->main_ncw);
122 assert(scr->sub_ncw);
124 return scr->main_ncw && scr->sub_ncw;