source: abuse/tags/pd/macabuse/src/idle.c @ 49

Last change on this file since 49 was 49, checked in by Sam Hocevar, 12 years ago
  • Imported original public domain release, for future reference.
  • Property svn:keywords set to Id
File size: 1.8 KB
Line 
1#include "idle.hpp"
2#include "jwindow.hpp"
3
4extern window_manager *eh;
5
6idle_manager *idle_man=0;
7
8idle_manager::~idle_manager()
9{
10  idle_reset();
11  int i;
12  for (i=0;i<total_wait_frames;i++)
13    delete wait_cursors[i];
14}
15
16idle_manager::idle_manager()
17{
18  cursor_frame_on=-1;
19  first=last=0;
20 
21  bFILE *fp=open_file("art/wait.spe","rb");
22  char name[20];
23  spec_directory sd(fp);
24
25  for (int i=0;i<total_wait_frames;i++)
26  {
27    sprintf(name,"watch_%d",i+1);
28    spec_entry *se=sd.find(name);
29    if (!se)
30    {
31      lbreak("could not find %s in %s\n",name,"art/wait.spe");
32      exit(0);
33    }
34
35    wait_cursors[i]=new image(se,fp);
36  }
37  delete fp;
38}
39
40void idle_manager::idle_reset()
41{
42  last_idle.get_time();
43  if (cursor_frame_on!=-1)
44  {
45    eh->set_mouse_shape(old,old_cx,old_cy);
46    cursor_frame_on=-1;
47
48    while (first)
49    {
50      eh->push_event(first->ev);
51      event_holder *l=first;
52      first=first->next;
53      delete l;
54    }
55    last=0;
56  }
57}
58
59void idle_manager::idle()
60{
61  time_marker now;
62
63  if (cursor_frame_on==-1)
64  {
65    if (now.diff_time(&last_idle)>0.5)
66    {
67      old=eh->eh->mouse->mouse_sprite()->visual->copy();
68      old_cx=eh->eh->mouse->center_x();
69      old_cy=eh->eh->mouse->center_y();
70      cursor_frame_on=0;
71      eh->set_mouse_shape(wait_cursors[cursor_frame_on]->copy(),0,0);
72      eh->flush_screen();
73    }
74  } else if (now.diff_time(&last_animate)>0.1)
75  {
76    cursor_frame_on++;
77    if (cursor_frame_on>=total_wait_frames)
78      cursor_frame_on=0;
79
80    eh->set_mouse_shape(wait_cursors[cursor_frame_on]->copy(),0,0);
81    last_animate.get_time();
82      eh->flush_screen();
83  } else
84  {
85    event ev;
86    while (eh->event_waiting())
87    {
88      eh->get_event(ev);
89      if (ev.type!=EV_MOUSE_MOVE)
90        que_event(ev);
91      eh->flush_screen();
92    }
93  }
94}
95
96
Note: See TracBrowser for help on using the repository browser.