Mercurial > mplayer.hg
comparison libmenu/menu_console.c @ 8197:b31caec933e9
OSD menus initial version
author | albeu |
---|---|
date | Thu, 14 Nov 2002 23:47:11 +0000 |
parents | |
children | 3050cfda3c61 |
comparison
equal
deleted
inserted
replaced
8196:419bdbfdb660 | 8197:b31caec933e9 |
---|---|
1 | |
2 #include "../config.h" | |
3 | |
4 #include <stdlib.h> | |
5 #include <stdio.h> | |
6 #include <string.h> | |
7 #include <ctype.h> | |
8 | |
9 #include "img_format.h" | |
10 #include "mp_image.h" | |
11 | |
12 #include "../m_struct.h" | |
13 #include "../m_option.h" | |
14 #include "menu.h" | |
15 | |
16 #include "../libvo/font_load.h" | |
17 #include "../linux/keycodes.h" | |
18 #include "../input/input.h" | |
19 #include "../linux/timer.h" | |
20 | |
21 struct menu_priv_s { | |
22 char** lines; // Our buffer | |
23 int last_line; | |
24 int num_lines; | |
25 char* input; // input buffer | |
26 int input_size; // size of the input buffer in lines | |
27 unsigned int hide_ts; | |
28 unsigned int show_ts; | |
29 | |
30 //int max_lines; // Max number of lines with the last mpi | |
31 | |
32 char* prompt; | |
33 int buf_lines; // Buffer size (in line) | |
34 int height; // Display size in % | |
35 int minb; | |
36 int vspace; | |
37 unsigned int hide_time; | |
38 unsigned int show_time; | |
39 }; | |
40 | |
41 static struct menu_priv_s cfg_dflt = { | |
42 NULL, | |
43 0, | |
44 0, | |
45 NULL, | |
46 0, | |
47 0, | |
48 0, | |
49 | |
50 "# ", | |
51 50, // lines | |
52 33, // % | |
53 3, | |
54 3, | |
55 500, | |
56 500, | |
57 }; | |
58 | |
59 #define ST_OFF(m) M_ST_OFF(struct menu_priv_s,m) | |
60 | |
61 static m_option_t cfg_fields[] = { | |
62 { "prompt", ST_OFF(prompt), CONF_TYPE_STRING, M_OPT_MIN, 1, 0, NULL }, | |
63 { "buffer-lines", ST_OFF(buf_lines), CONF_TYPE_INT, M_OPT_MIN, 5, 0, NULL }, | |
64 { "height", ST_OFF(height), CONF_TYPE_INT, M_OPT_RANGE, 1, 100, NULL }, | |
65 { "minbor", ST_OFF(minb), CONF_TYPE_INT, M_OPT_MIN, 0, 0, NULL }, | |
66 { "vspace", ST_OFF(vspace), CONF_TYPE_INT, M_OPT_MIN, 0, 0, NULL }, | |
67 { "show-time",ST_OFF(show_time), CONF_TYPE_INT, M_OPT_MIN, 0, 0, NULL }, | |
68 { "hide-time",ST_OFF(hide_time), CONF_TYPE_INT, M_OPT_MIN, 0, 0, NULL }, | |
69 { NULL, NULL, NULL, 0,0,0,NULL } | |
70 }; | |
71 | |
72 #define mpriv (menu->priv) | |
73 | |
74 static void add_line(struct menu_priv_s* priv, char* l) { | |
75 | |
76 if(priv->num_lines >= priv->buf_lines && priv->lines[priv->last_line]) | |
77 free(priv->lines[priv->last_line]); | |
78 else | |
79 priv->num_lines++; | |
80 | |
81 priv->lines[priv->last_line] = strdup(l); | |
82 priv->last_line = (priv->last_line + 1) % priv->buf_lines; | |
83 } | |
84 | |
85 static void draw(menu_t* menu, mp_image_t* mpi) { | |
86 int h = mpi->h*mpriv->height/100; | |
87 int w = mpi->w - 2* mpriv->minb; | |
88 int x = mpriv->minb, y; | |
89 int lw,lh,i, ll = mpriv->last_line - 1; | |
90 | |
91 if(mpriv->hide_ts) { | |
92 unsigned int t = GetTimerMS() - mpriv->hide_ts; | |
93 if(t >= mpriv->hide_time) { | |
94 mpriv->hide_ts = 0; | |
95 menu->show = 0; | |
96 return; | |
97 } | |
98 h = mpi->h*(mpriv->height - (mpriv->height * t /mpriv->hide_time))/100; | |
99 } else if(mpriv->show_time && mpriv->show_ts == 0) { | |
100 mpriv->show_ts = GetTimerMS(); | |
101 return; | |
102 } else if(mpriv->show_ts > 0) { | |
103 unsigned int t = GetTimerMS() - mpriv->show_ts; | |
104 if(t > mpriv->show_time) | |
105 mpriv->show_ts = -1; | |
106 else | |
107 h = mpi->h*(mpriv->height * t /mpriv->hide_time)/100; | |
108 } | |
109 | |
110 y = h - mpriv->vspace; | |
111 | |
112 if(x < 0 || y < 0 || w <= 0 || h <= 0 ) | |
113 return; | |
114 | |
115 menu_text_size(mpriv->input,w,mpriv->vspace,1,&lw,&lh); | |
116 menu_draw_text_full(mpi,mpriv->input,x,y,w,h,mpriv->vspace,1, | |
117 MENU_TEXT_BOT|MENU_TEXT_LEFT, | |
118 MENU_TEXT_BOT|MENU_TEXT_LEFT); | |
119 y -= lh + mpriv->vspace; | |
120 | |
121 for( i = 0 ; y > mpriv->minb && i < mpriv->num_lines ; i++){ | |
122 int c = (ll - i) >= 0 ? ll - i : mpriv->buf_lines + ll - i; | |
123 menu_text_size(mpriv->lines[c],w,mpriv->vspace,1,&lw,&lh); | |
124 menu_draw_text_full(mpi,mpriv->lines[c],x,y,w,h,mpriv->vspace,1, | |
125 MENU_TEXT_BOT|MENU_TEXT_LEFT, | |
126 MENU_TEXT_BOT|MENU_TEXT_LEFT); | |
127 y -= lh + mpriv->vspace; | |
128 } | |
129 return; | |
130 } | |
131 | |
132 static void read_cmd(menu_t* menu,int cmd) { | |
133 switch(cmd) { | |
134 case MENU_CMD_UP: | |
135 break; | |
136 case MENU_CMD_DOWN: | |
137 case MENU_CMD_OK: | |
138 break; | |
139 case MENU_CMD_CANCEL: | |
140 menu->show = 0; | |
141 menu->cl = 1; | |
142 break; | |
143 } | |
144 } | |
145 | |
146 static void read_key(menu_t* menu,int c) { | |
147 switch(c) { | |
148 case KEY_ESC: | |
149 if(mpriv->hide_time) | |
150 mpriv->hide_ts = GetTimerMS(); | |
151 else | |
152 menu->show = 0; | |
153 mpriv->show_ts = 0; | |
154 return; | |
155 case KEY_ENTER: { | |
156 mp_cmd_t* c = mp_input_parse_cmd(&mpriv->input[strlen(mpriv->prompt)]); | |
157 add_line(mpriv,mpriv->input); | |
158 if(!c) | |
159 add_line(mpriv,"Invalid command try help"); | |
160 else { | |
161 switch(c->id) { | |
162 case MP_CMD_CHELP: | |
163 add_line(mpriv,"Mplayer console 0.01"); | |
164 add_line(mpriv,"TODO: Write some mainful help msg ;)"); | |
165 add_line(mpriv,"Enter any mplayer command"); | |
166 add_line(mpriv,"exit close this console"); | |
167 break; | |
168 case MP_CMD_CEXIT: | |
169 menu->show = 0; | |
170 menu->cl = 1; | |
171 break; | |
172 case MP_CMD_CHIDE: | |
173 if(mpriv->hide_time) | |
174 mpriv->hide_ts = GetTimerMS(); | |
175 else | |
176 menu->show = 0; | |
177 mpriv->show_ts = 0; | |
178 break; | |
179 default: // Send the other commands to mplayer | |
180 mp_input_queue_cmd(c); | |
181 } | |
182 } | |
183 mpriv->input[strlen(mpriv->prompt)] = '\0'; | |
184 return; | |
185 } | |
186 case KEY_DELETE: | |
187 case KEY_BS: { | |
188 unsigned int i = strlen(mpriv->input); | |
189 if(i > strlen(mpriv->prompt)) | |
190 mpriv->input[i-1] = '\0'; | |
191 return; | |
192 } | |
193 } | |
194 | |
195 if(isascii(c)) { | |
196 int l = strlen(mpriv->input); | |
197 mpriv->input[l] = (char)c; | |
198 mpriv->input[l+1] = '\0'; | |
199 } | |
200 | |
201 } | |
202 | |
203 | |
204 static int open(menu_t* menu, char* args) { | |
205 | |
206 | |
207 menu->draw = draw; | |
208 menu->read_cmd = read_cmd; | |
209 menu->read_key = read_key; | |
210 | |
211 mpriv->lines = calloc(mpriv->buf_lines,sizeof(char*)); | |
212 mpriv->input_size = 1024; | |
213 mpriv->input = calloc(mpriv->input_size,sizeof(char)); | |
214 strcpy(mpriv->input,mpriv->prompt); | |
215 | |
216 if(args) | |
217 add_line(mpriv,args); | |
218 | |
219 return 1; | |
220 } | |
221 | |
222 const menu_info_t menu_info_console = { | |
223 "MPlayer console", | |
224 "console", | |
225 "Albeu", | |
226 "", | |
227 { | |
228 "console_cfg", | |
229 sizeof(struct menu_priv_s), | |
230 &cfg_dflt, | |
231 cfg_fields | |
232 }, | |
233 open, | |
234 }; |