-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from jaydg/master
Panel support
- Loading branch information
Showing
4 changed files
with
374 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "ptest", | ||
"description": "Example application for the D pdcurses bindings", | ||
"authors": [ | ||
"Mark Hessling", | ||
"William McBrine", | ||
"Joachim de Groot" | ||
], | ||
"license": "ncurses", | ||
"dependencies": { | ||
"pdcurses-d": { "path": "../../" } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,273 @@ | ||
import core.stdc.stdlib : exit; | ||
import std.conv : to; | ||
import std.string : toStringz; | ||
|
||
import pdcurses; | ||
import pdcurses.panel; | ||
|
||
string[] mod = ["test ", "TEST ", "(**) ", "*()* ", "<--> ", "LAST "]; | ||
|
||
void pflush() | ||
{ | ||
update_panels(); | ||
doupdate(); | ||
} | ||
|
||
void backfill() | ||
{ | ||
erase(); | ||
|
||
foreach (immutable y; 0 .. LINES - 1) | ||
foreach (immutable x; 0 .. COLS) | ||
printw("%d", (y + x) % 10); | ||
} | ||
|
||
void wait_a_while(int msec) | ||
{ | ||
if (msec != 1) | ||
timeout(msec); | ||
|
||
int c = getch(); | ||
|
||
if (c == 'q') | ||
{ | ||
endwin(); | ||
exit(1); | ||
} | ||
} | ||
|
||
void saywhat(immutable string text) | ||
{ | ||
mvprintw(LINES - 1, 0, "%-30.30s", toStringz(text)); | ||
} | ||
|
||
/* mkpanel - alloc a win and panel and associate them */ | ||
|
||
PANEL* mkpanel(int rows, int cols, int tly, int tlx) | ||
{ | ||
WINDOW* win = newwin(rows, cols, tly, tlx); | ||
PANEL* pan; | ||
|
||
if (win) | ||
{ | ||
pan = new_panel(win); | ||
|
||
if (!pan) | ||
delwin(win); | ||
} | ||
|
||
return pan; | ||
} | ||
|
||
void rmpanel(PANEL* pan) | ||
{ | ||
WINDOW* win = pan.win; | ||
|
||
del_panel(pan); | ||
delwin(win); | ||
} | ||
|
||
void fill_panel(PANEL* pan) | ||
{ | ||
char num = *cast(char*)(pan.user + 1); | ||
int maxy, maxx; | ||
|
||
box(pan.win, 0, 0); | ||
mvwprintw(pan.win, 1, 1, "-pan%c-", num); | ||
getmaxyx(pan.win, maxy, maxx); | ||
|
||
foreach (immutable y; 2 .. maxy - 1) | ||
foreach (immutable x; 1 .. maxx - 1) | ||
mvwaddch(pan.win, y, x, num); | ||
} | ||
|
||
int main(string[] args) | ||
{ | ||
PANEL* p1, p2, p3, p4, p5; | ||
WINDOW* w4, w5; | ||
|
||
int nap_msec = 1; | ||
|
||
if (args.length > 1 && to!int(args[1])) | ||
nap_msec = to!int(args[1]); | ||
|
||
initscr(); | ||
curs_set(false); | ||
backfill(); | ||
|
||
foreach (immutable y; 0 .. 5) | ||
{ | ||
p1 = mkpanel(10, 10, 0, 0); | ||
set_panel_userptr(p1, toStringz("p1")); | ||
|
||
p2 = mkpanel(14, 14, 5, 5); | ||
set_panel_userptr(p2, toStringz("p2")); | ||
|
||
p3 = mkpanel(6, 8, 12, 12); | ||
set_panel_userptr(p3, toStringz("p3")); | ||
|
||
p4 = mkpanel(10, 10, 10, 30); | ||
w4 = panel_window(p4); | ||
set_panel_userptr(p4, toStringz("p4")); | ||
|
||
p5 = mkpanel(10, 10, 13, 37); | ||
w5 = panel_window(p5); | ||
set_panel_userptr(p5, toStringz("p5")); | ||
|
||
fill_panel(p1); | ||
fill_panel(p2); | ||
fill_panel(p3); | ||
fill_panel(p4); | ||
fill_panel(p5); | ||
hide_panel(p4); | ||
hide_panel(p5); | ||
pflush(); | ||
wait_a_while(nap_msec); | ||
|
||
saywhat("hide 3, show 1, show 2, show 4, show 5;"); | ||
move_panel(p1, 0, 0); | ||
hide_panel(p3); | ||
show_panel(p1); | ||
show_panel(p2); | ||
show_panel(p4); | ||
show_panel(p5); | ||
pflush(); | ||
wait_a_while(nap_msec); | ||
|
||
saywhat("show 1;"); | ||
show_panel(p1); | ||
pflush(); | ||
wait_a_while(nap_msec); | ||
|
||
saywhat("show 2;"); | ||
show_panel(p2); | ||
pflush(); | ||
wait_a_while(nap_msec); | ||
|
||
saywhat("move 2;"); | ||
move_panel(p2, 10, 10); | ||
pflush(); | ||
wait_a_while(nap_msec); | ||
|
||
saywhat("show 3;"); | ||
show_panel(p3); | ||
pflush(); | ||
wait_a_while(nap_msec); | ||
|
||
saywhat("move 3;"); | ||
move_panel(p3, 5, 5); | ||
pflush(); | ||
wait_a_while(nap_msec); | ||
|
||
saywhat("bottom 3;"); | ||
bottom_panel(p3); | ||
pflush(); | ||
wait_a_while(nap_msec); | ||
|
||
saywhat("show 4;"); | ||
show_panel(p4); | ||
pflush(); | ||
wait_a_while(nap_msec); | ||
|
||
saywhat("show 5;"); | ||
show_panel(p5); | ||
pflush(); | ||
wait_a_while(nap_msec); | ||
|
||
saywhat("top 3;"); | ||
top_panel(p3); | ||
pflush(); | ||
wait_a_while(nap_msec); | ||
|
||
saywhat("top 1;"); | ||
top_panel(p1); | ||
pflush(); | ||
wait_a_while(nap_msec); | ||
|
||
saywhat("top 2;"); | ||
top_panel(p2); | ||
pflush(); | ||
wait_a_while(nap_msec); | ||
|
||
saywhat("top 3;"); | ||
top_panel(p3); | ||
pflush(); | ||
wait_a_while(nap_msec); | ||
|
||
saywhat("top 4;"); | ||
top_panel(p4); | ||
pflush(); | ||
wait_a_while(nap_msec); | ||
|
||
foreach (immutable itmp; 0 .. 6) | ||
{ | ||
saywhat("move 4;"); | ||
mvwaddstr(w4, 3, 1, toStringz(mod[itmp])); | ||
move_panel(p4, 4, itmp * 10); | ||
mvwaddstr(w5, 4, 1, toStringz(mod[itmp])); | ||
pflush(); | ||
wait_a_while(nap_msec); | ||
|
||
saywhat("move 5;"); | ||
mvwaddstr(w4, 4, 1, toStringz(mod[itmp])); | ||
move_panel(p5, 7, itmp * 10 + 6); | ||
mvwaddstr(w5, 3, 1, toStringz(mod[itmp])); | ||
pflush(); | ||
wait_a_while(nap_msec); | ||
} | ||
|
||
saywhat("move 4;"); | ||
move_panel(p4, 4, 60); | ||
pflush(); | ||
wait_a_while(nap_msec); | ||
|
||
saywhat("top 5;"); | ||
top_panel(p5); | ||
pflush(); | ||
wait_a_while(nap_msec); | ||
|
||
saywhat("top 2;"); | ||
top_panel(p2); | ||
pflush(); | ||
wait_a_while(nap_msec); | ||
|
||
saywhat("top 1;"); | ||
top_panel(p1); | ||
pflush(); | ||
wait_a_while(nap_msec); | ||
|
||
saywhat("delete 2;"); | ||
rmpanel(p2); | ||
pflush(); | ||
wait_a_while(nap_msec); | ||
|
||
saywhat("hide 3;"); | ||
hide_panel(p3); | ||
pflush(); | ||
wait_a_while(nap_msec); | ||
|
||
saywhat("delete 1;"); | ||
rmpanel(p1); | ||
pflush(); | ||
wait_a_while(nap_msec); | ||
|
||
saywhat("delete 4; "); | ||
rmpanel(p4); | ||
pflush(); | ||
wait_a_while(nap_msec); | ||
|
||
saywhat("delete 5; "); | ||
rmpanel(p5); | ||
pflush(); | ||
wait_a_while(nap_msec); | ||
|
||
if (nap_msec == 1) | ||
break; | ||
|
||
nap_msec = 100L; | ||
} | ||
|
||
endwin(); | ||
|
||
return 0; | ||
} /* end of main */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
module pdcurses.panel; | ||
|
||
import pdcurses.curses; | ||
|
||
/* Public Domain Curses */ | ||
|
||
/*----------------------------------------------------------------------* | ||
* Panels for PDCurses * | ||
*----------------------------------------------------------------------*/ | ||
|
||
extern (C): | ||
|
||
struct panelobs | ||
{ | ||
panelobs* above; | ||
panel* pan; | ||
} | ||
|
||
alias PANELOBS = panelobs; | ||
|
||
struct panel | ||
{ | ||
WINDOW* win; | ||
int wstarty; | ||
int wendy; | ||
int wstartx; | ||
int wendx; | ||
panel* below; | ||
panel* above; | ||
const(void)* user; | ||
panelobs* obscure; | ||
} | ||
|
||
alias PANEL = panel; | ||
|
||
int bottom_panel (PANEL* pan); | ||
int del_panel (PANEL* pan); | ||
int hide_panel (PANEL* pan); | ||
int move_panel (PANEL* pan, int starty, int startx); | ||
PANEL* new_panel (WINDOW* win); | ||
PANEL* panel_above (const(PANEL)* pan); | ||
PANEL* panel_below (const(PANEL)* pan); | ||
int panel_hidden (const(PANEL)* pan); | ||
const(void)* panel_userptr (const(PANEL)* pan); | ||
WINDOW* panel_window (const(PANEL)* pan); | ||
int replace_panel (PANEL* pan, WINDOW* win); | ||
int set_panel_userptr (PANEL* pan, const(void)* uptr); | ||
int show_panel (PANEL* pan); | ||
int top_panel (PANEL* pan); | ||
void update_panels (); |