/[svn]/gigedit/trunk/src/gigedit/dimensionmanager.cpp
ViewVC logotype

Diff of /gigedit/trunk/src/gigedit/dimensionmanager.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1677 by persson, Sun Feb 10 08:50:35 2008 UTC revision 1733 by persson, Sat May 3 09:54:36 2008 UTC
# Line 23  Line 23 
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) {
# Line 224  void DimensionManager::refreshManager() Line 226  void DimensionManager::refreshManager()
226              Gtk::TreeModel::Row row = *(refTableModel->append());              Gtk::TreeModel::Row row = *(refTableModel->append());
227              row[tableModel.m_dim_type] = __dimTypeAsString(dim->dimension);              row[tableModel.m_dim_type] = __dimTypeAsString(dim->dimension);
228              row[tableModel.m_bits] = dim->bits;              row[tableModel.m_bits] = dim->bits;
229              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] = dim->zones;
230              row[tableModel.m_description] = __dimDescriptionAsString(dim->dimension);              row[tableModel.m_description] = __dimDescriptionAsString(dim->dimension);
231              row[tableModel.m_definition] = dim;              row[tableModel.m_definition] = dim;
232          }          }
# Line 258  void DimensionManager::addDimension() { Line 260  void DimensionManager::addDimension() {
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;
# Line 285  void DimensionManager::addDimension() { Line 308  void DimensionManager::addDimension() {
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

Legend:
Removed from v.1677  
changed lines
  Added in v.1733

  ViewVC Help
Powered by ViewVC