diff options
author | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2011-10-09 12:33:48 +0000 |
---|---|---|
committer | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2011-10-09 12:33:48 +0000 |
commit | 0f2c685db3d3790ce9bdc9598df8dae7d6b67eae (patch) | |
tree | a2c2a7f8941e87368ee46163e028c553d1b6bcdf /src/essais | |
download | 2011-ddhardrescue-0f2c685db3d3790ce9bdc9598df8dae7d6b67eae.tar.gz 2011-ddhardrescue-0f2c685db3d3790ce9bdc9598df8dae7d6b67eae.tar.bz2 2011-ddhardrescue-0f2c685db3d3790ce9bdc9598df8dae7d6b67eae.zip |
On range tout le code actuel du trunk dans une branche nommée "0.x" et on crée une branche 1.x qui contiendra une nouvelle mouture (re-conception, méta info de packaging...).origin/0.x
git-svn-id: file:///var/svn/2011-ddhardrescue/branches/0.x@29 d3078510-dda0-49f1-841c-895ef4b7ec81
Diffstat (limited to 'src/essais')
-rwxr-xr-x | src/essais/compil.sh | 4 | ||||
-rw-r--r-- | src/essais/test.c | 86 | ||||
-rw-r--r-- | src/essais/test2.c | 121 | ||||
-rw-r--r-- | src/essais/test3.c | 169 |
4 files changed, 380 insertions, 0 deletions
diff --git a/src/essais/compil.sh b/src/essais/compil.sh new file mode 100755 index 0000000..a867c5a --- /dev/null +++ b/src/essais/compil.sh @@ -0,0 +1,4 @@ +#!/bin/bash +gcc -Wall -o ../../bin/test -g -lncurses test.c +gcc -Wall -o ../../bin/test2 -g -lncurses -lpanel test2.c +gcc -Wall -o ../../bin/test3 -g -lncurses -lpanel test3.c diff --git a/src/essais/test.c b/src/essais/test.c new file mode 100644 index 0000000..3a3e73f --- /dev/null +++ b/src/essais/test.c @@ -0,0 +1,86 @@ +#include <ncurses.h> + +WINDOW *create_newwin(int height, int width, int starty, int startx) +{ WINDOW *local_win; + + local_win = newwin(height, width, starty, startx); + wborder(local_win, '|', '|', '-', '-', '+', '+', '+', '+'); +// box(local_win,0,0); + wrefresh(local_win); + return local_win; +} + +int main() { + +/* + A_NORMAL Normal display (no highlight) + A_STANDOUT Best highlighting mode of the terminal. + A_UNDERLINE Underlining + A_REVERSE Reverse video + A_BLINK Blinking + A_DIM Half bright + A_BOLD Extra bright or bold + A_PROTECT Protected mode + A_INVIS Invisible or blank mode + A_ALTCHARSET Alternate character set + A_CHARTEXT Bit-mask to extract a character + COLOR_PAIR(n) Color-pair number n +*/ + int end, ch; + int row,col; + char msg[256]; + WINDOW *w1; + MEVENT event; + + initscr(); + getmaxyx(stdscr,row,col); + raw(); + keypad(stdscr, TRUE); + noecho(); + + start_color(); + init_pair(1, COLOR_WHITE, COLOR_BLUE); + + mousemask(ALL_MOUSE_EVENTS, NULL); +//http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/windows.html + //w1 = create_newwin(row/2, col/2, row/4, col/4); + w1 = create_newwin(10, 10, 10, 10); + attron(COLOR_PAIR(1) | A_BOLD); + mvprintw(row-2,0,"This screen has %d rows and %d columns\n",row,col); + attroff(COLOR_PAIR(1) | A_BOLD); + move(0,0); + + + end=0; + while (!end) { + refresh(); + ch=getch(); + switch(ch) { + case KEY_MOUSE: + if(getmouse(&event) == OK) { /* When the user clicks left mouse button */ + if(event.bstate & BUTTON1_PRESSED) { + attrset(A_NORMAL); + printw("mouse button1\n"); + } + } + break; + case KEY_F(2): + attrset(A_NORMAL); + printw("F2 key\n"); + break; + case 'q': + end=1; + break; + case 'b': + mvwchgat(w1,1,0,-1, A_REVERSE, 0, NULL); + break; + default: + sprintf(msg, "%c key\n", ch); + wattrset(w1,A_BOLD | A_UNDERLINE); + wprintw(w1, msg); + } + } + endwin(); + + return 0; +} diff --git a/src/essais/test2.c b/src/essais/test2.c new file mode 100644 index 0000000..3512329 --- /dev/null +++ b/src/essais/test2.c @@ -0,0 +1,121 @@ + +#include <string.h> +#include <panel.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() +{ 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 (F2 to Exit)"); + attroff(COLOR_PAIR(4)); + doupdate(); + + top = my_panels[2]; + while((ch = getch()) != KEY_F(2)) + { 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(); +} + diff --git a/src/essais/test3.c b/src/essais/test3.c new file mode 100644 index 0000000..c763cf3 --- /dev/null +++ b/src/essais/test3.c @@ -0,0 +1,169 @@ + +#include <string.h> +#include <panel.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() +{ WINDOW *my_wins[3]; + PANEL *my_panels[3]; + PANEL *top, *p, *pe; + int ch, res; + mmask_t mmask; + MEVENT mevent; + char buf[255]; + + /* Initialize curses */ + initscr(); + start_color(); + cbreak(); + noecho(); + keypad(stdscr, TRUE); + mmask = mousemask(REPORT_MOUSE_POSITION|BUTTON1_CLICKED, NULL); + + /* 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 (F2 to Exit)"); + sprintf(buf, "Debug infos : mmask=%lx", mmask); + mvprintw(LINES - 3, 0, buf); + attroff(COLOR_PAIR(4)); + doupdate(); + + top = my_panels[2]; + while((ch = getch()) != KEY_F(2)) + { switch(ch) + { case 9: // This is tab key, but ive not found the right symbol... other that '\t' + top = (PANEL *)panel_userptr(top); + top_panel(top); + break; + case KEY_MOUSE: + // Seems to have a mouse event + res = getmouse(&mevent); + if ( res == OK ) { + // Try to find in which panel (search first in top-level panel and go down) + pe=NULL; + p=top; + do { + if ((p == NULL) || wenclose(panel_window(p), mevent.y, mevent.x) ) { + pe = p; + break; + } + p = (PANEL *)panel_userptr(top); + } while (p != top); + + // If we found a panel + if (pe != NULL) { + // "switch" depending on event kind + if ( (mevent.bstate & BUTTON1_CLICKED) == BUTTON1_CLICKED) { + // A panel was clicked, set that panel on top + top = pe; + top_panel(top); + // FIXME : the userptr chain of panel must reflect panel order ! + // Or may be we can crawl panels by order with ncurses method + } + } +/* + if ( (mevent.bstate & BUTTON1_CLICKED) == BUTTON1_CLICKED) { + attron(COLOR_PAIR(4)); + sprintf(buf, "BUTTON1_CLICKED at %i/%i/%i ", mevent.x, mevent.y, mevent.z); + mvprintw(LINES - 4, 0, buf); + attroff(COLOR_PAIR(4)); + + } + */ + } + break; + default: + attron(COLOR_PAIR(4)); + sprintf(buf, "Unknown key : 0x%x ", ch); + mvprintw(LINES - 3, 0, buf); + attroff(COLOR_PAIR(4)); + } + 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(); +} + |