mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: barebox@lists.infradead.org
Subject: [PATCH 18/20] app: curses: add panel example
Date: Wed,  6 Mar 2013 10:29:47 +0100	[thread overview]
Message-ID: <1362562189-17783-18-git-send-email-plagnioj@jcrosoft.com> (raw)
In-Reply-To: <1362562189-17783-1-git-send-email-plagnioj@jcrosoft.com>

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 apps/Kconfig               |    4 ++
 apps/Makefile              |    1 +
 apps/panel_curses/Makefile |   11 +++++
 apps/panel_curses/main.c   |  118 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 134 insertions(+)
 create mode 100644 apps/panel_curses/Makefile
 create mode 100644 apps/panel_curses/main.c

diff --git a/apps/Kconfig b/apps/Kconfig
index e47f0c2..532b6fb 100644
--- a/apps/Kconfig
+++ b/apps/Kconfig
@@ -45,6 +45,10 @@ config APP_TEST_CURSES
 	bool "test curses"
 	select APP_LIB_CURSES
 
+config APP_TEST_CURSES_PANEL
+	bool "test curses panel"
+	depends on APP_LIB_PANEL
+
 config APP_TEST_CURSES_MENU
 	bool "test curses menu"
 	depends on APP_LIB_MENU
diff --git a/apps/Makefile b/apps/Makefile
index 47938ec..a26541a 100644
--- a/apps/Makefile
+++ b/apps/Makefile
@@ -8,6 +8,7 @@ export APP_CPPFLAGS
 apps-$(CONFIG_APP_EXAMPLE) += example
 apps-$(CONFIG_APP_TEST_CURSES) += test_curses
 apps-$(CONFIG_APP_TEST_CURSES_MENU) += menu_curses
+apps-$(CONFIG_APP_TEST_CURSES_PANEL) += panel_curses
 
 $(obj)/application: $(apps-lds) $(apps-y)
 
diff --git a/apps/panel_curses/Makefile b/apps/panel_curses/Makefile
new file mode 100644
index 0000000..b52c808
--- /dev/null
+++ b/apps/panel_curses/Makefile
@@ -0,0 +1,11 @@
+targets := panel_curses.map
+
+# Make sure files are removed during clean
+extra-y       += panel_curses.map
+
+app-y += main.o
+app-final-y = panel_curses
+
+OBJCOPYFLAGS_panel_curses.app = -O binary
+LDFLAGS_apps	:= -Map $(obj)/panel_curses.map
+LDFLAGS_apps	+= -static --gc-sections
diff --git a/apps/panel_curses/main.c b/apps/panel_curses/main.c
new file mode 100644
index 0000000..4be732f
--- /dev/null
+++ b/apps/panel_curses/main.c
@@ -0,0 +1,118 @@
+#include <panel.h>
+#include <string.h>
+
+#define NLINES 10
+#define NCOLS 40
+
+void init_wins(WINDOW **wins, int n);
+void win_show(WINDOW *win, char *label, int label_color);
+void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color);
+
+int main(int argc, char **argv)
+{	WINDOW *my_wins[3];
+	PANEL  *my_panels[3];
+	PANEL  *top;
+	int ch;
+
+	/* Initialize curses */
+	initscr();
+	start_color();
+	cbreak();
+	noecho();
+	keypad(stdscr, TRUE);
+
+	/* Initialize all the colors */
+	init_pair(1, COLOR_RED, COLOR_BLACK);
+	init_pair(2, COLOR_GREEN, COLOR_BLACK);
+	init_pair(3, COLOR_BLUE, COLOR_BLACK);
+	init_pair(4, COLOR_CYAN, COLOR_BLACK);
+
+	init_wins(my_wins, 3);
+	
+	/* Attach a panel to each window */ 	/* Order is bottom up */
+	my_panels[0] = new_panel(my_wins[0]); 	/* Push 0, order: stdscr-0 */
+	my_panels[1] = new_panel(my_wins[1]); 	/* Push 1, order: stdscr-0-1 */
+	my_panels[2] = new_panel(my_wins[2]); 	/* Push 2, order: stdscr-0-1-2 */
+
+	/* Set up the user pointers to the next panel */
+	set_panel_userptr(my_panels[0], my_panels[1]);
+	set_panel_userptr(my_panels[1], my_panels[2]);
+	set_panel_userptr(my_panels[2], my_panels[0]);
+
+	/* Update the stacking order. 2nd panel will be on top */
+	update_panels();
+
+	/* Show it on the screen */
+	attron(COLOR_PAIR(4));
+	mvprintw(LINES - 2, 0, "Use tab to browse through the windows (F1 to Exit)");
+	attroff(COLOR_PAIR(4));
+	doupdate();
+
+	top = my_panels[2];
+	while((ch = getch()) != KEY_F(1))
+	{	switch(ch)
+		{	case 9:
+				top = (PANEL *)panel_userptr(top);
+				top_panel(top);
+				break;
+		}
+		update_panels();
+		doupdate();
+	}
+	endwin();
+	return 0;
+}
+
+/* Put all the windows */
+void init_wins(WINDOW **wins, int n)
+{	int x, y, i;
+	char label[80];
+
+	y = 2;
+	x = 10;
+	for(i = 0; i < n; ++i)
+	{	wins[i] = newwin(NLINES, NCOLS, y, x);
+		sprintf(label, "Window Number %d", i + 1);
+		win_show(wins[i], label, i + 1);
+		y += 3;
+		x += 7;
+	}
+}
+
+/* Show the window with a border and a label */
+void win_show(WINDOW *win, char *label, int label_color)
+{	int startx, starty, height, width;
+
+	getbegyx(win, starty, startx);
+	getmaxyx(win, height, width);
+
+	box(win, 0, 0);
+	mvwaddch(win, 2, 0, ACS_LTEE); 
+	mvwhline(win, 2, 1, ACS_HLINE, width - 2); 
+	mvwaddch(win, 2, width - 1, ACS_RTEE); 
+	
+	print_in_middle(win, 1, 0, width, label, COLOR_PAIR(label_color));
+}
+
+void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color)
+{	int length, x, y;
+	float temp;
+
+	if(win == NULL)
+		win = stdscr;
+	getyx(win, y, x);
+	if(startx != 0)
+		x = startx;
+	if(starty != 0)
+		y = starty;
+	if(width == 0)
+		width = 80;
+
+	length = strlen(string);
+	temp = (width - length)/ 2;
+	x = startx + (int)temp;
+	wattron(win, color);
+	mvwprintw(win, y, x, "%s", string);
+	wattroff(win, color);
+	refresh();
+}
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2013-03-06  9:35 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-06  9:26 [RFC PATCH 00/20] introduce application support Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:29 ` [PATCH 01/20] Makefile: x_flags prepare for apps support Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:29   ` [PATCH 02/20] tlsf_malloc: drop duplicate include Jean-Christophe PLAGNIOL-VILLARD
2013-03-07  7:37     ` Sascha Hauer
2013-03-06  9:29   ` [PATCH 03/20] kbuild: add application (app) target Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:29   ` [PATCH 04/20] Introduce application (app) support Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:29   ` [PATCH 05/20] app: Introduce libc support Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:29   ` [PATCH 06/20] app: add some utils Jean-Christophe PLAGNIOL-VILLARD
2013-03-06 21:21     ` Sascha Hauer
2013-03-06 21:34       ` Jean-Christophe PLAGNIOL-VILLARD
2013-03-07  7:45         ` Sascha Hauer
2013-03-07  9:17           ` Alexander Aring
2013-03-06  9:29   ` [PATCH 07/20] app: Introduce example application Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:29   ` [PATCH 08/20] filetype: add barebox arm application Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:29   ` [PATCH 09/20] arm: add application support Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:59     ` Alexander Shiyan
2013-03-06 10:13       ` Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:29   ` [PATCH 10/20] app: printf: use HelenOS verison with wide char support Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:29   ` [PATCH 11/20] app: printf: add version from contiki Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:29   ` [PATCH 12/20] app: add tinycurses support Jean-Christophe PLAGNIOL-VILLARD
2013-03-06 11:31     ` Sascha Hauer
2013-03-06 13:04       ` Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:29   ` [PATCH 13/20] app: curses: add pdcurses Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:29   ` [PATCH 14/20] app: add test curses Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:29   ` [PATCH 15/20] app: pdcurses: add libmenu Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:29   ` [PATCH 16/20] app: pdcurses: add libform Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:29   ` [PATCH 17/20] app: curses: add menu example Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:29   ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2013-03-06  9:29   ` [PATCH 19/20] app: curses: add form example Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:29   ` [PATCH 20/20] highbank: enable application support Jean-Christophe PLAGNIOL-VILLARD
2013-03-07  7:36 ` [RFC PATCH 00/20] introduce " Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1362562189-17783-18-git-send-email-plagnioj@jcrosoft.com \
    --to=plagnioj@jcrosoft.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox