| 1 |
% Copyright 2018 by Till Tantau |
| 2 |
% |
| 3 |
% This file may be distributed and/or modified |
| 4 |
% |
| 5 |
% 1. under the LaTeX Project Public License and/or |
| 6 |
% 2. under the GNU Public License. |
| 7 |
% |
| 8 |
% See the file doc/generic/pgf/licenses/LICENSE for more details. |
| 9 |
|
| 10 |
\ProvidesFileRCS{tikzlibrarybackgrounds.code.tex} |
| 11 |
|
| 12 |
|
| 13 |
% Layers |
| 14 |
|
| 15 |
\pgfdeclarelayer{background}% |
| 16 |
\pgfsetlayers{background,main}% |
| 17 |
|
| 18 |
|
| 19 |
% Switch command |
| 20 |
\tikzset{on background layer/.style={ |
| 21 |
execute at begin scope={% |
| 22 |
\pgfonlayer{background}% |
| 23 |
\let\tikz@options=\pgfutil@empty% |
| 24 |
\tikzset{every on background layer/.try,#1}% |
| 25 |
\tikz@options}, |
| 26 |
execute at end scope={\endpgfonlayer} |
| 27 |
} |
| 28 |
}% |
| 29 |
|
| 30 |
|
| 31 |
% Main style |
| 32 |
|
| 33 |
\tikzset{background rectangle/.style= {draw}}% |
| 34 |
\tikzset{background top/.style= {draw}}% |
| 35 |
\tikzset{background bottom/.style= {draw}}% |
| 36 |
\tikzset{background left/.style= {draw}}% |
| 37 |
\tikzset{background right/.style= {draw}}% |
| 38 |
\tikzset{background grid/.style= {help lines,draw}}% |
| 39 |
|
| 40 |
\tikzoption{inner frame sep}{\def\tikz@framexsep{#1}\def\tikz@frameysep{#1}}% |
| 41 |
\tikzoption{inner frame xsep}{\def\tikz@framexsep{#1}}% |
| 42 |
\tikzoption{inner frame ysep}{\def\tikz@frameysep{#1}}% |
| 43 |
\def\tikz@framexsep{1ex}% |
| 44 |
\def\tikz@frameysep{1ex}% |
| 45 |
|
| 46 |
\tikzoption{outer frame sep}{\def\tikz@outerframexsep{#1}\def\tikz@outerframeysep{#1}}% |
| 47 |
\tikzoption{outer frame xsep}{\def\tikz@outerframexsep{#1}}% |
| 48 |
\tikzoption{outer frame ysep}{\def\tikz@outerframeysep{#1}}% |
| 49 |
\def\tikz@outerframexsep{0ex}% |
| 50 |
\def\tikz@outerframeysep{0ex}% |
| 51 |
|
| 52 |
|
| 53 |
% Looseness |
| 54 |
|
| 55 |
\tikzset{loose background/.style= {inner frame sep=2ex}}% |
| 56 |
\tikzset{tight background/.style= {inner frame sep=0ex}}% |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
% Showing background styles |
| 61 |
|
| 62 |
\tikzset{framed/.style= {style=show background rectangle}}% |
| 63 |
\tikzset{gridded/.style= {style=show background grid}}% |
| 64 |
|
| 65 |
\tikzset{show background rectangle/.style={execute at end picture=\tikz@background@framed}}% |
| 66 |
\tikzset{show background top/.style= {execute at end picture=\tikz@background@top}}% |
| 67 |
\tikzset{show background bottom/.style= {execute at end picture=\tikz@background@bottom}}% |
| 68 |
\tikzset{show background left/.style= {execute at end picture=\tikz@background@left}}% |
| 69 |
\tikzset{show background right/.style= {execute at end picture=\tikz@background@right}}% |
| 70 |
\tikzset{show background grid/.style= {execute at end picture=\tikz@background@grid}}% |
| 71 |
|
| 72 |
|
| 73 |
% Implementation |
| 74 |
|
| 75 |
\def\tikz@background@save{% |
| 76 |
\pgftransformreset% |
| 77 |
\ifx\tikz@bg@minx\@undefined% |
| 78 |
\pgf@xb=\pgf@picminx% |
| 79 |
\pgf@yb=\pgf@picminy% |
| 80 |
\pgf@xc=\pgf@picmaxx% |
| 81 |
\pgf@yc=\pgf@picmaxy% |
| 82 |
\pgfmathsetlength{\pgf@x}{\tikz@framexsep}% |
| 83 |
\pgfmathsetlength{\pgf@y}{\tikz@frameysep}% |
| 84 |
\advance\pgf@xb by-\pgf@x% |
| 85 |
\advance\pgf@yb by-\pgf@y% |
| 86 |
\advance\pgf@xc by\pgf@x% |
| 87 |
\advance\pgf@yc by\pgf@y% |
| 88 |
\edef\tikz@bg@minx{\the\pgf@xb}% |
| 89 |
\edef\tikz@bg@miny{\the\pgf@yb}% |
| 90 |
\edef\tikz@bg@maxx{\the\pgf@xc}% |
| 91 |
\edef\tikz@bg@maxy{\the\pgf@yc}% |
| 92 |
\pgfmathsetlength{\pgf@x}{\tikz@outerframexsep}% |
| 93 |
\pgfmathsetlength{\pgf@y}{\tikz@outerframeysep}% |
| 94 |
\advance\pgf@xb by-\pgf@x% |
| 95 |
\advance\pgf@yb by-\pgf@y% |
| 96 |
\advance\pgf@xc by\pgf@x% |
| 97 |
\advance\pgf@yc by\pgf@y% |
| 98 |
\edef\tikz@bg@outerminx{\the\pgf@xb}% |
| 99 |
\edef\tikz@bg@outerminy{\the\pgf@yb}% |
| 100 |
\edef\tikz@bg@outermaxx{\the\pgf@xc}% |
| 101 |
\edef\tikz@bg@outermaxy{\the\pgf@yc}% |
| 102 |
\fi% |
| 103 |
}% |
| 104 |
|
| 105 |
\def\tikz@background@framed{% |
| 106 |
\tikz@background@save% |
| 107 |
\pgfonlayer{background} |
| 108 |
\path[style=background rectangle] (\tikz@bg@minx,\tikz@bg@miny) rectangle (\tikz@bg@maxx,\tikz@bg@maxy); |
| 109 |
\endpgfonlayer |
| 110 |
}% |
| 111 |
|
| 112 |
\def\tikz@background@top{% |
| 113 |
\tikz@background@save% |
| 114 |
\pgfonlayer{background} |
| 115 |
\path[style=background top] (\tikz@bg@outerminx,\tikz@bg@maxy) -- (\tikz@bg@outermaxx,\tikz@bg@maxy); |
| 116 |
\endpgfonlayer |
| 117 |
}% |
| 118 |
|
| 119 |
\def\tikz@background@bottom{% |
| 120 |
\tikz@background@save% |
| 121 |
\pgfonlayer{background} |
| 122 |
\path[style=background bottom] (\tikz@bg@outerminx,\tikz@bg@miny) -- (\tikz@bg@outermaxx,\tikz@bg@miny); |
| 123 |
\endpgfonlayer |
| 124 |
}% |
| 125 |
|
| 126 |
\def\tikz@background@left{% |
| 127 |
\tikz@background@save% |
| 128 |
\pgfonlayer{background} |
| 129 |
\path[style=background left] (\tikz@bg@minx,\tikz@bg@outerminy) -- (\tikz@bg@minx,\tikz@bg@outermaxy); |
| 130 |
\endpgfonlayer |
| 131 |
}% |
| 132 |
|
| 133 |
\def\tikz@background@right{% |
| 134 |
\tikz@background@save% |
| 135 |
\pgfonlayer{background} |
| 136 |
\path[style=background right] (\tikz@bg@maxx,\tikz@bg@outerminy) -- (\tikz@bg@maxx,\tikz@bg@outermaxy); |
| 137 |
\endpgfonlayer |
| 138 |
}% |
| 139 |
|
| 140 |
\def\tikz@background@grid{% |
| 141 |
\tikz@background@save% |
| 142 |
\pgfonlayer{background} |
| 143 |
\path[style=background grid] (\tikz@bg@minx,\tikz@bg@miny) grid (\tikz@bg@maxx,\tikz@bg@maxy); |
| 144 |
\endpgfonlayer |
| 145 |
}% |
| 146 |
|
| 147 |
|
| 148 |
\endinput |