2002-10-23 16:52:54 +00:00
|
|
|
/* This file (C) Mark Zealey <mark@zealos.org> 2002, released under GPL */
|
|
|
|
|
2003-02-02 02:42:59 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2002-10-23 16:52:54 +00:00
|
|
|
#include "geometry.h"
|
|
|
|
#include "../mp_msg.h"
|
2002-11-23 10:58:14 +00:00
|
|
|
#include "../mplayer.h" /* exit_player() */
|
2002-10-23 16:52:54 +00:00
|
|
|
|
2003-01-03 20:46:44 +00:00
|
|
|
/* A string of the form [WxH][+X+Y] or xpos[%]:ypos[%] */
|
2002-10-23 16:52:54 +00:00
|
|
|
char *vo_geometry = NULL;
|
|
|
|
|
|
|
|
int geometry_error()
|
|
|
|
{
|
2003-01-03 20:46:44 +00:00
|
|
|
mp_msg(MSGT_VO, MSGL_ERR, "-geometry must be in [WxH][+X+Y] | [X[%%]:[Y[%%]]] format, incorrect (%s)\n", vo_geometry);
|
2002-10-23 16:52:54 +00:00
|
|
|
exit_player(NULL); /* ????? what else could we do ? */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-02 21:09:15 +00: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 16:52:54 +00:00
|
|
|
{
|
2003-01-03 20:46:44 +00:00
|
|
|
int width, height, xoff, yoff, xper, yper;
|
|
|
|
|
|
|
|
width = height = xoff = yoff = xper = yper = -1;
|
|
|
|
|
|
|
|
if(vo_geometry != NULL) {
|
2003-03-02 21:09:15 +00: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)
|
|
|
|
{
|
|
|
|
RESET_GEOMETRY
|
|
|
|
if(sscanf(vo_geometry, "%i:%i", &xoff, &yoff) != 2)
|
|
|
|
{
|
|
|
|
RESET_GEOMETRY
|
|
|
|
if(sscanf(vo_geometry, "%i:%i%%", &xper, &yper) != 2)
|
|
|
|
{
|
|
|
|
RESET_GEOMETRY
|
|
|
|
if(sscanf(vo_geometry, "%i%%:%i", &xper, &yper) != 2)
|
|
|
|
{
|
|
|
|
RESET_GEOMETRY
|
|
|
|
if(sscanf(vo_geometry, "%i%%:%i%%", &xper, &yper) != 2)
|
|
|
|
{
|
|
|
|
RESET_GEOMETRY
|
|
|
|
if(sscanf(vo_geometry, "%i%%", &xper) != 1)
|
2003-01-03 20:46:44 +00:00
|
|
|
return geometry_error();
|
2003-03-02 21:09:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-10-23 16:52:54 +00:00
|
|
|
|
2003-03-02 21:09:15 +00:00
|
|
|
mp_msg(MSGT_VO, MSGL_V,"geometry set to width: %i,"
|
|
|
|
"height: %i, xoff: %i, yoff: %i, xper: %1, yper: %i\n",
|
|
|
|
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 13:12:13 +00:00
|
|
|
|
|
|
|
/* FIXME: better checking of bounds... */
|
2003-03-02 21:09:15 +00:00
|
|
|
if(width < 0 || width > scrw) width = *widw;
|
|
|
|
if(height < 0 || height > scrh) height = *widh;
|
|
|
|
if(xoff < 0 || xoff + *widw > scrw) xoff = 0;
|
|
|
|
if(yoff < 0 || yoff + *widh > scrh) yoff = 0;
|
2003-01-04 13:12:13 +00:00
|
|
|
|
|
|
|
if(xpos) *xpos = xoff;
|
|
|
|
if(ypos) *ypos = yoff;
|
2003-03-02 21:09:15 +00:00
|
|
|
if(widw) *widw = width;
|
|
|
|
if(widh) *widh = height;
|
2003-01-04 13:11:18 +00:00
|
|
|
}
|
2002-10-23 16:52:54 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2003-03-02 21:09:15 +00:00
|
|
|
#undef RESET_GEOMETRY
|