-------- Forwarded Message --------
Subject: Re: [NTG-context] Touch my cow: Overlaying a picture with links to text
Date: Fri, 10 Jan 2025 01:09:47 +0100
From: Hans Hagen <j.ha...@xs4all.nl>
To: Axel Kielhorn <t...@axelkielhorn.de>

On 1/9/2025 8:29 PM, Axel Kielhorn wrote:
Hello,

I’m trying to make our documentation more interactive.

So far I managed to turn the labels in the picture into links.

The next step would be to mark certain areas in the picture.
When the reader clicks on these areas, they will follow the link.

This is where I am so far:

% !TEX TS-program = ConTeXt (LMTX)

\setupinteraction[state=start, color=middleblue]
\placebookmarks[section]

\setupexternalfigures[location=default]
\starttext

\startMPinclusions

color mycolor;

def gridscaled =
   pair ur;
   ur = urcorner currentpicture;
   width :=  xpart ur;
   height := ypart ur;
   xstep := ceiling(width / 10);
   ystep := ceiling(height / 10);
enddef;
% Bottom: The annotation is at the bottom of the start point
def annotb (expr a,  b, c, d) (text t) =
label.bot 
("\framed[background=color,backgroundcolor=transparentwhite,align=normal,corner=00,frame=no]{" 
& t &"}", (a * xstep,  b * ystep));
        drawarrow (a * xstep, b * ystep) -- ( c * xstep, d * ystep)
                withpen pencircle scaled .8mm withcolor white;
        drawarrow (a * xstep, b * ystep) -- ( c * xstep, d * ystep)
                withpen pencircle scaled .5mm withcolor mycolor;
enddef ;
% Top: The annotation is on top of the start point
def annott (expr a,  b, c, d) (text t) =
label.top 
("\framed[background=color,backgroundcolor=transparentwhite,align=normal,corner=00,frame=no]{" 
& t &"}", (a * xstep,  b * ystep));
        drawarrow (a * xstep, b * ystep) -- ( c * xstep, d * ystep)
                withpen pencircle scaled .8mm withcolor white;
        drawarrow (a * xstep, b * ystep) -- ( c * xstep, d * ystep)
                withpen pencircle scaled .5mm withcolor mycolor;
enddef ;
% Right: The annotation is on the right of the start point
def annotr (expr a,  b, c, d) (text t) =
label.rt (t, (a * xstep,  b * ystep));
        drawarrow (a * xstep, b * ystep) -- ( c * xstep, d * ystep)
                withpen pencircle scaled .8mm withcolor white;
        drawarrow (a * xstep, b * ystep) -- ( c * xstep, d * ystep)
                withpen pencircle scaled .5mm withcolor mycolor;
enddef ;
% Left: The annotation is on the left of the start point
def annotl (expr a,  b, c, d) (text t) =
label.lft (t, (a * xstep,  b * ystep));
        drawarrow (a * xstep, b * ystep) -- ( c * xstep, d * ystep)
                withpen pencircle scaled .8mm withcolor white;
        drawarrow (a * xstep, b * ystep) -- ( c * xstep, d * ystep)
                withpen pencircle scaled .5mm withcolor mycolor;
enddef ;
% touchtolink
def touchtolink (expr a,  b) (text t) =
label 
("\framed[background=color,backgroundcolor=transparentwhite,align=normal,corner=00,frame=no]{" 
& t &"}", (a * xstep,  b * ystep));
enddef ;
\stopMPinclusions

\startMPpage
% Picture
draw externalfigure "cow.pdf" xsized 16cm;
% Grid
gridscaled;
% Text
annotb (1, 5, .8, 7.3, "\goto{Maul}[Maul]");
touchtolink (.8, 7.3, "\goto{\blackrule[height=2cm, width=4cm, 
color=transparentwhite]}[Maul]");
annotb (6, 2, 7, 3.2, "\goto{Euter}[Euter]");
annott (9.2, 9.5, 9.6, 3, "Schwanz");
annotb (3, -.5, 3.1, .9, "\goto{Huf}[Huf]");
annotb (3, -.5, 3.9, 1.1, "");

\stopMPpage


\startsection[
     title={Das Maul},
     reference=Maul,
     bookmark={Maul},
     ]
     Lorem ipsum dolor
   \stopsection

\startsection[
     title={Die Hufe},
     reference=Huf,
     bookmark={Huf},
     ]
     Lorem ipsum dolor
\stopsection

\startsection[
     title={Das Euter},
     reference=Euter,
     bookmark={Euter},
     ]
     Lorem ipsum dolor
\stopsection

\stoptext
%%%%

I filled the area with a \blackrule, which is transparent and the link works.
Only problem the frame is filled with the link color, in this case blue.

How do I suppress the color for this link only?
Adding [color=transparentwhite] to the \goto command didn’t help.

Is there a more elegant way to define this area?

def touchtolink (expr a,  b) (text t) =
label ("\framed[background=color,backgroundcolor=transparentwhite,align=normal,corner=00,frame=no]{" & t &"}", (a * xstep, b * ystep));
enddef ;

but you forgot to define:

\definecolor[transparentwhite][s=1,t=.5,a=1]


Greetings from the snowy pastures of northern Germany
Axel

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________


--

-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
       tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

Reply via email to