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

Last change on this file since 56 was 56, checked in by Sam Hocevar, 11 years ago
  • Add licensing terms to most C / C++ files (Ref #5).
File size: 3.4 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 "status.hpp"
13#include "timing.hpp"
14#include "guistat.hpp"
15
16class gui_status_node
17{
18  public : 
19  char *name;
20  gui_status_node *next;
21  visual_object *show;
22  jwindow *stat_win;
23  window_manager *wm;
24  int last_update;
25  time_marker last_time;
26  gui_status_node(char const *Name, visual_object *Show, window_manager *WM, gui_status_node *Next)
27  { name=strcpy((char *)jmalloc(strlen(Name)+1,"status name"),Name);
28    show=Show;
29    next=Next;
30    last_update=0;
31    stat_win=NULL;
32    wm=WM;
33  }
34  ~gui_status_node();
35} ;
36
37
38gui_status_node::~gui_status_node()
39{
40  jfree(name);
41  if (show)
42    delete show;
43  if (stat_win)
44  {
45    wm->close_window(stat_win);
46    wm->flush_screen();
47  }
48}
49
50#ifdef __MWERKS__
51#pragma global_optimizer on
52#endif
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
69#ifdef __MWERKS__
70#pragma global_optimizer reset
71#endif
72
73void gui_status_manager::push(char const *name, visual_object *show)
74{
75  first=new gui_status_node(name,show,wm,first); 
76}
77
78gui_status_manager::gui_status_manager(window_manager *WM)
79{
80  wm=WM;
81  first=NULL;
82  strcpy(title,"STATUS");
83  last_perc=0;
84}
85
86void gui_status_manager::update(int percentage)
87{
88  last_perc=percentage;
89  if (first)
90  {
91    if (!first->stat_win)
92    {
93      time_marker now;
94      if (now.diff_time(&first->last_time)>1)
95      {
96        long wx=xres/2,wy=10,len1=strlen(first->name)*wm->font()->width()+10,len2=0,len3,
97          h1=wm->font()->height()+5,h2=first->show ? first->show->height(wm) : 0;
98
99        if (first->show) len2=first->show->width(wm)/2;
100        if (len2>len1) len3=len2; else len3=len1;
101        wx-=len3/2;
102       
103       
104        gui_status_node *p=first->next;
105        while (p && !p->stat_win) p=p->next;
106        if (p) wy=p->stat_win->y+p->stat_win->y2()+5;
107
108        int mx=WINDOW_FRAME_LEFT,my=WINDOW_FRAME_TOP;
109        first->stat_win=wm->new_window(wx,wy,len3, h1*2+h2,NULL,"status");
110        wm->font()->put_string(first->stat_win->screen,mx+1,my+1,first->name,wm->black());
111        wm->font()->put_string(first->stat_win->screen,mx,my,first->name,wm->bright_color());
112        if (first->show)
113          first->show->draw(first->stat_win->screen,(first->stat_win->x2()-first->stat_win->x1())/2-
114                            first->show->width(wm)/2,my+h1,wm,NULL);
115
116        draw_bar(first,percentage);
117        wm->flush_screen();
118      }
119    } else
120    {
121      if (percentage>first->last_update)
122      {
123        first->last_update=percentage;
124        draw_bar(first,percentage);
125        wm->flush_screen();
126      }
127    }
128  }
129}
130
131void gui_status_manager::force_display()
132{
133  update(last_perc);
134}
135
136void gui_status_manager::pop()
137{
138  CONDITION(first,"No status's to pop!");
139  gui_status_node *p=first;
140  first=first->next;
141  delete p;
142}
143
144
145
146
147
148
149
150
151
Note: See TracBrowser for help on using the repository browser.