Imported Upstream version 2.9.0
[debian/cc1111] / sim / ucsim / gui.src / obsolete / app.cc
1 /*
2  * Simulator of microcontrollers (app.cc)
3  *
4  * Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
5  * 
6  * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
7  *
8  */
9
10 /* This file is part of microcontroller simulator: ucsim.
11
12 UCSIM is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 UCSIM is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with UCSIM; see the file COPYING.  If not, write to the Free
24 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 02111-1307, USA. */
26 /*@1@*/
27
28 #include <stdlib.h>
29
30 #include "appcl.h"
31 #include "deskcl.h"
32
33
34 cl_app::cl_app(char *iname):
35   cl_group(iname, this)
36 {
37   drawn= 0;
38 }
39
40 cl_app::~cl_app(void)
41 {
42   endwin();
43 }
44
45 int
46 cl_app::init(void)
47 {
48   initscr();
49   keypad(stdscr, TRUE);
50   nonl();
51   cbreak();
52   noecho();
53   
54   pos= new cl_box(0,0, COLS, LINES);
55   cl_view::init();
56   state|= SF_SELECTED;//select();
57   class cl_box b(*pos);
58   //b.move_rel(0,1);
59   //b.grow(0,-2);
60   if ((desk= mk_desk(&b)))
61     insert(desk);
62   desk->select();
63   mk_views(desk);
64
65   //update();
66   update_panels();
67   doupdate();
68   return(0);
69 }
70
71 class cl_gin *
72 cl_app::mk_input(void)
73 {
74   class cl_gin *i= new cl_gin();
75   i->init();
76   i->add_input(stdin, 0);
77   return(i);
78 }
79
80 int *
81 cl_app::mk_palette(void)
82 {
83   int *p, i;
84   int colors;
85
86   colors= 64;
87   p= (int*)malloc(colors * sizeof(int));
88   if (has_colors())
89     {
90       start_color();
91
92       init_pair(i= C_WIN+C_WIN_NORMAL, COLOR_YELLOW, COLOR_BLUE);
93       p[i]= COLOR_PAIR(i)|A_BOLD;
94       for (i= 1; i < colors; i++)
95         p[i]= p[C_WIN+C_WIN_NORMAL];
96       // desktop
97       init_pair(i= C_DSK_BG, COLOR_BLACK, COLOR_WHITE);
98       p[i]= COLOR_PAIR(i);
99       // menus and status bar
100       init_pair(i= C_DSK_NORMAL, COLOR_WHITE, COLOR_BLUE);
101       p[i]= COLOR_PAIR(i)|A_BOLD;
102       init_pair(i= C_DSK_DISABLED, COLOR_WHITE, COLOR_BLUE);
103       p[i]= COLOR_PAIR(i);
104       // window
105       init_pair(i= C_WIN+C_WIN_FPASSIVE, COLOR_WHITE, COLOR_BLUE);
106       p[i]= COLOR_PAIR(i);
107       init_pair(i= C_WIN+C_WIN_FACTIVE, COLOR_WHITE, COLOR_BLUE);
108       p[i]= COLOR_PAIR(i)|A_BOLD;
109       init_pair(i= C_WIN+C_WIN_SELECTED, COLOR_YELLOW, COLOR_RED);
110       p[i]= COLOR_PAIR(i)|A_BOLD; 
111     }
112   else
113     {
114       for (i= 0; i < colors; i++)
115         p[i]= A_NORMAL;
116       p[C_WIN+C_WIN_FACTIVE]|= A_BOLD;
117       p[C_WIN+C_WIN_SELECTED]|= A_REVERSE;
118     }
119   return(p);
120 }
121
122 class cl_group *
123 cl_app::mk_desk(class cl_box *ipos)
124 {
125   class cl_group *d= new cl_desk(ipos, "desktop", this);
126   d->init();
127   return(d);
128 }
129
130
131 int
132 cl_app::handle_event(struct t_event *event)
133 {
134   if (!cl_group::handle_event(event))
135     {
136       if (event->what == EV_KEY)
137         switch (event->event.key)
138           {
139           case KEY_BREAK: case KEY_EXIT:
140             event->what= EV_COMMAND;
141             event->event.msg.cmd= CMD_QUIT;
142             break;
143           }
144     }
145   return(0);
146 }
147
148 int
149 cl_app::run(void)
150 {
151   struct t_event event;
152   
153   drawn= 0;
154   while (get_event(&event))
155     {
156       if (!handle_event(&event))
157         {
158           if (event.what == EV_COMMAND &&
159               event.event.msg.cmd == CMD_QUIT)
160             return(0);
161           unhandled(&event);
162         }
163       if (drawn)
164         update();
165       drawn= 0;
166     }
167   return(0);
168 }
169
170
171 /* End of gui.src/app.cc */