Code-source_du_jours Lecture_gradian 12.01.2008 (c) db

procedure Lecture_gradian_perso(amenu_degrader_selon:hmenu);
	const kpc_counter = 'Counter';
			kid_Gradian_personnaliser = 777;
	var i,j,k,counter,nb_couleur:integer;
		 pc_rubrique,pc_counter,pc_indice,pc_indice_tiret:pc20;
		 apc:pc50;
		 p,q,pc_red,pc_green,pc_blue,pc_position:pchar;
		 rouge,vert,bleu,position:integer;
		 aforme:pforme_dessin;
		 adc,memdc:hdc;
		 ajouter_ce_bitmap,old_bitmap:hbitmap;
		 local_bool_deja_ajouter,
			local_bool_todo:boolean;
	begin
	local_bool_deja_ajouter:=false;
	{lecture du nom de la rubrique gradian}
	loadstring(hinstance,WMenuK.code_gradian,pc_rubrique,pred(sizeof(pc_rubrique)));
	{$ifdef debug} box(0,pc_rubrique); {$endif debug}
	adc:=getdc(0);
	memdc:=Createcompatibledc(adc);
	counter:=getprivateprofileint(pc_rubrique,kpc_counter,0,vincent_ini);
	{si la liste des forme gradians n'est pas initialiser le faire, si elle était connue, la vider}
	if list_forme_gradian<>nil then
		dispose(list_forme_gradian,done);
	new(list_forme_gradian,init(counter,10));
	{initialiser une forme de dessin}
	aforme:=get_forme_dessin_rectangle_128x18;
	aforme^.calcul;
	{pour chaque gradian: counter le nombre de gradian dans l'ini}
	k:=1;
	for i:=1 to counter do
		begin
		if aforme^.col_degrader<>nil then begin aforme^.col_degrader^.Freeall; aforme^.col_degrader:=nil; end;

		inttopchar(i,pc_indice);
		nb_couleur:=getprivateprofileint(pc_rubrique,pc_indice,0,vincent_ini);
		{$ifdef debug} inttopchar(nb_couleur,apc); box(0,apc); {$endif debug}
		new(aforme^.col_degrader,init(succ(nb_couleur),5));
		local_bool_todo:=false;
		for j:=0 to pred(nb_couleur) do
			begin
			inttopchar(i,pc_indice_tiret);
			strcat(pc_indice_tiret,wutil.kpc_minus);
			inttopchar(j,apc);
			strcat(pc_indice_tiret,apc);
			if getprivateprofilestring(pc_rubrique,pc_indice_tiret,nil,apc,pred(sizeof(apc)),vincent_ini)<>0 then
				begin {getprivate}
				{$ifdef debug} box(0,apc); {$endif debug}
				pc_red:=nil; pc_green:=nil; pc_blue:=nil; pc_position:=nil;
				{extraire les composants Rouge,Vert,Bleu,position}
				p:=strpos(apc,wutil.kpc_equal);
				if p<>nil then
					begin
					inc(p);
					{$ifdef debug} box(0,p); {$endif debug}
					q:=strpos(p,wutil.kpc_comma);
					if q<>nil then
						begin
						q^:=#0;
						pc_red:=p;
						{$ifdef debug} box(0,pc_red); {$endif debug}
						inc(q);
						p:=strpos(q,wutil.kpc_comma);
						if p<>nil then
							begin
							p^:=#0;
							pc_green:=q;
							{$ifdef debug} box(0,pc_green); {$endif debug}
							inc(p);
							q:=strpos(p,wutil.kpc_equal);
							if q<>nil then
								begin
								q^:=#0;
								pc_blue:=p;
								{$ifdef debug} box(0,pc_blue); {$endif debug}
								inc(q);
								pc_position:=q;
								{$ifdef debug} box(0,pc_position); {$endif debug}
								end;
							end;
						end;
					end;
				if (pc_red<>nil) and (pc_green<>nil) and (pc_blue<>nil) and (pc_position<>nil) then
					begin {compossant trouvé}
					rouge:=wutil.PChartolongint(pc_red);
					vert:=wutil.PChartolongint(pc_green);
					bleu:=wutil.PChartolongint(pc_blue);
					position:=wutil.PChartolongint(pc_position);
					{ajouter cette index couleur}
					aforme^.col_degrader^.insert(new(u_object.P_index_color,init(position,RGB(rouge,vert,bleu))));
					local_bool_todo:=true;
					end;  {compossant trouvé}
				end; {getprivate}
			end; {for j}
		if local_bool_todo then
			begin {todo}
			ajouter_ce_bitmap:=CreateCompatiblebitmap(adc,128,18);
			old_bitmap:=Selectobject(memdc,ajouter_ce_bitmap);
			aforme^.paint(memdc,g_base.grand_plan);
			list_forme_gradian^.insert(aforme^.clone);
			Selectobject(memdc,old_bitmap);
			{ajouter le bitmap au menu popup}
			if not local_bool_deja_ajouter then
				begin
				appendmenu(amenu_degrader_selon,MF_MENUBARBREAK,0,nil);
				loadstring(hinstance,kid_Gradian_personnaliser,apc,pred(sizeof(apc)));
				appendmenu(amenu_degrader_selon,MF_String,wmenuk.cm_degrader,apc);
				local_bool_deja_ajouter:=True;
				end;
			appendmenu(amenu_degrader_selon,MF_BITMAP,wmenuk.cm_degrader_selon_futur_ecologiste+k,pchar(ajouter_ce_bitmap));
			{seulement si todo}
				inc(k);
			end; {todo}
		end; {for i}
	dispose(aforme,done);
	Deletedc(memdc);
	Releasedc(0,adc);
	end; {lecture_gradian_perso}