summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/progressbar/progressbar.sty
blob: 70e0f522d55456216bcfc050f612c7a04f7d3439 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
% ProgressBar
%
% kindly supported by mrunix-forum: http://www.mrunix.de/
%
%% progressbar.sty
%% Copyright 2010-2013 Marcel Jira
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3c
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
% 
% The Current Maintainer of this work is Marcel Jira.
%
% This work consists of the files progressbar.sty and progressbar.tex.
%
\NeedsTeXFormat{LaTeX2e}%
%
\ProvidesPackage{progressbar}[2014/05/04 v1.0b~4: progressbar]%
%
\RequirePackage{calc}%
\RequirePackage{tikz}%
\RequirePackage{kvoptions}[2011/06/30]%
\RequirePackage{kvsetkeys}%
%
% Define lengths for later use
\newlength{\BarWidth}%
\newlength{\BarWidthCenter}%
\newlength{\BarHeight}%
\newlength{\BarHeightCenter}%
\newlength{\BarBorderWidth}%
\newlength{\BarRoundedCorners}%
% This length will be used for the realisation of the progressbars
\newlength{\BarPartWidth}%
% And the ticks
\newlength{\BarSubDivisionsWidthANU}%
\newlength{\BarSubDivisionsWidthBNU}%
\newlength{\BarSubDivisionsWidthCNU}%
%
% All user-variables
\def\progressbar@keylist{borderwidth,heighta,roundnessa,heightr,roundnessr,width,linecolor,emptycolor,filledcolor,tickswidth,ticksheight,tickscolor,subdivisions}%
% Keys corresponding to the user-variables
\def\progressbar@defaultvaluelist{0.8pt,0pt,0pt,1,0.15,6em,black,black!10,black!60,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\progressbarlocal@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}%
}%
\newcommand{\setBarHeightCenter}{\setlength{\BarHeightCenter}{\BarHeight - \BarBorderWidth}}%
\newcommand{\setBarWidthCenter}{\setlength{\BarWidthCenter}{\BarWidth - \BarBorderWidth}}%
\AddToKeyvalOption{progressbarlocal}{heightr}{%
	\setlength{\BarHeight}{\heightof{I} * \real{\progressbarlocal@heightr}}%
	\kvsetkeys{progressbarlocal}{heighta=\BarHeight}%
}%
\AddToKeyvalOption{progressbarlocal}{roundnessr}{%
	\def\progressbarlocal@lastroundnessa{false}%
}%
\AddToKeyvalOption{progressbarlocal}{heighta}{%
	\setlength{\BarHeight}{\progressbarlocal@heighta}%
	\setBarHeightCenter%
}%
\AddToKeyvalOption{progressbarlocal}{width}{%
	\setlength{\BarWidth}{\progressbarlocal@width}%
	\setBarWidthCenter%
}%
\AddToKeyvalOption{progressbarlocal}{roundnessa}{%
	\def\progressbarlocal@lastroundnessa{true}%
	\setlength{\BarRoundedCorners}{\progressbarlocal@roundnessa}%
}%
\AddToKeyvalOption{progressbarlocal}{borderwidth}{%
	\setlength{\BarBorderWidth}{\progressbarlocal@borderwidth}%
	\setBarHeightCenter%
	\setBarWidthCenter%
}%
% 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}%
	% Make a correct roundndess, if roundnessr was defined
	\ifx\progressbarlocal@lastroundnessa\progressbar@true%
	\else%
		\setlength{\BarRoundedCorners}{\BarHeightCenter * \real{\progressbarlocal@roundnessr}}%
	\fi%
	% BarSubDivision
	\setlength{\BarSubDivisionsWidthANU}{\BarWidthCenter / \progressbarlocal@subdivisions}%
	\setlength{\BarSubDivisionsWidthBNU}{\BarSubDivisionsWidthANU * 2}%
	\setlength{\BarSubDivisionsWidthCNU}{\BarWidthCenter - \BarSubDivisionsWidthANU}%
	% The filled part of the bar is calculated and set
	\setlength{\BarPartWidth}{\BarWidthCenter * \real{#2}}%
	% Now let's draw a bar ;)
	\begin{tikzpicture}%
		\coordinate (Begin) at (0,0);%
		\coordinate (End) at (\BarWidthCenter,\BarHeightCenter);%
		\coordinate (Part) at (\BarPartWidth,\BarHeightCenter);%
		% Rounded Corners
		\draw[rounded corners=\BarRoundedCorners,line width=\BarBorderWidth,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 {\strip@pt\BarSubDivisionsWidthANU,\strip@pt\BarSubDivisionsWidthBNU,...,\strip@pt\BarSubDivisionsWidthCNU}%
		\draw[draw=\progressbarlocal@tickscolor,line width=\progressbarlocal@tickswidth] (\x pt,0) -- (\x pt,\BarHeightCenter*\progressbarlocal@ticksheight);%
		% Rounded Corners again
		\draw[rounded corners=\BarRoundedCorners,line width=\BarBorderWidth,color=\progressbarlocal@linecolor] (Begin) rectangle (End);%
	\end{tikzpicture}%
}%