Gtk::Table really slow
- From: Xaikon <jordi chacon gmail com>
- To: gtkmm-list gnome org
- Subject: Gtk::Table really slow
- Date: Sat, 18 Jul 2009 04:02:16 -0700 (PDT)
Hi,
I am developing an application which is a path finder that lets you choose
between different search algorithms. To show the grid (map), I decided to
use a Gtk::Table and in each cell there is an Gtk::EventBox and a Gtk::Image
that shows the kind of cell (road, grass, trail and so on). The problem is
that when I try to create a kind of big map, like 50x50, the process of
creation of the table is too slow, like 12 seconds :S
This is the code that creates the cells:
//Create a grid of event boxes on the table
t2.startTimer();
for(int y = 0; y < gData->width; y++)
{
for(int x = 0; x < gData->width; x++)
{
t3.startTimer();
//Initialise the array of cells to ROAD_CELL
*(gData->pmap + y*gData->width + x) = Pfv::ROAD_CELL;
//Initialise the array of firstCall to true
*(gData->pcalls + y*gData->width + x) = true;
//Create the event box
Gtk::EventBox* eb = manage(new Gtk::EventBox());
*(gData->pcells + y*gData->width + x) = eb;
eb->set_size_request(cellSize, cellSize);
//Add the event box to the grid
gData->grid->attach(*eb, x, x + 1, y, y + 1);
//Set the image of the event box to ROAD_IMAGE
Glib::RefPtr<Gdk::Pixbuf> pixb =
Gdk::Pixbuf::create_from_file(Pfv::ROAD_IMAGE);
Gtk::Image* image = manage(new Gtk::Image(pixb));
eb->add(*image);
eb->signal_button_press_event().connect(sigc::bind<Gtk::Image*,
int,int>(sigc::mem_fun(*this, &newGridAction::on_cell_clicked), image, x,
y));
eb->signal_size_allocate().connect(sigc::bind<Gtk::EventBox*, Gtk::Image*,
int,int>(sigc::mem_fun(*this, &newGridAction::on_grid_image_resized), eb,
image, x, y));
eb->signal_enter_notify_event().connect(sigc::bind<Gtk::Image*,
int,int>(sigc::mem_fun(*this, &newGridAction::on_mouse_over_cell), image, x,
y));
eb->show_all_children();
t3.stopTimer();
double diffticks2 = t3.getElapsedTime() * 1000;
std::cout << diffticks2 << std::endl;
}
}
//Show everything in the grid
gData->grid->show_all_children();
t2.stopTimer();
double diffticks = t2.getElapsedTime() * 1000;
std::cout << diffticks << std::endl;
Each iteration is like 0,8ms. When the map is 70x70 the time of the whole
loop and show_all_children() is 7seconds, but then the grid is not shown
until 5 seconds after.
For me this is a problem because I would like to use my search algorithms
with maps like 200x200, but it will take maybe 1minute to create that table.
So my questions are:
- Is my code very inefficient and is this the reason that creation of the
table is too long?
- Instead of using a Gtk::Table, what can I use? What do you suggest me to
solve this problem?
Thank you very much!
Jordi
--
View this message in context: http://www.nabble.com/Gtk%3A%3ATable-really-slow-tp24546767p24546767.html
Sent from the Gtkmm mailing list archive at Nabble.com.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]