Speech bubble

From Wiki
Revision as of 16:28, 10 September 2012 by Esteisbot (talk | contribs) (moved speech bubble to Speech bubble: move to Uppercase)
Jump to navigation Jump to search

In ConTeXt it is possible to use the Tikz module to create « speech bubbles ». Here are two ways of doing this: the first one works under mkii and mkiv, while the second one needs the Annotation module written by Wofgang Schuster who wrapped the Tikz commands in ConTeXt macros in the code below.


\usemodule[tikz]
\usetikzlibrary[shapes.callouts]

\setupbodyfont[bookman]

\setupTEXpage[offset=1em]

\starttext

\startTEXpage
\starttikzpicture[remember picture]
  \node[ellipse callout, draw] (node:ref) {Hi there!};
\stoptikzpicture
\stopTEXpage

\startTEXpage
\starttikzpicture[remember picture]
  \node[cloud callout, draw] (node:ref) {Hallo!};
\stoptikzpicture
\stopTEXpage

\startTEXpage
\starttikzpicture
  \node[cloud callout, cloud puffs=15, aspect=2.5, cloud puff arc=120,
    shading=ball,text=white] {\bf Imagine\dots};
\stoptikzpicture
\stopTEXpage

\startTEXpage
\starttikzpicture[remember picture, note/.style={rectangle callout, fill=#1}]
  \draw [help lines] grid(3,2);
  \node [note=red!50, callout relative pointer={(0,1)}] at (3,1) {Relative position};
  \node [note=blue!50, callout absolute pointer={(0,1)}] at (1,0) {Absolute position};
  \node [note=green!50, ellipse callout, opacity=.5, overlay, callout absolute pointer={(hallo.south)}] at (1,2) {Outside};
\stoptikzpicture
\stopTEXpage

\stoptext

In the above example, you can leave out the \startTEXpage and \stopTEXpage, and use the pictures and you wish in your text.

The second example is as follows:


\usemodule[tikz,annotation]
\usetikzlibrary[shapes.callouts]

\define[2]\SpeechbubbleCommand
 {\starttikzpicture[remember picture]
  \node[rectangle callout, draw] (node:ref) {\framedtext[width=fit,frame=off]{#2}};
  \stoptikzpicture}

\defineannotation
 [speechbubble]
 [alternative=command,
      command=\SpeechbubbleCommand]

\starttext

\speechbubble{Hello!}

\startspeechbubble
\input ward
\stopspeechbubble

\stoptext

As said before the above code needs mkiv functionalities (due to the usage of the Annotation module). Indeed you can change some of Tikz commands in the above defintions, for instance change the command

\node[rectangle callout, draw]

into

\node[cloud callout, draw]

to get other bubble shapes.