summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/scrn-bar.mkvi
blob: 4605f1d2e166b979e50c2eb336f7215bc3473191 (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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
%D \module
%D   [       file=scrn-bar, % was part of scrn-int
%D        version=1995.01.01,
%D          title=\CONTEXT\ Core Macros,
%D       subtitle=Progress Bars,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{ConTeXt Screen Macros / Progress Bars}

\unprotect

%D The code is a bit upgraded to \MKIV\ but the output is mostly the
%D same. In retrospect this should have been a module. We can move
%D some definitions to scrn-run-bar.mkiv if needed. We can also make
%D the code a bit more efficient.

% todo: replace blackrule by stupid rules

%D \starttyping
%D \setupinteraction
%D   [state=start]
%D
%D \setupsubpagenumber
%D   [state=start]
%D
%D \setuplayout
%D   [middle]
%D
%D \setuppapersize
%D   [S4][S4]
%D
%D \startsetups bars
%D     \ruledvbox to \textheight \bgroup
%D         a \ruledhbox{\interactionbar[a]}\vss
%D         b \ruledhbox{\interactionbar[b]}\vss
%D         c \ruledhbox{\interactionbar[c]}\vss
%D         d \ruledhbox{\interactionbar[d]}\vss
%D         e \ruledhbox{\interactionbar[e]}\vss
%D         f \ruledhbox{\interactionbar[f]}\vss
%D         g \ruledhbox{\interactionbar[g]}\vss
%D     \egroup
%D \stopsetups
%D
%D \setuptexttexts[\setups{bars}]
%D
%D \starttext
%D     \dorecurse {12} {
%D         \startstandardmakeup
%D         \stopstandardmakeup
%D     }
%D \stoptext
%D \stoptyping

\installcommandhandler \??ib {interactionbar} \??ib

\presetlocalframed[\??ib]

\unexpanded\def\interactionbar
  {\dodoubleempty\scrn_bar_direct}

\def\scrn_bar_direct[#tag][#settings]% somewhat messy
  {\iflocation
     \begingroup
     \doifassignmentelse{#tag}
       {\getparameters[\??ib][#tag]%
        \edef\currentinteractionbar{\interactionbarparameter\c!alternative}}%
       {\edef\currentinteractionbar{#tag}%
        \ifsecondargument\getparameters[\??ib#tag][#settings]\fi}%
     \doif{\interactionbarparameter\c!state}\v!start
       {\interactionbarparameter\c!command}%
     \endgroup
   \fi}

\newdimen\scrn_bar_width
\newdimen\scrn_bar_height
\newdimen\scrn_bar_depth
\newdimen\scrn_bar_distance

%D Interaction buttons, in fact a row of tiny buttons, are
%D typically only used for navigational purposed. The next
%D macro builds such a row based on a specification list.
%D
%D \startbuffer
%D \interactionbuttons[width=\hsize][page,PreviousJump,ExitViewer]
%D \stopbuffer
%D
%D \typebuffer
%D
%D gives
%D
%D \getbuffer
%D
%D Apart from individual entries, one can use \type{page} and
%D \type {subpage} as shortcuts to their four associated buttons.
%D The symbols are derived from the symbols linked to the
%D entries.

\unexpanded\def\interactionbuttons
  {\dodoubleempty\scrn_bar_buttons}

\def\scrn_bar_buttons
  {\iflocation
     \expandafter\scrn_bar_buttons_status
   \else
     \expandafter\scrn_bar_buttons_ignore
   \fi}

\def\scrn_bar_buttons_status[#settings][#list]%
   {\doif{\interactionbarparameter\c!state}\v!start
      {\ifsecondargument
         \scrn_bar_buttons_indeed[#settings][#list]%
       \else
         \scrn_bar_buttons_indeed[][#settings]%
       \fi}}

\def\scrn_bar_buttons_ignore[#settings][#list]% \gobbletwooptionals
  {}

\def\scrn_bar_buttons_indeed[#settings][#list]%
  {\begingroup
  %\let\menuparameter\interactionbarparameter
   \setupinteractionbar[#settings]%
   \scrn_bar_width\interactionbarparameter\c!width
   \ifdim\scrn_bar_width=\zeropoint
     \scrn_bar_width1.5\emwidth
   \fi
   \doifnothing{\interactionbarparameter\c!height}{\letinteractionbarparameter\c!height\v!broad}%
   \doifnothing{\interactionbarparameter\c!depth }{\letinteractionbarparameter\c!depth\!!zeropoint}%%%
   \setbox2\hbox{\localframed[\??ib\currentinteractionbar][\c!background=]{\symbol[\interactionparameter\c!symbolset][\v!previouspage]}}%
   \!!heighta\ht2 % needed because we default to nothing
   \setupinteractionbar[\c!strut=\v!no]%
   \letinteractionparameter\c!width\zeropoint
   \!!counta\zerocount % new, was 1
   \processallactionsinset
     [#list]
     [   \v!page=>\advance\!!counta 4,
      \v!subpage=>\advance\!!counta 4,
      \s!unknown=>\advance\!!counta 1]%
   \ifdim\scrn_bar_width=\zeropoint
     \!!widtha\dimexpr2\emwidth+\scrn_bar_distance\relax
     \!!widthb\dimexpr\!!counta\!!widtha-\scrn_bar_distance\relax
   \else
     \!!widtha\scrn_bar_width
     \!!widthb\dimexpr\!!counta\scrn_bar_distance-\scrn_bar_distance\relax
     \advance\!!widtha -\!!widthb
     \divide\!!widtha \!!counta
     \!!widthb\scrn_bar_width
   \fi
   \hbox to \!!widthb
     {\setnostrut
      \startsymbolset[\interactionparameter\c!symbolset]%
      \processallactionsinset
        [#list]
        [   \v!page=>\scrn_bar_goto\v!firstpage
                     \scrn_bar_goto\v!nextpage
                     \scrn_bar_goto\v!previouspage
                     \scrn_bar_goto\v!lastpage,
         \v!subpage=>\scrn_bar_goto\v!firstsubpage
                     \scrn_bar_goto\v!nextsubpage
                     \scrn_bar_goto\v!previoussubpage
                     \scrn_bar_goto\v!lastsubpage,
         \s!unknown=>\scrn_bar_goto\commalistelement]%
      \unskip
      \stopsymbolset}%
   \endgroup}

\def\scrn_bar_goto#action%
  {\button
     [\c!height=\the\!!heighta,\c!width=\the\!!widtha]%
     {\symbol[#action]}% we could expand this one once only
     [#action]%
   \hss}

\def\scrn_bar_alternative_a
  {\scrn_bar_width   \interactionbarparameter\c!width
   \scrn_bar_distance\interactionbarparameter\c!distance
   \scrn_bar_height  \interactionbarparameter\c!height
   \scrn_bar_depth   \interactionbarparameter\c!depth
   \noindent\hbox to \scrn_bar_width \bgroup
     \dontcomplain
     \setupblackrules[\c!height=\v!max,\c!depth=\v!max]%
     \!!widthb\dimexpr\scrn_bar_width-4\emwidth\relax
     \processaction
       [\interactionbarparameter\c!step]
       [   \v!small=>\scratchcounter 20,
          \v!medium=>\scratchcounter 10,
             \v!big=>\scratchcounter  5,
         \s!unknown=>\scratchcounter 10]%
     \!!widtha\dimexpr\!!widthb/\scratchcounter\relax
     \setupblackrules[\c!width=\!!widtha]%
     \setbox\scratchbox\hbox to \scrn_bar_width
       {\hskip2\emwidth
        \setbox\scratchbox\hbox{\blackrule[\c!color=\interactionbarparameter\c!backgroundcolor]}%
        \dorecurse\scratchcounter
          {\hss\normalexpanded{\directgotodumbbox{\copy\scratchbox}[page(\the\numexpr\recurselevel*\lastpage/\scratchcounter\relax)]}}%
        \hss
        \hskip2\emwidth}%
     \wd\scratchbox\zeropoint
     \box \scratchbox
     \setupblackrules[\c!width=\emwidth]%
     \normalexpanded{\directgotospecbox\noexpand\interactionbarparameter{\blackrule}[\v!firstpage]}%
     \hskip\emwidth
     \ifnum\realpageno>\plusone
       \hskip\zeropoint\!!plus\numexpr\realpageno-\plustwo\relax \s!sp\relax % cm gives overflow
       \normalexpanded{\directgotospecbox\noexpand\interactionbarparameter{\blackrule}[\v!previouspage)]}%
     \fi
     \normalexpanded{\directgotospecbox\noexpand\interactionbarparameter{\blackrule}[page(\number\realpageno)]}% todo: \v!currentpage
     \ifnum\realpageno<\lastpage\relax
       \normalexpanded{\directgotospecbox\noexpand\interactionbarparameter{\blackrule}[\v!nextpage]}%
       \hskip\zeropoint\!!plus\numexpr\lastpage-\realpageno-\plusone\relax \s!sp\relax % cm gives overflow
     \fi
     \hskip\emwidth
     \normalexpanded{\directgotospecbox\noexpand\interactionbarparameter{\blackrule}[\v!lastpage]}%
   \egroup}

\def\scrn_bar_alternative_b
  {\ifnum\lastpage>\firstpage\relax
     \interactionbuttons[\v!firstpage,\v!previouspage,\v!nextpage,\v!lastpage]%
   \fi}

\def\scrn_bar_alternative_c
  {\ifnum\lastpage>\plusone
     \scrn_bar_width\interactionbarparameter\c!width
     \hbox to \scrn_bar_width
       {\setupblackrules[\c!height=\interactionbarparameter\c!height,\c!depth=\interactionbarparameter\c!depth,\c!width=\emwidth]%
        \scratchdimen\dimexpr(\scrn_bar_width-4\emwidth)/\numexpr\lastpage+\minusone\relax\relax
        \!!widtha\numexpr\realpageno+\minusone\relax\scratchdimen
        \!!widthb\numexpr\lastpage-\realpageno\relax\scratchdimen
        \directgotospecbox\interactionbarparameter{\blackrule}[\v!firstpage]%
        \hss
        \directgotospecbox\interactionbarparameter{\blackrule[\c!width=\!!widtha]}[\v!previouspage]%
        \blackrule[\c!color=\interactionbarparameter\c!contrastcolor]%
        \directgotospecbox\interactionbarparameter{\blackrule[\c!width=\!!widthb]}[\v!nextpage]%
        \hss
        \directgotospecbox\interactionbarparameter{\blackrule}[\v!lastpage]}%
   \fi}

\unexpanded\def\scrn_bar_goto_a#whereto%
  {\symbol[\ifcase#whereto\v!previous\or\v!somewhere\or\v!next\fi]}

\unexpanded\def\scrn_bar_goto_b#whereto%
  {\vrule\!!height\scrn_bar_height\!!depth\scrn_bar_depth\!!width\!!widtha\relax}

\unexpanded\def\scrn_bar_goto_c#whereto%
  {\symbol[\ifcase#whereto\v!previous\or\v!somewhere\or\v!somewhere\or\v!somewhere\or\v!next\fi}

\unexpanded\def\scrn_bar_goto_d#whereto%
  {\vrule \!!width\!!widtha \ifcase#whereto%
     \!!height  \scrn_bar_height \!!depth  \scrn_bar_depth \or
     \!!height.5\scrn_bar_height \!!depth.5\scrn_bar_depth \or
     \!!height  \scrn_bar_height \!!depth  \scrn_bar_depth \or
     \!!height.5\scrn_bar_height \!!depth.5\scrn_bar_depth \else
     \!!height  \scrn_bar_height \!!depth  \scrn_bar_depth \fi}

\newconstant\scrn_bar_mode

\unexpanded\def\scrn_bar_goto_x#command%
  {\doifelse{\interactionbarparameter\c!symbol}\v!yes
     {\setupsymbolset[\interactionparameter\c!symbolset]%
      \let\scrn_bar_goto_indeed\scrn_bar_goto_a}
     {\let\scrn_bar_goto_indeed\scrn_bar_goto_b}%
   \dorecurse\nofsubpages
     {\scratchcounter\numexpr\recurselevel+\firstsubpage+\minusone\relax
      \scrn_bar_mode
        \ifnum\scratchcounter<\realpageno \zerocount \else
        \ifnum\scratchcounter=\realpageno \plusone   \else
                                          \plustwo   \fi\fi
      \normalexpanded{\directgotospecbox\noexpand\interactionbarparameter{\scrn_bar_goto_indeed\scrn_bar_mode}[page(\the\scratchcounter)]}%
      #command}%
   \unskip}

\def\scrn_bar_alternative_d
  {\ifnum\nofsubpages>\plusone \doif{\structurecounterparameter\s!subpage\c!state}\v!start{%
     \scrn_bar_width   \interactionbarparameter\c!width
     \scrn_bar_distance\interactionbarparameter\c!distance
     \scrn_bar_height  \interactionbarparameter\c!height
     \scrn_bar_depth   \interactionbarparameter\c!depth
     \!!widtha\scrn_bar_width
     \noindent\hbox{\scrn_bar_goto_x{\hskip\scrn_bar_distance}}%
   }\fi}

\def\scrn_bar_alternative_e
  {\ifnum\nofsubpages>\plusone \doif{\structurecounterparameter\s!subpage\c!state}\v!start{%
     \scrn_bar_width   \interactionbarparameter\c!width
     \scrn_bar_distance\interactionbarparameter\c!distance
     \scrn_bar_height  \interactionbarparameter\c!height
     \scrn_bar_depth   \interactionbarparameter\c!depth
     \!!widthb\dimexpr\nofsubpages\scrn_bar_distance-\scrn_bar_distance\relax % (n-1)
     \!!widtha\dimexpr(\scrn_bar_width-\!!widthb)/\nofsubpages\relax
     \ifdim\!!widtha<\scrn_bar_distance
       \scrn_bar_alternative_f
     \else
       \noindent\hbox to \scrn_bar_width{\scrn_bar_goto_x{\hss}\unskip}%
     \fi
   }\fi}

\def\scrn_bar_alternative_f
  {\ifnum\nofsubpages>\plusone \doif{\structurecounterparameter\s!subpage\c!state}\v!start{%
     \scrn_bar_width   \interactionbarparameter\c!width
     \scrn_bar_distance\interactionbarparameter\c!distance
     \scrn_bar_height  \interactionbarparameter\c!height
     \scrn_bar_depth   \interactionbarparameter\c!depth
     \noindent \hbox to \scrn_bar_width \bgroup
       \doloop
         {\!!countc\numexpr(\nofsubpages/\recurselevel)+\plusone\relax % rounding
          \!!widthb\scrn_bar_distance
          \multiply\!!widthb \!!countc
          \advance\!!widthb -\scrn_bar_distance
          \!!widtha\scrn_bar_width
          \advance\!!widtha -\!!widthb
          \divide\!!widtha \!!countc
          \ifdim\!!widtha<\scrn_bar_distance\else
            \!!countb\recurselevel
            \exitloop
          \fi}%
       \ifnum\!!countc>\plusone
         % this is not that well tested
         \advance\!!countc \minustwo
         \!!widtha-\scrn_bar_distance
         \!!widtha\!!countc\!!widtha
         \advance\!!widtha \scrn_bar_width
         \advance\!!countc \plusone
         \divide\!!widtha \!!countc
       \fi
       \doifelse{\interactionbarparameter\c!symbol}\v!yes
         {\setupsymbolset[\interactionparameter\c!symbolset]%
          \let\scrn_bar_goto_indeed\scrn_bar_goto_c}%
         {\let\scrn_bar_goto_indeed\scrn_bar_goto_d}%
       \!!countc\numexpr\realpageno-\plustwo\relax
       \!!countd\numexpr\realpageno+\plustwo\relax
       \ifnum\!!countc<\plusone \!!countc\plusone \fi
       \!!countf\zerocount
       \dostepwiserecurse\firstsubpage\lastsubpage\plusone
         {\!!doneafalse
          \advance\!!countf \plusone
          \ifnum\recurselevel=\firstsubpage\relax \!!doneatrue \fi
          \ifnum\recurselevel=\lastsubpage \relax \!!doneatrue \fi
          \scrn_bar_mode
            \if!!donea
              \ifnum\recurselevel<\realpageno
                \zerocount
              \else\ifnum\recurselevel>\realpageno
                \plustwo
              \else
                \plusfour
              \fi\fi
            \else
              \ifnum\!!countf=\!!countb
                \ifnum\recurselevel<\realpageno
                  \plusone
                \else\ifnum\recurselevel>\realpageno
                  \plusthree
                \else
                  \plustwo
                \fi\fi
              \else
                \plusthree
              \fi
            \fi
          \normalexpanded{\directgotospecbox\noexpand\interactionbarparameter{\scrn_bar_goto_indeed\scrn_bar_mode}[page(\recurselevel)]}%
          \hss
          \!!countf\zerocount}%
       \unskip
     \egroup
   }\fi}

\def\scrn_bar_alternative_g
  {\ifnum\lastsubpage>\firstsubpage\relax % no test for state?
     \interactionbuttons[\v!firstsubpage,\v!previoussubpage,\v!nextsubpage,\v!lastsubpage]%
   \fi}

\setupinteractionbar
  [\c!state=\v!start,
   \c!alternative=a,
   \c!symbol=\v!no,
   \c!width=10\emwidth,
   \c!height=.5\emwidth,
   \c!depth=\zeropoint,
   \c!distance=.5\emwidth,
   \c!step=\v!medium,
   \c!foregroundcolor=\interactionbarparameter\c!color,
   \c!foregroundstyle=\interactionbarparameter\c!style,
   \c!color=\interactionparameter\c!color,
   \c!contrastcolor=\interactionparameter\c!contrastcolor,
   \c!style=,
   \c!frame=\v!on,
   \c!background=color,
   \c!backgroundcolor=gray,
   \c!samepage=\v!yes]

\defineinteractionbar[a][\c!command=\scrn_bar_alternative_a]
\defineinteractionbar[b][\c!command=\scrn_bar_alternative_b,\c!height=\v!broad]
\defineinteractionbar[c][\c!command=\scrn_bar_alternative_c,\c!height=\v!max,\c!depth=\v!max]
\defineinteractionbar[d][\c!command=\scrn_bar_alternative_d,\c!width=.5\emwidth]
\defineinteractionbar[e][\c!command=\scrn_bar_alternative_e]
\defineinteractionbar[f][\c!command=\scrn_bar_alternative_f]
\defineinteractionbar[g][\c!command=\scrn_bar_alternative_g,\c!height=\v!broad]

\protect \endinput