2 * Silly demo program for the NCursesPanel class.
4 * written by Anatoly Ivasyuk (anatoly@nick.csh.rit.edu)
6 * $Id: demo.cc,v 1.7 1997/05/05 20:53:41 tom Exp $
20 void run(int sleeptime) {
21 // We need to define a full screen panel for the main screen so
22 // that when redraws happen, the main screen actually gets redrawn.
23 // I think there may be a bug in the panels code which won't redraw
24 // the main screen otherwise. Maybe someone out there can find it...
26 NCursesPanel *std = new NCursesPanel();
28 // Make a few small demo panels
30 NCursesPanel *u = new NCursesPanel(10,20,12,4);
31 NCursesPanel *v = new NCursesPanel(10,20,10,6);
32 NCursesPanel *w = new NCursesPanel(10,20,8,8);
33 NCursesPanel *x = new NCursesPanel(10,20,6,10);
34 NCursesPanel *y = new NCursesPanel(10,20,4,12);
35 NCursesPanel *z = new NCursesPanel(10,30,2,14);
37 // Draw something on the main screen, so we can see what happens
38 // when panels get moved or deleted.
46 // Draw frames with titles around panels so that we can see where
47 // the panels are located.
49 u->boldframe("Win U");
51 w->boldframe("Win W");
53 y->boldframe("Win Y");
56 // A refresh to any valid panel updates all panels and refreshes
57 // the screen. Using std is just convenient - We know it's always
58 // valid until the end of the program.
62 // Show that things actually come back correctly when the screen
63 // is cleared and the global NCursesPanel::redraw() is called.
66 ::clear(); // call ncurses clear() directly
67 ::wrefresh(stdscr); // call ncurses refresh directly
69 NCursesPanel::redraw();
71 // Show what happens when panels are deleted and moved.
85 // show how it looks when a panel moves
94 // show how it looks when you raise a panel
107 // Don't forget to clean up the main screen. Since this is the
108 // last thing using NCursesWindow, this has the effect of
109 // shutting down ncurses and restoring the terminal state.
122 UserData(int x) : u(x) {}
123 int sleeptime() const { return u; }
127 template<class T> class MyAction : public NCursesUserItem<T>
130 MyAction (const T* p_UserData,
132 : NCursesUserItem<T>(p_UserData, p_name)
139 a.run(UserData()->sleeptime());
144 class QuitItem : public NCursesMenuItem
147 QuitItem() : NCursesMenuItem("Quit") {
156 class MyMenu : public NCursesMenu
162 MyMenu (NCursesMenuItem* menu[])
163 : NCursesMenu (menu, 7, 8, 2, 2, TRUE)
165 if (NCursesWindow::NumberOfColors() > 2) {
167 setpalette(COLOR_YELLOW, COLOR_BLUE);
170 P = new NCursesPanel(1,COLS,LINES-1,0);
171 boldframe("Demo","Silly");
181 virtual void On_Menu_Init()
186 NCursesPanel::refresh();
189 virtual void On_Menu_Termination()
193 P->addstr("Menu Exit");
194 NCursesPanel::refresh();
197 virtual void On_Item_Init(NCursesMenuItem& item)
199 P->move(0,item.index());
200 P->attron(A_REVERSE);
201 P->printw("%1d",1+item.index());
202 P->attroff(A_REVERSE);
203 NCursesPanel::refresh();
206 virtual void On_Item_Termination(NCursesMenuItem& item)
208 P->move(0,item.index());
209 P->attroff(A_REVERSE);
210 P->printw("%1d",1+item.index());
211 NCursesPanel::refresh();
217 UserData* u = new UserData(1);
219 NCursesWindow::useColors();
221 NCursesMenuItem** I = new NCursesMenuItem*[6];
222 I[0] = new NCursesMenuItem("One");
223 I[1] = new NCursesMenuItem("Two");
224 I[2] = new MyAction<UserData> (u, "Silly");
225 I[3] = new NCursesMenuItem("Four");
226 I[4] = new QuitItem();
227 I[5] = new NCursesMenuItem();
233 for(int i=0; i < 6; i++) {