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

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

imlib: refactor a few image methods so that they use vec2i.

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