Mercurial > mplayer.hg
annotate libmenu/menu_list.c @ 26234:f0788169e503
Ignore if we fail to get disc key, fixes playback of one of my DVDs which
claims to be scrambled but actually is not, and always allows to
fallback to cached keys.
author | reimar |
---|---|
date | Fri, 21 Mar 2008 12:31:47 +0000 |
parents | 7ef04742572c |
children | f8b6c7045cf8 |
rev | line source |
---|---|
8197 | 1 |
2 #include <stdlib.h> | |
3 #include <stdio.h> | |
4 #include <ctype.h> | |
8623
440301fef3fe
Added/reordered #includes to silence warnings about "implicit declaration".
rathann
parents:
8197
diff
changeset
|
5 #include <string.h> |
8197 | 6 |
16862 | 7 #include "config.h" |
8197 | 8 |
19431
ac69ba536915
Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents:
18204
diff
changeset
|
9 #include "libmpcodecs/img_format.h" |
ac69ba536915
Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents:
18204
diff
changeset
|
10 #include "libmpcodecs/mp_image.h" |
8197 | 11 |
12 #include "m_struct.h" | |
13 #include "menu.h" | |
14 | |
16862 | 15 #include "libvo/font_load.h" |
16 #include "osdep/keycodes.h" | |
8197 | 17 |
18 #define IMPL 1 | |
19 #include "menu_list.h" | |
20 | |
25461 | 21 extern double menu_mouse_x; |
22 extern double menu_mouse_y; | |
23 extern int menu_mouse_pos_updated; | |
24 static int mouse_x; | |
25 static int mouse_y; | |
26 static int selection_x; | |
27 static int selection_y; | |
28 static int selection_w; | |
29 static int selection_h; | |
30 | |
8197 | 31 #define mpriv (menu->priv) |
32 | |
33 void menu_list_draw(menu_t* menu,mp_image_t* mpi) { | |
34 int x = mpriv->x; | |
35 int y = mpriv->y; | |
36 int i; | |
37 int h = mpriv->h; | |
38 int w = mpriv->w; | |
39 int dh = 0,dw = 0; | |
25438
11cd0fdfcb4a
Add variable bx, dx to simplify code of function menu_draw_list.
ulion
parents:
25437
diff
changeset
|
40 int bx, dx, dy = 0; |
17946
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
41 int need_h = 0,need_w = 0,ptr_l,sidx = 0; |
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
42 int th,count = 0; |
17993
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17980
diff
changeset
|
43 int bg_w; |
25437
2664bccccb80
Add local variable 'line_h' to simplify code of function menu_list_draw.
ulion
parents:
25435
diff
changeset
|
44 int line_h; |
8197 | 45 list_entry_t* m; |
46 | |
47 if(mpriv->count < 1) | |
48 return; | |
49 | |
50 if(h <= 0) h = mpi->height; | |
51 if(w <= 0) w = mpi->width; | |
52 dh = h - 2*mpriv->minb; | |
53 dw = w - 2*mpriv->minb; | |
17946
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
54 ptr_l = mpriv->ptr ? menu_text_length(mpriv->ptr) : 0; |
8197 | 55 // mpi is too small |
56 if(h - vo_font->height <= 0 || w - ptr_l <= 0 || dw <= 0 || dh <= 0) | |
57 return; | |
58 | |
25437
2664bccccb80
Add local variable 'line_h' to simplify code of function menu_list_draw.
ulion
parents:
25435
diff
changeset
|
59 line_h = mpriv->vspace + vo_font->height; |
2664bccccb80
Add local variable 'line_h' to simplify code of function menu_list_draw.
ulion
parents:
25435
diff
changeset
|
60 th = menu_text_num_lines(mpriv->title,dw) * line_h + mpriv->vspace; |
8197 | 61 |
17946
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
62 // the selected item is hidden, find a visible one |
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
63 if(mpriv->current->hide) { |
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
64 // try the next |
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
65 for(m = mpriv->current->next ; m ; m = m->next) |
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
66 if(!m->hide) break; |
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
67 if(!m) // or the previous |
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
68 for(m = mpriv->current->prev ; m ; m = m->prev) |
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
69 if(!m->hide) break; |
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
70 if(m) mpriv->current = m; |
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
71 else ptr_l = 0; |
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
72 } |
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
73 |
8197 | 74 for(i = 0, m = mpriv->menu ; m ; m = m->next, i++) { |
17946
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
75 int ll; |
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
76 if(m->hide) continue; |
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
77 ll = menu_text_length(m->txt); |
8197 | 78 if(ptr_l + ll > need_w) need_w = ptr_l + ll; |
79 if(m == mpriv->current) sidx = i; | |
17946
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
80 count++; |
8197 | 81 } |
82 if(need_w > dw) need_w = dw; | |
25421
cc1b8a9d0ae2
Here should add the minb to x when x>=0 because in later code
ulion
parents:
25263
diff
changeset
|
83 if(x >= 0) |
8197 | 84 x += mpriv->minb; |
85 if(y > 0) | |
86 y += mpriv->minb; | |
87 else | |
88 y = mpriv->minb; | |
89 | |
25437
2664bccccb80
Add local variable 'line_h' to simplify code of function menu_list_draw.
ulion
parents:
25435
diff
changeset
|
90 need_h = count * line_h - mpriv->vspace; |
8197 | 91 if( need_h + th > dh) { |
92 int start,end; | |
25437
2664bccccb80
Add local variable 'line_h' to simplify code of function menu_list_draw.
ulion
parents:
25435
diff
changeset
|
93 mpriv->disp_lines = (dh + mpriv->vspace - th) / line_h; |
24979
476d4922566a
Make page up and down with proper page size instead of always 10 rows.
ulion
parents:
19431
diff
changeset
|
94 if(mpriv->disp_lines < 4) { |
8197 | 95 th = 0; |
25437
2664bccccb80
Add local variable 'line_h' to simplify code of function menu_list_draw.
ulion
parents:
25435
diff
changeset
|
96 mpriv->disp_lines = (dh + mpriv->vspace) / line_h; |
8197 | 97 } |
98 // Too smoll | |
24979
476d4922566a
Make page up and down with proper page size instead of always 10 rows.
ulion
parents:
19431
diff
changeset
|
99 if(mpriv->disp_lines < 1) return; |
25437
2664bccccb80
Add local variable 'line_h' to simplify code of function menu_list_draw.
ulion
parents:
25435
diff
changeset
|
100 need_h = mpriv->disp_lines * line_h - mpriv->vspace; |
8197 | 101 |
24979
476d4922566a
Make page up and down with proper page size instead of always 10 rows.
ulion
parents:
19431
diff
changeset
|
102 start = sidx - (mpriv->disp_lines/2); |
8197 | 103 if(start < 0) start = 0; |
24979
476d4922566a
Make page up and down with proper page size instead of always 10 rows.
ulion
parents:
19431
diff
changeset
|
104 end = start + mpriv->disp_lines; |
17946
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
105 if(end > count) { |
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
106 end = count; |
24979
476d4922566a
Make page up and down with proper page size instead of always 10 rows.
ulion
parents:
19431
diff
changeset
|
107 if(end - start < mpriv->disp_lines) |
476d4922566a
Make page up and down with proper page size instead of always 10 rows.
ulion
parents:
19431
diff
changeset
|
108 start = end - mpriv->disp_lines < 0 ? 0 : end - mpriv->disp_lines; |
8197 | 109 } |
110 m = mpriv->menu; | |
17946
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
111 for(i = 0 ; m->next && i < start ; ) { |
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
112 if(!m->hide) i++; |
8197 | 113 m = m->next; |
17946
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
114 } |
24979
476d4922566a
Make page up and down with proper page size instead of always 10 rows.
ulion
parents:
19431
diff
changeset
|
115 } else { |
8197 | 116 m = mpriv->menu; |
24979
476d4922566a
Make page up and down with proper page size instead of always 10 rows.
ulion
parents:
19431
diff
changeset
|
117 mpriv->disp_lines = count; |
476d4922566a
Make page up and down with proper page size instead of always 10 rows.
ulion
parents:
19431
diff
changeset
|
118 } |
8197 | 119 |
17993
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17980
diff
changeset
|
120 bg_w = need_w+2*mpriv->minb; |
8197 | 121 if(th > 0) { |
25435
5779358c3f86
Currently menu title did not align center together with menu items when x>=0.
ulion
parents:
25421
diff
changeset
|
122 int tw,th2; |
5779358c3f86
Currently menu title did not align center together with menu items when x>=0.
ulion
parents:
25421
diff
changeset
|
123 menu_text_size(mpriv->title,dw,mpriv->vspace,1,&tw,&th2); |
17993
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17980
diff
changeset
|
124 if(mpriv->title_bg >= 0) { |
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17980
diff
changeset
|
125 if(tw+2*mpriv->minb > bg_w) bg_w = tw+2*mpriv->minb; |
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17980
diff
changeset
|
126 menu_draw_box(mpi,mpriv->title_bg,mpriv->title_bg_alpha, |
18204 | 127 x < 0 ? (mpi->w-bg_w)/2 : x-mpriv->minb,dy+y-mpriv->vspace/2,bg_w,th); |
17993
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17980
diff
changeset
|
128 } |
8197 | 129 menu_draw_text_full(mpi,mpriv->title, |
130 x < 0 ? mpi->w / 2 : x, | |
25435
5779358c3f86
Currently menu title did not align center together with menu items when x>=0.
ulion
parents:
25421
diff
changeset
|
131 dy+y, x < 0 ? dw : (tw > need_w ? tw : need_w), 0, |
8197 | 132 mpriv->vspace,1, |
133 MENU_TEXT_TOP|MENU_TEXT_HCENTER, | |
134 MENU_TEXT_TOP|(x < 0 ? MENU_TEXT_HCENTER :MENU_TEXT_LEFT)); | |
135 dy += th; | |
136 } | |
137 | |
25438
11cd0fdfcb4a
Add variable bx, dx to simplify code of function menu_draw_list.
ulion
parents:
25437
diff
changeset
|
138 dx = x < 0 ? (mpi->w - need_w) / 2 : x; |
11cd0fdfcb4a
Add variable bx, dx to simplify code of function menu_draw_list.
ulion
parents:
25437
diff
changeset
|
139 bx = x < 0 ? (mpi->w - bg_w) / 2 : x - mpriv->minb; |
25461 | 140 |
141 // If mouse moved, try to update selected menu item by the mouse position. | |
142 if (menu_mouse_pos_updated) { | |
143 mouse_x = menu_mouse_x * mpi->width; | |
144 mouse_y = menu_mouse_y * mpi->height; | |
145 if (mouse_x >= bx && mouse_x < bx + bg_w) { | |
146 int by = dy + y - mpriv->vspace / 2; | |
147 int max_by = dh + y + mpriv->vspace / 2; | |
148 if (mouse_y >= by && mouse_y < max_by) { | |
149 int cur_no = (mouse_y - by) / line_h; | |
150 list_entry_t* e = m; | |
151 for (i = 0; e != NULL; e = e->next) { | |
152 if (e->hide) continue; | |
153 if (i == cur_no) { | |
154 mpriv->current = e; | |
155 break; | |
156 } | |
157 ++i; | |
158 } | |
159 } | |
160 } | |
161 menu_mouse_pos_updated = 0; | |
162 } | |
163 | |
8197 | 164 for( ; m != NULL && dy + vo_font->height < dh ; m = m->next ) { |
17946
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
165 if(m->hide) continue; |
17993
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17980
diff
changeset
|
166 if(m == mpriv->current) { |
25461 | 167 // Record rectangle of current selection box. |
168 selection_x = bx; | |
169 selection_y = dy + y - mpriv->vspace / 2; | |
170 selection_w = bg_w; | |
171 selection_h = line_h; | |
172 | |
17993
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17980
diff
changeset
|
173 if(mpriv->ptr_bg >= 0) |
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17980
diff
changeset
|
174 menu_draw_box(mpi,mpriv->ptr_bg,mpriv->ptr_bg_alpha, |
25438
11cd0fdfcb4a
Add variable bx, dx to simplify code of function menu_draw_list.
ulion
parents:
25437
diff
changeset
|
175 bx, dy + y - mpriv->vspace / 2, |
25437
2664bccccb80
Add local variable 'line_h' to simplify code of function menu_list_draw.
ulion
parents:
25435
diff
changeset
|
176 bg_w, line_h); |
17993
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17980
diff
changeset
|
177 if(ptr_l > 0) |
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17980
diff
changeset
|
178 menu_draw_text_full(mpi,mpriv->ptr, |
25438
11cd0fdfcb4a
Add variable bx, dx to simplify code of function menu_draw_list.
ulion
parents:
25437
diff
changeset
|
179 dx, |
17993
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17980
diff
changeset
|
180 dy+y,dw,dh - dy, |
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17980
diff
changeset
|
181 mpriv->vspace,0, |
25438
11cd0fdfcb4a
Add variable bx, dx to simplify code of function menu_draw_list.
ulion
parents:
25437
diff
changeset
|
182 MENU_TEXT_TOP|MENU_TEXT_LEFT, |
11cd0fdfcb4a
Add variable bx, dx to simplify code of function menu_draw_list.
ulion
parents:
25437
diff
changeset
|
183 MENU_TEXT_TOP|MENU_TEXT_LEFT); |
17993
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17980
diff
changeset
|
184 } else if(mpriv->item_bg >= 0) |
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17980
diff
changeset
|
185 menu_draw_box(mpi,mpriv->item_bg,mpriv->item_bg_alpha, |
25438
11cd0fdfcb4a
Add variable bx, dx to simplify code of function menu_draw_list.
ulion
parents:
25437
diff
changeset
|
186 bx, dy + y - mpriv->vspace / 2, |
25437
2664bccccb80
Add local variable 'line_h' to simplify code of function menu_list_draw.
ulion
parents:
25435
diff
changeset
|
187 bg_w, line_h); |
8197 | 188 menu_draw_text_full(mpi,m->txt, |
25438
11cd0fdfcb4a
Add variable bx, dx to simplify code of function menu_draw_list.
ulion
parents:
25437
diff
changeset
|
189 dx + ptr_l, |
8197 | 190 dy+y,dw-ptr_l,dh - dy, |
191 mpriv->vspace,0, | |
192 MENU_TEXT_TOP|MENU_TEXT_LEFT, | |
193 MENU_TEXT_TOP|MENU_TEXT_LEFT); | |
25437
2664bccccb80
Add local variable 'line_h' to simplify code of function menu_list_draw.
ulion
parents:
25435
diff
changeset
|
194 dy += line_h; |
8197 | 195 } |
196 | |
197 } | |
198 | |
199 void menu_list_read_cmd(menu_t* menu,int cmd) { | |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
24979
diff
changeset
|
200 list_entry_t* m; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
24979
diff
changeset
|
201 int i; |
8197 | 202 switch(cmd) { |
203 case MENU_CMD_UP: | |
17980 | 204 while(mpriv->current->prev) { |
205 mpriv->current = mpriv->current->prev; | |
17946
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
206 if(!mpriv->current->hide) return; |
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
207 } |
17980 | 208 for( ; mpriv->current->next != NULL ; mpriv->current = mpriv->current->next) |
209 /* NOTHING */; | |
210 if(!mpriv->current->hide) return; | |
17946
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
211 while(mpriv->current->prev) { |
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
212 mpriv->current = mpriv->current->prev; |
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
213 if(!mpriv->current->hide) return; |
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
214 } |
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
215 break; |
8197 | 216 case MENU_CMD_DOWN: |
17980 | 217 while(mpriv->current->next) { |
218 mpriv->current = mpriv->current->next; | |
17946
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
219 if(!mpriv->current->hide) return; |
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
220 } |
17980 | 221 mpriv->current = mpriv->menu; |
222 if(!mpriv->current->hide) return; | |
17946
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
223 while(mpriv->current->next) { |
8197 | 224 mpriv->current = mpriv->current->next; |
17946
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
225 if(!mpriv->current->hide) return; |
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
226 } |
0afe12256464
Allow hiding list elements and disableing the pointer.
albeu
parents:
17945
diff
changeset
|
227 break; |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
24979
diff
changeset
|
228 case MENU_CMD_HOME: |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
24979
diff
changeset
|
229 mpriv->current = mpriv->menu; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
24979
diff
changeset
|
230 break; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
24979
diff
changeset
|
231 case MENU_CMD_END: |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
24979
diff
changeset
|
232 for(m = mpriv->current ; m && m->next ; m = m->next) |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
24979
diff
changeset
|
233 /**/; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
24979
diff
changeset
|
234 if(m) |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
24979
diff
changeset
|
235 mpriv->current = m; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
24979
diff
changeset
|
236 break; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
24979
diff
changeset
|
237 case MENU_CMD_PAGE_UP: |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
24979
diff
changeset
|
238 for(i = 0, m = mpriv->current ; m && m->prev && i < mpriv->disp_lines ; m = m->prev, i++) |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
24979
diff
changeset
|
239 /**/; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
24979
diff
changeset
|
240 if(m) |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
24979
diff
changeset
|
241 mpriv->current = m; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
24979
diff
changeset
|
242 break; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
24979
diff
changeset
|
243 case MENU_CMD_PAGE_DOWN: |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
24979
diff
changeset
|
244 for(i = 0, m = mpriv->current ; m && m->next && i < mpriv->disp_lines ; m = m->next, i++) |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
24979
diff
changeset
|
245 /**/; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
24979
diff
changeset
|
246 if(m) |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
24979
diff
changeset
|
247 mpriv->current = m; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
24979
diff
changeset
|
248 break; |
17945
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
16862
diff
changeset
|
249 case MENU_CMD_LEFT: |
8197 | 250 case MENU_CMD_CANCEL: |
251 menu->show = 0; | |
252 menu->cl = 1; | |
253 break; | |
25461 | 254 case MENU_CMD_CLICK: |
255 if (mouse_x >= selection_x && mouse_x < selection_x + selection_w && | |
256 mouse_y >= selection_y && mouse_y < selection_y + selection_h) | |
257 menu_read_cmd(menu, MENU_CMD_OK); | |
258 break; | |
8197 | 259 } |
260 } | |
261 | |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
24979
diff
changeset
|
262 int menu_list_jump_to_key(menu_t* menu,int c) { |
10935
ec8a1e6443d5
Fix long-known bug with handling 'down key' in lists.
lumag
parents:
9380
diff
changeset
|
263 if(c < 256 && isalnum(c)) { |
8197 | 264 list_entry_t* e = mpriv->current; |
265 if(e->txt[0] == c) e = e->next; | |
266 for( ; e ; e = e->next) { | |
267 if(e->txt[0] == c) { | |
268 mpriv->current = e; | |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
24979
diff
changeset
|
269 return 1; |
8197 | 270 } |
271 } | |
272 for(e = mpriv->menu ; e ; e = e->next) { | |
273 if(e->txt[0] == c) { | |
274 mpriv->current = e; | |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
24979
diff
changeset
|
275 return 1; |
8197 | 276 } |
277 } | |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
24979
diff
changeset
|
278 return 1; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
24979
diff
changeset
|
279 } |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
24979
diff
changeset
|
280 return 0; |
8197 | 281 } |
282 | |
283 void menu_list_add_entry(menu_t* menu,list_entry_t* entry) { | |
284 list_entry_t* l; | |
285 mpriv->count++; | |
286 | |
287 if(mpriv->menu == NULL) { | |
288 mpriv->menu = mpriv->current = entry; | |
289 return; | |
290 } | |
291 | |
292 for(l = mpriv->menu ; l->next != NULL ; l = l->next) | |
293 /* NOP */; | |
294 l->next = entry; | |
295 entry->prev = l; | |
296 } | |
297 | |
298 void menu_list_init(menu_t* menu) { | |
299 if(!mpriv) | |
300 mpriv = calloc(1,sizeof(struct menu_priv_s)); | |
301 | |
302 } | |
303 | |
304 void menu_list_uninit(menu_t* menu,free_entry_t free_func) { | |
305 list_entry_t *i,*j; | |
306 | |
307 if(!free_func) free_func = (free_entry_t)free; | |
308 | |
309 for(i = mpriv->menu ; i != NULL ; ) { | |
310 j = i->next; | |
311 free_func(i); | |
312 i = j; | |
313 } | |
314 | |
315 mpriv->menu = mpriv->current = NULL; | |
316 | |
317 } | |
17945
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
16862
diff
changeset
|
318 |