[comp.windows.x] porting unstructured graphics code to X

henry@yogi.fhhosp.ab.ca (02/26/91)

I have a pile of code that needs to run under X.  It all uses
graphic primitive calls (lines, dots, crosses) that are PLOT-10 like.

I'm unenthused about doing a lot of code rewrites to bundle graphics
code into repaint procedures.

Is there any easy way to port the code so that I can just draw into
a window, and *not* have to worry about redrawing from Expose events?

Thanks,
-Henry Bland

mouse@lightning.mcrcim.mcgill.EDU (02/26/91)

> I have a pile of code that needs to run under X.  It all uses graphic
> primitive calls (lines, dots, crosses) that are PLOT-10 like.

> I'm unenthused about doing a lot of code rewrites to bundle graphics
> code into repaint procedures.

> Is there any easy way to port the code so that I can just draw into a
> window, and *not* have to worry about redrawing from Expose events?

Technically no, but close enough.  You draw into both a pixmap and a
window, and handle Expose events with XCopyArea() from the pixmap to
the window.

Of course, this carries a price: the pixmap (and a relatively slight
speed penalty).  On some servers, pixmaps of reasonable size are more
or less free; on others, even fairly small ones are precious.  You pays
yer money and you takes yer choice....

					der Mouse

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

klee@wsl.dec.com (Ken Lee) (02/27/91)

In article <1991Feb25.212501.1776@yogi.fhhosp.ab.ca>, henry@yogi.fhhosp.ab.ca writes:
|> Is there any easy way to port the code so that I can just draw into
|> a window, and *not* have to worry about redrawing from Expose events?

Try using the X Toolkit, with the graphics encapsulated in a widget.
The X Toolkit will manage your expose events for you.

-- 
Ken Lee
DEC Western Software Laboratory, Palo Alto, Calif.
Internet: klee@wsl.dec.com
uucp: uunet!decwrl!klee

tp@mccall.com (Terry Poot) (02/27/91)

In article <1991Feb26.092358@wsl.dec.com>, klee@wsl.dec.com (Ken Lee) writes:
>In article <1991Feb25.212501.1776@yogi.fhhosp.ab.ca>,
>henry@yogi.fhhosp.ab.ca writes:
>|> Is there any easy way to port the code so that I can just draw into
>|> a window, and *not* have to worry about redrawing from Expose
>events?
>
>Try using the X Toolkit, with the graphics encapsulated in a widget.
>The X Toolkit will manage your expose events for you.

Of course, you'd still have to write that widget. The other thing you could 
consider is using a higher level graphics package that will manage those low
level considerations for you. Examples would be GKS and PHIGS. 
--
Terry Poot <tp@mccall.com>                   The McCall Pattern Company
(uucp: ...!rutgers!ksuvax1!deimos!mccall!tp) 615 McCall Road
(800)255-2762, in KS (913)776-4041           Manhattan, KS 66502, USA

sundar@ai.mit.edu (Sundar Narasimhan) (02/28/91)

In article <1991Feb27.073653@mccall.com>, tp@mccall.com (Terry Poot) writes:
|> In article <1991Feb26.092358@wsl.dec.com>, klee@wsl.dec.com (Ken Lee) writes:
|> >In article <1991Feb25.212501.1776@yogi.fhhosp.ab.ca>,
|> >henry@yogi.fhhosp.ab.ca writes:
|> >|> Is there any easy way to port the code so that I can just draw into
|> >|> a window, and *not* have to worry about redrawing from Expose
|> >events?
|> >
|> >Try using the X Toolkit, with the graphics encapsulated in a widget.
|> >The X Toolkit will manage your expose events for you.
|> 
|> Of course, you'd still have to write that widget. 
Hmm.. You may want to look at the Display widget found in
trix.ai.mit.edu:/com/ftp/pub/users/sundar/graph.tar.Z. It attempts
to manage Expose events for the programmer and the package has
a simple graph widget built on top of it. The display widget uses 
a list of graphic objects to redraw on each Expose event.

-Sundar

ps. Standard disclaimers.

pps. I do have another set of library functions that manages Expose 
events directly using raw Xlib calls. The idea is to create a pixmap,
and draw on the pixmap as well as on the window during each drawing
operation. On an expose event one simply copies the pixmap to the
window. We use this library for the graphics course here at MIT and 
are quite happy with it.

gjc@mitech.com (02/28/91)

In article <1991Feb26.092358@wsl.dec.com>, klee@wsl.dec.com (Ken Lee) writes:
> In article <1991Feb25.212501.1776@yogi.fhhosp.ab.ca>, henry@yogi.fhhosp.ab.ca writes:
> |> Is there any easy way to port the code so that I can just draw into
> |> a window, and *not* have to worry about redrawing from Expose events?
> 
> Try using the X Toolkit, with the graphics encapsulated in a widget.
> The X Toolkit will manage your expose events for you.
> 

Which widget? If a simple drawing window widget you still have to
make PLOT-10 like emulation routes which keep a display list around
so that you can redraw on the expose event.

The *big* problem in this area may have nothing to do with
keeping track of the display list but instead have to do with
completely mangling the CONTROL-STRUCTURE of the program in question
in order to be able to fit into the XtMainLoop style event-driven model.

The simplest way out of that may be to handle X graphics in a subprocess.

One example of this is a TEKTRONICS 4010 emulator on top of XLIB,
that was designed specifically for running old PLOT-10 style code.

Anonymous FTP to BU.EDU, cd to users/gjc and get decwindows-tek-vms.
(Still has #ifdef Unix stuff in the code however).


-gjc

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

In <1991Feb25.212501.1776@yogi.fhhosp.ab.ca> henry@yogi.fhhosp.ab.ca writes:

>I have a pile of code that needs to run under X.  It all uses
>graphic primitive calls (lines, dots, crosses) that are PLOT-10 like.
>
>I'm unenthused about doing a lot of code rewrites to bundle graphics
>code into repaint procedures.
>
>Is there any easy way to port the code so that I can just draw into
>a window, and *not* have to worry about redrawing from Expose events?

There are advantages and disadvantages to the following
suggestion but here goes ...

X allows the programmer to create a pixmap, which can be
thought of as an off-screen window. The term "drawable"
refers to either a pixmap or a window. Most [%] of the Xlib
graphic routines to draw lines, circles etc work on
drawables, i.e., either pixmaps of windows. So you could
create a pixmap (using XCreatePixmap), and draw into that.
Then your expose handler simply uses XCopyArea to copy from
the pixmap to the exposed section of the window.

[%] You can clear a window (via XClearWindow or XClearArea)
but you can't clear a pixmap simply because a pixmap doesn't
have a background colour. Instead, if you want to clear a
pixmap then you should use XFillRectangle to fill it with a
suitable "background" colour.


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

klee@wsl.dec.com (Ken Lee) (03/02/91)

In article <13601@life.ai.mit.edu>, sundar@ai.mit.edu (Sundar Narasimhan) writes:
|> Hmm.. You may want to look at the Display widget found in
|> trix.ai.mit.edu:/com/ftp/pub/users/sundar/graph.tar.Z. It attempts
|> to manage Expose events for the programmer

Is this really any simpler than writing your own widget?  Check out
simple widgets like the Athena logo widget.  The bulk of the work in
widgets like this is the Expose semantics, which you must any way.

-- 
Ken Lee
DEC Western Software Laboratory, Palo Alto, Calif.
Internet: klee@wsl.dec.com
uucp: uunet!decwrl!klee