⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 menu.c

📁 君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图片解码,浏览,电子书,录音,想学ucos,识货的人就下吧 russblock fmradio explore set
💻 C
📖 第 1 页 / 共 2 页
字号:
      fribidi_set_mirroring (1);      fribidi_set_reorder_nsm (0);      char_set_num = fribidi_parse_charset("UTF-8");      buffer_size = FFMAX(1024,len+1);      logical = malloc(buffer_size);      visual = malloc(buffer_size);      outputstr = malloc(buffer_size);    } else if (len+1 > buffer_size) {      buffer_size = len+1;      logical = realloc(logical, buffer_size);      visual = realloc(visual, buffer_size);      outputstr = realloc(outputstr, buffer_size);    }    len = fribidi_charset_to_unicode (char_set_num, txt, len, logical);    base = menu_fribidi_flip_commas?FRIBIDI_TYPE_ON:FRIBIDI_TYPE_L;    log2vis = fribidi_log2vis (logical, len, &base, visual, NULL, NULL, NULL);    if (log2vis) {      len = fribidi_remove_bidi_marks (visual, len, NULL, NULL, NULL);      fribidi_unicode_to_charset (char_set_num, visual, len, outputstr);      return outputstr;    }  }  return txt;}#endifvoid menu_draw_text(mp_image_t* mpi,char* txt, int x, int y) {  draw_alpha_f draw_alpha = get_draw_alpha(mpi->imgfmt);  int font;  if(!draw_alpha) {    mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_UnsupportedOutformat);    return;  }#ifdef USE_FRIBIDI  txt = menu_fribidi(txt);#endif  render_txt(txt);  while (*txt) {    int c=utf8_get_char(&txt);    if ((font=vo_font->font[c])>=0 && (x + vo_font->width[c] <= mpi->w) && (y + vo_font->pic_a[font]->h <= mpi->h))      draw_alpha(vo_font->width[c], vo_font->pic_a[font]->h,		 vo_font->pic_b[font]->bmp+vo_font->start[c],		 vo_font->pic_a[font]->bmp+vo_font->start[c],		 vo_font->pic_a[font]->w,		 mpi->planes[0] + y * mpi->stride[0] + x * (mpi->bpp>>3),		 mpi->stride[0]);    x+=vo_font->width[c]+vo_font->charspace;  }}void menu_draw_text_full(mp_image_t* mpi,char* txt,			 int x, int y,int w, int h,			 int vspace, int warp, int align, int anchor) {  int need_w,need_h;  int sy, ymin, ymax;  int sx, xmin, xmax, xmid, xrmin;  int ll = 0;  int font;  draw_alpha_f draw_alpha = get_draw_alpha(mpi->imgfmt);  if(!draw_alpha) {    mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_UnsupportedOutformat);    return;  }#ifdef USE_FRIBIDI  txt = menu_fribidi(txt);#endif  render_txt(txt);  if(x > mpi->w || y > mpi->h)    return;  if(anchor & MENU_TEXT_VCENTER) {    if(h <= 0) h = mpi->h;    ymin = y - h/2;    ymax = y + h/2;  }  else if(anchor & MENU_TEXT_BOT) {    if(h <= 0) h = mpi->h - y;    ymin = y - h;    ymax = y;  } else {    if(h <= 0) h = mpi->h - y;    ymin = y;    ymax = y + h;  }  if(anchor & MENU_TEXT_HCENTER) {    if(w <= 0) w = mpi->w;    xmin = x - w/2;    xmax = x + w/2;  }  else if(anchor & MENU_TEXT_RIGHT) {    if(w <= 0) w = mpi->w -x;    xmin = x - w;    xmax = x;  } else {    if(w <= 0) w = mpi->w -x;    xmin = x;    xmax = x + w;  }  // How many space do we need to draw this ?  menu_text_size(txt,w,vspace,warp,&need_w,&need_h);  // Find the first line  if(align & MENU_TEXT_VCENTER)    sy = ymin + ((h - need_h)/2);  else if(align & MENU_TEXT_BOT)     sy = ymax - need_h - 1;  else    sy = y;#if 0  // Find the first col  if(align & MENU_TEXT_HCENTER)    sx = xmin + ((w - need_w)/2);  else if(align & MENU_TEXT_RIGHT)    sx = xmax - need_w;#endif    xmid = xmin + (xmax - xmin) / 2;  xrmin = xmin;  // Clamp the bb to the mpi size  if(ymin < 0) ymin = 0;  if(xmin < 0) xmin = 0;  if(ymax > mpi->h) ymax = mpi->h;  if(xmax > mpi->w) xmax = mpi->w;    // Jump some the beginnig text if needed  while(sy < ymin && *txt) {    int c=utf8_get_char(&txt);    if(c == '\n' || (warp && ll + vo_font->width[c] > w)) {      ll = 0;      sy += vo_font->height + vspace;      if(c == '\n') continue;    }    ll += vo_font->width[c]+vo_font->charspace;  }  if(*txt == '\0') // Nothing left to draw      return;  while(sy < ymax && *txt) {    char* line_end = NULL;    int n;    if(txt[0] == '\n') { // New line      sy += vo_font->height + vspace;      txt++;      continue;    }    // Get the length and end of this line    for(n = 0, ll = 0 ; txt[n] != '\0' && txt[n] != '\n'  ; n++) {      unsigned char c = txt[n];      if(warp && ll + vo_font->width[c]  > w)  break;      ll += vo_font->width[c]+vo_font->charspace;    }    line_end = &txt[n];    ll -= vo_font->charspace;    if(align & (MENU_TEXT_HCENTER|MENU_TEXT_RIGHT)) {      // Too long line      if(ll > xmax-xmin) {	if(align & MENU_TEXT_HCENTER) {	  int mid = ll/2;	  // Find the middle point	  for(n--, ll = 0 ; n <= 0 ; n--) {	    ll += vo_font->width[(int)txt[n]]+vo_font->charspace;	    if(ll - vo_font->charspace > mid) break;	  }	  ll -= vo_font->charspace;	  sx = xmid + mid - ll;	} else// MENU_TEXT_RIGHT)	  sx = xmax + vo_font->charspace;	// We are after the start point -> go back	if(sx > xmin) {	  for(n-- ; n <= 0 ; n--) {	    unsigned char c = txt[n];	    if(sx - vo_font->width[c] - vo_font->charspace < xmin) break;	    sx -= vo_font->width[c]+vo_font->charspace;	  }	} else { // We are before the start point -> go forward	  for( ; sx < xmin && (&txt[n]) != line_end ; n++) {	    unsigned char c = txt[n];	    sx += vo_font->width[c]+vo_font->charspace;	  }	}	txt = &txt[n]; // Jump to the new start char      } else {	if(align & MENU_TEXT_HCENTER)	  sx = xmid - ll/2;	else	  sx = xmax - 1 - ll;      }    } else {      for(sx = xrmin ;  sx < xmin && txt != line_end ; txt++) {	unsigned char c = txt[n];	sx += vo_font->width[c]+vo_font->charspace;      }    }    while(sx < xmax && txt != line_end) {      int c=utf8_get_char(&txt);      font = vo_font->font[c];      if(font >= 0) { 	int cs = (vo_font->pic_a[font]->h - vo_font->height) / 2;	if ((sx + vo_font->width[c] < xmax)  &&  (sy + vo_font->height < ymax) )	  draw_alpha(vo_font->width[c], vo_font->height,		     vo_font->pic_b[font]->bmp+vo_font->start[c] +		     cs * vo_font->pic_a[font]->w,		     vo_font->pic_a[font]->bmp+vo_font->start[c] +		     cs * vo_font->pic_a[font]->w,		     vo_font->pic_a[font]->w,		     mpi->planes[0] + sy * mpi->stride[0] + sx * (mpi->bpp>>3),		     mpi->stride[0]);	//	else	//printf("Can't draw '%c'\n",c);      }      sx+=vo_font->width[c]+vo_font->charspace;    }    txt = line_end;    if(txt[0] == '\0') break;    sy += vo_font->height + vspace;  }}	  int menu_text_length(char* txt) {  int l = 0;  render_txt(txt);  while (*txt) {    int c=utf8_get_char(&txt);    l += vo_font->width[c]+vo_font->charspace;  }  return l - vo_font->charspace;}void menu_text_size(char* txt,int max_width, int vspace, int warp, int* _w, int* _h) {  int l = 1, i = 0;  int w = 0;  render_txt(txt);  while (*txt) {    int c=utf8_get_char(&txt);    if(c == '\n' || (warp && i + vo_font->width[c] >= max_width)) {      if(*txt)	l++;      i = 0;      if(c == '\n') continue;    }    i += vo_font->width[c]+vo_font->charspace;    if(i > w) w = i;  }    *_w = w;  *_h = (l-1) * (vo_font->height + vspace) + vo_font->height;}int menu_text_num_lines(char* txt, int max_width) {  int l = 1, i = 0;  render_txt(txt);  while (*txt) {    int c=utf8_get_char(&txt);    if(c == '\n' || i + vo_font->width[c] > max_width) {      l++;      i = 0;      if(c == '\n') continue;    }    i += vo_font->width[c]+vo_font->charspace;  }  return l;}  char* menu_text_get_next_line(char* txt, int max_width) {  int i = 0;  render_txt(txt);  while (*txt) {    int c=utf8_get_char(&txt);    if(c == '\n') {      txt++;      break;    }    i += vo_font->width[c];    if(i >= max_width)      break;    i += vo_font->charspace;  }  return txt;}void menu_draw_box(mp_image_t* mpi,unsigned char grey,unsigned char alpha, int x, int y, int w, int h) {  draw_alpha_f draw_alpha = get_draw_alpha(mpi->imgfmt);  int g;    if(!draw_alpha) {    mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_UnsupportedOutformat);    return;  }    if(x > mpi->w || y > mpi->h) return;    if(x < 0) w += x, x = 0;  if(x+w > mpi->w) w = mpi->w-x;  if(y < 0) h += y, y = 0;  if(y+h > mpi->h) h = mpi->h-y;      g = ((256-alpha)*grey)>>8;  if(g < 1) g = 1;      {    int stride = (w+7)&(~7); // round to 8    char pic[stride*h],pic_alpha[stride*h];    memset(pic,g,stride*h);    memset(pic_alpha,alpha,stride*h);    draw_alpha(w,h,pic,pic_alpha,stride,               mpi->planes[0] + y * mpi->stride[0] + x * (mpi->bpp>>3),               mpi->stride[0]);  }  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -