source: abuse/trunk/src/imlib/status.cpp @ 131

Last change on this file since 131 was 131, checked in by Sam Hocevar, 15 years ago
  • Use strdup(foo) everywhere instead of strcpy(malloc(strlen(foo)+1),foo);
File size: 1.5 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
4 *
5 *  This software was released into the Public Domain. As with most public
6 *  domain software, no warranty is made or implied by Crack dot Com or
7 *  Jonathan Clark.
8 */
9
10#include "config.h"
11
12#include <string.h>
13
14#include "macs.hpp"
15#include "status.hpp"
16#include "dprint.hpp"
17
18status_manager *stat_man=NULL;
19
20class text_status_node
21{
22  public :
23  char *name;
24  text_status_node *next;
25  visual_object *show;
26  int last_update;
27  text_status_node(char const *Name, visual_object *Show, text_status_node *Next)
28  { name = strdup(Name);
29    show = Show;
30    next = Next;
31    last_update = 0;
32  }
33  ~text_status_node() { free(name); if (show) delete show; }
34} ;
35
36
37
38text_status_manager::text_status_manager()
39{
40  first=NULL;
41  level=0;
42}
43
44void text_status_manager::push(char const *name, visual_object *show)
45{
46  level++;
47  first=new text_status_node(name,show,first);
48}
49
50void text_status_manager::update(int percentage)
51{
52//    return;
53  if (level==1 && percentage-first->last_update>4)
54  {
55      char s[256], len;
56    first->last_update=percentage;
57    sprintf(s,"\r%s [",first->name);
58    len = strlen(s);
59    int t=percentage*40/100;
60    int i=0;
61    for (;i<t;i++)
62      s[len+i] = '.';
63    for (;i<40;i++)
64        s[len+i] = ' ';
65    s[len+i++] = ']';
66    s[len+i] = 0;
67    dprintf("%s",s);
68  }
69}
70
71void text_status_manager::pop()
72{
73  CONDITION(first,"No status's to pop!");
74  if (level==1) dprintf("\n");
75  level--;
76  text_status_node *p=first; first=first->next;
77  delete p;
78}
79
80
81
82
83
Note: See TracBrowser for help on using the repository browser.