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

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

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

revision 2626 by schoenebeck, Thu Jun 12 15:12:00 2014 UTC revision 2695 by schoenebeck, Tue Jan 6 18:11:27 2015 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2014 Andreas Persson   * Copyright (C) 2006-2015 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
# Line 86  DimRegionChooser::DimRegionChooser(Gtk:: Line 86  DimRegionChooser::DimRegionChooser(Gtk::
86      focus_line = 0;      focus_line = 0;
87      resize.active = false;      resize.active = false;
88      cursor_is_resize = false;      cursor_is_resize = false;
89      h = 20;      h = 24;
90      multiSelectKeyDown = false;      multiSelectKeyDown = false;
91      set_can_focus();      set_can_focus();
92    
# Line 273  bool DimRegionChooser::on_draw(const Cai Line 273  bool DimRegionChooser::on_draw(const Cai
273                  // draw focus rectangle around dimension's label and zones                  // draw focus rectangle around dimension's label and zones
274                  if (has_focus() && focus_line == i) {                  if (has_focus() && focus_line == i) {
275  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
276                      Gdk::Rectangle farea(0, y, 150, 20);                      Gdk::Rectangle farea(0, y, 150, h);
277                      get_style()->paint_focus(get_window(), get_state(), farea,                      get_style()->paint_focus(get_window(), get_state(), farea,
278                                               *this, "",                                               *this, "",
279                                               0, y, label_width, 20);                                               0, y, label_width, h);
280  #else  #else
281                      get_style_context()->render_focus(cr,                      get_style_context()->render_focus(cr,
282                                                        0, y, label_width, 20);                                                        0, y, label_width, h);
283  #endif  #endif
284                  }                  }
285    
# Line 318  bool DimRegionChooser::on_draw(const Cai Line 318  bool DimRegionChooser::on_draw(const Cai
318                      cr->move_to(label_width + 0.5, y + 1);                      cr->move_to(label_width + 0.5, y + 1);
319                      cr->line_to(label_width + 0.5, y + h - 1);                      cr->line_to(label_width + 0.5, y + h - 1);
320                      int prevX = label_width;                      int prevX = label_width;
321                      int prevUpperLimit = 0;                      int prevUpperLimit = -1;
322    
323                      for (int j = 0 ; j < nbZones ; j++) {                      for (int j = 0 ; j < nbZones ; j++) {
324                          // draw dimension zone's borders for custom splits                          // draw dimension zone's borders for custom splits
# Line 346  bool DimRegionChooser::on_draw(const Cai Line 346  bool DimRegionChooser::on_draw(const Cai
346                          // as numeric value to the user                          // as numeric value to the user
347                          {                          {
348                              Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(context);                              Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(context);
349                              layout->set_text(Glib::Ascii::dtostr(prevUpperLimit));                              layout->set_text(Glib::Ascii::dtostr(prevUpperLimit+1));
350                              Gdk::Cairo::set_source_rgba(cr, black);                              Gdk::Cairo::set_source_rgba(cr, black);
351                              Pango::Rectangle rect = layout->get_logical_extents();                              Pango::Rectangle rect = layout->get_logical_extents();
352                              // get the text dimensions                              // get the text dimensions
353                              int text_width, text_height;                              int text_width, text_height;
354                              layout->get_pixel_size(text_width, text_height);                              layout->get_pixel_size(text_width, text_height);
355                              // move text to the left end of the dimension zone                              // move text to the left end of the dimension zone
356                              cr->move_to(prevX + 3, y + 1);                              cr->move_to(prevX + 3, y + (h - text_height) / 2);
357  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 16) || GTKMM_MAJOR_VERSION < 2  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 16) || GTKMM_MAJOR_VERSION < 2
358                              pango_cairo_show_layout(cr->cobj(), layout->gobj());                              pango_cairo_show_layout(cr->cobj(), layout->gobj());
359  #else  #else
# Line 371  bool DimRegionChooser::on_draw(const Cai Line 371  bool DimRegionChooser::on_draw(const Cai
371                              int text_width, text_height;                              int text_width, text_height;
372                              layout->get_pixel_size(text_width, text_height);                              layout->get_pixel_size(text_width, text_height);
373                              // move text to the left end of the dimension zone                              // move text to the left end of the dimension zone
374                              cr->move_to(x - 3 - text_width, y + 1);                              cr->move_to(x - 3 - text_width, y + (h - text_height) / 2);
375  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 16) || GTKMM_MAJOR_VERSION < 2  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 16) || GTKMM_MAJOR_VERSION < 2
376                              pango_cairo_show_layout(cr->cobj(), layout->gobj());                              pango_cairo_show_layout(cr->cobj(), layout->gobj());
377  #else  #else
# Line 413  bool DimRegionChooser::on_draw(const Cai Line 413  bool DimRegionChooser::on_draw(const Cai
413                                  int text_width, text_height;                                  int text_width, text_height;
414                                  layout->get_pixel_size(text_width, text_height);                                  layout->get_pixel_size(text_width, text_height);
415                                  // move text to the left end of the dimension zone                                  // move text to the left end of the dimension zone
416                                  cr->move_to(prevX + 3, y + 1);                                  cr->move_to(prevX + 3, y + (h - text_height) / 2);
417  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 16) || GTKMM_MAJOR_VERSION < 2  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 16) || GTKMM_MAJOR_VERSION < 2
418                                  pango_cairo_show_layout(cr->cobj(), layout->gobj());                                  pango_cairo_show_layout(cr->cobj(), layout->gobj());
419  #else  #else
# Line 431  bool DimRegionChooser::on_draw(const Cai Line 431  bool DimRegionChooser::on_draw(const Cai
431                                  int text_width, text_height;                                  int text_width, text_height;
432                                  layout->get_pixel_size(text_width, text_height);                                  layout->get_pixel_size(text_width, text_height);
433                                  // move text to the left end of the dimension zone                                  // move text to the left end of the dimension zone
434                                  cr->move_to(x - 3 - text_width, y + 1);                                  cr->move_to(x - 3 - text_width, y + (h - text_height) / 2);
435  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 16) || GTKMM_MAJOR_VERSION < 2  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 16) || GTKMM_MAJOR_VERSION < 2
436                                  pango_cairo_show_layout(cr->cobj(), layout->gobj());                                  pango_cairo_show_layout(cr->cobj(), layout->gobj());
437  #else  #else
# Line 469  void DimRegionChooser::set_region(gig::R Line 469  void DimRegionChooser::set_region(gig::R
469          }          }
470      }      }
471      dimregion_selected();      dimregion_selected();
472      set_size_request(800, region ? nbDimensions * 20 : 0);      set_size_request(800, region ? nbDimensions * h : 0);
473    
474      labels_changed = true;      labels_changed = true;
475      queue_resize();      queue_resize();
# Line 933  bool DimRegionChooser::onKeyReleased(Gdk Line 933  bool DimRegionChooser::onKeyReleased(Gdk
933          multiSelectKeyDown = false;          multiSelectKeyDown = false;
934  }  }
935    
936    void DimRegionChooser::resetSelectedZones() {
937        this->dimzones.clear();
938        if (!region) {
939            queue_draw(); // redraw required parts
940            return;
941        }
942        if (maindimregno < 0 || maindimregno >= region->DimensionRegions) {
943            queue_draw(); // redraw required parts
944            return;
945        }
946        if (!region->pDimensionRegions[maindimregno]) {
947            queue_draw(); // redraw required parts
948            return;
949        }
950        gig::DimensionRegion* dimrgn = region->pDimensionRegions[maindimregno];
951    
952        bool isValidZone;
953        this->maindimcase = caseOfDimRegion(dimrgn, &isValidZone);
954        if (!isValidZone) {
955            queue_draw(); // redraw required parts
956            return;
957        }
958    
959        for (std::map<gig::dimension_t,int>::const_iterator it = this->maindimcase.begin();
960             it != this->maindimcase.end(); ++it)
961        {
962            this->dimzones[it->first].insert(it->second);
963        }
964    
965        // redraw required parts
966        queue_draw();
967    }
968    
969    bool DimRegionChooser::select_dimregion(gig::DimensionRegion* dimrgn) {
970        if (!region) return false; //.selection failed
971    
972        for (int dr = 0; dr < region->DimensionRegions && region->pDimensionRegions[dr]; ++dr) {
973            if (region->pDimensionRegions[dr] == dimrgn) {
974                // reset dim region zone selection to the requested specific dim region case
975                maindimregno = dr;
976                resetSelectedZones();
977    
978                // emit signal that dimregion selection has changed, for external entities
979                dimregion_selected();
980    
981                return true; // selection success
982            }
983        }
984    
985        return false; //.selection failed
986    }
987    
988  gig::DimensionRegion* DimRegionChooser::get_main_dimregion() const {  gig::DimensionRegion* DimRegionChooser::get_main_dimregion() const {
989      if (!region) return NULL;      if (!region) return NULL;
990      return region->pDimensionRegions[maindimregno];      return region->pDimensionRegions[maindimregno];

Legend:
Removed from v.2626  
changed lines
  Added in v.2695

  ViewVC Help
Powered by ViewVC