[comp.windows.x] XDrawLine event driven ?

bradd@csd.uwo.ca (krusty the klown) (03/04/91)

Thanks to all those who helped me out with XDrawLine.
I've managed to get real nifty looking lines on my screen, but there
is just one problem:

Whenever a window appears over the lines and disappears, or the
application is iconified, the lines (or portions of) disappear.
I suppose this is because the lines from XDrawLine are not
event driven (ie: no auto refresh).

For a solution, I attempted to figure out when an event such as
realizing a window or window movement occurs, but, unfortunately
I could not find/understand the required info from the Xt Intrinsic
or Xlib manuals.

Is this the best solution to this problem?  What is the proper way
to check for the required events, and how should I go about
keeping those cool looking lines on my screen?
Any help appreciated.
BTW, I'm using the Athena widgets (but that shouldn't matter, should it?)

Thanks.

-- 

Patrick Bradd                                        bradd@csd.uwo.ca
The University of Western Ontario
Department of Computer Science

Signature? What signature?  I don't have enough damn time to sleep.

mouse@lightning.mcrcim.mcgill.EDU (der Mouse) (03/04/91)

> I've managed to get real nifty looking lines on my screen, but there
> is just one problem:

> Whenever a window appears over the lines and disappears, or the
> application is iconified, the lines (or portions of) disappear.  I
> suppose this is because the lines from XDrawLine are not event driven
> (ie: no auto refresh).

Quite right.  This is what Expose events are all about: if your
application is one where window damage matters, you have to be prepared
to redraw arbitrary pieces of your window.

To get Expose events on a window, set ExposureMask in the window's
input-mask at creation time, or use XSelectInput.  Each Expose event
indicates a rectangle that needs repairing; it is up to your code to do
whatever is necessary to arrange this.

> BTW, I'm using the Athena widgets (but that shouldn't matter, should
> it?)

I don't know.  The above is written from an Xlib perspective; what it
amounts to in toolkit or widget terms someone else will have to
explain.

					der Mouse

			old: mcgill-vision!mouse
			new: mouse@larry.mcrcim.mcgill.edu

cjmchale@cs.tcd.ie (Ciaran McHale) (03/04/91)

In <1991Mar3.231115@csd.uwo.ca> bradd@csd.uwo.ca (krusty the klown) writes:

>Whenever a window appears over the lines and disappears, or the
>application is iconified, the lines (or portions of) disappear.
>I suppose this is because the lines from XDrawLine are not
>event driven (ie: no auto refresh).

An application is responsible for redrawing (parts of) any
of its windows which have become obscured and then re-exposed.
What you should do is look out for Expose events and then
redraw the window's contents. The Expose event data
structure contains information to tell you which portion of
the window you need to redraw so you only have to redraw
the necessary section.

Oliver Jones' book on Xlib programming has some good
examples and advice on how to handle Expose events. It might
be of some use. From the monthly X bibliography popting...

Jones, Oliver, Introduction to the X Window System, Prentice-Hall, 1988,
     1989.  ISBN 0-13-499997-5. An excellent introduction to programming
     with Xlib.  Written with the programmer in mind, this book includes
     many practical tips that are not found anywhere else. This book is not
     as broad as the O'Reilly Xlib tutorial and doesn't offer as many exam-
     ples as the Johnson & Reichard book, but Jones is probably the most
     experienced X programmer of this group and this shows in the quality
     and depth of the material in the book. Originally written for X11R1,
     recent printings have included corrections and additions.  The sixth
     printing should have X11R4 material.


Ciaran.
-- 
Ciaran McHale		"Verbosity says it all"			      ____
Department of Computer Science, Trinity College, Dublin 2, Ireland.   \  /
Telephone: +353-1-772941 ext 1538	FAX: +353-1-772204	       \/
Telex: 93782 TCD EI			email: cjmchale@cs.tcd.ie

morten@modulex.dk (Morten Hastrup) (03/04/91)

bradd@csd.uwo.ca (krusty the klown) writes:

>Thanks to all those who helped me out with XDrawLine.
>I've managed to get real nifty looking lines on my screen, but there
>is just one problem:

>Whenever a window appears over the lines and disappears, or the
>application is iconified, the lines (or portions of) disappear.
>I suppose this is because the lines from XDrawLine are not
>event driven (ie: no auto refresh).
Yes, You are right.

>For a solution, I attempted to figure out when an event such as
>realizing a window or window movement occurs, but, unfortunately
>I could not find/understand the required info from the Xt Intrinsic
>or Xlib manuals.
What you wanted to find is: Expose events! This type of event is occure
whenever a window or an region of a window is exposed. That is your
application (widget) should re-draw on such events.

>Is this the best solution to this problem?  What is the proper way
>to check for the required events, and how should I go about
>keeping those cool looking lines on my screen?
This IS the way of doing it under X (Done exactly this way in widgets,
Motif as well as Athena).

You could do this in at least two ways.
1. Add an event handler to the expose event of you widnow (widget).
   Ie. XtAddEventHandler().
2. Or, add an action/translation procedure to you widget.

I prefer the last one - I think is more clear and I'm doing it
this ways when I'm writing new widgets.

Morten

-----------------------------------------------------
Morten Hastrup		| Email:    morten@modulex.dk
A/S MODULEX		| Phone:    +45 44 53 30 11
Lyskaer 15		| Telefax:  +45 44 53 30 74
DK-2730 Herlev		|
Denmark			|