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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
* Abuse - dark 2D side-scrolling platform game
* Copyright (c) 1995 Crack dot Com
* Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
*
* This software was released into the Public Domain. As with most public
* domain software, no warranty is made or implied by Crack dot Com, by
* Jonathan Clark, or by Sam Hocevar.
*/
#if defined HAVE_CONFIG_H
# include "config.h"
#endif
#include <string.h>
#include "common.h"
#include "input.h"
#include "status.h"
#include "timing.h"
#include "guistat.h"
class gui_status_node
{
public :
char *name;
gui_status_node *next;
visual_object *show;
Jwindow *stat_win;
int last_update;
time_marker last_time;
gui_status_node(char const *Name, visual_object *Show, gui_status_node *Next)
{ name = strdup(Name);
show=Show;
next=Next;
last_update=0;
stat_win=NULL;
}
~gui_status_node();
} ;
gui_status_node::~gui_status_node()
{
free(name);
if (show)
delete show;
if (stat_win)
{
wm->close_window(stat_win);
wm->flush_screen();
}
}
void gui_status_manager::draw_bar(gui_status_node *whom, int perc)
{
long l=whom->stat_win->x2()-whom->stat_win->x1()-6;
long h=wm->font()->height();
whom->stat_win->screen->bar(whom->stat_win->x1()+1,whom->stat_win->y2()-h-1,whom->stat_win->x2()-1,
whom->stat_win->y2()-1,wm->black());
whom->stat_win->screen->bar(whom->stat_win->x1()+2,whom->stat_win->y2()-h,whom->stat_win->x2()-2,
whom->stat_win->y2()-2,wm->dark_color());
if (perc)
whom->stat_win->screen->bar(whom->stat_win->x1()+3,whom->stat_win->y2()-h+1,
whom->stat_win->x1()+l*perc/100,
whom->stat_win->y2()-3,wm->bright_color());
}
void gui_status_manager::push(char const *name, visual_object *show)
{
first=new gui_status_node(name,show,first);
}
gui_status_manager::gui_status_manager()
{
first=NULL;
strcpy(title,"STATUS");
last_perc=0;
}
void gui_status_manager::update(int percentage)
{
last_perc=percentage;
if (first)
{
if (!first->stat_win)
{
time_marker now;
if (now.diff_time(&first->last_time)>1)
{
long wx=xres/2,wy=10,len1=strlen(first->name)*wm->font()->width()+10,len2=0,len3,
h1=wm->font()->height()+5,h2=first->show ? first->show->height() : 0;
if (first->show) len2=first->show->width()/2;
if (len2>len1) len3=len2; else len3=len1;
wx-=len3/2;
gui_status_node *p=first->next;
while (p && !p->stat_win) p=p->next;
if (p) wy=p->stat_win->y+p->stat_win->y2()+5;
int mx = first->stat_win->x1() + 1;
int my = first->stat_win->y1() + wm->font()->height() / 2;
first->stat_win=wm->new_window(wx, wy, len3, h1*2+h2, NULL, "status");
wm->font()->put_string(first->stat_win->screen, mx, my, first->name, wm->black());
wm->font()->put_string(first->stat_win->screen, mx, my, first->name, wm->bright_color());
if (first->show)
first->show->draw(first->stat_win->screen, (first->stat_win->x2()-first->stat_win->x1())/2-
first->show->width()/2, my+h1, NULL);
draw_bar(first,percentage);
wm->flush_screen();
}
} else
{
if (percentage>first->last_update)
{
first->last_update=percentage;
draw_bar(first,percentage);
wm->flush_screen();
}
}
}
}
void gui_status_manager::force_display()
{
update(last_perc);
}
void gui_status_manager::pop()
{
CONDITION(first,"No status's to pop!");
gui_status_node *p=first;
first=first->next;
delete p;
}