Пример #1
0
int main (int argc, char **argv)
{
int ix,tv,found=0, spr, resolution;
int dloop=1, rcc=-1;
char rstr[BUFSIZE]={0}, *rptr=NULL, *aptr=NULL;
time_t tm1,tm2;
#ifndef MARTII
FILE *fh;
#endif

		if(argc<2)
		{
			ShowUsage();
			return 0;
		}

		//init framebuffer before 1st scale2res
		fb = open(FB_DEVICE, O_RDWR);
#if HAVE_SPARK_HARDWARE || HAVE_DUCKBOX_HARDWARE
		if (fb < 0)
			fb = open(FB_DEVICE_FALLBACK, O_RDWR);
#endif
		if(fb == -1)
		{
			perror(__plugin__ " <open framebuffer device>");
			exit(1);
		}
		if(ioctl(fb, FBIOGET_FSCREENINFO, &fix_screeninfo) == -1)
		{
			perror(__plugin__ " <FBIOGET_FSCREENINFO>\n");
			return -1;
		}
		if(ioctl(fb, FBIOGET_VSCREENINFO, &var_screeninfo) == -1)
		{
			perror(__plugin__ " <FBIOGET_VSCREENINFO>\n");
			return -1;
		}
#if defined(HAVE_SPARK_HARDWARE) || defined(HAVE_DUCKBOX_HARDWARE)
		var_screeninfo.xres = DEFAULT_XRES;
		var_screeninfo.yres = DEFAULT_YRES;
#endif

		if(!(lfb = (uint32_t*)mmap(0, fix_screeninfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0)))
		{
			perror(__plugin__ " <mapping of Framebuffer>\n");
			return -1;
		}

		dloop=0;
		for(tv=1; !dloop && tv<argc; tv++)
		{
			aptr=argv[tv];
			if(!strcmp(aptr,"-v") || !strcmp(aptr,"--version"))
			{
				printf("%s Version %.2f\n", __plugin__, M_VERSION);
				return 0;
			}
			if((rptr=strchr(aptr,'='))!=NULL)
			{
				rptr++;
				if(strstr(aptr,"size=")!=NULL)
				{
					if(sscanf(rptr,"%d",&FSIZE_MED)!=1)
					{
						dloop=1;
					}
				}
				else
				{
					if(strstr(aptr,"title=")!=NULL)
					{
						size_t l = strlen(rptr);
						char *t = (char *)alloca(l * 4 + 1);
						memcpy(t, rptr, l + 1);
						TranslateString(t, l * 4);
						title = strdup(t);
						CatchTabs(title);

						if(strcmp(title,"none")==0)
						{
							header=0;
						}
					}
					else
					{
						if(strstr(aptr,"timeout=")!=NULL)
						{
							if(sscanf(rptr,"%d",&timeout)!=1)
							{
								dloop=1;
							}
						}
						else
						{
							if(strstr(aptr,"msg=")!=NULL)
							{
								dloop=Transform_Msg(rptr);
								if(timeout==0)
								{
										if((timeout=Read_Neutrino_Cfg("timing.epg"))<0)
											timeout=300;
								}
								type=1;
							}
							else
							{
								if(strstr(aptr,"popup=")!=NULL)
								{
									dloop=Transform_Msg(rptr);
									if(timeout==0)
									{
										if((timeout=Read_Neutrino_Cfg("timing.infobar"))<0)
											timeout=6;
									}
									type=2;
								}
								else
								{
									if(strstr(aptr,"refresh=")!=NULL)
									{
										if(sscanf(rptr,"%d",&refresh)!=1)
										{
											dloop=1;
										}
									}
									else
									{
										if(strstr(aptr,"select=")!=NULL)
										{
											dloop=GetSelection(rptr);
										}
										else
										{
											if(strstr(aptr,"default=")!=NULL)
											{
												if((sscanf(rptr,"%d",&selection)!=1) || selection<1)
												{
													dloop=1;
												}
											}
											else
											{
												if(strstr(aptr,"order=")!=NULL)
												{
													if(sscanf(rptr,"%d",&bpline)!=1)
													{
														dloop=1;
													}
												}
												else
												{
													if(strstr(aptr,"echo=")!=NULL)
													{
														if(sscanf(rptr,"%d",&echo)!=1)
														{
															dloop=1;
														}
													}
													else
													{
														if(strstr(aptr,"absolute=")!=NULL)
														{
															if(sscanf(rptr,"%d",&absolute)!=1)
															{
																dloop=1;
															}
														}
														else
														{
															if(strstr(aptr,"hide=")!=NULL)
															{
																if(sscanf(rptr,"%d",&mute)!=1)
																{
																	dloop=1;
																}
															}
															else
															{
																if(strstr(aptr,"cyclic=")!=NULL)
																{
																	if(sscanf(rptr,"%d",&cyclic)!=1)
																	{
																		dloop=1;
																	}
																}
																else
																{
																	if(strstr(aptr,"icon=")!=NULL)
																	{
																		icon=rptr;
																		dloop=Transform_Icon(icon)==0;
																	}
																	else
																	{
																		dloop=2;
																	}
																}
															}
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
			switch (dloop)
			{
				case 1:
					printf("%s <param error: %s>\n", __plugin__, aptr);
					return 0;
					break;
				
				case 2:
					printf("%s <unknown command: %s>\n\n", __plugin__, aptr);
					ShowUsage();
					return 0;
					break;
			}
		}

		FSIZE_BIG=(float)FSIZE_MED*1.25;
		FSIZE_SMALL=(FSIZE_MED*4)/5;
		TABULATOR=2*FSIZE_MED;
		size=FSIZE_MED;
		
		/*
		if(!echo)
		{
			printf("\nMsgBox Version %.2f\n", M_VERSION);
		}
		*/
		if(!buttons)
		{
			butmsg[0]=strdup("OK");
			buttons=1;
		}
		if(!absolute)
		{
			for(tv=0; tv<buttons; tv++)
			{
				rbutt[tv]=tv+1;
			}
		}
		if(selection)
		{	
			for(tv=0; tv<buttons && !found; tv++)		
			{
				if(rbutt[tv]==selection)
				{
					selection=tv+1;
					found=1;
				}
			}
			if(!found)
			{
				printf("%s <param error: default=%d>\n", __plugin__, selection);
				return 0;
			}
		}
		else
		{
			for(tv=0; tv<buttons && !selection; tv++)
			{
				if(strlen(butmsg[tv]))
				{
					selection=tv+1;
				}
			}
		}
		if(!icon)
		{
			icon=strdup("info");
		}
		if(!title)
		{
			title=strdup("Information");
		}
		if((line_buffer=calloc(BUFSIZE+1, sizeof(char)))==NULL)
		{
			printf(NOMEM);
			return -1;
		}
	
		spr=Read_Neutrino_Cfg("screen_preset")+1;
		resolution=Read_Neutrino_Cfg("osd_resolution");

		if (resolution == -1)
			sprintf(line_buffer,"screen_StartX_%s", spres[spr]);
		else
			sprintf(line_buffer,"screen_StartX_%s_%d", spres[spr], resolution);
		if((sx=Read_Neutrino_Cfg(line_buffer))<0)
			sx=scale2res(100);

		if (resolution == -1)
			sprintf(line_buffer,"screen_EndX_%s", spres[spr]);
		else
			sprintf(line_buffer,"screen_EndX_%s_%d", spres[spr], resolution);
		if((ex=Read_Neutrino_Cfg(line_buffer))<0)
			ex=scale2res(1180);

		if (resolution == -1)
			sprintf(line_buffer,"screen_StartY_%s", spres[spr]);
		else
			sprintf(line_buffer,"screen_StartY_%s_%d", spres[spr], resolution);
		if((sy=Read_Neutrino_Cfg(line_buffer))<0)
			sy=scale2res(100);

		if (resolution == -1)
			sprintf(line_buffer,"screen_EndY_%s", spres[spr]);
		else
			sprintf(line_buffer,"screen_EndY_%s_%d", spres[spr], resolution);
		if((ey=Read_Neutrino_Cfg(line_buffer))<0)
			ey=scale2res(620);

		for(ix=CMCST; ix<=CMH; ix++)
		{
			sprintf(rstr,"menu_%s_alpha",menucoltxt[ix]);
			if((tv=Read_Neutrino_Cfg(rstr))>=0)
				tr[ix]=255-(float)tv*2.55;

			sprintf(rstr,"menu_%s_blue",menucoltxt[ix]);
			if((tv=Read_Neutrino_Cfg(rstr))>=0)
				bl[ix]=(float)tv*2.55;

			sprintf(rstr,"menu_%s_green",menucoltxt[ix]);
			if((tv=Read_Neutrino_Cfg(rstr))>=0)
				gn[ix]=(float)tv*2.55;

			sprintf(rstr,"menu_%s_red",menucoltxt[ix]);
			if((tv=Read_Neutrino_Cfg(rstr))>=0)
				rd[ix]=(float)tv*2.55;
		}

		int	cix=CMC;
		for(ix=COL_MENUCONTENT_PLUS_0; ix<=COL_MENUCONTENT_PLUS_3; ix++)
		{
			rd[ix]=rd[cix]+25;
			gn[ix]=gn[cix]+25;
			bl[ix]=bl[cix]+25;
			tr[ix]=tr[cix];
			cix=ix;
		}

		sprintf(rstr,"infobar_alpha");
		if((tv=Read_Neutrino_Cfg(rstr))>=0)
			tr[COL_SHADOW_PLUS_0]=255-(float)tv*2.55;

		sprintf(rstr,"infobar_blue");
		if((tv=Read_Neutrino_Cfg(rstr))>=0)
			bl[COL_SHADOW_PLUS_0]=(float)tv*2.55*0.4;

		sprintf(rstr,"infobar_green");
		if((tv=Read_Neutrino_Cfg(rstr))>=0)
			gn[COL_SHADOW_PLUS_0]=(float)tv*2.55*0.4;

		sprintf(rstr,"infobar_red");
		if((tv=Read_Neutrino_Cfg(rstr))>=0)
			rd[COL_SHADOW_PLUS_0]=(float)tv*2.55*0.4;

		for (ix = 0; ix <= COL_SHADOW_PLUS_0; ix++)
			bgra[ix] = (tr[ix] << 24) | (rd[ix] << 16) | (gn[ix] << 8) | bl[ix];

		if(Read_Neutrino_Cfg("rounded_corners")>0)
		{
			radius = scale2res(11);
			radius_small = scale2res(5);
		}
		else
			radius = radius_small = 0;

		InitRC();
		
		if((trstr=malloc(BUFSIZE))==NULL)
		{
			printf(NOMEM);
			return -1;
		}
		
	//init fontlibrary

		if((error = FT_Init_FreeType(&library)))
		{
			printf("%s <FT_Init_FreeType failed with Errorcode 0x%.2X>", __plugin__, error);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}

		if((error = FTC_Manager_New(library, 1, 2, 0, &MyFaceRequester, NULL, &manager)))
		{
			printf("%s <FTC_Manager_New failed with Errorcode 0x%.2X>\n", __plugin__, error);
			FT_Done_FreeType(library);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}

		if((error = FTC_SBitCache_New(manager, &cache)))
		{
			printf("%s <FTC_SBitCache_New failed with Errorcode 0x%.2X>\n", __plugin__, error);
			FTC_Manager_Done(manager);
			FT_Done_FreeType(library);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}

		Read_Neutrino_Cfg("font_file=");
		if((error = FTC_Manager_LookupFace(manager, FONT, &face)))
		{
			if((error = FTC_Manager_LookupFace(manager, FONT2, &face)))
			{
				printf("%s <FTC_Manager_LookupFace failed with Errorcode 0x%.2X>\n", __plugin__, error);
				FTC_Manager_Done(manager);
				FT_Done_FreeType(library);
				munmap(lfb, fix_screeninfo.smem_len);
				return 2;
			}
			else
				desc.face_id = FONT2;
		}
		else
			desc.face_id = FONT;
		
		use_kerning = FT_HAS_KERNING(face);

		desc.flags = FT_LOAD_RENDER | FT_LOAD_FORCE_AUTOHINT;

		//init backbuffer
#if HAVE_SPARK_HARDWARE || HAVE_DUCKBOX_HARDWARE
		lbb = lfb + 1920 * 1080;
		fix_screeninfo.line_length = DEFAULT_XRES * sizeof(uint32_t);
		stride = DEFAULT_XRES;
#else
		stride = fix_screeninfo.line_length/sizeof(uint32_t);
		if(stride == 7680 && var_screeninfo.xres == 1280) {
			var_screeninfo.yres = 1080;
		}
		if(!(lbb = malloc(var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t))))
		{
			perror(__plugin__ " <allocating of Backbuffer>\n");
			FTC_Manager_Done(manager);
			FT_Done_FreeType(library);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}
#endif
		if(!(obb = malloc(var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t))))
		{
			perror(__plugin__ " <allocating of Backbuffer>\n");
			FTC_Manager_Done(manager);
			FT_Done_FreeType(library);
			free(lbb);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}
		if(!(hbb = malloc(var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t))))
		{
			perror(__plugin__ " <allocating of Backbuffer>\n");
			FTC_Manager_Done(manager);
			FT_Done_FreeType(library);
			free(lbb);
			free(obb);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}
		if(!(ibb = malloc(var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t))))
		{
			perror(__plugin__ " <allocating of Backbuffer>\n");
			FTC_Manager_Done(manager);
			FT_Done_FreeType(library);
			free(lbb);
			free(obb);
			free(hbb);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}

		if(refresh & 1)
		{
			memcpy(ibb, lbb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
		}
		else
		{
			memset(ibb, TRANSP, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
		}
		if(mute==2)
		{
			memcpy(hbb, lbb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
		}
		else
		{
			memset(hbb, TRANSP, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
		}
		if(refresh & 2)
		{
			memcpy(obb, lbb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
		}
		else
		{
			memset(obb, TRANSP, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
		}

		startx = sx;
		starty = sy;


	/* scale to resolution */
	FSIZE_BIG = scale2res(FSIZE_BIG);
	FSIZE_MED = scale2res(FSIZE_MED);
	FSIZE_SMALL = scale2res(FSIZE_SMALL);

	TABULATOR = scale2res(TABULATOR);

	OFFSET_MED = scale2res(OFFSET_MED);
	OFFSET_SMALL = scale2res(OFFSET_SMALL);
	OFFSET_MIN = scale2res(OFFSET_MIN);

	size = scale2res(size);

	/* Set up signal handlers. */
	signal(SIGINT, quit_signal);
	signal(SIGTERM, quit_signal);
	signal(SIGQUIT, quit_signal);
	signal(SIGSEGV, quit_signal);

	put_instance(instance=get_instance()+1);

  	show_txt(0);	
	
	time(&tm1);
	tm2=tm1;
	
	//main loop
	while((rcc!=KEY_EXIT) && (rcc!=KEY_HOME) && (rcc!=KEY_OK) && ((timeout==-1)||((tm2-tm1)<timeout)))
	{
		rcc=GetRCCode(1000);
		if(rcc!=-1)
		{
			time(&tm1);
		}
		else
		{
			if(cyclic)
				show_txt(0);
#if 0
			if(++cupd>100)
			{
				if(cyclic)
				{
					show_txt(0);
					cupd=0;
				}
			}
			usleep(10000L);
#endif
		}
		if(mute && rcc==KEY_MUTE)
		{
			hide^=1;
			show_txt(0);
#if HAVE_SPARK_HARDWARE || HAVE_DUCKBOX_HARDWARE
			ClearRC();
#else

			while(GetRCCode(300)!=-1);
			if(hide)
			{
				if((fh=fopen(HDF_FILE,"w"))!=NULL)
				{
					fprintf(fh,"hidden");
					fclose(fh);
				}
			}
			else
			{
				remove(HDF_FILE);
			}
#endif
		}
		if((!hide) && (rcc!=KEY_EXIT) && (rcc!=KEY_HOME) && (rcc!=KEY_OK))
		{
			switch(rcc)
			{
				case KEY_LEFT:
					if(!hide && (--selection<1))
					{
						selection=buttons;
					}
					show_txt(1);
				break;
				
				case KEY_RIGHT:
					if(!hide && (++selection>buttons))
					{
						selection=1;
					}
					show_txt(1);
				break;
				
				case KEY_UP:
					if(!hide && ((selection-=bpline)<1))
					{
						selection=1;
					}
					show_txt(1);
				break;
				
				case KEY_DOWN:
					if(!hide && ((selection+=bpline)>buttons))
					{
						selection=buttons;
					}
					show_txt(1);
				break;

				default:
					flash^=1;
				break;
			}
		}
		time(&tm2);
		if(hide)
		{
			rcc=-1;
		}
	}
	if((type!=1) || (rcc!=KEY_OK))
	{
		selection=0;
	}
	
	
	//cleanup
#if HAVE_SPARK_HARDWARE || HAVE_DUCKBOX_HARDWARE
	memcpy(lbb, obb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
	blit();
#else
	memcpy(lfb, obb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
#endif
	munmap(lfb, fix_screeninfo.smem_len);
	close(fb);
#if !defined(HAVE_SPARK_HARDWARE) && !defined(HAVE_DUCKBOX_HARDWARE)
	free(lbb);
#endif

	put_instance(get_instance()-1);

	if(echo && selection>0)
	{
		printf("%s\n",butmsg[selection-1]);
	}

	for(tv=0; tv<buttons; tv++)
	{
		free(butmsg[tv]);
	}
	free(trstr);
	free(line_buffer);
	free(title);

	FTC_Manager_Done(manager);
	FT_Done_FreeType(library);

	free(obb);
	free(hbb);
	free(ibb);

	CloseRC();

	remove("/tmp/msgbox.tmp");

	if(selection)
	{
		return rbutt[selection-1];
	}
	return 0;
}
int Get_Selection(MENU *m)
{
	int rv=1,rccode, mloop=1,i,j,first,last,active,knew=1;
	time_t tm1,tm2;

	if(m->num_active)
	{
		i=m->act_entry;
		while((i>=0) && ((m->list[i]->type==TYP_COMMENT) || (m->list[i]->type==TYP_INACTIVE)))
		{
			++i;
			if(i>=m->num_entrys)
			{
				i=-1;
			}
		}
		if(i==-1)
		{
			i=0;
		}
		m->act_entry=i;
	}
	time(&tm1);
	do{
		//usleep(100000L);
		first=(paging)?0:(MAX_FUNCS*(int)(m->act_entry/MAX_FUNCS));
		last=(paging)?(m->num_entrys-1):(MAX_FUNCS*(int)(m->act_entry/MAX_FUNCS)+MAX_FUNCS-1);
		if(last>=m->num_entrys)
		{
			last=m->num_entrys-1;
		}

		active=0;
		for(i=first; i<=last && !active; i++)
		{
			active |= ((m->list[i]->type != TYP_COMMENT) && (m->list[i]->type != TYP_INACTIVE));
		}

		rccode=-1;
		if(knew)
		{
			ShowInfo(m, knew);
		}
		knew=1;
		switch(rccode = GetRCCode(mtmo * 1000))
		{
			case RC_RED:
				if(active && direct[0]>=0)
				{
					m->act_entry=direct[0];
					rv=1;
					mloop=0;
				}
				break;

			case RC_GREEN:
				if(active && direct[1]>=0)
				{
					m->act_entry=direct[1];
					rv=1;
					mloop=0;
				}
				break;

			case RC_YELLOW:
				if(active && direct[2]>=0)
				{
					m->act_entry=direct[2];
					rv=1;
					mloop=0;
				}
				break;

			case RC_BLUE:
				if(active && direct[3]>=0)
				{
					m->act_entry=direct[3];
					rv=1;
					mloop=0;
				}
				break;

			case RC_1:
				if(active && direct[4]>=0)
				{
					m->act_entry=direct[4];
					rv=1;
					mloop=0;
				}
				break;

			case RC_2:
				if(active && direct[5]>=0)
				{
					m->act_entry=direct[5];
					rv=1;
					mloop=0;
				}
				break;

			case RC_3:
				if(active && direct[6]>=0)
				{
					m->act_entry=direct[6];
					rv=1;
					mloop=0;
				}
				break;

			case RC_4:
				if(active && direct[7]>=0)
				{
					m->act_entry=direct[7];
					rv=1;
					mloop=0;
				}
				break;

			case RC_5:
				if(active && direct[8]>=0)
				{
					m->act_entry=direct[8];
					rv=1;
					mloop=0;
				}
				break;

			case RC_6:
				if(active && direct[9]>=0)
				{
					m->act_entry=direct[9];
					rv=1;
					mloop=0;
				}
				break;

			case RC_7:
				if(active && direct[10]>=0)
				{
					m->act_entry=direct[10];
					rv=1;
					mloop=0;
				}
				break;

			case RC_8:
				if(active && direct[11]>=0)
				{
					m->act_entry=direct[11];
					rv=1;
					mloop=0;
				}
				break;

			case RC_9:
				if(active && direct[12]>=0)
				{
					m->act_entry=direct[12];
					rv=1;
					mloop=0;
				}
				break;

			case RC_0:
				if(active && direct[13]>=0)
				{
					m->act_entry=direct[13];
					rv=1;
					mloop=0;
				}
				break;

			case RC_UP:
			case RC_MINUS:
				if(m->num_active)
				{
					i=m->act_entry-1;
					if(i<first)
					{
						i=last;
					}
					while(active && ((m->list[i]->type==TYP_COMMENT) || (m->list[i]->type==TYP_INACTIVE)))
					{
						--i;
						if(i<first)
						{
							i=last;
						}
					}
					m->act_entry=i;
				}
				//knew=1;
				break;

			case RC_DOWN:
			case RC_PLUS:
				if(m->num_active)
				{
					i=m->act_entry+1;
					if(i>last)
					{
						i=first;
					}
					while(active && ((m->list[i]->type==TYP_COMMENT) || (m->list[i]->type==TYP_INACTIVE)))
					{
						++i;
						if(i>last)
						{
							i=first;
						}
					}
					m->act_entry=i;
				}
				//knew=1;
				break;

			case RC_PAGEUP:
				i=MAX_FUNCS*(m->act_entry/MAX_FUNCS)-MAX_FUNCS;
				if(i<0)
				{
					i=MAX_FUNCS*((m->num_entrys-1)/MAX_FUNCS);
				}
				j=0;
				while((m->list[i+j]->type==TYP_COMMENT || m->list[i+j]->type==TYP_INACTIVE) && active && (i+j)<=(last+MAX_FUNCS) && (i+j)<m->num_entrys)
				{
					++j;
				}
				if((i+j)<=(last+MAX_FUNCS) && (i+j)<m->num_entrys)
				{
					i+=j;
				}
				m->act_entry=i;
				break;

			case RC_PAGEDOWN:
				i=MAX_FUNCS*(m->act_entry/MAX_FUNCS)+MAX_FUNCS;
				if(i>=m->num_entrys)
				{
					i=0;
				}
				j=0;
				while((m->list[i+j]->type==TYP_COMMENT || m->list[i+j]->type==TYP_INACTIVE) && active && (i+j)<=(last+MAX_FUNCS) && (i+j)<m->num_entrys)
				{
					++j;
				}
				if((i+j)<=(last+MAX_FUNCS) && (i+j)<m->num_entrys)
				{
					i+=j;
				}
				m->act_entry=i;
				break;

			case RC_OK:
				if(m->num_active)
				{
					rv=1;
					mloop=0;
				}
				break;

			case -1:
				knew=0;
				time(&tm2);
				if(mtmo==0 || (tm2-tm1)<mtmo)
				{
					break;
				}
				rv=RC_HOME;
			case RC_HOME:
				rv=0;
				mloop=0;
				break;

			case RC_MUTE:
#ifdef MARTII
#if defined(HAVE_SPARK_HARDWARE) || defined(HAVE_DUCKBOX_HARDWARE)
				FillRect(0, 0, DEFAULT_XRES, DEFAULT_YRES, 0);
#else
				memset(lbb, TRANSP, var_screeninfo.xres * var_screeninfo.yres * sizeof(uint32_t));
#endif
				blit();
#else
				memset(lfb, TRANSP, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
#endif


#ifdef MARTII
				usleep(500000L);
				ClearRC();
				while(GetRCCode(-1)!=RC_MUTE);
				ClearRC();
#else
				while(GetRCCode(300)!=RC_MUTE);
#endif
				break;

			case RC_STANDBY:
				rv=-1;
				mloop=0;
				break;

			default: knew=0; break;
		}
		if(rccode!=-1)
		{
			time(&tm1);
		}
	} while(mloop);

	ShowInfo(m, knew);

	return rv;
}
Пример #3
0
char *inputd(char *form, char *title, char *defstr, int keys, int frame, int mask, int bhelp, int cols, int tmo, int debounce)
{
#ifdef MARTII
unsigned int i,j;
int exs,eys,wxs,wxw,wys,wyw,xp,yp;
#else
int exs,eys,wxs,wxw,wys,wyw,i,j,xp,yp;
#endif
char trnd[2]={0,0},tch;
int act_key=-1, last_key=-1, b_key=-1, run=1, ipos=0;
time_t t1,t2,tm1;
char knum[12][2]={"1","2","3","4","5","6","7","8","9"," ","0"};
char kalp[12][5]={"+-*/","abcä","def","ghi","jkl","mnoö","pqrs","tuvü","wxyz","","_,.;"};

	epos=-1;
	cpos=0;
	kpos=0;
	first=1;
	time(&tm1);
	if(cols>25)
	{
		cols=25;
	}
	if(cols<1)
	{
		cols=1;
	}
	format=form;
	estr=strdup(form);
	cnt=strlen(form);
	
	i=GetStringLen(title, BIG)+10;
	j=((cnt>cols)?cols:cnt)*exsz;
	if(j>i)
	{
		i=j;
	}
	if(keys)
	{
		j=3*bxsz;
		if(j>i)
		{
			i=j;
		}
	}
	wxw=i+2*xbrd;

	i=(((cnt-1)/cols)+1)*eysz;
	if(keys)
	{
		i+=4*bysz;
	}
	wyw=((keys)?4:2)*ybrd+i;

	wxs=((ex-sx)-wxw)/2;
	wys=(((ey-sy)-wyw)+hsz)/2;
	exs=wxs+(wxw-((cnt>cols)?cols:cnt)*exsz)/2;
	eys=wys+ybrd;

	*estr=0;
	*rstr=0;
		
	j=0;
	for(i=0; i<strlen(format); i++)
	{
		tch=format[i];
		if(IsInput(tch))
		{
			if(epos==-1)
			{
				epos=i;
			}
			if(defstr && j<strlen(defstr))
			{
				estr[i]=defstr[j++];
			}
			else
			{
				estr[i]=' ';
			}
		}
		else
		{
			estr[i]=format[i];
		}
	}
	estr[i]=0;

	RenderBox(wxs-2, wys-hsz-2, wxs+wxw+2, wys+wyw+2, radius, CMH);
	RenderBox(wxs, wys-hsz, wxs+wxw, wys+wyw, radius, CMC);
	RenderBox(wxs, wys-hsz, wxs+wxw, wys, radius, CMH);
	RenderString(title, wxs, wys-15, wxw, CENTER, BIG, CMHT);
	if(keys)
	{
		int bxs=wxs+(wxw-(3*bxsz))/2;
		int bys=((wys+wyw)-2*ybrd)-4*bysz;
		
		for(i=0; i<11; i++)
		{
			if(i!=9)
			{
				RenderBox(bxs+(i%3)*bxsz, bys+(i/3)*bysz, bxs+((i%3)+1)*bxsz, bys+((i/3)+1)*bysz, radius, CMS);
				RenderBox(bxs+(i%3)*bxsz+2, bys+(i/3)*bysz+2, bxs+((i%3)+1)*bxsz-2, bys+((i/3)+1)*bysz-2, radius, CMC);
				RenderString(knum[i], bxs+(i%3)*bxsz, bys+(i/3)*bysz+bysz/2, bxsz, CENTER, MED, CMCIT);
				RenderString(kalp[i], bxs+(i%3)*bxsz, bys+(i/3)*bysz+bysz-8, bxsz, CENTER, SMALL, CMCIT);
				
			}
		}	
		RenderCircle(bxs,wys+wyw-ybrd-8,RED);
		RenderString("Groß/Klein",bxs+15,wys+wyw-ybrd+5,3*bxsz,LEFT,SMALL,CMCIT);
		RenderCircle(bxs+3*bxsz-GetStringLen("löschen",SMALL)-15,wys+wyw-ybrd-8,YELLOW);
		RenderString("löschen",bxs,wys+wyw-ybrd+5,3*bxsz,RIGHT,SMALL,CMCIT);
	}
	
	while(run)
	{
		for(i=0; i<cnt; i++)
		{
			xp=i%cols;
			yp=i/cols;
			if(frame && IsInput(format[i]))
			{
				RenderBox(exs+xp*exsz, eys+5+yp*eysz, exs+(xp+1)*exsz, eys+(yp+1)*eysz, radius, CMS);
			}
			RenderBox(exs+xp*exsz+1, eys+5+yp*eysz+1, exs+(xp+1)*exsz-1, eys+(yp+1)*eysz-1, radius, (epos==i)?CMCS:CMC);
			*trnd=(mask && format[i]==NUM && IsNum(estr[i]))?'*':estr[i];
			RenderString(trnd, exs+xp*exsz+2, eys+yp*eysz+tys, exsz-2, CENTER, MED, (epos==i)?CMCST:(IsInput(format[i]))?CMCT:CMCIT);
		}
#ifdef MARTII
		blit();
#else
		memcpy(lfb, lbb, fix_screeninfo.line_length*var_screeninfo.yres);
#endif
		
//		sleep(1);

		time(&t1);
		i=-1;
		while(i==-1)
		{
#ifdef MARTII
			i=GetRCCode(tmo * 1000);
#else
			i=GetRCCode();
#endif
			if(i!=-1)
			{
				tmo=0;
				if(i==b_key)
				{
					usleep(debounce*1000);
#ifdef MARTII
					ClearRC();
#else
					while((i=GetRCCode())!=-1);
#endif
				}
				b_key=i;
			}
			time(&t2);
			if(tmo)
			{
				if((t2-tm1)>=tmo)
				{
					i=KEY_EXIT;
				}
			}
			if((((format[epos]!=NUM) && (format[epos]!=HEX)) || ((format[epos]==HEX)&&(strlen(hcod[cpos])>1))) && ((t2-t1)>ndelay) && last_key>=0)
			{
				act_key=i=-2;
				b_key=-3;
				NextPos();
			}
		}
		act_key=i;
		
		switch(act_key)
		{
			case KEY_0:
				SetCode(0);
			break;
			
			case KEY_1:
				SetCode(1);
			break;
			
			case KEY_2:
				SetCode(2);
			break;
			
			case KEY_3:
				SetCode(3);
			break;
			
			case KEY_4:
				SetCode(4);
			break;
			
			case KEY_5:
				SetCode(5);
			break;
			
			case KEY_6:
				SetCode(6);
			break;
			
			case KEY_7:
				SetCode(7);
			break;
			
			case KEY_8:
				SetCode(8);
			break;
			
			case KEY_9:
				SetCode(9);
			break;
			
			case KEY_RIGHT:
				NextPos();
				act_key=-2;
			break;
			
			case KEY_LEFT:
				PrevPos();
				act_key=-2;
			break;
			
			case KEY_VOLUMEUP:
				ipos=epos;
				while(IsInput(format[ipos+1]) && ((ipos+1)<cnt))
				{
					++ipos;
				}
				while(ipos>epos)
				{
					estr[ipos]=estr[ipos-1];
					--ipos;
				}
				estr[epos]=' ';
//				estr[epos]=((format[epos]=='#')||(format[epos]=='^'))?'0':' ';
				act_key=-1;
			break;

			case KEY_VOLUMEDOWN:
				ipos=epos+1;
				while(IsInput(format[ipos]) && (ipos<cnt))
				{
					estr[ipos-1]=estr[ipos];
					++ipos;
				}
				estr[ipos-1]=' ';
//				estr[ipos-1]=(format[ipos-1]=='#')?'0':' ';
				act_key=-1;
			break;

			case KEY_OK:
				run=0;
			break;
			
			case KEY_MUTE:
#ifdef MARTII
				memset(lbb, 0, DEFAULT_XRES * DEFAULT_YRES * sizeof(uint32_t));
				blit();
#else
				memset(lfb, TRANSP, fix_screeninfo.line_length*var_screeninfo.yres);
#endif
#ifdef MARTII
				usleep(500000L);
				ClearRC();
				while(GetRCCode(-1)!=KEY_MUTE);
				ClearRC();
#else
				usleep(500000L);
				while(GetRCCode()!=-1)
				{
					usleep(100000L);
				}
				while(GetRCCode()!=KEY_MUTE)
				{
					usleep(500000L);
				}
				while((act_key=GetRCCode())!=-1)
				{
					usleep(100000L);
				}
#endif
//				knew=1;
			break;

			case KEY_UP:
				if(epos>=cols)
				{
					epos-=cols;
					if(!IsInput(format[epos]))
					{
						NextPos();
					}
				}
				else
				{
					epos=cnt-1;
					if(!IsInput(format[epos]))
					{
						PrevPos();
					}
				}
				act_key=-2;
			break;
			
			case KEY_DOWN:
				if(epos<=(cnt-cols))
				{
					epos+=cols;
					if(!IsInput(format[epos]))
					{
						NextPos();
					}
				}
				else
				{
					epos=0;
					if(!IsInput(format[epos]))
					{
						NextPos();
					}
				}
				act_key=-2;
			break;
			
			case KEY_EXIT:
				free(estr);
				estr=NULL;
				*rstr=0;
				run=0;
			break;
			
			case KEY_RED:
				if(IsAlpha(estr[epos]))
				{
					estr[epos]^=0x20;
				}
				act_key=-2;
			break;
			
			case KEY_YELLOW:
				epos=-1;
				for(i=0; i<strlen(format); i++)
				{
					if(IsInput(format[i]))
					{
						if(epos==-1)
						{
							epos=i;
						}
						estr[i]=' ';
					}
				}
				act_key=-2;
			break;
			
			case KEY_HELP:
				if(bhelp)
				{
					sprintf(estr,"?");
					run=0;
				}
			break;
			
			default:
				act_key=-2;
			break;
		}
		last_key=act_key;
	}
	
	if(estr)
	{
		j=0;
		for(i=0; i<strlen(format); i++)
		{
			if(IsInput(format[i]))
			{
				rstr[j++]=estr[i];
			}
		}
		rstr[j]=0;
		free(estr);
	}	
#ifdef MARTII
	return rstr;
#else
	ReTransform_Msg(rstr);
	return tstr;
#endif
}