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

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

style: remove trailing spaces, fix copyright statements.

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