c++ - Attaching to Gtk::Grid the same image -
** edit: have tried below (compiles strangly not work)**
class nibblerwindow : public gtk::window { private: gtk::grid grid; gtk::image tmp; gtk::image gridelem[5]; public: bool initimgarray(); nibblerwindow(); ~nibblerwindow(){} }; bool mywindow::initimgarray() { int = 0; while (i != 5) { this->gridelem[i].set("someimage.gif"); ++i; } return true; } mywindow::mywindow() { this->set_title("work in progress"); this->set_default_size(512, 512); this->add(grid); this->grid.add(gridelem[0]); this->grid.add(gridelem[1]); this->grid.show(); this->grid.show_all_children(); }
hello everybody,
i trying build game grid (like draughts or checkers), each child widget containing same image pattern. functional method found create each child widget individually, , build them in constructor list of class, this:
class mainwindow { private: gtk::grid gamegrid; gtk::image gridelement1; gtk::image gridelement2; gtk::image gridelement3; gtk::image gridelement4; /* , on ... */ /* member functions */ public: mainwindow(); ~mainwindow(); }; mainwindow::mainwindow() : gridelement1("background.png"), gridelement2("background.png"), gridelement3("background.png"), gridelement4("background.png") /* et caetera ...*/ { this->add(grid); this->add(gridelement1); this->gamegrid.attach_next_to(gridelement1, gridelement2, gtk::pos_left, 40, 41); this->gamegrid.attach_next_to(gridelement2, gridelement3, gtk::pos_left, 40, 41); this->gamegrid.attach_next_to(gridelement2, gridelement2, gtk::pos_left, 40, 41); /* et caetera */ }
i not find appropriate, case, instantiate in such static manner objects... initialize them in kind of loop. have tried many times in many ways put them in vectors or arrays, showed not work... considering should not manipulate direct pointers of gtk::objects gtk::refptr instead.
does know manner declare image objects ?
Comments
Post a Comment