source: abuse/tags/pd/macabuse/imlib/guistat.c @ 57

Last change on this file since 57 was 49, checked in by Sam Hocevar, 15 years ago
  • Imported original public domain release, for future reference.
  • Property svn:keywords set to Id
File size: 3.1 KB
RevLine 
[49]1#include "status.hpp"
2#include "timing.hpp"
3#include "guistat.hpp"
4
5class gui_status_node
6{
7  public : 
8  char *name;
9  gui_status_node *next;
10  visual_object *show;
11  jwindow *stat_win;
12  window_manager *wm;
13  int last_update;
14  time_marker last_time;
15  gui_status_node(char *Name, visual_object *Show, window_manager *WM, gui_status_node *Next)
16  { name=strcpy((char *)jmalloc(strlen(Name)+1,"status name"),Name);
17    show=Show;
18    next=Next;
19    last_update=0;
20    stat_win=NULL;
21    wm=WM;
22  }
23  ~gui_status_node();
24} ;
25
26
27gui_status_node::~gui_status_node()
28{
29  jfree(name);
30  if (show)
31    delete show;
32  if (stat_win)
33  {
34    wm->close_window(stat_win);
35    wm->flush_screen();
36  }
37}
38
39#ifdef __MAC__
40#pragma global_optimizer on
41#endif
42
43void gui_status_manager::draw_bar(gui_status_node *whom, int perc)
44{
45  long l=whom->stat_win->x2()-whom->stat_win->x1()-6;
46  long h=wm->font()->height();
47
48  whom->stat_win->screen->bar(whom->stat_win->x1()+1,whom->stat_win->y2()-h-1,whom->stat_win->x2()-1,
49                      whom->stat_win->y2()-1,wm->black());
50  whom->stat_win->screen->bar(whom->stat_win->x1()+2,whom->stat_win->y2()-h,whom->stat_win->x2()-2,
51                      whom->stat_win->y2()-2,wm->dark_color());
52  if (perc)
53    whom->stat_win->screen->bar(whom->stat_win->x1()+3,whom->stat_win->y2()-h+1,
54                                whom->stat_win->x1()+l*perc/100,
55                                whom->stat_win->y2()-3,wm->bright_color());
56}
57
58#ifdef __MAC__
59#pragma global_optimizer reset
60#endif
61
62void gui_status_manager::push(char *name, visual_object *show)
63{
64  first=new gui_status_node(name,show,wm,first); 
65}
66
67gui_status_manager::gui_status_manager(window_manager *WM)
68{
69  wm=WM;
70  first=NULL;
71  strcpy(title,"STATUS");
72  last_perc=0;
73}
74
75void gui_status_manager::update(int percentage)
76{
77  last_perc=percentage;
78  if (first)
79  {
80    if (!first->stat_win)
81    {
82      time_marker now;
83      if (now.diff_time(&first->last_time)>1)
84      {
85        long wx=xres/2,wy=10,len1=strlen(first->name)*wm->font()->width()+10,len2=0,len3,
86          h1=wm->font()->height()+5,h2=first->show ? first->show->height(wm) : 0;
87
88        if (first->show) len2=first->show->width(wm)/2;
89        if (len2>len1) len3=len2; else len3=len1;
90        wx-=len3/2;
91       
92       
93        gui_status_node *p=first->next;
94        while (p && !p->stat_win) p=p->next;
95        if (p) wy=p->stat_win->y+p->stat_win->y2()+5;
96
97        int mx=WINDOW_FRAME_LEFT,my=WINDOW_FRAME_TOP;
98        first->stat_win=wm->new_window(wx,wy,len3, h1*2+h2,NULL,"status");
99        wm->font()->put_string(first->stat_win->screen,mx+1,my+1,first->name,wm->black());
100        wm->font()->put_string(first->stat_win->screen,mx,my,first->name,wm->bright_color());
101        if (first->show)
102          first->show->draw(first->stat_win->screen,(first->stat_win->x2()-first->stat_win->x1())/2-
103                            first->show->width(wm)/2,my+h1,wm,NULL);
104
105        draw_bar(first,percentage);
106        wm->flush_screen();
107      }
108    } else
109    {
110      if (percentage>first->last_update)
111      {
112        first->last_update=percentage;
113        draw_bar(first,percentage);
114        wm->flush_screen();
115      }
116    }
117  }
118}
119
120void gui_status_manager::force_display()
121{
122  update(last_perc);
123}
124
125void gui_status_manager::pop()
126{
127  CONDITION(first,"No status's to pop!");
128  gui_status_node *p=first;
129  first=first->next;
130  delete p;
131}
132
133
134
135
136
137
138
139
140
Note: See TracBrowser for help on using the repository browser.