Delphi & Pascal (česká wiki)
Přejít na: navigace, hledání
/*****************************************************************************
*								             *
*                             Subor HELP.C                                   *
*									     *
*****************************************************************************/
 
#include <stdlib.h>
 
#include "glob.h"
#include "key.h"
#include "menu.h"
#include "video.h"
#include "okno.h"
 
//************************************************************************//
// HELP                                                                   //
//                                                            30.10.1997  //
//************************************************************************//
 
void help(char *help)
{
 register int i,j;
 char ret1[]={' ',24,' ',' ','\0'};
 char ret2[]={' ',24,25,' ','\0'};
 char ret3[]={' ',' ',25,' ','\0'};
 char *p;
 int rx,ry;
 int zx,zy;
 int koniec=0;
 int zaciatok=0;
 int pocet_riadkov=0;
 int max;
 
 if(help==NULL)
	return;
 p=help;
 rx=0;
 while(1)
	{
	max=0;
	while(*p!='\n' && *p!='\0')
		{
		p++;
		max++;
		}
	if(rx<max)
		rx=max;
	pocet_riadkov++;
	if(*p=='\0')
		break;
	else
		p++;
	}
 pocet_riadkov++;
 rx+=2;
 if(rx>=_stlpcov-3)
	rx=_stlpcov-3;
 if(pocet_riadkov>=_riadkov-5)
	ry=_riadkov-5;
 else
	ry=pocet_riadkov;
 zx=(_stlpcov-rx)/2;
 zy=(_riadkov-ry)/2;
 vypni_kurzor();
 if(otvor_okno(zx,zy,zx+rx,zy+ry,atributy[20],atributy[21],1)!=TRUE)
	return;
 tlac_retazec(_stlpcov/2-4,zy,atributy[21]," POMOC ");
 rx-=2;
 ry-=2;
 pocet_riadkov-=2;
 tlac_riadok_help(" ~PgUp strana hore  ~PgDn strana dole  ~ posun  ~ESC,ENTER n vrat",atributy[4],atributy[5]);
 while(!koniec)
	{
	if(ry<pocet_riadkov)
		{
		if(zaciatok==0)
			tlac_retazec(zx+rx-6,zy+ry+1,atributy[21],ret3);
 
		else
			{
			if(zaciatok+ry>=pocet_riadkov)
				tlac_retazec(zx+rx-6,zy+ry+1,atributy[21],ret1);
			else
				tlac_retazec(zx+rx-6,zy+ry+1,atributy[21],ret2);
			}
		}
	i=0;
	p=help;
	for(i=0;i<zaciatok;i++)
		while(*p++!='\n');
	i=0;
	while(i<ry)
		{
		if(zaciatok+i>=pocet_riadkov)
			break;
		j=0;
		while(*p!='\n' && *p!='\0')
			if(j>=rx)
				break;
			else
				{
				tlac_znak(zx+1+j,zy+1+i,atributy[20],*p);
				p++;
				j++;
				}
		while(j<rx)tlac_znak(zx+1+j++,zy+1+i,atributy[20],' ');
		i++;
		p++;
		}
	while(i<ry)
		{
		j=0;
		while(j<rx)tlac_znak(zx+1+j++,zy+1+i,atributy[20],' ');
		i++;
		}
	switch(key())
		{
		case ESC:
		case ENTER:
			zatvor_okno1();
			return;
		case UP:
			if(zaciatok>0)
				zaciatok--;
			break;
		case DOWN:
			if(zaciatok+ry<pocet_riadkov)
				zaciatok++;
			break;
		case PGUP:
			if(zaciatok>ry)
				zaciatok-=ry;
			else
				zaciatok=0;
			break;
		case PGDOWN:
			if(zaciatok+ry<pocet_riadkov)
				zaciatok+=ry;
			break;
		case HOME:
			zaciatok=0;
			break;
		case END:
			zaciatok=pocet_riadkov-ry;
			break;
		}
	}
}
 
 
/*---------------------------------END--------------------------------------*/