diff libvo/geometry.c @ 8745:93f78fb709e6

Added support for X style -geometry options (adapted from Henk's patch) -- Mark
author mark
date Fri, 03 Jan 2003 20:46:44 +0000
parents 772d6d27fd66
children e497d7e42d8a
line wrap: on
line diff
--- a/libvo/geometry.c	Fri Jan 03 18:33:26 2003 +0000
+++ b/libvo/geometry.c	Fri Jan 03 20:46:44 2003 +0000
@@ -4,80 +4,58 @@
 #include "../mp_msg.h"
 #include "../mplayer.h" /* exit_player() */
 #include <string.h>
-#include <stdlib.h> /* strtol */
 
-/* A string of the form xpos[%]:ypos[%] */
+/* A string of the form [WxH][+X+Y] or xpos[%]:ypos[%] */
 char *vo_geometry = NULL;
 
 int geometry_error()
 {
-	mp_msg(MSGT_VO, MSGL_ERR, "-geometry option format incorrect (%s)\n", vo_geometry);
+	mp_msg(MSGT_VO, MSGL_ERR, "-geometry must be in [WxH][+X+Y] | [X[%%]:[Y[%%]]] format, incorrect (%s)\n", vo_geometry);
 	exit_player(NULL);		/* ????? what else could we do ? */
 	return 0;
 }
 
-int get_num(char *s, int *num, char *end)
+// A little kludge as to not to have to update all drivers
+// Only the vo_xv driver supports now the full [WxH][+X+Y] option
+int geometryFull(int *pwidth, int *pheight, int *xpos, int *ypos, int scrw, int scrh, int vidw, int vidh)
 {
-	char *e;
-	long int t;
+        int width, height, xoff, yoff, xper, yper;
+
+	width = height = xoff = yoff = xper = yper = -1;
 
-	t = strtol(s, &e, 10);
+	/* no need to save a few extra cpu cycles here ;) */
+	/* PUKE i will rewrite this code sometime maybe - euck but it works */
+        if(vo_geometry != NULL) {
+		if(sscanf(vo_geometry, "%ix%i+%i+%i", &width, &height, &xoff, &yoff) != 4 &&
+		   sscanf(vo_geometry, "%ix%i", &width, &height) != 2 &&
+		   sscanf(vo_geometry, "+%i+%i", &xoff, &yoff) != 2 &&
+		   sscanf(vo_geometry, "%i:%i", &xoff, &yoff) != 2 &&
+		   sscanf(vo_geometry, "%i:%i%%", &xper, &yper) != 2 &&
+		   sscanf(vo_geometry, "%i%%:%i", &xper, &yper) != 2 &&
+		   sscanf(vo_geometry, "%i%%:%i%%", &xper, &yper) != 2 &&
+		   sscanf(vo_geometry, "%i%%", &xper) != 1)
+			return geometry_error();
+        }
 
-	if(e != end)
-		return 0;
+	if(xper >= 0 && xper <= 100) xoff = (scrw - vidw) * ((float)xper / 100.0);
+	if(yper >= 0 && yper <= 100) yoff = (scrh - vidh) * ((float)yper / 100.0);
 
-	*num = t;
+	/* FIXME: better checking of bounds... */
+	if(width < 0 || width > scrw) width = vidw;
+	if(height < 0 || height > scrh) height = vidh;
+	if(xoff < 0 || xoff + vidw > scrw) xoff = 0;
+	if(yoff < 0 || yoff + vidh > scrh) yoff = 0;
+
+	if(xpos) *xpos = xoff;
+	if(ypos) *ypos = yoff;
+	if(pwidth) *pwidth = width;
+	if(pheight) *pheight = height;
 	return 1;
 }
 
-int geometry(int *xpos, int *ypos, int scrw, int scrh, int vidw, int vidh, int fs)
+// compatibility function
+// only libvo working with full geometry options.
+int geometry(int *xpos, int *ypos, int scrw, int scrh, int vidw, int vidh)
 {
-	int xper = 0, yper = 0;
-	int glen;
-	char *colpos;
-
-	*xpos = 0; *ypos = 0;
-
-	if(vo_geometry == NULL)
-		return 1;
-
-	glen = strlen(vo_geometry);
-	colpos = strchr(vo_geometry, ':');
-	if(colpos == NULL)
-		colpos = (char *)(vo_geometry + glen);
-
-	/* Parse the x bit */
-	if(colpos[-1] == '%') {
-		if(!get_num(vo_geometry, &xper, colpos - 1))
-			return geometry_error();
-	} else {
-		if(!get_num(vo_geometry, xpos, colpos))
-			return geometry_error();
-	}
-
-	if(*colpos != '\0') {
-		if(vo_geometry[glen - 1] == '%') {
-			if(!get_num(colpos + 1, &yper, vo_geometry + glen - 1))
-				return geometry_error();
-		} else {
-			if(!get_num(colpos + 1, ypos, vo_geometry + glen))
-				return geometry_error();
-		}
-	}
-
-	if(xper)
-		*xpos = (scrw - vidw) * ((float)xper / 100.0);
-	if(yper)
-		*ypos = (scrh - vidh) * ((float)yper / 100.0);
-
-	if(*xpos + vidw > scrw) {
-		mp_msg(MSGT_VO, MSGL_ERR, "X position is too large\n");
-		return geometry_error();
-	}
-	if(*ypos + vidh > scrh) {
-		mp_msg(MSGT_VO, MSGL_ERR, "Y position is too large\n");
-		return geometry_error();
-	}
-
-	return 1;
+  return geometryFull(NULL, NULL, xpos, ypos, scrw, scrh, vidw, vidh);
 }