1 | #include "netstat.hpp" |
---|
2 | #include "dprint.hpp" |
---|
3 | #include "cache.hpp" |
---|
4 | #include "jwindow.hpp" |
---|
5 | |
---|
6 | extern palette *pal; |
---|
7 | static int old_xres; |
---|
8 | |
---|
9 | extern window_manager *eh; |
---|
10 | |
---|
11 | class net_status_node |
---|
12 | { |
---|
13 | public : |
---|
14 | char *name; |
---|
15 | net_status_node *next; |
---|
16 | visual_object *show; |
---|
17 | int last_update; |
---|
18 | |
---|
19 | net_status_node(char *Name, visual_object *Show, net_status_node *Next) |
---|
20 | { |
---|
21 | name=strcpy((char *)jmalloc(strlen(Name)+1,"status name"),Name); |
---|
22 | show=Show; |
---|
23 | next=Next; |
---|
24 | last_update=0; |
---|
25 | } |
---|
26 | ~net_status_node() { jfree(name); if (show) delete show; } |
---|
27 | } ; |
---|
28 | |
---|
29 | net_status_manager::net_status_manager(char *graphic_file, |
---|
30 | int x1, int y1, |
---|
31 | int x2, int y2, |
---|
32 | int color1, int color2) : g_file(graphic_file), color1(color1), color2(color2) |
---|
33 | { |
---|
34 | first_x1=x1; |
---|
35 | first_y1=y1; |
---|
36 | |
---|
37 | |
---|
38 | if (x2-x1<y2-y1) |
---|
39 | { |
---|
40 | first_x2=(x1+x2)/2-1; |
---|
41 | first_y2=y2; |
---|
42 | second_x1=(x1+x2)/2+1; |
---|
43 | } else |
---|
44 | { |
---|
45 | first_x2=x2; |
---|
46 | first_y2=(y1+y2)/2-1; |
---|
47 | second_x1=x1; |
---|
48 | second_y1=(y1+y2)/2+1; |
---|
49 | } |
---|
50 | second_x2=x2; |
---|
51 | second_y2=y2; |
---|
52 | |
---|
53 | |
---|
54 | first=NULL; |
---|
55 | level=0; |
---|
56 | } |
---|
57 | |
---|
58 | void load_image_into_screen(char *filename, char *name, int &x_loaded, int &y_loaded); |
---|
59 | |
---|
60 | void net_status_manager::push(char *name, visual_object *show) |
---|
61 | { |
---|
62 | |
---|
63 | |
---|
64 | level++; |
---|
65 | first=new net_status_node(name,show,first); |
---|
66 | if (level==1) |
---|
67 | { |
---|
68 | screen->clear(); |
---|
69 | update_dirty(screen); // make sure the screen is actually clear before we mess with the palette |
---|
70 | |
---|
71 | // save a copy of the old palette |
---|
72 | if (pal) |
---|
73 | old_pal=pal->copy(); |
---|
74 | else old_pal=0; |
---|
75 | bFILE *fp=open_file(g_file,"rb"); |
---|
76 | if (fp->open_failure()) |
---|
77 | { |
---|
78 | dprintf("Unable to open art/status.spe\n"); |
---|
79 | exit(0); |
---|
80 | } |
---|
81 | |
---|
82 | old_xres=xres; |
---|
83 | switch_mode(VMODE_640x480); |
---|
84 | |
---|
85 | spec_directory sd(fp); |
---|
86 | spec_entry *se=sd.find(SPEC_PALETTE); // find the palette used by this screen |
---|
87 | fp->seek(se->offset,0); |
---|
88 | palette new_pal(fp); |
---|
89 | new_pal.load(); |
---|
90 | delete fp; |
---|
91 | |
---|
92 | // now load the status image direct into our back buffer so that |
---|
93 | // another image is not allocated |
---|
94 | int x,y; |
---|
95 | load_image_into_screen(g_file,"status",x,y); |
---|
96 | xp=x; yp=y; |
---|
97 | |
---|
98 | // cash.img(cash.reg("art/status.spe","status", SPEC_IMAGE,1))->put_image(screen,0,0); |
---|
99 | // xp=0; |
---|
100 | // yp=0; |
---|
101 | |
---|
102 | update_dirty(screen); |
---|
103 | } |
---|
104 | |
---|
105 | |
---|
106 | |
---|
107 | } |
---|
108 | |
---|
109 | void draw_bar(int x1, int y1, int x2, int y2, int percent, int color) |
---|
110 | { |
---|
111 | int h=(y2-y1)*percent/100; |
---|
112 | int w=(x2-x1)*percent/100; |
---|
113 | |
---|
114 | if (h>w) |
---|
115 | { |
---|
116 | screen->bar(x1,y2-h,x2,y2,color); |
---|
117 | if (y2-h!=y1) |
---|
118 | screen->bar(x1,y1,x2,y2-h-1,0); |
---|
119 | } else |
---|
120 | { |
---|
121 | screen->bar(x1,y1,x1+w,y2,color); |
---|
122 | if (x2-x1!=w) |
---|
123 | screen->bar(x1+w+1,y1,x2,y2,0); |
---|
124 | } |
---|
125 | } |
---|
126 | |
---|
127 | |
---|
128 | void net_status_manager::update(int percentage) |
---|
129 | { |
---|
130 | if (level==last_level && percentage==last_percent) |
---|
131 | return ; |
---|
132 | |
---|
133 | if (level==1) |
---|
134 | first_percent=percentage; |
---|
135 | |
---|
136 | if (level==1 || level==2) |
---|
137 | { |
---|
138 | draw_bar(xp+first_x1,yp+first_y1,xp+first_x2,yp+first_y2,first_percent,color1); |
---|
139 | } |
---|
140 | |
---|
141 | if (level==2) |
---|
142 | { |
---|
143 | draw_bar(xp+second_x1,yp+second_y1,xp+second_x2,yp+second_y2,percentage,color2); |
---|
144 | } |
---|
145 | |
---|
146 | last_percent=percentage; |
---|
147 | last_level=level; |
---|
148 | |
---|
149 | update_dirty(screen); |
---|
150 | } |
---|
151 | |
---|
152 | |
---|
153 | void net_status_manager::pop() |
---|
154 | { |
---|
155 | // return; |
---|
156 | |
---|
157 | level--; |
---|
158 | if (level==0) |
---|
159 | { |
---|
160 | |
---|
161 | screen->clear(); |
---|
162 | update_dirty(screen); |
---|
163 | |
---|
164 | if (old_xres<=320) |
---|
165 | switch_mode(VMODE_320x200); |
---|
166 | |
---|
167 | if (eh) |
---|
168 | { |
---|
169 | event e,*ev=new event; |
---|
170 | |
---|
171 | ev->type=EV_REDRAW; |
---|
172 | ev->redraw.x1=0; |
---|
173 | ev->redraw.y1=0; |
---|
174 | ev->redraw.x2=xres; |
---|
175 | ev->redraw.y2=yres; |
---|
176 | |
---|
177 | eh->push_event(ev); |
---|
178 | eh->get_event(e); // cause the window manager to process this event |
---|
179 | } |
---|
180 | |
---|
181 | if (old_pal) |
---|
182 | { |
---|
183 | old_pal->load(); |
---|
184 | delete old_pal; |
---|
185 | } |
---|
186 | |
---|
187 | } |
---|
188 | |
---|
189 | net_status_node *p=first; |
---|
190 | first=first->next; |
---|
191 | delete p; |
---|
192 | |
---|
193 | if (level==0) |
---|
194 | { |
---|
195 | } |
---|
196 | } |
---|
197 | |
---|
198 | |
---|
199 | |
---|
200 | |
---|
201 | |
---|