Game Programming and Development Tools

Linux GUI programming – Jari

Jari

Member

Posts: 1471
From: Helsinki, Finland
Registered: 03-11-2005
Hi. I am interested in learning some linux GUI programming using c/c++. So I thought that it would be nice to start a discussion about the differences between windows API and linux API and about the crossplatform GUI libraries that there is.

It would be great some linux programmer could start and show how to create simple window.

Thanks!

------------------
And whatsoever ye do in word or deed, do all in the name of the Lord Jesus, giving thanks to God and the Father by him. - Col 3:17

Unless the LORD builds the house, they labor in vain who build it; unless the LORD keeps the city, the watchman stays awake in vain. - Psalms 127:1

cwc

Member

Posts: 121
From: USA
Registered: 07-30-2005
Hello, well the win32 api(Windows) and the XWindow System/Xlib(Linux) is totaly different. Alot of linux widget toolkits ,"as in(GTK)" extends Xlib. The Xlib library provides a C interface to the X Windows messaging system and GTK/widget toolkits uses the Xlib and extends its functionallity cause the Xlib is very limited in what it is able to do. Anyways, I would use a widget toolkit like the GTK to build a GUI(note there are other widget toolkits like Xaw,Motif and so on). Anyways here is a simple GUI program made with the GTK.

#include <gtk/gtk.h>
void destroy_func(GtkWidget *widget, gpointer data);
int main(int argc, char *argv[]) {
GtkWidget *main_win;
//initialize the GTK libraries
gtk_init(&argc,&argv);

//Create a top level window
main_win = gtk_window_new(GTK_WINDOW_TOPLEVEL);

//Set the size of the window
gtk_widget_set_usize(GTK_WIDGET(main_win), 180,120);

//Set the title of the window;
gtk_window_title(GTK_WINDOW(main_win),"My title");

//Catch the Closing event
gtk_signal_connect(GTK_OBJECT(main_win), "destroy",GTK_SIGNAL_FUNC(destroy_func), NULL);

//Show the window;
gtk_widget_show(main_win);

//Gtk main function;
gtk_main();

g_print("About to exit main()\n");
return 0;
}

void destroy_func(GtkWidget *widget, gpointer pdata) {
//Tells the GTK main to return;(Closing the window)
gtk_main_quit()
}


Also to see if you have GTK+ already installed on your linux box you should be able to use a program named gtk-config. When GTK is installed it installs this program. This program will tell you where all the required header files and lib are located. To run it go to the command line and just type gtk-config and hit enter and you should get a option list.If you don't get nothing then the GTK+ prob is not installed. Anyways god bless you all.

[This message has been edited by cwc (edited August 14, 2005).]

Jari

Member

Posts: 1471
From: Helsinki, Finland
Registered: 03-11-2005
Thanks cwc! That was a good explanation.
I did some searching and some one said that gnome apps use GTK to render and KDE use Qt, is this correct?
I'm on a windows now but I'll try to compile your code later in linux. Though if I not badly mistakes it should compile in windows too since I have the GTK installed, unless of course it's the binaries only.

Btw, do you need anything else than Xlib if you compile say openGL app create simple window for it?

------------------
And whatsoever ye do in word or deed, do all in the name of the Lord Jesus, giving thanks to God and the Father by him. - Col 3:17

Unless the LORD builds the house, they labor in vain who build it; unless the LORD keeps the city, the watchman stays awake in vain. - Psalms 127:1

cwc

Member

Posts: 121
From: USA
Registered: 07-30-2005
quote:
Originally posted by Jari:
I did some searching and some one said that gnome apps use GTK to render and KDE use Qt

I am not a expert linux gui programmer but from my understand all of Linux GUI is based on the X Window system/Xlib. All that GTK,Qt,Mofit and other do is use Xlib and extend the Xlib cause all the Xlib can do is create windows,draw simple objects and transmit mouse and keyboard actions from the server to the client. Now alot of gnome does use the GTK, I am not that familiar with KDE("but I know what it is and played with it alittle"), so I don't know about KDE but far as I understand, GTK should be able to run on KDE and Qt on gnome as long as you have them installed cause they are both widget toolkits which extends the Xlib. People prob use the Qt toolkit with KDE cause it prob has the KDE look and feel to its widgets and the same with gnome and GTK. God bless you.


[This message has been edited by cwc (edited August 14, 2005).]

D-SIPL

Moderator

Posts: 1345
From: Maesteg, Wales
Registered: 07-21-2001
I would suggest using GTK as Qt is only free to use for open source projects and there license is a little sketchy... grr KDE

--D-SIPL

------------------
"One World. One Web. One Program." -Microsoft promotional advertisement
"Ein Volk, ein Reich, ein Fuhrer!" -Adolf Hitler

Jari

Member

Posts: 1471
From: Helsinki, Finland
Registered: 03-11-2005
Hey thanks for the info cwc and D-SIPL, I just compiled my first GTK app.

------------------
And whatsoever ye do in word or deed, do all in the name of the Lord Jesus, giving thanks to God and the Father by him. - Col 3:17

Unless the LORD builds the house, they labor in vain who build it; unless the LORD keeps the city, the watchman stays awake in vain. - Psalms 127:1

cwc

Member

Posts: 121
From: USA
Registered: 07-30-2005
quote:
Originally posted by jari:
Hey thanks for the info cwc and D-SIPL, I just compiled my first GTK app.


SWEET

HanClinto

Administrator

Posts: 1828
From: Indiana
Registered: 10-11-2004
Congrats, Jari!

I just wanted to put in my $0.02, as for the past couple of months I've been working at one of my jobs creating a cross-platform GUI application. For the project, I've been using C#/.NET on the Windows side, and C#/Mono on the Linux side. I'm using GTK#, with Glade as my forms designer. It works great! It runs on everything from RH9 to Debian Sid to Windows XP. I'm a big fan of GTK and GTK# -- it's very nice to work with.

--clint

------------------
http://www.includingjudas.com/christiangame.html

Jari

Member

Posts: 1471
From: Helsinki, Finland
Registered: 03-11-2005
That's cool Clint.
GTK seems to be fine solution but I do wonder how much extra overhead it takes to render using GTK than native windows GUI as example?

Also are there any libraries that provide abstract layer to native GUIs? I mean the kind of library that allows you to compile using the windows API calls in windows and something else in linux... (mingw?)

------------------
And whatsoever ye do in word or deed, do all in the name of the Lord Jesus, giving thanks to God and the Father by him. - Col 3:17

Unless the LORD builds the house, they labor in vain who build it; unless the LORD keeps the city, the watchman stays awake in vain. - Psalms 127:1

HanClinto

Administrator

Posts: 1828
From: Indiana
Registered: 10-11-2004
*shrug* There's overhead in anything -- GTK on Windows is fast enough for me, it's fast enough for Gimp, for Gaim, and many other apps. If you need faster graphics, you need to take control yourself with something like SDL.

As far as implementing a Windows toolkit on Linux, the WINE project did this, and for C#, both Mono and DotGNU have their own managed Windows.Forms implementation. Here is a link to Mono's implementation. It's pretty cool stuff!

--clint

------------------
http://www.includingjudas.com/christiangame.html

Jari

Member

Posts: 1471
From: Helsinki, Finland
Registered: 03-11-2005
quote:
Originally posted by HanClinto:
C#, both Mono and DotGNU have their own managed Windows.Forms implementation. Here is a link to Mono's implementation. It's pretty cool stuff!

--clint


Interesting and yea you are right about the gaim and gimp, they work in our comps but I always try to think people with lower end machines...

And btw, paragui is fine solution if you ever need to make crossplatform GUI's using SDL.

------------------
And whatsoever ye do in word or deed, do all in the name of the Lord Jesus, giving thanks to God and the Father by him. - Col 3:17

Unless the LORD builds the house, they labor in vain who build it; unless the LORD keeps the city, the watchman stays awake in vain. - Psalms 127:1

HanClinto

Administrator

Posts: 1828
From: Indiana
Registered: 10-11-2004
Oh cool! Paragui looks nice -- thanks for the link! I was only ever aware of cegui (which looks sweet).

Sorry, I hope I wasn't too condescending in my last post -- sorry for going so basic on you.

Respectfully,
clint

------------------
http://www.includingjudas.com/christiangame.html

Jari

Member

Posts: 1471
From: Helsinki, Finland
Registered: 03-11-2005
quote:
Originally posted by HanClinto:

Sorry, I hope I wasn't too condescending in my last post -- sorry for going so basic on you.

Oh, no need to be sorry.

------------------
And whatsoever ye do in word or deed, do all in the name of the Lord Jesus, giving thanks to God and the Father by him. - Col 3:17

Unless the LORD builds the house, they labor in vain who build it; unless the LORD keeps the city, the watchman stays awake in vain. - Psalms 127:1

Jari

Member

Posts: 1471
From: Helsinki, Finland
Registered: 03-11-2005
I started working on Bible study tool for linux using GTK.
But I was wondering if it's bossible to create a link in tree view which user can click. Any one know about this?

I think that maybe tags should be used and gtk_text_tag_event() but I don't understand how are you supposed to use that function. Because I don't get the idea of GdkEvent parameter.

------------------
And whatsoever ye do in word or deed, do all in the name of the Lord Jesus, giving thanks to God and the Father by him. - Col 3:17

Unless the LORD builds the house, they labor in vain who build it; unless the LORD keeps the city, the watchman stays awake in vain. - Psalms 127:1

[This message has been edited by jari (edited August 24, 2005).]

cwc

Member

Posts: 121
From: USA
Registered: 07-30-2005
I think this tutorial should get you up and running
Look at
Getting the Cell Renderer a Click Event Happened On?
Not sure but I think this is what you are tring to do, I might be mis-interpreting you though, but you might be tring to just figure out click event. This tutorial should show you how to do that as well.

http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-treeview

Its a good tutorial that has to do with tree view.

God BLESS you and everyone!!!

Jari

Member

Posts: 1471
From: Helsinki, Finland
Registered: 03-11-2005
Thanks cwc! It's was not the kind of tutorial I was looking for but it might be too.
Here is a screenshot of what I have made so far if you are interested:

http://www.voiceofhisword.com/test/biblestudy.png

What I would to do is to add links to the notes (textView) which you can click and it sets the right scripture visible on the left.
So that you can write in the notes: "Romans 1:1" and that becomes link that takes you to book of romans at 1:1.
But I don't know how to create links, if that's even bossible.

Edit: Solved the other problem! Still dont know how to make links though.

------------------
And whatsoever ye do in word or deed, do all in the name of the Lord Jesus, giving thanks to God and the Father by him. - Col 3:17

Unless the LORD builds the house, they labor in vain who build it; unless the LORD keeps the city, the watchman stays awake in vain. - Psalms 127:1

[This message has been edited by jari (edited August 28, 2005).]