20 |
#include "dimensionmanager.h" |
#include "dimensionmanager.h" |
21 |
|
|
22 |
#include <gtkmm/stock.h> |
#include <gtkmm/stock.h> |
23 |
|
#include <gtkmm/messagedialog.h> |
24 |
|
#include <gtkmm/dialog.h> |
25 |
|
#include <gtkmm/comboboxtext.h> |
26 |
|
|
27 |
// returns a human readable name of the given dimension type |
// returns a human readable name of the given dimension type |
28 |
static Glib::ustring __dimTypeAsString(gig::dimension_t d) { |
static Glib::ustring __dimTypeAsString(gig::dimension_t d) { |
220 |
refTableModel->clear(); |
refTableModel->clear(); |
221 |
|
|
222 |
for (int i = 0; i < region->Dimensions; i++) { |
for (int i = 0; i < region->Dimensions; i++) { |
223 |
gig::dimension_def_t dim = region->pDimensionDefinitions[i]; |
gig::dimension_def_t* dim = ®ion->pDimensionDefinitions[i]; |
224 |
Gtk::TreeModel::Row row = *(refTableModel->append()); |
Gtk::TreeModel::Row row = *(refTableModel->append()); |
225 |
row[tableModel.m_dim_type] = __dimTypeAsString(dim.dimension); |
row[tableModel.m_dim_type] = __dimTypeAsString(dim->dimension); |
226 |
row[tableModel.m_bits] = dim.bits; |
row[tableModel.m_bits] = dim->bits; |
227 |
row[tableModel.m_zones] = 1 << dim.bits; //TODO: for now we calculate it here until libgig always ensures 'zones' to be correct |
row[tableModel.m_zones] = 1 << dim->bits; //TODO: for now we calculate it here until libgig always ensures 'zones' to be correct |
228 |
row[tableModel.m_description] = __dimDescriptionAsString(dim.dimension); |
row[tableModel.m_description] = __dimDescriptionAsString(dim->dimension); |
229 |
|
row[tableModel.m_definition] = dim; |
230 |
} |
} |
231 |
|
|
232 |
Gtk::Window::show(); |
Gtk::Window::show(); |
234 |
} |
} |
235 |
|
|
236 |
void DimensionManager::addDimension() { |
void DimensionManager::addDimension() { |
237 |
//TODO: show a small dialog for adding a new dimension |
try { |
238 |
|
Gtk::Dialog dialog("New Dimension", true /*modal*/); |
239 |
|
// add dimension type combo box to the dialog |
240 |
|
Glib::RefPtr<Gtk::ListStore> refComboModel = Gtk::ListStore::create(comboModel); |
241 |
|
for (int i = 0x01; i < 0xff; i++) { |
242 |
|
Glib::ustring sType = |
243 |
|
__dimTypeAsString(static_cast<gig::dimension_t>(i)); |
244 |
|
if (sType.find("Unknown") != 0) { |
245 |
|
Gtk::TreeModel::Row row = *(refComboModel->append()); |
246 |
|
row[comboModel.m_type_id] = i; |
247 |
|
row[comboModel.m_type_name] = sType; |
248 |
|
} |
249 |
|
} |
250 |
|
Gtk::ComboBox comboDimType; |
251 |
|
comboDimType.set_model(refComboModel); |
252 |
|
comboDimType.pack_start(comboModel.m_type_id); |
253 |
|
comboDimType.pack_start(comboModel.m_type_name); |
254 |
|
dialog.get_vbox()->pack_start(comboDimType); |
255 |
|
comboDimType.show(); |
256 |
|
// add zones combo box to the dialog |
257 |
|
Gtk::ComboBoxText comboZones; |
258 |
|
for (int i = 1; i <= 7; i++) { //FIXME: is 7 the correct amount of max. bits ??? |
259 |
|
char buf[64]; |
260 |
|
sprintf(buf, "%d Zones (%d Bits)", 1 << i, i); |
261 |
|
comboZones.append_text(buf); |
262 |
|
} |
263 |
|
dialog.get_vbox()->pack_start(comboZones); |
264 |
|
comboZones.show(); |
265 |
|
// add OK and CANCEL buttons to the dialog |
266 |
|
dialog.add_button(Gtk::Stock::OK, 0); |
267 |
|
dialog.add_button(Gtk::Stock::CANCEL, 1); |
268 |
|
dialog.show_all_children(); |
269 |
|
if (!dialog.run()) { // OK selected ... |
270 |
|
Gtk::TreeModel::iterator iterType = comboDimType.get_active(); |
271 |
|
if (!iterType) return; |
272 |
|
Gtk::TreeModel::Row rowType = *iterType; |
273 |
|
if (!rowType) return; |
274 |
|
gig::dimension_def_t dim; |
275 |
|
int iTypeID = rowType[comboModel.m_type_id]; |
276 |
|
dim.dimension = static_cast<gig::dimension_t>(iTypeID); |
277 |
|
if (comboZones.get_active_row_number() < 0) return; |
278 |
|
dim.bits = comboZones.get_active_row_number() + 1; |
279 |
|
dim.zones = 1 << dim.bits; //TODO: support zones != pow(2,bits) - feature of gig v3 |
280 |
|
printf( |
281 |
|
"Adding dimension (type=0x%x, bits=%d, zones=%d)\n", |
282 |
|
dim.dimension, dim.bits, dim.zones |
283 |
|
); |
284 |
|
// add the new dimension to the region |
285 |
|
// (implicitly creates new dimension regions) |
286 |
|
region->AddDimension(&dim); |
287 |
|
// let everybody know there was a change |
288 |
|
articulation_changed_signal.emit(); |
289 |
|
} |
290 |
|
} catch (RIFF::Exception e) { |
291 |
|
Glib::ustring txt = "Could not remove dimension: " + e.Message; |
292 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
293 |
|
msg.run(); |
294 |
|
} |
295 |
} |
} |
296 |
|
|
297 |
void DimensionManager::removeDimension() { |
void DimensionManager::removeDimension() { |
298 |
//TODO: remove selected dimension |
Glib::RefPtr<Gtk::TreeSelection> sel = treeView.get_selection(); |
299 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
300 |
|
if (it) { |
301 |
|
// remove selected dimension |
302 |
|
Gtk::TreeModel::Row row = *it; |
303 |
|
gig::dimension_def_t* dim = row[tableModel.m_definition]; |
304 |
|
region->DeleteDimension(dim); |
305 |
|
// remove respective row from table |
306 |
|
refTableModel->erase(it); |
307 |
|
// let everybody know there was a change |
308 |
|
articulation_changed_signal.emit(); |
309 |
|
} |
310 |
} |
} |