annotate libvo/geometry.c @ 32791:ece4313fbf15

Use defined variable and do not recalculate again.
author ib
date Thu, 10 Feb 2011 13:26:18 +0000
parents eff096c1ea0a
children 8528f4b70dff
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27509
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 15058
diff changeset
1 /*
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 15058
diff changeset
2 * copyright (C) 2002 Mark Zealey <mark@zealos.org>
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 15058
diff changeset
3 *
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 15058
diff changeset
4 * This file is part of MPlayer.
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 15058
diff changeset
5 *
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 15058
diff changeset
6 * MPlayer is free software; you can redistribute it and/or modify
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 15058
diff changeset
7 * it under the terms of the GNU General Public License as published by
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 15058
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 15058
diff changeset
9 * (at your option) any later version.
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 15058
diff changeset
10 *
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 15058
diff changeset
11 * MPlayer is distributed in the hope that it will be useful,
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 15058
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 15058
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 15058
diff changeset
14 * GNU General Public License for more details.
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 15058
diff changeset
15 *
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 15058
diff changeset
16 * You should have received a copy of the GNU General Public License along
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 15058
diff changeset
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 15058
diff changeset
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
d97a607821f1 Replace casual GPL notices by proper license headers.
diego
parents: 15058
diff changeset
19 */
7866
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
20
9217
420e2b2f8e5a compiler warning fixes patch by Dominik Mierzejewski <dominik@rangers.eu.org>
arpi
parents: 8768
diff changeset
21 #include <stdio.h>
420e2b2f8e5a compiler warning fixes patch by Dominik Mierzejewski <dominik@rangers.eu.org>
arpi
parents: 8768
diff changeset
22 #include <string.h>
29073
a5f19a8ecc86 Get rid of nonsensical limits on -geometry x, y,w and h values, they only
reimar
parents: 27509
diff changeset
23 #include <limits.h>
7866
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
24 #include "geometry.h"
13787
e047e70a9767 Handle "xxx.h" vs "../xxx.h" include paths in a consistent way.
diego
parents: 11996
diff changeset
25 #include "mp_msg.h"
7866
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
26
8745
93f78fb709e6 Added support for X style -geometry options (adapted from Henk's patch)
mark
parents: 8254
diff changeset
27 /* A string of the form [WxH][+X+Y] or xpos[%]:ypos[%] */
30450
201c9a709547 Remove pointless initializers and also set geometry_*_changed to 0 when
reimar
parents: 29350
diff changeset
28 char *vo_geometry;
11125
d9478c8e5ffe fix aspect hack
attila
parents: 10734
diff changeset
29 // set when either width or height is changed
30450
201c9a709547 Remove pointless initializers and also set geometry_*_changed to 0 when
reimar
parents: 29350
diff changeset
30 int geometry_wh_changed;
201c9a709547 Remove pointless initializers and also set geometry_*_changed to 0 when
reimar
parents: 29350
diff changeset
31 int geometry_xy_changed;
7866
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
32
9517
d65ddafbc404 clean up of -geometry code.
attila
parents: 9217
diff changeset
33 // xpos,ypos: position of the left upper corner
d65ddafbc404 clean up of -geometry code.
attila
parents: 9217
diff changeset
34 // widw,widh: width and height of the window
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29073
diff changeset
35 // scrw,scrh: width and height of the current screen
9517
d65ddafbc404 clean up of -geometry code.
attila
parents: 9217
diff changeset
36 int geometry(int *xpos, int *ypos, int *widw, int *widh, int scrw, int scrh)
7866
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
37 {
8745
93f78fb709e6 Added support for X style -geometry options (adapted from Henk's patch)
mark
parents: 8254
diff changeset
38 if(vo_geometry != NULL) {
31236
08ce2830d10c Extend geometry parsing to reject all invalid strings.
reimar
parents: 30781
diff changeset
39 char xsign[2], ysign[2], dummy[2];
30778
dc08ce042315 Avoid very deep indentation level and RESET_GEOMETRY macro in -geometry
reimar
parents: 30450
diff changeset
40 int width, height, xoff, yoff, xper, yper;
dc08ce042315 Avoid very deep indentation level and RESET_GEOMETRY macro in -geometry
reimar
parents: 30450
diff changeset
41 int i;
dc08ce042315 Avoid very deep indentation level and RESET_GEOMETRY macro in -geometry
reimar
parents: 30450
diff changeset
42 int ok = 0;
31252
eff096c1ea0a Add support for -geometry x syntax since the documentation claims
reimar
parents: 31236
diff changeset
43 for (i = 0; !ok && i < 9; i++) {
30778
dc08ce042315 Avoid very deep indentation level and RESET_GEOMETRY macro in -geometry
reimar
parents: 30450
diff changeset
44 width = height = xoff = yoff = xper = yper = INT_MIN;
30780
0ab92d0c1901 Add support for specifying window position relative to right and bottom
reimar
parents: 30779
diff changeset
45 strcpy(xsign, "+");
0ab92d0c1901 Add support for specifying window position relative to right and bottom
reimar
parents: 30779
diff changeset
46 strcpy(ysign, "+");
30778
dc08ce042315 Avoid very deep indentation level and RESET_GEOMETRY macro in -geometry
reimar
parents: 30450
diff changeset
47 switch (i) {
dc08ce042315 Avoid very deep indentation level and RESET_GEOMETRY macro in -geometry
reimar
parents: 30450
diff changeset
48 case 0:
31236
08ce2830d10c Extend geometry parsing to reject all invalid strings.
reimar
parents: 30781
diff changeset
49 ok = sscanf(vo_geometry, "%ix%i%1[+-]%i%1[+-]%i%c",
08ce2830d10c Extend geometry parsing to reject all invalid strings.
reimar
parents: 30781
diff changeset
50 &width, &height, xsign, &xoff, ysign,
08ce2830d10c Extend geometry parsing to reject all invalid strings.
reimar
parents: 30781
diff changeset
51 &yoff, dummy) == 6;
30778
dc08ce042315 Avoid very deep indentation level and RESET_GEOMETRY macro in -geometry
reimar
parents: 30450
diff changeset
52 break;
dc08ce042315 Avoid very deep indentation level and RESET_GEOMETRY macro in -geometry
reimar
parents: 30450
diff changeset
53 case 1:
31236
08ce2830d10c Extend geometry parsing to reject all invalid strings.
reimar
parents: 30781
diff changeset
54 ok = sscanf(vo_geometry, "%ix%i%c", &width, &height, dummy) == 2;
30778
dc08ce042315 Avoid very deep indentation level and RESET_GEOMETRY macro in -geometry
reimar
parents: 30450
diff changeset
55 break;
dc08ce042315 Avoid very deep indentation level and RESET_GEOMETRY macro in -geometry
reimar
parents: 30450
diff changeset
56 case 2:
31236
08ce2830d10c Extend geometry parsing to reject all invalid strings.
reimar
parents: 30781
diff changeset
57 ok = sscanf(vo_geometry, "%1[+-]%i%1[+-]%i%c",
08ce2830d10c Extend geometry parsing to reject all invalid strings.
reimar
parents: 30781
diff changeset
58 xsign, &xoff, ysign, &yoff, dummy) == 4;
30778
dc08ce042315 Avoid very deep indentation level and RESET_GEOMETRY macro in -geometry
reimar
parents: 30450
diff changeset
59 break;
dc08ce042315 Avoid very deep indentation level and RESET_GEOMETRY macro in -geometry
reimar
parents: 30450
diff changeset
60 case 3:
31236
08ce2830d10c Extend geometry parsing to reject all invalid strings.
reimar
parents: 30781
diff changeset
61 ok = sscanf(vo_geometry, "%i%%:%i%1[%]%c", &xper, &yper, dummy, dummy) == 3;
30778
dc08ce042315 Avoid very deep indentation level and RESET_GEOMETRY macro in -geometry
reimar
parents: 30450
diff changeset
62 break;
dc08ce042315 Avoid very deep indentation level and RESET_GEOMETRY macro in -geometry
reimar
parents: 30450
diff changeset
63 case 4:
31236
08ce2830d10c Extend geometry parsing to reject all invalid strings.
reimar
parents: 30781
diff changeset
64 ok = sscanf(vo_geometry, "%i:%i%1[%]%c", &xoff, &yper, dummy, dummy) == 3;
30778
dc08ce042315 Avoid very deep indentation level and RESET_GEOMETRY macro in -geometry
reimar
parents: 30450
diff changeset
65 break;
dc08ce042315 Avoid very deep indentation level and RESET_GEOMETRY macro in -geometry
reimar
parents: 30450
diff changeset
66 case 5:
31236
08ce2830d10c Extend geometry parsing to reject all invalid strings.
reimar
parents: 30781
diff changeset
67 ok = sscanf(vo_geometry, "%i%%:%i%c", &xper, &yoff, dummy) == 2;
30778
dc08ce042315 Avoid very deep indentation level and RESET_GEOMETRY macro in -geometry
reimar
parents: 30450
diff changeset
68 break;
dc08ce042315 Avoid very deep indentation level and RESET_GEOMETRY macro in -geometry
reimar
parents: 30450
diff changeset
69 case 6:
31236
08ce2830d10c Extend geometry parsing to reject all invalid strings.
reimar
parents: 30781
diff changeset
70 ok = sscanf(vo_geometry, "%i:%i%c", &xoff, &yoff, dummy) == 2;
30778
dc08ce042315 Avoid very deep indentation level and RESET_GEOMETRY macro in -geometry
reimar
parents: 30450
diff changeset
71 break;
dc08ce042315 Avoid very deep indentation level and RESET_GEOMETRY macro in -geometry
reimar
parents: 30450
diff changeset
72 case 7:
31236
08ce2830d10c Extend geometry parsing to reject all invalid strings.
reimar
parents: 30781
diff changeset
73 ok = sscanf(vo_geometry, "%i%1[%]%c", &xper, dummy, dummy) == 2;
30778
dc08ce042315 Avoid very deep indentation level and RESET_GEOMETRY macro in -geometry
reimar
parents: 30450
diff changeset
74 break;
31252
eff096c1ea0a Add support for -geometry x syntax since the documentation claims
reimar
parents: 31236
diff changeset
75 case 8:
eff096c1ea0a Add support for -geometry x syntax since the documentation claims
reimar
parents: 31236
diff changeset
76 ok = sscanf(vo_geometry, "%i%c", &xoff, dummy) == 1;
eff096c1ea0a Add support for -geometry x syntax since the documentation claims
reimar
parents: 31236
diff changeset
77 break;
30778
dc08ce042315 Avoid very deep indentation level and RESET_GEOMETRY macro in -geometry
reimar
parents: 30450
diff changeset
78 }
dc08ce042315 Avoid very deep indentation level and RESET_GEOMETRY macro in -geometry
reimar
parents: 30450
diff changeset
79 }
dc08ce042315 Avoid very deep indentation level and RESET_GEOMETRY macro in -geometry
reimar
parents: 30450
diff changeset
80 if (!ok) {
10734
b105d7aba10d remove exit_player and exit references
alex
parents: 9947
diff changeset
81 mp_msg(MSGT_VO, MSGL_ERR,
30780
0ab92d0c1901 Add support for specifying window position relative to right and bottom
reimar
parents: 30779
diff changeset
82 "-geometry must be in [WxH][[+-]X[+-]Y] | [X[%%]:[Y[%%]]] format, incorrect (%s)\n", vo_geometry);
10734
b105d7aba10d remove exit_player and exit references
alex
parents: 9947
diff changeset
83 return 0;
b105d7aba10d remove exit_player and exit references
alex
parents: 9947
diff changeset
84 }
7866
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
85
30781
1b4d24af52a7 Save the new width and height earlier so that e.g. -geometry 30x30-50-50
reimar
parents: 30780
diff changeset
86 mp_msg(MSGT_VO, MSGL_V,"geometry window parameter: widw: %i,"
1b4d24af52a7 Save the new width and height earlier so that e.g. -geometry 30x30-50-50
reimar
parents: 30780
diff changeset
87 " widh: %i, scrw: %i, scrh: %i\n",*widw, *widh, scrw, scrh);
1b4d24af52a7 Save the new width and height earlier so that e.g. -geometry 30x30-50-50
reimar
parents: 30780
diff changeset
88
9517
d65ddafbc404 clean up of -geometry code.
attila
parents: 9217
diff changeset
89 mp_msg(MSGT_VO, MSGL_V,"geometry set to width: %i,"
30780
0ab92d0c1901 Add support for specifying window position relative to right and bottom
reimar
parents: 30779
diff changeset
90 "height: %i, xoff: %s%i, yoff: %s%i, xper: %i, yper: %i\n",
0ab92d0c1901 Add support for specifying window position relative to right and bottom
reimar
parents: 30779
diff changeset
91 width, height, xsign, xoff, ysign, yoff, xper, yper);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29073
diff changeset
92
30781
1b4d24af52a7 Save the new width and height earlier so that e.g. -geometry 30x30-50-50
reimar
parents: 30780
diff changeset
93 if (width > 0 && widw) *widw = width;
1b4d24af52a7 Save the new width and height earlier so that e.g. -geometry 30x30-50-50
reimar
parents: 30780
diff changeset
94 if (height > 0 && widh) *widh = height;
1b4d24af52a7 Save the new width and height earlier so that e.g. -geometry 30x30-50-50
reimar
parents: 30780
diff changeset
95
30780
0ab92d0c1901 Add support for specifying window position relative to right and bottom
reimar
parents: 30779
diff changeset
96 if(xoff != INT_MIN && xsign[0] == '-') xoff = scrw - *widw - xoff;
0ab92d0c1901 Add support for specifying window position relative to right and bottom
reimar
parents: 30779
diff changeset
97 if(yoff != INT_MIN && ysign[0] == '-') yoff = scrh - *widh - yoff;
9517
d65ddafbc404 clean up of -geometry code.
attila
parents: 9217
diff changeset
98 if(xper >= 0 && xper <= 100) xoff = (scrw - *widw) * ((float)xper / 100.0);
d65ddafbc404 clean up of -geometry code.
attila
parents: 9217
diff changeset
99 if(yper >= 0 && yper <= 100) yoff = (scrh - *widh) * ((float)yper / 100.0);
7866
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
100
9947
b552e7939ca2 adding geometry support for xvidix
attila
parents: 9517
diff changeset
101 mp_msg(MSGT_VO, MSGL_V,"geometry set to width: %i,"
b552e7939ca2 adding geometry support for xvidix
attila
parents: 9517
diff changeset
102 "height: %i, xoff: %i, yoff: %i, xper: %i, yper: %i\n",
b552e7939ca2 adding geometry support for xvidix
attila
parents: 9517
diff changeset
103 width, height, xoff, yoff, xper, yper);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29073
diff changeset
104
29073
a5f19a8ecc86 Get rid of nonsensical limits on -geometry x, y,w and h values, they only
reimar
parents: 27509
diff changeset
105 if (xoff != INT_MIN && xpos) *xpos = xoff;
a5f19a8ecc86 Get rid of nonsensical limits on -geometry x, y,w and h values, they only
reimar
parents: 27509
diff changeset
106 if (yoff != INT_MIN && ypos) *ypos = yoff;
8745
93f78fb709e6 Added support for X style -geometry options (adapted from Henk's patch)
mark
parents: 8254
diff changeset
107
30450
201c9a709547 Remove pointless initializers and also set geometry_*_changed to 0 when
reimar
parents: 29350
diff changeset
108 geometry_wh_changed = width > 0 || height > 0;
201c9a709547 Remove pointless initializers and also set geometry_*_changed to 0 when
reimar
parents: 29350
diff changeset
109 geometry_xy_changed = xoff != INT_MIN || yoff != INT_MIN;
8767
e497d7e42d8a fix xv window position problem
attila
parents: 8745
diff changeset
110 }
7866
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
111 return 1;
732a8bfc7681 Added the -geometry option (supports fbdev and tdfxfb drivers)
mark
parents:
diff changeset
112 }