mp_msg: Remove uses of MSGT_MENCODER
[mplayer/glamo.git] / libvo / geometry.c
blob4bc08f811d35640523851416cd6a7c2208ab73a3
1 /*
2 * copyright (C) 2002 Mark Zealey <mark@zealos.org>
4 * This file is part of MPlayer.
6 * MPlayer is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * MPlayer is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include <stdio.h>
22 #include <string.h>
23 #include <limits.h>
24 #include "geometry.h"
25 #include "mp_msg.h"
27 /* A string of the form [WxH][+X+Y] or xpos[%]:ypos[%] */
28 char *vo_geometry;
29 // set when either width or height is changed
30 int geometry_wh_changed;
31 int geometry_xy_changed;
33 // xpos,ypos: position of the left upper corner
34 // widw,widh: width and height of the window
35 // scrw,scrh: width and height of the current screen
36 int geometry(int *xpos, int *ypos, int *widw, int *widh, int scrw, int scrh)
38 if(vo_geometry != NULL) {
39 char xsign[2], ysign[2], dummy[2];
40 int width, height, xoff, yoff, xper, yper;
41 int i;
42 int ok = 0;
43 for (i = 0; !ok && i < 9; i++) {
44 width = height = xoff = yoff = xper = yper = INT_MIN;
45 strcpy(xsign, "+");
46 strcpy(ysign, "+");
47 switch (i) {
48 case 0:
49 ok = sscanf(vo_geometry, "%ix%i%1[+-]%i%1[+-]%i%c",
50 &width, &height, xsign, &xoff, ysign,
51 &yoff, dummy) == 6;
52 break;
53 case 1:
54 ok = sscanf(vo_geometry, "%ix%i%c", &width, &height, dummy) == 2;
55 break;
56 case 2:
57 ok = sscanf(vo_geometry, "%1[+-]%i%1[+-]%i%c",
58 xsign, &xoff, ysign, &yoff, dummy) == 4;
59 break;
60 case 3:
61 ok = sscanf(vo_geometry, "%i%%:%i%1[%]%c", &xper, &yper, dummy, dummy) == 3;
62 break;
63 case 4:
64 ok = sscanf(vo_geometry, "%i:%i%1[%]%c", &xoff, &yper, dummy, dummy) == 3;
65 break;
66 case 5:
67 ok = sscanf(vo_geometry, "%i%%:%i%c", &xper, &yoff, dummy) == 2;
68 break;
69 case 6:
70 ok = sscanf(vo_geometry, "%i:%i%c", &xoff, &yoff, dummy) == 2;
71 break;
72 case 7:
73 ok = sscanf(vo_geometry, "%i%1[%]%c", &xper, dummy, dummy) == 2;
74 break;
75 case 8:
76 ok = sscanf(vo_geometry, "%i%c", &xoff, dummy) == 1;
77 break;
80 if (!ok) {
81 mp_msg(MSGT_VO, MSGL_ERR,
82 "-geometry must be in [WxH][[+-]X[+-]Y] | [X[%%]:[Y[%%]]] format, incorrect (%s)\n", vo_geometry);
83 return 0;
86 mp_msg(MSGT_VO, MSGL_V,"geometry window parameter: widw: %i,"
87 " widh: %i, scrw: %i, scrh: %i\n",*widw, *widh, scrw, scrh);
89 mp_msg(MSGT_VO, MSGL_V,"geometry set to width: %i,"
90 "height: %i, xoff: %s%i, yoff: %s%i, xper: %i, yper: %i\n",
91 width, height, xsign, xoff, ysign, yoff, xper, yper);
93 if (width > 0 && widw) *widw = width;
94 if (height > 0 && widh) *widh = height;
96 if(xoff != INT_MIN && xsign[0] == '-') xoff = scrw - *widw - xoff;
97 if(yoff != INT_MIN && ysign[0] == '-') yoff = scrh - *widh - yoff;
98 if(xper >= 0 && xper <= 100) xoff = (scrw - *widw) * ((float)xper / 100.0);
99 if(yper >= 0 && yper <= 100) yoff = (scrh - *widh) * ((float)yper / 100.0);
101 mp_msg(MSGT_VO, MSGL_V,"geometry set to width: %i,"
102 "height: %i, xoff: %i, yoff: %i, xper: %i, yper: %i\n",
103 width, height, xoff, yoff, xper, yper);
105 if (xoff != INT_MIN && xpos) *xpos = xoff;
106 if (yoff != INT_MIN && ypos) *ypos = yoff;
108 geometry_wh_changed = width > 0 || height > 0;
109 geometry_xy_changed = xoff != INT_MIN || yoff != INT_MIN;
111 return 1;