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

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