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

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

imlib: reverse the image::put_image logic.

File size: 3.5 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
4 *  Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
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, by
8 *  Jonathan Clark, or by Sam Hocevar.
9 */
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include <string.h>
16
17#include "common.h"
18
19#include "input.h"
20#include "status.h"
21#include "timing.h"
22#include "guistat.h"
23
24class gui_status_node
25{
26  public :
27  char *name;
28  gui_status_node *next;
29  visual_object *show;
30  Jwindow *stat_win;
31  int last_update;
32  time_marker last_time;
33  gui_status_node(char const *Name, visual_object *Show, gui_status_node *Next)
34  { name = strdup(Name);
35    show=Show;
36    next=Next;
37    last_update=0;
38    stat_win=NULL;
39  }
40  ~gui_status_node();
41} ;
42
43
44gui_status_node::~gui_status_node()
45{
46  free(name);
47  if (show)
48    delete show;
49  if (stat_win)
50  {
51    wm->close_window(stat_win);
52    wm->flush_screen();
53  }
54}
55
56void gui_status_manager::draw_bar(gui_status_node *whom, int perc)
57{
58  long l=whom->stat_win->x2()-whom->stat_win->x1()-6;
59  long h=wm->font()->height();
60
61  whom->stat_win->m_surf->bar(whom->stat_win->x1()+1,whom->stat_win->y2()-h-1,whom->stat_win->x2()-1,
62              whom->stat_win->y2()-1,wm->black());
63  whom->stat_win->m_surf->bar(whom->stat_win->x1()+2,whom->stat_win->y2()-h,whom->stat_win->x2()-2,
64              whom->stat_win->y2()-2,wm->dark_color());
65  if (perc)
66    whom->stat_win->m_surf->bar(whom->stat_win->x1()+3,whom->stat_win->y2()-h+1,
67                whom->stat_win->x1()+l*perc/100,
68                whom->stat_win->y2()-3,wm->bright_color());
69}
70
71void gui_status_manager::push(char const *name, visual_object *show)
72{
73  first=new gui_status_node(name,show,first);
74}
75
76gui_status_manager::gui_status_manager()
77{
78  first=NULL;
79  strcpy(title,"STATUS");
80  last_perc=0;
81}
82
83void gui_status_manager::update(int percentage)
84{
85  last_perc=percentage;
86  if (first)
87  {
88    if (!first->stat_win)
89    {
90      time_marker now;
91      if (now.diff_time(&first->last_time)>1)
92      {
93    long wx=xres/2,wy=10,len1=strlen(first->name)*wm->font()->width()+10,len2=0,len3,
94      h1=wm->font()->height()+5,h2=first->show ? first->show->height() : 0;
95
96    if (first->show) len2=first->show->width()/2;
97    if (len2>len1) len3=len2; else len3=len1;
98    wx-=len3/2;
99
100
101    gui_status_node *p=first->next;
102    while (p && !p->stat_win) p=p->next;
103    if (p) wy=p->stat_win->y+p->stat_win->y2()+5;
104
105    int mx = first->stat_win->x1() + 1;
106    int my = first->stat_win->y1() + wm->font()->height() / 2;
107    first->stat_win=wm->new_window(wx, wy, len3, h1*2+h2, NULL, "status");
108    wm->font()->put_string(first->stat_win->m_surf, mx, my, first->name, wm->black());
109    wm->font()->put_string(first->stat_win->m_surf, mx, my, first->name, wm->bright_color());
110    if (first->show)
111      first->show->draw(first->stat_win->m_surf, (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.