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

Last change on this file since 106 was 106, checked in by Sam Hocevar, 11 years ago
  • Rename the "eh" variable to "wm" because it's a window manager, not an event handler.
  • No longer pass the window manager to functions, there's only one.

Inspired by Win32 Abuse changelog for January 28, 2001:

  • Starting work on singleton code; will get rid of all

references to an arbitrary window_manager* because
there's only going to be one, and it's not ever
going to change.

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