annotate libmenu/menu_list.c @ 30521:828219ec9742

Remove useless casts.
author reimar
date Sun, 14 Feb 2010 11:09:24 +0000
parents 0f1b5b68af32
children 32725ca88fed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28113
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 25461
diff changeset
1 /*
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 25461
diff changeset
2 * This file is part of MPlayer.
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 25461
diff changeset
3 *
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 25461
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 25461
diff changeset
5 * it under the terms of the GNU General Public License as published by
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 25461
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 25461
diff changeset
7 * (at your option) any later version.
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 25461
diff changeset
8 *
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 25461
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 25461
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 25461
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 25461
diff changeset
12 * GNU General Public License for more details.
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 25461
diff changeset
13 *
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 25461
diff changeset
14 * You should have received a copy of the GNU General Public License along
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 25461
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 25461
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
f8b6c7045cf8 Add standard GPL headers.
diego
parents: 25461
diff changeset
17 */
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
18
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
19 #include <stdlib.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
20 #include <stdio.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
21 #include <ctype.h>
8623
440301fef3fe Added/reordered #includes to silence warnings about "implicit declaration".
rathann
parents: 8197
diff changeset
22 #include <string.h>
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
23
16862
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 10935
diff changeset
24 #include "config.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
25
19431
ac69ba536915 Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents: 18204
diff changeset
26 #include "libmpcodecs/img_format.h"
ac69ba536915 Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents: 18204
diff changeset
27 #include "libmpcodecs/mp_image.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
28
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
29 #include "m_struct.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
30 #include "menu.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
31
16862
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 10935
diff changeset
32 #include "libvo/font_load.h"
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 10935
diff changeset
33 #include "osdep/keycodes.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
34
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
35 #define IMPL 1
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
36 #include "menu_list.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
37
25461
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
38 extern double menu_mouse_x;
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
39 extern double menu_mouse_y;
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
40 extern int menu_mouse_pos_updated;
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
41 static int mouse_x;
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
42 static int mouse_y;
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
43 static int selection_x;
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
44 static int selection_y;
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
45 static int selection_w;
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
46 static int selection_h;
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
47
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
48 #define mpriv (menu->priv)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
49
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
50 void menu_list_draw(menu_t* menu,mp_image_t* mpi) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
51 int x = mpriv->x;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
52 int y = mpriv->y;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
53 int i;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
54 int h = mpriv->h;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
55 int w = mpriv->w;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
56 int dh = 0,dw = 0;
25438
11cd0fdfcb4a Add variable bx, dx to simplify code of function menu_draw_list.
ulion
parents: 25437
diff changeset
57 int bx, dx, dy = 0;
17946
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
58 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
59 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
60 int bg_w;
25437
2664bccccb80 Add local variable 'line_h' to simplify code of function menu_list_draw.
ulion
parents: 25435
diff changeset
61 int line_h;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
62 list_entry_t* m;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
63
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
64 if(mpriv->count < 1)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
65 return;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
66
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
67 if(h <= 0) h = mpi->height;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
68 if(w <= 0) w = mpi->width;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
69 dh = h - 2*mpriv->minb;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
70 dw = w - 2*mpriv->minb;
17946
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
71 ptr_l = mpriv->ptr ? menu_text_length(mpriv->ptr) : 0;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
72 // mpi is too small
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
73 if(h - vo_font->height <= 0 || w - ptr_l <= 0 || dw <= 0 || dh <= 0)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
74 return;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
75
25437
2664bccccb80 Add local variable 'line_h' to simplify code of function menu_list_draw.
ulion
parents: 25435
diff changeset
76 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
77 th = menu_text_num_lines(mpriv->title,dw) * line_h + mpriv->vspace;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
78
17946
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
79 // the selected item is hidden, find a visible one
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
80 if(mpriv->current->hide) {
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
81 // try the next
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
82 for(m = mpriv->current->next ; m ; m = m->next)
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
83 if(!m->hide) break;
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
84 if(!m) // or the previous
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
85 for(m = mpriv->current->prev ; m ; m = m->prev)
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
86 if(!m->hide) break;
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
87 if(m) mpriv->current = m;
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
88 else ptr_l = 0;
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
89 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28113
diff changeset
90
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
91 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
92 int ll;
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
93 if(m->hide) continue;
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
94 ll = menu_text_length(m->txt);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
95 if(ptr_l + ll > need_w) need_w = ptr_l + ll;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
96 if(m == mpriv->current) sidx = i;
17946
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
97 count++;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
98 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
99 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
100 if(x >= 0)
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
101 x += mpriv->minb;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
102 if(y > 0)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
103 y += mpriv->minb;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28113
diff changeset
104 else
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
105 y = mpriv->minb;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
106
25437
2664bccccb80 Add local variable 'line_h' to simplify code of function menu_list_draw.
ulion
parents: 25435
diff changeset
107 need_h = count * line_h - mpriv->vspace;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
108 if( need_h + th > dh) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
109 int start,end;
25437
2664bccccb80 Add local variable 'line_h' to simplify code of function menu_list_draw.
ulion
parents: 25435
diff changeset
110 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
111 if(mpriv->disp_lines < 4) {
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
112 th = 0;
25437
2664bccccb80 Add local variable 'line_h' to simplify code of function menu_list_draw.
ulion
parents: 25435
diff changeset
113 mpriv->disp_lines = (dh + mpriv->vspace) / line_h;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
114 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
115 // Too smoll
24979
476d4922566a Make page up and down with proper page size instead of always 10 rows.
ulion
parents: 19431
diff changeset
116 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
117 need_h = mpriv->disp_lines * line_h - mpriv->vspace;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
118
24979
476d4922566a Make page up and down with proper page size instead of always 10 rows.
ulion
parents: 19431
diff changeset
119 start = sidx - (mpriv->disp_lines/2);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
120 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
121 end = start + mpriv->disp_lines;
17946
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
122 if(end > count) {
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
123 end = count;
24979
476d4922566a Make page up and down with proper page size instead of always 10 rows.
ulion
parents: 19431
diff changeset
124 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
125 start = end - mpriv->disp_lines < 0 ? 0 : end - mpriv->disp_lines;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
126 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
127 m = mpriv->menu;
17946
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
128 for(i = 0 ; m->next && i < start ; ) {
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
129 if(!m->hide) i++;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
130 m = m->next;
17946
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
131 }
24979
476d4922566a Make page up and down with proper page size instead of always 10 rows.
ulion
parents: 19431
diff changeset
132 } else {
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
133 m = mpriv->menu;
24979
476d4922566a Make page up and down with proper page size instead of always 10 rows.
ulion
parents: 19431
diff changeset
134 mpriv->disp_lines = count;
476d4922566a Make page up and down with proper page size instead of always 10 rows.
ulion
parents: 19431
diff changeset
135 }
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
136
17993
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17980
diff changeset
137 bg_w = need_w+2*mpriv->minb;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
138 if(th > 0) {
25435
5779358c3f86 Currently menu title did not align center together with menu items when x>=0.
ulion
parents: 25421
diff changeset
139 int tw,th2;
5779358c3f86 Currently menu title did not align center together with menu items when x>=0.
ulion
parents: 25421
diff changeset
140 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
141 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
142 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
143 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
144 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
145 }
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
146 menu_draw_text_full(mpi,mpriv->title,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
147 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
148 dy+y, x < 0 ? dw : (tw > need_w ? tw : need_w), 0,
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
149 mpriv->vspace,1,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
150 MENU_TEXT_TOP|MENU_TEXT_HCENTER,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
151 MENU_TEXT_TOP|(x < 0 ? MENU_TEXT_HCENTER :MENU_TEXT_LEFT));
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
152 dy += th;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
153 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28113
diff changeset
154
25438
11cd0fdfcb4a Add variable bx, dx to simplify code of function menu_draw_list.
ulion
parents: 25437
diff changeset
155 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
156 bx = x < 0 ? (mpi->w - bg_w) / 2 : x - mpriv->minb;
25461
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
157
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
158 // If mouse moved, try to update selected menu item by the mouse position.
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
159 if (menu_mouse_pos_updated) {
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
160 mouse_x = menu_mouse_x * mpi->width;
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
161 mouse_y = menu_mouse_y * mpi->height;
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
162 if (mouse_x >= bx && mouse_x < bx + bg_w) {
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
163 int by = dy + y - mpriv->vspace / 2;
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
164 int max_by = dh + y + mpriv->vspace / 2;
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
165 if (mouse_y >= by && mouse_y < max_by) {
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
166 int cur_no = (mouse_y - by) / line_h;
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
167 list_entry_t* e = m;
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
168 for (i = 0; e != NULL; e = e->next) {
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
169 if (e->hide) continue;
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
170 if (i == cur_no) {
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
171 mpriv->current = e;
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
172 break;
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
173 }
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
174 ++i;
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
175 }
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
176 }
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
177 }
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
178 menu_mouse_pos_updated = 0;
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
179 }
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
180
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
181 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
182 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
183 if(m == mpriv->current) {
25461
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
184 // Record rectangle of current selection box.
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
185 selection_x = bx;
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
186 selection_y = dy + y - mpriv->vspace / 2;
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
187 selection_w = bg_w;
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
188 selection_h = line_h;
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
189
17993
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17980
diff changeset
190 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
191 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
192 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
193 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
194 if(ptr_l > 0)
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17980
diff changeset
195 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
196 dx,
17993
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17980
diff changeset
197 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
198 mpriv->vspace,0,
25438
11cd0fdfcb4a Add variable bx, dx to simplify code of function menu_draw_list.
ulion
parents: 25437
diff changeset
199 MENU_TEXT_TOP|MENU_TEXT_LEFT,
11cd0fdfcb4a Add variable bx, dx to simplify code of function menu_draw_list.
ulion
parents: 25437
diff changeset
200 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
201 } 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
202 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
203 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
204 bg_w, line_h);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
205 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
206 dx + ptr_l,
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
207 dy+y,dw-ptr_l,dh - dy,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
208 mpriv->vspace,0,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
209 MENU_TEXT_TOP|MENU_TEXT_LEFT,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
210 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
211 dy += line_h;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
212 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
213
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
214 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
215
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
216 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
217 list_entry_t* m;
96d0992c7920 Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents: 24979
diff changeset
218 int i;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
219 switch(cmd) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
220 case MENU_CMD_UP:
17980
05b65e0b8d6f Fix cycling in menu with hidden items.
albeu
parents: 17946
diff changeset
221 while(mpriv->current->prev) {
05b65e0b8d6f Fix cycling in menu with hidden items.
albeu
parents: 17946
diff changeset
222 mpriv->current = mpriv->current->prev;
17946
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
223 if(!mpriv->current->hide) return;
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
224 }
17980
05b65e0b8d6f Fix cycling in menu with hidden items.
albeu
parents: 17946
diff changeset
225 for( ; mpriv->current->next != NULL ; mpriv->current = mpriv->current->next)
05b65e0b8d6f Fix cycling in menu with hidden items.
albeu
parents: 17946
diff changeset
226 /* NOTHING */;
05b65e0b8d6f Fix cycling in menu with hidden items.
albeu
parents: 17946
diff changeset
227 if(!mpriv->current->hide) return;
17946
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
228 while(mpriv->current->prev) {
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
229 mpriv->current = mpriv->current->prev;
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
230 if(!mpriv->current->hide) return;
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
231 }
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
232 break;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
233 case MENU_CMD_DOWN:
17980
05b65e0b8d6f Fix cycling in menu with hidden items.
albeu
parents: 17946
diff changeset
234 while(mpriv->current->next) {
05b65e0b8d6f Fix cycling in menu with hidden items.
albeu
parents: 17946
diff changeset
235 mpriv->current = mpriv->current->next;
17946
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
236 if(!mpriv->current->hide) return;
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
237 }
17980
05b65e0b8d6f Fix cycling in menu with hidden items.
albeu
parents: 17946
diff changeset
238 mpriv->current = mpriv->menu;
05b65e0b8d6f Fix cycling in menu with hidden items.
albeu
parents: 17946
diff changeset
239 if(!mpriv->current->hide) return;
17946
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
240 while(mpriv->current->next) {
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
241 mpriv->current = mpriv->current->next;
17946
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
242 if(!mpriv->current->hide) return;
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
243 }
0afe12256464 Allow hiding list elements and disableing the pointer.
albeu
parents: 17945
diff changeset
244 break;
25263
96d0992c7920 Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents: 24979
diff changeset
245 case MENU_CMD_HOME:
96d0992c7920 Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents: 24979
diff changeset
246 mpriv->current = mpriv->menu;
96d0992c7920 Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents: 24979
diff changeset
247 break;
96d0992c7920 Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents: 24979
diff changeset
248 case MENU_CMD_END:
96d0992c7920 Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents: 24979
diff changeset
249 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
250 /**/;
96d0992c7920 Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents: 24979
diff changeset
251 if(m)
96d0992c7920 Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents: 24979
diff changeset
252 mpriv->current = m;
96d0992c7920 Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents: 24979
diff changeset
253 break;
96d0992c7920 Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents: 24979
diff changeset
254 case MENU_CMD_PAGE_UP:
96d0992c7920 Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents: 24979
diff changeset
255 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
256 /**/;
96d0992c7920 Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents: 24979
diff changeset
257 if(m)
96d0992c7920 Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents: 24979
diff changeset
258 mpriv->current = m;
96d0992c7920 Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents: 24979
diff changeset
259 break;
96d0992c7920 Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents: 24979
diff changeset
260 case MENU_CMD_PAGE_DOWN:
96d0992c7920 Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents: 24979
diff changeset
261 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
262 /**/;
96d0992c7920 Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents: 24979
diff changeset
263 if(m)
96d0992c7920 Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents: 24979
diff changeset
264 mpriv->current = m;
96d0992c7920 Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents: 24979
diff changeset
265 break;
17945
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
266 case MENU_CMD_LEFT:
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
267 case MENU_CMD_CANCEL:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
268 menu->show = 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
269 menu->cl = 1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
270 break;
25461
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
271 case MENU_CMD_CLICK:
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
272 if (mouse_x >= selection_x && mouse_x < selection_x + selection_w &&
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
273 mouse_y >= selection_y && mouse_y < selection_y + selection_h)
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
274 menu_read_cmd(menu, MENU_CMD_OK);
7ef04742572c OSD menu support mouse selection.
ulion
parents: 25438
diff changeset
275 break;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28113
diff changeset
276 }
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
277 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
278
25263
96d0992c7920 Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents: 24979
diff changeset
279 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
280 if(c < 256 && isalnum(c)) {
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
281 list_entry_t* e = mpriv->current;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
282 if(e->txt[0] == c) e = e->next;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
283 for( ; e ; e = e->next) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
284 if(e->txt[0] == c) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
285 mpriv->current = e;
25263
96d0992c7920 Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents: 24979
diff changeset
286 return 1;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
287 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
288 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
289 for(e = mpriv->menu ; e ; e = e->next) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
290 if(e->txt[0] == c) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
291 mpriv->current = e;
25263
96d0992c7920 Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents: 24979
diff changeset
292 return 1;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
293 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
294 }
25263
96d0992c7920 Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents: 24979
diff changeset
295 return 1;
96d0992c7920 Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents: 24979
diff changeset
296 }
96d0992c7920 Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents: 24979
diff changeset
297 return 0;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
298 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
299
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
300 void menu_list_add_entry(menu_t* menu,list_entry_t* entry) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
301 list_entry_t* l;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
302 mpriv->count++;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
303
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
304 if(mpriv->menu == NULL) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
305 mpriv->menu = mpriv->current = entry;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
306 return;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
307 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
308
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
309 for(l = mpriv->menu ; l->next != NULL ; l = l->next)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
310 /* NOP */;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
311 l->next = entry;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
312 entry->prev = l;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
313 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28113
diff changeset
314
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
315 void menu_list_init(menu_t* menu) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
316 if(!mpriv)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
317 mpriv = calloc(1,sizeof(struct menu_priv_s));
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
318
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
319 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
320
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
321 void menu_list_uninit(menu_t* menu,free_entry_t free_func) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
322 list_entry_t *i,*j;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
323
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
324 if(!free_func) free_func = (free_entry_t)free;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
325
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
326 for(i = mpriv->menu ; i != NULL ; ) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
327 j = i->next;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
328 free_func(i);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
329 i = j;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
330 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28113
diff changeset
331
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
332 mpriv->menu = mpriv->current = NULL;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
333
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
334 }
17945
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
335