% ConTeXt file
% filename: test-thumb-pictures
% 18-03-2022


\startsetups[Thumb-pictures]
	\definecolor[chap_frame][black] %[g=1,t=1,a=12]
	\definecolor[textcolor][white] %[r=1,t=1,a=12]

	\startuseMPgraphic{chapter-thumb}
	  path chap_frame ;  
		pair pos,a,b ;  
		picture Chap ;

	  if  \somenamedheadnumber{chapter}{current} > 0 :
			curr_chap := \somenamedheadnumber{chapter}{current} ; 
	  else :
			curr_chap := 1 ;
	  fi;
	  if \somenamedheadnumber{chapter}{last} > 0 :
	   	last_chap := \somenamedheadnumber{chapter}{last} ;
	  else :
	  	last_chap := 1 ;
		  fi;
		  if \somenamedheadnumber{section}{current} > 0 : 
				curr_sect := \somenamedheadnumber{section}{current} ; 
		  else: 
	  		curr_sect := 1 ;
	  fi;
	  if \somenamedheadnumber{section}{last} > 0 :
	  	last_sect := \somenamedheadnumber{section}{last};
	  else:
		last_sect := 1;
	  fi;
		if curr_chap < 11  :
			skip := TextHeight * (curr_chap-1)/11 ;
		elseif curr_chap < 21  :
			skip := TextHeight * (curr_chap-11)/11 ;
		else:
			skip := TextHeight * (curr_chap-21)/11 ;
		fi;
 
	  Chap   := textext("\bfa\textcolor\getmarking[chapter]");

	  StartPage ;
	    chap_frame := lcircle xscaled (2*RightMarginWidth) yscaled (1.5*RightMarginWidth);

	    a := ulcorner chap_frame ;
	    b := urcorner chap_frame ;

	    pos := urcorner Field[Text][RightMarginSeparator] -
	           ulcorner chap_frame - (-1mm,skip);

	    fill chap_frame shifted pos withcolor \MPcolor{chap_frame};
	    draw Chap rotated 90 shifted (xpart pos-4mm,ypart pos) ;
	  StopPage ;
	\stopuseMPgraphic


	\defineoverlay[chapter-thumb][\useMPgraphic{chapter-thumb}]

	\setupbackgrounds[rightpage][background=chapter-thumb]
	\stopsetups



\showframe

\starttext

\startchapter[title=Test A]
	\samplefile{ward}
\stopchapter

\page[yes]
% \startchapter[title=Test B]
% 	\samplefile{ward}
% \stopchapter

\setups{Thumb-pictures}

\startchapter[title=Test C]
	\samplefile{ward}
\stopchapter
% 
\stoptext