ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Hans Hagen <pragma@wxs.nl>
Subject: Re: mfun-004.tex \startuseMPgraphic
Date: Mon, 19 Dec 2005 10:52:01 +0100	[thread overview]
Message-ID: <43A682C1.1040802@wxs.nl> (raw)
In-Reply-To: <33BC85AD-C214-4820-B74E-7618631C9F96@cox.net>

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

      reply	other threads:[~2005-12-19  9:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-12-19  0:13 David Arnold
2005-12-19  9:52 ` Hans Hagen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=43A682C1.1040802@wxs.nl \
    --to=pragma@wxs.nl \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).