Exemple #1
0
//! Frees items allocated in the constructor and shuts down FreeType
FontServer::~FontServer(void)
{
	delete_sem(lock);
	delete families;
	FTC_Manager_Done(ftmanager);
	FT_Done_FreeType(ftlib);
}
Exemple #2
0
/* exported interface documented in framebuffer/font.h */
bool fb_font_finalise(void)
{
	int i, j;

        FTC_Manager_Done(ft_cmanager);
        FT_Done_FreeType(library);

	for (i = 0; i < FB_FACE_COUNT; i++) {
		if (fb_faces[i] == NULL)
			continue;

		/* Unset any faces that duplicate this one */
		for (j = i + 1; j < FB_FACE_COUNT; j++) {
			if (fb_faces[i] == fb_faces[j])
				fb_faces[j] = NULL;
		}

		free(fb_faces[i]->fontfile);
		free(fb_faces[i]);

		fb_faces[i] = NULL;
	}

        return true;
}
Exemple #3
0
FreeType::~FreeType() noexcept
{
	FTC_Manager_Done(this->cache_);
	FT_Done_FreeType(this->library_);
	this->cmap_ = nullptr;
	this->image_ = nullptr;
	this->cache_ = nullptr;
	this->library_ = nullptr;
}
Exemple #4
0
void destroy_freetype()
{
	FT_Error ft_error;

	FTC_Manager_Done(ft_cache_man);

	ft_error = FT_Done_FreeType(ft_lib);
	assert(ft_error == 0);
}
Exemple #5
0
static void rfb_destroy(RFBDISPLAY *mod)
{
	TDestroy((struct THandle *) mod->rfb_Lock);
	if (mod->rfb_FTLibrary)
	{
		if (mod->rfb_FTCManager)
			FTC_Manager_Done(mod->rfb_FTCManager);
		FT_Done_FreeType(mod->rfb_FTLibrary);
	}
}
void vita2d_free_font(vita2d_font *font)
{
	if (font) {
		FTC_FaceID face_id = (FTC_FaceID)font;
		FTC_Manager_RemoveFaceID(font->ftcmanager, face_id);
		FTC_Manager_Done(font->ftcmanager);
		if (font->load_from == VITA2D_LOAD_FROM_FILE) {
			free(font->filename);
		}
		texture_atlas_free(font->tex_atlas);
		free(font);
	}
}
Exemple #7
0
FBFontRenderClass::~FBFontRenderClass()
{
	fontListEntry * g;
	
	for (fontListEntry * f = font; f; f = g)
	{
		g = f->next;
		delete f;
	}

	FTC_Manager_Done(cacheManager);
	FT_Done_FreeType(library);
}
Exemple #8
0
void
overlay_destructor(void *p) {
	fbvnc_overlay_t *this = p;
	//if(this->pixels) free(this->pixels); 
	if(this->data) free(this->data);
    if (manager )
	FTC_Manager_Done(manager);
    if (library)
	FT_Done_FreeType(library);
	if (ico_keybd        ) {free(ico_keybd        ); ico_keybd         = NULL; }
	if (ico_keybd_shifted) {free(ico_keybd_shifted); ico_keybd_shifted = NULL; }
    manager = NULL;
    library = NULL;
}
Exemple #9
0
void
_PGFT_Quit(FreeTypeInstance *ft)
{
    if (!ft)
        return;

    if (ft->cache_manager)
        FTC_Manager_Done(ft->cache_manager);

    if (ft->library)
        FT_Done_FreeType(ft->library);

    _PGFT_free(ft);
}
Exemple #10
0
FreeType::FreeType()
:library_(nullptr)
,cache_(nullptr)
,cmap_(nullptr)
,image_(nullptr)
{
	if(FT_Init_FreeType(&this->library_) != 0){
		CINAMO_EXCEPTION(Exception, "[BUG] Failed to init Freetype.");
	}
	if(FTC_Manager_New(this->library_, 16, 0, 1024*1024*10, face_requester, nullptr, &this->cache_ )){
		FT_Done_FreeType(this->library_);
		CINAMO_EXCEPTION(Exception, "[BUG] Failed to init cache manager.");
	}
	if(FTC_CMapCache_New(this->cache_, &this->cmap_)) {
		FTC_Manager_Done(this->cache_);
		FT_Done_FreeType(this->library_);
		CINAMO_EXCEPTION(Exception, "[BUG] Failed to init cmap cache.");
	}
	if(FTC_ImageCache_New(this->cache_, &this->image_)) {
		FTC_Manager_Done(this->cache_);
		FT_Done_FreeType(this->library_);
		CINAMO_EXCEPTION(Exception, "[BUG] Failed to init image cache.");
	}
}
  void
  FTDemo_Done( FTDemo_Handle*  handle )
  {
    int  i;


    if ( !handle )
      return;

    for ( i = 0; i < handle->max_fonts; i++ )
    {
      if ( handle->fonts[i] )
      {
        if ( handle->fonts[i]->filepathname )
          free( (void*)handle->fonts[i]->filepathname );
        free( handle->fonts[i] );
      }
    }
    free( handle->fonts );

    /* string_done */
    for ( i = 0; i < MAX_GLYPHS; i++ )
    {
      PGlyph  glyph = handle->string + i;


      if ( glyph->image )
        FT_Done_Glyph( glyph->image );
    }

    FT_Stroker_Done( handle->stroker );
    FT_Bitmap_Done( handle->library, &handle->bitmap );
    FTC_Manager_Done( handle->cache_manager );
    FT_Done_FreeType( handle->library );

    free( handle );
  }
bool fb_font_finalise(void)
{
        FTC_Manager_Done(ft_cmanager );
        FT_Done_FreeType(library);
        return true;
}
/* initialise font handling */
bool fb_font_init(void)
{
        FT_Error error;
        FT_ULong max_cache_size;
        FT_UInt max_faces = 6;
	fb_faceid_t *fb_face;

LOG(("Freetype init..."));

	nsoptions.fb_font_monochrome = false;			
	nsoptions.fb_font_cachesize = 2048;			
	nsoptions.fb_face_sans_serif = NULL;			
	nsoptions.fb_face_sans_serif_bold = NULL;		
	nsoptions.fb_face_sans_serif_italic = NULL;		
	nsoptions.fb_face_sans_serif_italic_bold = NULL;		
	nsoptions.fb_face_serif = NULL;				
	nsoptions.fb_face_serif_bold = NULL;			
	nsoptions.fb_face_monospace = NULL;			
	nsoptions.fb_face_monospace_bold = NULL;			
	nsoptions.fb_face_cursive = NULL;			
	nsoptions.fb_face_fantasy = NULL;		


        /* freetype library initialise */
        error = FT_Init_FreeType( &library ); 
        if (error) {
                LOG(("Freetype could not initialised (code %d)\n", error));
                return false;
        }

        /* set the Glyph cache size up */
        max_cache_size = nsoption_int(fb_font_cachesize) * 1024; 

	if (max_cache_size < CACHE_MIN_SIZE) {
		max_cache_size = CACHE_MIN_SIZE;
	}

LOG(("Freetype cache..."));
DBG("Ft cache\n");
        /* cache manager initialise */
        error = FTC_Manager_New(library, 
                                max_faces, 
                                0, 
                                max_cache_size, 
                                ft_face_requester, 
                                NULL, 
                                &ft_cmanager);
        if (error) {
                LOG(("Freetype could not initialise cache manager (code %d)\n", error));
                FT_Done_FreeType(library);
                return false;
        }


LOG(("Freetype map cache..."));
DBG("Ft map cache\n");
        error = FTC_CMapCache_New(ft_cmanager, &ft_cmap_cache);

        error = FTC_ImageCache_New(ft_cmanager, &ft_image_cache);

	/* need to obtain the generic font faces */


LOG(("Freetype load fonts..."));
DBG("Ft load fonts\n");

	/* Start with the sans serif font */
	fb_face = fb_new_face(nsoption_charp(fb_face_sans_serif),
			      "sans_serif.ttf",
			      NETSURF_FB_FONT_SANS_SERIF);
	if (fb_face == NULL) {
		
LOG(("Freetype load fonts failed due SANS unavailable :(..."));
DBG("Ft Z:(((\n");
		/* The sans serif font is the default and must be found. */
                LOG(("Could not find the default font\n"));
                FTC_Manager_Done(ft_cmanager);
                FT_Done_FreeType(library);
                return false;
        } else {
		fb_faces[FB_FACE_SANS_SERIF] = fb_face;
	}

LOG(("Freetype loaded sans.."));
DBG("Ft sans loaded:)\n");

	/* Bold sans serif face */
	fb_face = fb_new_face(nsoption_charp(fb_face_sans_serif_bold),
                            "sans_serif_bold.ttf",
                            NETSURF_FB_FONT_SANS_SERIF_BOLD);
	if (fb_face == NULL) {
		/* seperate bold face unavailabe use the normal weight version */
		fb_faces[FB_FACE_SANS_SERIF_BOLD] = fb_faces[FB_FACE_SANS_SERIF];
	} else {
		fb_faces[FB_FACE_SANS_SERIF_BOLD] = fb_face;
	}

	/* Italic sans serif face */
	fb_face = fb_new_face(nsoption_charp(fb_face_sans_serif_italic),
			      "sans_serif_italic.ttf",
			      NETSURF_FB_FONT_SANS_SERIF_ITALIC);
	if (fb_face == NULL) {
		/* seperate italic face unavailabe use the normal weight version */
		fb_faces[FB_FACE_SANS_SERIF_ITALIC] = fb_faces[FB_FACE_SANS_SERIF];
	} else {
		fb_faces[FB_FACE_SANS_SERIF_ITALIC] = fb_face;
	}

	/* Bold italic sans serif face */
	fb_face = fb_new_face(nsoption_charp(fb_face_sans_serif_italic_bold), 
			      "sans_serif_italic_bold.ttf",
			      NETSURF_FB_FONT_SANS_SERIF_ITALIC_BOLD);
	if (fb_face == NULL) {
		/* seperate italic face unavailabe use the normal weight version */
		fb_faces[FB_FACE_SANS_SERIF_ITALIC_BOLD] = fb_faces[FB_FACE_SANS_SERIF];
	} else {
		fb_faces[FB_FACE_SANS_SERIF_ITALIC_BOLD] = fb_face;
	}

	/* serif face */
	fb_face = fb_new_face(nsoption_charp(fb_face_serif),
                            "serif.ttf",
			      NETSURF_FB_FONT_SERIF);
	if (fb_face == NULL) {
		/* serif face unavailabe use the default */
		fb_faces[FB_FACE_SERIF] = fb_faces[FB_FACE_SANS_SERIF];
	} else {
		fb_faces[FB_FACE_SERIF] = fb_face;
	}

	/* bold serif face*/
	fb_face = fb_new_face(nsoption_charp(fb_face_serif_bold),
			      "serif_bold.ttf",
			      NETSURF_FB_FONT_SERIF_BOLD);
	if (fb_face == NULL) {
		/* bold serif face unavailabe use the normal weight */
		fb_faces[FB_FACE_SERIF_BOLD] = fb_faces[FB_FACE_SERIF];
	} else {
		fb_faces[FB_FACE_SERIF_BOLD] = fb_face;
	}


	/* monospace face */
	fb_face = fb_new_face(nsoption_charp(fb_face_monospace),
			      "monospace.ttf",
			      NETSURF_FB_FONT_MONOSPACE);
	if (fb_face == NULL) {
		/* serif face unavailabe use the default */
		fb_faces[FB_FACE_MONOSPACE] = fb_faces[FB_FACE_SANS_SERIF];
	} else {
		fb_faces[FB_FACE_MONOSPACE] = fb_face;
	}

	/* bold monospace face*/
	fb_face = fb_new_face(nsoption_charp(fb_face_monospace_bold),
			      "monospace_bold.ttf",
			      NETSURF_FB_FONT_MONOSPACE_BOLD);
	if (fb_face == NULL) {
		/* bold serif face unavailabe use the normal weight */
		fb_faces[FB_FACE_MONOSPACE_BOLD] = fb_faces[FB_FACE_MONOSPACE];
	} else {
		fb_faces[FB_FACE_MONOSPACE_BOLD] = fb_face;
	}

	/* cursive face */
	fb_face = fb_new_face(nsoption_charp(fb_face_cursive),
			      "cursive.ttf",
			      NETSURF_FB_FONT_CURSIVE);
	if (fb_face == NULL) {
		/* cursive face unavailabe use the default */
		fb_faces[FB_FACE_CURSIVE] = fb_faces[FB_FACE_SANS_SERIF];
	} else {
		fb_faces[FB_FACE_CURSIVE] = fb_face;
	}

	/* fantasy face */
	fb_face = fb_new_face(nsoption_charp(fb_face_fantasy),
			      "fantasy.ttf",
			      NETSURF_FB_FONT_FANTASY);
	if (fb_face == NULL) {
		/* fantasy face unavailabe use the default */
		fb_faces[FB_FACE_FANTASY] = fb_faces[FB_FACE_SANS_SERIF];
	} else {
		fb_faces[FB_FACE_FANTASY] = fb_face;
	}

LOG(("Freetype fonts ready..."));
DBG("Ft ready :)\n");
        
        /* set the default render mode */
        if (nsoption_bool(fb_font_monochrome) == true)
                ft_load_type = FT_LOAD_MONOCHROME; /* faster but less pretty */
        else
                ft_load_type = 0;
        
        return true;
}
int main (int argc, char **argv)
{
	int i,j,found=0,m,mask=1,kmode=1,pmode=0, lc=-1, changed=0, todo=1, help=1, help_changed=0, move=0;
	unsigned char actchan[20]=""/*,channel[128]=""*/;
	FILE *fh,*fh2;
	char *cpt1,*cpt2;
	gpixel mp, mc[MAX_MASK], tp;
	int tsx=430, tsy=120, tdy=24, tsz=28, txw=500, tcol=TURQUOISE;
	int xp[MAX_MASK][8],yp[MAX_MASK][8],xw[MAX_MASK][8],yw[MAX_MASK][8],valid[MAX_MASK],cmc[MAX_MASK],xxp,xxw,yyp,yyw,nmsk=0,amsk=0;
	double xs=1.0, ys=1.0;
	time_t t1,t2;

		for(j=0; j<MAX_MASK; j++)
		{
			valid[j]=0;
			cmc[j]=BLACK;
			make_color(BLACK, &mc[j]);
			for(i=0; i<8; i++)
			{
				xp[j][i]=(1280-40)/2;
				xw[j][i]=40;
				yp[j][i]=(720-20)/2;
				yw[j][i]=20;
			}	
		}
		system("pzapit -var > /tmp/logomaskset.stat");
		if((fh=fopen("/tmp/logomaskset.stat","r"))!=NULL)
		{
			if(fgets(tstr,500,fh))
			{
				TrimString(tstr);
				if(strlen(tstr))
				{
					if(sscanf(tstr+strlen(tstr)-1,"%d",&pmode)!=1)
					{
						pmode=0;
					}
				}
			}
			fclose(fh);
		}
	
		system("touch /tmp/.logomask_kill");

		fb = open(FB_DEVICE, O_RDWR);

		if(ioctl(fb, FBIOGET_FSCREENINFO, &fix_screeninfo) == -1)
		{
			printf("logomask <FBIOGET_FSCREENINFO failed>\n");
			return -1;
		}
		if(ioctl(fb, FBIOGET_VSCREENINFO, &var_screeninfo) == -1)
		{
			printf("logomask <FBIOGET_VSCREENINFO failed>\n");
			return -1;
		}
		
		if(!(lfb = (unsigned char*)mmap(0, fix_screeninfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0)))
		{
			printf("logomask <mapping of Framebuffer failed>\n");
			return -1;
		}

	//init fontlibrary

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

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

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

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

		use_kerning = FT_HAS_KERNING(face);

		desc.face_id = FONT;
		desc.flags = FT_LOAD_MONOCHROME;


		InitRC();

	//init backbuffer

		if(!(lbb = malloc(fix_screeninfo.line_length*var_screeninfo.yres)))
		{
			printf("logomask <allocating of Backbuffer failed>\n");
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}

		memset(lbb, 0, fix_screeninfo.line_length*var_screeninfo.yres);

		system("pzapit -gi > /tmp/logomask.chan");
		if((fh=fopen("/tmp/logomask.chan","r"))!=NULL)
		{
			if(fgets(tstr, BUFSIZE, fh))
			{
				TrimString(tstr);
				if((cpt1=strchr(tstr,' '))!=NULL)
					*cpt1=0;
			}
			fclose(fh);
			if(strlen(tstr))
			{
				strcpy(actchan,tstr);
			}

			if((fh=fopen(CFG_FILE,"r"))!=NULL)
			{
				found=0;
				while(fgets(tstr, BUFSIZE, fh) && !found)
				{
					TrimString(tstr);
					if(strlen(tstr))
					{
						if(strstr(tstr,actchan)!=NULL)
						{
							mask=1;
							nmsk=0;
							cpt2=strstr(tstr,",MC");
							if((cpt1=strchr(tstr,','))!=NULL)
							{
								while(cpt1)
								{
									valid[nmsk]=0;
									if(cpt2 && sscanf(cpt2+1,"MC%8X",&mp.lpixel)==1)
									{
										cpt2=strchr(cpt2+1,',');
									}
									else
									{
										make_color(BLACK, &mp);
									}
									for(i=0; i<8 && cpt1; i++)
									{
										cpt1++;
										if(sscanf(cpt1,"%d,%d,%d,%d",&xxp,&xxw,&yyp,&yyw)==4)
										{
											xp[nmsk][i]=xxp;
											xw[nmsk][i]=xxw;
											yp[nmsk][i]=yyp;
											yw[nmsk][i]=yyw;
											mc[nmsk].lpixel=mp.lpixel;
											found=1;
											valid[nmsk]=1;
										}
										for(j=0; j<4 && cpt1; j++)
										{
											cpt1=strchr(cpt1+1,',');
										}
									}
									if(valid[nmsk])
									{
										nmsk++;
									}
								}
							}
						}
					}
				}
				fclose(fh);
			}
		}

		if(!nmsk)
		{
			nmsk=1;
			valid[0]=1;
		}
		mask=nmsk;
		for(m=0; m<MAX_MASK; m++)
		{
			if(valid[m])
			{
				xxp=xp[m][pmode];
				xxw=xw[m][pmode];				
				yyp=yp[m][pmode];
				yyw=yw[m][pmode];
				tp.lpixel=mc[m].lpixel;
				RenderBox(xxp, yyp, xxp+xxw, yyp+yyw, FILL, &tp);
				if(m==amsk)
					RenderBox(xxp, yyp, xxp+xxw, yyp+yyw, GRID, make_color(LBLUE,&tp));
				for(i=0;i<=yyw;i++)
				{
					j=(yyp+i)*fix_screeninfo.line_length+(xxp<<2);
					if((j+(xxw<<2))<fix_screeninfo.line_length*var_screeninfo.yres)
					{
						memcpy(lfb+j, lbb+j, xxw<<2);
					}
				}
			}
		}
		time(&t1);
		while((rc!=KEY_EXIT) && (rc!=KEY_OK))
		{
			rc=GetRCCode();
			if((rc!=-1) && (rc!=KEY_EXIT) && (rc!=KEY_OK))
			{
				time(&t1);
				move=0;
				xxp=xp[amsk][pmode];
				xxw=xw[amsk][pmode];
				yyp=yp[amsk][pmode];
				yyw=yw[amsk][pmode];
				lpix.lpixel=mc[amsk].lpixel;
				switch(rc)
				{
					case KEY_LEFT:
					if(lc==KEY_LEFT)
					{
						xs+=0.3;
					}
					else
					{
						xs=1.0;
					}
					if(kmode)
					{
						if(xxp>0)
						{
							changed=1;
							xxp-=xs;
						}
					}
					else
					{
						if(xxw>6)
						{
							changed=1;
							xxw-=xs;
						}
					}
					move=1;
					break;
				
					case KEY_RIGHT:
					if((xxp+xxw)<(fix_screeninfo.line_length-1))
					{
						changed=1;
						if(lc==KEY_RIGHT)
						{
							xs+=0.3;
						}
						else
						{
							xs=1.0;
						}
						if(kmode)
						{
							xxp+=xs;
						}
						else
						{
							xxw+=xs;
						}
					}
					move=1;
					break;
				
					case KEY_UP:
					if(lc==KEY_UP)
					{
						ys+=0.2;
					}
					else
					{
						ys=1.0;
					}
					if(kmode)
					{
						if(yyp>0)
						{
							changed=1;
							yyp-=ys;
						}
					}
					else
					{
						if(yyw>6)
						{
							changed=1;
							yyw-=ys;
						}
					}
					move=1;
					break;
				
					case KEY_DOWN:
					if((yyp+yyw)<(var_screeninfo.yres-1))
					{
						changed=1;
						if(lc==KEY_DOWN)
						{
							ys+=0.2;
						}
						else
						{
							ys=1.0;
						}
						if(kmode)
						{
							yyp+=ys;
						}
						else
						{
							yyw+=ys;
						}
					}
					move=1;
					break;
				
					case KEY_RED:
						changed=1;
						RenderBox(xxp, yyp, xxp+xxw, yyp+yyw, FILL, make_color(TRANSP,&tp));
						for(i=0;i<=yyw;i++)
						{
							j=(yyp+i)*fix_screeninfo.line_length+(xxp<<2);
							if(((j+(xxw<<2)))<fix_screeninfo.line_length*var_screeninfo.yres)
							{
								memcpy(lfb+j, lbb+j, xxw<<2);
							}
						}
						valid[amsk]=0;
						nmsk--;
						kmode=1;
						if(nmsk)
						{
							todo=2;
							amsk=-1;
							for(m=0; m<MAX_MASK && amsk<0; m++)
							{
								if(valid[m])
								{
									amsk=m;
									xxp=xp[amsk][pmode];
									xxw=xw[amsk][pmode];
									yyp=yp[amsk][pmode];
									yyw=yw[amsk][pmode];
									lpix.lpixel=mc[amsk].lpixel;
								}
							}	
						}
						else
						{
							todo=mask=0;
						}
					break;
				
					case KEY_GREEN:
						if(nmsk<MAX_MASK)
						{
							todo=2;
							changed=1;
							kmode=1;
							amsk=-1;
							for(m=0; amsk<0 && m<MAX_MASK; m++)
							{
								if(!valid[m])
								{
									amsk=m;
									valid[amsk]=1;
									nmsk++;
									cmc[amsk]=BLACK;
									make_color(BLACK, &mc[amsk]);
									for(i=0; i<8; i++)
									{
										xp[amsk][i]=(1280-40)/2;
										xw[amsk][i]=40;
										yp[amsk][i]=(720-20)/2;
										yw[amsk][i]=20;
									}
									xxp=xp[amsk][pmode];
									xxw=xw[amsk][pmode];
									yyp=yp[amsk][pmode];
									yyw=yw[amsk][pmode];
									lpix.lpixel=mc[amsk].lpixel;
								}
							}
						}	
					break;
					
					case KEY_PAGEUP:
						if(nmsk>1)
						{
							m=amsk+1;
							if(m>=MAX_MASK)
							{
								m=0;
							}
							while(!valid[m])
							{
								if(++m>=MAX_MASK)
								{
									m=0;
								}
							}
							RenderBox(xxp, yyp, xxp+xxw, yyp+yyw, FILL, &lpix);
							amsk=m;
							xxp=xp[amsk][pmode];
							xxw=xw[amsk][pmode];
							yyp=yp[amsk][pmode];
							yyw=yw[amsk][pmode];
							lpix.lpixel=mc[amsk].lpixel;
						}
					break;
				
					case KEY_PAGEDOWN:
						if(nmsk>1)
						{
							m=amsk-1;
							if(m<0)
							{
								m=MAX_MASK-1;
							}
							while(!valid[m])
							{
								if(--m<0)
								{
									m=MAX_MASK;
								}
							}
							RenderBox(xxp, yyp, xxp+xxw, yyp+yyw, FILL, &lpix);
							amsk=m;
							xxp=xp[amsk][pmode];
							xxw=xw[amsk][pmode];
							yyp=yp[amsk][pmode];
							yyw=yw[amsk][pmode];
							lpix.lpixel=mc[amsk].lpixel;
						}
					break;

					case KEY_YELLOW:
						kmode=0;
					break;
				
					case KEY_BLUE:
						kmode=1;
					break;
					
					case KEY_1:
						if(nmsk)
						{
							if(mc[amsk].cpixel.rd < 0xF0)
								mc[amsk].cpixel.rd+=0x10;
							else
								mc[amsk].cpixel.rd=0xFF;
							changed=1;
						}
					break;

					case KEY_4:
						if(nmsk)
						{
							mc[amsk].cpixel.rd=0x80;
							changed=1;
						}
					break;

					case KEY_7:
						if(nmsk)
						{
							if(mc[amsk].cpixel.rd > 0x0F)
								mc[amsk].cpixel.rd-=0x10;
							else
								mc[amsk].cpixel.rd=0x00;
							changed=1;
						}
					break;

					case KEY_2:
						if(nmsk)
						{
							if(mc[amsk].cpixel.gn < 0xF0)
								mc[amsk].cpixel.gn+=0x10;
							else
								mc[amsk].cpixel.gn=0xFF;
							changed=1;
						}
					break;

					case KEY_5:
						if(nmsk)
						{
							mc[amsk].cpixel.gn=0x80;
							changed=1;
						}
					break;

					case KEY_8:
						if(nmsk)
						{
							if(mc[amsk].cpixel.gn > 0x0F)
								mc[amsk].cpixel.gn-=0x10;
							else
								mc[amsk].cpixel.gn=0x00;
							changed=1;
						}
					break;

					case KEY_3:
						if(nmsk)
						{
							if(mc[amsk].cpixel.bl < 0xF0)
								mc[amsk].cpixel.bl+=0x10;
							else
								mc[amsk].cpixel.bl=0xFF;
							changed=1;
						}
					break;

					case KEY_6:
						if(nmsk)
						{
							mc[amsk].cpixel.bl=0x80;
							changed=1;
						}
					break;

					case KEY_9:
						if(nmsk)
						{
							if(mc[amsk].cpixel.bl > 0x0F)
								mc[amsk].cpixel.bl-=0x10;
							else
								mc[amsk].cpixel.bl=0x00;
							changed=1;
						}
					break;

					case KEY_VOLUMEDOWN:
						if(nmsk)
						{
							if(mc[amsk].cpixel.tr < 0xF8)
								mc[amsk].cpixel.tr+=0x08;
							else
								mc[amsk].cpixel.tr=0xFF;
							changed=1;
						}
					break;

					case KEY_VOLUMEUP:
						if(nmsk)
						{
							if(mc[amsk].cpixel.tr > 0x08)
								mc[amsk].cpixel.tr-=0x08;
							else
								mc[amsk].cpixel.tr=0x00;
							changed=1;
						}
					break;

					case KEY_MUTE:
						if(nmsk)
						{
							if(++cmc[amsk]>LTURQUOISE)
								cmc[amsk]=BLACK;
							make_color(cmc[amsk], &mc[amsk]);
							changed=1;
						}
					break;

					case KEY_HELP:
						help_changed=1;
					break;
				}
				lc=rc;
				lpix.lpixel=mc[amsk].lpixel;
				if(mask || todo==2)
				{
					RenderBox(xp[amsk][pmode], yp[amsk][pmode], xp[amsk][pmode]+xw[amsk][pmode], yp[amsk][pmode]+yw[amsk][pmode], FILL, make_color(TRANSP, &tp));
					for(i=0;i<=yw[amsk][pmode];i++)
					{
						j=(yp[amsk][pmode]+i)*fix_screeninfo.line_length+(xp[amsk][pmode]<<2);
						if((j+(xw[amsk][pmode]<<2))<fix_screeninfo.line_length*var_screeninfo.yres)
						{
							memcpy(lfb+j, lbb+j, (xw[amsk][pmode]+1)<<2);
						}
					}
					xp[amsk][pmode]=xxp;
					xw[amsk][pmode]=xxw;
					yp[amsk][pmode]=yyp;
					yw[amsk][pmode]=yyw;
					for(m=0; mask && m<MAX_MASK; m++)
					{
						if(valid[m])
						{
							xxp=xp[m][pmode];
							xxw=xw[m][pmode];
							yyp=yp[m][pmode];
							yyw=yw[m][pmode];
							tp.lpixel=mc[m].lpixel;
							RenderBox(xxp, yyp, xxp+xxw, yyp+yyw, FILL, ((m==amsk) && move)?make_color(TRANSP, &tp):&tp);
							if(m==amsk)
								RenderBox(xxp, yyp, xxp+xxw, yyp+yyw, GRID, make_color((kmode)?LBLUE:LYELLOW,&tp));
							for(i=0;i<=yyw;i++)
							{
								j=(yyp+i)*fix_screeninfo.line_length+(xxp<<2);
								if((j+(xxw<<2))<fix_screeninfo.line_length*var_screeninfo.yres)
								{
									memcpy(lfb+j, lbb+j, (xxw+1)<<2);
								}
							}
						}
					}
				}
			}
			time(&t2);
			if((t2-t1)>1)
			{
				xs=1.0;
				ys=1.0;
				tsy=120;
				if(move)
				{
					RenderBox(xp[amsk][pmode], yp[amsk][pmode], xp[amsk][pmode]+xw[amsk][pmode], yp[amsk][pmode]+yw[amsk][pmode], FILL, &mc[amsk]);
					RenderBox(xp[amsk][pmode], yp[amsk][pmode], xp[amsk][pmode]+xw[amsk][pmode], yp[amsk][pmode]+yw[amsk][pmode], GRID, make_color((kmode)?LBLUE:LYELLOW,&tp));
				}
				move=0;
				if(help_changed)
				{
					help^=1;
				}
				if(help)
				{
					RenderBox(tsx,tsy,tsx+txw,tsy+21*tdy,FILL,make_color(TRANSP, &tp));
					if(nmsk)
						RenderBox(xp[amsk][pmode], yp[amsk][pmode], xp[amsk][pmode]+xw[amsk][pmode], yp[amsk][pmode]+yw[amsk][pmode], GRID, make_color((kmode)?LBLUE:LYELLOW, &tp));
					RenderString("Maskensteuerung", tsx, tsy+=tdy, txw, LEFT, tsz, tcol);
					RenderString("Blau  :  Umschalten auf Positionseinstellung", tsx, tsy+=tdy, txw, LEFT, tsz, tcol);
					RenderString("Gelb  :  Umschalten auf Größeneinstellung", tsx, tsy+=tdy, txw, LEFT, tsz, tcol);
					RenderString("Grün  :  Maske hinzufügen", tsx, tsy+=tdy, txw, LEFT, tsz, tcol);
					RenderString("Rot    :  Maske löschen", tsx, tsy+=tdy, txw, LEFT, tsz, tcol);
					RenderString("PgUp :  nächste Maske auswählen", tsx, tsy+=tdy, txw, LEFT, tsz, tcol);
					RenderString("PgDn :  vorherige Maske auswählen", tsx, tsy+=tdy, txw, LEFT, tsz, tcol);
					RenderString("Maskenfarbe", tsx, tsy+=(2*tdy), txw, LEFT, tsz, tcol);
					RenderString("Mute  :  Maskenfarbe aus Vorgabe auswählen", tsx, tsy+=tdy, txw, LEFT, tsz, tcol);
					RenderString("1,4,7   :  Farbton Rot erhöhen, auf Mitte setzen, verringern", tsx, tsy+=tdy, txw, LEFT, tsz, tcol);
					RenderString("2,5,8  :  Farbton Grün erhöhen, auf Mitte setzen, verringern", tsx, tsy+=tdy, txw, LEFT, tsz, tcol);
					RenderString("3,6,9  :  Farbton Blau erhöhen, auf Mitte setzen, verringern", tsx, tsy+=tdy, txw, LEFT, tsz, tcol);
					RenderString("Vol +  :  Transparenz erhöhen", tsx, tsy+=tdy, txw, LEFT, tsz, tcol);
					RenderString("Vol -  :  Transparenz verringern", tsx, tsy+=tdy, txw, LEFT, tsz, tcol);
					RenderString("Allgemein", tsx, tsy+=(2*tdy), txw, LEFT, tsz, tcol);
					RenderString("?        :  Hilfetext ein/ausschalten", tsx, tsy+=tdy, txw, LEFT, tsz, tcol);
					RenderString("Exit    :  Abbrechen", tsx, tsy+=tdy, txw, LEFT, tsz, tcol);
					RenderString("OK     :  Speichern und Beenden", tsx, tsy+=tdy, txw, LEFT, tsz, tcol);
				}
				else
				{
					if(help_changed)
					{
						RenderBox(tsx, tsy, tsx+txw, tsy+21*tdy, FILL, make_color(TRANSP, &tp));
						if(nmsk)
							RenderBox(xp[amsk][pmode], yp[amsk][pmode], xp[amsk][pmode]+xw[amsk][pmode], yp[amsk][pmode]+yw[amsk][pmode], GRID, make_color((kmode)?LBLUE:LYELLOW, &tp));
					}
				}
				help_changed=0;
				memcpy(lfb, lbb, fix_screeninfo.line_length*var_screeninfo.yres);
			}
		}
		if(rc==KEY_EXIT)
		{
			changed=0;
			todo=0;
		}
		if(rc==KEY_OK && changed)
		{
			if((fh2=fopen("/tmp/logomask.conf","w"))!=NULL)
			{
				fh=fopen(CFG_FILE,"r");
				while(fh && fgets(tstr, BUFSIZE, fh))
				{
					TrimString(tstr);
					if(strlen(tstr))
					{
						if(strstr(tstr,actchan)==NULL)
						{
							fprintf(fh2,"%s\n",tstr);
						}
					}
				}
				if(fh)
				{
					fclose(fh);
				}
				if(todo)
				{
					fprintf(fh2,"%s",actchan);
					for(j=0; j<MAX_MASK; j++)
					{
						if(valid[j])
						{
							for(i=0; i<8; i++)
							{
								fprintf(fh2,",%d,%d,%d,%d",xp[j][i],xw[j][i],yp[j][i],yw[j][i]);
							}
						}
					}
					for(j=0; j<MAX_MASK; j++)
					{
						if(valid[j])
						{
							fprintf(fh2,",MC%08X",mc[j].lpixel);
						}
					}
					fprintf(fh2,",\n");
				}
				fclose(fh2);
				remove(CFG_FILE);
				system("mv /tmp/logomask.conf /var/tuxbox/config/logomask.conf");
			}
		}		
		free(lbb);
		munmap(lfb, fix_screeninfo.smem_len);

		close(fb);
		CloseRC();
		remove("/tmp/.logomask_kill");
		remove("/tmp/logomaskset.*");
		system("logomask &");
		return 0;
}
Exemple #15
0
LcdFontRenderClass::~LcdFontRenderClass()
{
	FTC_Manager_Done(cacheManager);
	FT_Done_FreeType(library);
}
Exemple #16
0
int main (int argc, char **argv)
{
int tv,cols=25,debounce=25,tmo=0;
char ttl[]="Input";
int dloop=1,keys=0,frame=1,mask=0,bhelp=0;
char *title=NULL, *format=NULL, *defstr=NULL, *aptr, *rptr; 
unsigned int alpha;

		if(argc==1)
		{
			ShowUsage();
			return 0;
		}

		dloop=0;
		for(tv=1; !dloop && tv<argc; tv++)
		{
			aptr=argv[tv];
			if((rptr=strchr(aptr,'='))!=NULL)
			{
				rptr++;
				if(strstr(aptr,"l=")!=NULL)
				{
					format=rptr;
					dloop=Transform_Msg(format)==0;
				}
				else
				{
					if(strstr(aptr,"t=")!=NULL)
					{
						title=rptr;
						dloop=Transform_Msg(title)==0;
					}
					else
					{
						if(strstr(aptr,"d=")!=NULL)
						{
							defstr=rptr;
							dloop=Transform_Msg(defstr)==0;
						}
						else
						{
							if(strstr(aptr,"m=")!=NULL)
							{
								if(sscanf(rptr,"%d",&mask)!=1)
								{
									dloop=1;
								}
							}
							else
							{
								if(strstr(aptr,"f=")!=NULL)
								{
									if(sscanf(rptr,"%d",&frame)!=1)
									{
										dloop=1;
									}
								}
								else
								{
									if(strstr(aptr,"k=")!=NULL)
									{
										if(sscanf(rptr,"%d",&keys)!=1)
										{
											dloop=1;
										}
									}
									else
									{
										if(strstr(aptr,"h=")!=NULL)
										{
											if(sscanf(rptr,"%d",&bhelp)!=1)
											{
												dloop=1;
											}
										}
										else
										{
											if(strstr(aptr,"c=")!=NULL)
											{
												if(sscanf(rptr,"%d",&cols)!=1)
												{
													dloop=1;
												}
											}
											else
											{
												if(strstr(aptr,"o=")!=NULL)
												{
													if(sscanf(rptr,"%d",&tmo)!=1)
													{
														dloop=1;
													}
												}
												else
												{
													dloop=2;
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
			switch (dloop)
			{
				case 1:
					printf("input <param error: %s>\n",aptr);
					return 0;
					break;
				
				case 2:
					printf("input <unknown command: %s>\n\n",aptr);
					ShowUsage();
					return 0;
					break;
			}
		}
		if(!format)
		{
			printf("input <missing format string>\n");
			return 0;
    	}
		if(!title)
		{
			title=ttl;
		}

		if((buffer=calloc(BUFSIZE+1, sizeof(char)))==NULL)
		{
			printf(NOMEM);
			return 0;
		}

		if(((sx=Read_Neutrino_Cfg("screen_StartX"))<0)&&((sx=Read_Neutrino_Cfg("/enigma/plugins/needoffsets/left"))<0))
			sx=80;
		
		if(((ex=Read_Neutrino_Cfg("screen_EndX"))<0)&&((ex=Read_Neutrino_Cfg("/enigma/plugins/needoffsets/right"))<0))
			ex=620;

		if(((sy=Read_Neutrino_Cfg("screen_StartY"))<0)&&((sy=Read_Neutrino_Cfg("/enigma/plugins/needoffsets/top"))<0))
			sy=80;

		if(((ey=Read_Neutrino_Cfg("screen_EndY"))<0)&&((ey=Read_Neutrino_Cfg("/enigma/plugins/needoffsets/bottom"))<0))
			ey=505;

		if(Read_Neutrino_Cfg("rounded_corners")>0)
			radius=9;
		else
			radius=0;

		fb = open(FB_DEVICE, O_RDWR);
#ifdef HAVE_DBOX_HARDWARE
		ioctl(fb, AVIA_GT_GV_GET_BLEV, &alpha);
#endif
		InitRC();

	//init framebuffer

		if(ioctl(fb, FBIOGET_FSCREENINFO, &fix_screeninfo) == -1)
		{
			printf("input <FBIOGET_FSCREENINFO failed>\n");
			return 0;
		}
		if(ioctl(fb, FBIOGET_VSCREENINFO, &var_screeninfo) == -1)
		{
			printf("input <FBIOGET_VSCREENINFO failed>\n");
			return 0;
		}
		
		if(!(lfb = (unsigned char*)mmap(0, fix_screeninfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0)))
		{
			printf("input <mapping of Framebuffer failed>\n");
			return 0;
		}
		
	//init fontlibrary

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

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

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

		if((error = FTC_Manager_Lookup_Face(manager, FONT, &face)))
		{
			printf("input <FTC_Manager_Lookup_Face failed with Errorcode 0x%.2X>\n", error);
			FTC_Manager_Done(manager);
			FT_Done_FreeType(library);
			munmap(lfb, fix_screeninfo.smem_len);
			return 0;
		}

		use_kerning = FT_HAS_KERNING(face);
#ifdef FT_NEW_CACHE_API
	desc.face_id = (char*)FONT;
#else
		desc.font.face_id = FONT;
#endif
#if FREETYPE_MAJOR == 2 && FREETYPE_MINOR == 0
		desc.image_type = ftc_image_mono;
#else
		desc.flags = FT_LOAD_MONOCHROME;
#endif

	//init backbuffer

		if(!(lbb = malloc(var_screeninfo.xres*var_screeninfo.yres)))
		{
			printf("input <allocating of Backbuffer failed>\n");
			FTC_Manager_Done(manager);
			FT_Done_FreeType(library);
			munmap(lfb, fix_screeninfo.smem_len);
			return 0;
		}

		if(!(obb = malloc(var_screeninfo.xres*var_screeninfo.yres)))
		{
			printf("input <allocating of Backbuffer failed>\n");
			FTC_Manager_Done(manager);
			FT_Done_FreeType(library);
			free(lbb);
			munmap(lfb, fix_screeninfo.smem_len);
			return 0;
		}

		memcpy(lbb, lfb, var_screeninfo.xres*var_screeninfo.yres);
		memcpy(obb, lfb, var_screeninfo.xres*var_screeninfo.yres);

		startx = sx /*+ (((ex-sx) - 620)/2)*/;
		starty = sy /* + (((ey-sy) - 505)/2)*/;



	signal(SIGINT, quit_signal);
	signal(SIGTERM, quit_signal);
	signal(SIGQUIT, quit_signal);

	//main loop
	put_instance(instance=get_instance()+1);
	printf("%s\n",inputd(format, title, defstr, keys, frame, mask, bhelp, cols, tmo, debounce));
	put_instance(get_instance()-1);

	memcpy(lfb, obb, var_screeninfo.xres*var_screeninfo.yres);

	free(buffer);

	FTC_Manager_Done(manager);
	FT_Done_FreeType(library);

	free(lbb);
	free(obb);
#ifdef HAVE_DBOX_HARDWARE
	ioctl(fb, AVIA_GT_GV_SET_BLEV, alpha);
#endif
	munmap(lfb, fix_screeninfo.smem_len);

	close(fb);
	CloseRC();

	return 1;
}
Exemple #17
0
int
main(int argc,
     char** argv)
{
  FT_Face     face;
  long        max_bytes = CACHE_SIZE * 1024;
  char*       test_string = NULL;
  int         size = FACE_SIZE;
  int         max_iter = 0;
  double      max_time = BENCH_TIME;
  int         compare_cached = 0;
  int         i;

  while ( 1 )
  {
    int  opt;


    opt = getopt( argc, argv, "Cc:f:m:pr:s:t:b:" );

    if ( opt == -1 )
      break;

    switch ( opt )
    {
    case 'C':
      compare_cached = 1;
      break;
    case 'c':
      max_iter = atoi( optarg );
      break;
    case 'f':
      load_flags = strtol( optarg, NULL, 16 );
      break;
    case 'm':
      max_bytes = atoi( optarg );
      max_bytes *= 1024;
      break;
    case 'p':
      preload = 1;
      break;
    case 'r':
      render_mode = (FT_Render_Mode)atoi( optarg );
      if ( render_mode >= FT_RENDER_MODE_MAX )
        render_mode = FT_RENDER_MODE_NORMAL;
      break;
    case 's':
      size = atoi( optarg );
      if ( size <= 0 )
        size = 1;
      else if ( size > 500 )
        size = 500;
      break;
    case 't':
      max_time = atof( optarg );
      break;
    case 'b':
      test_string = optarg;
      break;
    default:
      usage();
      break;
    }
  }

  argc -= optind;
  argv += optind;

  if ( argc != 1 )
    usage();

  if ( FT_Init_FreeType( &lib ) )
  {
    fprintf( stderr, "could not initialize font library\n" );

    return 1;
  }

  filename = *argv;

  if ( get_face( &face ) )
    goto Exit;

  if ( FT_IS_SCALABLE( face ) )
  {

    if ( FT_Set_Pixel_Sizes( face, size, size ) )
    {
      fprintf( stderr, "failed to set pixel size to %d\n", size );

      return 1;
    }
  }
  else
    size = face->available_sizes[0].width;

  FTC_Manager_New( lib, 0, 0, max_bytes, face_requester, face, &cache_man );

  font_type.face_id = (FTC_FaceID) 1;
  font_type.width   = (short) size;
  font_type.height  = (short) size;
  font_type.flags   = load_flags;

  for ( i = 0; i < N_FT_BENCH; i++ )
  {
    btest_t   test;
    FT_ULong  flags;


    if ( !TEST( 'a' + i ) )
      continue;

    test.title       = NULL;
    test.bench       = NULL;
    test.cache_first = 0;
    test.user_data   = NULL;

    switch ( i )
    {
    case FT_BENCH_LOAD_GLYPH:
      test.title = "Load";
      test.bench = test_load;
      benchmark( face, &test, max_iter, max_time );

      if ( compare_cached )
      {
        test.cache_first = 1;

        test.title = "Load (image cached)";
        test.bench = test_image_cache;
        benchmark( face, &test, max_iter, max_time );

        test.title = "Load (sbit cached)";
        test.bench = test_sbit_cache;
        benchmark( face, &test, max_iter, max_time );
      }
      break;
    case FT_BENCH_LOAD_ADVANCES:
      test.user_data = &flags;

      test.title = "Load_Advances (Normal)";
      test.bench = test_load_advances;
      flags      = FT_LOAD_DEFAULT;
      benchmark( face, &test, max_iter, max_time );

      test.title  = "Load_Advances (Fast)";
      test.bench  = test_load_advances;
      flags       = FT_LOAD_TARGET_LIGHT;
      benchmark( face, &test, max_iter, max_time );
      break;
    case FT_BENCH_RENDER:
      test.title = "Render";
      test.bench = test_render;
      benchmark( face, &test, max_iter, max_time );
      break;
    case FT_BENCH_GET_GLYPH:
      test.title = "Get_Glyph";
      test.bench = test_get_glyph;
      benchmark( face, &test, max_iter, max_time );
      break;
    case FT_BENCH_GET_CBOX:
      test.title = "Get_CBox";
      test.bench = test_get_cbox;
      benchmark( face, &test, max_iter, max_time );
      break;
    case FT_BENCH_CMAP:
      {
        bcharset_t  charset;


        get_charset( face, &charset );
        if ( charset.code )
        {
          test.user_data = (void*)&charset;


          test.title = "Get_Char_Index";
          test.bench = test_get_char_index;

          benchmark( face, &test, max_iter, max_time );

          if ( compare_cached )
          {
            test.cache_first = 1;

            test.title = "Get_Char_Index (cached)";
            test.bench = test_cmap_cache;
            benchmark( face, &test, max_iter, max_time );
          }

          free( charset.code );
        }
      }
      break;
    case FT_BENCH_CMAP_ITER:
      test.title = "Iterate CMap";
      test.bench = test_cmap_iter;
      benchmark( face, &test, max_iter, max_time );
      break;
    case FT_BENCH_NEW_FACE:
      test.title = "New_Face";
      test.bench = test_new_face;
      benchmark( face, &test, max_iter, max_time );
      break;
    case FT_BENCH_EMBOLDEN:
      test.title = "Embolden";
      test.bench = test_embolden;
      benchmark( face, &test, max_iter, max_time );
      break;
    }
  }

Exit:
  /* The following is a bit subtle: When we call FTC_Manager_Done, this
   * normally destroys all FT_Face objects that the cache might have created
   * by calling the face requester.
   *
   * However, this little benchmark uses a tricky face requester that
   * doesn't create a new FT_Face through FT_New_Face but simply pass a
   * pointer to the one that was previously created.
   *
   * If the cache manager has been used before, the call to FTC_Manager_Done
   * discards our single FT_Face.
   *
   * In the case where no cache manager is in place, or if no test was run,
   * the call to FT_Done_FreeType releases any remaining FT_Face object
   * anyway.
   */
  if ( cache_man )
    FTC_Manager_Done( cache_man );

  FT_Done_FreeType( lib );

  return 0;
}
Exemple #18
0
int main (int argc, char **argv)
{
	unsigned int margin_left_F, digit_width, margin_top_t, font_size, margin_top_box, margin_top_d, digits, secs_width, adj_height;
	int i = 0;
	int j = 0;
	int w = 0;
	int ms = 0;
	int mw = 0;
	int loop = 1;
	unsigned int newmail = 0;
	unsigned int mailgfx = 0;
	int xdir = 1, ydir = 1;
	double xstep = 1, ystep = 1; 
	double csx, cex, csy, cey;
	time_t atim;
	struct tm *ltim;
	char *aptr,*rptr;
	char dstr[2] = {0,0};
	FILE *tfh;

		printf("Clock / SSaver Version %s\n",CL_VERSION);

		for (i = 1; i < argc; i++)
		{
			if (!strncmp(argv[i], "-ss", 3))
			{
				ssaver = 1;
				continue;
			}
		}

		if (ssaver)
		{
			time(&atim);
			srand((unsigned int)atim);
			ReadConf(SCFG_FILE);
		}
		else
		{
			ReadConf(CCFG_FILE);
		}

		for (i = 1; i < argc; i++)
		{
			aptr=argv[i];
			if((rptr=strchr(aptr,'='))!=NULL)
			{
				rptr++;
				if (!ssaver)
				{
					if(strstr(aptr,"X=")!=NULL)
					{
						if(sscanf(rptr,"%d",&j)==1)
						{
							xpos=j;
						}
					}	
					if(strstr(aptr,"Y=")!=NULL)
					{
						if(sscanf(rptr,"%d",&j)==1)
						{
							ypos=j;
						}
					}
					if(strstr(aptr,"MAIL=")!=NULL)
					{
						if(sscanf(rptr,"%d",&j)==1)
						{
							mail=j;
						}
					}
				}
				if(strstr(aptr,"DATE=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						show_date=j;
					}
				}
				if(strstr(aptr,"BIG=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						big=(j)?1:0;
					}
				}
				if(strstr(aptr,"SEC=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						show_sec=j;
					}
				}
				if(strstr(aptr,"BLINK=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						blink=j;
					}
				}
				if(strstr(aptr,"SLOW=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						if(!j)
						{
							j=1;
						}
						slow=j;
					}
				}
				if(strstr(aptr,"FCOL=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						fcol=j;
					}
				}
				if(strstr(aptr,"BCOL=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						bcol=j;
					}
				}
			}
		}
		if((sx=Read_Neutrino_Cfg("screen_StartX"))<0)
			sx=80;
		
		if((ex=Read_Neutrino_Cfg("screen_EndX"))<0)
			ex=620;

		if((sy=Read_Neutrino_Cfg("screen_StartY"))<0)
			sy=80;

		if((ey=Read_Neutrino_Cfg("screen_EndY"))<0)
			ey=505;
		
		fb = open(FB_DEVICE, O_RDWR);

		if(ioctl(fb, FBIOGET_FSCREENINFO, &fix_screeninfo) == -1)
		{
			printf("Clock / SSaver <FBIOGET_FSCREENINFO failed>\n");
			return -1;
		}
		if(ioctl(fb, FBIOGET_VSCREENINFO, &var_screeninfo) == -1)
		{
			printf("Clock / SSaver <FBIOGET_VSCREENINFO failed>\n");
			return -1;
		}
		if(!(lfb = (unsigned char*)mmap(0, fix_screeninfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0)))
		{
			printf("Clock / SSaver <mapping of Framebuffer failed>\n");
			return -1;
		}

	//init fontlibrary

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

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

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

		if((error = FTC_Manager_Lookup_Face(manager, FONT, &face)))
		{
			printf("Clock / SSaver <FTC_Manager_Lookup_Face failed with Errorcode 0x%.2X>\n", error);
			FTC_Manager_Done(manager);
			FT_Done_FreeType(library);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}

		use_kerning = FT_HAS_KERNING(face);

#ifdef FT_NEW_CACHE_API
		desc.face_id = FONT;
#else
		desc.font.face_id = FONT;
#endif
#if FREETYPE_MAJOR  == 2 && FREETYPE_MINOR == 0
		desc.image_type = ftc_image_mono;
#else
		desc.flags = FT_LOAD_MONOCHROME;
#endif

		//init backbuffer

		if(!(lbb = malloc(var_screeninfo.xres*var_screeninfo.yres)))
		{
			printf("Clock / SSaver <allocating of Backbuffer failed>\n");
			FTC_Manager_Done(manager);
			FT_Done_FreeType(library);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}

		if (!slow)
			slow=1;

		if (slow>10)
			slow=10;

		if (fcol > MAXCOL && !(ssaver == 1 && fcol == 99))
			fcol = 2;
		if (bcol > 3 && !(bcol == 10))
			bcol = 1;

		if (ssaver)
		{
			memset(lbb, col[bcol], var_screeninfo.xres*var_screeninfo.yres);
			memset(lfb, col[bcol], var_screeninfo.xres*var_screeninfo.yres);
		}
		else
			memset(lbb, 0, var_screeninfo.xres*var_screeninfo.yres);

		if (big)			//grosse Schrift (time/date)
		{
			margin_left_F = 3;			// 3
			digit_width = 14;			// 14
			margin_top_t = 26;			// 26
			font_size = BIG;			// 40
			margin_top_box = 30;		// 30
			margin_top_d = 60;			// 60
		}
		else
		{
			margin_left_F = 7;			//7  Abstand links
			digit_width = 12;			//12 Ziffernblockbreite
			margin_top_t = 19;			//19 Abstand "TimeString"-Unterkante von oben
			font_size = MED;			//30 Schriftgroesse
			margin_top_box = 20;		//20 Abstand Renderbox von oben
			margin_top_d = 40;			//40 Abstand "DateString" von oben
		}
		digits = 0;
		secs_width = 0;
		startx = sx;
		starty = sy;
		mw = (big) ? 42 : 36;			//mailwidth
		adj_height = 1 * (!big && !show_date); //max steprange == 3, so we need always a top/bottom margin of >=3

		if (!show_sec && !show_date)
		{
			digits = 3;				//3 Platzhalter ':ss'
			secs_width = digits * digit_width;
		}

		if (ssaver)
		{
			xpos = rand() %480 + 10;
			ypos = rand() %460 + 10;	
			xdir *= (rand() &1) == 0 ? -1 : 1;
			ydir *= (rand() &1) == 0 ? -1 : 1;
			xstep/=(double)slow;
			ystep/=(double)slow;
			if (fcol == 99)
			{
				cCol = 1;
				Change_Col(&fcol, &bcol);
			}
			InitRC();
		}

	while (loop)
	{
		if (ssaver)
			usleep(15000L);
		else
		{
			usleep(150000L);
			newmail = 0;
			if(mail && ExistFile(MAIL_FILE))
			{
				if((tfh = fopen(MAIL_FILE,"r")) != NULL)
				{
					if(fgets(tstr, 511, tfh))
					{
						if(sscanf(tstr, "%d", &i))
						{
							newmail = i;
						}
					}
					fclose(tfh);
				}
			}
		}

		time(&atim);
		ltim=localtime(&atim);
		if (show_sec)
		{
			sprintf(tstr,"%02d:%02d:%02d", ltim->tm_hour, ltim->tm_min, ltim->tm_sec);
		}
		else
		{
			if (blink)
				sprintf(tstr,"   %02d%c%02d", ltim->tm_hour, (ltim->tm_sec & 1)? ' ' : ':', ltim->tm_min);
			else
				sprintf(tstr,"   %02d:%02d", ltim->tm_hour, ltim->tm_min);
		}

		if (!ssaver)
		{
			if (((int)xpos >= mw) || (!show_sec))
			{
				ms = (int)xpos + ((show_sec) ? 0 : mw) - mw;	//mail left
			}
			else
			{
				ms = (int)xpos + 100 + 20 * big;		//mail right
			}
			//paint Backgroundcolor to clear digit
			RenderBox(xpos+secs_width, ypos, xpos+secs_width+100+20*big, ypos+margin_top_box + adj_height, FILL, col[bcol]);
		}

		if (ssaver)
		{
			xpos += xstep * (double)xdir;
			ypos += ystep * (double)ydir;

			csx = xpos + secs_width;
			csy = ypos;
			cex = xpos + secs_width + 100 + 20 * big;
			cey = ypos + margin_top_t + 2 * (1 + big) + (margin_top_box * show_date) + adj_height;

			if ((int)csx < 0 || (sx + (int)cex) > ex)
			{
				if (cCol)
					Change_Col(&fcol, &bcol);
				xdir *= -1;
				xpos += xstep * (double)xdir;
				csx = xpos + secs_width;
				cex = xpos + secs_width + 100 + 20 * big;
				xstep = rand() &3;
				if (!xstep)
				{
					xstep = 1;
				}
				xstep /= (double)slow;
			}
			if ((int)csy < 0 || (sy + (int)cey) > ey)
			{
				if (cCol)
					Change_Col(&fcol, &bcol);
				ydir *= -1;
				ypos += ystep * (double)ydir;
				csy = ypos;
				cey = ypos + margin_top_t + 2 * (1 + big) + (margin_top_box * show_date) + adj_height;	
				ystep = rand() &3;
				if (!ystep)
				{
					ystep = 1;
				}
				ystep /= (double)slow;
			}
			RenderBox(csx, csy, cex, cey, FILL, col[bcol]);
		}

		for (i = digits; i < strlen(tstr); i++)
		{
			*dstr = tstr[i];
			RenderString(dstr, xpos - margin_left_F + (i * digit_width), ypos + margin_top_t, 30, CENTER, font_size, col[fcol]);
		}

		if (show_date)
		{
			sprintf(tstr, "%02d.%02d.%02d", ltim->tm_mday, ltim->tm_mon + 1, ltim->tm_year - 100);
			if (!ssaver)
			{
			//Backgroundbox color Date
			RenderBox(xpos, ypos + margin_top_box, xpos + 100 + 20 * big, ypos + margin_top_d, FILL, col[bcol]);
			}
			for(i = 0; i < strlen(tstr); i++)
			{
				*dstr = tstr[i];
				RenderString(dstr, xpos - margin_left_F + (i * digit_width), ypos + margin_top_d - 2 - (2 * big), 30, CENTER, font_size, col[fcol]);
			}
		}

		if (ssaver)
		{
			w = 100 + 20 * big + ((show_sec) ? 0 : - secs_width);
			for (i = 0; i <= ((show_date) ? 20 : 10) * (2 + big) + adj_height; i++)
			{
				j = (starty + (int)ypos + i) * var_screeninfo.xres + (int)xpos + ((show_sec) ? 0 : secs_width) + startx;
				if ((j + w) < var_screeninfo.xres * var_screeninfo.yres)
				{
					memcpy(lfb+j, lbb+j, w);
				}
			}
		}
		else
		{
			if (newmail > 0)
			{
				mailgfx = 1;

				//Background mail, left site from clock
				RenderBox(ms, ypos, ms+mw, ypos+margin_top_box + adj_height, FILL, col[bcol]); //bcol

				if(!(ltim->tm_sec & 1))
				{
					RenderBox (ms+8, ypos+5+(1+big), ms+mw-8, ypos+margin_top_box+adj_height-2-(3*big), GRID,	col[fcol]);
					DrawLine  (ms+8, ypos+5+(1+big), ms+mw-8, ypos+margin_top_box+adj_height-2-(3*big),			col[fcol]);
					DrawLine  (ms+8, ypos+margin_top_box+adj_height-2-(3*big), ms+mw-8, ypos+5+(1+big),			col[fcol]);
					DrawLine  (ms+(9+1*big), ypos+4+(1+big), ms+(mw/2), ypos+1,                  				col[fcol]);
					DrawLine  (ms+(9+1*big), ypos+5+(1+big), ms+(mw/2), ypos+2,                  				col[fcol]);
					DrawLine  (ms+(mw/2), ypos+1, ms+mw-(9+1*big), ypos+4+(1+big),               				col[fcol]);
					DrawLine  (ms+(mw/2), ypos+2, ms+mw-(9+1*big), ypos+5+(1+big),               				col[fcol]);
				}
				else
				{
					sprintf(tstr,"%d",newmail);
					RenderString(tstr, ms, ypos+margin_top_t, mw, CENTER, font_size, col[fcol]);
				}
			}
			else
			{
				if (mailgfx > 0)
					RenderBox(ms, ypos, ms+mw, ypos + margin_top_box + adj_height, FILL, (!show_date || show_sec) ? TRANSP : col[bcol]);
				else
					ms=(int)xpos;
			}

			w = 100 + 20 * big + ((mailgfx) ? ((show_sec) ? mw : 0) : - secs_width);
			for (i=0; i <= ((show_date) ? 20 : 10) * (2 + big) + adj_height; i++)
			{
				j = (starty + (int)ypos + i) * var_screeninfo.xres + ( ((ms < (int)xpos) ? ms : (int)xpos) + ((show_sec) ? 0 : ((mailgfx) ? 0 : secs_width)) ) + startx;			
				if ((j + w) < var_screeninfo.xres * var_screeninfo.yres)
				{
					memcpy(lfb+j, lbb+j, w);
				}
			}
			if (newmail == 0 && mailgfx > 0)
				mailgfx = 0;
		}

		if (++loop > 10)
		{
			if ( (ssaver && (RCKeyPressed() || ExistFile("/tmp/.ssaver_kill")))
				|| (!ssaver && ExistFile("/tmp/.clock_kill")) )
				loop = 0;
		}
	}


/****************************
 * close down Clock / SSaver
 ****************************/
	if (ssaver)
	{
		memset(lfb, 0, var_screeninfo.xres*var_screeninfo.yres);
		remove("/tmp/.ssaver_kill");
		CloseRC();
	}
	else
	{
		memset(lbb, 0, var_screeninfo.xres*var_screeninfo.yres);
		remove("/tmp/.clock_kill");
		for (i=0; i <= ((show_date) ? 20 : 10) * (2 + big) + adj_height; i++)
		{
			j=(starty+(int)ypos+i)*var_screeninfo.xres+((ms<(int)xpos)?ms:(int)xpos)+((show_sec)?0:((mailgfx)?0:secs_width))+startx;
			if((j+100+20*big+((mail)?mw:0))<var_screeninfo.xres*var_screeninfo.yres)
			{
				memcpy(lfb+j, lbb+j, w);
			}
		}
	}

	FTC_Manager_Done(manager);
	FT_Done_FreeType(library);

	free(lbb);
	munmap(lfb, fix_screeninfo.smem_len);

	close(fb);

	return 0;
}
Exemple #19
0
int main (int argc, char **argv)
{
	int tv,index,i,j,k,w,cmct=CMCT,cmc=CMC,trnspi=TRANSP,trnsp=0,found,loop=1,x0,x1,x2,x3,x4,x5,x6,x7,ms,mw,newmail=0;
	time_t atim;
	struct tm *ltim;
	char *aptr,*rptr;
	char dstr[2]={0,0};
	FILE *tfh;

		printf("Clock Version %s\n",CL_VERSION);
		
		ReadConf();
	
		for(i=1; i<argc; i++)
		{
			aptr=argv[i];
			if((rptr=strchr(aptr,'='))!=NULL)
			{
				rptr++;
				if(strstr(aptr,"X=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						xpos=j;
					}
				}
				if(strstr(aptr,"Y=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						ypos=j;
					}
				}
				if(strstr(aptr,"DATE=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						sdat=j;
					}
				}
				if(strstr(aptr,"BIG=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						big=j;
					}
				}
				if(strstr(aptr,"SEC=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						secs=j;
					}
				}
				if(strstr(aptr,"FCOL=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						fcol=j;
					}
				}
				if(strstr(aptr,"BCOL=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						bcol=j;
					}
				}
				if(strstr(aptr,"MAIL=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						mail=j;
					}
				}
			}
		}
		if((sx=Read_Neutrino_Cfg("screen_StartX"))<0)
			sx=80;
		
		if((ex=Read_Neutrino_Cfg("screen_EndX"))<0)
			ex=620;

		if((sy=Read_Neutrino_Cfg("screen_StartY"))<0)
			sy=80;

		if((ey=Read_Neutrino_Cfg("screen_EndY"))<0)
			ey=505;
			
		for(index=CMCST; index<=CMH; index++)
		{
			sprintf(tstr,"menu_%s_alpha",menucoltxt[index-1]);
			if((tv=Read_Neutrino_Cfg(tstr))>=0)
				tr[index-1]=(tv<<8);

			sprintf(tstr,"menu_%s_blue",menucoltxt[index-1]);
			if((tv=Read_Neutrino_Cfg(tstr))>=0)
				bl[index-1]=(tv+(tv<<8));

			sprintf(tstr,"menu_%s_green",menucoltxt[index-1]);
			if((tv=Read_Neutrino_Cfg(tstr))>=0)
				gn[index-1]=(tv+(tv<<8));

			sprintf(tstr,"menu_%s_red",menucoltxt[index-1]);
			if((tv=Read_Neutrino_Cfg(tstr))>=0)
				rd[index-1]=(tv+(tv<<8));
		}
		
		fb = open(FB_DEVICE, O_RDWR);

		if(ioctl(fb, FBIOGET_FSCREENINFO, &fix_screeninfo) == -1)
		{
			printf("Clock <FBIOGET_FSCREENINFO failed>\n");
			return -1;
		}
		if(ioctl(fb, FBIOGET_VSCREENINFO, &var_screeninfo) == -1)
		{
			printf("Clock <FBIOGET_VSCREENINFO failed>\n");
			return -1;
		}
		
		if(ioctl(fb, FBIOGETCMAP, &colormap) == -1)
		{
			printf("Clock <FBIOGETCMAP failed>\n");
			return -1;
		}

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

	//init fontlibrary

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

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

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

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

		use_kerning = FT_HAS_KERNING(face);

#ifdef FT_NEW_CACHE_API
		desc.face_id = FONT;
#else
		desc.font.face_id = FONT;
#endif
#if FREETYPE_MAJOR  == 2 && FREETYPE_MINOR == 0
		desc.image_type = ftc_image_mono;
#else
		desc.flags = FT_LOAD_MONOCHROME;
#endif

	//init backbuffer

		if(!(lbb = malloc(var_screeninfo.xres*var_screeninfo.yres)))
		{
			printf("Clock <allocating of Backbuffer failed>\n");
			FTC_Manager_Done(manager);
			FT_Done_FreeType(library);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}

		memset(lbb, 0, var_screeninfo.xres*var_screeninfo.yres);

		startx = sx;
		starty = sy;
		mw=(big)?40:30;

	while(loop)
	{
		usleep(150000L);
		newmail=0;
		if(mail && ExistFile(MAIL_FILE))
		{
			if((tfh=fopen(MAIL_FILE,"r"))!=NULL)
			{
				if(fgets(tstr,511,tfh))
				{
					if(sscanf(tstr,"%d",&i))
					{
						newmail=i;
					}
				}
				fclose(tfh);
			}
		}
		ioctl(fb, FBIOGETCMAP, &colormap);
		found=0;
		trnsp=0;
		for(i=colormap.start;i<colormap.len && found!=7;i++)
		{
			if(!colormap.red[i] && !colormap.green[i] && !colormap.blue[i] && !colormap.transp[i])
			{
				cmc=i;
				found|=1;
			}
			if(colormap.red[i]>=0xF000 && colormap.green[i]>=0xF000  && colormap.blue[i]>=0xF000 && !colormap.transp[i])
			{
				cmct=i;
				found|=2;
			}
			if(colormap.transp[i]>trnsp)
			{
				trnspi=i;
				trnsp=colormap.transp[i];
				found|=4;
			}
		}	

		if(big)
		{
			x0=3;
			x1=14;
			x2=26;
			x3=BIG;
			x4=30;
			x5=60;
		}
		else
		{
			x0=7;
			x1=12;
			x2=18;
			x3=MED;
			x4=18;
			x5=40;
		}
		x6=0;
		x7=0;
		time(&atim);
		ltim=localtime(&atim);
		if(secs)
		{
			sprintf(tstr,"%02d:%02d:%02d",ltim->tm_hour,ltim->tm_min,ltim->tm_sec);
		}
		else
		{
			sprintf(tstr,"   %02d%c%02d",ltim->tm_hour,(ltim->tm_sec & 1)?':':' ',ltim->tm_min);
			if(!sdat)
			{
				x6=3;
				x7=36+4*big;
			}
		}
		if((xpos>=mw)||(!secs))
		{
			ms=xpos+((secs)?0:36+4*big)-mw;
		}
		else
		{
			ms=xpos+100+20*big;
		}
		k=((ms>xpos)&&mail)?mw:0;
		RenderBox(xpos+x7, ypos, xpos+x7+100+20*big, ypos+x2+2*(1+big), FILL, (bcol==0)?trnspi:((bcol==1)?cmc:cmct));
		for(i=x6; i<strlen(tstr); i++)
		{
			*dstr=tstr[i];
			RenderString(dstr, xpos-x0+(i*x1), ypos+x2, 30, CENTER, x3, (fcol==0)?trnspi:((fcol==2)?cmct:cmc));
		}

		if(sdat)
		{
			sprintf(tstr,"%02d.%02d.%02d",ltim->tm_mday,ltim->tm_mon+1,ltim->tm_year-100);
			RenderBox(xpos, ypos+x4, xpos+100+20*big, ypos+x5, FILL, (bcol==0)?trnspi:((bcol==1)?cmc:cmct));
			for(i=0; i<strlen(tstr); i++)
			{
				*dstr=tstr[i];
				RenderString(dstr, xpos-x0+(i*x1), ypos+x5-2-2*big, 30, CENTER, x3, (fcol==0)?trnspi:((fcol==2)?cmct:cmc));
			}
		}
		if(mail)
		{
			if(newmail)
			{
				RenderBox(ms, ypos, ms+mw, ypos+x2+2*(1+big), FILL, (bcol==0)?trnspi:((bcol==1)?cmc:cmct));
				if(!(ltim->tm_sec & 1))
				{
					RenderBox(ms+5, ypos+5+(1+big), ms+mw-5, ypos+x2+(1+big)-2, GRID, (fcol==0)?trnspi:((fcol==1)?cmc:cmct));
					DrawLine(ms+5, ypos+5+(1+big), ms+mw-5, ypos+x2+(1+big)-2, (fcol==0)?trnspi:((fcol==1)?cmc:cmct));
					DrawLine(ms+5, ypos+x2+(1+big)-2, ms+mw-5, ypos+5+(1+big), (fcol==0)?trnspi:((fcol==1)?cmc:cmct));
					DrawLine(ms+5, ypos+5+(1+big), ms+((mw-2)/2), ypos+2, (fcol==0)?trnspi:((fcol==1)?cmc:cmct));
					DrawLine(ms+6, ypos+6+(1+big), ms+((mw-2)/2)+1, ypos+3, (fcol==0)?trnspi:((fcol==1)?cmc:cmct));
					DrawLine(ms+((mw-2)/2), ypos+2, ms+mw-5, ypos+5+(1+big), (fcol==0)?trnspi:((fcol==1)?cmc:cmct));
					DrawLine(ms+((mw-2)/2)+1, ypos+3, ms+mw-6, ypos+6+(1+big), (fcol==0)?trnspi:((fcol==1)?cmc:cmct));
				}
				else
				{
					sprintf(tstr,"%d",newmail);
					RenderString(tstr, ms, ypos+x2, mw, CENTER, x3, (fcol==0)?trnspi:((fcol==2)?cmct:cmc));
				}
			}
			else
			{
				if(!sdat || secs)
				{
					RenderBox(ms+((ms>(xpos+100))?1:0), ypos, ms+mw-((k)?0:1), ypos+x2+2*(1+big), FILL, trnspi);
				}
			}
		}
		else
		{
			ms=xpos;
		}
		
		w=100+20*big+((mail)?5*big+((secs)?mw:0):0)+k-((k&&!sdat)?mw:0);
		for(i=0;i<=((sdat)?40:20)*(1+big);i++)
		{
			j=(starty+ypos+i)*var_screeninfo.xres+((ms<xpos)?ms:xpos)+startx;
			if((j+w)<var_screeninfo.xres*var_screeninfo.yres)
			{
				memcpy(lfb+j, lbb+j, w);
			}
		}
		if(++loop>5)
		{
			if(ExistFile("/tmp/.clock_kill"))
			{
				loop=0;
			}
		}	
	}	

	cmct=0;
	cmc=0;
	for(i=colormap.start;i<colormap.len;i++)
	{
		if(colormap.transp[i]>cmct)
		{
			cmc=i;
			cmct=colormap.transp[i];
		}
	}
	memset(lbb, cmc, var_screeninfo.xres*var_screeninfo.yres);
	for(i=0;i<=((sdat)?40:20)*(1+big);i++)
	{
		j=(starty+ypos+i)*var_screeninfo.xres+((ms<xpos)?ms:xpos)+startx;
		if((j+100+20*big+((mail)?mw:0))<var_screeninfo.xres*var_screeninfo.yres)
		{
			memcpy(lfb+j, lbb+j, w);
		}
	}
	FTC_Manager_Done(manager);
	FT_Done_FreeType(library);

	free(lbb);
	munmap(lfb, fix_screeninfo.smem_len);

	close(fb);
	remove("/tmp/.clock_kill");
	return 0;
}
Exemple #20
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;
}
Exemple #21
0
int main (int argc, char **argv)
{
    int index,index2,tv,found=0;
    int dloop=1, rcc=-1, flsh=0, cupd=0;
    char rstr[BUFSIZE], *rptr, *aptr;
    time_t tm1,tm2;
    unsigned int alpha;
    clock_t tk1=0;
    FILE *fh;

    if(argc<2)
    {
        ShowUsage();
        return 0;
    }
    dloop=0;
    for(tv=1; !dloop && tv<argc; tv++)
    {
        aptr=argv[tv];
        if((rptr=strchr(aptr,'='))!=NULL)
        {
            rptr++;
            if(strstr(aptr,"size=")!=NULL)
            {
                if(sscanf(rptr,"%d",&size)!=1)
                {
                    dloop=1;
                }
            }
            else
            {
                if(strstr(aptr,"title=")!=NULL)
                {
                    title=strdup(rptr);
                    CatchTabs(title);
                    if(strcmp(title,"none")==0)
                    {
                        header=0;
                    }
                    /*
                    						tpos=0;
                    						while(*rptr)
                    						{
                    							if(*rptr!='~')
                    							{
                    								nstr[tpos]=*rptr;
                    							}
                    							else
                    							{
                    								rc=*(rptr+1);
                    								found=0;
                    								for(i=0; i<sizeof(sc) && !found; i++)
                    								{
                    									if(rc==sc[i])
                    									{
                    										rc=tc[i];
                    										found=1;
                    									}
                    								}
                    								if(found)
                    								{
                    									nstr[tpos]=rc;
                    									++rptr;
                    								}
                    								else
                    								{
                    									nstr[tpos]=*rptr;
                    								}
                    							}
                    							++tpos;
                    							++rptr;
                    						}
                    						nstr[tpos]=0;
                    						title=strdup(nstr);
                    */
                }
                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
                                                            {
                                                                dloop=2;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        switch (dloop)
        {
        case 1:
            printf("msgbox <param error: %s>\n",aptr);
            return 0;
            break;

        case 2:
            printf("msgbox <unknown command: %s>\n\n",aptr);
            ShowUsage();
            return 0;
            break;
        }
    }
    /*for(tv=0; tv<buttons; tv++)
    {
    	printf("%cButton %d: %s\n",(tv==selection-1)?'>':' ',tv+1,butmsg[tv]);
    }
    return 0;*/

    if(!echo)
    {
        printf("\nmsgbox  Message-Box Version %.2f\n",M_VERSION);
    }
    if(!buttons)
    {
        butmsg[0]=strdup("OK");
        buttons=1;
    }
    /*
    		if(selection>buttons)
    		{
    			printf("msgbox <param error: default=%d>\n",selection);
    			return 0;
    		}
    */
    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("msgbox <param error: default=%d>\n",selection);
            return 0;
        }
    }
    else
    {
        for(tv=0; tv<buttons && !selection; tv++)
        {
            if(strlen(butmsg[tv]))
            {
                selection=tv+1;
            }
        }
    }
    /*		for(tv=0; selection!=rbutt[tv] && tv<buttons; tv++);

    		if(tv>=buttons)
    		{
    			selection=1;
    		}
    */
    if(!title)
    {
        title=strdup("Information");
    }
    if((line_buffer=calloc(BUFSIZE+1, sizeof(char)))==NULL)
    {
        printf(NOMEM);
        return -1;
    }

    if((debounce=Read_Neutrino_Cfg("repeat_genericblocker"))<0)
        debounce=200;

    if((rblock=Read_Neutrino_Cfg("repeat_blocker"))<0)
        rblock=50;

    if(((sx=Read_Neutrino_Cfg("screen_StartX"))<0)&&((sx=Read_Neutrino_Cfg("/enigma/plugins/needoffsets/left"))<0))
        sx=80;

    if(((ex=Read_Neutrino_Cfg("screen_EndX"))<0)&&((ex=Read_Neutrino_Cfg("/enigma/plugins/needoffsets/right"))<0))
        ex=620;

    if(((sy=Read_Neutrino_Cfg("screen_StartY"))<0)&&((sy=Read_Neutrino_Cfg("/enigma/plugins/needoffsets/top"))<0))
        sy=80;

    if(((ey=Read_Neutrino_Cfg("screen_EndY"))<0)&&((ey=Read_Neutrino_Cfg("/enigma/plugins/needoffsets/bottom"))<0))
        ey=505;

    if(Read_Neutrino_Cfg("rounded_corners")>0)
        radius=9;
    else
        radius=0;

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

    fb = open(FB_DEVICE, O_RDWR);
#ifdef HAVE_DBOX_HARDWARE
    ioctl(fb, AVIA_GT_GV_GET_BLEV, &alpha);
#endif
    rc = open(RC_DEVICE, O_RDONLY);
    fcntl(rc, F_SETFL, (fcntl(rc, F_GETFL) | O_EXCL) | O_NONBLOCK);

    //init framebuffer

    if(ioctl(fb, FBIOGET_FSCREENINFO, &fix_screeninfo) == -1)
    {
        printf("msgbox <FBIOGET_FSCREENINFO failed>\n");
        return -1;
    }
    if(ioctl(fb, FBIOGET_VSCREENINFO, &var_screeninfo) == -1)
    {
        printf("msgbox <FBIOGET_VSCREENINFO failed>\n");
        return -1;
    }

    if(ioctl(fb, FBIOGETCMAP, &oldcmap) == -1)
    {
        printf("msgbox <FBIOGETCMAP failed>\n");
        return -1;
    }
    /*
    		fh=fopen("/tmp/cmap.log","w");
    		fprintf(fh,"Start: %d, LEN: %d\n",oldcmap.start,oldcmap.len);
    		for(tv=0; tv<256; tv++)
    		{
    			fprintf(fh,"%02d %04x %04x %04x %04x\n",tv,oldcmap.red[tv],oldcmap.green[tv],oldcmap.blue[tv],oldcmap.transp[tv]);
    		}
    		fclose(fh);
    */
    for(index=0; index<8; index++)
    {
        sprintf(rstr,"menu_%s_alpha",menucoltxt[index]);
        if((tv=Read_Neutrino_Cfg(rstr))>=0)
            for(index2=0; index2<7; index2++)
                otr[menucolval[index]+index2]=(tv<<8);
    }

    ord[FLASH]=ord[CMCT];
    ogn[FLASH]=ogn[CMCT];
    obl[FLASH]=obl[CMCT];
    otr[FLASH]=otr[CMCT];
    /*
    		fh=fopen("/tmp/cmap2.log","w");
    		fprintf(fh,"Start: %d, LEN: %d\n",oldcmap.start,oldcmap.len);
    		for(tv=0; tv<256; tv++)
    		{
    			fprintf(fh,"%02d %04x %04x %04x %04x\n",tv,oldcmap.red[tv],oldcmap.green[tv],oldcmap.blue[tv],oldcmap.transp[tv]);
    		}
    		fclose(fh);

    */
    /*
    {
    int i;
    printf("unsigned short rd[] = {");
    for(i=CMCST; i<=CMH;i++)
    printf("0x%02x<<8, ",(ord[i]>>8)&0xFF);
    printf("\nunsigned short gn[] = {");
    for(i=CMCST; i<=CMH;i++)
    printf("0x%02x<<8, ",(ogn[i]>>8)&0xFF);
    printf("\nunsigned short bl[] = {");
    for(i=CMCST; i<=CMH;i++)
    printf("0x%02x<<8, ",(obl[i]>>8)&0xFF);
    printf("\nunsigned short tr[] = {");
    for(i=CMCST; i<=CMH;i++)
    printf("0x%02x<<8, ",(otr[i]>>8)&0xFF);
    printf("\n");
    }
    return 0;
    */

    if(ioctl(fb, FBIOPUTCMAP, &oldcmap) == -1)
    {
        printf("msgbox <FBIOPUTCMAP failed>\n");
        return -1;
    }

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

    //init fontlibrary

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

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

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

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

    use_kerning = FT_HAS_KERNING(face);

#ifdef FT_NEW_CACHE_API
    desc.face_id = FONT;
#else
    desc.font.face_id = FONT;
#endif

#if FREETYPE_MAJOR == 2 && FREETYPE_MINOR == 0
    desc.image_type = ftc_image_mono;
#else
    desc.flags = FT_LOAD_MONOCHROME;
#endif

    //init backbuffer

    if(!(lbb = malloc(var_screeninfo.xres*var_screeninfo.yres)))
    {
        printf("msgbox <allocating of Backbuffer failed>\n");
        FTC_Manager_Done(manager);
        FT_Done_FreeType(library);
        munmap(lfb, fix_screeninfo.smem_len);
        return -1;
    }

    if(!(obb = malloc(var_screeninfo.xres*var_screeninfo.yres)))
    {
        printf("msgbox <allocating of Backbuffer failed>\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)))
    {
        printf("msgbox <allocating of Backbuffer failed>\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)))
    {
        printf("msgbox <allocating of Backbuffer failed>\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, lfb, var_screeninfo.xres*var_screeninfo.yres);
    }
    else
    {
        memset(ibb, TRANSP, var_screeninfo.xres*var_screeninfo.yres);
    }
    if(mute==2)
    {
        memcpy(hbb, lfb, var_screeninfo.xres*var_screeninfo.yres);
    }
    else
    {
        memset(hbb, TRANSP, var_screeninfo.xres*var_screeninfo.yres);
    }
    if(refresh & 2)
    {
        memcpy(obb, lfb, var_screeninfo.xres*var_screeninfo.yres);
    }
    else
    {
        memset(obb, TRANSP, var_screeninfo.xres*var_screeninfo.yres);
    }

    startx = sx /*+ (((ex-sx) - 620)/2)*/;
    starty = sy /* + (((ey-sy) - 505)/2)*/;


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

    put_instance(instance=get_instance()+1);

    show_txt(0);
//FBEnterWord( 100, 100, 100,20,CMCT);
//rc=RC_HOME;

    time(&tm1);
    tm2=tm1;
    tk1=clock()/(CLOCKS_PER_SEC/1000);
#ifdef HAVE_DREAMBOX_HARDWARE
    ClearKeys();
#endif

    //main loop

    while((rcc!=RC_HOME) && (rcc!=RC_OK) && ((timeout==-1)||((tm2-tm1)<timeout)))
    {
        rcc=GetRCCode();
        if(rcc!=-1)
        {
            time(&tm1);
        }
        else
        {
            if(++cupd>10)
            {
                if(cyclic)
                {
                    show_txt(0);
                    cupd=0;
                }
            }
            usleep(100000L);
        }
        if(mute && rcc==RC_MUTE)
        {
            hide^=1;
            show_txt(0);
            usleep(500000L);
            while(GetRCCode()!=-1);
            if(hide)
            {
                if((fh=fopen(HDF_FILE,"w"))!=NULL)
                {
                    fprintf(fh,"hidden");
                    fclose(fh);
                }
            }
            else
            {
                remove(HDF_FILE);
            }
        }
        if((!hide) && (rcc!=RC_HOME) && (rcc!=RC_OK))
        {
            switch(rcc)
            {
            case RC_LEFT:
                if(!hide && (--selection<1))
                {
                    selection=buttons;
                }
                show_txt(1);
                break;

            case RC_RIGHT:
                if(!hide && (++selection>buttons))
                {
                    selection=1;
                }
                show_txt(1);
                break;

            case RC_UP:
                if(!hide && ((selection-=bpline)<1))
                {
                    selection=1;
                }
                show_txt(1);
                break;

            case RC_DOWN:
                if(!hide && ((selection+=bpline)>buttons))
                {
                    selection=buttons;
                }
                show_txt(1);
                break;

            default:
                if(++flsh==7)
                {
                    flsh=0;
                    flash^=1;

                    ord[FLASH]=(flash)?ord[CMC]:ord[CMCT];
                    ogn[FLASH]=(flash)?ogn[CMC]:ogn[CMCT];
                    obl[FLASH]=(flash)?obl[CMC]:obl[CMCT];
                    otr[FLASH]=(flash)?otr[CMC]:otr[CMCT];
                    ioctl(fb, FBIOPUTCMAP, &oldcmap);
                }
                break;
            }
        }
        time(&tm2);
        if(hide)
        {
            rcc=-1;
        }
    }
    if((type!=1) || (rcc!=RC_OK))
    {
        selection=0;
    }


    //cleanup

    // clear Display
//	memset(lbb, TRANSP, var_screeninfo.xres*var_screeninfo.yres);
//	memcpy(lfb, lbb, var_screeninfo.xres*var_screeninfo.yres);

    memcpy(lfb, obb, var_screeninfo.xres*var_screeninfo.yres);
    munmap(lfb, fix_screeninfo.smem_len);
#ifdef HAVE_DBOX_HARDWARE
    ioctl(fb, AVIA_GT_GV_SET_BLEV, alpha);
#endif
    close(fb);
    free(lbb);

    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);

    close(rc);

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

    if(selection)
    {
        return rbutt[selection-1];
    }
    return 0;
}
int main (int argc, char **argv)
{
	int index=0,cindex=0,mainloop=1,dloop=1,tv, spr, resolution;
	char tstr[BUFSIZE]={0}, *rptr;
	PLISTENTRY pl;

	printf("%s Version %.2f\n", __plugin__, SH_VERSION);
	for(tv=1; tv<argc; tv++)
	{
		if(*argv[tv]=='/')
		{
			strcpy(CFG_FILE,argv[tv]);
		}
	}

	//init framebuffer before 1st scale2res
	fb = open(FB_DEVICE, O_RDWR);
#ifdef MARTII
	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_WRITE|PROT_READ, MAP_SHARED, fb, 0)))
	{
		perror(__plugin__ " <mapping of Framebuffer>\n");
		return -1;
	}

	// read config
	ixw=scale2res(600), iyw=scale2res(680), xoffs=scale2res(13);
	if((line_buffer=calloc(BUFSIZE+1, sizeof(char)))==NULL)
	{
		printf(NOMEM);
		return -1;
	}

	if((trstr=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(trstr,"screen_StartX_%s", spres[spr]);
	else
		sprintf(trstr,"screen_StartX_%s_%d", spres[spr], resolution);
	if((sx=Read_Neutrino_Cfg(trstr))<0)
		sx=scale2res(100);

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

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

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

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

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

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

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

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

	mtmo = Read_Neutrino_Cfg("timing.menu");
	if (mtmo < 0)
		mtmo = 0;

	cindex=CMC;
	for(index=COL_MENUCONTENT_PLUS_0; index<=COL_MENUCONTENT_PLUS_3; index++)
	{
		rd[index]=rd[cindex]+25;
		gn[index]=gn[cindex]+25;
		bl[index]=bl[cindex]+25;
		tr[index]=tr[cindex];
		cindex=index;
	}
	sprintf(trstr,"infobar_alpha");
	if((tv=Read_Neutrino_Cfg(trstr))>=0)
		tr[COL_SHADOW_PLUS_0]=255-(float)tv*2.55;

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

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

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

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

	InitRC();
	//InitVFD();

	//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;
	}

	memset(&menu,0,sizeof(MENU));
	if(Check_Config())
	{
		printf("%s <Check_Config> Unable to read Config %s\n", __plugin__, CFG_FILE);
		FTC_Manager_Done(manager);
		FT_Done_FreeType(library);
		munmap(lfb, fix_screeninfo.smem_len);
		Clear_List(&menu,-1);
		free(line_buffer);
		return -1;
	}

	if((error = FTC_Manager_LookupFace(manager, FONT, &face)))
	{
		printf("%s <FTC_Manager_LookupFace failed with Errorcode 0x%.2X, trying default font>\n", __plugin__, error);
		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;
	printf("%s <FTC_Manager_LookupFace Font \"%s\" loaded>\n", __plugin__, desc.face_id);

	use_kerning = FT_HAS_KERNING(face);
	desc.flags = FT_LOAD_RENDER | FT_LOAD_FORCE_AUTOHINT;

	//init backbuffer
#if defined(HAVE_SPARK_HARDWARE) || defined(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))))
	{
		printf("%s <allocating of Backbuffer failed>\n", __plugin__);
		FTC_Manager_Done(manager);
		FT_Done_FreeType(library);
		munmap(lfb, fix_screeninfo.smem_len);
		return -1;
	}
#endif

	//lbb=lfb;
#if defined(HAVE_SPARK_HARDWARE) || defined(HAVE_DUCKBOX_HARDWARE)
	FillRect(0, 0, DEFAULT_XRES, DEFAULT_YRES, 0);
	blit();
#else
	memset(lbb, TRANSP, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
	memcpy(lfb, lbb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
	//blit();
#endif

	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);

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

	index=0;
	if(vfd)
	{
		sprintf(tstr,"%s -c", VFD);
		system(tstr);
	}
	ShowInfo(&menu, 1);
	//main loop
	menu.act_entry=0;
	if(Get_Menu(1))
	{
		printf("%s <unable to create menu>\n", __plugin__);
		FTC_Manager_Done(manager);
		FT_Done_FreeType(library);
		munmap(lfb, fix_screeninfo.smem_len);
		return -1;
	}
	cindex=0;

	put_instance(instance=get_instance()+1);

	while(mainloop)
	{
		cindex=Get_Selection(&menu);
		dloop=1;
		switch(cindex)
		{
			case -1:
				mainloop=0;
				break;

			case 0:
				mainloop=Menu_Up(&menu);
				break;

			case 1:
				pl=menu.list[menu.act_entry];
				switch (pl->type)
				{
					case TYP_MENU:
						menu.act_header=pl->headerpos;
						menu.lastheaderentrys[menu.act_header]=menu.act_entry;
						menu.headerwait[menu.act_header]=pl->message!=NULL;
						if(menu.headerwait[menu.act_header])
							{
								strcpy(tstr,pl->entry);
								if((rptr=strxchr(tstr,','))!=NULL)
								{
									*rptr=0;
								}
								ShowMessage(tstr, pl->message, 0);
							}
						Get_Menu(0);
						menu.act_entry=0;
						break;

					case TYP_EXECUTE:
						if((rptr=strxchr(pl->entry,','))!=NULL)
						{
							strcpy(tstr,pl->entry);
							rptr=strxchr(tstr,',');
							*rptr=0;
							rptr=strxchr(pl->entry,',');
							rptr++;
							if(pl->stay)
							{
								if(pl->stay==1)
								{
									if(pl->message)
									{
										if(strlen(pl->message))
										{
											ShowMessage(tstr, pl->message, 0);
										}
									}
									else
									{
										ShowMessage(tstr, "Bitte warten", 0);
									}
								}
								else
								{
#if defined(HAVE_SPARK_HARDWARE) || defined(HAVE_DUCKBOX_HARDWARE)
									FillRect(0, 0, DEFAULT_XRES, DEFAULT_YRES, 0);
									blit();
#else
									memset(lbb, TRANSP, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
									memcpy(lfb, lbb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
									//blit();
#endif
								}

								if(*(rptr+strlen(rptr)-1)=='&')
								{
									*(rptr+strlen(rptr)-1)=0;
								}
							}
							else
							{
								if(*(rptr+strlen(rptr)-1)!='&')
								{
									sprintf(tstr,"%s &",rptr);
									rptr=tstr;
								}
							}
							CloseRC();
							system(rptr);
							InitRC();

							mainloop= pl->stay==1;
							if(pl->stay==1)
							{
								Get_Menu(1);
							}
						}
						break;
				}
		}
	}

	//cleanup
	Clear_List(&menu,-1);

	FTC_Manager_Done(manager);
	FT_Done_FreeType(library);
#if 0
	if(strlen(url))
	{
		sprintf(line_buffer,"/sbin/rdate -s %s > /dev/null &",url);
		system(line_buffer);
	}
#endif
	CloseRC();
	//CloseVFD();

	free(line_buffer);
	free(trstr);

	// clear Display
#if defined(HAVE_SPARK_HARDWARE) || defined(HAVE_DUCKBOX_HARDWARE)
	FillRect(0, 0, DEFAULT_XRES, DEFAULT_YRES, 0);
	blit();
#else
	memset(lbb, TRANSP, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
	memcpy(lfb, lbb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
	//blit();
#endif
	munmap(lfb, fix_screeninfo.smem_len);

	close(fb);
#if !defined(MARTII) && !defined(HAVE_SPARK_HARDWARE) && !defined(HAVE_DUCKBOX_HARDWARE)
	free(lbb);
#endif

	put_instance(get_instance()-1);

	return 0;
}
Exemple #23
0
int main (int argc, char **argv)
{
	int tv,index,i,j,cmct=CMCT,cmc=CMC,trnspi=TRANSP,trnsp=0,found,loop=1,first=1,x0,x1,x2,x3,x4,x5,x6,x7;
	int xdir=1, ydir=1;
	double xstep=1, ystep=1; 
	double csx, cex, csy, cey;
	time_t atim;
	struct tm *ltim;
	char *aptr,*rptr;
	char dstr[2]={0,0};

		printf("SSaver Version %s\n",CL_VERSION);
		
		ReadConf();
	
		for(i=1; i<argc; i++)
		{
			aptr=argv[i];
			if((rptr=strchr(aptr,'='))!=NULL)
			{
				rptr++;
				if(strstr(aptr,"DATE=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						sdat=j;
					}
				}
				if(strstr(aptr,"BIG=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						big=(j)?1:0;
					}
				}
				if(strstr(aptr,"SEC=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						secs=j;
					}
				}
				if(strstr(aptr,"SLOW=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						if(!j)
						{
							j=1;
						}
						slow=j;
					}
				}
				if(strstr(aptr,"FCOL=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						fcol=j;
					}
				}
				if(strstr(aptr,"BCOL=")!=NULL)
				{
					if(sscanf(rptr,"%d",&j)==1)
					{
						bcol=j;
					}
				}
			}
		}
		if((sx=Read_Neutrino_Cfg("screen_StartX"))<0)
			sx=80;
		
		if((ex=Read_Neutrino_Cfg("screen_EndX"))<0)
			ex=620;

		if((sy=Read_Neutrino_Cfg("screen_StartY"))<0)
			sy=80;

		if((ey=Read_Neutrino_Cfg("screen_EndY"))<0)
			ey=505;
		
		if(!slow)
		{
			slow=1;
		}	
		if(slow>10)
		{
			slow=10;
		}
		
		xpos=ex/2;
		ypos=ey/2;	
		for(index=CMCST; index<=CMH; index++)
		{
			sprintf(tstr,"menu_%s_alpha",menucoltxt[index-1]);
			if((tv=Read_Neutrino_Cfg(tstr))>=0)
				tr[index-1]=(tv<<8);

			sprintf(tstr,"menu_%s_blue",menucoltxt[index-1]);
			if((tv=Read_Neutrino_Cfg(tstr))>=0)
				bl[index-1]=(tv+(tv<<8));

			sprintf(tstr,"menu_%s_green",menucoltxt[index-1]);
			if((tv=Read_Neutrino_Cfg(tstr))>=0)
				gn[index-1]=(tv+(tv<<8));

			sprintf(tstr,"menu_%s_red",menucoltxt[index-1]);
			if((tv=Read_Neutrino_Cfg(tstr))>=0)
				rd[index-1]=(tv+(tv<<8));
		}
		
		fb = open(FB_DEVICE, O_RDWR);

		if(ioctl(fb, FBIOGET_FSCREENINFO, &fix_screeninfo) == -1)
		{
			printf("Clock <FBIOGET_FSCREENINFO failed>\n");
			return -1;
		}
		if(ioctl(fb, FBIOGET_VSCREENINFO, &var_screeninfo) == -1)
		{
			printf("Clock <FBIOGET_VSCREENINFO failed>\n");
			return -1;
		}
		
		if(ioctl(fb, FBIOGETCMAP, &colormap) == -1)
		{
			printf("Clock <FBIOGETCMAP failed>\n");
			return -1;
		}

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

	//init fontlibrary

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

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

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

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

		use_kerning = FT_HAS_KERNING(face);

#ifdef FT_NEW_CACHE_API
		desc.face_id = FONT;
		desc.flags = FT_LOAD_MONOCHROME;
#else
		desc.font.face_id = FONT;
		desc.image_type = ftc_image_mono;
#endif
		if(!(lbb = malloc(var_screeninfo.xres*var_screeninfo.yres)))
		{
			printf("Clock <allocating of Backbuffer failed>\n");
			FTC_Manager_Done(manager);
			FT_Done_FreeType(library);
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}

		memset(lbb, 0, var_screeninfo.xres*var_screeninfo.yres);

		startx = sx;
		starty = sy;
		xstep/=(double)slow;
		ystep/=(double)slow;
		
		InitRC();

	while(loop)
	{
		usleep(15000L);
		ioctl(fb, FBIOGETCMAP, &colormap);
		found=0;
		trnsp=0;
		for(i=colormap.start;i<colormap.len && found!=7;i++)
		{
			if(!colormap.red[i] && !colormap.green[i] && !colormap.blue[i] && !colormap.transp[i])
			{
				cmc=i;
				found|=1;
			}
			if(colormap.red[i]>=0xF000 && colormap.green[i]>=0xF000  && colormap.blue[i]>=0xF000 && !colormap.transp[i])
			{
				cmct=i;
				found|=2;
			}
			if(colormap.transp[i]>trnsp)
			{
				trnspi=i;
				trnsp=colormap.transp[i];
				found|=4;
			}
		}
		if(first)
		{
			first=0;
			memset(lbb, (bcol==0)?trnspi:((bcol==1)?cmc:cmct), var_screeninfo.xres*var_screeninfo.yres);
			memset(lfb, (bcol==0)?trnspi:((bcol==1)?cmc:cmct), var_screeninfo.xres*var_screeninfo.yres);
		}
		if(big)
		{
			x0=3;
			x1=14;
			x2=26;
			x3=BIG;
			x4=30;
			x5=60;
		}
		else
		{
			x0=7;
			x1=12;
			x2=18;
			x3=MED;
			x4=18;
			x5=40;
		}
		x6=0;
		x7=0;
		time(&atim);
		ltim=localtime(&atim);
		if(secs)
		{
			sprintf(tstr,"%02d:%02d:%02d",ltim->tm_hour,ltim->tm_min,ltim->tm_sec);
		}
		else
		{
			sprintf(tstr,"   %02d%c%02d",ltim->tm_hour,(ltim->tm_sec & 1)?':':' ',ltim->tm_min);
			if(!sdat)
			{
				x6=3;
				x7=36+4*big;
			}
		}

		xpos+=xstep*(double)xdir;
		ypos+=ystep*(double)ydir;

		csx=xpos+x7;
		csy=ypos;
		cex=xpos+x7+100+20*big;
		cey=ypos+x2+2*(1+big)+sdat*x4;
		if(csx<0 || (sx+cex)>=ex)
		{
			xdir*=-1;
			xpos+=xstep*(double)xdir;
			csx=xpos+x7;
			cex=xpos+x7+100+20*big;
			xstep=rand()&3;
			if(!xstep)
			{
				xstep=1;
			}
			xstep/=(double)slow;
		}
		if(csy<0 || (sy+cey)>=ey)
		{
			ydir*=-1;
			ypos+=ystep*(double)ydir;
			csy=ypos;
			cey=ypos+x2+2*(1+big)+sdat*x4;
			ystep=rand()&3;
			if(!ystep || (ystep==3 && ydir==1))
			{
				ystep=1;
			}
			ystep/=(double)slow;
		}

		for(i=x6; i<strlen(tstr); i++)
		{
			*dstr=tstr[i];
			RenderString(dstr, xpos-x0+(i*x1), ypos+x2, 30, CENTER, x3, (fcol==0)?trnspi:((fcol==2)?cmct:cmc));
		}

		if(sdat)
		{
			sprintf(tstr,"%02d.%02d.%02d",ltim->tm_mday,ltim->tm_mon+1,ltim->tm_year-100);
			for(i=0; i<strlen(tstr); i++)
			{
				*dstr=tstr[i];
				RenderString(dstr, xpos-x0+(i*x1), ypos+x5-2-2*big, 30, CENTER, x3, (fcol==0)?trnspi:((fcol==2)?cmct:cmc));
			}
		}

		for(i=0;i<=((sdat)?40:20)*(1+big);i++)
		{
			j=(starty+ypos+i)*var_screeninfo.xres+xpos+startx;
			if((j+100+20*big)<var_screeninfo.xres*var_screeninfo.yres)
			{
				memcpy(lfb+j, lbb+j, 100+20*big);
			}
		}
		
		RenderBox(csx, csy, cex, cey, FILL, (bcol==0)?trnspi:((bcol==1)?cmc:cmct));

		if(++loop>10)
		{
			if(RCKeyPressed()||ExistFile("/tmp/.ssaver_kill"))
			{
				loop=0;
			}
		}	
	}	

	cmct=0;
	cmc=0;
	for(i=colormap.start;i<colormap.len;i++)
	{
		if(colormap.transp[i]>cmct)
		{
			cmc=i;
			cmct=colormap.transp[i];
		}
	}
	memset(lfb, cmc, var_screeninfo.xres*var_screeninfo.yres);
	FTC_Manager_Done(manager);
	FT_Done_FreeType(library);

	free(lbb);
	munmap(lfb, fix_screeninfo.smem_len);

	close(fb);
	CloseRC();
	remove("/tmp/.ssaver_kill");
	return 0;
}
Exemple #24
0
/******************************************************************************
 * Blockads Main
 ******************************************************************************/
int main (void)
{
int loop=0,found,werbung=0,tnet, tv, cnum=-1;
char tstr[512],line_buffer[512],zapchan[40],srcchan[40],*cpt1=NULL;
FILE *fh1,*fh2;

	printf("Blockads Version %s\n",P_VERSION);
	
	if((fh1=fopen(FLG_FILE,"r"))==NULL)
	{
//		system("ping -c 5 google.com &");
		fb = open(FB_DEVICE, O_RDWR);
		rc = open(RC_DEVICE, O_RDONLY);
		fcntl(rc, F_SETFL, (fcntl(rc, F_GETFL) | O_EXCL) & ~O_NONBLOCK);


		if((sx=Read_Neutrino_Cfg("screen_StartX"))<0)
			sx=80;
		
		if((ex=Read_Neutrino_Cfg("screen_EndX"))<0)
			ex=620;

		if((sy=Read_Neutrino_Cfg("screen_StartY"))<0)
			sy=80;

		if((ey=Read_Neutrino_Cfg("screen_EndY"))<0)
			ey=505;

		if(Read_Neutrino_Cfg("rounded_corners")>0)
			radius=9;
		else
			radius=0;

	//init framebuffer
		if(ioctl(fb, FBIOGET_FSCREENINFO, &fix_screeninfo) == -1)
		{
			printf("Blockads <FBIOGET_FSCREENINFO failed>\n");
			return -1;
		}
		if(ioctl(fb, FBIOGET_VSCREENINFO, &var_screeninfo) == -1)
		{
			printf("Blockads <FBIOGET_VSCREENINFO failed>\n");
			return -1;
		}
		
		if(!(lfb = (unsigned char*)mmap(0, fix_screeninfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0)))
		{
			printf("Blockads <mapping of Framebuffer failed>\n");
			return -1;
		}
	
	//init fontlibrary

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

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

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

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

		use_kerning = FT_HAS_KERNING(face);

#ifdef FT_NEW_CACHE_API
		desc.face_id = FONT;
		desc.flags = FT_LOAD_MONOCHROME;
#else
		desc.font.face_id = FONT;
		desc.image_type = ftc_image_mono;
#endif
	//init backbuffer
		if(!(lbb = malloc(var_screeninfo.xres*var_screeninfo.yres)))
		{
			printf("Blockads <allocating of Backbuffer failed>\n");
			munmap(lfb, fix_screeninfo.smem_len);
			return -1;
		}

		memset(lbb, TRANSP, var_screeninfo.xres*var_screeninfo.yres);
	
		if (!ReadConf())
		{
			printf("Blockads <Configuration failed>\n");
			return -1;
		}
		found=0;
		loop=0;
		if(!HTTP_downloadFile("localhost",80,"/control/channellist", LST_FILE, 0, 1))
		{
			if(!HTTP_downloadFile("localhost",80,"/control/zapto", ZAP_FILE, 0, 1))
			{
				if((fh1=fopen(ZAP_FILE,"r"))!=NULL)
				{
					while((fgets(line_buffer, sizeof(line_buffer), fh1)>0) && (strlen(line_buffer)<4));
					if(strlen(line_buffer)>1)
					{
						Trim_String(line_buffer);
						strcpy(zapchan,line_buffer);
						if((fh2=fopen(LST_FILE,"r"))!=NULL)
						{
							while(!found && (fgets(line_buffer, sizeof(line_buffer), fh2)))
							{
								if(strstr(line_buffer,zapchan)==line_buffer)
								{
									if((cpt1=strchr(line_buffer,' '))!=NULL)
									{
										cpt1++;
										Trim_String(cpt1);
										strcpy(msgchan,cpt1);
										loop=1;
										if(!Translate_Channel(cpt1, tstr))
										{
											cnum=Get_ChannelNumber(tstr);
											strcpy(srcchan,tstr);
											found=1;
										}
									}
								}
							}
							if(!found)
							{
								inet=-1;
							}
							fclose(fh2);
						}
					}
					fclose(fh1);
				}
			}
		}		
		if(!loop)
		{
			sprintf(tstr,"Fehler beim Auslesen der Kanalliste.\nPlugin konnte nicht gestartet werden.");
			Msg_Popup(tstr);
			return -1;
		}
		if(volume)
		{
			volume=0;
			if(!HTTP_downloadFile("localhost",80,"/control/volume?status", ZAP_FILE, 0, 1))
			{
				if((fh1=fopen(ZAP_FILE,"r"))!=NULL)
				{
					while((fgets(line_buffer, sizeof(line_buffer), fh1)>0) && !strlen(line_buffer));
					if(strlen(line_buffer)>=1)
					{
						Trim_String(line_buffer);
						sscanf(line_buffer,"%d",&mute);
					}
					fclose(fh1);
				}
			}
			if(!HTTP_downloadFile("localhost",80,"/control/volume", ZAP_FILE, 0, 1))
			{
				if((fh1=fopen(ZAP_FILE,"r"))!=NULL)
				{
					while((fgets(line_buffer, sizeof(line_buffer), fh1)>0) && !strlen(line_buffer));
					if(strlen(line_buffer)>=1)
					{
						Trim_String(line_buffer);
						sscanf(line_buffer,"%d",&volume);
					}
					fclose(fh1);
				}
			}
		}
		if(inet>=0)
		{
			tnet=-1;
			if(Open_Socket()!=-1)
			{
				tv=Check_Socket(cnum,&werbung);
				if(tv>0)
				{
					tnet=inet;
					if(!werbung)
					{
						if(!zapalways)
						{
							int adf=0;

							sprintf(tstr,"Für Kanal %s wird\nmomentan keine Werbung gemeldet.\nWerbung läuft im Augenblick auf:\n",msgchan);
							for(tv=0; tv<NUM_CHANNELS; tv++)
							{
								Check_Channel(tv,&found);
								if(found)
								{
									sprintf(tstr+strlen(tstr),"\n%s",Get_ChannelName(tv));
									adf=1;
								}
							}
							if(!adf)
							{
								sprintf(tstr+strlen(tstr),"\nkeinem anderen Sender");
							}
							Msg_Popup(tstr);
							loop=0;
						}
						else
						{
							tnet=-1;
						}
					}
					else
					{
						if((fh2=fopen(FLG_FILE,"w"))!=NULL)
						{
							int adf=0;
							
							fprintf(fh2,"%s\n%d\n%d\n%s\n%d\n%d\n%d\n",zapchan,cnum,rezap*60,msgchan,volume,mute,debounce);
							fclose(fh2);
							system("/bin/blockad &");
							sprintf(tstr,"Werbezapper fr Kanal %s aktiviert.\nSie können jetzt umschalten.\n\nWerbung läuft im Augenblick auch auf:\n",msgchan);
							for(tv=0; tv<NUM_CHANNELS; tv++)
							{
								Check_Channel(tv,&found);
								if(found && (tv != cnum))
								{
									sprintf(tstr+strlen(tstr),"\n%s",Get_ChannelName(tv));
									adf=1;
								}
							}
							if(!adf)
							{
								sprintf(tstr+strlen(tstr),"\nkeinem anderen Sender");
							}
							Msg_Popup(tstr);
						}
					}
				}
				Close_Socket();
			}
			inet=tnet;
		}
		if(inet==-1 && loop)
		{
			Start_NoInet(zapchan);
		}
	}
	else
	{
		Msg_Popup("Werbezapper deaktiviert");
		remove(FLG_FILE);
		sleep(2);
	}

	// clear Display
	memset(lbb, TRANSP, var_screeninfo.xres*var_screeninfo.yres);
	memcpy(lfb, lbb, var_screeninfo.xres*var_screeninfo.yres);
	munmap(lfb, fix_screeninfo.smem_len);
	close(fb);
	free(lbb);

	FTC_Manager_Done(manager);
	FT_Done_FreeType(library);


	fcntl(rc, F_SETFL, O_NONBLOCK);
	
	close(rc);

	return 0;
}