tags:

views:

328

answers:

6

I'd like build a GUI where every single pixel is under my control (i.e. not using the standard widgets that something like GTK+ provides). Renoise is a good example of what I'm looking to produce.

Is getting down to the Xlib or XCB level the best way to go, or is it possible to achieve this with higher level frameworks like GTK+ (maybe even PyGTK)? Should I be looking at Cairo for the drawing?

I'd like to work in Python or Ruby if possible, but C is fine too.

Thanks!

+2  A: 

You'll probably want something like pygame then.

Ignacio Vazquez-Abrams
+1  A: 

GTK and PyGTK are probably the wrong tools to use. It's not impossible, because you could have your entire application be one big gtk.DrawingArea (an example of this where it actually makes sense is Gargoyle) but for any sort of complicated GUI you'd go crazy.

ptomato
+3  A: 

With Clutter toolkit (or some other canvas widget/toolkit) you can build such an interface. I would not advise going to the level of Xlib/XCB or DrawingArea because it would require implementing much of generic functionality already present in canvases.

dmitry_vk
Wow! Clutter looks great! Thanks Dmitry! Is there any reason I *shouldn't* use it?
splicer
+1  A: 

http://www.oluyede.org/blog/writing-a-widget-using-cairo-and-pygtk-28/ shows how to create a simple widget using PyGTK and Cairo.

Florian Diesch
+1  A: 

In simplest terms, you need something that gives you a bounding rectangle and free reign to draw into it whatever you want. Such objects are commonly called a "canvas". I have done this before (in Ruby) using the FXCanvas class available through the Fox toolkit, but there are others available as well (wxWidgets, for example, but I have no personal experience with this toolkit).

Be warned, though. Low-level interfaces like this offer a lot of flexibility, but they also require a lot more work on your part.

bta
+3  A: 

In X there is one problem with this approach which you might not have taken into consideration. The font size is measured in points (ine point being 1/72 of an inch) and thus varies in (pixel) size with resolution and monitor size. The text strings will also vary in length depending on the language so it's not really possible to determine how large buttons and such need to be. The common GUI tolkits for X are designed with this in mind. Apart from that it would be easy to just write your own theme engine for GTK that draws all widgets exactly as you want them (using Cairo[1] or GDK[2]) and make your application always use that theme. Perhaps it would also be possible for your application to set the default font size (in points) based on the DPI to always get the same size in pixels (and of course not making your application translatable).

There are at least a couble of GUIs using this pixel perfect approach based on SDL[3], for example AGAR[4], PicoGUI[5] and Guichan[6]. Most of them are written in C++ and some in C and as far as I know none of them have bindings for Python nor Ruby. Then using SDL you can only have one toplevel window which means your application (or the GUI tolkit you use) have to do it's own window managing for various dialogs and such. But I guess that was what you intended anyway.

[1] cairographics.org/
[2] library.gnome.org/devel/gdk/unstable/index.html
[3] www.libsdl.org/
[4] libagar.org/
[5] picogui.org/
[6] guichan.sourceforge.net/wiki/index.php/Main_Page

Grim
The right answer!
Joshua