[vox-tech] Text Scroller in Xlib---

Sharad Bajaj vox-tech@lists.lugod.org
Wed, 26 Nov 2003 16:57:42 -0800 (PST)


--0-35707318-1069894662=:39334
Content-Type: text/plain; charset=us-ascii

I vaguely remember the thread about that.  I don't recall if there
was any consensus or solution, though.
Out of curiosity, are you planning to use plain Xlib, or are you going 
to
(or willing to) use a toolkit on top of it, like GTK+ or Qt?
I've done Xlib, long ago, but didn't do anything very fancy with text.
I usually stuck with fixed-width (non-proportional) fonts, and used 
them
for status displays in games. :^)
Either way, though, the way _I_ would do it would be to, in my main 
loop,
have something that acts as a timer.  Every 30th of a second (or 20th, 
50th,
60th, whatever...), increment a "position" variable, and use that to
determine what part of my text string to display, and where.
For something like a stock market ticker, or news crawl, it shouldn't 
be
to hard to get something that, over time, looks like this:
      HELLO THIS IS MY 
     HELLO THIS IS MY S
    HELLO THIS IS MY SC
   HELLO THIS IS MY SCR
  HELLO THIS IS MY SCRO
  ELLO THIS IS MY SCROL
  LLO THIS IS MY SCROLL
  LO THIS IS MY SCROLLE
  O THIS IS MY SCROLLER
   THIS IS MY SCROLLER 
  ...

I've seen this done in web pages (especially popular a few years ago, 
was
to make things like these appear in web browser status bars) using 
JavaScript
to update the text.
One problem with this is that most of the time they used proportional 
fonts,
so the text would move jerkily.  Consider if you had the string:
  IIWWIWIWIWWIWIWIIWWIWWIIW
with an 'Arial'-style font.  When a "W" disappeared off the left edge, 
the
string would move many more pixels to the left than if an "I" had 
disappeared
(since the "W" is, say, 12 pixels wide, while the "I" is only 2 
pixels!)

So I would do a combination of moving within the string, to determine 
what
portion to display in the window, along with fine-scrolling by changing
the pixel position of the string.
I hope that makes some sense. ;)
Good luck!
-bill!
(who has mostly moved on from straight X-lib)
bill@newbreedsoftware.com                           Got kids?  Get Tux 
Paint! 
http://newbreedsoftware.com/bill/       
http://newbreedsoftware.com/tuxpaint/

--__--__--
Hello Sir,
                           I was looking for help regrading Xlib for some graphics as I have two window i want to play movie in one window and in another window i want to scroll some image and text,For that purpose i gone thru so many documents so find problems

(1) How Blitting is possible in Xlib as when we make windows we specify same GC and whenever we will update gc it will update all display.

(2) How can we scroll text or Image flicker free in Xlib.

I am Looking for positive help from you side I hope u will help me I am giving you the code by which i am making windows.
Thanks and Regards
Linux---Worker
=========================================
void Init_X11()
{
XPixmapFormatValues *pf;
 int argc=1;
 int n;
 char * argv[2]={"swfplay",NULL};
 XSetWindowAttributes attr;
 unsigned long mask;
 XInitThreads();
 XtToolkitThreadInitialize();
 XtToolkitInitialize ();
 context = XtCreateApplicationContext();
 dpy = XtOpenDisplay (context,
  getenv("PLAYDPY")?getenv("PLAYDPY"):getenv("DISPLAY"),
   "ScrollPlay", "ScrollPlay", 0,0,
   &argc, argv);
 if (dpy == 0) {
  fprintf(stderr,"Can't open X display\n");
  system("reboot");
  exit(1);
 }
 if(!XShmQueryExtension(dpy)){
  fprintf(stderr,"No SHM extension found");
 }
 scr = DefaultScreenOfDisplay(dpy);
 screen = XScreenNumberOfScreen(scr);
 gc = DefaultGC(dpy, DefaultScreen(dpy));
 attr.bit_gravity = NorthWestGravity;
 attr.event_mask =
//  ButtonMotionMask |
//  ButtonPressMask |
//  ButtonReleaseMask |
  EnterWindowMask |
  ExposureMask |
//  KeyPressMask |
//  KeyReleaseMask |
//  LeaveWindowMask |
//  PointerMotionMask |
  StructureNotifyMask |
  VisibilityChangeMask |
  FocusChangeMask;
 mask = CWBitGravity | CWEventMask | CWBorderPixel | CWBackPixel;
 if (on_root) {
  //frame = VirtualRootWindowOfScreen(screen);
  Window root = RootWindow(dpy, DefaultScreen(dpy));
      XGetWindowAttributes(dpy, root, &wattr);
  width = 1020; /* wattr.width */
  height = 1000;/* wattr.height; */
  dprintf("use root window\n");
 }
 frame = XCreateSimpleWindow
  (dpy, RootWindow(dpy, screen),
   0, 0, 1020, 680, 0,
   BlackPixel(dpy,  screen),
   BlackPixel(dpy,  screen));
 
 scrollwin= XCreateSimpleWindow
  (dpy, RootWindow(dpy, screen),
   0,669, 1020,120, 0,
   BlackPixel(dpy,  screen),
   BlackPixel(dpy,  screen));
 dprintf("without root\n");
 XChangeWindowAttributes(dpy,scrollwin,mask,&attr);
 XChangeWindowAttributes(dpy,frame,mask,&attr);
 XMapWindow(dpy,frame);
 XMapWindow(dpy, scrollwin);
 XSetWindowBackground(dpy,scrollwin,GetColor("yellow"));
 XSetWindowBackgroundPixmap(dpy,scrollwin,None);
 XSelectInput(dpy, scrollwin, ExposureMask);
 XSetForeground(dpy, gc,GetColor("red"));
 
 XSetWindowBackground(dpy,frame,BlackPixel(dpy,  screen));
 XSetWindowBackgroundPixmap(dpy,frame,None);
 XSelectInput(dpy, frame, ExposureMask);
 XGetWindowAttributes(dpy, frame, &wattr);
 visual = wattr.visual;
 width = 1020;/*wattr.width;*/
 height = 690;/*wattr.height;*/
 XFlush(dpy);
 Widget topLevel  =
  XtAppCreateShell("drawingArea", "SwfPlay",
    topLevelShellWidgetClass, dpy, NULL, 0);
 widget = XtVaCreateWidget("form", compositeWidgetClass, topLevel, NULL);
 n = 0;
 XtSetArg(args[n], XtNheight, height); n++;
 XtSetArg(args[n], XtNwidth,  width);  n++;
 XtSetValues(topLevel, args, n);
 n = 0;
 XtSetArg(args[n], XtNheight, height); n++;
 XtSetArg(args[n], XtNwidth,  width);  n++;
 XtSetValues(widget, args, n);  
 topLevel->core.window = frame;
 XtRegisterDrawable(dpy,frame,topLevel);
 XtRealizeWidget(widget);
 XtRealizeWidget(topLevel);
 window = XtWindow(widget);
 XSetWindowBackground(dpy,window,BlackPixel(dpy,  screen));
 XSetWindowBackgroundPixmap(dpy,window,None);
 XtManageChild(widget);
 XFlush(dpy);
 //Pixmap pixmap=XCreatePixmap(dpy,frame,1,1,1);
 //static XColor black;
 //Cursor cursor=XCreatePixmapCursor(dpy,pixmap,pixmap,&black,&black,0,0);
 //Cursor dot=XCreateFontCursor(dpy,XC_man);
 XDefineCursor(dpy,window,None);
 XDefineCursor(dpy,frame,None);
 XWarpPointer(dpy,window,window,0,0,0,0,width,height);
 //XUnmapSubwindows(dpy,frame);
 playerWindow.window = (void*) window;
 playerWindow.x=0;
 playerWindow.y=0;
 playerWindow.width=width;          /* Maximum window size */
 playerWindow.height=690;
 playerWindow.clipRect.top =10;
 playerWindow.clipRect.left=10;
 playerWindow.clipRect.right=width;
 playerWindow.clipRect.bottom= 690;
 playerWindow.ws_info=&ws_info;
 ws_info.type=0;
 ws_info.display=dpy;
 ws_info.visual=visual;
 ws_info.colormap=DefaultColormap(dpy,screen);
 ws_info.depth=DefaultDepth(dpy,screen);
 font=XLoadFont(dpy,USE_FONT);
 XSetFont(dpy,gc,font);
 XUnmapSubwindows(dpy,frame); 
}



---------------------------------
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
--0-35707318-1069894662=:39334
Content-Type: text/html; charset=us-ascii

<DIV>I vaguely remember the thread about that.&nbsp; I don't recall if there<BR>was any consensus or solution, though.</DIV>
<DIV>Out of curiosity, are you planning to use plain Xlib, or are you going <BR>to<BR>(or willing to) use a toolkit on top of it, like GTK+ or Qt?</DIV>
<DIV>I've done Xlib, long ago, but didn't do anything very fancy with text.<BR>I usually stuck with fixed-width (non-proportional) fonts, and used <BR>them<BR>for status displays in games. :^)</DIV>
<DIV>Either way, though, the way _I_ would do it would be to, in my main <BR>loop,<BR>have something that acts as a timer.&nbsp; Every 30th of a second (or 20th, <BR>50th,<BR>60th, whatever...), increment a "position" variable, and use that to<BR>determine what part of my text string to display, and where.</DIV>
<DIV>For something like a stock market ticker, or news crawl, it shouldn't <BR>be<BR>to hard to get something that, over time, looks like this:</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HELLO THIS IS MY <BR>&nbsp;&nbsp;&nbsp;&nbsp; HELLO THIS IS MY S<BR>&nbsp;&nbsp;&nbsp; HELLO THIS IS MY SC<BR>&nbsp;&nbsp; HELLO THIS IS MY SCR<BR>&nbsp; HELLO THIS IS MY SCRO<BR>&nbsp; ELLO THIS IS MY SCROL<BR>&nbsp; LLO THIS IS MY SCROLL<BR>&nbsp; LO THIS IS MY SCROLLE<BR>&nbsp; O THIS IS MY SCROLLER<BR>&nbsp;&nbsp; THIS IS MY SCROLLER <BR>&nbsp; ...</DIV>
<DIV><BR>I've seen this done in web pages (especially popular a few years ago, <BR>was<BR>to make things like these appear in web browser status bars) using <BR>JavaScript<BR>to update the text.</DIV>
<DIV>One problem with this is that most of the time they used proportional <BR>fonts,<BR>so the text would move jerkily.&nbsp; Consider if you had the string:</DIV>
<DIV>&nbsp; IIWWIWIWIWWIWIWIIWWIWWIIW</DIV>
<DIV>with an 'Arial'-style font.&nbsp; When a "W" disappeared off the left edge, <BR>the<BR>string would move many more pixels to the left than if an "I" had <BR>disappeared<BR>(since the "W" is, say, 12 pixels wide, while the "I" is only 2 <BR>pixels!)</DIV>
<DIV><BR>So I would do a combination of moving within the string, to determine <BR>what<BR>portion to display in the window, along with fine-scrolling by changing<BR>the pixel position of the string.</DIV>
<DIV>I hope that makes some sense. ;)</DIV>
<DIV>Good luck!</DIV>
<DIV>-bill!<BR>(who has mostly moved on from straight X-lib)<BR><A href="mailto:bill@newbreedsoftware.com">bill@newbreedsoftware.com</A>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Got kids?&nbsp; Get Tux <BR>Paint! <BR><A href="http://newbreedsoftware.com/bill/">http://newbreedsoftware.com/bill/</A>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR><A href="http://newbreedsoftware.com/tuxpaint/">http://newbreedsoftware.com/tuxpaint/</A></DIV>
<DIV><BR>--__--__--</DIV>
<DIV>Hello Sir,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I was looking for help regrading Xlib for some graphics as I have two window i want to play movie in one window and in another window i want to scroll some image and text,For that purpose i gone thru so many documents so find problems</DIV>
<DIV><BR>(1) How Blitting is possible in Xlib as when we make windows we specify same GC and whenever we will update gc it will update all display.</DIV>
<DIV><BR>(2) How can we scroll text or Image flicker free in Xlib.</DIV>
<DIV><BR>I am Looking for positive help from you side I hope u will help me I am giving you the code by which i am making windows.<BR>Thanks and Regards<BR>Linux---Worker<BR>=========================================<BR>void Init_X11()<BR>{<BR>XPixmapFormatValues *pf;<BR>&nbsp;int argc=1;<BR>&nbsp;int n;<BR>&nbsp;char * argv[2]={"swfplay",NULL};<BR>&nbsp;XSetWindowAttributes attr;<BR>&nbsp;unsigned long mask;<BR>&nbsp;XInitThreads();<BR>&nbsp;XtToolkitThreadInitialize();<BR>&nbsp;XtToolkitInitialize ();<BR>&nbsp;context = XtCreateApplicationContext();<BR>&nbsp;dpy = XtOpenDisplay (context,<BR>&nbsp; getenv("PLAYDPY")?getenv("PLAYDPY"):getenv("DISPLAY"),<BR>&nbsp;&nbsp; "ScrollPlay", "ScrollPlay", 0,0,<BR>&nbsp;&nbsp; &amp;argc, argv);<BR>&nbsp;if (dpy == 0) {<BR>&nbsp; fprintf(stderr,"Can't open X display\n");<BR>&nbsp; system("reboot");<BR>&nbsp; exit(1);<BR>&nbsp;}<BR>&nbsp;if(!XShmQueryExtension(dpy)){<BR>&nbsp; fprintf(stderr,"No SHM extension found");<BR>&nbsp;}<BR>&nbsp;
 scr =
 DefaultScreenOfDisplay(dpy);<BR>&nbsp;screen = XScreenNumberOfScreen(scr);<BR>&nbsp;gc = DefaultGC(dpy, DefaultScreen(dpy));<BR>&nbsp;attr.bit_gravity = NorthWestGravity;<BR>&nbsp;attr.event_mask =<BR>//&nbsp; ButtonMotionMask |<BR>//&nbsp; ButtonPressMask |<BR>//&nbsp; ButtonReleaseMask |<BR>&nbsp; EnterWindowMask |<BR>&nbsp; ExposureMask |<BR>//&nbsp; KeyPressMask |<BR>//&nbsp; KeyReleaseMask |<BR>//&nbsp; LeaveWindowMask |<BR>//&nbsp; PointerMotionMask |<BR>&nbsp; StructureNotifyMask |<BR>&nbsp; VisibilityChangeMask |<BR>&nbsp; FocusChangeMask;<BR>&nbsp;mask = CWBitGravity | CWEventMask | CWBorderPixel | CWBackPixel;<BR>&nbsp;if (on_root) {<BR>&nbsp; //frame = VirtualRootWindowOfScreen(screen);<BR>&nbsp; Window root = RootWindow(dpy, DefaultScreen(dpy));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; XGetWindowAttributes(dpy, root, &amp;wattr);<BR>&nbsp; width = 1020; /* wattr.width */<BR>&nbsp; height = 1000;/* wattr.height; */<BR>&nbsp; dprintf("use root
 window\n");<BR>&nbsp;}<BR>&nbsp;frame = XCreateSimpleWindow<BR>&nbsp; (dpy, RootWindow(dpy, screen),<BR>&nbsp;&nbsp; 0, 0, 1020, 680, 0,<BR>&nbsp;&nbsp; BlackPixel(dpy,&nbsp; screen),<BR>&nbsp;&nbsp; BlackPixel(dpy,&nbsp; screen));<BR>&nbsp;<BR>&nbsp;scrollwin= XCreateSimpleWindow<BR>&nbsp; (dpy, RootWindow(dpy, screen),<BR>&nbsp;&nbsp; 0,669, 1020,120, 0,<BR>&nbsp;&nbsp; BlackPixel(dpy,&nbsp; screen),<BR>&nbsp;&nbsp; BlackPixel(dpy,&nbsp; screen));<BR>&nbsp;dprintf("without root\n");<BR>&nbsp;XChangeWindowAttributes(dpy,scrollwin,mask,&amp;attr);<BR>&nbsp;XChangeWindowAttributes(dpy,frame,mask,&amp;attr);<BR>&nbsp;XMapWindow(dpy,frame);<BR>&nbsp;XMapWindow(dpy, scrollwin);<BR>&nbsp;XSetWindowBackground(dpy,scrollwin,GetColor("yellow"));<BR>&nbsp;XSetWindowBackgroundPixmap(dpy,scrollwin,None);<BR>&nbsp;XSelectInput(dpy, scrollwin, ExposureMask);<BR>&nbsp;XSetForeground(dpy, gc,GetColor("red"));</DIV>
<DIV>&nbsp;<BR>&nbsp;XSetWindowBackground(dpy,frame,BlackPixel(dpy,&nbsp; screen));<BR>&nbsp;XSetWindowBackgroundPixmap(dpy,frame,None);<BR>&nbsp;XSelectInput(dpy, frame, ExposureMask);<BR>&nbsp;XGetWindowAttributes(dpy, frame, &amp;wattr);<BR>&nbsp;visual = wattr.visual;<BR>&nbsp;width = 1020;/*wattr.width;*/<BR>&nbsp;height = 690;/*wattr.height;*/<BR>&nbsp;XFlush(dpy);<BR>&nbsp;Widget topLevel&nbsp; =<BR>&nbsp; XtAppCreateShell("drawingArea", "SwfPlay",<BR>&nbsp;&nbsp;&nbsp; topLevelShellWidgetClass, dpy, NULL, 0);<BR>&nbsp;widget = XtVaCreateWidget("form", compositeWidgetClass, topLevel, NULL);<BR>&nbsp;n = 0;<BR>&nbsp;XtSetArg(args[n], XtNheight, height); n++;<BR>&nbsp;XtSetArg(args[n], XtNwidth,&nbsp; width);&nbsp; n++;<BR>&nbsp;XtSetValues(topLevel, args, n);<BR>&nbsp;n = 0;<BR>&nbsp;XtSetArg(args[n], XtNheight, height); n++;<BR>&nbsp;XtSetArg(args[n], XtNwidth,&nbsp; width);&nbsp; n++;<BR>&nbsp;XtSetValues(widget, args, n);&nbsp; <BR>&nbsp;topLevel-&gt;core.window =
 frame;<BR>&nbsp;XtRegisterDrawable(dpy,frame,topLevel);<BR>&nbsp;XtRealizeWidget(widget);<BR>&nbsp;XtRealizeWidget(topLevel);<BR>&nbsp;window = XtWindow(widget);<BR>&nbsp;XSetWindowBackground(dpy,window,BlackPixel(dpy,&nbsp; screen));<BR>&nbsp;XSetWindowBackgroundPixmap(dpy,window,None);<BR>&nbsp;XtManageChild(widget);<BR>&nbsp;XFlush(dpy);<BR>&nbsp;//Pixmap pixmap=XCreatePixmap(dpy,frame,1,1,1);<BR>&nbsp;//static XColor black;<BR>&nbsp;//Cursor cursor=XCreatePixmapCursor(dpy,pixmap,pixmap,&amp;black,&amp;black,0,0);<BR>&nbsp;//Cursor dot=XCreateFontCursor(dpy,XC_man);<BR>&nbsp;XDefineCursor(dpy,window,None);<BR>&nbsp;XDefineCursor(dpy,frame,None);<BR>&nbsp;XWarpPointer(dpy,window,window,0,0,0,0,width,height);<BR>&nbsp;//XUnmapSubwindows(dpy,frame);<BR>&nbsp;playerWindow.window = (void*) window;<BR>&nbsp;playerWindow.x=0;<BR>&nbsp;playerWindow.y=0;<BR>&nbsp;playerWindow.width=width;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* Maximum window size
 */<BR>&nbsp;playerWindow.height=690;<BR>&nbsp;playerWindow.clipRect.top =10;<BR>&nbsp;playerWindow.clipRect.left=10;<BR>&nbsp;playerWindow.clipRect.right=width;<BR>&nbsp;playerWindow.clipRect.bottom= 690;<BR>&nbsp;playerWindow.ws_info=&amp;ws_info;<BR>&nbsp;ws_info.type=0;<BR>&nbsp;ws_info.display=dpy;<BR>&nbsp;ws_info.visual=visual;<BR>&nbsp;ws_info.colormap=DefaultColormap(dpy,screen);<BR>&nbsp;ws_info.depth=DefaultDepth(dpy,screen);<BR>&nbsp;font=XLoadFont(dpy,USE_FONT);<BR>&nbsp;XSetFont(dpy,gc,font);<BR>&nbsp;XUnmapSubwindows(dpy,frame); <BR>}<BR></DIV><p><hr SIZE=1>
Do you Yahoo!?<br>
<a href="http://us.rd.yahoo.com/slv/mailtag/*http://companion.yahoo.com/">Free Pop-Up Blocker - Get it now</a>
--0-35707318-1069894662=:39334--