Пример #1
0
int show_txt(int buttonly)
{
    FILE *tfh;
    int i,bx,by,x1,y1,rv=-1,run=1,line=0,action=1,cut,itmp,btns=buttons,lbtns=(buttons>bpline)?bpline:buttons,blines=1+((btns-1)/lbtns);


    if(hide)
    {
        memcpy(lfb, hbb, var_screeninfo.xres*var_screeninfo.yres);
        return 0;
    }
    yo=(header)?80:35;
    if(!buttonly)
    {
        memcpy(lbb, ibb, var_screeninfo.xres*var_screeninfo.yres);
    }
    if((tfh=fopen(TMP_FILE,"r"))!=NULL)
    {
        fclose(tfh);
        if(!buttonly)
        {
            if(type!=1)
            {
                btns=0;
                myo=0;
            }

            RenderString("X", 310, 270, 20, LEFT, BIG, TRANSP);
            pxw=GetStringLen(sx,title)+10;
            if(type==1)
            {
                RenderString("X", 310, 270, 20, LEFT, MED, TRANSP);
                myo=blines*(butty+buttdy);
                for(i=0; i<btns; i++)
                {
                    itmp=GetStringLen(sx,butmsg[i])+10;
                    if(itmp>buttx)
                    {
                        buttx=itmp;
                    }
                }
            }
            buttsize=buttx;

            RenderString("X", 310, 270, 20, LEFT, size, TRANSP);
            if(fh_txt_getsize(TMP_FILE, &x1, &y1, &cut))
            {
                printf("msgbox <invalid Text-Format>\n");
                return -1;
            }
            x1+=10;

            dy=0.8*(double)size;
            if(pxw<x1)
            {
                pxw=x1;
            }
            if(pxw<(lbtns*buttx+lbtns*buttdx))
            {
                pxw=(lbtns*buttx+lbtns*buttdx);
            }
            if(pxw>((ex-sx)-2*buttdx))
            {
                pxw=ex-sx-2*buttdx;
            }
            psx=((ex-sx)/2-pxw/2);
            pyw=y1*dy/*-myo*/;
            if(pyw>((ey-sy)-yo-myo))
            {
                pyw=((ey-sy)-yo-myo);
            }
            psy=/*sy+*/((ey-sy)/2-(pyw+myo-yo)/2);
            if(btns)
            {
                buttxstart=psx+pxw/2-(((double)lbtns*(double)buttsize+(((lbtns>2)&&(lbtns&1))?((double)buttdx):0.0))/2.0);
//				buttystart=psy+pyw/2-(((double)blines*(double)butty+(((blines>2)&&(blines&1))?((double)buttdy):0.0))/2.0);
                buttystart=psy+y1*dy;
            }
        }

        while(run)
        {
            //frame layout
            if(action)
            {
                if(!buttonly)
                {
                    RenderBox(psx-20, psy-yo, psx+pxw+20, psy+pyw+myo, radius, CMH);
                    RenderBox(psx-20+2, psy-yo+2, psx+pxw+20-2, psy+pyw+myo-2, radius, CMC);
                    if(header)
                    {
                        RenderBox(psx-18, psy-yo+2, psx+pxw+18, psy-yo+44, radius, CMH);
                        RenderString(title, psx, psy-yo+36, pxw, CENTER, BIG, CMHT);
                    }
                }
                if(buttonly || !(rv=fh_txt_load(TMP_FILE, psx, pxw, psy, dy, size, line, &cut)))
                {
                    if(type==1)
                    {
                        for(i=0; i<btns; i++)
                        {
                            bx=i%lbtns;
                            by=i/lbtns;
                            RenderBox(buttxstart+bx*(buttsize+buttdx/2), buttystart+by*(butty+buttdy/2), buttxstart+(bx+1)*buttsize+bx*(buttdx/2), buttystart+by*(butty+buttdy/2)+butty, radius, YELLOW);
                            RenderBox(buttxstart+bx*(buttsize+buttdx/2)+2, buttystart+by*(butty+buttdy/2)+2, buttxstart+(bx+1)*buttsize+bx*(buttdx/2)-2, buttystart+by*(butty+buttdy/2)+butty-2, radius, ((by*bpline+bx)==(selection-1))?CMCS:CMC);
                            RenderString(butmsg[i], buttxstart+bx*(buttsize+buttdx/2), buttystart+by*(butty+buttdy/2)+butty-7, buttsize, CENTER, MED, (i==(selection-1))?CMCST:CMCIT);
                        }

//						RenderBox((ex-sx)/2-buttx/2, psy+pyw+myo/2-butty/2, (ex-sx)/2+buttx/2, psy+pyw+myo/2+butty/2, FILL, CMCS);
//						RenderBox((ex-sx)/2-buttx/2, psy+pyw+myo/2-butty/2, (ex-sx)/2+buttx/2, psy+pyw+myo/2+butty/2, GRID, YELLOW);
//						RenderString("OK", (ex-sx)/2-buttx/2, psy+pyw+myo/2+butty/2-7, buttx, CENTER, MED, CMCST);
                    }
                    memcpy(lfb, lbb, var_screeninfo.xres*var_screeninfo.yres);
                }
            }
            run=0;
        }
    }
    return (rv)?-1:0;
}
Пример #2
0
int show_txt(int buttonly)
{
	FILE *tfh;
	char const *fname=NULL;
	int yo=scale2res(80), buttx=scale2res(80), butty=scale2res(30), buttdx=scale2res(20), buttdy=scale2res(10);
	int icon_w=0, icon_h=0, xsize=0, ysize=0;
	int i,bx,by,x1,y1,rv=-1,run=1,line=0,action=1,cut,itmp,btns=buttons,lbtns=(buttons>bpline)?bpline:buttons,blines=1+((btns-1)/lbtns);

	if(hide)
	{
#if HAVE_SPARK_HARDWARE || HAVE_DUCKBOX_HARDWARE
		memcpy(lbb, hbb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
		blit();
#else
		memcpy(lfb, hbb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
#endif
		return 0;
	}
	if (strcmp(icon, "none")==0 || strcmp(icon, "0")==0)
		fname = "";
	else if (strcmp(icon, "error")==0 || strcmp(icon, "1")==0)
		fname = ICON_ERROR;
	else if (strcmp(icon, "info")==0 || strcmp(icon, "2")==0)
		fname = ICON_INFO;
	else	
		fname = icon;
	png_getsize(fname, &icon_w, &icon_h);

	// limit icon size
	if(icon_w > 100 || icon_h > 60) {
		icon_w = xsize = 100;
		icon_h = ysize = 60;
	}

	int h_head = max(FSIZE_MED+(size/2), icon_h);
	yo=((header)?h_head:0);

	int moffs=yo-h_head/3-(size/2);
	if(!buttonly)
	{
		memcpy(lbb, ibb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
	}
	if((tfh=fopen(TMP_FILE,"r"))!=NULL)
	{
		fclose(tfh);
		int fsizebut = scale2res(26);

		if(!buttonly)
		{
			if(type!=1)
			{
				btns=0;
				myo=0;
			}	
		
			pxw=GetStringLen(sx,title,FSIZE_BIG)+OFFSET_MED;
			if(type==1)
			{
				myo=blines*(butty+buttdy);
				for(i=0; i<btns; i++)
				{
					itmp=GetStringLen(sx,butmsg[i],fsizebut)+OFFSET_MED;
					if(itmp>buttx)
					{
						buttx=itmp;
					}
				}
			}
			buttsize=buttx;
			
			if(fh_txt_getsize(TMP_FILE, &x1, &y1, size, &cut))
			{
				printf(__plugin__ " <invalid Text-Format>\n");
				return -1;
			}
			x1+=OFFSET_MED;

			dy=size;
			if(pxw<x1)
			{
				pxw=x1;
			}
			if(pxw<(lbtns*buttx+lbtns*buttdx))
			{
				pxw=(lbtns*buttx+lbtns*buttdx);
			}
			if(pxw>((ex-sx)-2*buttdx))
			{
				pxw=ex-sx-2*buttdx;
			}
			psx=((ex-sx)/2-pxw/2);
			pyw=y1*dy/*-myo*/;
			if(pyw>((ey-sy)-yo-myo))
			{
				pyw=((ey-sy)-yo-myo);
			}
			psy=((ey-sy)/2-(pyw+myo-yo)/2);
			if(btns)
			{
				buttxstart=psx+pxw/2-(((double)lbtns*(double)buttsize+(((lbtns>2)&&(lbtns&1))?((double)buttdx):0.0))/2.0);
				buttystart=psy+y1*dy+2*OFFSET_MED;
			}
		}

		while(run)
		{
			//frame layout
			if(action)
			{
				if(!buttonly)
				{
					int iw, ih, pxoffs = 0;
					int slen = GetStringLen(sx, title, FSIZE_BIG)+2*OFFSET_MED;
					if (icon_w > 0 && (psx+pxw-2*OFFSET_MED-slen <= psx-OFFSET_MED+icon_w+OFFSET_MED))
						pxoffs = (icon_w)/2;
					RenderBox(psx-2*OFFSET_MED-pxoffs+OFFSET_SMALL, psy-yo-h_head/3-OFFSET_SMALL, psx+pxw+pxoffs+2*OFFSET_MED+OFFSET_SMALL, psy+pyw+myo+(h_head/3)+OFFSET_MED+OFFSET_SMALL, radius, COL_SHADOW_PLUS_0);
					RenderBox(psx-2*OFFSET_MED-pxoffs, psy-yo-h_head/3-OFFSET_MED, psx+pxw+pxoffs+2*OFFSET_MED, psy+pyw+myo+(h_head/3)+OFFSET_MED, radius, CMC);
					if(header)
					{
						int pyoffs=(icon_h < h_head)?1:0;
						RenderBox(psx-2*OFFSET_MED-pxoffs, psy-yo-h_head/3-OFFSET_MED, psx+pxw+pxoffs+2*OFFSET_MED, psy-yo+(h_head*2)/3-OFFSET_MED, radius, CMH);
						paintIcon(fname,  psx-OFFSET_MED-pxoffs, psy-yo-h_head/3+h_head/2-icon_h/2+pyoffs-OFFSET_MED, xsize, ysize, &iw, &ih);
						RenderString(title, psx+pxoffs, psy-moffs-OFFSET_MED, pxw, CENTER, FSIZE_BIG, CMHT);
					}
				}
				if(buttonly || !(rv=fh_txt_load(TMP_FILE, psx, pxw, psy+size, dy, size, line, &cut)))
				{
					if(type==1)
					{
						for(i=0; i<btns; i++)
						{
							bx=i%lbtns;
							by=i/lbtns;
							RenderBox(buttxstart+bx*(buttsize+buttdx/2)+OFFSET_SMALL/2, buttystart+by*(butty+buttdy/2)+OFFSET_SMALL/2, buttxstart+(bx+1)*buttsize+bx*(buttdx/2)+OFFSET_SMALL/2, buttystart+by*(butty+buttdy/2)+butty+OFFSET_SMALL/2, radius_small, COL_SHADOW_PLUS_0);
							RenderBox(buttxstart+bx*(buttsize+buttdx/2), buttystart+by*(butty+buttdy/2), buttxstart+(bx+1)*buttsize+bx*(buttdx/2), buttystart+by*(butty+buttdy/2)+butty, radius_small, CMCS/*YELLOW*/);
							RenderBox(buttxstart+bx*(buttsize+buttdx/2)+1, buttystart+by*(butty+buttdy/2)+1, buttxstart+(bx+1)*buttsize+bx*(buttdx/2)-1, buttystart+by*(butty+buttdy/2)+butty-1, radius_small, ((by*bpline+bx)==(selection-1))?CMCS:CMC);
							RenderString(butmsg[i], buttxstart+bx*(buttsize+buttdx/2), buttystart+by*(butty+buttdy/2)+butty, buttsize, CENTER, fsizebut, (i==(selection-1))?CMCST:CMCIT);
						}
					}
#if HAVE_SPARK_HARDWARE || HAVE_DUCKBOX_HARDWARE
					blit();
#else
					memcpy(lfb, lbb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
#endif
				}
			}
			run=0;
		}
	}
	return (rv)?-1:0;	
}