% Copyright 2006 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 $Header: /cvsroot/pgf/pgf/generic/pgf/basiclayer/pgfcoreobjects.code.tex,v 1.2 2006/10/11 15:22:25 tantau Exp $


% Object reuse


% Define a pgf object for reuse. Such objects will be stored
% efficiently internally.
%
% #1 = name for later reuse
% #2 = lower left corner point of bounding box
% #3 = upper right left corner point of bounding box
% #4 = pure pgf code (nothing too fancy!)
%
% Description:
% 
% Used to define reusable objects. The object must be composed of
% basic pgf graphic primitives. Nothing fancy can be used. The
% created object will be stored as an xform object in pdf or as a
% postscript procedure in postscript.
%  
% Example:
%
% \pgfdefobject{myrect}{\pgfpoint{-1pt}{-1pt}}{\pgfpoint{11pt}{11pt}}
% {\pgfpathqmoveto{0pt}{0pt}
%  \pgfpathqmoveto{10pt}{0pt}
%  \pgfpathqmoveto{10pt}{10pt}
%  \pgfpathqmoveto{0pt}{10pt}
%  \pgfpathclose
%  \pgfusepath{stroke}}
%
% \begin{pgfpicture}{0cm}{0cm}{1cm}{1cm}
%   \pgfuseobject{myrect}
% \end{pgfpicture}

\def\pgfdefobject#1#2#3#4{%
  \pgfinterruptpath%
    \pgf@relevantforpicturesizefalse%
    \pgfsys@defobject{#1}{#2}{#3}{#4}%
  \endpgfinterruptpath%
  \ignorespaces%
}


% Use an object that was previously defined using pgfdefobject
%
% #1 = name of previously defined object
%  
% Example:
%
% \pgfdefobject{myrect}{\pgfpoint{-1pt}{-1pt}}{\pgfpoint{11pt}{11pt}}
% {\pgfqmoveto{0}{0}
%  \pgfqmoveto{10}{0}
%  \pgfqmoveto{10}{10}
%  \pgfqmoveto{0}{10}
%  \pgfclosestroke}
%
% \begin{pgfpicture}{0cm}{0cm}{1cm}{1cm}
%   \pgfuseobject{myrect}
% \end{pgfpicture}

\def\pgfuseobject#1{\pgfsys@beginscope\pgfsys@useobject{#1}{}\pgfsys@endscope}


% Use an object that was previously defined using pgfdefobject, but
% magnify the object by the current x and y register values
%
% #1 = name of previously defined object
%  
% Example:
%
% \pgfdefobject{myrect}{\pgfpoint{-1pt}{-1pt}}{\pgfpoint{11pt}{11pt}}
% {\pgfqmoveto{0}{0}
%  \pgfqmoveto{10}{0}
%  \pgfqmoveto{10}{10}
%  \pgfqmoveto{0}{10}
%  \pgfclosestroke}
%
% \begin{pgfpicture}{0cm}{0cm}{1cm}{1cm}
%   \pgf@x=2pt% Scale by factor two in x-direction
%   \pgf@y=2pt% Scale by factor two in y-direction
%   \pgfuseobjectmagnify{myrect}
% \end{pgfpicture}

\def\pgfuseobjectmagnify#1{%
  \pgfsys@beginscope%
  \pgfsys@useobject{#1}{\pgfsys@transformxyscale{\pgf@sys@tonumber{\pgf@x}}{\pgf@sys@tonumber{\pgf@y}}}%
  \pgfsys@endscope%
}


\endinput
