ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* mfun-004.tex \startuseMPgraphic
@ 2005-12-19  0:13 David Arnold
  2005-12-19  9:52 ` Hans Hagen
  0 siblings, 1 reply; 2+ messages in thread
From: David Arnold @ 2005-12-19  0:13 UTC (permalink / raw)


Hans,

In mfun-004.tex, I find:

\startuseMPgraphic{axis}
   tickstep := 1cm ; ticklength := 2mm ;
   drawticks unitsquare xscaled 4cm yscaled 3cm shifted (-1cm,-1cm) ;
   tickstep := tickstep/2 ; ticklength := ticklength/2 ;
   drawticks unitsquare xscaled 4cm yscaled 3cm shifted (-1cm,-1cm) ;
\stopuseMPgraphic

\startlinecorrection[blank]
\startMPcode
   \includeMPgraphic{axis}
   drawpoint "1cm,1.5cm" ;
\stopMPcode
\stoplinecorrection


If the axis graphic is going to be "reused" over and over again, why  
didn't you use \startreusableMPgraphic?

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: mfun-004.tex \startuseMPgraphic
  2005-12-19  0:13 mfun-004.tex \startuseMPgraphic David Arnold
@ 2005-12-19  9:52 ` Hans Hagen
  0 siblings, 0 replies; 2+ messages in thread
From: Hans Hagen @ 2005-12-19  9:52 UTC (permalink / raw)


David Arnold wrote:

> Hans,
>
> In mfun-004.tex, I find:
>
> \startuseMPgraphic{axis}
>   tickstep := 1cm ; ticklength := 2mm ;
>   drawticks unitsquare xscaled 4cm yscaled 3cm shifted (-1cm,-1cm) ;
>   tickstep := tickstep/2 ; ticklength := ticklength/2 ;
>   drawticks unitsquare xscaled 4cm yscaled 3cm shifted (-1cm,-1cm) ;
> \stopuseMPgraphic
>
> \startlinecorrection[blank]
> \startMPcode
>   \includeMPgraphic{axis}
>   drawpoint "1cm,1.5cm" ;
> \stopMPcode
> \stoplinecorrection
>
>
> If the axis graphic is going to be "reused" over and over again, why  
> didn't you use \startreusableMPgraphic?

in that case i should have used overlays or so since re-use is not part 
of mp itself (when we use tex for such an overlay one needs to position 
them); the problem in the current implementation is that the reference 
points are not saved, so you need a patched \douseMPbox

% \def\douseMPbox#1%
%   {\global\advance\MPobjectcounter\plusone
%    \setobject{MP}{\number\MPobjectcounter}\vbox
%      {\forgetall
%       \loadMPgraphic{\MPgraphicfile.\the\currentMPgraphic}{}%
%       \deallocateMPslot\currentMPgraphic
%       \placeMPgraphic}%
%    \setxvalue{#1}%
%      {\noexpand\dosetMPboxXY{\MPllx}{\MPlly}{\MPurx}{\MPury}%
%       \noexpand\getobject{MP}{\number\MPobjectcounter}}}
%
% \def\dosetMPboxXY#1#2#3#4%
%   {\xdef\MPllx{#1}\xdef\MPlly{#2}\xdef\MPurx{#3}\xdef\MPury{#4}}%
%
% less memory:

\def\douseMPbox#1%
  {\global\advance\MPobjectcounter\plusone
   \setobject{MP}{\number\MPobjectcounter}\vbox
     {\forgetall
      \loadMPgraphic{\MPgraphicfile.\the\currentMPgraphic}{}%
      \deallocateMPslot\currentMPgraphic
      \placeMPgraphic}%
   \setxvalue{#1}%
     
{\noexpand\dodouseMPbox{\number\MPobjectcounter}{\MPllx}{\MPlly}{\MPurx}{\MPury}}}

\def\dodouseMPbox#1#2#3#4#5% space delimiting would save some tokens
  {\xdef\MPllx{#2}%          but it's not worth the effort and looks
   \xdef\MPlly{#3}%          ugly as well
   \xdef\MPurx{#4}%
   \xdef\MPury{#5}%
   \getobject{MP}{#1}}

\starttext

\setupcolors[state=start]

\startreusableMPgraphic{axis}
  tickstep := 1cm ; ticklength := 2mm ;
  drawticks unitsquare xscaled 4cm yscaled 3cm shifted (-1cm,-1cm) ;
  tickstep := tickstep/2 ; ticklength := ticklength/2 ;
  drawticks unitsquare xscaled 4cm yscaled 3cm shifted (-1cm,-1cm) ;
\stopreusableMPgraphic

\startuseMPgraphic{one}
  drawpoint "1cm,1.5cm" ;
\stopuseMPgraphic

\definelayer[mp][preset=mp]
\setlayer[mp]{\reuseMPgraphic{axis}}
\setlayer[mp]{\useMPgraphic{one}}
\ruledhbox{\flushlayer[mp]}

\startuseMPgraphic{two}
  drawpoint "1.5cm,2.0cm" ;
\stopuseMPgraphic

\definelayer[mp][preset=mp]
\setlayer[mp]{\reuseMPgraphic{axis}}
\setlayer[mp]{\useMPgraphic{two}}
\ruledhbox{\flushlayer[mp]}

\definelayer[davan][preset=mp]
\setlayer[davan]{\reuseMPgraphic{axis}}
\setlayer[davan]{\useMPgraphic{one}}
\setlayer[davan]{\useMPgraphic{two}}
\setlayerframed[davan][x=0cm,y=0cm,location=middle,align=middle]{\blue 
Origin}
\setlayerframed[davan][x=1cm,y=1cm]{\red Interesting}
\ruledhbox{\flushlayer[davan]}

\stoptext

I leave it to you to figure out what happens here -)

(i'll move the patch to the core)

Hans

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-12-19  9:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-19  0:13 mfun-004.tex \startuseMPgraphic David Arnold
2005-12-19  9:52 ` Hans Hagen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).