annotate libmenu/menu_list.c @ 18708:9e2b300db17b

Change free_sh_audio() to take demuxer and stream id as parameters (same as new_sh_audio()) instead of sh_audio_t *, use those to remove the pointer from demuxer->a_streams[] before freeing it. Some demuxers use free_sh_audio() to undo the creation of an already-allocated audio stream in case of error. These uses were unsafe since free_sh_audio() freed the data structure but left the pointer in demuxer->a_streams[], leading to double free later in free_demuxer() (and perhaps use of the freed stream before that, I didn't check).
author uau
date Wed, 14 Jun 2006 14:05:59 +0000
parents df2c2642a65c
children ac69ba536915
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
1
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
2 #include <stdlib.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
3 #include <stdio.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
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
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
6
16862
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 10935
diff changeset
7 #include "config.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
8
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
9 #include "img_format.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
10 #include "mp_image.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
11
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
12 #include "m_struct.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
13 #include "menu.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
14
16862
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 10935
diff changeset
15 #include "libvo/font_load.h"
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 10935
diff changeset
16 #include "osdep/keycodes.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
17
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
18 #define IMPL 1
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
19 #include "menu_list.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
20
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
21 #define mpriv (menu->priv)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
22
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
23 void menu_list_draw(menu_t* menu,mp_image_t* mpi) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
24 int x = mpriv->x;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
25 int y = mpriv->y;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
26 int i;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
27 int h = mpriv->h;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
28 int w = mpriv->w;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
29 int dh = 0,dw = 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
30 int dy = 0;
17946
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
31 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
32 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
33 int bg_w;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
34 list_entry_t* m;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
35
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
36 if(mpriv->count < 1)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
37 return;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
38
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
39 if(h <= 0) h = mpi->height;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
40 if(w <= 0) w = mpi->width;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
41 dh = h - 2*mpriv->minb;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
42 dw = w - 2*mpriv->minb;
17946
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
43 ptr_l = mpriv->ptr ? menu_text_length(mpriv->ptr) : 0;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
44 // mpi is too small
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
45 if(h - vo_font->height <= 0 || w - ptr_l <= 0 || dw <= 0 || dh <= 0)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
46 return;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
47
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
48 th = menu_text_num_lines(mpriv->title,dw) * (mpriv->vspace + vo_font->height) + mpriv->vspace;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
49
17946
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
50 // the selected item is hidden, find a visible one
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
51 if(mpriv->current->hide) {
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
52 // try the next
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
53 for(m = mpriv->current->next ; m ; m = m->next)
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
54 if(!m->hide) break;
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
55 if(!m) // or the previous
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
56 for(m = mpriv->current->prev ; m ; m = m->prev)
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
57 if(!m->hide) break;
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
58 if(m) mpriv->current = m;
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
59 else ptr_l = 0;
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
60 }
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
61
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
62 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
63 int ll;
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
64 if(m->hide) continue;
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
65 ll = menu_text_length(m->txt);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
66 if(ptr_l + ll > need_w) need_w = ptr_l + ll;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
67 if(m == mpriv->current) sidx = i;
17946
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
68 count++;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
69 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
70 if(need_w > dw) need_w = dw;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
71 if(x > 0)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
72 x += mpriv->minb;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
73 if(y > 0)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
74 y += mpriv->minb;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
75 else
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
76 y = mpriv->minb;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
77
17946
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
78 need_h = count * (mpriv->vspace + vo_font->height) - mpriv->vspace;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
79 if( need_h + th > dh) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
80 int start,end;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
81 int maxl = (dh + mpriv->vspace - th) / (mpriv->vspace + vo_font->height);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
82 if(maxl < 4) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
83 th = 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
84 maxl = (dh + mpriv->vspace) / ( vo_font->height + mpriv->vspace);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
85 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
86 // Too smoll
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
87 if(maxl < 1) return;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
88 need_h = maxl*(mpriv->vspace + vo_font->height) - mpriv->vspace;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
89
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
90 start = sidx - (maxl/2);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
91 if(start < 0) start = 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
92 end = start + maxl;
17946
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
93 if(end > count) {
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
94 end = count;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
95 if(end - start < maxl)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
96 start = end - maxl < 0 ? 0 : end - maxl;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
97 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
98 m = mpriv->menu;
17946
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
99 for(i = 0 ; m->next && i < start ; ) {
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
100 if(!m->hide) i++;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
101 m = m->next;
17946
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
102 }
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
103 } else
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
104 m = mpriv->menu;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
105
17993
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17980
diff changeset
106 bg_w = need_w+2*mpriv->minb;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
107 if(th > 0) {
17993
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17980
diff changeset
108 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
109 int tw,th2;
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17980
diff changeset
110 menu_text_size(mpriv->title,dw,mpriv->vspace,1,&tw,&th2);
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17980
diff changeset
111 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
112 menu_draw_box(mpi,mpriv->title_bg,mpriv->title_bg_alpha,
18204
df2c2642a65c Verticaly center the background around the text.
albeu
parents: 17993
diff changeset
113 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
114 }
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
115 menu_draw_text_full(mpi,mpriv->title,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
116 x < 0 ? mpi->w / 2 : x,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
117 dy+y,dw,0,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
118 mpriv->vspace,1,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
119 MENU_TEXT_TOP|MENU_TEXT_HCENTER,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
120 MENU_TEXT_TOP|(x < 0 ? MENU_TEXT_HCENTER :MENU_TEXT_LEFT));
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
121 dy += th;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
122 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
123
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
124 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
125 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
126 if(m == mpriv->current) {
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17980
diff changeset
127 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
128 menu_draw_box(mpi,mpriv->ptr_bg,mpriv->ptr_bg_alpha,
18204
df2c2642a65c Verticaly center the background around the text.
albeu
parents: 17993
diff changeset
129 x < 0 ? (mpi->w-bg_w)/2 : x-mpriv->minb,dy+y-mpriv->vspace/2,
17993
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17980
diff changeset
130 bg_w,vo_font->height + mpriv->vspace);
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17980
diff changeset
131 if(ptr_l > 0)
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17980
diff changeset
132 menu_draw_text_full(mpi,mpriv->ptr,
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17980
diff changeset
133 x < 0 ? (mpi->w - need_w) / 2 + ptr_l : x,
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17980
diff changeset
134 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
135 mpriv->vspace,0,
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17980
diff changeset
136 MENU_TEXT_TOP|(x < 0 ? MENU_TEXT_RIGHT :MENU_TEXT_LEFT) ,
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17980
diff changeset
137 MENU_TEXT_TOP|(x < 0 ? MENU_TEXT_RIGHT :MENU_TEXT_LEFT));
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17980
diff changeset
138 } 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
139 menu_draw_box(mpi,mpriv->item_bg,mpriv->item_bg_alpha,
18204
df2c2642a65c Verticaly center the background around the text.
albeu
parents: 17993
diff changeset
140 x < 0 ? (mpi->w-bg_w)/2 : x-mpriv->minb,dy+y-mpriv->vspace/2,
17993
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17980
diff changeset
141 bg_w,vo_font->height + mpriv->vspace);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
142 menu_draw_text_full(mpi,m->txt,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
143 x < 0 ? (mpi->w - need_w) / 2 + ptr_l : x + ptr_l,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
144 dy+y,dw-ptr_l,dh - dy,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
145 mpriv->vspace,0,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
146 MENU_TEXT_TOP|MENU_TEXT_LEFT,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
147 MENU_TEXT_TOP|MENU_TEXT_LEFT);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
148 dy += vo_font->height + mpriv->vspace;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
149 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
150
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
151 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
152
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
153 void menu_list_read_cmd(menu_t* menu,int cmd) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
154 switch(cmd) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
155 case MENU_CMD_UP:
17980
05b65e0b8d6f Fix cycling in menu with hidden items.
albeu
parents: 17946
diff changeset
156 while(mpriv->current->prev) {
05b65e0b8d6f Fix cycling in menu with hidden items.
albeu
parents: 17946
diff changeset
157 mpriv->current = mpriv->current->prev;
17946
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
158 if(!mpriv->current->hide) return;
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
159 }
17980
05b65e0b8d6f Fix cycling in menu with hidden items.
albeu
parents: 17946
diff changeset
160 for( ; mpriv->current->next != NULL ; mpriv->current = mpriv->current->next)
05b65e0b8d6f Fix cycling in menu with hidden items.
albeu
parents: 17946
diff changeset
161 /* NOTHING */;
05b65e0b8d6f Fix cycling in menu with hidden items.
albeu
parents: 17946
diff changeset
162 if(!mpriv->current->hide) return;
17946
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
163 while(mpriv->current->prev) {
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
164 mpriv->current = mpriv->current->prev;
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
165 if(!mpriv->current->hide) return;
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
166 }
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
167 break;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
168 case MENU_CMD_DOWN:
17980
05b65e0b8d6f Fix cycling in menu with hidden items.
albeu
parents: 17946
diff changeset
169 while(mpriv->current->next) {
05b65e0b8d6f Fix cycling in menu with hidden items.
albeu
parents: 17946
diff changeset
170 mpriv->current = mpriv->current->next;
17946
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
171 if(!mpriv->current->hide) return;
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
172 }
17980
05b65e0b8d6f Fix cycling in menu with hidden items.
albeu
parents: 17946
diff changeset
173 mpriv->current = mpriv->menu;
05b65e0b8d6f Fix cycling in menu with hidden items.
albeu
parents: 17946
diff changeset
174 if(!mpriv->current->hide) return;
17946
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
175 while(mpriv->current->next) {
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
176 mpriv->current = mpriv->current->next;
17946
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
177 if(!mpriv->current->hide) return;
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
178 }
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
179 break;
17945
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
180 case MENU_CMD_LEFT:
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
181 case MENU_CMD_CANCEL:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
182 menu->show = 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
183 menu->cl = 1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
184 break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
185 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
186 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
187
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
188 void 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
189 if(c < 256 && isalnum(c)) {
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
190 list_entry_t* e = mpriv->current;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
191 if(e->txt[0] == c) e = e->next;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
192 for( ; e ; e = e->next) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
193 if(e->txt[0] == c) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
194 mpriv->current = e;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
195 return;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
196 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
197 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
198 for(e = mpriv->menu ; e ; e = e->next) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
199 if(e->txt[0] == c) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
200 mpriv->current = e;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
201 return;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
202 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
203 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
204 } else
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
205 menu_dflt_read_key(menu,c);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
206 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
207
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
208 void menu_list_read_key(menu_t* menu,int c,int jump_to) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
209 list_entry_t* m;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
210 int i;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
211 switch(c) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
212 case KEY_HOME:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
213 mpriv->current = mpriv->menu;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
214 break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
215 case KEY_END:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
216 for(m = mpriv->current ; m && m->next ; m = m->next)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
217 /**/;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
218 if(m)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
219 mpriv->current = m;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
220 break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
221 case KEY_PAGE_UP:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
222 for(i = 0, m = mpriv->current ; m && m->prev && i < 10 ; m = m->prev, i++)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
223 /**/;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
224 if(m)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
225 mpriv->current = m;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
226 break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
227 case KEY_PAGE_DOWN:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
228 for(i = 0, m = mpriv->current ; m && m->next && i < 10 ; m = m->next, i++)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
229 /**/;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
230 if(m)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
231 mpriv->current = m;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
232 break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
233 default:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
234 if(jump_to)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
235 menu_list_jump_to_key(menu,c);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
236 else
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
237 menu_dflt_read_key(menu,c);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
238 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
239 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
240
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
241 void menu_list_add_entry(menu_t* menu,list_entry_t* entry) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
242 list_entry_t* l;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
243 mpriv->count++;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
244
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
245 if(mpriv->menu == NULL) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
246 mpriv->menu = mpriv->current = entry;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
247 return;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
248 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
249
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
250 for(l = mpriv->menu ; l->next != NULL ; l = l->next)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
251 /* NOP */;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
252 l->next = entry;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
253 entry->prev = l;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
254 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
255
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
256 void menu_list_init(menu_t* menu) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
257 if(!mpriv)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
258 mpriv = calloc(1,sizeof(struct menu_priv_s));
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
259
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
260 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
261
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
262 void menu_list_uninit(menu_t* menu,free_entry_t free_func) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
263 list_entry_t *i,*j;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
264
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
265 if(!free_func) free_func = (free_entry_t)free;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
266
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
267 for(i = mpriv->menu ; i != NULL ; ) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
268 j = i->next;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
269 free_func(i);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
270 i = j;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
271 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
272
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
273 mpriv->menu = mpriv->current = NULL;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
274
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
275 }
17945
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
276