annotate libmenu/menu_cmdlist.c @ 17945:98f4e3704a76

Allow 6 ways (up/down/left/right/ok/cancel) navigation.
author albeu
date Sat, 25 Mar 2006 17:32:10 +0000
parents 931bdbc37ee0
children 6927fabaef92
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
1
16862
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 8623
diff changeset
2 #include "config.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
3
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
4 #include <stdlib.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
5 #include <stdio.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
6 #include <ctype.h>
8623
440301fef3fe Added/reordered #includes to silence warnings about "implicit declaration".
rathann
parents: 8197
diff changeset
7 #include <string.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
16862
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 8623
diff changeset
12 #include "m_option.h"
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 8623
diff changeset
13 #include "m_struct.h"
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 8623
diff changeset
14 #include "asxparser.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
15 #include "menu.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
16 #include "menu_list.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
17
16862
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 8623
diff changeset
18 #include "libvo/font_load.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
19
16862
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 8623
diff changeset
20 #include "input/input.h"
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 8623
diff changeset
21 #include "version.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
22
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
23
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
24
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
25 struct list_entry_s {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
26 struct list_entry p;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
27
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
28 char* ok;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
29 char* cancel;
17945
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
30 char* left;
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
31 char* right;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
32 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
33
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
34 struct menu_priv_s {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
35 menu_list_priv_t p;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
36 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
37
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
38 static struct menu_priv_s cfg_dflt = {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
39 MENU_LIST_PRIV_DFLT
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
40 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
41
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
42 static m_option_t cfg_fields[] = {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
43 MENU_LIST_PRIV_FIELDS,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
44 { "title",M_ST_OFF(struct menu_priv_s,p.title), CONF_TYPE_STRING, 0, 0, 0, NULL },
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
45 { NULL, NULL, NULL, 0,0,0,NULL }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
46 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
47
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 static void read_cmd(menu_t* menu,int cmd) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
51 switch(cmd) {
17945
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
52 case MENU_CMD_RIGHT:
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
53 if(mpriv->p.current->right) {
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
54 mp_cmd_t* c = mp_input_parse_cmd(mpriv->p.current->right);
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
55 if(c) mp_input_queue_cmd(c);
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
56 break;
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
57 } // fallback on ok if right is not defined
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
58 case MENU_CMD_OK: {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
59 if(mpriv->p.current->ok) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
60 mp_cmd_t* c = mp_input_parse_cmd(mpriv->p.current->ok);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
61 if(c)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
62 mp_input_queue_cmd(c);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
63 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
64 } break;
17945
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
65 case MENU_CMD_LEFT:
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
66 if(mpriv->p.current->left) {
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
67 mp_cmd_t* c = mp_input_parse_cmd(mpriv->p.current->left);
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
68 if(c) mp_input_queue_cmd(c);
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
69 break;
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
70 } // fallback on cancel if left is not defined
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
71 case MENU_CMD_CANCEL:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
72 if(mpriv->p.current->cancel) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
73 mp_cmd_t* c = mp_input_parse_cmd(mpriv->p.current->cancel);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
74 if(c)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
75 mp_input_queue_cmd(c);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
76 break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
77 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
78 default:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
79 menu_list_read_cmd(menu,cmd);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
80 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
81 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
82
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
83 static void read_key(menu_t* menu,int c){
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
84 menu_list_read_key(menu,c,0);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
85 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
86
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
87 static void free_entry(list_entry_t* entry) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
88 if(entry->ok)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
89 free(entry->ok);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
90 if(entry->cancel)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
91 free(entry->cancel);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
92 free(entry->p.txt);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
93 free(entry);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
94 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
95
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
96 static void close(menu_t* menu) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
97 menu_list_uninit(menu,free_entry);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
98 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
99
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
100 static int parse_args(menu_t* menu,char* args) {
17945
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
101 char *element,*body, **attribs, *name;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
102 list_entry_t* m = NULL;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
103 int r;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
104 ASX_Parser_t* parser = asx_parser_new();
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
105
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
106 while(1) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
107 r = asx_get_element(parser,&args,&element,&body,&attribs);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
108 if(r < 0) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
109 printf("Syntax error at line %d\n",parser->line);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
110 asx_parser_free(parser);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
111 return -1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
112 } else if(r == 0) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
113 asx_parser_free(parser);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
114 if(!m)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
115 printf("No entry found in the menu definition\n");
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
116 return m ? 1 : 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
117 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
118 // Has it a name ?
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
119 name = asx_get_attrib("name",attribs);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
120 if(!name) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
121 printf("List menu entry definitions need a name (line %d)\n",parser->line);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
122 free(element);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
123 if(body) free(body);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
124 asx_free_attribs(attribs);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
125 continue;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
126 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
127 m = calloc(1,sizeof(struct list_entry_s));
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
128 m->p.txt = name;
17945
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
129 m->ok = asx_get_attrib("ok",attribs);
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
130 m->cancel = asx_get_attrib("cancel",attribs);
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
131 m->left = asx_get_attrib("left",attribs);
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
132 m->right = asx_get_attrib("right",attribs);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
133 menu_list_add_entry(menu,m);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
134
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
135 free(element);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
136 if(body) free(body);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
137 asx_free_attribs(attribs);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
138 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
139 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
140
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
141 static int open(menu_t* menu, char* args) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
142 menu->draw = menu_list_draw;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
143 menu->read_cmd = read_cmd;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
144 menu->read_key = read_key;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
145 menu->close = close;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
146
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
147 if(!args) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
148 printf("List menu need an argument\n");
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
149 return 0;
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 menu_list_init(menu);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
153 if(!parse_args(menu,args))
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
154 return 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
155 return 1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
156 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
157
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
158 const menu_info_t menu_info_cmdlist = {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
159 "Command list menu",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
160 "cmdlist",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
161 "Albeu",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
162 "",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
163 {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
164 "cmdlist_cfg",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
165 sizeof(struct menu_priv_s),
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
166 &cfg_dflt,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
167 cfg_fields
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
168 },
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
169 open
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
170 };