summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/ocgx/tikzlibraryocgx.code.tex
blob: 0ad0b30f9120d53072313fa4e0dd8707bcec9116 (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
% Copyright (C) 2012 by Paul Gaborit
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.

\RequirePackage{ocgx}

\makeatletter
\tikzset{
  ocg/.style={ocg/.cd,#1,/tikz/.cd},
  ocg={
    % parameters
    name/.store in=\ocgx@name,
    visibity/.store in=\ocgx@visibility,
    status/.is choice,
    status/visible/.style={visibity=1},
    status/invisible/.style={visibity=0},
    % default values
    name=,
    status=visible,
    % ref
    ref/.style={
      /tikz/execute at begin scope={\ocg{\ocgx@name}{#1}{\ocgx@visibility}},
      /tikz/execute at end scope={\endocg},
    },
  },
  switch ocg/.style={
    postaction={
      path picture={
        \path let
        \p1 = (path picture bounding box.south west),
        \p2 = (path picture bounding box.north east),
        \p3 = (\x2-\x1,\y2-\y1)
        in
        (path picture bounding box.center)
        node[inner sep=0pt,anchor=center,outer sep=0pt]
        {\switchocg{#1}{\phantom{\rule{\x3}{\y3}}}};
      }
    },
  },
  switch ocg with mark on/.style 2 args={
    postaction={
      path picture={
        \begin{ocg}{#1}{#1}{1}
          \draw
          (path picture bounding box.south west)
          --
          (path picture bounding box.north east)
          (path picture bounding box.south east)
          --
          (path picture bounding box.north west)
          ;
        \end{ocg}
      },
      switch ocg={#1 #2},
    }
  },
  switch ocg with mark off/.style 2 args={
    postaction={
      path picture={
        \begin{ocg}{#1}{#1}{0}
          \draw
          (path picture bounding box.south west)
          --
          (path picture bounding box.north east)
          (path picture bounding box.south east)
          --
          (path picture bounding box.north west)
          ;
        \end{ocg}
      },
      switch ocg={#1 #2},
    }
  },
  show ocg/.style={
    postaction={
      path picture={
        \path let
        \p1 = (path picture bounding box.south west),
        \p2 = (path picture bounding box.north east),
        \p3 = (\x2-\x1,\y2-\y1)
        in
        (path picture bounding box.center)
        node[inner sep=0pt,anchor=center]
        {\showocg{#1}{\phantom{\rule{\x3}{\y3}}}};
      },
    },
  },
  hide ocg/.style={
    postaction={
      path picture={
        \path let
        \p1 = (path picture bounding box.south west),
        \p2 = (path picture bounding box.north east),
        \p3 = (\x2-\x1,\y2-\y1)
        in
        (path picture bounding box.center)
        node[inner sep=0pt,anchor=center]
        {\hideocg{#1}{\phantom{\rule{\x3}{\y3}}}};
      },
    },
  },
  actions ocg/.style n args={3}{
    postaction={
      path picture={
        \path let
        \p1 = (path picture bounding box.south west),
        \p2 = (path picture bounding box.north east),
        \p3 = (\x2-\x1,\y2-\y1)
        in
        (path picture bounding box.center)
        node[inner sep=0pt,anchor=center]
        {\actionsocg{#1}{#2}{#3}{\phantom{\rule{\x3}{\y3}}}};
      },
    },
  },
}
\makeatother