[linux-audio-dev] Which widgets?

Erik de Castro Lopo mle+la at mega-nerd.com
Sat Feb 25 01:56:43 UTC 2006


james at dis-dot-dat.net wrote:

> I'd prefer not to have to move my app from C to
> C++ just to implement the interface, so that's quite a few out of the
> window.

I'm sure that I dislike C++ even more than you do and I can completely
understand why you'd want to keep you app as C.

However, GUIs is actually one of the few applications where IMHO
C++ may actually have some benefits over C. It would definitely
be possible to do a C++ GUI which communicates with a C backend
but it would be necessay place a clothes peg over one's nose
while doing the C++ stuff.

That said, I have done GUIs in GTK+ (which is C) and it is doable, 
especially if you spend some time wrapping the the GTK+ trivialities 
into something more managable. So for instance, it you need 5 buttons
that are basically the same bar button names etc, instead of doing

   button1 = gtk_new_button("button1 name") ;
   gtk_fiddle_with (button1) ;
   button2 = gtk_new_button("button1 name") ;
   gtk_fiddle_with (button2) ;

   ...

   button5 = gtk_new_button("button1 name") ;
   gtk_fiddle_with (button5) ;

do something like:

struct button_s
{   const char * name ;
    int xpos, ypos, xsize, ysize ;
} ;

static struct button_s deez_buttons [] =
{  { "button1_name", 0, 0, 20, 20 },
   { "button2_name", 0, 0, 20, 20 },
   { "button3_name", 0, 0, 20, 20 },
   { "button4_name", 0, 0, 20, 20 },
   { "button5_name", 0, 0, 20, 20 }
} ;

and then write a function that takes an array of button_s structs
and does whatever is required to make them happen.

I also like to have all button messages pass back through one
callback. Each button will have a unique identifier so that in
the callback I can just switch on the button identifier.

This can easily be extended to have all GUI callbacks passing
through the one callback function and them make the whole thing
a model controller view thing.

> I don't really want huge dependencies for a knob, text box and a
> button, either.

Most GUI widget toolkits have a huge set of dependancies regardless :-).
GTK+ is no different in this regard.

> And something that's installed as default in most distros would be
> good, too.

GTK+ is shipped with most distros.

Erik
-- 
+-----------------------------------------------------------+
  Erik de Castro Lopo
+-----------------------------------------------------------+
"Perl as a language has less a design than a thousand special features
flying in close formation."
-- From the c2 wiki



More information about the Linux-audio-dev mailing list