%%
%% This is file `sidebarbidipres.sty'
%% 
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{sidebarpres}%
[2010/07/21 Style with sidebar for using with bidipresentation class]
\usepackage[RL]{flowfram}
\usepackage{eso-pic}
\usepackage{graphicx}
\usepackage{tikz}\usetikzlibrary{shapes, snakes}
\usepackage{lastpage}
\paperwidth=128mm
\paperheight=96mm
\def\lmargin{0.04\paperwidth}
\def\bmargin{0.1\paperheight}
\def\rmargin{0.2\paperwidth}
\def\tmargin{0.05\paperheight}
\geometry{paperwidth=\paperwidth, paperheight=\paperheight, rmargin=\rmargin, lmargin=\lmargin, top=\tmargin, bottom=\bmargin, foot=\bmargin, head=0pt,}

\usepackage{bidi-atbegshi}
\usepackage{bidishadowtext}
\usepackage{titlesec}
\usepackage{titletoc}

\flowframesep=0pt
%\flowframerule=0.5pt

\def\bgtopc#1{\colorlet{bg-top}{#1}}
\def\bgbotc#1{\colorlet{bg-bot}{#1}}
%% قاب اصلی
\newdynamicframe*{0.83\paperwidth}{0.95\paperheight}{-\lmargin}{\dimexpr(-\bmargin+0.05\paperheight)}[main]
\setdynamicframe*{main}{valign=t, border=none}

\setdynamiccontents*{main}{
\AddToShipoutPicture{
\put(-\LengthToUnit{\dimexpr(\paperwidth-0.17\paperwidth)}, \LengthToUnit{0.05\paperheight})
{\begin{tikzpicture}
\shade[top color=bg-top, bottom color=bg-bot] (0,0) rectangle (0.83\paperwidth, 0.95\paperheight);
\end{tikzpicture}}
}}


\renewcommand{\sectionmark}[1]{\markright{#1}{}}

%% تغییر فهرست مطالب

%% نوار کنار
\def\sidebartopc#1{\colorlet{sidebar-top}{#1}}
\def\sidebarbotc#1{\colorlet{sidebar-bot}{#1}}

\newdynamicframe*{0.17\paperwidth}{0.95\paperheight}{\dimexpr(\paperwidth-0.17\paperwidth-\lmargin)}{\dimexpr(-\bmargin+0.05\paperheight)}[sidebar]
\setdynamicframe*{sidebar}{valign=t}

\AtBeginDocument{\begin{dynamiccontents*}{sidebar}
\AddToShipoutPicture{
\put(-\LengthToUnit{\dimexpr(\paperwidth)}, \LengthToUnit{0.05\paperheight})
{\begin{tikzpicture}
\shade[top color=sidebar-top, bottom color=sidebar-bot] (0,0) rectangle (0.17\paperwidth, 0.95\paperheight);
\end{tikzpicture}}
}
\begin{center}
\includegraphics[width=0.15\paperwidth]\instlogo\\
\scriptsize{\institute}\\
\scriptsize{\faculty}
\\[0.05\paperwidth]
\bfseries\footnotesize{\rightmark}
%\@starttoc{toc}
\end{center}
\end{dynamiccontents*}}

%% نوار پایین
%\def\lbotbarc#1#2{\definecolor{lbotbar-color}{#1}{#2}}
\def\lbotbarc#1{\colorlet{lbotbar-color}{#1}}
\def\lbotbartc#1{\colorlet{lbotbar-text}{#1}}
\def\mbotbarc#1{\colorlet{mbotbar-color}{#1}}
\def\mbotbartc#1{\colorlet{mbotbar-text}{#1}}
\def\rbotbarc#1{\colorlet{rbotbar-color}{#1}}
\def\rbotbartc#1{\colorlet{rbotbar-text}{#1}}

\newdynamicframe*{0.17\paperwidth}{0.05\paperheight}{-\lmargin}{-\bmargin}[lbotbar]
\newdynamicframe*{0.66\paperwidth}{0.05\paperheight}{\dimexpr(0.17\paperwidth-\lmargin)}{-\bmargin}[mbotbar]
\newdynamicframe*{0.17\paperwidth}{0.05\paperheight}{\dimexpr(0.83\paperwidth-\lmargin)}{-\bmargin}[rbotbar]
\setdynamicframe*{lbotbar}{valign=c, backcolor=lbotbar-color, textcolor=lbotbar-text}
\setdynamicframe*{mbotbar}{valign=c, backcolor=mbotbar-color, textcolor=mbotbar-text}
\setdynamicframe*{rbotbar}{valign=c, backcolor=rbotbar-color, textcolor=rbotbar-text}

\setdynamiccontents*{mbotbar}{\begin{center}\scriptsize{\@title}\end{center}}

\setdynamiccontents*{rbotbar}{\begin{center}\footnotesize{\@date}\end{center}}

\begin{dynamiccontents*}{lbotbar}
\begin{center}
\footnotesize{\pageref{LastPage}\slash\thepage}
\end{center}
\end{dynamiccontents*}

%% تغییر نماد itemize
\def\labelitemi{
\begin{tikzpicture}[rounded corners, ultra thick]
\shade[ball color=blue] (0,0) circle (500ex);
\end{tikzpicture}}

%% تعریف الگو
\tikzstyle{titlebox}=[draw=black, very thick, inner color=blue!30!black, outer color=blue!80!red, rectangle, rounded corners, inner sep=10pt, inner ysep=10pt, preaction={fill=blue!30!black, opacity=.5, transform canvas={xshift=-1.5mm, yshift=-1.5mm}}, white]

\tikzstyle{boxstyle} = [fill=none, very thick, rectangle, rounded corners, inner sep=10pt, inner ysep=15pt]

\newenvironment{boxtemp}[4][\empty]{%
\tikzstyle{titlestyle} =[fill=#2, text=#3, rounded corners]
\def\boxtitle{\ifx\empty#1#4\else{#4~(#1)}\fi}
\begin{tikzpicture}
\node [boxstyle, draw=#3] (box)\bgroup%
\setRTL\begin{minipage}{0.9\textwidth}
}
{\end{minipage}
\egroup;
\node[titlestyle, left=10pt] at (box.north east) {\hboxR{\large{\boxtitle}}};
\end{tikzpicture}}

\renewenvironment{plainslide}[1][]%
   {{\raggedleft \large\bfseries
\bidishadowoffset{1.5pt}
\bidishadowcolor{blue!40!black}
\bidishadowtext{%
   \textcolor{white}{#1}
}%
\par}\par\vspace*{\stretch{1}}}%
{\par\vspace*{\stretch{1}}\newpage}