Code:
%
% ProgressBar
% by Marcel Jira
% kindly supported by mrunix-forum: http://www.mrunix.de/
%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{progressbar}[2010/09/06 v0.1: progressbar]
\newcommand{\progressbarpackagename}{progressbar}
\newcommand{\progressbar@PackageWarning}[1]{\PackageWarning{\progressbarpackagename}{#1}}
\newcommand{\progressbar@LoadFile@IfExist}[1]{%
\IfFileExists{#1.sty}{%
\RequirePackage{#1}%
}{%
\progressbar@PackageWarning{The package #1 does not exist\MessageBreak
but it is required by \progressbarname}%
}
}
\progressbar@LoadFile@IfExist{fp}
\progressbar@LoadFile@IfExist{tikz}
\progressbar@LoadFile@IfExist{kvoptions}
\progressbar@LoadFile@IfExist{kvsetkeys}
% Define lengths for later use
\newlength{\BarWidth}
\newlength{\BarHeight}
\newlength{\BarRoundedCorners}
% This length will be used for the realisation of the progressbars
\newlength{\BarPartWidth}
%
% All user-variables
\def\progressbar@keylist{heighta,roundnessa,heightr,roundnessr,width,linecolor,emptycolor,filledcolor,borderwidth,tickswidth,ticksheight,tickscolor,subdivisions}
% Keys corresponding to the user-variables
\def\progressbar@defaultvaluelist{,,0.75,0.15,6em,black,black!10,black!60,0.8pt,0.4pt,0.33,black,10}
\newcounter{progressbar@counter}
% KeyVal-Options
% Define default-Keyval-Options for this package
\setcounter{progressbar@counter}{0}
\@for\progressbar@value:=\progressbar@defaultvaluelist\do{%
\stepcounter{progressbar@counter}%
\expandafter\edef\csname progressbar@value\the\value{progressbar@counter}\endcsname{\progressbar@value}%
}%
\setcounter{progressbar@counter}{0}
\@for\progressbar@key:=\progressbar@keylist\do{%
\stepcounter{progressbar@counter}%
\expandafter\DeclareStringOption\expandafter[\csname progressbar@value\the\value{progressbar@counter}\endcsname]{\progressbar@key}%
}
\ProcessKeyvalOptions*
% Change Keyval family and prefix
\SetupKeyvalOptions{family=progressbarlocal,prefix=progressbarlocal@}
% Define Keyval-Options that are used in the macro
\@for\progressbar@key:=\progressbar@keylist\do{%
\DeclareStringOption{\progressbar@key}%
}
\def\progressbar@lastheighta{false}
\def\progressbar@lastroundnessa{false}
\def\progressbar@true{true}
\AddToKeyvalOption{progressbar}{heightr}{%
\def\progressbar@lastheighta{false}%
}
\AddToKeyvalOption{progressbar}{heighta}{%
\def\progressbar@lastheighta{true}%
}
\AddToKeyvalOption{progressbar}{roundnessr}{%
\def\progressbar@lastroundnessa{false}%
}
\AddToKeyvalOption{progressbar}{roundnessa}{%
\def\progressbar@lastroundnessa{true}%
}
\AddToKeyvalOption{progressbarlocal}{heightr}{%
\FPmul{\BarHeightNU}{\progressbarlocal@heightr}{\f@size}%
\kvsetkeys{progressbarlocal}{heighta=\BarHeightNU pt}%
}
\AddToKeyvalOption{progressbarlocal}{roundnessr}{%
\FPmul{\BarRoundedCornersNU}{\progressbarlocal@roundnessr}{\BarHeightNU}%
\kvsetkeys{progressbarlocal}{roundnessa=\BarRoundedCornersNU pt}%
}
% Macor to change Options
\newcommand{\progressbarchange}[1]{%
\kvsetkeys{progressbar}{#1}%
}
%
% The actual realisation of the progressbar
\newcommand{\progressbar}[2][]{%
% Get the global keys in the local keys
\@for\progressbar@key:=\progressbar@keylist\do{%
\@expandtwoargs\kvsetkeys{progressbarlocal}{\progressbar@key=\csname progressbar@\progressbar@key\endcsname}%
}%
\ifx\progressbar@lastheighta\progressbar@true%
\kvsetkeys{progressbarlocal}{heighta=\progressbar@heighta}%
\else%
\kvsetkeys{progressbarlocal}{heightr=\progressbar@heightr}%
\fi%
\ifx\progressbar@lastroundnessa\progressbar@true%
\kvsetkeys{progressbarlocal}{roundnessa=\progressbar@roundnessa}%
\else%
\kvsetkeys{progressbarlocal}{roundnessr=\progressbar@roundnessr}%
\fi%
%Now get the optional user input keys
\kvsetkeys{progressbarlocal}{#1}%
% Convert KeyVal-Options to lengths
\setlength{\BarHeight}{\progressbarlocal@heighta}%
\setlength{\BarWidth}{\progressbarlocal@width}%
\setlength{\BarRoundedCorners}{\progressbarlocal@roundnessa}%
% Will be important later for calculations
\def\BarHeightNU{\strip@pt\BarHeight}%
\def\BarWidthNU{\strip@pt \BarWidth}%
% BarSubDivision
\FPdiv{\BarSubDivisionsWidthANU}{\BarWidthNU}{\progressbarlocal@subdivisions}%
\FPmul{\BarSubDivisionsWidthBNU}{\BarSubDivisionsWidthANU}{2}%
\FPsub{\BarSubDivisionsWidthCNU}{\BarWidthNU}{\BarSubDivisionsWidthANU}%
% The filled part of the bar is calculated and set
\FPmul{\BarPartWidthNU}{#2}{\BarWidthNU}%
\setlength{\BarPartWidth}{\BarPartWidthNU pt}%
%
\begin{tikzpicture}%
\coordinate (Begin) at (0,0);%
\coordinate (End) at (\BarWidth,\BarHeight);%
\coordinate (Part) at (\BarPartWidth,\BarHeight);%
% Rounded Corners
\draw[rounded corners=\BarRoundedCorners,line width=\progressbarlocal@borderwidth,color=\progressbarlocal@linecolor] (Begin) rectangle (End);%
\clip[rounded corners=\BarRoundedCorners] (Begin) rectangle (End);%
% Fill the bar
\fill[fill=\progressbarlocal@emptycolor] (Begin) rectangle (End);%
% the full part
\fill[fill=\progressbarlocal@filledcolor] (Begin) rectangle (Part);%
% Ticks
\foreach \x in {\BarSubDivisionsWidthANU,\BarSubDivisionsWidthBNU,...,\BarSubDivisionsWidthCNU}%
\draw[draw=\progressbarlocal@tickscolor,line width=\progressbarlocal@tickswidth] (\x pt,0) -- (\x pt,\BarHeight*\progressbar@ticksheight);%
% Rounded Corners again
\draw[rounded corners=\BarRoundedCorners,line width=\progressbarlocal@borderwidth,color=\progressbarlocal@linecolor] (Begin) rectangle (End);%
\end{tikzpicture}%
}
Lesezeichen