summaryrefslogtreecommitdiff
path: root/ycurses/src/main.cpp
blob: 1ede8da4e769fabad622ebdf97e50ca8beee6a8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <iostream>
#include <signal.h>

#include "curses/ycurses.h"
#include "examples/example1.h"
#include "examples/example2.h"
#include "examples/example3.h"
#include "examples/example4.h"

using namespace std;

static void finish_demo(int i_signal);

int main(int argc, char* argv[])
{
  /* Catch SIGINT for proper shutdown */
  signal(SIGINT, finish_demo);

  curses cur;

  color col(Red,Black);
  attributes attr(col); 
  attr.set_bold(true);

  coordinate coord(5,5);

  for (;;)
  {
    cursor::set_invisible();

    window win_root(root);
    win_root.print(1, 2, "Examples of ycurses", attr);
    win_root.print(2, 2, "See src/examples/* for the sample code!");

    vector<string> vec_choices; 
    vec_choices.push_back("1. Example with mixed stuff");
    vec_choices.push_back("2. Class pwindow basic usage");
    vec_choices.push_back("3. Class pwindow usage #2");
    vec_choices.push_back("4. Class menu usage");
    vec_choices.push_back("5. Move menu left");
    vec_choices.push_back("6. Move menu right");
    vec_choices.push_back("7. Move menu up");
    vec_choices.push_back("8. Move menu down");
    vec_choices.push_back("9. Exit");
 
    menu menu(vec_choices);
    window& menu_window = menu.get_window();
    pwindow pan(menu_window);
    pan.move(coord);

    switch ( menu.run() )
    {
      case 0:
	cur.clear();
        pan.hide();
	example1();
	break;

      case 1:
        pan.hide();
	cur.clear();
	example2();
	break;

      case 2:
        pan.hide();
	cur.clear();
	example3();
	break;

      case 3:
        pan.hide();
	cur.clear();
	example4();
	break;

      case 4: 
        pan.move(coord.left());
	break;

      case 5: 
        pan.move(coord.right());
	break;

      case 6: 
        pan.move(coord.up());
	break;

      case 7: 
        pan.move(coord.down());
	break;

      case 8:
  	return 0;
    }

    cur.clear();
    pan.show();
  }

  return 0;
}

static void finish_demo(int i_signal)
{
  curses::finish();

  cout << "Process received SIGINT" << endl;
  exit(0);
}