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

Last change on this file since 111 was 111, checked in by Sam Hocevar, 11 years ago
  • Simplified the window creation arguments. Got rid of a lot of macros and hid stuff in private namespaces.

Inspired by Win32 Abuse changelog for January 28, 2001:

  • Well, in the process of adding changes necessary to

handle recovery from alt-tabbing away from Abuse
(which is why I was updating jwindow::redraw()),
the entire windowing system is getting an overhaul.
It's gonna be sweet when I'm done, though.

  • jwindow::redraw() has been changed to a virtual

function requiring no parameters. This'll make
it much easier to implement special specific-
purpose windows.

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
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
64void gui_status_manager::push(char const *name, visual_object *show)
65{
66  first=new gui_status_node(name,show,first); 
67}
68
69gui_status_manager::gui_status_manager()
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,
87          h1=wm->font()->height()+5,h2=first->show ? first->show->height() : 0;
88
89        if (first->show) len2=first->show->width()/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 = first->stat_win->x1() + 1;
99        int my = first->stat_win->y1() + wm->font()->height() / 2;
100        first->stat_win=wm->new_window(wx, wy, len3, h1*2+h2, NULL, "status");
101        wm->font()->put_string(first->stat_win->screen, mx, my, first->name, wm->black());
102        wm->font()->put_string(first->stat_win->screen, mx, my, first->name, wm->bright_color());
103        if (first->show)
104          first->show->draw(first->stat_win->screen, (first->stat_win->x2()-first->stat_win->x1())/2-
105                            first->show->width()/2, my+h1, NULL);
106
107        draw_bar(first,percentage);
108        wm->flush_screen();
109      }
110    } else
111    {
112      if (percentage>first->last_update)
113      {
114        first->last_update=percentage;
115        draw_bar(first,percentage);
116        wm->flush_screen();
117      }
118    }
119  }
120}
121
122void gui_status_manager::force_display()
123{
124  update(last_perc);
125}
126
127void gui_status_manager::pop()
128{
129  CONDITION(first,"No status's to pop!");
130  gui_status_node *p=first;
131  first=first->next;
132  delete p;
133}
134
135
136
137
138
139
140
141
142
Note: See TracBrowser for help on using the repository browser.