Hi,
I am trying to display a bitmap in an X11 window. The idea is that I
would draw the bitmap using Cairo, and then copy it to the X11 window
as needed (initially and each time the bitmap is updated or when X11
needs to redraw). This window would be created with a given width,
height and color depth, the user could move or close it but not
resize.
I am looking for advice on how to do this from Common Lisp. The
problem is that I have never done any X11 programming before, so I
need to learn many things at the same time. Some questions:
1. should I use plain X11 or GDK?
2. which package should I use if I want my code to be portable across
different implementations? There are plenty for either choice.
3. If I understand correctly, X11 is event-driven. I just want this
window to behave like a canvas and not worry about events in my Lisp
code any more -- I guess this requires a new thread, doesn't it?
Any advice would be appreciated, especially example code or links on
what to read. X11 seems overwhelming, even when I want to do
something simple.
Thanks,
Tamas
On Thu, 07 Jun 2007 12:20:06 -0700, Tamas Papp <······@gmail.com> wrote:
> Hi,
>
> I am trying to display a bitmap in an X11 window. The idea is that I
> would draw the bitmap using Cairo, and then copy it to the X11 window
> as needed (initially and each time the bitmap is updated or when X11
> needs to redraw). This window would be created with a given width,
> height and color depth, the user could move or close it but not
> resize.
>
> I am looking for advice on how to do this from Common Lisp. The
> problem is that I have never done any X11 programming before, so I
> need to learn many things at the same time. Some questions:
>
> 1. should I use plain X11 or GDK?
I have made some progress integrating the drawing-area widget from
cells-gtk with your cl-cairo2. It is far from being ready for the
public; at this point it runs stable, and you can draw and modify lines
and rectangles. Integrating more cairo functions should be fairly
straight forward, thanks to your cl-cairo2.
The interface is pretty simple: you just call methods on drawing-are
widget to create cairo primitives. The methods return a handle, which you
can use to modify (move, change color/transparency, etc) or delete the
primitives.
The widget itself keeps a hash-table of all primitives and takes care of
redrawing by calling the appropriate cairo functions.
To implement further features (currently I only have lines and
rectangles), all you need to do is
- define a datatype which saves the relevant information (currently it is
defstructs, I'll be moving over to CLOS shortly)
- define a method that takes parameters and creates an entry in the
hash-table
- define a method for drawing the primitive by calling the appropriate
cairo functions with the data in the hash-table
For simple things (like rectangles), you end up with about a dozen lines
of code per primitive.
If you'd like to check it out, I can give you access to my work in
progress.
My next steps will be
- bitmaps
- simple 3D stuff ("tron" style)
- text
Peter.
> 2. which package should I use if I want my code to be portable across
> different implementations? There are plenty for either choice.
>
> 3. If I understand correctly, X11 is event-driven. I just want this
> window to behave like a canvas and not worry about events in my Lisp
> code any more -- I guess this requires a new thread, doesn't it?
>
> Any advice would be appreciated, especially example code or links on
> what to read. X11 seems overwhelming, even when I want to do
> something simple.
>
> Thanks,
>
> Tamas
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
On Thu, 07 Jun 2007 21:20:06 +0200, Tamas Papp <······@gmail.com> wrote:
> Hi,
>
> I am trying to display a bitmap in an X11 window. The idea is that I
> would draw the bitmap using Cairo, and then copy it to the X11 window
> as needed (initially and each time the bitmap is updated or when X11
> needs to redraw). This window would be created with a given width,
> height and color depth, the user could move or close it but not
> resize.
>
> I am looking for advice on how to do this from Common Lisp. The
> problem is that I have never done any X11 programming before, so I
> need to learn many things at the same time. Some questions:
>
> 1. should I use plain X11 or GDK?
>
> 2. which package should I use if I want my code to be portable across
> different implementations? There are plenty for either choice.
>
> 3. If I understand correctly, X11 is event-driven. I just want this
> window to behave like a canvas and not worry about events in my Lisp
> code any more -- I guess this requires a new thread, doesn't it?
>
> Any advice would be appreciated, especially example code or links on
> what to read. X11 seems overwhelming, even when I want to do
> something simple.
>
> Thanks,
>
> Tamas
Look at LTK instead of using X11 directly and you can save yourselves some
headaches.
You will also have to install tcl/tk as well. (If you don't have it.)
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
"John Thingstad" <··············@chello.no> writes:
> On Thu, 07 Jun 2007 21:20:06 +0200, Tamas Papp <······@gmail.com> wrote:
>
>> Hi,
>>
>> I am trying to display a bitmap in an X11 window. The idea is that I
>> would draw the bitmap using Cairo, and then copy it to the X11 window
>> as needed (initially and each time the bitmap is updated or when X11
>> needs to redraw). This window would be created with a given width,
>> height and color depth, the user could move or close it but not
>> resize.
>
> Look at LTK instead of using X11 directly and you can save yourselves
> some headaches.
> You will also have to install tcl/tk as well. (If you don't have it.)
Hi John,
Thanks for the suggestion, LTK looks nice and I will try it. One
question still remains: once I start a loop that is waiting for
events, how can I put it in the "background"? I want to do something
like this:
1. open a window with a drawable, start a loop in the background,
return a CLOS object which has a slot with a C pointer
2. if the user closes/destroys the window, stop the loop and set the
pointer to nil
Do I need to use threads for this?
Thanks,
Tamas