Subject: Vector offsets patch

From: Marcus Lundblad <[email-masked]>
Date: Sat, 26 Oct 2002 13:21:23 +0200 (CEST)

I made a patch to implement the vector offset additions I suggested a
while ago on the FVWM-list.

I followed the instructions on the web for CVS, I hope I did everything
correct.

With this you can do for example:

ButtonStyle 2 5 0+3x0+3@2 100-5x0+3@2 100-5x100-5@2 0+3x100-5@2 0+3x0+3@2

to get a button that is aligned with an absolute number of pixels from the
border.
With this it's also possible to get lines of double witdh by using offset
of 1 pixel.

//Marcus
Index: ChangeLog
===================================================================
RCS file: /home/cvs/fvwm/fvwm/ChangeLog,v
retrieving revision 1.2103
diff -u -u -r1.2103 ChangeLog
--- ChangeLog	2002/10/25 11:11:43	1.2103
+++ ChangeLog	2002/10/26 11:14:00
@@ -1,3 +1,17 @@
+2002-10-26  Marcus Lundblad <[email-masked]>
+	* fvwm/screen.h (vector_coords):
+	added fields for offsets
+	* fvwm/builtins.c (ReadDecorFace):
+	rewrote parser for vector definitions to accept optinal
+	offsets
+	* fvwm/fvwm.c (LoadDefaultLeftButton):
+	  (LoadDefaultRightButton)
+	set default values for offsets
+	* fvwm/borders.c (border_draw_vector_to_pixmap):
+	updated XDrawLine call to take offsets into account
+	* fvwm/fvwm.1.in:
+	documented new options for vector offsets
+	
 2002-10-25  Dominik Vogt  <[email-masked]>
 
 	* fvwm/functable.c (func_table):
Index: fvwm/borders.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/borders.c,v
retrieving revision 1.218
diff -u -u -r1.218 borders.c
--- fvwm/borders.c	2002/10/17 11:01:06	1.218
+++ fvwm/borders.c	2002/10/26 11:14:06
@@ -1540,12 +1540,17 @@
 			/* don't draw a line */
 			continue;
 		}
+
 		XDrawLine(
 			dpy, dest_pix, gcs[coords->c[i]],
-			pixmap_g->width * coords->x[i-1] / 100,
-			pixmap_g->height * coords->y[i-1] / 100,
-			pixmap_g->width * coords->x[i] / 100,
-			pixmap_g->height * coords->y[i] / 100);
+			pixmap_g->width * coords->x[i-1] / 100 + 
+			                  coords->xoff[i-1],
+			pixmap_g->height * coords->y[i-1] / 100 +
+			                   coords->yoff[i-1],
+			pixmap_g->width * coords->x[i] / 100 +
+			                  coords->xoff[i],
+			pixmap_g->height * coords->y[i] / 100 +
+		                           coords->yoff[i]);
 	}
 
 	return;
Index: fvwm/builtins.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/builtins.c,v
retrieving revision 1.378
diff -u -u -r1.378 builtins.c
--- fvwm/builtins.c	2002/10/24 07:21:43	1.378
+++ fvwm/builtins.c	2002/10/26 11:14:35
@@ -1159,6 +1159,15 @@
 		{
 			free (df->u.vector.y);
 		}
+		/* free offsets for coord */
+		if (df->u.vector.xoff)
+		{
+		  free(df->u.vector.xoff);
+		}
+		if(df->u.vector.yoff)
+		{
+		  free(df->u.vector.xoff);
+		}
 		if (df->u.vector.c)
 		{
 			free (df->u.vector.c);
@@ -1292,6 +1301,8 @@
 			vc->use_fgbg = 0;
 			vc->x = safemalloc(sizeof(char) * num_coords);
 			vc->y = safemalloc(sizeof(char) * num_coords);
+			vc->xoff = safemalloc(sizeof(char) * num_coords);
+			vc->yoff = safemalloc(sizeof(char) * num_coords);
 			vc->c = safemalloc(sizeof(char) * num_coords);
 
 			/* get the points */
@@ -1299,13 +1310,70 @@
 			{
 				int x;
 				int y;
+				int xoff = 0;
+				int yoff = 0;
 				int c;
+				Bool valid = True;
 
-				/* X x Y @ line_style */
-				num = sscanf(
-					s,"%dx%d@%d%n", &x, &y, &c, &offset);
-				if (num != 3)
+				/*printf(stderr,"Button: %s\n",s);*/
+
+				/* read X-coord */
+				num = sscanf(s,"%d%n",&x,&offset);
+				if(num != 1)
+				  valid = False;
+				if(valid)
+				{
+				  s += offset;
+				  /* check for offest */
+				  if(*s == '+' || *s == '-')
+				  {
+				    num = sscanf(s,"%d%n",&xoff,&offset);
+				    s += offset;
+				    if(num != 1)
+				      valid = False;
+				  }
+				  if(*s != 'x')
+				    valid = False;
+				  s++;
+				}
+				 
+				if(valid)
 				{
+				  /* read y-coord */
+				  num = sscanf(s,"%d%n",&y,&offset);
+				  if(num != 1)
+				    valid = False;  
+				}
+				if(valid) 
+				{
+				  s += offset;
+				  /* if a posstive vector offset was 
+				     specified*/
+				  if(*s == '+' || *s == '-')
+				  {
+				    num = sscanf(s,"%d%n",&yoff,&offset);
+				    s += offset;
+				    if(num != 1)
+				      valid = False;
+				  }
+				  
+				  if(*s != '@')
+				    valid = False;
+				  /* eat the '@' */
+				  s++;
+				}
+
+				if(valid)
+				{
+				  /* read the line style */
+				  num = sscanf(s,"%d%n",&c,&offset);
+				  if(num != 1)
+				    valid = False;
+				  s += offset;
+				}
+					
+				if(!valid)
+				{
 					if (verbose)
 					{
 						fvwm_msg(
@@ -1316,9 +1384,13 @@
 					free(vc->x);
 					free(vc->y);
 					free(vc->c);
+					free(vc->xoff);
+					free(vc->yoff);
 					vc->x = NULL;
 					vc->y = NULL;
 					vc->c = NULL;
+					vc->xoff = NULL;
+					vc->yoff = NULL;
 					return False;
 				}
 				if (x < 0)
@@ -1344,11 +1416,12 @@
 				vc->x[i] = x;
 				vc->y[i] = y;
 				vc->c[i] = c;
+				vc->xoff[i] = xoff;
+				vc->yoff[i] = yoff;
 				if (c == 2 || c == 3)
 				{
 					vc->use_fgbg = 1;
 				}
-				s += offset;
 			}
 			memset(&df->style, 0, sizeof(df->style));
 			DFS_FACE_TYPE(df->style) = VectorButton;
Index: fvwm/fvwm.1.in
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/fvwm.1.in,v
retrieving revision 1.26
diff -u -u -r1.26 fvwm.1.in
--- fvwm/fvwm.1.in	2002/10/24 07:21:43	1.26
+++ fvwm/fvwm.1.in	2002/10/26 11:15:13
@@ -7649,7 +7649,8 @@
 .IR X x Y @ C .
 .IR X " and " Y
 are point coordinates inside the button, given in percents
-(from 0 to 100).
+(from 0 to 100) with an optional absolute offset in pixels, given as
++off or -off for a positive and a negative offset of off pixels respetivly.
 .I C
 specifies a line color (0 - the shadow color, 1 - the highlight
 color, 2 - the background color, 3 - the foreground color, 4 -
Index: fvwm/fvwm.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/fvwm.c,v
retrieving revision 1.336
diff -u -u -r1.336 fvwm.c
--- fvwm/fvwm.c	2002/10/22 00:48:32	1.336
+++ fvwm/fvwm.c	2002/10/26 11:15:23
@@ -834,6 +834,7 @@
 static void LoadDefaultLeftButton(DecorFace *df, int i)
 {
 	struct vector_coords *v = &df->u.vector;
+	int i = 0;
 
 	memset(&df->style, 0, sizeof(df->style));
 	DFS_FACE_TYPE(df->style) = DefaultVectorButton;
@@ -844,6 +845,8 @@
 		v->num = 5;
 		v->x = safemalloc(sizeof(char) * v->num);
 		v->y = safemalloc(sizeof(char) * v->num);
+		v->xoff = safemalloc(sizeof(char) * v->num);
+		v->yoff = safemalloc(sizeof(char) * v->num);
 		v->c = safecalloc(v->num, sizeof(char));
 		v->x[0] = 22;
 		v->y[0] = 39;
@@ -863,6 +866,8 @@
 		v->num = 5;
 		v->x = safemalloc(sizeof(char) * v->num);
 		v->y = safemalloc(sizeof(char) * v->num);
+		v->xoff = safemalloc(sizeof(char) * v->num);
+		v->yoff = safemalloc(sizeof(char) * v->num);
 		v->c = safecalloc(v->num, sizeof(char));
 		v->x[0] = 32;
 		v->y[0] = 45;
@@ -881,6 +886,8 @@
 		v->num = 5;
 		v->x = safemalloc(sizeof(char) * v->num);
 		v->y = safemalloc(sizeof(char) * v->num);
+		v->xoff = safemalloc(sizeof(char) * v->num);
+		v->yoff = safemalloc(sizeof(char) * v->num);
 		v->c = safecalloc(v->num, sizeof(char));
 		v->x[0] = 49;
 		v->y[0] = 49;
@@ -900,6 +907,8 @@
 		v->num = 5;
 		v->x = safemalloc(sizeof(char) * v->num);
 		v->y = safemalloc(sizeof(char) * v->num);
+		v->xoff = safemalloc(sizeof(char) * v->num);
+		v->yoff = safemalloc(sizeof(char) * v->num);
 		v->c = safecalloc(v->num, sizeof(char));
 		v->x[0] = 32;
 		v->y[0] = 45;
@@ -917,6 +926,13 @@
 		break;
 	}
 
+	/* set offsets to 0, for all buttons */
+	for(i = 0 ; i < v->num ; i++)
+	{
+	  v->xoff[i] = 0;
+	  v->yoff[i] = 0;
+	}
+	
 	return;
 }
 
@@ -929,6 +945,7 @@
 static void LoadDefaultRightButton(DecorFace *df, int i)
 {
 	struct vector_coords *v = &df->u.vector;
+	int i = 0;
 
 	memset(&df->style, 0, sizeof(df->style));
 	DFS_FACE_TYPE(df->style) = DefaultVectorButton;
@@ -939,6 +956,8 @@
 		v->num = 5;
 		v->x = safemalloc(sizeof(char) * v->num);
 		v->y = safemalloc(sizeof(char) * v->num);
+		v->xoff = safemalloc(sizeof(char) * v->num);
+		v->yoff = safemalloc(sizeof(char) * v->num);
 		v->c = safecalloc(v->num, sizeof(char));
 		v->x[0] = 25;
 		v->y[0] = 25;
@@ -958,6 +977,8 @@
 		v->num = 5;
 		v->x = safemalloc(sizeof(char) * v->num);
 		v->y = safemalloc(sizeof(char) * v->num);
+		v->xoff = safemalloc(sizeof(char) * v->num);
+		v->yoff = safemalloc(sizeof(char) * v->num);
 		v->c = safecalloc(v->num, sizeof(char));
 		v->x[0] = 39;
 		v->y[0] = 39;
@@ -977,6 +998,8 @@
 		v->num = 5;
 		v->x = safemalloc(sizeof(char) * v->num);
 		v->y = safemalloc(sizeof(char) * v->num);
+		v->xoff = safemalloc(sizeof(char) * v->num);
+		v->yoff = safemalloc(sizeof(char) * v->num);
 		v->c = safecalloc(v->num, sizeof(char));
 		v->x[0] = 49;
 		v->y[0] = 49;
@@ -996,6 +1019,8 @@
 		v->num = 5;
 		v->x = safemalloc(sizeof(char) * v->num);
 		v->y = safemalloc(sizeof(char) * v->num);
+		v->xoff = safemalloc(sizeof(char) * v->num);
+		v->yoff = safemalloc(sizeof(char) * v->num);
 		v->c = safecalloc(v->num, sizeof(char));
 		v->x[0] = 36;
 		v->y[0] = 36;
@@ -1011,6 +1036,13 @@
 		v->y[4] = 36;
 		v->c[4] = 1;
 		break;
+	}
+
+	/* set offsets to 0, for all buttons */
+	for(i = 0 ; i < v->num ; i++)
+	{
+	  v->xoff[i] = 0;
+	  v->yoff[i] = 0;
 	}
 
 	return;
Index: fvwm/screen.h
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/screen.h,v
retrieving revision 1.136
diff -u -u -r1.136 screen.h
--- fvwm/screen.h	2002/10/21 11:10:40	1.136
+++ fvwm/screen.h	2002/10/26 11:15:24
@@ -148,9 +148,13 @@
 		} grad;
 		struct vector_coords
 		{
-			int num;
+		        int num;
 			signed char *x;
 			signed char *y;
+		        /* added offsets for vector coords
+			   [email-masked] */
+		        signed char *xoff;
+		        signed char *yoff;
 			signed char *c;
 			unsigned use_fgbg : 1;
 		} vector;