comparison libmenu/menu_list.c @ 25437:2664bccccb80

Add local variable 'line_h' to simplify code of function menu_list_draw.
author ulion
date Thu, 20 Dec 2007 02:17:29 +0000
parents 5779358c3f86
children 11cd0fdfcb4a
comparison
equal deleted inserted replaced
25436:333ba4e7d5e3 25437:2664bccccb80
29 int dh = 0,dw = 0; 29 int dh = 0,dw = 0;
30 int dy = 0; 30 int dy = 0;
31 int need_h = 0,need_w = 0,ptr_l,sidx = 0; 31 int need_h = 0,need_w = 0,ptr_l,sidx = 0;
32 int th,count = 0; 32 int th,count = 0;
33 int bg_w; 33 int bg_w;
34 int line_h;
34 list_entry_t* m; 35 list_entry_t* m;
35 36
36 if(mpriv->count < 1) 37 if(mpriv->count < 1)
37 return; 38 return;
38 39
43 ptr_l = mpriv->ptr ? menu_text_length(mpriv->ptr) : 0; 44 ptr_l = mpriv->ptr ? menu_text_length(mpriv->ptr) : 0;
44 // mpi is too small 45 // mpi is too small
45 if(h - vo_font->height <= 0 || w - ptr_l <= 0 || dw <= 0 || dh <= 0) 46 if(h - vo_font->height <= 0 || w - ptr_l <= 0 || dw <= 0 || dh <= 0)
46 return; 47 return;
47 48
48 th = menu_text_num_lines(mpriv->title,dw) * (mpriv->vspace + vo_font->height) + mpriv->vspace; 49 line_h = mpriv->vspace + vo_font->height;
50 th = menu_text_num_lines(mpriv->title,dw) * line_h + mpriv->vspace;
49 51
50 // the selected item is hidden, find a visible one 52 // the selected item is hidden, find a visible one
51 if(mpriv->current->hide) { 53 if(mpriv->current->hide) {
52 // try the next 54 // try the next
53 for(m = mpriv->current->next ; m ; m = m->next) 55 for(m = mpriv->current->next ; m ; m = m->next)
73 if(y > 0) 75 if(y > 0)
74 y += mpriv->minb; 76 y += mpriv->minb;
75 else 77 else
76 y = mpriv->minb; 78 y = mpriv->minb;
77 79
78 need_h = count * (mpriv->vspace + vo_font->height) - mpriv->vspace; 80 need_h = count * line_h - mpriv->vspace;
79 if( need_h + th > dh) { 81 if( need_h + th > dh) {
80 int start,end; 82 int start,end;
81 mpriv->disp_lines = (dh + mpriv->vspace - th) / (mpriv->vspace + vo_font->height); 83 mpriv->disp_lines = (dh + mpriv->vspace - th) / line_h;
82 if(mpriv->disp_lines < 4) { 84 if(mpriv->disp_lines < 4) {
83 th = 0; 85 th = 0;
84 mpriv->disp_lines = (dh + mpriv->vspace) / ( vo_font->height + mpriv->vspace); 86 mpriv->disp_lines = (dh + mpriv->vspace) / line_h;
85 } 87 }
86 // Too smoll 88 // Too smoll
87 if(mpriv->disp_lines < 1) return; 89 if(mpriv->disp_lines < 1) return;
88 need_h = mpriv->disp_lines*(mpriv->vspace + vo_font->height) - mpriv->vspace; 90 need_h = mpriv->disp_lines * line_h - mpriv->vspace;
89 91
90 start = sidx - (mpriv->disp_lines/2); 92 start = sidx - (mpriv->disp_lines/2);
91 if(start < 0) start = 0; 93 if(start < 0) start = 0;
92 end = start + mpriv->disp_lines; 94 end = start + mpriv->disp_lines;
93 if(end > count) { 95 if(end > count) {
127 if(m->hide) continue; 129 if(m->hide) continue;
128 if(m == mpriv->current) { 130 if(m == mpriv->current) {
129 if(mpriv->ptr_bg >= 0) 131 if(mpriv->ptr_bg >= 0)
130 menu_draw_box(mpi,mpriv->ptr_bg,mpriv->ptr_bg_alpha, 132 menu_draw_box(mpi,mpriv->ptr_bg,mpriv->ptr_bg_alpha,
131 x < 0 ? (mpi->w-bg_w)/2 : x-mpriv->minb,dy+y-mpriv->vspace/2, 133 x < 0 ? (mpi->w-bg_w)/2 : x-mpriv->minb,dy+y-mpriv->vspace/2,
132 bg_w,vo_font->height + mpriv->vspace); 134 bg_w, line_h);
133 if(ptr_l > 0) 135 if(ptr_l > 0)
134 menu_draw_text_full(mpi,mpriv->ptr, 136 menu_draw_text_full(mpi,mpriv->ptr,
135 x < 0 ? (mpi->w - need_w) / 2 + ptr_l : x, 137 x < 0 ? (mpi->w - need_w) / 2 + ptr_l : x,
136 dy+y,dw,dh - dy, 138 dy+y,dw,dh - dy,
137 mpriv->vspace,0, 139 mpriv->vspace,0,
138 MENU_TEXT_TOP|(x < 0 ? MENU_TEXT_RIGHT :MENU_TEXT_LEFT) , 140 MENU_TEXT_TOP|(x < 0 ? MENU_TEXT_RIGHT :MENU_TEXT_LEFT) ,
139 MENU_TEXT_TOP|(x < 0 ? MENU_TEXT_RIGHT :MENU_TEXT_LEFT)); 141 MENU_TEXT_TOP|(x < 0 ? MENU_TEXT_RIGHT :MENU_TEXT_LEFT));
140 } else if(mpriv->item_bg >= 0) 142 } else if(mpriv->item_bg >= 0)
141 menu_draw_box(mpi,mpriv->item_bg,mpriv->item_bg_alpha, 143 menu_draw_box(mpi,mpriv->item_bg,mpriv->item_bg_alpha,
142 x < 0 ? (mpi->w-bg_w)/2 : x-mpriv->minb,dy+y-mpriv->vspace/2, 144 x < 0 ? (mpi->w-bg_w)/2 : x-mpriv->minb,dy+y-mpriv->vspace/2,
143 bg_w,vo_font->height + mpriv->vspace); 145 bg_w, line_h);
144 menu_draw_text_full(mpi,m->txt, 146 menu_draw_text_full(mpi,m->txt,
145 x < 0 ? (mpi->w - need_w) / 2 + ptr_l : x + ptr_l, 147 x < 0 ? (mpi->w - need_w) / 2 + ptr_l : x + ptr_l,
146 dy+y,dw-ptr_l,dh - dy, 148 dy+y,dw-ptr_l,dh - dy,
147 mpriv->vspace,0, 149 mpriv->vspace,0,
148 MENU_TEXT_TOP|MENU_TEXT_LEFT, 150 MENU_TEXT_TOP|MENU_TEXT_LEFT,
149 MENU_TEXT_TOP|MENU_TEXT_LEFT); 151 MENU_TEXT_TOP|MENU_TEXT_LEFT);
150 dy += vo_font->height + mpriv->vspace; 152 dy += line_h;
151 } 153 }
152 154
153 } 155 }
154 156
155 void menu_list_read_cmd(menu_t* menu,int cmd) { 157 void menu_list_read_cmd(menu_t* menu,int cmd) {