summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/wargame/source/util/tikz.dtx
blob: 2f6dbefc1767a0a3eddf43574c708a71e30700a8 (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
% \iffalse
% --------------------------------------------------------------------
% <*utils>
% \fi
% 
% \subsubsection{Other Tikz utilities}
% 
% \begin{TikzKey}{tikz/reverseclip}
%   
%   A reverse clipping path.  This is used to cut out stuff outside of
%   path defined.
%   
%    \begin{macrocode}
\tikzstyle{reverseclip}=[insert path={(current bounding box.north east) --
  (current bounding box.south east) --
  (current bounding box.south west) --
  (current bounding box.north west) --
  (current bounding box.north east)}]
%    \end{macrocode}
% \end{TikzKey}
% 
% \begin{TikzKey}{tikz/clip even odd rule}
%   A reverse clipping path
%
%    \begin{macrocode}
\tikzset{
  clip even odd rule/.code={\pgfseteorule}, % Credit to Andrew Stacey
}
%    \end{macrocode}
% \end{TikzKey}
% 
%
% \begin{TikzKey}{tikz/invclip}
%
% Inverse clipping.  This should be an option \emph{after} the path to
% do the inverse clipping by.  This works by adding a \emph{large}
% (page) path to the current path, and then use that as clipping.
% 
%    \begin{macrocode}
\tikzset{
  invclip/.style={
    clip,insert path=
    [clip even odd rule]{
      [reset cm](-\maxdimen,-\maxdimen)rectangle(\maxdimen,\maxdimen)
    }
  },
}
%    \end{macrocode}
% \end{TikzKey}
%
% \begin{TikzKey}{save clip}
%
%   An option for use with sub-elements of NATO App 6(c) or chit
%   nodes.  This will save the current path as a clipping path for the
%   next paths to be drawn in the sub-element
%
%    \begin{macrocode}
\newif\ifwg@s@ve\wg@s@vefalse
\tikzset{
  save clip/.is choice,
  save clip/true/.code={\global\wg@s@vetrue},
  save clip/false/.code={\global\wg@s@vefalse},
  save clip/.default={true},
  save clip/.initial={false},
}
%    \end{macrocode}
% \end{TikzKey}
%
% \begin{TikzKey}{scale line widths}
%
%   Scales any line width specified in the node options.
%
%   Use like
%
% \begin{verbatim}
%    \tikzset{
%      some/.style={
%        scale line widths,
%        line width=1pt}
%    }
% \end{verbatim}
%
% Note that the order is important.
%   
%    \begin{macrocode}
%      Save pgf rounded corners macro
%      \let\wg@pgfsetcornersarced\pgfsetcornersarced
\def\wg@setcornersarched#1{%
  \def\arg{#1}%
  \let\isarched\relax%   Cannot set \ifpgf@arccorners directly inside
                     %   other \if
  \ifx\arg\@empty\else%
    \edef\pgf@corner@arc{{#1}{#1}}%
    \let\isarched\pgf@arccornerstrue%
    \ifdim#1=0pt%
      \let\isarched\pgf@arccornersfalse%
    \fi%
  \fi%
  \isarched}
\newdimen\wg@lw@scaled\wg@lw@scaled=1pt
\def\wg@getscale{%
  \pgfgettransformentries{%
    \wg@jaca}{%
    \wg@jacb}{%
    \wg@jacc}{%
    \wg@jacd}{%
    \wg@tmp}{%
    \wg@tmp}%
  \pgfmathsetmacro{\wg@jac}{sqrt(abs(\wg@jaca*\wg@jacd-\wg@jacb*\wg@jacc))}%
  \wg@dbg{4}{Scale is \wg@jac}
  \xdef\wg@scale{\wg@jac}}
\def\wg@scaled#1{%
  \wg@getscale%
  \wg@dbg{4}{Scaling #1 by \wg@scale}
  \pgfmathsetmacro{\wg@tmp}{\wg@scale*#1}%
  \xdef\wg@tmp{\wg@tmp}%
  \xdef\wg@lw@scale{\wg@tmp}%
  \wg@dbg{4}{Scaled #1 -> \wg@tmp}}
%% \message{^^JRounded corners: \meaning\pgfsetcornersarced}
\tikzset{
  %% Get current scale and store in \wg@scale
  get scale/.code={\wg@getscale},
  scale line widths/.style={%
    /utils/exec=\def\tikz@semiaddlinewidth##1{%
      \wg@scaled{##1}
      \wg@lw@scaled=\wg@tmp pt
      \tikz@addoption{\pgfsetlinewidth{\wg@lw@scaled}}%
      \wg@dbg{4}{Added scaled option \wg@tmp}
      \pgfmathsetlength\pgflinewidth{\wg@tmp pt}
      \wg@dbg{4}{Did set line width \wg@tmp pt}
    }
  },
  scale rounded corners/.style={%
    /utils/exec=\def\pgfsetcornersarced##1{%
      \pgf@process{##1}%
      \pgf@xa=\pgf@x%
      \wg@scaled{\the\pgf@xa}%
      % \tikz@addoption{\wg@setcornersarched{\wg@tmp pt}}%
      \wg@dbg{4}{Scaled rounded corners: \the\pgf@xa -> \wg@tmp}%
      \wg@setcornersarched{\wg@tmp pt}%
    }
  },
  relative line width/.style={%
    /utils/exec=\def\tikz@semiaddlinewidth##1{%
      \wg@dbg{4}{Relative line width #1 times ##1}%
      \pgfmathsetmacro{\wg@lv}{#1*##1}%
      \tikz@addoption{\pgfsetlinewidth{\wg@lw pt}}%
      \pgfmathsetlength\pgflinewidth{\wg@lw pt}}}
}
%    \end{macrocode}
% \end{TikzKey}
%
% \begin{TikzKey}{sub pic actions}
%
%   This is key that propagates actions to sub pictures of pictures.
%   The normal \texttt{pic actions} cannot be used as it causes an
%   infinite loop.
%
%    \begin{macrocode}
\tikzset{
  sub pic actions/.code={%
    \tikz@picmode%
    \edef\opts{%
      \iftikz@mode@draw draw,\else draw=none,\fi 
      \iftikz@mode@fill fill\else fill=none\fi}
    \wg@dbg{5}{^^JSub Mode: \meaning\tikz@picmode  \meaning\opts}
    \pgfset{/tikz/.cd}
    \pgfkeysalsofrom{\opts}
  }}
%    \end{macrocode}
% \end{TikzKey}
% 
% \begin{TikzKey}{wg/debug show}
%
%   Show debugging information
%   
%    \begin{macrocode}
\tikzset{
  wg/debug show/.code={%
    \extractcolorspec{pgfstrokecolor}{\wg@tmp@fg}
    \def\wg@tmp@bg{none}
    \@ifundefinedcolor{pgffillcolor}{}{
      \extractcolorspec{pgffillcolor}{\wg@tmp@bg}}
    \begingroup
    \tikz@mode
    \wargamedbglvl=#1
    \wg@dbg{3}{Drawing with w/stroke `\wg@tmp@fg'
      (\tikz@strokecolor,\iftikz@mode@draw\else not\space\fi drawing)
      and fill `\wg@tmp@bg' (\tikz@fillcolor,\iftikz@mode@fill\else
      not\space\fi  filling)}
    \endgroup
  }
}
%    \end{macrocode}
% \end{TikzKey}
%
% 
% \iffalse
% --------------------------------------------------------------------
% </utils>
% \fi