static void draw(menu_t* menu, mp_image_t* mpi) {
  int h = mpi->h*mpriv->height/100;
  int w = mpi->w - 2* mpriv->minb;
  int x = mpriv->minb, y;
  int lw,lh,i, ll;

  if(mpriv->child) check_child(menu);

  ll = mpriv->last_line - 1;

  if(mpriv->hide_ts) {
    unsigned int t = GetTimerMS() - mpriv->hide_ts;
    if(t >= mpriv->hide_time) {
      mpriv->hide_ts = 0;
      menu->show = 0;
      return;
    }
    h = mpi->h*(mpriv->height - (mpriv->height * t /mpriv->hide_time))/100;
  } else if(mpriv->show_time && mpriv->show_ts == 0) {
    mpriv->show_ts = GetTimerMS();
    return;
  } else if(mpriv->show_ts > 0) {
    unsigned int t = GetTimerMS() - mpriv->show_ts;
    if(t > mpriv->show_time)
      mpriv->show_ts = -1;
    else
      h = mpi->h*(mpriv->height * t /mpriv->hide_time)/100;
  }

  y = h -  mpriv->vspace;

  if(x < 0 || y < 0 || w <= 0 || h <= 0 )
    return;

  if(mpriv->bg >= 0)
    menu_draw_box(mpi,mpriv->bg,mpriv->bg_alpha,0,0,mpi->w,h);

  if(!mpriv->child || !mpriv->raw_child){
    char input[strlen(mpriv->cur_history->buffer) + strlen(mpriv->prompt) + 1];
    sprintf(input,"%s%s",mpriv->prompt,mpriv->cur_history->buffer);
    menu_text_size(input,w,mpriv->vspace,1,&lw,&lh);
    menu_draw_text_full(mpi,input,x,y,w,h,mpriv->vspace,1,
			MENU_TEXT_BOT|MENU_TEXT_LEFT,
			MENU_TEXT_BOT|MENU_TEXT_LEFT);
    y -= lh + mpriv->vspace;
  }


  for( i = 0 ; y > mpriv->minb && i < mpriv->num_lines ; i++){
    int c = (ll - i) >= 0 ? ll - i : mpriv->buf_lines + ll - i;
    menu_text_size(mpriv->lines[c],w,mpriv->vspace,1,&lw,&lh);
    menu_draw_text_full(mpi,mpriv->lines[c],x,y,w,h,mpriv->vspace,1,
			MENU_TEXT_BOT|MENU_TEXT_LEFT,
			MENU_TEXT_BOT|MENU_TEXT_LEFT);
    y -= lh + mpriv->vspace;
  }
  return;
}
Esempio n. 2
0
void menu_list_draw(menu_t* menu,mp_image_t* mpi) {
  int x = mpriv->x;
  int y = mpriv->y;
  int i;
  int h = mpriv->h;
  int w = mpriv->w;
  int dh = 0,dw =  0;
  int dy = 0;
  int need_h = 0,need_w = 0,ptr_l,sidx = 0;
  int th,count = 0;
  int bg_w;
  list_entry_t* m;

  if(mpriv->count < 1)
    return;

  if(h <= 0) h = mpi->height;
  if(w <= 0) w = mpi->width;
  dh = h - 2*mpriv->minb;
  dw = w - 2*mpriv->minb;
  ptr_l = mpriv->ptr ? menu_text_length(mpriv->ptr) : 0;
  // mpi is too small
  if(h - vo_font->height <= 0 || w - ptr_l <= 0 || dw <= 0 || dh <= 0)
    return;

  th = menu_text_num_lines(mpriv->title,dw) * (mpriv->vspace + vo_font->height) + mpriv->vspace;

  // the selected item is hidden, find a visible one
  if(mpriv->current->hide) {
    // try the next
    for(m = mpriv->current->next ; m ; m = m->next)
      if(!m->hide) break;
    if(!m) // or the previous
      for(m = mpriv->current->prev ; m ; m = m->prev)
        if(!m->hide) break;
    if(m) mpriv->current = m;
    else ptr_l = 0;
  }
  
  for(i = 0, m = mpriv->menu ; m ; m = m->next, i++) {
    int ll;
    if(m->hide) continue;
    ll = menu_text_length(m->txt);
    if(ptr_l + ll > need_w) need_w = ptr_l + ll;
    if(m == mpriv->current) sidx = i;
    count++;
  }
  if(need_w > dw) need_w = dw;
  if(x > 0)
    x += mpriv->minb;
  if(y > 0)
    y += mpriv->minb;
  else 
    y = mpriv->minb;

  need_h = count * (mpriv->vspace + vo_font->height) - mpriv->vspace;
  if( need_h + th > dh) {
    int start,end;
    mpriv->disp_lines = (dh + mpriv->vspace - th) / (mpriv->vspace + vo_font->height);
    if(mpriv->disp_lines < 4) {
      th = 0;
      mpriv->disp_lines = (dh + mpriv->vspace) / ( vo_font->height + mpriv->vspace);
    }
    // Too smoll
    if(mpriv->disp_lines < 1) return;
    need_h = mpriv->disp_lines*(mpriv->vspace + vo_font->height) - mpriv->vspace;

    start = sidx - (mpriv->disp_lines/2);
    if(start < 0) start = 0;
    end = start + mpriv->disp_lines;
    if(end > count) {
      end = count;
      if(end - start < mpriv->disp_lines)
	start = end - mpriv->disp_lines < 0 ? 0 : end - mpriv->disp_lines;
    }
    m = mpriv->menu;
    for(i = 0 ; m->next && i < start ; ) {
      if(!m->hide) i++;
      m = m->next;
    }
  } else {
    m = mpriv->menu;
    mpriv->disp_lines = count;
  }

  bg_w = need_w+2*mpriv->minb;
  if(th > 0) {
    if(mpriv->title_bg >= 0) {
      int tw,th2;
      menu_text_size(mpriv->title,dw,mpriv->vspace,1,&tw,&th2);
      if(tw+2*mpriv->minb > bg_w) bg_w = tw+2*mpriv->minb;
      menu_draw_box(mpi,mpriv->title_bg,mpriv->title_bg_alpha,
                    x < 0 ? (mpi->w-bg_w)/2 : x-mpriv->minb,dy+y-mpriv->vspace/2,bg_w,th);
    }
    menu_draw_text_full(mpi,mpriv->title,
			x < 0 ? mpi->w / 2 : x,
			dy+y,dw,0,
			mpriv->vspace,1,
			MENU_TEXT_TOP|MENU_TEXT_HCENTER,
			MENU_TEXT_TOP|(x < 0 ? MENU_TEXT_HCENTER :MENU_TEXT_LEFT));
    dy += th;
  }
  
  for( ; m != NULL && dy + vo_font->height < dh ; m = m->next ) {
    if(m->hide) continue;
    if(m == mpriv->current) {
      if(mpriv->ptr_bg >= 0)
        menu_draw_box(mpi,mpriv->ptr_bg,mpriv->ptr_bg_alpha,
                      x < 0 ? (mpi->w-bg_w)/2 : x-mpriv->minb,dy+y-mpriv->vspace/2,
                      bg_w,vo_font->height + mpriv->vspace);
      if(ptr_l > 0)
        menu_draw_text_full(mpi,mpriv->ptr,
                            x < 0 ? (mpi->w - need_w) / 2 + ptr_l : x,
                            dy+y,dw,dh - dy,
                            mpriv->vspace,0,
                            MENU_TEXT_TOP|(x < 0 ? MENU_TEXT_RIGHT :MENU_TEXT_LEFT) ,
                            MENU_TEXT_TOP|(x < 0 ? MENU_TEXT_RIGHT :MENU_TEXT_LEFT));
    } else if(mpriv->item_bg >= 0)
      menu_draw_box(mpi,mpriv->item_bg,mpriv->item_bg_alpha,
                    x < 0 ? (mpi->w-bg_w)/2 : x-mpriv->minb,dy+y-mpriv->vspace/2,
                    bg_w,vo_font->height + mpriv->vspace);
    menu_draw_text_full(mpi,m->txt,
			x < 0 ? (mpi->w - need_w) / 2  + ptr_l : x + ptr_l,
			dy+y,dw-ptr_l,dh - dy,
			mpriv->vspace,0,
			MENU_TEXT_TOP|MENU_TEXT_LEFT,
			MENU_TEXT_TOP|MENU_TEXT_LEFT);
    dy +=  vo_font->height + mpriv->vspace;
  }

}
Esempio n. 3
0
void menu_list_draw(menu_t* menu,mp_image_t* mpi) {
  int x = mpriv->x;
  int y = mpriv->y;
  int i;
  int h = mpriv->h;
  int w = mpriv->w;
  int dh = 0,dw =  0;
  int bx, dx, dy = 0;
  int need_h = 0,need_w = 0,ptr_l,sidx = 0;
  int th,count = 0;
  int bg_w;
  int line_h;
  list_entry_t* m;

  if(mpriv->count < 1)
    return;

  if(h <= 0) h = mpi->height;
  if(w <= 0) w = mpi->width;
  dh = h - 2*mpriv->minb;
  dw = w - 2*mpriv->minb;
  ptr_l = mpriv->ptr ? menu_text_length(mpriv->ptr) : 0;
  // mpi is too small
  if(h - vo_font->height <= 0 || w - ptr_l <= 0 || dw <= 0 || dh <= 0)
    return;

  line_h = mpriv->vspace + vo_font->height;
  th = menu_text_num_lines(mpriv->title,dw) * line_h + mpriv->vspace;

  // the selected item is hidden, find a visible one
  if(mpriv->current->hide) {
    // try the next
    for(m = mpriv->current->next ; m ; m = m->next)
      if(!m->hide) break;
    if(!m) // or the previous
      for(m = mpriv->current->prev ; m ; m = m->prev)
        if(!m->hide) break;
    if(m) mpriv->current = m;
    else ptr_l = 0;
  }

  for(i = 0, m = mpriv->menu ; m ; m = m->next, i++) {
    int ll;
    if(m->hide) continue;
    ll = menu_text_length(m->txt);
    if(ptr_l + ll > need_w) need_w = ptr_l + ll;
    if(m == mpriv->current) sidx = i;
    count++;
  }
  if(need_w > dw) need_w = dw;
  if(x >= 0)
    x += mpriv->minb;
  if(y > 0)
    y += mpriv->minb;
  else
    y = mpriv->minb;

  need_h = count * line_h - mpriv->vspace;
  if( need_h + th > dh) {
    int start,end;
    mpriv->disp_lines = (dh + mpriv->vspace - th) / line_h;
    if(mpriv->disp_lines < 4) {
      th = 0;
      mpriv->disp_lines = (dh + mpriv->vspace) / line_h;
    }
    // Too smoll
    if(mpriv->disp_lines < 1) return;
    need_h = mpriv->disp_lines * line_h - mpriv->vspace;

    start = sidx - (mpriv->disp_lines/2);
    if(start < 0) start = 0;
    end = start + mpriv->disp_lines;
    if(end > count) {
      end = count;
      if(end - start < mpriv->disp_lines)
	start = end - mpriv->disp_lines < 0 ? 0 : end - mpriv->disp_lines;
    }
    m = mpriv->menu;
    for(i = 0 ; m->next && i < start ; ) {
      if(!m->hide) i++;
      m = m->next;
    }
  } else {
    m = mpriv->menu;
    mpriv->disp_lines = count;
  }

  bg_w = need_w+2*mpriv->minb;
  if(th > 0) {
    int tw,th2;
    menu_text_size(mpriv->title,dw,mpriv->vspace,1,&tw,&th2);
    if(mpriv->title_bg >= 0) {
      if(tw+2*mpriv->minb > bg_w) bg_w = tw+2*mpriv->minb;
      menu_draw_box(mpi,mpriv->title_bg,mpriv->title_bg_alpha,
                    x < 0 ? (mpi->w-bg_w)/2 : x-mpriv->minb,dy+y-mpriv->vspace/2,bg_w,th);
    }
    menu_draw_text_full(mpi,mpriv->title,
			x < 0 ? mpi->w / 2 : x,
			dy+y, x < 0 ? dw : (tw > need_w ? tw : need_w), 0,
			mpriv->vspace,1,
			MENU_TEXT_TOP|MENU_TEXT_HCENTER,
			MENU_TEXT_TOP|(x < 0 ? MENU_TEXT_HCENTER :MENU_TEXT_LEFT));
    dy += th;
  }

  dx = x < 0 ? (mpi->w - need_w) / 2 : x;
  bx = x < 0 ? (mpi->w - bg_w) / 2 : x - mpriv->minb;

  // If mouse moved, try to update selected menu item by the mouse position.
  if (menu_mouse_pos_updated) {
    mouse_x = menu_mouse_x * mpi->width;
    mouse_y = menu_mouse_y * mpi->height;
    if (mouse_x >= bx && mouse_x < bx + bg_w) {
      int by = dy + y - mpriv->vspace / 2;
      int max_by = dh + y + mpriv->vspace / 2;
      if (mouse_y >= by && mouse_y < max_by) {
        int cur_no = (mouse_y - by) / line_h;
        list_entry_t* e = m;
        for (i = 0; e != NULL; e = e->next) {
          if (e->hide) continue;
          if (i == cur_no) {
            mpriv->current = e;
            break;
          }
          ++i;
        }
      }
    }
    menu_mouse_pos_updated = 0;
  }

  for( ; m != NULL && dy + vo_font->height < dh ; m = m->next ) {
    if(m->hide) continue;
    if(m == mpriv->current) {
      // Record rectangle of current selection box.
      selection_x = bx;
      selection_y = dy + y - mpriv->vspace / 2;
      selection_w = bg_w;
      selection_h = line_h;

      if(mpriv->ptr_bg >= 0)
        menu_draw_box(mpi,mpriv->ptr_bg,mpriv->ptr_bg_alpha,
                      bx, dy + y - mpriv->vspace / 2,
                      bg_w, line_h);
      if(ptr_l > 0)
        menu_draw_text_full(mpi,mpriv->ptr,
                            dx,
                            dy+y,dw,dh - dy,
                            mpriv->vspace,0,
                            MENU_TEXT_TOP|MENU_TEXT_LEFT,
                            MENU_TEXT_TOP|MENU_TEXT_LEFT);
    } else if(mpriv->item_bg >= 0)
      menu_draw_box(mpi,mpriv->item_bg,mpriv->item_bg_alpha,
                    bx, dy + y - mpriv->vspace / 2,
                    bg_w, line_h);
    menu_draw_text_full(mpi,m->txt,
			dx + ptr_l,
			dy+y,dw-ptr_l,dh - dy,
			mpriv->vspace,0,
			MENU_TEXT_TOP|MENU_TEXT_LEFT,
			MENU_TEXT_TOP|MENU_TEXT_LEFT);
    dy += line_h;
  }

}