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

Last change on this file since 518 was 512, checked in by Sam Hocevar, 12 years ago

imlib: use vec2i for image::size and unroll all necessary changes
everywhere else in the code.

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