2002-10-23 18:52:54 +02:00
|
|
|
/* This file (C) Mark Zealey <mark@zealos.org> 2002, released under GPL */
|
|
|
|
|
2003-02-02 03:42:59 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2002-10-23 18:52:54 +02:00
|
|
|
#include "geometry.h"
|
2004-10-28 03:15:53 +02:00
|
|
|
#include "mp_msg.h"
|
2002-10-23 18:52:54 +02:00
|
|
|
|
2003-01-03 21:46:44 +01:00
|
|
|
/* A string of the form [WxH][+X+Y] or xpos[%]:ypos[%] */
|
2002-10-23 18:52:54 +02:00
|
|
|
char *vo_geometry = NULL;
|
2003-10-15 17:17:09 +02:00
|
|
|
// set when either width or height is changed
|
|
|
|
int geometry_wh_changed = 0;
|
2004-02-24 22:09:21 +01:00
|
|
|
int geometry_xy_changed = 0;
|
2002-10-23 18:52:54 +02:00
|
|
|
|
2003-03-02 22:09:15 +01:00
|
|
|
#define RESET_GEOMETRY width = height = xoff = yoff = xper = yper = -1;
|
|
|
|
|
|
|
|
// xpos,ypos: position of the left upper corner
|
|
|
|
// widw,widh: width and height of the window
|
|
|
|
// scrw,scrh: width and height of the current screen
|
|
|
|
int geometry(int *xpos, int *ypos, int *widw, int *widh, int scrw, int scrh)
|
2002-10-23 18:52:54 +02:00
|
|
|
{
|
2003-01-03 21:46:44 +01:00
|
|
|
int width, height, xoff, yoff, xper, yper;
|
|
|
|
|
|
|
|
width = height = xoff = yoff = xper = yper = -1;
|
|
|
|
|
|
|
|
if(vo_geometry != NULL) {
|
2003-03-02 22:09:15 +01:00
|
|
|
if(sscanf(vo_geometry, "%ix%i+%i+%i", &width, &height, &xoff, &yoff) != 4 )
|
|
|
|
{
|
|
|
|
RESET_GEOMETRY
|
|
|
|
if(sscanf(vo_geometry, "%ix%i", &width, &height) != 2)
|
|
|
|
{
|
|
|
|
RESET_GEOMETRY
|
|
|
|
if(sscanf(vo_geometry, "+%i+%i", &xoff, &yoff) != 2)
|
|
|
|
{
|
2005-02-09 18:58:41 +01:00
|
|
|
char percent[2];
|
2003-03-02 22:09:15 +01:00
|
|
|
RESET_GEOMETRY
|
2005-04-06 13:57:10 +02:00
|
|
|
if(sscanf(vo_geometry, "%i%%:%i%1[%]", &xper, &yper, percent) != 3)
|
2003-03-02 22:09:15 +01:00
|
|
|
{
|
|
|
|
RESET_GEOMETRY
|
2005-04-06 13:57:10 +02:00
|
|
|
if(sscanf(vo_geometry, "%i:%i%1[%]", &xoff, &yper, percent) != 3)
|
2003-03-02 22:09:15 +01:00
|
|
|
{
|
|
|
|
RESET_GEOMETRY
|
2005-02-09 18:58:41 +01:00
|
|
|
if(sscanf(vo_geometry, "%i%%:%i", &xper, &yoff) != 2)
|
2003-03-02 22:09:15 +01:00
|
|
|
{
|
|
|
|
RESET_GEOMETRY
|
2005-02-09 18:58:41 +01:00
|
|
|
if(sscanf(vo_geometry, "%i:%i", &xoff, &yoff) != 2)
|
2003-03-02 22:09:15 +01:00
|
|
|
{
|
|
|
|
RESET_GEOMETRY
|
2005-04-06 13:57:10 +02:00
|
|
|
if(sscanf(vo_geometry, "%i%1[%]", &xper, percent) != 2)
|
2003-08-31 20:33:02 +02:00
|
|
|
{
|
|
|
|
mp_msg(MSGT_VO, MSGL_ERR,
|
|
|
|
"-geometry must be in [WxH][+X+Y] | [X[%%]:[Y[%%]]] format, incorrect (%s)\n", vo_geometry);
|
|
|
|
return 0;
|
|
|
|
}
|
2003-03-02 22:09:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-10-23 18:52:54 +02:00
|
|
|
|
2003-03-02 22:09:15 +01:00
|
|
|
mp_msg(MSGT_VO, MSGL_V,"geometry set to width: %i,"
|
2003-04-20 17:09:19 +02:00
|
|
|
"height: %i, xoff: %i, yoff: %i, xper: %i, yper: %i\n",
|
2003-03-02 22:09:15 +01:00
|
|
|
width, height, xoff, yoff, xper, yper);
|
|
|
|
|
|
|
|
if(xper >= 0 && xper <= 100) xoff = (scrw - *widw) * ((float)xper / 100.0);
|
|
|
|
if(yper >= 0 && yper <= 100) yoff = (scrh - *widh) * ((float)yper / 100.0);
|
2003-01-04 14:12:13 +01:00
|
|
|
|
2003-04-20 17:09:19 +02:00
|
|
|
mp_msg(MSGT_VO, MSGL_V,"geometry set to width: %i,"
|
|
|
|
"height: %i, xoff: %i, yoff: %i, xper: %i, yper: %i\n",
|
|
|
|
width, height, xoff, yoff, xper, yper);
|
|
|
|
mp_msg(MSGT_VO, MSGL_V,"geometry window parameter: widw: %i,"
|
|
|
|
" widh: %i, scrw: %i, scrh: %i\n",*widw, *widh, scrw, scrh);
|
|
|
|
|
2003-01-04 14:12:13 +01:00
|
|
|
/* FIXME: better checking of bounds... */
|
2003-10-15 17:17:09 +02:00
|
|
|
if( width != -1 && (width < 0 || width > scrw))
|
|
|
|
width = (scrw < *widw) ? scrw : *widw;
|
|
|
|
if( height != -1 && (height < 0 || height > scrh))
|
|
|
|
height = (scrh < *widh) ? scrh : *widh;
|
|
|
|
if(xoff != -1 && (xoff < 0 || xoff + width > scrw)) xoff = 0;
|
|
|
|
if(yoff != -1 && (yoff < 0 || yoff + height > scrh)) yoff = 0;
|
2003-01-04 14:12:13 +01:00
|
|
|
|
2003-10-15 17:17:09 +02:00
|
|
|
if(xoff != -1 && xpos) *xpos = xoff;
|
|
|
|
if(yoff != -1 && ypos) *ypos = yoff;
|
|
|
|
if(width != -1 && widw) *widw = width;
|
|
|
|
if(height != -1 && widh) *widh = height;
|
|
|
|
|
|
|
|
if( width != -1 || height != -1)
|
|
|
|
geometry_wh_changed = 1;
|
2004-02-24 22:09:21 +01:00
|
|
|
if( xoff != -1 || yoff != -1)
|
|
|
|
geometry_xy_changed = 1;
|
2003-01-04 14:11:18 +01:00
|
|
|
}
|
2002-10-23 18:52:54 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2003-03-02 22:09:15 +01:00
|
|
|
#undef RESET_GEOMETRY
|