Debian Codegraph @

texmf-dist/source/latex/wargame/util/tikz.dtx

raw
1 % \iffalse
2 % --------------------------------------------------------------------
3 % <*utils>
4 % \fi
5 %
6 % \subsubsection{Other Tikz utilities}
7 %
8 % \begin{TikzKey}{tikz/reverseclip}
9 %
10 % A reverse clipping path. This is used to cut out stuff outside of
11 % path defined.
12 %
13 % \begin{macrocode}
14 \tikzstyle{reverseclip}=[insert path={(current bounding box.north east) --
15 (current bounding box.south east) --
16 (current bounding box.south west) --
17 (current bounding box.north west) --
18 (current bounding box.north east)}]
19 % \end{macrocode}
20 % \end{TikzKey}
21 %
22 % \begin{TikzKey}{tikz/clip even odd rule}
23 % A reverse clipping path
24 %
25 % \begin{macrocode}
26 \tikzset{
27 clip even odd rule/.code={\pgfseteorule}, % Credit to Andrew Stacey
28 }
29 % \end{macrocode}
30 % \end{TikzKey}
31 %
32 %
33 % \begin{TikzKey}{tikz/invclip}
34 %
35 % Inverse clipping. This should be an option \emph{after} the path to
36 % do the inverse clipping by. This works by adding a \emph{large}
37 % (page) path to the current path, and then use that as clipping.
38 %
39 % \begin{macrocode}
40 \tikzset{
41 invclip/.style={
42 clip,insert path=
43 [clip even odd rule]{
44 [reset cm](-\maxdimen,-\maxdimen)rectangle(\maxdimen,\maxdimen)
45 }
46 },
47 }
48 % \end{macrocode}
49 % \end{TikzKey}
50 %
51 % \begin{TikzKey}{save clip}
52 %
53 % An option for use with sub-elements of NATO App 6(c) or chit
54 % nodes. This will save the current path as a clipping path for the
55 % next paths to be drawn in the sub-element
56 %
57 % \begin{macrocode}
58 \newif\ifwg@s@ve\wg@s@vefalse
59 \tikzset{
60 save clip/.is choice,
61 save clip/true/.code={\global\wg@s@vetrue},
62 save clip/false/.code={\global\wg@s@vefalse},
63 save clip/.default={true},
64 save clip/.initial={false},
65 }
66 % \end{macrocode}
67 % \end{TikzKey}
68 %
69 % \begin{TikzKey}{scale line widths}
70 %
71 % Scales any line width specified in the node options.
72 %
73 % Use like
74 %
75 % \begin{verbatim}
76 % \tikzset{
77 % some/.style={
78 % scale line widths,
79 % line width=1pt}
80 % }
81 % \end{verbatim}
82 %
83 % Note that the order is important.
84 %
85 % \begin{macrocode}
86 % Save pgf rounded corners macro
87 % \let\wg@pgfsetcornersarced\pgfsetcornersarced
88 \def\wg@setcornersarched#1{%
89 \def\arg{#1}%
90 \let\isarched\relax% Cannot set \ifpgf@arccorners directly inside
91 % other \if
92 \ifx\arg\@empty\else%
93 \edef\pgf@corner@arc{{#1}{#1}}%
94 \let\isarched\pgf@arccornerstrue%
95 \ifdim#1=0pt%
96 \let\isarched\pgf@arccornersfalse%
97 \fi%
98 \fi%
99 \isarched}
100 \newdimen\wg@lw@scaled\wg@lw@scaled=1pt
101 \def\wg@getscale{%
102 \pgfgettransformentries{%
103 \wg@jaca}{%
104 \wg@jacb}{%
105 \wg@jacc}{%
106 \wg@jacd}{%
107 \wg@tmp}{%
108 \wg@tmp}%
109 \pgfmathsetmacro{\wg@jac}{sqrt(abs(\wg@jaca*\wg@jacd-\wg@jacb*\wg@jacc))}%
110 \wg@dbg{4}{Scale is \wg@jac}
111 \xdef\wg@scale{\wg@jac}}
112 \def\wg@scaled#1{%
113 \wg@getscale%
114 \wg@dbg{4}{Scaling #1 by \wg@scale}
115 \pgfmathsetmacro{\wg@tmp}{\wg@scale*#1}%
116 \xdef\wg@tmp{\wg@tmp}%
117 \xdef\wg@lw@scale{\wg@tmp}%
118 \wg@dbg{4}{Scaled #1 -> \wg@tmp}}
119 %% \message{^^JRounded corners: \meaning\pgfsetcornersarced}
120 \tikzset{
121 %% Get current scale and store in \wg@scale
122 get scale/.code={\wg@getscale},
123 scale line widths/.style={%
124 /utils/exec=\def\tikz@semiaddlinewidth##1{%
125 \wg@scaled{##1}
126 \wg@lw@scaled=\wg@tmp pt
127 \tikz@addoption{\pgfsetlinewidth{\wg@lw@scaled}}%
128 \wg@dbg{4}{Added scaled option \wg@tmp}
129 \pgfmathsetlength\pgflinewidth{\wg@tmp pt}
130 \wg@dbg{4}{Did set line width \wg@tmp pt}
131 }
132 },
133 scale rounded corners/.style={%
134 /utils/exec=\def\pgfsetcornersarced##1{%
135 \pgf@process{##1}%
136 \pgf@xa=\pgf@x%
137 \wg@scaled{\the\pgf@xa}%
138 % \tikz@addoption{\wg@setcornersarched{\wg@tmp pt}}%
139 \wg@dbg{4}{Scaled rounded corners: \the\pgf@xa -> \wg@tmp}%
140 \wg@setcornersarched{\wg@tmp pt}%
141 }
142 },
143 relative line width/.style={%
144 /utils/exec=\def\tikz@semiaddlinewidth##1{%
145 \wg@dbg{4}{Relative line width #1 times ##1}%
146 \pgfmathsetmacro{\wg@lv}{#1*##1}%
147 \tikz@addoption{\pgfsetlinewidth{\wg@lw pt}}%
148 \pgfmathsetlength\pgflinewidth{\wg@lw pt}}}
149 }
150 % \end{macrocode}
151 % \end{TikzKey}
152 %
153 % \begin{TikzKey}{sub pic actions}
154 %
155 % This is key that propagates actions to sub pictures of pictures.
156 % The normal \texttt{pic actions} cannot be used as it causes an
157 % infinite loop.
158 %
159 % \begin{macrocode}
160 \tikzset{
161 sub pic actions/.code={%
162 \tikz@picmode%
163 \edef\opts{%
164 \iftikz@mode@draw draw,\else draw=none,\fi
165 \iftikz@mode@fill fill\else fill=none\fi}
166 \wg@dbg{5}{^^JSub Mode: \meaning\tikz@picmode \meaning\opts}
167 \pgfset{/tikz/.cd}
168 \pgfkeysalsofrom{\opts}
169 }}
170 % \end{macrocode}
171 % \end{TikzKey}
172 %
173 % \begin{TikzKey}{wg/debug show}
174 %
175 % Show debugging information
176 %
177 % \begin{macrocode}
178 \tikzset{
179 wg/debug show/.code={%
180 \extractcolorspec{pgfstrokecolor}{\wg@tmp@fg}
181 \def\wg@tmp@bg{none}
182 \@ifundefinedcolor{pgffillcolor}{}{
183 \extractcolorspec{pgffillcolor}{\wg@tmp@bg}}
184 \begingroup
185 \tikz@mode
186 \wargamedbglvl=#1
187 \wg@dbg{3}{Drawing with w/stroke `\wg@tmp@fg'
188 (\tikz@strokecolor,\iftikz@mode@draw\else not\space\fi drawing)
189 and fill `\wg@tmp@bg' (\tikz@fillcolor,\iftikz@mode@fill\else
190 not\space\fi filling)}
191 \endgroup
192 }
193 }
194 % \end{macrocode}
195 % \end{TikzKey}
196 %
197 %
198 % \iffalse
199 % --------------------------------------------------------------------
200 % </utils>
201 % \fi