scrn-bar.mkvi /size: 16 Kb    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=scrn-bar, % was part of scrn-int
3
%D version=1995.01.01,
4
%D title=\CONTEXT\ Core Macros,
5
%D subtitle=Progress Bars,
6
%D author=Hans Hagen,
7
%D date=\currentdate,
8
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9
%C
10
%C This module is part of the \CONTEXT\ macro||package and is
11
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12
%C details.
13 14
\writestatus
{
loading
}{
ConTeXt
Screen
Macros
/
Progress
Bars
}
15 16
\unprotect
17 18
%D The code is a bit upgraded to \MKIV\ but the output is mostly the
19
%D same. In retrospect this should have been a module. We can move
20
%D some definitions to scrn-run-bar.mkiv if needed. We can also make
21
%D the code a bit more efficient.
22 23
% todo: replace blackrule by stupid rules
24 25
%D \starttyping
26
%D \setupinteraction
27
%D [state=start]
28
%D
29
%D \setupsubpagenumber
30
%D [state=start]
31
%D
32
%D \setuplayout
33
%D [middle]
34
%D
35
%D \setuppapersize
36
%D [S4][S4]
37
%D
38
%D \startsetups bars
39
%D \ruledvbox to \textheight \bgroup
40
%D a \ruledhbox{\interactionbar[a]}\vss
41
%D b \ruledhbox{\interactionbar[b]}\vss
42
%D c \ruledhbox{\interactionbar[c]}\vss
43
%D d \ruledhbox{\interactionbar[d]}\vss
44
%D e \ruledhbox{\interactionbar[e]}\vss
45
%D f \ruledhbox{\interactionbar[f]}\vss
46
%D g \ruledhbox{\interactionbar[g]}\vss
47
%D \egroup
48
%D \stopsetups
49
%D
50
%D \setuptexttexts[\setups{bars}]
51
%D
52
%D \starttext
53
%D \dorecurse {12} {
54
%D \startstandardmakeup
55
%D \stopstandardmakeup
56
%D }
57
%D \stoptext
58
%D \stoptyping
59 60
\installcorenamespace
{
interactionbar
}
61 62
\installframedcommandhandler
\??interactionbar
{
interactionbar
}
\??interactionbar
63 64
\unexpanded
\def
\interactionbar
65
{
\dodoubleempty
\scrn_bar_direct
}
66 67
\def
\scrn_bar_direct
[#
tag
][#
settings
]
% somewhat messy
68
{
\iflocation
69
\begingroup
70
\doifelseassignment
{
#
tag
}
71
{
\let
\currentinteractionbar
\empty
72
\setupcurrentinteractionbar
[#
tag
]
%
73
\edef
\currentinteractionbar
{
\interactionbarparameter
\c!alternative
}}
%
74
{
\edef
\currentinteractionbar
{
#
tag
}
%
75
\ifsecondargument
\setupcurrentinteractionbar
[#
settings
]
\fi
}
%
76
\doif
{
\interactionbarparameter
\c!state
}
\v!start
77
{
\interactionbarparameter
\c!command
}
%
78
\endgroup
79
\fi
}
80 81
\newdimen
\d_scrn_bar_width
82
\newdimen
\d_scrn_bar_height
83
\newdimen
\d_scrn_bar_depth
84
\newdimen
\d_scrn_bar_distance
85 86
%D Interaction buttons, in fact a row of tiny buttons, are
87
%D typically only used for navigational purposed. The next
88
%D macro builds such a row based on a specification list.
89
%D
90
%D \startbuffer
91
%D \interactionbuttons[width=\hsize][page,PreviousJump,ExitViewer]
92
%D \stopbuffer
93
%D
94
%D \typebuffer
95
%D
96
%D gives
97
%D
98
%D \getbuffer
99
%D
100
%D Apart from individual entries, one can use \type{page} and
101
%D \type {subpage} as shortcuts to their four associated buttons.
102
%D The symbols are derived from the symbols linked to the
103
%D entries.
104 105
\unexpanded
\def
\interactionbuttons
106
{
\dodoubleempty
\scrn_bar_buttons
}
107 108
\def
\scrn_bar_buttons
109
{
\iflocation
110
\expandafter
\scrn_bar_buttons_status
111
\else
112
\expandafter
\scrn_bar_buttons_ignore
113
\fi
}
114 115
\def
\scrn_bar_buttons_status
[#
settings
][#
list
]
%
116
{
\doif
{
\interactionbarparameter
\c!state
}
\v!start
117
{
\ifsecondargument
118
\scrn_bar_buttons_indeed
[#
settings
][#
list
]
%
119
\else
120
\scrn_bar_buttons_indeed
[][#
settings
]
%
121
\fi
}}
122 123
\def
\scrn_bar_buttons_ignore
[#
settings
][#
list
]
% \gobbletwooptionals
124
{}
125 126
\def
\scrn_bar_buttons_indeed
[#
settings
][#
list
]
%
127
{
\begingroup
128
%\let\currentinteractionbar\empty
129
\setupcurrentinteractionbar
[#
settings
]
%
130
\d_scrn_bar_width
\interactionbarparameter
\c!width
\relax
131
\d_scrn_bar_distance
\interactionbarparameter
\c!distance
\relax
132
\ifzeropt
\d_scrn_bar_width
133
\d_scrn_bar_width
1
.
5
\emwidth
134
\fi
135
\doifnothing
{
\interactionbarparameter
\c!height
}{
\letinteractionbarparameter
\c!height\v!broad
}
%
136
\doifnothing
{
\interactionbarparameter
\c!depth
}{
\letinteractionbarparameter
\c!depth
\zeropoint
}
%%%
137
\letinteractionbarparameter
\c!background
\empty
138
\setbox
2
\hbox
{
\inheritedinteractionbarframed
{
\symbol
[
\interactionparameter
\c!symbolset
][
\v!previouspage
]
}}
%
139
\scratchheight
\ht
2
% needed because we default to nothing
140
\letinteractionbarparameter
\c!strut\v!no
141
% \letinteractionparameter\c!width\zeropoint
142
\scratchcounterone
\zerocount
% new, was 1
143
\processallactionsinset
144
[#
list
]
145
[
\v!page
=>
\advance
\scratchcounterone
\plusfour
,
146
\v!subpage
=>
\advance
\scratchcounterone
\plusfour
,
147
\s!unknown
=>
\advance
\scratchcounterone
\plusone
]
%
148
\ifzeropt
\d_scrn_bar_width
149
\scratchdimenone
\dimexpr
2
\emwidth
+
\d_scrn_bar_distance
\relax
150
\scratchdimentwo
\dimexpr
\scratchcounterone\scratchdimenone
-
\d_scrn_bar_distance
\relax
151
\else
152
\scratchdimenone
\d_scrn_bar_width
153
\scratchdimentwo
\dimexpr
\scratchcounterone
\d_scrn_bar_distance
-
\d_scrn_bar_distance
\relax
154
\advance
\scratchdimenone
-
\scratchdimentwo
155
\divide
\scratchdimenone
\scratchcounterone
156
\scratchdimentwo
\d_scrn_bar_width
157
\fi
158
\hbox
to
\scratchdimentwo
159
{
\setnostrut
160
\startsymbolset
[
\interactionparameter
\c!symbolset
]
%
161
\setupbuttons
162
[#
settings
,
%
163
\c!height
=
\the
\scratchheight
,
%
164
\c!width
=
\the
\scratchdimenone
]
%
165
\processallactionsinset
166
[#
list
]
167
[
\v!page
=>
\scrn_bar_goto
\v!firstpage
168
\scrn_bar_goto
\v!nextpage
169
\scrn_bar_goto
\v!previouspage
170
\scrn_bar_goto
\v!lastpage
,
171
\v!subpage
=>
\scrn_bar_goto
\v!firstsubpage
172
\scrn_bar_goto
\v!nextsubpage
173
\scrn_bar_goto
\v!previoussubpage
174
\scrn_bar_goto
\v!lastsubpage
,
175
\s!unknown
=>
\scrn_bar_goto
\commalistelement
]
%
176
\unskip
177
\stopsymbolset
}
%
178
\endgroup
}
179 180
\def
\scrn_bar_goto
#
action
%
181
{
\button
{
\symbol
[#
action
]
}
[#
action
]
\hss
}
182 183
% todo: this will be \letblackruleparameter\c!width\scratchdimenone (faster)
184 185
\def
\scrn_bar_alternative_a
186
{
\d_scrn_bar_width
\interactionbarparameter
\c!width
187
\d_scrn_bar_distance
\interactionbarparameter
\c!distance
188
\d_scrn_bar_height
\interactionbarparameter
\c!height
189
\d_scrn_bar_depth
\interactionbarparameter
\c!depth
190
\noindent\hbox
to
\d_scrn_bar_width
\bgroup
191
\dontcomplain
192
\setupblackrules
[
\c!height
=
\v!max
,
\c!depth
=
\v!max
]
%
193
\scratchdimentwo
\dimexpr
\d_scrn_bar_width
-
4
\emwidth
\relax
194
\processaction
195
[
\interactionbarparameter
\c!step
]
196
[
\v!small
=>
\scratchcounter
2
0
,
197
\v!medium
=>
\scratchcounter
1
0
,
198
\v!big
=>
\scratchcounter
5
,
199
\s!unknown
=>
\scratchcounter
1
0
]
%
200
\scratchdimenone
\dimexpr
\scratchdimentwo
/
\scratchcounter
\relax
201
\setupblackrules
[
\c!width
=
\scratchdimenone
]
%
202
\setbox
\scratchbox
\hbox
to
\d_scrn_bar_width
203
{
\hskip
2
\emwidth
204
\setbox
\scratchbox
\hpack
{
\blackrule
[
\c!color
=
\interactionbarparameter
\c!backgroundcolor
]
}
%
205
\dorecurse\scratchcounter
206
{
\hss\normalexpanded
{
\directgotodumbbox
{
\copy
\scratchbox
}
[
page
(
\the\numexpr
\recurselevel
*
\lastpage
/
\scratchcounter
\relax
)]
}}
%
207
\hss
208
\hskip
2
\emwidth
}
%
209
\wd
\scratchbox
\zeropoint
210
\box
\scratchbox
211
\setupblackrules
[
\c!width
=
\emwidth
]
%
212
\normalexpanded
{
\directgotospecbox
\noexpand
\interactionbarparameter
{
\blackrule
}
[
\v!firstpage
]
}
%
213
\hskip
\emwidth
214
\ifnum
\realpageno
>
\plusone
215
\hskip
\zeropoint
\s!plus
\numexpr
\realpageno
-
\plustwo
\relax
\s!sp
\relax
% cm gives overflow
216
\normalexpanded
{
\directgotospecbox
\noexpand
\interactionbarparameter
{
\blackrule
}
[
\v!previouspage
)]
}
%
217
\fi
218
\normalexpanded
{
\directgotospecbox
\noexpand
\interactionbarparameter
{
\blackrule
}
[
page
(
\number
\realpageno
)]
}
% todo: \v!currentpage
219
\ifnum
\realpageno
<
\lastpage
\relax
220
\normalexpanded
{
\directgotospecbox
\noexpand
\interactionbarparameter
{
\blackrule
}
[
\v!nextpage
]
}
%
221
\hskip
\zeropoint
\s!plus
\numexpr
\lastpage
-
\realpageno
-
\plusone
\relax
\s!sp
\relax
% cm gives overflow
222
\fi
223
\hskip
\emwidth
224
\normalexpanded
{
\directgotospecbox
\noexpand
\interactionbarparameter
{
\blackrule
}
[
\v!lastpage
]
}
%
225
\egroup
}
226 227
\def
\scrn_bar_alternative_b
228
{
\ifnum
\lastpage
>
\firstpage
\relax
229
\interactionbuttons
[
\v!firstpage
,
\v!previouspage
,
\v!nextpage
,
\v!lastpage
]
%
230
\fi
}
231 232
\def
\scrn_bar_alternative_c
233
{
\ifnum
\lastpage
>
\plusone
234
\d_scrn_bar_width
\interactionbarparameter
\c!width
235
\hbox
to
\d_scrn_bar_width
236
{
\setupblackrules
[
\c!height
=
\interactionbarparameter
\c!height
,
\c!depth
=
\interactionbarparameter
\c!depth
,
\c!width
=
\emwidth
]
%
237
\scratchdimen
\dimexpr
(
\d_scrn_bar_width
-
4
\emwidth
)
/
\numexpr
\lastpage
+
\minusone
\relax\relax
238
\scratchdimenone
\numexpr
\realpageno
+
\minusone
\relax
\scratchdimen
239
\scratchdimentwo
\numexpr
\lastpage
-
\realpageno
\relax
\scratchdimen
240
\directgotospecbox
\interactionbarparameter
{
\blackrule
}
[
\v!firstpage
]
%
241
\hss
242
\directgotospecbox
\interactionbarparameter
{
\blackrule
[
\c!width
=
\scratchdimenone
]
}
[
\v!previouspage
]
%
243
\blackrule
[
\c!color
=
\interactionbarparameter
\c!contrastcolor
]
%
244
\directgotospecbox
\interactionbarparameter
{
\blackrule
[
\c!width
=
\scratchdimentwo
]
}
[
\v!nextpage
]
%
245
\hss
246
\directgotospecbox
\interactionbarparameter
{
\blackrule
}
[
\v!lastpage
]
}
%
247
\fi
}
248 249
\unexpanded
\def
\scrn_bar_goto_a
#
whereto
%
250
{
\symbol
[
\ifcase
#
whereto
\v!previous
\or
\v!somewhere
\or
\v!next
\fi
]
}
251 252
\unexpanded
\def
\scrn_bar_goto_b
#
whereto
%
253
{
\vrule
\s!height
\d_scrn_bar_height
\s!depth
\d_scrn_bar_depth
\s!width
\scratchdimenone
\relax
}
254 255
\unexpanded
\def
\scrn_bar_goto_c
#
whereto
%
256
{
\symbol
[
\ifcase
#
whereto
\v!previous
\or
\v!somewhere
\or
\v!somewhere
\or
\v!somewhere
\or
\v!next
\fi
}
257 258
\unexpanded
\def
\scrn_bar_goto_d
#
whereto
%
259
{
\vrule
\s!width
\scratchdimenone
\ifcase
#
whereto
%
260
\s!height
\d_scrn_bar_height
\s!depth
\d_scrn_bar_depth
\or
261
\s!height
.
5
\d_scrn_bar_height
\s!depth
.
5
\d_scrn_bar_depth
\or
262
\s!height
\d_scrn_bar_height
\s!depth
\d_scrn_bar_depth
\or
263
\s!height
.
5
\d_scrn_bar_height
\s!depth
.
5
\d_scrn_bar_depth
\else
264
\s!height
\d_scrn_bar_height
\s!depth
\d_scrn_bar_depth
\fi
}
265 266
\newconstant
\c_scrn_bar_mode
267 268
\unexpanded
\def
\scrn_bar_goto_x
#
command
%
269
{
\doifelse
{
\interactionbarparameter
\c!symbol
}
\v!yes
270
{
\setupsymbolset
[
\interactionparameter
\c!symbolset
]
%
271
\let
\scrn_bar_goto_indeed
\scrn_bar_goto_a
}
272
{
\let
\scrn_bar_goto_indeed
\scrn_bar_goto_b
}
%
273
\dorecurse
\nofsubpages
274
%{\scratchcounter\numexpr\recurselevel+\firstsubpage+\minusone\relax
275
{
\scratchcounter
\therealsubpageno
\recurselevel
276
\c_scrn_bar_mode
277
\ifnum
\scratchcounter
<
\realpageno
\zerocount
\else
278
\ifnum
\scratchcounter
=
\realpageno
\plusone
\else
279
\plustwo
\fi\fi
280
\normalexpanded
{
\directgotospecbox
\noexpand
\interactionbarparameter
{
\scrn_bar_goto_indeed
\c_scrn_bar_mode
}
[
page
(
\the
\scratchcounter
)]
}
%
281
#
command
}
%
282
\unskip
}
283 284
\def
\scrn_bar_alternative_d
285
{
\ifnum
\nofsubpages
>
\plusone
\doif
{
\namedcounterparameter
\s!subpage\c!state
}
\v!start
{
%
286
\d_scrn_bar_width
\interactionbarparameter
\c!width
287
\d_scrn_bar_distance
\interactionbarparameter
\c!distance
288
\d_scrn_bar_height
\interactionbarparameter
\c!height
289
\d_scrn_bar_depth
\interactionbarparameter
\c!depth
290
\scratchdimenone
\d_scrn_bar_width
291
\noindent\hbox
{
\scrn_bar_goto_x
{
\hskip
\d_scrn_bar_distance
}}
% \hpack ?
292
}
\fi
}
293 294
\def
\scrn_bar_alternative_e
295
{
\ifnum
\nofsubpages
>
\plusone
\doif
{
\namedcounterparameter
\s!subpage\c!state
}
\v!start
{
%
296
\d_scrn_bar_width
\interactionbarparameter
\c!width
297
\d_scrn_bar_distance
\interactionbarparameter
\c!distance
298
\d_scrn_bar_height
\interactionbarparameter
\c!height
299
\d_scrn_bar_depth
\interactionbarparameter
\c!depth
300
\scratchdimentwo
\dimexpr
\nofsubpages
\d_scrn_bar_distance
-
\d_scrn_bar_distance
\relax
% (n-1)
301
\scratchdimenone
\dimexpr
(
\d_scrn_bar_width
-
\scratchdimentwo
)
/
\nofsubpages
\relax
302
\ifdim
\scratchdimenone
<
\d_scrn_bar_distance
303
\scrn_bar_alternative_f
304
\else
305
\noindent\hbox
to
\d_scrn_bar_width
{
\scrn_bar_goto_x
{
\hss
}
\unskip
}
% \hpack ?
306
\fi
307
}
\fi
}
308 309
\def
\scrn_bar_alternative_f
310
{
\ifnum
\nofsubpages
>
\plusone
\doif
{
\namedcounterparameter
\s!subpage\c!state
}
\v!start
{
%
311
\d_scrn_bar_width
\interactionbarparameter
\c!width
312
\d_scrn_bar_distance
\interactionbarparameter
\c!distance
313
\d_scrn_bar_height
\interactionbarparameter
\c!height
314
\d_scrn_bar_depth
\interactionbarparameter
\c!depth
315
\noindent
\hbox
to
\d_scrn_bar_width
\bgroup
316
\doloop
317
{
\scratchcounterthree
\numexpr
(
\nofsubpages
/
\recurselevel
)
+
\plusone
\relax
% rounding
318
\scratchdimentwo
\d_scrn_bar_distance
319
\multiply
\scratchdimentwo
\scratchcounterthree
320
\advance
\scratchdimentwo
-
\d_scrn_bar_distance
321
\scratchdimenone
\d_scrn_bar_width
322
\advance
\scratchdimenone
-
\scratchdimentwo
323
\divide
\scratchdimenone
\scratchcounterthree
324
\ifdim
\scratchdimenone
<
\d_scrn_bar_distance
\else
325
\scratchcountertwo\recurselevel
326
\exitloop
327
\fi
}
%
328
\ifnum
\scratchcounterthree
>
\plusone
329
% this is not that well tested
330
\advance
\scratchcounterthree
\minustwo
331
\scratchdimenone
-
\d_scrn_bar_distance
332
\scratchdimenone\scratchcounterthree\scratchdimenone
333
\advance
\scratchdimenone
\d_scrn_bar_width
334
\advance
\scratchcounterthree
\plusone
335
\divide
\scratchdimenone
\scratchcounterthree
336
\fi
337
\doifelse
{
\interactionbarparameter
\c!symbol
}
\v!yes
338
{
\setupsymbolset
[
\interactionparameter
\c!symbolset
]
%
339
\let
\scrn_bar_goto_indeed
\scrn_bar_goto_c
}
%
340
{
\let
\scrn_bar_goto_indeed
\scrn_bar_goto_d
}
%
341
\scratchcounterthree
\numexpr
\realpageno
-
\plustwo
\relax
342
\scratchcounterfour
\numexpr
\realpageno
+
\plustwo
\relax
343
\ifnum
\scratchcounterthree
<
\plusone
\scratchcounterthree
\plusone
\fi
344
\scratchcounterfive
\zerocount
345
\dostepwiserecurse
\firstsubpage\lastsubpage
\plusone
346
{
\!!doneafalse
347
\advance
\scratchcounterfive
\plusone
348
\ifnum
\recurselevel
=
\firstsubpage
\relax
\!!doneatrue
\fi
349
\ifnum
\recurselevel
=
\lastsubpage
\relax
\!!doneatrue
\fi
350
\scratchcountersix
\therealsubpageno
\recurselevel
\relax
351
\c_scrn_bar_mode
352
\if!!donea
353
\ifnum
\scratchcountersix
<
\realpageno
354
\zerocount
355
\else\ifnum
\scratchcountersix
>
\realpageno
356
\plustwo
357
\else
358
\plusfour
359
\fi\fi
360
\else
361
\ifnum
\scratchcounterfive
=
\scratchcountertwo
362
\ifnum
\scratchcountersix
<
\realpageno
363
\plusone
364
\else\ifnum
\scratchcountersix
>
\realpageno
365
\plusthree
366
\else
367
\plustwo
368
\fi\fi
369
\else
370
\minusone
371
\fi
372
\fi
373
\ifnum
\c_scrn_bar_mode
<
\zerocount
\else
374
\normalexpanded
{
\directgotospecbox
\noexpand
\interactionbarparameter
{
\scrn_bar_goto_indeed
\c_scrn_bar_mode
}
[
realpage
(
\the
\scratchcountersix
)]
}
%
375
\hss
376
\scratchcounterfive
\zerocount
377
\fi
}
%
378
\unskip
379
\egroup
380
}
\fi
}
381 382
\def
\scrn_bar_alternative_g
383
{
\ifnum
\lastsubpage
>
\firstsubpage
\relax
% no test for state?
384
\interactionbuttons
[
\v!firstsubpage
,
\v!previoussubpage
,
\v!nextsubpage
,
\v!lastsubpage
]
%
385
\fi
}
386 387
\setupinteractionbar
388
[
\c!state
=
\v!start
,
389
\c!alternative
=
a
,
390
\c!symbol
=
\v!no
,
391
\c!width
=
1
0
\emwidth
,
392
\c!height
=
.
5
\emwidth
,
393
\c!depth
=
\zeropoint
,
394
\c!distance
=
.
5
\emwidth
,
395
\c!step
=
\v!medium
,
396
\c!foregroundcolor
=
\interactionbarparameter
\c!color
,
397
\c!foregroundstyle
=
\interactionbarparameter
\c!style
,
398
\c!color
=
\interactionparameter
\c!color
,
399
\c!contrastcolor
=
\interactionparameter
\c!contrastcolor
,
400
\c!style
=
,
401
\c!frame
=
\v!on
,
402
\c!background
=
color
,
403
\c!backgroundcolor
=
gray
,
404
\c!samepage
=
\v!yes
]
405 406
\defineinteractionbar
[
a
][
\c!command
=
\scrn_bar_alternative_a
]
407
\defineinteractionbar
[
b
][
\c!command
=
\scrn_bar_alternative_b
,
\c!height
=
\v!broad
]
408
\defineinteractionbar
[
c
][
\c!command
=
\scrn_bar_alternative_c
,
\c!height
=
\v!max
,
\c!depth
=
\v!max
]
409
\defineinteractionbar
[
d
][
\c!command
=
\scrn_bar_alternative_d
,
\c!width
=
.
5
\emwidth
]
410
\defineinteractionbar
[
e
][
\c!command
=
\scrn_bar_alternative_e
]
411
\defineinteractionbar
[
f
][
\c!command
=
\scrn_bar_alternative_f
]
412
\defineinteractionbar
[
g
][
\c!command
=
\scrn_bar_alternative_g
,
\c!height
=
\v!broad
]
413 414
\protect
\endinput
415