source: abuse/trunk/src/imlib/guistat.cpp @ 481

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

Fuck the history, I'm renaming all .hpp files to .h for my own sanity.

File size: 3.3 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 "input.h"
15#include "status.h"
16#include "timing.h"
17#include "guistat.h"
18
19class gui_status_node
20{
21  public :
22  char *name;
23  gui_status_node *next;
24  visual_object *show;
25  Jwindow *stat_win;
26  int last_update;
27  time_marker last_time;
28  gui_status_node(char const *Name, visual_object *Show, gui_status_node *Next)
29  { name = strdup(Name);
30    show=Show;
31    next=Next;
32    last_update=0;
33    stat_win=NULL;
34  }
35  ~gui_status_node();
36} ;
37
38
39gui_status_node::~gui_status_node()
40{
41  free(name);
42  if (show)
43    delete show;
44  if (stat_win)
45  {
46    wm->close_window(stat_win);
47    wm->flush_screen();
48  }
49}
50
51void gui_status_manager::draw_bar(gui_status_node *whom, int perc)
52{
53  long l=whom->stat_win->x2()-whom->stat_win->x1()-6;
54  long h=wm->font()->height();
55
56  whom->stat_win->screen->bar(whom->stat_win->x1()+1,whom->stat_win->y2()-h-1,whom->stat_win->x2()-1,
57              whom->stat_win->y2()-1,wm->black());
58  whom->stat_win->screen->bar(whom->stat_win->x1()+2,whom->stat_win->y2()-h,whom->stat_win->x2()-2,
59              whom->stat_win->y2()-2,wm->dark_color());
60  if (perc)
61    whom->stat_win->screen->bar(whom->stat_win->x1()+3,whom->stat_win->y2()-h+1,
62                whom->stat_win->x1()+l*perc/100,
63                whom->stat_win->y2()-3,wm->bright_color());
64}
65
66void gui_status_manager::push(char const *name, visual_object *show)
67{
68  first=new gui_status_node(name,show,first);
69}
70
71gui_status_manager::gui_status_manager()
72{
73  first=NULL;
74  strcpy(title,"STATUS");
75  last_perc=0;
76}
77
78void gui_status_manager::update(int percentage)
79{
80  last_perc=percentage;
81  if (first)
82  {
83    if (!first->stat_win)
84    {
85      time_marker now;
86      if (now.diff_time(&first->last_time)>1)
87      {
88    long wx=xres/2,wy=10,len1=strlen(first->name)*wm->font()->width()+10,len2=0,len3,
89      h1=wm->font()->height()+5,h2=first->show ? first->show->height() : 0;
90
91    if (first->show) len2=first->show->width()/2;
92    if (len2>len1) len3=len2; else len3=len1;
93    wx-=len3/2;
94   
95   
96    gui_status_node *p=first->next;
97    while (p && !p->stat_win) p=p->next;
98    if (p) wy=p->stat_win->y+p->stat_win->y2()+5;
99
100    int mx = first->stat_win->x1() + 1;
101    int my = first->stat_win->y1() + wm->font()->height() / 2;
102    first->stat_win=wm->new_window(wx, wy, len3, h1*2+h2, NULL, "status");
103    wm->font()->put_string(first->stat_win->screen, mx, my, first->name, wm->black());
104    wm->font()->put_string(first->stat_win->screen, mx, my, first->name, wm->bright_color());
105    if (first->show)
106      first->show->draw(first->stat_win->screen, (first->stat_win->x2()-first->stat_win->x1())/2-
107                first->show->width()/2, my+h1, NULL);
108
109    draw_bar(first,percentage);
110    wm->flush_screen();
111      }
112    } else
113    {
114      if (percentage>first->last_update)
115      {
116    first->last_update=percentage;
117    draw_bar(first,percentage);
118    wm->flush_screen();
119      }
120    }
121  }
122}
123
124void gui_status_manager::force_display()
125{
126  update(last_perc);
127}
128
129void gui_status_manager::pop()
130{
131  CONDITION(first,"No status's to pop!");
132  gui_status_node *p=first;
133  first=first->next;
134  delete p;
135}
136
137
138
139
140
141
142
143
144
Note: See TracBrowser for help on using the repository browser.