]> git.webhop.me Git - msgbox.git/commitdiff
add descender hack & new params ~C (vol. 2), see readme.txt
authorGetAway <get-away@t-online.de>
Sun, 27 Nov 2016 20:59:30 +0000 (21:59 +0100)
committersvenhoefer <svenhoefer@svenhoefer.com>
Sun, 27 Nov 2016 21:39:33 +0000 (22:39 +0100)
- change ~s separator line to half font high
- add ~C! for separator line with full font high
- fix indent
- fix munmap_chunk(): invalid pointer on Nevis
- init some vars

gfx.c
msgbox.c
text.c
txtform.c

diff --git a/gfx.c b/gfx.c
index fadbb28b917e32f438fa312f28b9c6b9d3f4d72b..c96ceed0b7c99748052357fd42e03d2adc6d0185 100644 (file)
--- a/gfx.c
+++ b/gfx.c
@@ -7,12 +7,18 @@ void RenderBox(int _sx, int _sy, int _ex, int _ey, int rad, int col)
        uint32_t *pos = lbb + ssx + stride * ssy;
        uint32_t *pos0, *pos1, *pos2, *pos3, *i;
        uint32_t pix = bgra[col];
-               
+
        if (dxx<0) 
        {
                printf("msgbox RenderBox called with dx < 0 (%d)\n", dxx);
                dxx=0;
        }
+       if (dyy > 700)
+       {
+               printf("msgbox RenderBox called with dyy > 700 (%d)\n", dyy); //FIXME
+               //*** Error in `msgbox': munmap_chunk(): invalid pointer: 0x31459008 *** //Nevis
+               dyy = 700;
+       }
 
        if(R)
        {
index c1cf5f47ecdba0b54c1cb4d4e6c24cb8ea7889de..4403d497b99a376775de528ace2d9c58cf14614d 100644 (file)
--- a/msgbox.c
+++ b/msgbox.c
@@ -8,7 +8,7 @@
 #include "gfx.h"
 #include "txtform.h" 
 
-#define M_VERSION 1.20
+#define M_VERSION 1.21
 
 #define NCF_FILE       "/var/tuxbox/config/neutrino.conf"
 #define HDF_FILE       "/tmp/.msgbox_hidden"
@@ -40,7 +40,7 @@ static char spres[][5]={"","_crt","_lcd"};
 
 char *line_buffer=NULL, *title=NULL;
 int size=24, type=0, timeout=0, refresh=3, flash=0, selection=0, tbuttons=0, buttons=0, bpline=3, echo=0, absolute=0, mute=1, header=1, cyclic=1;
-char *butmsg[16];
+char *butmsg[16]={0};
 int rbutt[16],hide=0,radius=11;
 
 // Misc
@@ -48,7 +48,7 @@ const char NOMEM[]="msgbox <Out of memory>\n";
 char TMP_FILE[64]="/tmp/msgbox.tmp";
 uint32_t *lfb = NULL, *lbb = NULL, *obb = NULL, *hbb = NULL, *ibb = NULL;
 char nstr[BUFSIZE]={0};
-char *trstr;
+char *trstr=NULL;
 const char INST_FILE[]="/tmp/rc.locked";
 int instance=0;
 int stride;
@@ -94,7 +94,7 @@ static void quit_signal(int sig)
 int Read_Neutrino_Cfg(char *entry)
 {
 FILE *nfh;
-char tstr [512], *cfptr=NULL;
+char tstr [512]={0}, *cfptr=NULL;
 int rv=-1;
 
        if((nfh=fopen(NCF_FILE,"r"))!=NULL)
@@ -161,7 +161,7 @@ char *pt1=strg, *pt2=strg;
 int GetSelection(char *sptr)
 {
 int rv=0,btn=0,run=1;
-char *pt1=strdup(sptr),*pt2,*pt3;
+char *pt1=strdup(sptr),*pt2=NULL,*pt3=NULL;
 
        pt2=pt1;
        while(*pt2 && run && btn<MAX_BUTTONS)
@@ -216,7 +216,9 @@ int i,bx,by,x1,y1,rv=-1,run=1,line=0,action=1,cut,itmp,btns=buttons,lbtns=(butto
                memcpy(lfb, hbb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
                return 0;
        }
+
        yo=20+((header)?FSIZE_MED*5/4:0);
+       int moffs=yo*3/4+6;
        if(!buttonly)
        {
                memcpy(lbb, ibb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
@@ -293,10 +295,10 @@ int i,bx,by,x1,y1,rv=-1,run=1,line=0,action=1,cut,itmp,btns=buttons,lbtns=(butto
                                        if(header)
                                        {
                                                RenderBox(psx-20, psy-yo+2-FSIZE_BIG/2, psx+pxw+20, psy-yo+FSIZE_BIG*3/4, radius, CMH);
-                                               RenderString(title, psx, psy-yo+FSIZE_BIG/2, pxw, CENTER, FSIZE_BIG, CMHT);
+                                               RenderString(title, psx, psy-moffs+FSIZE_BIG/2, pxw, CENTER, FSIZE_BIG, CMHT);
                                        }
                                }
-                               if(buttonly || !(rv=fh_txt_load(TMP_FILE, psx, pxw, psy+15, dy, size, line, &cut)))
+                               if(buttonly || !(rv=fh_txt_load(TMP_FILE, psx, pxw, psy+20, dy, size, line, &cut)))
                                {
                                        if(type==1)
                                        {
@@ -306,7 +308,7 @@ int i,bx,by,x1,y1,rv=-1,run=1,line=0,action=1,cut,itmp,btns=buttons,lbtns=(butto
                                                        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, 26, (i==(selection-1))?CMCST:CMCIT);
+                                                       RenderString(butmsg[i], buttxstart+bx*(buttsize+buttdx/2), buttystart+by*(butty+buttdy/2)+butty, buttsize, CENTER, 26, (i==(selection-1))?CMCST:CMCIT);
                                                }
                                        }
                                        memcpy(lfb, lbb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
@@ -402,7 +404,7 @@ int main (int argc, char **argv)
 {
 int ix,tv,found=0, spr;
 int dloop=1, rcc=-1;
-char rstr[BUFSIZE]={0}, *rptr, *aptr;
+char rstr[BUFSIZE]={0}, *rptr=NULL, *aptr=NULL;
 time_t tm1,tm2;
 FILE *fh;
 
@@ -766,7 +768,7 @@ FILE *fh;
 
        //init backbuffer
 
-               if(!(lbb = malloc(fix_screeninfo.line_length*var_screeninfo.yres)))
+               if(!(lbb = malloc(var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t))))
                {
                        perror("msgbox <allocating of Backbuffer>\n");
                        FTC_Manager_Done(manager);
@@ -776,7 +778,7 @@ FILE *fh;
                }
                stride = fix_screeninfo.line_length/sizeof(uint32_t);
 
-               if(!(obb = malloc(fix_screeninfo.line_length*var_screeninfo.yres)))
+               if(!(obb = malloc(var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t))))
                {
                        perror("msgbox <allocating of Backbuffer>\n");
                        FTC_Manager_Done(manager);
@@ -785,8 +787,7 @@ FILE *fh;
                        munmap(lfb, fix_screeninfo.smem_len);
                        return -1;
                }
-
-               if(!(hbb = malloc(fix_screeninfo.line_length*var_screeninfo.yres)))
+               if(!(hbb = malloc(var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t))))
                {
                        perror("msgbox <allocating of Backbuffer>\n");
                        FTC_Manager_Done(manager);
@@ -796,8 +797,7 @@ FILE *fh;
                        munmap(lfb, fix_screeninfo.smem_len);
                        return -1;
                }
-
-               if(!(ibb = malloc(fix_screeninfo.line_length*var_screeninfo.yres)))
+               if(!(ibb = malloc(var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t))))
                {
                        perror("msgbox <allocating of Backbuffer>\n");
                        FTC_Manager_Done(manager);
@@ -943,7 +943,6 @@ FILE *fh;
        
        
        //cleanup
-
        memcpy(lfb, obb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t));
        munmap(lfb, fix_screeninfo.smem_len);
        close(fb);
diff --git a/text.c b/text.c
index c223f5110580039aa065a03a14cbccb9030026f7..2569d572b69f3312750fb2fb61f4d5ff7925d502 100644 (file)
--- a/text.c
+++ b/text.c
@@ -221,7 +221,7 @@ int RenderChar(FT_ULong currentchar, int _sx, int _sy, int _ex, int color)
                if(color != -1)
                {
                        if (_sx + 10 < _ex)
-                               RenderBox(_sx, _sy - 10, _sx + 10, _sy, GRID, color);
+                               RenderBox(_sx, _sy - 16, _sx + 10, _sy - 6, GRID, color);
                        else
                                return -1;
                }
@@ -236,59 +236,69 @@ int RenderChar(FT_ULong currentchar, int _sx, int _sy, int _ex, int color)
 
        //load char
 
-               if(!(glyphindex = FT_Get_Char_Index(face, currentchar)))
-               {
-                       printf("msgbox <FT_Get_Char_Index for Char \"%c\" failed\n", (int)currentchar);
-                       return 0;
-               }
+       if(!(glyphindex = FT_Get_Char_Index(face, currentchar)))
+       {
+               printf("msgbox <FT_Get_Char_Index for Char \"%c\" failed\n", (int)currentchar);
+               return 0;
+       }
 
-               if((err = FTC_SBitCache_Lookup(cache, &desc, glyphindex, &sbit, NULL)))
-               {
-                       printf("msgbox <FTC_SBitCache_Lookup for Char \"%c\" failed with Errorcode 0x%.2X>\n", (int)currentchar, error);
-                       return 0;
-               }
+       if((err = FTC_SBitCache_Lookup(cache, &desc, glyphindex, &sbit, NULL)))
+       {
+               printf("msgbox <FTC_SBitCache_Lookup for Char \"%c\" failed with Errorcode 0x%.2X>\n", (int)currentchar, error);
+               return 0;
+       }
 
-               if(use_kerning)
-               {
-                       FT_Get_Kerning(face, prev_glyphindex, glyphindex, ft_kerning_default, &kerning);
+       int _d = 0;
+       if (1)
+       {
+               FT_UInt _i = FT_Get_Char_Index(face, 'g');
+               FTC_SBit _g;
+               FTC_SBitCache_Lookup(cache, &desc, _i, &_g, NULL);
+               _d = _g->height - _g->top;
+               _d += 1;
+       }
 
-                       prev_glyphindex = glyphindex;
-                       kerning.x >>= 6;
-               } else
-                       kerning.x = 0;
+       if(use_kerning)
+       {
+               FT_Get_Kerning(face, prev_glyphindex, glyphindex, ft_kerning_default, &kerning);
+
+               prev_glyphindex = glyphindex;
+               kerning.x >>= 6;
+       } else
+               kerning.x = 0;
 
-               //render char
+       //render char
 
-               if(color != -1) /* don't render char, return charwidth only */
+       if(color != -1) /* don't render char, return charwidth only */
+       {
+               if (_sx + sbit->xadvance >= _ex)
+                       return -1; /* limit to maxwidth */
+
+               uint32_t bgcolor = *(lbb + (sy + _sy) * stride + (sx + _sx));
+               uint32_t fgcolor = bgra[color];
+               uint32_t *colors = lookup_colors(fgcolor, bgcolor);
+               uint32_t *p = lbb + (sx + _sx + sbit->left + kerning.x) + stride * (sy + _sy - sbit->top - _d);
+               uint32_t *r = p + (_ex - _sx);  /* end of usable box */
+               for(row = 0; row < sbit->height; row++)
                {
-                       if (_sx + sbit->xadvance >= _ex)
-                               return -1; /* limit to maxwidth */
-
-                       uint32_t bgcolor = *(lbb + (sy + _sy) * stride + (sx + _sx));
-                       uint32_t fgcolor = bgra[color];
-                       uint32_t *colors = lookup_colors(fgcolor, bgcolor);
-                       uint32_t *p = lbb + (sx + _sx + sbit->left + kerning.x) + stride * (sy + _sy - sbit->top);
-                       uint32_t *r = p + (_ex - _sx);  /* end of usable box */
-                       for(row = 0; row < sbit->height; row++)
+                       uint32_t *q = p;
+                       uint8_t *s = sbit->buffer + row * sbit->pitch;
+                       for(pitch = 0; pitch < sbit->width; pitch++)
                        {
-                               uint32_t *q = p;
-                               uint8_t *s = sbit->buffer + row * sbit->pitch;
-                               for(pitch = 0; pitch < sbit->width; pitch++)
-                               {
-                                       if (*s)
-                                                       *q = colors[*s];
-                                       q++, s++;
-                                       if (q > r)      /* we are past _ex */
-                                               break;
-                               }
-                               p += stride;
-                               r += stride;
+                               if (*s)
+                                               *q = colors[*s];
+                               q++, s++;
+                               if (q > r)      /* we are past _ex */
+                                       break;
                        }
+                       p += stride;
+                       r += stride;
                }
+       }
 
        //return charwidth
 
-               return sbit->xadvance + kerning.x;
+       return sbit->xadvance + kerning.x;
 }
 
 /******************************************************************************
@@ -318,6 +328,9 @@ int GetStringLen(int _sx, char *string, size_t size)
                                string+=5;
                                stringlen=i-_sx;
                        }
+                       else if(*string=='!') {
+                               string++;
+                       }
                        break;
                default:
                        stringlen += RenderChar(UTF8ToUnicode(&string, 1), -1, -1, -1, -1);
@@ -373,7 +386,7 @@ int RenderString(char *string, int _sx, int _sy, int maxwidth, int layout, int s
                        case CENTER:    if(stringlen < maxwidth) _sx += (maxwidth - stringlen)/2;
                                        break;
 
-                       case RIGHT:     if(stringlen < maxwidth) _sx += maxwidth - stringlen;
+                       case RIGHT:     if(stringlen < maxwidth) _sx += maxwidth - stringlen * 0.8;
                }
        }
 
index b53b3d631c1710e8b239b9a2bddbfe112b61acea..52a73626722c5c2263e8a811b2f1312cc3c8bf34 100644 (file)
--- a/txtform.c
+++ b/txtform.c
 
 int fh_txt_trans(const char *name, int xs, int xw, int ys, int dy, int size, int line, int *cut, int *x, int *y, int plot)
 {
-char tstr[BUFSIZE],rstr[BUFSIZE],*tptr;
-int loop=1, j, slen, cnt=0;
+char tstr[BUFSIZE]={0},rstr[BUFSIZE]={0},*tptr=NULL;
+int loop=1, j, slen;
 FILE *fh;
-int just, color=CMCT;
+int just, comment, color=CMCT;
 
        if(!(fh=fopen(name,"rb")))      return(FH_ERROR_FILE);
 
@@ -27,6 +27,7 @@ int just, color=CMCT;
        {
                j=0;
                just=LEFT;
+               comment=0;
                color=CMCT;
                
                tptr=tstr+strlen(tstr);
@@ -39,7 +40,6 @@ int just, color=CMCT;
                while(*tptr)
                {
                        rstr[j++]=*tptr;
-                       cnt++;
 
                        if(*tptr == '~')
                        {
@@ -48,9 +48,24 @@ int just, color=CMCT;
                                        case 'l': just=LEFT; break;
                                        case 'r': just=RIGHT; break;
                                        case 'c': just=CENTER; break;
+                                       case 'C':
+                                               if (*(tptr+2) == '!') {
+                                                       comment=1;
+                                                       tptr++;
+                                               }
+                                               else if (*(tptr+2) == 'L') {
+                                                       comment=2;
+                                                       tptr++;
+                                               }
+                                               else if (*(tptr+2) == 'R') {
+                                                       comment=3;
+                                                       tptr++;
+                                               }
+                                               break;
                                        case 's':
-                                               RenderBox(xs, ys-size/3+1, xs+xw, ys-size/3+2, FILL, CMS);
-                                               RenderBox(xs, ys-size/3, xs+xw, ys-size/3+1, FILL, CMCIT);
+                                               ys-=(dy/2);
+                                               RenderBox(xs, ys-2-size/3+1, xs+xw, ys-2-size/3+2, FILL, CMS);
+                                               RenderBox(xs, ys-2-size/3, xs+xw, ys-2-size/3+1, FILL, CMCIT);
                                                break;
                                }
                        }
@@ -67,7 +82,34 @@ int just, color=CMCT;
                        {
                                if(loop>=line)
                                {
-                                       RenderString(t, xs, ys, xw, just, size, color);
+                                       slen=GetStringLen(xs, t, size);
+                                       if (comment == 1)
+                                       {
+                                               int xxs = xs;
+                                               RenderBox(xs, ys-2-size/2+1, xs+xw, ys-2-size/2+2, FILL, CMS);
+                                               RenderBox(xs, ys-2-size/2, xs+xw, ys-2-size/2+1, FILL, CMCIT);
+                                               if(slen > 0 && slen < xw) {
+                                                       xxs += (xw-slen-10)/2-5;
+                                                       RenderBox(xxs, ys-2-size/2, xxs+slen+20, ys-2-size/2+2, FILL, CMC);
+                                               }
+                                               RenderString(t, xs, ys, xw, CENTER, size, CMCIT);
+                                       }
+                                       else if (comment == 2)
+                                       {
+                                               RenderBox(xs+slen, ys-2-size/2+1, xs+xw, ys-2-size/2+2, FILL, CMS);
+                                               RenderBox(xs+slen, ys-2-size/2, xs+xw, ys-2-size/2+1, FILL, CMCIT);
+                                               RenderString(t, xs, ys, xw, LEFT, size, color);
+                                       }
+                                       else if (comment == 3)
+                                       {
+                                               RenderBox(xs, ys-2-size/2+1, xs+xw-slen, ys-2-size/2+2, FILL, CMS);
+                                               RenderBox(xs, ys-2-size/2, xs+xw-slen, ys-2-size/2+1, FILL, CMCIT);
+                                               RenderString(t, xs, ys, xw, RIGHT, size, color);
+                                       }
+                                       else
+                                       {
+                                               RenderString(t, xs, ys, xw, just, size, color);
+                                       }
                                        ys+=dy;
                                }
                        }