\ProvidesPackage{analogclock} [2007/10/30 v1.0 analog clock accessory]

%
%  Luis Randez  randez@unizar.es
%  Juan I. Montijano  monti@unizar.es
%
% This program can be redistributed and/or modified under the terms
% of the GNU Public License, version 2.


\RequirePackage{hyperref}
\RequirePackage{xcolor}[2004/05/09]
\RequirePackage{xkeyval}
\RequirePackage{tikz}

\ifdefined\clock@interval\else\def\clock@interval{15}\fi
\DeclareOptionX{timeinterval}{\renewcommand{\clock@interval}{#1}}
\ProcessOptionsX

\newdimen\clock@fontsize
\def\clock@setfontcolor{\clock@temp{.}\let\clock@fontcolor=\clock@tempa}
%\def\clock@setbgcolor{\clock@temp{.}\let\clock@fontcolor=\clock@tempa}


\def\clock@temp#1{\def\clock@tempa##1,##2,##3\@nil{##1 ##2 ##3}%
\extractcolorspec{#1}\clock@tempb
   \expandafter\convertcolorspec\clock@tempb{rgb}\clock@tempb
   \edef\clock@tempa{\expandafter\clock@tempa\clock@tempb\@nil}}

%\clock@temp{black!10}\let\clock@bgcolor=\clock@tempa
\def\clock@bgcolor{black!30}


\def\kk{\mbox{\TextField[name=rolex0, width=2\clock@fontsize, height=2\clock@fontsize, align = 1, charsize =1.1\clock@fontsize, color =\clock@bgcolor, readonly=true, value={}]{}}}

%
\def\initclock{
\vbox to 0pt{
\begin{Form}
$$
\TextField[format=\startclock,name=resultado2, width=0truecm, height=0truecm, bordercolor= 1 1 1, backgroundcolor= 1 1 1,value={}]{}
$$
\end{Form}%
\TextField[name=rolex0, hidden=true, width=0pt, height=0pt,charsize=0pt]{}%
\TextField[name=rolex1, hidden=true, width=0pt, height=0pt,charsize=0pt]{}%
\TextField[name=rolex2, hidden=true, width=0pt, height=0pt,charsize=0pt]{}%
\TextField[name=rolex3, hidden=true, width=0pt, height=0pt,charsize=0pt]{}%
\TextField[name=rolex4, hidden=true, width=0pt, height=0pt,charsize=0pt]{}%
\TextField[name=rolex5, hidden=true, width=0pt, height=0pt,charsize=0pt]{}%
}\vskip -\baselineskip%
}
%
\newbox\sizebox
\newdimen\uu
%
\def\analogclock{\clock@setfontcolor\clock@setfontsize\clock@setfontnumber%
\uu=\f@size pt\raisebox{0.41\clock@fontsize}{\raisebox{-0.41\uu}{\mbox{%
\vrule width 0pt height 2pt%
\kern0.31\clock@fontsize\kern-0.31\uu%
\begin{tikzpicture}[scale=\clock@fontnumber]%
\useasboundingbox (-0.57 pt,-0.72 pt) rectangle (0.89 pt,1.05 pt);
%\clockskin
\faceframe%
\facebg%
\face%
\node at (0 pt,-0.0013 pt) {\colocafield{rolex1}};
\node at (0 pt,-0.0013 pt) {\colocafield{rolex2}};
\end{tikzpicture}%
\vrule width 0pt height 2pt%
}}}%
}%

\newcount\@face
\def\faceclock#1#2{%
\@face=#1\def\@col{#2}%
\ifx\@col\@empty\def\facebg{}\else\fi%
\ifnum\@face<0\def\faceframe{}\else\fi%
\ifnum\@face=4\def\face{}\else\fi%           Esfera sin simbolos
\ifnum\@face=-4\def\face{}\else\fi%           Esfera sin simbolos
\ifnum\@face=2\def\face@type{rolex3}\fi%  Esfera  con muchos simbolos
\ifnum\@face=-1\def\face@type{rolex3}\fi%  Esfera  con muchos simbolos
\ifnum\@face=2\def\face@type{rolex4}\fi%  Esfera  con puntos
\ifnum\@face=-2\def\face@type{rolex4}\fi%  Esfera  con puntos
\ifnum\@face=3\def\face@type{rolex5}\fi%  Esfera  con cuatro rayas
\ifnum\@face=-3\def\face@type{rolex5}\fi%  Esfera  con cuatro rayas
\def\clock@bgcolor{#2}%
}
%

\def\colocafield#1{%
\setbox\sizebox=\hbox{\mbox{\unskip\TextField[name=#1, width=2\clock@fontsize, height=2\clock@fontsize, align = 1, charsize =\clock@fontsize, color =\clock@fontcolor, readonly=true, value={}]{}}}%
\kern-\wd\sizebox\kern 2\clock@fontsize%
\box\sizebox%
}
%
\def\clock@setfontsize{\clock@fontsize=\f@size pt\clock@fontsize=\fac@font\clock@fontsize}
\def\fac@font{1.0}
\def\clocksizefactor#1{\def\fac@font{#1}}


\def\facebg{\fill[fill=\clock@bgcolor] (0,0) circle (0.75 pt);}
\def\faceframe{\draw[color=., thick] (0.00,0.00) circle (0.77 pt);}
\def\face{\node at (0 pt,-0.0013 pt) {\colocafield{\face@type}};\font\peque=cmr5 at 0.12\clock@fontsize \draw (0pt,-0.34 pt)  node {\peque M\&R};}
\def\face@type{rolex3}
\def\clockskin{%
\filldraw[rotate=22, fill=black!10!white] (0.2 pt,0.83 pt) arc (0:180:0.2 pt) -- cycle;
\filldraw[rotate=-22, fill=black!10!white] (0.2 pt,0.83 pt) arc (0:180:0.2 pt) -- cycle;
\draw[very thick] (0 pt, 0.75 pt) -- (0pt,0.92pt)  circle (0.05pt);
\draw[very thick] (-65:0.75 pt) -- (-65:0.90 pt);
\draw[very thick] (-115:0.75 pt) -- (-115:0.90 pt);
}
%\def\clockskin{}

\def\@p{p}
\def\extract@number#1{\edef\clock@tempb{#1 pp}\def\clock@tempa##1##2\@nil{\if##1\@p\else ##1\clock@tempa##2\@nil\fi}
\edef\clock@fontnumber{\expandafter\clock@tempa\clock@tempb\@nil}}
\def\clock@setfontnumber{\extract@number{\the\clock@fontsize}}



%
\def\startclock{%
%
fecha1 = reloj();
run = app.setInterval("reloj();",\clock@interval000);
%
%
function reloj()
{
%
var fObj     = new Date();
var horas    = fObj.getHours();
var minutos  = fObj.getMinutes(); minutos1 = minutos+0.0;
%
horaa=horas+0.0;
if (horaa >= 12) {horaa=horaa-12.0; };
%
%
%this.getField("rolex0").textColor=color.red;
this.getField("rolex0").strokeColor=color.transparent;
this.getField("rolex0").fillColor=color.transparent;
%this.getField("rolex1").textColor=color.red;
this.getField("rolex1").strokeColor=color.transparent;
this.getField("rolex1").fillColor=color.transparent;
%this.getField("rolex2").textColor=color.red;
this.getField("rolex2").strokeColor=color.transparent;
this.getField("rolex2").fillColor=color.transparent;
this.getField("rolex3").strokeColor=color.transparent;
this.getField("rolex3").fillColor=color.transparent;
this.getField("rolex4").strokeColor=color.transparent;
this.getField("rolex4").fillColor=color.transparent;
this.getField("rolex5").strokeColor=color.transparent;
this.getField("rolex5").fillColor=color.transparent;
this.getField("rolex0").textFont="clock";
this.getField("rolex1").textFont="clock";
this.getField("rolex2").textFont="clock";
this.getField("rolex3").textFont="clock";
this.getField("rolex4").textFont="clock";
this.getField("rolex5").textFont="clock";
var str = new String();
numero=Math.floor(192.0 + horaa*5.0 + minutos1/12.0);
str =  String.fromCharCode(48);
this.getField("rolex0").value=str;
str =  String.fromCharCode(numero);
this.getField("rolex1").value=str;
str =  String.fromCharCode(64+minutos1);
this.getField("rolex2").value=str;
str =  String.fromCharCode(49);
this.getField("rolex3").value=str;
str =  String.fromCharCode(50);
this.getField("rolex4").value=str;
str =  String.fromCharCode(51);
this.getField("rolex5").value=str;
}
%
}
% 