[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[mgp-users 01122] Re: New feature proposal: Scrolling text?



Il 09:58, lunedì 10 marzo 2003, scrivesti:
> How about using %lcutin or %rcutin?
> I know they're not "nice", but might help you to some extent.
Hello all.
I have made few changes to the mgp cvs sources, to add the command 
%xscrolltext to permit to a long sentence to be scrolled from right to left:
The patch below is only a demostrative code, which must be improved, but it 
seems to work.
Try this source:
%page
%nodefault
%size 5, tfont "times"
%fore "red", back "white"

%size 90, xscrolltext
%% follow two lines... one that may be splitted by the mail user agent, and
%% the 2nd line containing "Text finished!"
This is a very very very long sentence, with many many words that do NOT fill 
in the screen entirely, but it can be scrolled horizzontally from right to 
left side.
Text finished!


Below, the patch that should be applied to the CVS sources to obtain this: 
note that i do not know Xlib well, so there can be better solution to mine to 
obtain text scrolling around the screen.
Also, i suppose that "size" variable, in xscrolltext() function in draw.c, 
must be increased/decreased to obtain higher/lower speed. Probably the 
correct way to achieve this is to add a %xscrollspeed command.
Also, i think that another command that should be added is %nextpage which 
tell mgp to start drawing the next page, instead of waiting for space or 
button or cursor key to be pressed. At the last page, it can be used to 
terminate presentation (close window and exit).
Finally, another command like %usleep or %msleep may be added to set a delay 
between line drawings, or between jumping to the next page (using the 
%nextpage command).

Please let me know if my work can be useful for mgp, so i should improve it 
and send someone (who?) a better patch.
Best regards.   Paolo
-----


diff -Naur kit/.cvsignore devel/.cvsignore
--- kit/.cvsignore	Thu Dec 17 05:37:40 1998
+++ devel/.cvsignore	Thu Jan  1 01:00:00 1970
@@ -1,20 +0,0 @@
-config.log
-config.cache
-configure.scan
-Imakefile
-config.status
-Makefile
-tp
-ctlwords.h
-tp2ps
-mgp
-mgp2ps
-mgp.0
-mgp2ps.0
-mgpembed.0
-grammar.c
-tokdefs.h
-scanner.c
-mgpembed.pl
-.depend
-ctlwords
diff -Naur kit/draw.c devel/draw.c
--- kit/draw.c	Tue Mar  4 21:00:52 2003
+++ devel/draw.c	Wed Mar 12 22:29:27 2003
@@ -70,6 +70,7 @@
 static void draw_line_output __P((struct render_state *, char *));
 static void draw_line_end __P((struct render_state *));
 static void cutin __P((struct render_state *, int, int, int));
+static void xscrolltext __P((struct render_state *, int, int, int));	
//psubiaco
 #if 0
 static void shrink __P((char *, u_int));
 #endif
@@ -632,6 +633,11 @@
 		state->special = SP_RCUTIN;
 		break;
 
+	case CTL_XSCROLLTEXT:
+		CHECK_CACHE
+		state->special = SP_XSCROLLTEXT;
+		break;
+
 	case CTL_SHRINK:
 		CHECK_CACHE
 		state->special = SP_SHRINK;
@@ -925,6 +931,9 @@
 	case SP_RCUTIN:
 		cutin(state, xpos, state->ypos, -1);
 		break;
+	case SP_XSCROLLTEXT:
+		xscrolltext(state, xpos, state->ypos, -1);
+		return;
 	default:
 		break;
 	}
@@ -1005,46 +1014,74 @@
 	state->yoff = yoff;	
 }
 
-#if 0
 static void
-shrink(data, page)
-	char *data;
-	u_int page;
+xscrolltext(state, lx, ly, dir)	/* psubiaco: Scroll long text horizzontally 
*/
+	struct render_state *state;
+	int lx;
+	int ly;
+	int dir;
 {
-	u_int min_csize = char_size;
-	u_int max_csize = state->height / 4;
-	u_int csize, i, x;
-	u_int step = (max_csize - min_csize) / 3;
+	u_int step, x, xoff, yoff;
+	int i;
+	int sx;
+	int round;
+	Window cutinWin;
+	Pixmap scrollTextPixmap;
+  static GC gc;
+												
 
-	if (!step)
-		step = 1;
+	if (state->repaint)
+		return;
 
-	if (state->align != AL_CENTER) {
-		fprintf(stderr, "align is not center: \n");
+	if (!state->linewidth)
 		return;
+	cutinWin = XCreateSimpleWindow(display, state->target,
+		state->xoff, ly, state->width, state->maxascent + state->maxdescent,
+		0, fore_color[caching], back_color[caching]);
+	XSetWindowBackgroundPixmap(display, cutinWin, None);
+	XMapSubwindows(display, state->target);
+	// GC is needed by XCopyArea()
+	gc=XCreateGC(display, state->target, 0, 0);
+	xoff = state->xoff;	
+	yoff = state->yoff;	
+	state->xoff = state->yoff = 0;
+	// create a pixmap object within the text
+	scrollTextPixmap=XCreatePixmap(display, state->target, state->linewidth, 
+		state->maxascent+state->maxdescent, depth);
+	XSetForeground(display,gc,back_color[caching]);
+	XFillRectangle(display, scrollTextPixmap, gc, 0, 0, state->linewidth,
+		state->maxascent+state->maxdescent);
+
+	
+	if (state->obj) {
+		obj_draw(state, scrollTextPixmap, 0, 0);
 	}
 
-	csize = char_size;
-	for (i = max_csize; i > min_csize; i -= step) {
-		char_size = i;
-		draw_string(state, data);
-		x = (state->width - state->linewidth) / 2;
-		XCopyArea(display, maskpix, state->target, gc,
-			0, 0, state->linewidth, char_size, x, state->ypos);
-		XCopyArea(display, pixmap, state->target, gcor,
-			0, 0, state->linewidth, char_size, x, state->ypos);
+	step=5;	// Increment
+	for (x=(state->width/step)*step;x>0;x-=step) {
+		XCopyArea(display, scrollTextPixmap, cutinWin, gc, 
+			0, 0, state->width-x, state->maxascent+state->maxdescent, x, 0);
 		XFlush(display);
-		usleep(SHRINK_DELAY);
-		XFillRectangle(display, pixmap, gcall,
-			0, 0, state->width, char_size);
-		XFillRectangle(display, maskpix, gcall,
-			0, 0, state->width, char_size);
-		XClearArea(display, state->target, x, state->ypos,
-			state->linewidth, char_size, 0);
+		usleep(10000);
 	}
-	char_size = csize;
+  for (x=0;x<state->linewidth;x+=step) {
+	  XCopyArea(display, scrollTextPixmap, cutinWin, gc,
+	    x, 0, 
x+state->width>state->linewidth?state->linewidth:state->linewidth, 
state->maxascent+state->maxdescent, 0, 0);
+		if (state->linewidth-x < state->width) {
+			// draw a filled rectangle at the end of the scrolling text
+			XFillRectangle(display,cutinWin,gc,state->linewidth-x,0,
+				state->width,state->maxascent+state->maxdescent);
+		}
+	  XFlush(display);
+	  usleep(10000);
+	}
+	
+	XDestroyWindow(display, cutinWin);
+	XFreePixmap(display,scrollTextPixmap);
+	state->xoff = xoff;	
+	state->yoff = yoff;	
 }
-#endif
+
 
 /*
  * render characters.
@@ -1336,17 +1373,21 @@
 
 		state->linewidth += HORIZ_STEP(char_size[caching], char_len);
 		/* ukai */
-		if (!charset16 && state->linewidth + HORIZ_STEP(char_size[caching], 
-				char_len) > state->width) {
-			if (len >= 20) break; /* too long word */
-			for (i = 0; i < len; i ++){
-				if (isspace(*(p +i))) break;	
+		if ( state->special!=SP_XSCROLLTEXT ) {
+			/* Split long lines */
+			fprintf(stderr,"Split line\n");
+			if (!charset16 && state->linewidth + HORIZ_STEP(char_size[caching], 
+					char_len) > state->width) {
+				if (len >= 20) break; /* too long word */
+				for (i = 0; i < len; i ++){
+					if (isspace(*(p +i))) break;	
+				}
+				if (i == len) break;
 			}
-			if (i == len) break;
 		}
 	}
 
-	if (state->width - state->leftfillpos / 2 < state->linewidth
+	if (state->special!=SP_XSCROLLTEXT && (state->width - state->leftfillpos / 
2 < state->linewidth)
 #if 0
 	 && state->align == AL_LEFTFILL1
 #endif
@@ -1896,9 +1937,13 @@
 	 *	state->ypos	absolute y position in main window.
 	 */
 	xpos += state->tabxprefix ? state->tabxprefix : state->xprefix;
-	width = (state->linewidth <= state->width - xpos)
+	if (state->special!=SP_XSCROLLTEXT) { //psubiaco
+		width = (state->linewidth <= state->width - xpos)
 			? state->linewidth
 			: state->width - xpos;
+	} else {	// psubiaco
+		width=state->linewidth-xpos; //psubiaco
+	}
 	height = state->maxascent + state->maxdescent + 1;
 	xpos += state->xoff;
 	ypos += state->yoff;
diff -Naur kit/globals.c devel/globals.c
--- kit/globals.c	Mon Sep 17 16:48:30 2001
+++ devel/globals.c	Mon Mar 10 19:18:17 2003
@@ -103,6 +103,7 @@
 /*CTL*/	{ CTL_SHRINK,		T_VOID,	"shrink", 6 },
 /*CTL*/	{ CTL_LCUTIN,		T_VOID,	"lcutin", 6 },
 /*CTL*/	{ CTL_RCUTIN,		T_VOID,	"rcutin", 6 },
+/*CTL*/	{ CTL_XSCROLLTEXT,		T_VOID,	"xscrolltext", 11 },
 /*CTL*/	{ CTL_CONT,		T_VOID,	"cont", 4 },
 /*CTL*/	{ CTL_NODEF,		T_VOID,	"nodefault", 9 },
 /*CTL*/	{ CTL_XFONT,		T_STR,	"xfont", 5 },
diff -Naur kit/grammar.y devel/grammar.y
--- kit/grammar.y	Mon Sep 17 16:48:30 2001
+++ devel/grammar.y	Mon Mar 10 19:15:01 2003
@@ -731,7 +731,7 @@
 %token KW_LINESTART KW_LINEEND KW_MARK KW_SYSTEM KW_FILTER KW_ENDFILTER
 %token KW_QUALITY KW_ICON KW_LEFTFILL KW_XSYSTEM KW_VFCAP KW_TFONT KW_TFDIR
 %token KW_DEFFONT KW_FONT KW_TFONT0 KW_EMBED KW_ENDEMBED KW_NEWIMAGE
-%token KW_CHARSET KW_TMFONT KW_PCACHE KW_TMFONT0 KW_ANIM KW_VALIGN KW_AREA
+%token KW_CHARSET KW_TMFONT KW_PCACHE KW_TMFONT0 KW_ANIM KW_VALIGN KW_AREA 
KW_XSCROLLTEXT
 
 %type <ct> toplevel
 %type <ct> line defaultline tabline shellline deffontline
@@ -977,6 +977,7 @@
 	| KW_CHARSET STR	{ $$ = gen_str(CTL_CHARSET, $2); }
 	| KW_AREA NUM NUM { $$ = gen_area($2, $3, -1, -1); }
 	| KW_AREA NUM NUM NUM NUM { $$ = gen_area($2, $3, $4, $5); }
+	| KW_XSCROLLTEXT	{ $$ = gen_void(CTL_XSCROLLTEXT); }
 	| KW_PCACHE NUM NUM NUM NUM
 			{ $$ = gen_pcache($2, $3, $4, $5); }
 	| KW_PCACHE NUM
diff -Naur kit/mgp.h devel/mgp.h
--- kit/mgp.h	Mon Feb 17 06:25:22 2003
+++ devel/mgp.h	Mon Mar 10 17:24:39 2003
@@ -147,6 +147,7 @@
 #define SP_SHRINK	1
 #define SP_LCUTIN	2
 #define SP_RCUTIN	3
+#define SP_XSCROLLTEXT 65
 
 #define AL_LEFT		0
 #define AL_CENTER	1
diff -Naur kit/scanner.l devel/scanner.l
--- kit/scanner.l	Sat Aug 11 10:50:01 2001
+++ devel/scanner.l	Mon Mar 10 17:12:40 2003
@@ -165,6 +165,7 @@
 (ANIM|anim)	return KW_ANIM;
 (VALIGN|valign)	return KW_VALIGN;
 (AREA|area)	return KW_AREA;
+(XSCROLLTEXT|xscrolltext) return KW_XSCROLLTEXT;
 
 [ \n\t]		;
 ","		return COMMA;