1 |
/* -*- c++ -*- |
/* -*- c++ -*- |
2 |
* Copyright (C) 2006, 2007 Andreas Persson |
* Copyright (C) 2006-2008 Andreas Persson |
3 |
* |
* |
4 |
* This program is free software; you can redistribute it and/or |
* This program is free software; you can redistribute it and/or |
5 |
* modify it under the terms of the GNU General Public License as |
* modify it under the terms of the GNU General Public License as |
23 |
#include <gtkmm/messagedialog.h> |
#include <gtkmm/messagedialog.h> |
24 |
#include <gtkmm/dialog.h> |
#include <gtkmm/dialog.h> |
25 |
#include <gtkmm/comboboxtext.h> |
#include <gtkmm/comboboxtext.h> |
26 |
|
#include <gtkmm/spinbutton.h> |
27 |
|
#include <gtkmm/table.h> |
28 |
|
|
29 |
// returns a human readable name of the given dimension type |
// returns a human readable name of the given dimension type |
30 |
static Glib::ustring __dimTypeAsString(gig::dimension_t d) { |
static Glib::ustring __dimTypeAsString(gig::dimension_t d) { |
220 |
// update all GUI elements according to current gig::Region informations |
// update all GUI elements according to current gig::Region informations |
221 |
void DimensionManager::refreshManager() { |
void DimensionManager::refreshManager() { |
222 |
refTableModel->clear(); |
refTableModel->clear(); |
223 |
for (int i = 0; i < region->Dimensions; i++) { |
if (region) { |
224 |
gig::dimension_def_t* dim = ®ion->pDimensionDefinitions[i]; |
for (int i = 0; i < region->Dimensions; i++) { |
225 |
Gtk::TreeModel::Row row = *(refTableModel->append()); |
gig::dimension_def_t* dim = ®ion->pDimensionDefinitions[i]; |
226 |
row[tableModel.m_dim_type] = __dimTypeAsString(dim->dimension); |
Gtk::TreeModel::Row row = *(refTableModel->append()); |
227 |
row[tableModel.m_bits] = dim->bits; |
row[tableModel.m_dim_type] = __dimTypeAsString(dim->dimension); |
228 |
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_bits] = dim->bits; |
229 |
row[tableModel.m_description] = __dimDescriptionAsString(dim->dimension); |
row[tableModel.m_zones] = dim->zones; |
230 |
row[tableModel.m_definition] = dim; |
row[tableModel.m_description] = __dimDescriptionAsString(dim->dimension); |
231 |
|
row[tableModel.m_definition] = dim; |
232 |
|
} |
233 |
} |
} |
234 |
|
set_sensitive(region); |
235 |
} |
} |
236 |
|
|
237 |
void DimensionManager::show(gig::Region* region) { |
void DimensionManager::show(gig::Region* region) { |
241 |
deiconify(); |
deiconify(); |
242 |
} |
} |
243 |
|
|
244 |
|
void DimensionManager::set_region(gig::Region* region) { |
245 |
|
this->region = region; |
246 |
|
refreshManager(); |
247 |
|
} |
248 |
|
|
249 |
void DimensionManager::addDimension() { |
void DimensionManager::addDimension() { |
250 |
try { |
try { |
251 |
Gtk::Dialog dialog("New Dimension", true /*modal*/); |
Gtk::Dialog dialog("New Dimension", true /*modal*/); |
260 |
row[comboModel.m_type_name] = sType; |
row[comboModel.m_type_name] = sType; |
261 |
} |
} |
262 |
} |
} |
263 |
|
Gtk::Table table(2, 2); |
264 |
|
Gtk::Label labelDimType("Dimension:", Gtk::ALIGN_LEFT); |
265 |
Gtk::ComboBox comboDimType; |
Gtk::ComboBox comboDimType; |
266 |
comboDimType.set_model(refComboModel); |
comboDimType.set_model(refComboModel); |
267 |
comboDimType.pack_start(comboModel.m_type_id); |
comboDimType.pack_start(comboModel.m_type_id); |
268 |
comboDimType.pack_start(comboModel.m_type_name); |
comboDimType.pack_start(comboModel.m_type_name); |
269 |
dialog.get_vbox()->pack_start(comboDimType); |
Gtk::Label labelZones("Zones:", Gtk::ALIGN_LEFT); |
270 |
comboDimType.show(); |
table.attach(labelDimType, 0, 1, 0, 1); |
271 |
// add zones combo box to the dialog |
table.attach(comboDimType, 1, 2, 0, 1); |
272 |
|
table.attach(labelZones, 0, 1, 1, 2); |
273 |
|
dialog.get_vbox()->pack_start(table); |
274 |
|
|
275 |
|
// number of zones: use a combo box with fix values for gig |
276 |
|
// v2 and a spin button for v3 |
277 |
Gtk::ComboBoxText comboZones; |
Gtk::ComboBoxText comboZones; |
278 |
for (int i = 1; i <= 7; i++) { //FIXME: is 7 the correct amount of max. bits ??? |
Gtk::SpinButton spinZones; |
279 |
char buf[64]; |
bool version2 = false; |
280 |
sprintf(buf, "%d Zones (%d Bits)", 1 << i, i); |
if (region) { |
281 |
comboZones.append_text(buf); |
gig::File* file = (gig::File*)region->GetParent()->GetParent(); |
282 |
|
version2 = file->pVersion && file->pVersion->major == 2; |
283 |
|
} |
284 |
|
if (version2) { |
285 |
|
for (int i = 1; i <= 5; i++) { |
286 |
|
char buf[3]; |
287 |
|
sprintf(buf, "%d", 1 << i); |
288 |
|
comboZones.append_text(buf); |
289 |
|
} |
290 |
|
table.attach(comboZones, 1, 2, 1, 2); |
291 |
|
} else { |
292 |
|
spinZones.set_increments(1, 8); |
293 |
|
spinZones.set_numeric(true); |
294 |
|
spinZones.set_range(2, 128); |
295 |
|
spinZones.set_value(2); |
296 |
|
table.attach(spinZones, 1, 2, 1, 2); |
297 |
} |
} |
298 |
dialog.get_vbox()->pack_start(comboZones); |
|
|
comboZones.show(); |
|
|
// add OK and CANCEL buttons to the dialog |
|
299 |
dialog.add_button(Gtk::Stock::OK, 0); |
dialog.add_button(Gtk::Stock::OK, 0); |
300 |
dialog.add_button(Gtk::Stock::CANCEL, 1); |
dialog.add_button(Gtk::Stock::CANCEL, 1); |
301 |
dialog.show_all_children(); |
dialog.show_all_children(); |
302 |
|
|
303 |
if (!dialog.run()) { // OK selected ... |
if (!dialog.run()) { // OK selected ... |
304 |
Gtk::TreeModel::iterator iterType = comboDimType.get_active(); |
Gtk::TreeModel::iterator iterType = comboDimType.get_active(); |
305 |
if (!iterType) return; |
if (!iterType) return; |
308 |
gig::dimension_def_t dim; |
gig::dimension_def_t dim; |
309 |
int iTypeID = rowType[comboModel.m_type_id]; |
int iTypeID = rowType[comboModel.m_type_id]; |
310 |
dim.dimension = static_cast<gig::dimension_t>(iTypeID); |
dim.dimension = static_cast<gig::dimension_t>(iTypeID); |
311 |
if (comboZones.get_active_row_number() < 0) return; |
|
312 |
dim.bits = comboZones.get_active_row_number() + 1; |
if (version2) { |
313 |
dim.zones = 1 << dim.bits; //TODO: support zones != pow(2,bits) - feature of gig v3 |
if (comboZones.get_active_row_number() < 0) return; |
314 |
|
dim.bits = comboZones.get_active_row_number() + 1; |
315 |
|
dim.zones = 1 << dim.bits; |
316 |
|
} else { |
317 |
|
dim.zones = spinZones.get_value_as_int(); |
318 |
|
// Find the number of bits required to hold the |
319 |
|
// specified amount of zones. |
320 |
|
int zoneBits = dim.zones - 1; |
321 |
|
for (dim.bits = 0; zoneBits > 1; dim.bits += 2, zoneBits >>= 2); |
322 |
|
dim.bits += zoneBits; |
323 |
|
} |
324 |
printf( |
printf( |
325 |
"Adding dimension (type=0x%x, bits=%d, zones=%d)\n", |
"Adding dimension (type=0x%x, bits=%d, zones=%d)\n", |
326 |
dim.dimension, dim.bits, dim.zones |
dim.dimension, dim.bits, dim.zones |
356 |
Gtk::TreeModel::Row row = *it; |
Gtk::TreeModel::Row row = *it; |
357 |
gig::dimension_def_t* dim = row[tableModel.m_definition]; |
gig::dimension_def_t* dim = row[tableModel.m_definition]; |
358 |
region->DeleteDimension(dim); |
region->DeleteDimension(dim); |
|
// remove respective row from table |
|
|
refTableModel->erase(it); |
|
359 |
// let everybody know there was a change |
// let everybody know there was a change |
360 |
region_changed_signal.emit(region); |
region_changed_signal.emit(region); |
361 |
|
// update all GUI elements |
362 |
|
refreshManager(); |
363 |
} catch (RIFF::Exception e) { |
} catch (RIFF::Exception e) { |
364 |
// notify that the changes are over (i.e. to avoid dead locks) |
// notify that the changes are over (i.e. to avoid dead locks) |
365 |
region_changed_signal.emit(region); |
region_changed_signal.emit(region); |