10l initial patch by Oded Shimon <ods15 at ods15.dyndns.org>
[mplayer/greg.git] / libvo / geometry.c
blobfbafb5a9553357b631bdb675039cd95ba10eb353
1 /* This file (C) Mark Zealey <mark@zealos.org> 2002, released under GPL */
3 #include <stdio.h>
4 #include <string.h>
5 #include "geometry.h"
6 #include "mp_msg.h"
8 /* A string of the form [WxH][+X+Y] or xpos[%]:ypos[%] */
9 char *vo_geometry = NULL;
10 // set when either width or height is changed
11 int geometry_wh_changed = 0;
12 int geometry_xy_changed = 0;
14 #define RESET_GEOMETRY width = height = xoff = yoff = xper = yper = -1;
16 // xpos,ypos: position of the left upper corner
17 // widw,widh: width and height of the window
18 // scrw,scrh: width and height of the current screen
19 int geometry(int *xpos, int *ypos, int *widw, int *widh, int scrw, int scrh)
21 int width, height, xoff, yoff, xper, yper;
23 width = height = xoff = yoff = xper = yper = -1;
25 if(vo_geometry != NULL) {
26 if(sscanf(vo_geometry, "%ix%i+%i+%i", &width, &height, &xoff, &yoff) != 4 )
28 RESET_GEOMETRY
29 if(sscanf(vo_geometry, "%ix%i", &width, &height) != 2)
31 RESET_GEOMETRY
32 if(sscanf(vo_geometry, "+%i+%i", &xoff, &yoff) != 2)
34 RESET_GEOMETRY
35 if(sscanf(vo_geometry, "%i:%i", &xoff, &yoff) != 2)
37 RESET_GEOMETRY
38 if(sscanf(vo_geometry, "%i:%i%%", &xper, &yper) != 2)
40 RESET_GEOMETRY
41 if(sscanf(vo_geometry, "%i%%:%i", &xper, &yper) != 2)
43 RESET_GEOMETRY
44 if(sscanf(vo_geometry, "%i%%:%i%%", &xper, &yper) != 2)
46 RESET_GEOMETRY
47 if(sscanf(vo_geometry, "%i%%", &xper) != 1)
49 mp_msg(MSGT_VO, MSGL_ERR,
50 "-geometry must be in [WxH][+X+Y] | [X[%%]:[Y[%%]]] format, incorrect (%s)\n", vo_geometry);
51 return 0;
61 mp_msg(MSGT_VO, MSGL_V,"geometry set to width: %i,"
62 "height: %i, xoff: %i, yoff: %i, xper: %i, yper: %i\n",
63 width, height, xoff, yoff, xper, yper);
65 if(xper >= 0 && xper <= 100) xoff = (scrw - *widw) * ((float)xper / 100.0);
66 if(yper >= 0 && yper <= 100) yoff = (scrh - *widh) * ((float)yper / 100.0);
68 mp_msg(MSGT_VO, MSGL_V,"geometry set to width: %i,"
69 "height: %i, xoff: %i, yoff: %i, xper: %i, yper: %i\n",
70 width, height, xoff, yoff, xper, yper);
71 mp_msg(MSGT_VO, MSGL_V,"geometry window parameter: widw: %i,"
72 " widh: %i, scrw: %i, scrh: %i\n",*widw, *widh, scrw, scrh);
74 /* FIXME: better checking of bounds... */
75 if( width != -1 && (width < 0 || width > scrw))
76 width = (scrw < *widw) ? scrw : *widw;
77 if( height != -1 && (height < 0 || height > scrh))
78 height = (scrh < *widh) ? scrh : *widh;
79 if(xoff != -1 && (xoff < 0 || xoff + width > scrw)) xoff = 0;
80 if(yoff != -1 && (yoff < 0 || yoff + height > scrh)) yoff = 0;
82 if(xoff != -1 && xpos) *xpos = xoff;
83 if(yoff != -1 && ypos) *ypos = yoff;
84 if(width != -1 && widw) *widw = width;
85 if(height != -1 && widh) *widh = height;
87 if( width != -1 || height != -1)
88 geometry_wh_changed = 1;
89 if( xoff != -1 || yoff != -1)
90 geometry_xy_changed = 1;
92 return 1;
95 #undef RESET_GEOMETRY