annotate libmenu/menu.c @ 23101:253a6da2be20

Add general variables for either static or shared FFmpeg libraries.
author diego
date Thu, 26 Apr 2007 11:22:22 +0000
parents 83366c8e1928
children a142b048c65e
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: 10626
diff changeset
2 #include "config.h"
17994
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 17993
diff changeset
3 #include "mp_msg.h"
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 17993
diff changeset
4 #include "help_mp.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
5
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
6 #include <stdlib.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
7 #include <stdio.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
8 #include <string.h>
8604
41a1e5dbb552 This patch fixes the reading of the menu.conf, because stream_open()
arpi
parents: 8251
diff changeset
9 #include <fcntl.h>
41a1e5dbb552 This patch fixes the reading of the menu.conf, because stream_open()
arpi
parents: 8251
diff changeset
10 #include <unistd.h>
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
11
16862
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 10626
diff changeset
12 #include "libvo/osd.h"
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 10626
diff changeset
13 #include "libvo/font_load.h"
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 10626
diff changeset
14 #include "osdep/keycodes.h"
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 10626
diff changeset
15 #include "asxparser.h"
19271
64d82a45a05d introduce new 'stream' directory for all stream layer related components and split them from libmpdemux
ben
parents: 18194
diff changeset
16 #include "stream/stream.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
17
19431
ac69ba536915 Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents: 19271
diff changeset
18 #include "libmpcodecs/img_format.h"
ac69ba536915 Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents: 19271
diff changeset
19 #include "libmpcodecs/mp_image.h"
16862
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 10626
diff changeset
20 #include "m_option.h"
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 10626
diff changeset
21 #include "m_struct.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
22 #include "menu.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
23
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
24 extern menu_info_t menu_info_cmdlist;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
25 extern menu_info_t menu_info_pt;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
26 extern menu_info_t menu_info_filesel;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
27 extern menu_info_t menu_info_txt;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
28 extern menu_info_t menu_info_console;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
29 extern menu_info_t menu_info_pref;
10626
fd97f3727f15 Finnaly commit Nico's dvb menu. Sorry for committing this
albeu
parents: 10397
diff changeset
30 #ifdef HAS_DVBIN_SUPPORT
fd97f3727f15 Finnaly commit Nico's dvb menu. Sorry for committing this
albeu
parents: 10397
diff changeset
31 extern menu_info_t menu_info_dvbsel;
fd97f3727f15 Finnaly commit Nico's dvb menu. Sorry for committing this
albeu
parents: 10397
diff changeset
32 #endif
fd97f3727f15 Finnaly commit Nico's dvb menu. Sorry for committing this
albeu
parents: 10397
diff changeset
33
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
34
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
35 menu_info_t* menu_info_list[] = {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
36 &menu_info_pt,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
37 &menu_info_cmdlist,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
38 &menu_info_filesel,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
39 &menu_info_txt,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
40 &menu_info_console,
10626
fd97f3727f15 Finnaly commit Nico's dvb menu. Sorry for committing this
albeu
parents: 10397
diff changeset
41 #ifdef HAS_DVBIN_SUPPORT
fd97f3727f15 Finnaly commit Nico's dvb menu. Sorry for committing this
albeu
parents: 10397
diff changeset
42 &menu_info_dvbsel,
fd97f3727f15 Finnaly commit Nico's dvb menu. Sorry for committing this
albeu
parents: 10397
diff changeset
43 #endif
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
44 &menu_info_pref,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
45 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 typedef struct menu_def_st {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
49 char* name;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
50 menu_info_t* type;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
51 void* cfg;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
52 char* args;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
53 } menu_def_t;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
54
22284
83366c8e1928 Fix menu to work with mpctx
uau
parents: 21797
diff changeset
55 static struct MPContext *menu_ctx = NULL;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
56 static menu_def_t* menu_list = NULL;
21797
14061bc22cb3 fix gprof support (aka work around gprof's brain dead design)
gpoirier
parents: 20507
diff changeset
57 static int menu_count = 0;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
58
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
59
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
60 static int menu_parse_config(char* buffer) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
61 char *element,*body, **attribs, *name;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
62 menu_info_t* minfo = NULL;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
63 int r,i;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
64 ASX_Parser_t* parser = asx_parser_new();
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
65
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
66 while(1) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
67 r = asx_get_element(parser,&buffer,&element,&body,&attribs);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
68 if(r < 0) {
17994
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 17993
diff changeset
69 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_SyntaxErrorAtLine,parser->line);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
70 asx_parser_free(parser);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
71 return 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
72 } else if(r == 0) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
73 asx_parser_free(parser);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
74 return 1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
75 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
76 // Has it a name ?
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
77 name = asx_get_attrib("name",attribs);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
78 if(!name) {
17994
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 17993
diff changeset
79 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_MenuDefinitionsNeedANameAttrib,parser->line);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
80 free(element);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
81 if(body) free(body);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
82 asx_free_attribs(attribs);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
83 continue;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
84 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
85
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
86 // Try to find this menu type in our list
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
87 for(i = 0, minfo = NULL ; menu_info_list[i] ; i++) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
88 if(strcasecmp(element,menu_info_list[i]->name) == 0) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
89 minfo = menu_info_list[i];
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
90 break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
91 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
92 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
93 // Got it : add this to our list
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
94 if(minfo) {
21797
14061bc22cb3 fix gprof support (aka work around gprof's brain dead design)
gpoirier
parents: 20507
diff changeset
95 menu_list = realloc(menu_list,(menu_count+2)*sizeof(menu_def_t));
14061bc22cb3 fix gprof support (aka work around gprof's brain dead design)
gpoirier
parents: 20507
diff changeset
96 menu_list[menu_count].name = name;
14061bc22cb3 fix gprof support (aka work around gprof's brain dead design)
gpoirier
parents: 20507
diff changeset
97 menu_list[menu_count].type = minfo;
14061bc22cb3 fix gprof support (aka work around gprof's brain dead design)
gpoirier
parents: 20507
diff changeset
98 menu_list[menu_count].cfg = m_struct_alloc(&minfo->priv_st);
14061bc22cb3 fix gprof support (aka work around gprof's brain dead design)
gpoirier
parents: 20507
diff changeset
99 menu_list[menu_count].args = body;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
100 // Setup the attribs
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
101 for(i = 0 ; attribs[2*i] ; i++) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
102 if(strcasecmp(attribs[2*i],"name") == 0) continue;
21797
14061bc22cb3 fix gprof support (aka work around gprof's brain dead design)
gpoirier
parents: 20507
diff changeset
103 if(!m_struct_set(&minfo->priv_st,menu_list[menu_count].cfg,attribs[2*i], attribs[2*i+1]))
17994
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 17993
diff changeset
104 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_BadAttrib,attribs[2*i],attribs[2*i+1],
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
105 name,parser->line);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
106 }
21797
14061bc22cb3 fix gprof support (aka work around gprof's brain dead design)
gpoirier
parents: 20507
diff changeset
107 menu_count++;
14061bc22cb3 fix gprof support (aka work around gprof's brain dead design)
gpoirier
parents: 20507
diff changeset
108 memset(&menu_list[menu_count],0,sizeof(menu_def_t));
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
109 } else {
17994
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 17993
diff changeset
110 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_UnknownMenuType,element,parser->line);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
111 free(name);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
112 if(body) free(body);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
113 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
114
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
115 free(element);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
116 asx_free_attribs(attribs);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
117 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
118
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
119 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
120
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
121
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
122 /// This will build the menu_defs list from the cfg file
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
123 #define BUF_STEP 1024
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
124 #define BUF_MIN 128
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
125 #define BUF_MAX BUF_STEP*1024
22284
83366c8e1928 Fix menu to work with mpctx
uau
parents: 21797
diff changeset
126 int menu_init(struct MPContext *mpctx, char* cfg_file) {
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
127 char* buffer = NULL;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
128 int bl = BUF_STEP, br = 0;
9103
6c2c74adaebe mplayer crashes if one tries to use osd menu without having a font
arpi
parents: 8604
diff changeset
129 int f, fd;
9212
24b102dbd0fe Fixes a problem where the menu won't work, if you just use freetype fonts
arpi
parents: 9103
diff changeset
130 #ifndef HAVE_FREETYPE
9103
6c2c74adaebe mplayer crashes if one tries to use osd menu without having a font
arpi
parents: 8604
diff changeset
131 if(vo_font == NULL)
6c2c74adaebe mplayer crashes if one tries to use osd menu without having a font
arpi
parents: 8604
diff changeset
132 return 0;
9212
24b102dbd0fe Fixes a problem where the menu won't work, if you just use freetype fonts
arpi
parents: 9103
diff changeset
133 #endif
9103
6c2c74adaebe mplayer crashes if one tries to use osd menu without having a font
arpi
parents: 8604
diff changeset
134 fd = open(cfg_file, O_RDONLY);
8604
41a1e5dbb552 This patch fixes the reading of the menu.conf, because stream_open()
arpi
parents: 8251
diff changeset
135 if(fd < 0) {
17994
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 17993
diff changeset
136 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_CantOpenConfigFile,cfg_file);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
137 return 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
138 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
139 buffer = malloc(bl);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
140 while(1) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
141 int r;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
142 if(bl - br < BUF_MIN) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
143 if(bl >= BUF_MAX) {
17994
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 17993
diff changeset
144 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_ConfigFileIsTooBig,BUF_MAX/1024);
8604
41a1e5dbb552 This patch fixes the reading of the menu.conf, because stream_open()
arpi
parents: 8251
diff changeset
145 close(fd);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
146 free(buffer);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
147 return 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
148 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
149 bl += BUF_STEP;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
150 buffer = realloc(buffer,bl);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
151 }
8604
41a1e5dbb552 This patch fixes the reading of the menu.conf, because stream_open()
arpi
parents: 8251
diff changeset
152 r = read(fd,buffer+br,bl-br);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
153 if(r == 0) break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
154 br += r;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
155 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
156 if(!br) {
17994
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 17993
diff changeset
157 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_ConfigFileIsEmpty);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
158 return 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
159 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
160 buffer[br-1] = '\0';
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
161
8604
41a1e5dbb552 This patch fixes the reading of the menu.conf, because stream_open()
arpi
parents: 8251
diff changeset
162 close(fd);
41a1e5dbb552 This patch fixes the reading of the menu.conf, because stream_open()
arpi
parents: 8251
diff changeset
163
22284
83366c8e1928 Fix menu to work with mpctx
uau
parents: 21797
diff changeset
164 menu_ctx = mpctx;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
165 f = menu_parse_config(buffer);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
166 free(buffer);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
167 return f;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
168 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
169
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
170 // Destroy all this stuff
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
171 void menu_unint(void) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
172 int i;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
173 for(i = 0 ; menu_list && menu_list[i].name ; i++) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
174 free(menu_list[i].name);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
175 m_struct_free(&menu_list[i].type->priv_st,menu_list[i].cfg);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
176 if(menu_list[i].args) free(menu_list[i].args);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
177 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
178 free(menu_list);
21797
14061bc22cb3 fix gprof support (aka work around gprof's brain dead design)
gpoirier
parents: 20507
diff changeset
179 menu_count = 0;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
180 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
181
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
182 /// Default read_key function
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
183 void menu_dflt_read_key(menu_t* menu,int cmd) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
184 switch(cmd) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
185 case KEY_UP:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
186 menu->read_cmd(menu,MENU_CMD_UP);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
187 break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
188 case KEY_DOWN:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
189 menu->read_cmd(menu,MENU_CMD_DOWN);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
190 break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
191 case KEY_LEFT:
17945
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
192 menu->read_cmd(menu,MENU_CMD_LEFT);
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
193 break;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
194 case KEY_ESC:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
195 menu->read_cmd(menu,MENU_CMD_CANCEL);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
196 break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
197 case KEY_RIGHT:
17945
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
198 menu->read_cmd(menu,MENU_CMD_RIGHT);
98f4e3704a76 Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents: 16862
diff changeset
199 break;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
200 case KEY_ENTER:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
201 menu->read_cmd(menu,MENU_CMD_OK);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
202 break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
203 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
204 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
205
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
206 menu_t* menu_open(char *name) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
207 menu_t* m;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
208 int i;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
209
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
210 for(i = 0 ; menu_list[i].name != NULL ; i++) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
211 if(strcmp(name,menu_list[i].name) == 0)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
212 break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
213 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
214 if(menu_list[i].name == NULL) {
17994
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 17993
diff changeset
215 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_MenuNotFound,name);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
216 return NULL;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
217 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
218 m = calloc(1,sizeof(menu_t));
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
219 m->priv_st = &(menu_list[i].type->priv_st);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
220 m->priv = m_struct_copy(m->priv_st,menu_list[i].cfg);
22284
83366c8e1928 Fix menu to work with mpctx
uau
parents: 21797
diff changeset
221 m->ctx = menu_ctx;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
222 if(menu_list[i].type->open(m,menu_list[i].args))
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
223 return m;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
224 if(m->priv)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
225 m_struct_free(m->priv_st,m->priv);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
226 free(m);
17994
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 17993
diff changeset
227 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_MenuInitFailed,name);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
228 return NULL;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
229 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
230
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
231 void menu_draw(menu_t* menu,mp_image_t* mpi) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
232 if(menu->show && menu->draw)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
233 menu->draw(menu,mpi);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
234 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
235
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
236 void menu_read_cmd(menu_t* menu,int cmd) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
237 if(menu->read_cmd)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
238 menu->read_cmd(menu,cmd);
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_close(menu_t* menu) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
242 if(menu->close)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
243 menu->close(menu);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
244 if(menu->priv)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
245 m_struct_free(menu->priv_st,menu->priv);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
246 free(menu);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
247 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
248
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
249 void menu_read_key(menu_t* menu,int cmd) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
250 if(menu->read_key)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
251 menu->read_key(menu,cmd);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
252 else
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
253 menu_dflt_read_key(menu,cmd);
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 ///////////////////////////// Helpers ////////////////////////////////////
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
257
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
258 typedef void (*draw_alpha_f)(int w,int h, unsigned char* src, unsigned char *srca, int srcstride, unsigned char* dstbase,int dststride);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
259
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
260 inline static draw_alpha_f get_draw_alpha(uint32_t fmt) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
261 switch(fmt) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
262 case IMGFMT_BGR15:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
263 case IMGFMT_RGB15:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
264 return vo_draw_alpha_rgb15;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
265 case IMGFMT_BGR16:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
266 case IMGFMT_RGB16:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
267 return vo_draw_alpha_rgb16;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
268 case IMGFMT_BGR24:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
269 case IMGFMT_RGB24:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
270 return vo_draw_alpha_rgb24;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
271 case IMGFMT_BGR32:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
272 case IMGFMT_RGB32:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
273 return vo_draw_alpha_rgb32;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
274 case IMGFMT_YV12:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
275 case IMGFMT_I420:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
276 case IMGFMT_IYUV:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
277 case IMGFMT_YVU9:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
278 case IMGFMT_IF09:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
279 case IMGFMT_Y800:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
280 case IMGFMT_Y8:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
281 return vo_draw_alpha_yv12;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
282 case IMGFMT_YUY2:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
283 return vo_draw_alpha_yuy2;
18194
fe877135c408 There is a draw_alpha for uyvy, use it.
albeu
parents: 18193
diff changeset
284 case IMGFMT_UYVY:
fe877135c408 There is a draw_alpha for uyvy, use it.
albeu
parents: 18193
diff changeset
285 return vo_draw_alpha_uyvy;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
286 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
287
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
288 return NULL;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
289 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
290
8224
fefc56153615 Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents: 8197
diff changeset
291 // return the real height of a char:
fefc56153615 Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents: 8197
diff changeset
292 static inline int get_height(int c,int h){
fefc56153615 Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents: 8197
diff changeset
293 int font;
fefc56153615 Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents: 8197
diff changeset
294 if ((font=vo_font->font[c])>=0)
fefc56153615 Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents: 8197
diff changeset
295 if(h<vo_font->pic_a[font]->h) h=vo_font->pic_a[font]->h;
fefc56153615 Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents: 8197
diff changeset
296 return h;
fefc56153615 Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents: 8197
diff changeset
297 }
fefc56153615 Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents: 8197
diff changeset
298
fefc56153615 Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents: 8197
diff changeset
299 #ifdef HAVE_FREETYPE
20507
d03b71ab8b65 Fix possible crash: negative values may no be passed to render_one_glyph
reimar
parents: 19431
diff changeset
300 #define render_txt(t) { unsigned char* p = t; while(*p) render_one_glyph(vo_font,*p++); }
8224
fefc56153615 Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents: 8197
diff changeset
301 #else
fefc56153615 Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents: 8197
diff changeset
302 #define render_txt(t)
fefc56153615 Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents: 8197
diff changeset
303 #endif
fefc56153615 Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents: 8197
diff changeset
304
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
305
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
306 void menu_draw_text(mp_image_t* mpi,char* txt, int x, int y) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
307 draw_alpha_f draw_alpha = get_draw_alpha(mpi->imgfmt);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
308 int font;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
309
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
310 if(!draw_alpha) {
17994
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 17993
diff changeset
311 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_UnsupportedOutformat);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
312 return;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
313 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
314
8224
fefc56153615 Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents: 8197
diff changeset
315 render_txt(txt);
fefc56153615 Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents: 8197
diff changeset
316
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
317 while (*txt) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
318 unsigned char c=*txt++;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
319 if ((font=vo_font->font[c])>=0 && (x + vo_font->width[c] <= mpi->w) && (y + vo_font->pic_a[font]->h <= mpi->h))
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
320 draw_alpha(vo_font->width[c], vo_font->pic_a[font]->h,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
321 vo_font->pic_b[font]->bmp+vo_font->start[c],
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
322 vo_font->pic_a[font]->bmp+vo_font->start[c],
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
323 vo_font->pic_a[font]->w,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
324 mpi->planes[0] + y * mpi->stride[0] + x * (mpi->bpp>>3),
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
325 mpi->stride[0]);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
326 x+=vo_font->width[c]+vo_font->charspace;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
327 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
328
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
329 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
330
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
331 void menu_draw_text_full(mp_image_t* mpi,char* txt,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
332 int x, int y,int w, int h,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
333 int vspace, int warp, int align, int anchor) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
334 int need_w,need_h;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
335 int sy, ymin, ymax;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
336 int sx, xmin, xmax, xmid, xrmin;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
337 int ll = 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
338 int font;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
339 draw_alpha_f draw_alpha = get_draw_alpha(mpi->imgfmt);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
340
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
341 if(!draw_alpha) {
17994
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 17993
diff changeset
342 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_UnsupportedOutformat);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
343 return;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
344 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
345
8224
fefc56153615 Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents: 8197
diff changeset
346 render_txt(txt);
fefc56153615 Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents: 8197
diff changeset
347
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
348 if(x > mpi->w || y > mpi->h)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
349 return;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
350
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
351 if(anchor & MENU_TEXT_VCENTER) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
352 if(h <= 0) h = mpi->h;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
353 ymin = y - h/2;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
354 ymax = y + h/2;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
355 } else if(anchor & MENU_TEXT_BOT) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
356 if(h <= 0) h = mpi->h - y;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
357 ymin = y - h;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
358 ymax = y;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
359 } else {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
360 if(h <= 0) h = mpi->h - y;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
361 ymin = y;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
362 ymax = y + h;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
363 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
364
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
365 if(anchor & MENU_TEXT_HCENTER) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
366 if(w <= 0) w = mpi->w;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
367 xmin = x - w/2;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
368 xmax = x + w/2;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
369 } else if(anchor & MENU_TEXT_RIGHT) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
370 if(w <= 0) w = mpi->w -x;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
371 xmin = x - w;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
372 xmax = x;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
373 } else {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
374 if(w <= 0) w = mpi->w -x;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
375 xmin = x;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
376 xmax = x + w;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
377 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
378
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
379 // How many space do we need to draw this ?
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
380 menu_text_size(txt,w,vspace,warp,&need_w,&need_h);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
381
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
382 // Find the first line
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
383 if(align & MENU_TEXT_VCENTER)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
384 sy = ymin + ((h - need_h)/2);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
385 else if(align & MENU_TEXT_BOT)
8232
5bbbccba0ad5 Fix buffer overflow in a drawing func
albeu
parents: 8224
diff changeset
386 sy = ymax - need_h - 1;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
387 else
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
388 sy = y;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
389
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
390 #if 0
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
391 // Find the first col
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
392 if(align & MENU_TEXT_HCENTER)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
393 sx = xmin + ((w - need_w)/2);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
394 else if(align & MENU_TEXT_RIGHT)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
395 sx = xmax - need_w;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
396 #endif
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
397
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
398 xmid = xmin + (xmax - xmin) / 2;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
399 xrmin = xmin;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
400 // Clamp the bb to the mpi size
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
401 if(ymin < 0) ymin = 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
402 if(xmin < 0) xmin = 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
403 if(ymax > mpi->h) ymax = mpi->h;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
404 if(xmax > mpi->w) xmax = mpi->w;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
405
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
406 // Jump some the beginnig text if needed
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
407 while(sy < ymin && *txt) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
408 unsigned char c=*txt++;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
409 if(c == '\n' || (warp && ll + vo_font->width[c] > w)) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
410 ll = 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
411 sy += vo_font->height + vspace;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
412 if(c == '\n') continue;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
413 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
414 ll += vo_font->width[c]+vo_font->charspace;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
415 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
416 if(*txt == '\0') // Nothing left to draw
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
417 return;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
418
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
419 while(sy < ymax && *txt) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
420 char* line_end = NULL;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
421 int n;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
422
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
423 if(txt[0] == '\n') { // New line
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
424 sy += vo_font->height + vspace;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
425 txt++;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
426 continue;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
427 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
428
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
429 // Get the length and end of this line
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
430 for(n = 0, ll = 0 ; txt[n] != '\0' && txt[n] != '\n' ; n++) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
431 unsigned char c = txt[n];
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
432 if(warp && ll + vo_font->width[c] > w) break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
433 ll += vo_font->width[c]+vo_font->charspace;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
434 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
435 line_end = &txt[n];
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
436 ll -= vo_font->charspace;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
437
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
438
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
439 if(align & (MENU_TEXT_HCENTER|MENU_TEXT_RIGHT)) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
440 // Too long line
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
441 if(ll > xmax-xmin) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
442 if(align & MENU_TEXT_HCENTER) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
443 int mid = ll/2;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
444 // Find the middle point
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
445 for(n--, ll = 0 ; n <= 0 ; n--) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
446 ll += vo_font->width[(int)txt[n]]+vo_font->charspace;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
447 if(ll - vo_font->charspace > mid) break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
448 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
449 ll -= vo_font->charspace;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
450 sx = xmid + mid - ll;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
451 } else// MENU_TEXT_RIGHT)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
452 sx = xmax + vo_font->charspace;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
453
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
454 // We are after the start point -> go back
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
455 if(sx > xmin) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
456 for(n-- ; n <= 0 ; n--) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
457 unsigned char c = txt[n];
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
458 if(sx - vo_font->width[c] - vo_font->charspace < xmin) break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
459 sx -= vo_font->width[c]+vo_font->charspace;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
460 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
461 } else { // We are before the start point -> go forward
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
462 for( ; sx < xmin && (&txt[n]) != line_end ; n++) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
463 unsigned char c = txt[n];
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
464 sx += vo_font->width[c]+vo_font->charspace;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
465 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
466 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
467 txt = &txt[n]; // Jump to the new start char
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
468 } else {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
469 if(align & MENU_TEXT_HCENTER)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
470 sx = xmid - ll/2;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
471 else
8232
5bbbccba0ad5 Fix buffer overflow in a drawing func
albeu
parents: 8224
diff changeset
472 sx = xmax - 1 - ll;
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
473 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
474 } else {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
475 for(sx = xrmin ; sx < xmin && txt != line_end ; txt++) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
476 unsigned char c = txt[n];
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
477 sx += vo_font->width[c]+vo_font->charspace;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
478 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
479 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
480
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
481 while(sx < xmax && txt != line_end) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
482 unsigned char c = *txt++;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
483 font = vo_font->font[c];
8232
5bbbccba0ad5 Fix buffer overflow in a drawing func
albeu
parents: 8224
diff changeset
484 if(font >= 0) {
5bbbccba0ad5 Fix buffer overflow in a drawing func
albeu
parents: 8224
diff changeset
485 int cs = (vo_font->pic_a[font]->h - vo_font->height) / 2;
5bbbccba0ad5 Fix buffer overflow in a drawing func
albeu
parents: 8224
diff changeset
486 if ((sx + vo_font->width[c] < xmax) && (sy + vo_font->height < ymax) )
5bbbccba0ad5 Fix buffer overflow in a drawing func
albeu
parents: 8224
diff changeset
487 draw_alpha(vo_font->width[c], vo_font->height,
5bbbccba0ad5 Fix buffer overflow in a drawing func
albeu
parents: 8224
diff changeset
488 vo_font->pic_b[font]->bmp+vo_font->start[c] +
5bbbccba0ad5 Fix buffer overflow in a drawing func
albeu
parents: 8224
diff changeset
489 cs * vo_font->pic_a[font]->w,
5bbbccba0ad5 Fix buffer overflow in a drawing func
albeu
parents: 8224
diff changeset
490 vo_font->pic_a[font]->bmp+vo_font->start[c] +
5bbbccba0ad5 Fix buffer overflow in a drawing func
albeu
parents: 8224
diff changeset
491 cs * vo_font->pic_a[font]->w,
5bbbccba0ad5 Fix buffer overflow in a drawing func
albeu
parents: 8224
diff changeset
492 vo_font->pic_a[font]->w,
5bbbccba0ad5 Fix buffer overflow in a drawing func
albeu
parents: 8224
diff changeset
493 mpi->planes[0] + sy * mpi->stride[0] + sx * (mpi->bpp>>3),
5bbbccba0ad5 Fix buffer overflow in a drawing func
albeu
parents: 8224
diff changeset
494 mpi->stride[0]);
5bbbccba0ad5 Fix buffer overflow in a drawing func
albeu
parents: 8224
diff changeset
495 // else
5bbbccba0ad5 Fix buffer overflow in a drawing func
albeu
parents: 8224
diff changeset
496 //printf("Can't draw '%c'\n",c);
5bbbccba0ad5 Fix buffer overflow in a drawing func
albeu
parents: 8224
diff changeset
497 }
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
498 sx+=vo_font->width[c]+vo_font->charspace;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
499 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
500 txt = line_end;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
501 if(txt[0] == '\0') break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
502 sy += vo_font->height + vspace;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
503 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
504 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
505
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
506 int menu_text_length(char* txt) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
507 int l = 0;
8224
fefc56153615 Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents: 8197
diff changeset
508 render_txt(txt);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
509 while (*txt) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
510 unsigned char c=*txt++;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
511 l += vo_font->width[c]+vo_font->charspace;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
512 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
513 return l - vo_font->charspace;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
514 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
515
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
516 void menu_text_size(char* txt,int max_width, int vspace, int warp, int* _w, int* _h) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
517 int l = 1, i = 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
518 int w = 0;
8224
fefc56153615 Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents: 8197
diff changeset
519
fefc56153615 Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents: 8197
diff changeset
520 render_txt(txt);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
521 while (*txt) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
522 unsigned char c=*txt++;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
523 if(c == '\n' || (warp && i + vo_font->width[c] >= max_width)) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
524 if(*txt)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
525 l++;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
526 i = 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
527 if(c == '\n') continue;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
528 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
529 i += vo_font->width[c]+vo_font->charspace;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
530 if(i > w) w = i;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
531 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
532
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
533 *_w = w;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
534 *_h = (l-1) * (vo_font->height + vspace) + vo_font->height;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
535 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
536
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
537
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
538 int menu_text_num_lines(char* txt, int max_width) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
539 int l = 1, i = 0;
8224
fefc56153615 Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents: 8197
diff changeset
540 render_txt(txt);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
541 while (*txt) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
542 unsigned char c=*txt++;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
543 if(c == '\n' || i + vo_font->width[c] > max_width) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
544 l++;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
545 i = 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
546 if(c == '\n') continue;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
547 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
548 i += vo_font->width[c]+vo_font->charspace;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
549 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
550 return l;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
551 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
552
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
553 char* menu_text_get_next_line(char* txt, int max_width) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
554 int i = 0;
8224
fefc56153615 Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents: 8197
diff changeset
555 render_txt(txt);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
556 while (*txt) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
557 unsigned char c=*txt;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
558 if(c == '\n') {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
559 txt++;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
560 break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
561 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
562 i += vo_font->width[c];
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
563 if(i >= max_width)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
564 break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
565 i += vo_font->charspace;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
566 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
567 return txt;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
568 }
17993
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17945
diff changeset
569
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17945
diff changeset
570
18193
e8cbaf092e96 Fix menu background drawing.
albeu
parents: 17994
diff changeset
571 void menu_draw_box(mp_image_t* mpi,unsigned char grey,unsigned char alpha, int x, int y, int w, int h) {
17993
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17945
diff changeset
572 draw_alpha_f draw_alpha = get_draw_alpha(mpi->imgfmt);
18193
e8cbaf092e96 Fix menu background drawing.
albeu
parents: 17994
diff changeset
573 int g;
17993
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17945
diff changeset
574
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17945
diff changeset
575 if(!draw_alpha) {
18193
e8cbaf092e96 Fix menu background drawing.
albeu
parents: 17994
diff changeset
576 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_UnsupportedOutformat);
17993
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17945
diff changeset
577 return;
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17945
diff changeset
578 }
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17945
diff changeset
579
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17945
diff changeset
580 if(x > mpi->w || y > mpi->h) return;
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17945
diff changeset
581
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17945
diff changeset
582 if(x < 0) w += x, x = 0;
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17945
diff changeset
583 if(x+w > mpi->w) w = mpi->w-x;
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17945
diff changeset
584 if(y < 0) h += y, y = 0;
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17945
diff changeset
585 if(y+h > mpi->h) h = mpi->h-y;
18193
e8cbaf092e96 Fix menu background drawing.
albeu
parents: 17994
diff changeset
586
e8cbaf092e96 Fix menu background drawing.
albeu
parents: 17994
diff changeset
587 g = ((256-alpha)*grey)>>8;
e8cbaf092e96 Fix menu background drawing.
albeu
parents: 17994
diff changeset
588 if(g < 1) g = 1;
e8cbaf092e96 Fix menu background drawing.
albeu
parents: 17994
diff changeset
589
17993
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17945
diff changeset
590 {
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17945
diff changeset
591 int stride = (w+7)&(~7); // round to 8
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17945
diff changeset
592 char pic[stride*h],pic_alpha[stride*h];
18193
e8cbaf092e96 Fix menu background drawing.
albeu
parents: 17994
diff changeset
593 memset(pic,g,stride*h);
17993
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17945
diff changeset
594 memset(pic_alpha,alpha,stride*h);
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17945
diff changeset
595 draw_alpha(w,h,pic,pic_alpha,stride,
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17945
diff changeset
596 mpi->planes[0] + y * mpi->stride[0] + x * (mpi->bpp>>3),
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17945
diff changeset
597 mpi->stride[0]);
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17945
diff changeset
598 }
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17945
diff changeset
599
98eb966a4024 Add a function to draw flat boxes and use it to make the list
albeu
parents: 17945
diff changeset
600 }