summaryrefslogtreecommitdiffstats
path: root/src/timeout.inc
blob: bc75bc20523e4413c0e888388f7a08a7afad8e6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
%
% include before common.inc
%

% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Boot timeout counter.
%
% ( timeout time ) ==> ( )
%
% timeout: total time in 18.2Hz steps, time: current value.
%
% The code below assumes we're showing seconds and some symbolic counter.
%
/Timeout {
  % first time
  timeout.current .undef eq { over timeout.init } if

  % no counter
  timeout.steps .undef eq { return } if

  /timeout.s.last timeout.s.current def
  /timeout.s.current over 10 mul 150 add 182 div def

  /timeout.last timeout.current def
  over sub neg timeout.steps mul exch div
  /timeout.current exch def

  timeout.current timeout.steps ge {
    % last run
    timeout.s.done
    timeout.done
  } {
    % 0 270 moveto timeout.last print "<" print timeout.current print "<" print

    timeout.s.last timeout.s.current ne { timeout.s.current timeout.s.update } if

    timeout.last timeout.current ne {
      timeout.last 1 add 1 timeout.current { timeout.update } for
    } if

  } ifelse
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Initialize timeout indicator.
%
% ( time ) ==> ( )
%
/timeout.init {
  "timer_a.jpg" findfile /timeout.file over def dup .undef ne {
    currentimage exch setimage
    0 0 image.size unpackimage /timeout.image exch def
    setimage

    /timeout.steps timeout.image imgsize div def

    /timeout.width timeout.image imgsize exch pop def

    /timeout.x menu.start.x menu.bar.width add 24 sub def
    /timeout.y menu.start.y 1 sub menu.entry menu.item.height mul add def

    timeout.x timeout.y moveto
    /timeout.bg timeout.width dup savescreen def
    % just a few buffers
    /timeout.img_buf timeout.width dup savescreen def
    /timeout.alpha_buf timeout.width dup savescreen def

    /timeout.current 0 def

    timeout.current timeout.update
  } { pop } ifelse

  /timeout.s.buf 64 string def
  /timeout.s.x 100 def
  /timeout.s.y 250 def
  /timeout.s.current -1 def

  pop
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Update timeout indicator.
%
% ( index ) ==> ( )
%
% index runs from 0 to timeout.steps - 1. It is guaranteed that index is
% 1 larger than the last index. Never a step twice and no step is left out.
%
/timeout.update {
  timeout.width mul 0 moveto
  timeout.image 255 timeout.alpha_buf blend

  timeout.img_buf timeout.bg dup length memcpy

  0 0 moveto
  black timeout.alpha_buf timeout.img_buf blend

  timeout.x timeout.y moveto
  timeout.img_buf restorescreen
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Clear timeout indicator.
%
% ( ) ==> ( )
%
/timeout.done {
  timeout.x timeout.y moveto
  timeout.bg restorescreen

  /timeout.bg timeout.bg free .undef def
  /timeout.img_buf timeout.img_buf free .undef def
  /timeout.alpha_buf timeout.alpha_buf free .undef def
  /timeout.image timeout.image free .undef def
  /timeout.file timeout.file free .undef def
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Update seconds counter.
%
% ( time_in_s ) ==> ( )
%
/timeout.s.update {
%  white setcolor
%  timeout.s.x timeout.s.y moveto -30 0 rmoveto
%  currentpoint 30 fontheight image
%  "%ds" timeout.s.buf sprintf
%  timeout.s.x timeout.s.y moveto timeout.s.buf showright
  pop
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Clear seconds counter.
%
% ( ) ==> ( )
%
/timeout.s.done {
%  timeout.s.x timeout.s.y moveto -30 0 rmoveto
%  currentpoint 30 fontheight image
} def