GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Aug 21, 2014 12:25 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: gtkmm - some beginner questions
PostPosted: Mon Nov 18, 2013 9:03 pm 
Offline

Joined: Mon Nov 18, 2013 3:15 pm
Posts: 4
hello everybody
this is my first time trying to create a GUI application in GTKmm. but i'm having trouble because of the lack of suport to it. as a newbie programmer, it's too hard to discover everything by just reading the references.
what i'm trying to do is a simple tile map creator (no, i'm not trying to create the next RPG Maker, btw :P)
at first, it would consist of: a menubar, on the top, with its options; a status bar, on the bottom; and two main frames (i think that's the name) with lots of images in a grid (and scrollbars, of course).

i have almost nothing so far:
Code:
#include <gtkmm/main.h>
#include <gtkmm/window.h>
int main(int argc, char* argv[]){
    const int tile_size = 64;
    const int window_size_x = tile_size*10+tile_size*5;
    const int window_size_y = tile_size*10;
    Gtk::Main kit(argc, argv);
    Gtk::Window window;
    window.set_title("GTK Test");
    window.set_size_request(window_size_x, window_size_y);
    window.set_resizable(false);
    window.set_position(Gtk::WIN_POS_CENTER);

    kit.run(window);
    return 0;
}

i'm starting on the menubar. but i haven't even been able to put it on the screen (altough i *think* i successfully created it). could someone give me a direction?
thanks in advance!


Top
 Profile  
 
 Post subject: Re: gtkmm - some beginner questions
PostPosted: Mon Nov 18, 2013 9:34 pm 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 745
Location: UK
Hello,

Which version of gtkmm are you using? Have you seen the gtkmm tutorial at https://developer.gnome.org/gtkmm-tutorial/unstable/index.html. This is for the latest version.

The tutorial will go through the basics which includes the menus, connecting signals, etc.

Another thing to consider is to use Glade to create the user interface. You then load the generated XML file into your application using Gtk::Builder and get the objects that you want to work with from it. These are the windows that you want to show, objects that you need to connect signals to or interface with in some way.

_________________
E.


Top
 Profile  
 
 Post subject: Re: gtkmm - some beginner questions
PostPosted: Tue Nov 19, 2013 11:14 am 
Offline

Joined: Mon Nov 18, 2013 3:15 pm
Posts: 4
oops, sorry, i totaly forgot to mention: i'm using Lubuntu 13.04, Code::Blocks 12.11, g++ 4.7.3, and the gtkmm-3.0-dev lib downloaded from the repositories (i don't know it's exact version).
well, my main goal would be to really learn how to make gui applications, that's why i do not want to use Glade and similars for now...

and ooh yeahh, thanks to your help, it's starting to happen!
Code:
#include <gtkmm/main.h>
#include <gtkmm/window.h>
#include <gtkmm/actiongroup.h>
#include <gtkmm/box.h>
#include <gtkmm/uimanager.h>
#include <gtkmm/action.h>
#include <gtkmm/stock.h>
#include <gtkmm/widget.h>
int main(int argc, char* argv[]){
    const int tile_size = 64;
    const int window_size_x = tile_size*10+tile_size*5;
    const int window_size_y = tile_size*10;
    Gtk::Main kit(argc, argv);
    Gtk::Window window;
    window.set_title("GTK Test");
    window.set_size_request(window_size_x, window_size_y);
    window.set_resizable(false);
    window.set_position(Gtk::WIN_POS_CENTER);

    Gtk::Box menubar_box(Gtk::ORIENTATION_VERTICAL);
    window.add(menubar_box);
    Glib::RefPtr<Gtk::ActionGroup> menubar_actgr = Gtk::ActionGroup::create();
    menubar_actgr->add(Gtk::Action::create("FileMenu", Gtk::Stock::FILE));
    menubar_actgr->add(Gtk::Action::create("NewFile", Gtk::Stock::NEW));
    menubar_actgr->add(Gtk::Action::create("SaveFile", Gtk::Stock::SAVE));
    menubar_actgr->add(Gtk::Action::create("SaveFileAs", Gtk::Stock::SAVE_AS));
    menubar_actgr->add(Gtk::Action::create("OpenFile", Gtk::Stock::OPEN));
    menubar_actgr->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT));
    menubar_actgr->add(Gtk::Action::create("OptionsMenu", Gtk::Stock::PREFERENCES));
    menubar_actgr->add(Gtk::Action::create("EditorOptions", Gtk::Stock::PREFERENCES));
    menubar_actgr->add(Gtk::Action::create("MapOptions", Gtk::Stock::PREFERENCES));
    menubar_actgr->add(Gtk::Action::create("Help", Gtk::Stock::HELP));
    menubar_actgr->add(Gtk::Action::create("About", Gtk::Stock::ABOUT));
    Glib::RefPtr<Gtk::UIManager> menubar_uimngr = Gtk::UIManager::create();
    menubar_uimngr->insert_action_group(menubar_actgr);
    {
        Glib::ustring menubar_uiinfo =
        "<ui>"
        "  <menubar name='MenuBar'>"
        "    <menu action='FileMenu'>"
        "      <menuitem action='NewFile'/>"
        "      <menuitem action='OpenFile'/>"
        "      <separator/>"
        "      <menuitem action='Quit'/>"
        "    </menu>"
        "    <menu action='OptionsMenu'>"
        "      <menuitem action='MapOptions'/>"
        "      <menuitem action='EditorOptions'/>"
        "    </menu>"
        "    <menu action='Help'>"
        "      <menuitem action='About'/>"
        "    </menu>"
        "  </menubar>"
        "</ui>";
        menubar_uimngr->add_ui_from_string(menubar_uiinfo);
    }
    Gtk::Widget* menubar_wdgt = menubar_uimngr->get_widget("/MenuBar");
    menubar_box.pack_start(*menubar_wdgt, Gtk::PACK_SHRINK);

    window.show_all_children();
    kit.run(window);
    return 0;
}



ok, altough i know that these menus do nothing yet, i'd like to move on for now. i'll need two frames on the main window, correct?
i want something visually like this is the end:
Image


Top
 Profile  
 
 Post subject: Re: gtkmm - some beginner questions
PostPosted: Tue Nov 19, 2013 3:41 pm 
Offline

Joined: Mon Nov 18, 2013 3:15 pm
Posts: 4
ok, so from what i've read, i shouldn't add widgets directly to the main window, right?
i first need to create a container (such as Gtk::Grid), add it to the main window, and the add widgets to this container (and maybe other containers to this container). is that right?

if so, i'd like some help in structurating this:

Gtk::Window
-Gtk::Grid
--Gtk::Box (menu bar)
--GtK::Box (status bar)
...

now i'm stuck. should i add another 2 grids inside the main grid, to handle many small images at once? or is there any better way?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group