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
|
#include "macs.hpp"
#include "status.hpp"
#include "dprint.hpp"
status_manager *stat_man=NULL;
class text_status_node
{
public :
char *name;
text_status_node *next;
visual_object *show;
int last_update;
text_status_node(char *Name, visual_object *Show, text_status_node *Next)
{ name=strcpy((char *)jmalloc(strlen(Name)+1,"status name"),Name);
show=Show;
next=Next;
last_update=0;
}
~text_status_node() { jfree(name); if (show) delete show; }
} ;
text_status_manager::text_status_manager()
{
first=NULL;
level=0;
}
void text_status_manager::push(char *name, visual_object *show)
{
level++;
first=new text_status_node(name,show,first);
}
void text_status_manager::update(int percentage)
{
// return;
if (level==1 && percentage-first->last_update>4)
{
char s[256], len;
first->last_update=percentage;
sprintf(s,"\r%s [",first->name);
len = strlen(s);
int t=percentage*40/100;
int i=0;
for (;i<t;i++)
s[len+i] = '.';
for (;i<40;i++)
s[len+i] = ' ';
s[len+i++] = ']';
s[len+i] = 0;
dprintf("%s",s);
}
}
void text_status_manager::pop()
{
CONDITION(first,"No status's to pop!");
if (level==1) dprintf("\n");
level--;
text_status_node *p=first; first=first->next;
delete p;
}
|