From 652fddcc2fe810532f6c88b47758fc2ab8eae299 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Fri, 7 Aug 2015 21:44:47 +0000 Subject: roundrect (7aug15) git-svn-id: svn://tug.org/texlive/trunk@38070 c570f23f-e606-0410-a88d-b1316a301751 --- .../source/metapost/roundrect/roundrect.dtx | 116 +++++++++++++++++++-- 1 file changed, 107 insertions(+), 9 deletions(-) (limited to 'Master/texmf-dist/source/metapost') diff --git a/Master/texmf-dist/source/metapost/roundrect/roundrect.dtx b/Master/texmf-dist/source/metapost/roundrect/roundrect.dtx index 3ffe2344a13..b63914371c8 100644 --- a/Master/texmf-dist/source/metapost/roundrect/roundrect.dtx +++ b/Master/texmf-dist/source/metapost/roundrect/roundrect.dtx @@ -56,7 +56,7 @@ \end{document} % % \fi -% \title{The \texttt{roundrect} Macros, v2.0} +% \title{The \texttt{roundrect} Macros, v2.1} % \author{Donald P.\ Goodman III} % \date{\today} % @@ -116,7 +116,7 @@ % Here, we simply post the plain vanilla \MP\ code, and let % you work out those details however you prefer. % -% \section{Basic Usage} +% \section{Shapes and Styles} % % The core of all the action is the % \DescribeMacro{roundrect}|roundrect| macro; this @@ -214,11 +214,15 @@ % makes it much easier to combine multiple rectangles into % interesting forms, which we'll see a bit more about later. % -% Of course, the color of both the background and the border -% can be controlled with -% \DescribeMacro{rrinnercolor}|rrinnercolor| and -% \DescribeMacro{rrbordercolor}|rrbordercolor()|, -% respectively. +% \section{Coloring the Parts} +% \label{sect:colorpart} +% +% The colors of the |roundrect| are extremely configurable, +% both on the whole and for individual parts. The +% background color of the |roundrect| is controlled by +% \DescribeMacro{rrinnercolor}|rrinnercolor|, while the +% border is colored by +% \DescribeMacro{rrbordercolor}|rrbordercolor()|. % % \demonstrate{% % \hbox{|rrbordercolor(blue);|} @@ -368,6 +372,76 @@ % and drawn it with a square pen scaled on the y-axis only % by 6. Clearly, there are huge possibilities here. % +% \section{Drop Shadows} +% \label{sect:dropshadows} +% +% We can also put a \emph{shadow} on the boxes using +% \DescribeMacro{rrdropshadow}|rrdropshadow|, a boolean +% value which defaults to |false|: +% +% \demonstrate{% +% \hbox{|rrdropshadow := true;|} +% \hbox{|roundrect(1in,2in)(rectangle);|} +% \hbox{|draw rectangle;|} +% }{% +% \begin{mpost} +% rrdropshadow := true; +% roundrect(1in,2in)(rectangle); +% draw rectangle; +% \end{mpost} +% }% +% +% The drop shadow always mimics the shape of the box itself; +% there is presently no way to avoid that. If for some +% reason you want to, you'll have to create a separate +% |roundrect| and place it manually. +% +% We can control the size and direction of the drop shadow +% fairly easily, however, along with its color. Its color +% is controlled by +% \DescribeMacro{rrshadowcolor}|rrshadowcolor|, which +% can be set to any arbitrary \MP\ color: +% +% \demonstrate{% +% \hbox{|rrdropshadow := true;|} +% \hbox{|rrshadowcolor := blue;|} +% \hbox{|roundrect(1in,2in)(rectangle);|} +% \hbox{|draw rectangle;|} +% }{% +% \begin{mpost} +% rrdropshadow := true; +% rrshadowcolor := blue; +% roundrect(1in,2in)(rectangle); +% draw rectangle; +% \end{mpost} +% }% +% +% The position of the drop shadow is governed by +% \DescribeMacro{rrshadowx}|rrshadowx| and +% \DescribeMacro{rrshadowy}|rrshadowy|, which will shift the +% |roundrect| on the |x| or |y| axis, respectively. By +% default, these are set to one quarter of the border radius +% in effect for the bottom left corner: +% +% \demonstrate{% +% \hbox{|rrdropshadow := true;|} +% \hbox{|rrshadowcolor := blue;|} +% \hbox{|roundrect(1in,2in)(rectangle);|} +% \hbox{|draw rectangle;|} +% }{% +% \begin{mpost} +% rrdropshadow := true; +% rrshadowcolor := blue; +% rrshadowx := -rrbotlftborderrad/4; +% rrshadowy := rrbotlftborderrad/4; +% roundrect(1in,2in)(rectangle); +% draw rectangle shifted (1in,0.5in); +% \end{mpost} +% }% +% +% \section{Including Text} +% \label{sect:text} +% % Finally, we can put text in the rectangles; this is as % configurable as everything else: % @@ -433,7 +507,8 @@ % \end{mpost} % } % -% Finally, the restore all these values to the default, use +% +% Finally, to restore all these values to the default, use % the |rrrestorevals;| directive. This will clear % everything to default so you can have a completely % different |roundrect| in the same figure. @@ -448,6 +523,8 @@ numeric rrbotrtborderrad; rrbotrtborderrad := 40pt; numeric rrbotlftborderrad; rrbotlftborderrad := 40pt; numeric rrtoplftborderrad; rrtoplftborderrad := 40pt; numeric rrtextwd; rrtextwd := 0; +numeric rrshadowx; rrshadowx := rrbotrtborderrad/4; +numeric rrshadowy; rrshadowy := -rrbotrtborderrad/4; string rrtextfont; rrtextfont := "\fontsize{10pt}{12pt}\selectfont "; color rrtextcolor; rrtextcolor := black; string rrbodytext; rrbodytext := ""; @@ -456,10 +533,12 @@ boolean rrnotop; rrnotop := false; boolean rrnobot; rrnobot := false; boolean rrnolft; rrnolft := false; boolean rrnort; rrnort := false; +boolean rrdropshadow; rrdropshadow := false; color rrtopbordercolor; rrtopbordercolor := black; color rrbotbordercolor; rrbotbordercolor := black; color rrlftbordercolor; rrlftbordercolor := black; color rrrtbordercolor; rrrtbordercolor := black; +color rrshadowcolor; rrshadowcolor := black; def rrbordercolor(expr x) = rrtopbordercolor := x; rrbotbordercolor := x; @@ -496,6 +575,10 @@ def rrrestorevals = rrtextcolor := black; rrbodytext := ""; rrtextalign; rrtextalign := "\centering"; + rrdropshadow := false; + rrshadowcolor := black; + rrshadowx := rrbotrtborderrad/4; + rrshadowy := -rrbotrtborderrad/4; enddef; def roundrect(expr rrht, rrwd)(suffix name) = TEXPRE("%&latex" & char(10) & "\documentclass{article}\begin{document}"); @@ -541,9 +624,24 @@ def roundrect(expr rrht, rrwd)(suffix name) = rrbotborder := rrbotrtcorner--rrbotlftcorner; rrlftborder := rrbotlftcorner--rrtoplftcorner; rrrtborder := rrtoprtcorner--rrbotrtcorner; - name := image(fill rrtoplftcorner--rrtoprtcorner-- + picture rrdropshadowpic; + if (rrdropshadow = true): + rrdropshadowpic := image(fill rrtoplftcorner--rrtoprtcorner-- + rrbotrtcorner--rrbotlftcorner--cycle + shifted (rrshadowx,rrshadowy) withcolor + rrshadowcolor); + else: + rrdropshadowpic := currentpicture; + fi + name := currentpicture; + addto name also rrdropshadowpic; + rrdropshadowpic := image(fill rrtoplftcorner--rrtoprtcorner-- rrbotrtcorner--rrbotlftcorner--cycle withcolor rrinnercolor); + addto name also rrdropshadowpic; +% name := image(fill rrtoplftcorner--rrtoprtcorner-- +% rrbotrtcorner--rrbotlftcorner--cycle withcolor +% rrinnercolor); picture rrtmpborder; border := currentpicture; if (rrnotop = false): -- cgit v1.2.3