summaryrefslogtreecommitdiff
path: root/graphics/pgf/base/tex/tikzlibrarybackgrounds.code.tex
blob: 1a42a4b40e4ab13996cd3ab0e42f7613d08efe45 (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
% Copyright 2018 by Till Tantau
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.

\ProvidesFileRCS{tikzlibrarybackgrounds.code.tex}


% Layers

\pgfdeclarelayer{background}%
\pgfsetlayers{background,main}%


% Switch command
\tikzset{on background layer/.style={
    execute at begin scope={%
      \pgfonlayer{background}%
      \let\tikz@options=\pgfutil@empty%
      \tikzset{every on background layer/.try,#1}%
      \tikz@options},
    execute at end scope={\endpgfonlayer}
  }
}%


% Main style

\tikzset{background rectangle/.style= {draw}}%
\tikzset{background top/.style=       {draw}}%
\tikzset{background bottom/.style=    {draw}}%
\tikzset{background left/.style=      {draw}}%
\tikzset{background right/.style=     {draw}}%
\tikzset{background grid/.style=      {help lines,draw}}%

\tikzoption{inner frame sep}{\def\tikz@framexsep{#1}\def\tikz@frameysep{#1}}%
\tikzoption{inner frame xsep}{\def\tikz@framexsep{#1}}%
\tikzoption{inner frame ysep}{\def\tikz@frameysep{#1}}%
\def\tikz@framexsep{1ex}%
\def\tikz@frameysep{1ex}%

\tikzoption{outer frame sep}{\def\tikz@outerframexsep{#1}\def\tikz@outerframeysep{#1}}%
\tikzoption{outer frame xsep}{\def\tikz@outerframexsep{#1}}%
\tikzoption{outer frame ysep}{\def\tikz@outerframeysep{#1}}%
\def\tikz@outerframexsep{0ex}%
\def\tikz@outerframeysep{0ex}%


% Looseness

\tikzset{loose background/.style=     {inner frame sep=2ex}}%
\tikzset{tight background/.style=     {inner frame sep=0ex}}%



% Showing background styles

\tikzset{framed/.style=                   {style=show background rectangle}}%
\tikzset{gridded/.style=                  {style=show background grid}}%

\tikzset{show background rectangle/.style={execute at end picture=\tikz@background@framed}}%
\tikzset{show background top/.style=      {execute at end picture=\tikz@background@top}}%
\tikzset{show background bottom/.style=   {execute at end picture=\tikz@background@bottom}}%
\tikzset{show background left/.style=     {execute at end picture=\tikz@background@left}}%
\tikzset{show background right/.style=    {execute at end picture=\tikz@background@right}}%
\tikzset{show background grid/.style=     {execute at end picture=\tikz@background@grid}}%


% Implementation

\def\tikz@background@save{%
  \pgftransformreset%
  \ifx\tikz@bg@minx\@undefined%
    \pgf@xb=\pgf@picminx%
    \pgf@yb=\pgf@picminy%
    \pgf@xc=\pgf@picmaxx%
    \pgf@yc=\pgf@picmaxy%
    \pgfmathsetlength{\pgf@x}{\tikz@framexsep}%
    \pgfmathsetlength{\pgf@y}{\tikz@frameysep}%
    \advance\pgf@xb by-\pgf@x%
    \advance\pgf@yb by-\pgf@y%
    \advance\pgf@xc by\pgf@x%
    \advance\pgf@yc by\pgf@y%
    \edef\tikz@bg@minx{\the\pgf@xb}%
    \edef\tikz@bg@miny{\the\pgf@yb}%
    \edef\tikz@bg@maxx{\the\pgf@xc}%
    \edef\tikz@bg@maxy{\the\pgf@yc}%
    \pgfmathsetlength{\pgf@x}{\tikz@outerframexsep}%
    \pgfmathsetlength{\pgf@y}{\tikz@outerframeysep}%
    \advance\pgf@xb by-\pgf@x%
    \advance\pgf@yb by-\pgf@y%
    \advance\pgf@xc by\pgf@x%
    \advance\pgf@yc by\pgf@y%
    \edef\tikz@bg@outerminx{\the\pgf@xb}%
    \edef\tikz@bg@outerminy{\the\pgf@yb}%
    \edef\tikz@bg@outermaxx{\the\pgf@xc}%
    \edef\tikz@bg@outermaxy{\the\pgf@yc}%
  \fi%
}%

\def\tikz@background@framed{%
  \tikz@background@save%
  \pgfonlayer{background}
    \path[style=background rectangle] (\tikz@bg@minx,\tikz@bg@miny) rectangle (\tikz@bg@maxx,\tikz@bg@maxy);
  \endpgfonlayer
}%

\def\tikz@background@top{%
  \tikz@background@save%
  \pgfonlayer{background}
    \path[style=background top] (\tikz@bg@outerminx,\tikz@bg@maxy) -- (\tikz@bg@outermaxx,\tikz@bg@maxy);
  \endpgfonlayer
}%

\def\tikz@background@bottom{%
  \tikz@background@save%
  \pgfonlayer{background}
    \path[style=background bottom] (\tikz@bg@outerminx,\tikz@bg@miny) -- (\tikz@bg@outermaxx,\tikz@bg@miny);
  \endpgfonlayer
}%

\def\tikz@background@left{%
  \tikz@background@save%
  \pgfonlayer{background}
    \path[style=background left] (\tikz@bg@minx,\tikz@bg@outerminy) -- (\tikz@bg@minx,\tikz@bg@outermaxy);
  \endpgfonlayer
}%

\def\tikz@background@right{%
  \tikz@background@save%
  \pgfonlayer{background}
    \path[style=background right] (\tikz@bg@maxx,\tikz@bg@outerminy) -- (\tikz@bg@maxx,\tikz@bg@outermaxy);
  \endpgfonlayer
}%

\def\tikz@background@grid{%
  \tikz@background@save%
  \pgfonlayer{background}
    \path[style=background grid] (\tikz@bg@minx,\tikz@bg@miny) grid (\tikz@bg@maxx,\tikz@bg@maxy);
  \endpgfonlayer
}%


\endinput