annotate libvo/geometry.c @ 7866:732a8bfc7681

Added the -geometry option (supports fbdev and tdfxfb drivers)
author mark
date Wed, 23 Oct 2002 16:52:54 +0000
parents
children 9fc45fe0d444
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7866
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
1 /* This file (C) Mark Zealey <mark@zealos.org> 2002, released under GPL */
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
2
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
3 #include "geometry.h"
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
4 #include "../mp_msg.h"
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
5 #include <string.h>
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
6
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
7 /* A string of the form xpos[%]:ypos[%] */
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
8 char *vo_geometry = NULL;
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
9
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
10 int geometry_error()
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
11 {
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
12 mp_msg(MSGT_VO, MSGL_ERR, "-geometry option format incorrect (%s)\n", vo_geometry);
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
13 exit_player(NULL); /* ????? what else could we do ? */
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
14 return 0;
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
15 }
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
16
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
17 int get_num(char *s, int *num, char *end)
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
18 {
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
19 char *e;
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
20 long int t;
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
21
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
22 t = strtol(s, &e, 10);
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
23
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
24 if(e != end)
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
25 return 0;
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
26
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
27 *num = t;
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
28 return 1;
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
29 }
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
30
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
31 int geometry(int *xpos, int *ypos, int scrw, int scrh, int vidw, int vidh, int fs)
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
32 {
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
33 int xper = 0, yper = 0;
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
34 int glen;
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
35 char *colpos;
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
36
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
37 *xpos = 0; *ypos = 0;
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
38
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
39 if(vo_geometry == NULL)
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
40 return 1;
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
41
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
42 glen = strlen(vo_geometry);
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
43 colpos = strchr(vo_geometry, ':');
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
44 if(colpos == NULL)
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
45 colpos = (char *)(vo_geometry + glen);
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
46
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
47 /* Parse the x bit */
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
48 if(colpos[-1] == '%') {
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
49 if(!get_num(vo_geometry, &xper, colpos - 1))
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
50 return geometry_error();
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
51 } else {
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
52 if(!get_num(vo_geometry, xpos, colpos))
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
53 return geometry_error();
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
54 }
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
55
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
56 if(*colpos != '\0')
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
57 if(vo_geometry[glen - 1] == '%') {
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
58 if(!get_num(colpos + 1, &yper, vo_geometry + glen - 1))
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
59 return geometry_error();
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
60 } else {
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
61 if(!get_num(colpos + 1, ypos, vo_geometry + glen))
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
62 return geometry_error();
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
63 }
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
64
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
65 if(xper)
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
66 *xpos = (scrw - vidw) * ((float)xper / 100.0);
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
67 if(yper)
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
68 *ypos = (scrh - vidh) * ((float)yper / 100.0);
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
69
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
70 if(*xpos + vidw > scrw) {
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
71 mp_msg(MSGT_VO, MSGL_ERR, "X position is too large\n");
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
72 return geometry_error();
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
73 }
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
74 if(*ypos + vidh > scrh) {
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
75 mp_msg(MSGT_VO, MSGL_ERR, "Y position is too large\n");
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
76 return geometry_error();
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
77 }
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
78
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
79 return 1;
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
80 }