I've been learning SDL with C++ lately, but wanted to give some other graphic libraries a try. So i used GTK (specifically gtkmm).
take a look at this example code:
Code:
#include <gtkmm/main.h>
#include <iostream>
#include <gtkmm/button.h>
#include <gtkmm/window.h>
using namespace std;
class HelloWorld : public Gtk::Window
{
public:
HelloWorld();
virtual ~HelloWorld();
protected:
//Signal handlers:
virtual void on_button_clicked();
//Member widgets:
Gtk::Button m_button;
};
HelloWorld::HelloWorld()
: m_button("Hello World") // creates a new button with label "Hello World".
{
// Sets the border width of the window.
set_border_width(10);
// When the button receives the "clicked" signal, it will call the
// on_button_clicked() method defined below.
m_button.signal_clicked().connect(sigc::mem_fun(*this,
&HelloWorld::on_button_clicked));
// This packs the button into the Window (a container).
add(m_button);
// The final step is to display this newly created widget...
m_button.show();
}
HelloWorld::~HelloWorld()
{
}
void HelloWorld::on_button_clicked()
{
cout << "Hello World" << endl;
}
int main (int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
HelloWorld helloworld;
//Shows the window and returns when it is closed.
Gtk::Main::run(helloworld);
return 0;
}
and guess what it does? it draws one button on one window and executes one line of code when the button is clicked. that's all. For 55-60 lines of code!
Why so complex? seriously, reading the gtkmm manual, half of it is completely confusing. I'm halfway through the Lazyfoo SDL tutorials. I've used SDL_image, mixer, ttf. I have classes to spawn enemies drawn on the screen.
Seriously, just to draw a button, you have to use advanced classes? Why so much? I hate dealing with huge amounts of code. It should work like this:
Code:
#include <gtksomething.h>
#include <iostream>
int main()
{
NewWindow (windowname)
windowname.TitleText = "Hello World in GTK";
NewButton (buttonname, x, y, w, h) //x,y, width and height of button
buttonname.ButtonText = "Hello World";
bool quit=false;
while(quit == false)
{
windowname.show();
buttonname.show();
if (buttonname.clicked==true)
{
cout << "hello world" << endl;
quit = true;
}
}
return 0;
}
20 lines of code. Much better. As I'm still learning C++, I'd like to know what each line of code does, which with SDL, I do. I'm still grasping pointers, etc. Is there a library like the above I can use, or should i fumble about trying to learn GTKmm?
Bookmarks