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

Last change on this file since 107 was 107, checked in by Sam Hocevar, 11 years ago
  • Remove #pragma directives. They're unknown to us.
File size: 3.2 KB
RevLine 
[56]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
[106]12#include "input.hpp"
[2]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;
[106]26  gui_status_node(char const *Name, visual_object *Show, gui_status_node *Next)
[2]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
49void gui_status_manager::draw_bar(gui_status_node *whom, int perc)
50{
51  long l=whom->stat_win->x2()-whom->stat_win->x1()-6;
52  long h=wm->font()->height();
53
54  whom->stat_win->screen->bar(whom->stat_win->x1()+1,whom->stat_win->y2()-h-1,whom->stat_win->x2()-1,
55                      whom->stat_win->y2()-1,wm->black());
56  whom->stat_win->screen->bar(whom->stat_win->x1()+2,whom->stat_win->y2()-h,whom->stat_win->x2()-2,
57                      whom->stat_win->y2()-2,wm->dark_color());
58  if (perc)
59    whom->stat_win->screen->bar(whom->stat_win->x1()+3,whom->stat_win->y2()-h+1,
60                                whom->stat_win->x1()+l*perc/100,
61                                whom->stat_win->y2()-3,wm->bright_color());
62}
63
[39]64void gui_status_manager::push(char const *name, visual_object *show)
[2]65{
[106]66  first=new gui_status_node(name,show,first); 
[2]67}
68
[106]69gui_status_manager::gui_status_manager()
[2]70{
71  first=NULL;
72  strcpy(title,"STATUS");
73  last_perc=0;
74}
75
76void gui_status_manager::update(int percentage)
77{
78  last_perc=percentage;
79  if (first)
80  {
81    if (!first->stat_win)
82    {
83      time_marker now;
84      if (now.diff_time(&first->last_time)>1)
85      {
86        long wx=xres/2,wy=10,len1=strlen(first->name)*wm->font()->width()+10,len2=0,len3,
[106]87          h1=wm->font()->height()+5,h2=first->show ? first->show->height() : 0;
[2]88
[106]89        if (first->show) len2=first->show->width()/2;
[2]90        if (len2>len1) len3=len2; else len3=len1;
91        wx-=len3/2;
92       
93       
94        gui_status_node *p=first->next;
95        while (p && !p->stat_win) p=p->next;
96        if (p) wy=p->stat_win->y+p->stat_win->y2()+5;
97
98        int mx=WINDOW_FRAME_LEFT,my=WINDOW_FRAME_TOP;
99        first->stat_win=wm->new_window(wx,wy,len3, h1*2+h2,NULL,"status");
100        wm->font()->put_string(first->stat_win->screen,mx+1,my+1,first->name,wm->black());
101        wm->font()->put_string(first->stat_win->screen,mx,my,first->name,wm->bright_color());
102        if (first->show)
103          first->show->draw(first->stat_win->screen,(first->stat_win->x2()-first->stat_win->x1())/2-
[106]104                            first->show->width()/2,my+h1,NULL);
[2]105
106        draw_bar(first,percentage);
107        wm->flush_screen();
108      }
109    } else
110    {
111      if (percentage>first->last_update)
112      {
113        first->last_update=percentage;
114        draw_bar(first,percentage);
115        wm->flush_screen();
116      }
117    }
118  }
119}
120
121void gui_status_manager::force_display()
122{
123  update(last_perc);
124}
125
126void gui_status_manager::pop()
127{
128  CONDITION(first,"No status's to pop!");
129  gui_status_node *p=first;
130  first=first->next;
131  delete p;
132}
133
134
135
136
137
138
139
140
141
Note: See TracBrowser for help on using the repository browser.