?
Solved

Text flickering when scrolling it.

Posted on 2003-03-13
5
Medium Priority
?
263 Views
Last Modified: 2010-04-15

Hi folks,

I am programming an application where I have to play a video, show some images in slideshow mode and scroll a text. All this has to be running at the same time and with one window for each media. So far I manage to get everything running. I am programming on Linux and using X-Window functions, it is NOT KDE/GNOME... dependent.

My problem comes when scrolling a text. If I scroll it with no other action on the screen, seems to work just fine. However, when I put everything together, after few seconds, it starts flickering or flashing. What I do to scroll the text is, on the text window, print a string starting for the left of the window. After 1ms or so, I clear the window and print the same string again but this time starting one pixel to the right from previous print. This way I get a scrolling effect. The next piece of code may help understanding it a bit better (BTW the text is 'Adobe-New Century Schoolbook-Bold-R-Normal' font type and its size is 24).

I tried doing this in three different ways, here are they:

-Way 1, loop {wait, clear window, print a string}
     
    /* Find out the width of the text */
    movUntil = -XTextWidth(font, myStringItem->chars, myStringItem->nchars);
   
    /* Start printing from the right side of the window */
    textPos = TS_WIDTH;
   
    nitems = 1;
    while(1){
      /* Wait for timeout */
      sigwait(&wait_for,&signal);
     
      XClearWindow(display,window[TEXT]);
     /* Print the string on x=textPos, y=(2/3*window_height) */
      XDrawText(display, window[TEXT], myGC, textPos, (2*TS_HEIGHT/3), myStringItem, nitems);
     
      /* Next time put the text one pixel more to the left */
      textPos --;
     
      /* If the text is out of the window start printing it from the right
       * side of the window */
      if (textPos == movUntil){
      textPos = TS_WIDTH;
      }
    }
   
-Way 2, loop {wait, print a string}
     
    /* Find out the width of the text */
    movUntil = -XTextWidth(font, myStringItem->chars, myStringItem->nchars);
   
    /* Start printing from the right side of the window */
    textPos = TS_WIDTH;
   
    while(1){
      /* Wait for timeout */
      sigwait(&wait_for,&signal);
     
      /* Print an orange colored string with black background */
      XDrawImageString(display, window[TEXT], myGC, textPos, (2*TS_HEIGHT/3), myStringItem->chars,\
       myStringItem->nchars);
     
      /* Next time put the text one pixel more to the left */
      textPos --;
     
      /* If the text is out of the window start printing it from the right
       * side of the window */
      if (textPos == movUntil){
      textPos = TS_WIDTH;
      }
    }
   
-Way 3, loop {wait, print black string, print non-black string}
     
    /* Find out the width of the text */
    movUntil = -XTextWidth(font, myStringItem->chars, myStringItem->nchars);
   
    /* Start printing from the right side of the window */
    textPos = TS_WIDTH;
   
    nitems = 1;
    while(1){
      /* Wait for timeout */
      sigwait(&wait_for,&signal);
     
      /* Print black colored string over previous string */
      XDrawText(display, window[TEXT], myGC2, textPos+1, (2*TS_HEIGHT/3), myStringItem, nitems);
      /* Print orange colored string */
      XDrawText(display, window[TEXT], myGC, textPos, (2*TS_HEIGHT/3), myStringItem, nitems);
     
      /* Next time put the text one pixel more to the left */
      textPos --;
     
      /* If the text is out of the window start printing it from the right
       * side of the window */
      if (textPos == movUntil){
      textPos = TS_WIDTH;
      }
    }
   
NOTE1: myStringItem is a pointer to XTextItem. myStringItem->chars is the text to be printed whereas
       myStringItem->nchars is the number of characteres of the text.

The effect is the same no matter which approach I choose. I would really appreciate any help. Thanks a lot.

Cheers,

Asier
0
Comment
Question by:Asier
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 1

Expert Comment

by:MartinGreen
ID: 8142701
I have not programmed for linux myself, but the problem is suffered by us windows programmer too. The solution we often use (and I think itmay help you) is that instead of drawing to the screen, we draw to a device context (that mimics the screen) then take a bitmap copy of that area and paste it onto the screen area (Much much quicker to perform than drawing to the screen). This has ALWAYS stopped any flickering problems I have had.

The crux of the solution is perform all lengthy draw operations somewhere that isn't displayed.

Once you have rendered what you want to draw, make a bitmap (or similar) copy of it and blat that to the screen in a single operation.

I hope this is of some use to you. I'm sure a linuc programmer out there can translate this windowsy idea into the linux equivalent.

Regards

Martin Green
0
 

Author Comment

by:Asier
ID: 8152941
Hi Martin,

First of all thank you for your answer. I know that the main problem of the flickering is created by the drawing calls/functions.

About your answer, I don't undesrtand what you mean with "draw to a device context". I have not problems with the rest, making a bitmap copy of it, and pasting it into the screen area where I want to display.

Just another question more, when you say "...perform all lengthy draw operations somewhere that isn't displayed" do you mean to display it out of the "visual screen"?

I'll try it as soon as I finish the actual part of the project and I'll let you know.

Thank you,

Asier
0
 
LVL 1

Accepted Solution

by:
MartinGreen earned 200 total points
ID: 8157051
I there Asier,

Sorry about the device context confusion. It as a windows phenomena!! Basically it is a handle to a device on which you are drawing. You can create a device contect compatable with the display (but not actually the display) and draw to that in windows and when all drawing to it is done, take a bitmap copy of the contents of the device context and put it into the device context for the real display itself. I am hoping there is a similar sort of thing in you linux environment. If not then you may have to draw to an invisible area of the display (off screen) and then make a bitmap and copy to a visible area (less elegant I grant you!)

Anyway, let me know how you get on.

Regards

Martin Green
0
 
LVL 20

Expert Comment

by:jmcg
ID: 10131589
Nothing has happened on this question in more than 9 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
accept answer by MartinGreen.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question