annotate libmenu/menu.c @ 25237:963cd0542cec

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