/[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 2845 by persson, Sun Sep 20 10:18:22 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 17  Line 17 
17   * 02110-1301 USA.   * 02110-1301 USA.
18   */   */
19    
20    #include <gtkmm/box.h>
21  #include "dimregionchooser.h"  #include "dimregionchooser.h"
22  #include <cairomm/context.h>  #include <cairomm/context.h>
23  #include <gdkmm/cursor.h>  #include <gdkmm/cursor.h>
24  #include <gdkmm/general.h>  #include <gdkmm/general.h>
25  #include <glibmm/stringutils.h>  #include <glibmm/stringutils.h>
 #include <gtkmm/stock.h>  
26  #include <glibmm/ustring.h>  #include <glibmm/ustring.h>
27  #include <gtkmm/messagedialog.h>  #include <gtkmm/messagedialog.h>
28    
# 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);
                             Pango::Rectangle rect = layout->get_logical_extents();  
351                              // get the text dimensions                              // get the text dimensions
352                              int text_width, text_height;                              int text_width, text_height;
353                              layout->get_pixel_size(text_width, text_height);                              layout->get_pixel_size(text_width, text_height);
354                              // move text to the left end of the dimension zone                              // move text to the left end of the dimension zone
355                              cr->move_to(prevX + 3, y + 1);                              cr->move_to(prevX + 3, y + (h - text_height) / 2);
356  #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
357                              pango_cairo_show_layout(cr->cobj(), layout->gobj());                              pango_cairo_show_layout(cr->cobj(), layout->gobj());
358  #else  #else
# Line 366  bool DimRegionChooser::on_draw(const Cai Line 365  bool DimRegionChooser::on_draw(const Cai
365                              Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(context);                              Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(context);
366                              layout->set_text(Glib::Ascii::dtostr(upperLimit));                              layout->set_text(Glib::Ascii::dtostr(upperLimit));
367                              Gdk::Cairo::set_source_rgba(cr, black);                              Gdk::Cairo::set_source_rgba(cr, black);
                             Pango::Rectangle rect = layout->get_logical_extents();  
368                              // get the text dimensions                              // get the text dimensions
369                              int text_width, text_height;                              int text_width, text_height;
370                              layout->get_pixel_size(text_width, text_height);                              layout->get_pixel_size(text_width, text_height);
371                              // move text to the left end of the dimension zone                              // move text to the left end of the dimension zone
372                              cr->move_to(x - 3 - text_width, y + 1);                              cr->move_to(x - 3 - text_width, y + (h - text_height) / 2);
373  #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
374                              pango_cairo_show_layout(cr->cobj(), layout->gobj());                              pango_cairo_show_layout(cr->cobj(), layout->gobj());
375  #else  #else
# Line 408  bool DimRegionChooser::on_draw(const Cai Line 406  bool DimRegionChooser::on_draw(const Cai
406                                  Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(context);                                  Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(context);
407                                  layout->set_text(Glib::Ascii::dtostr((j-1) * 128/nbZones));                                  layout->set_text(Glib::Ascii::dtostr((j-1) * 128/nbZones));
408                                  Gdk::Cairo::set_source_rgba(cr, black);                                  Gdk::Cairo::set_source_rgba(cr, black);
                                 Pango::Rectangle rect = layout->get_logical_extents();  
409                                  // get the text dimensions                                  // get the text dimensions
410                                  int text_width, text_height;                                  int text_width, text_height;
411                                  layout->get_pixel_size(text_width, text_height);                                  layout->get_pixel_size(text_width, text_height);
412                                  // move text to the left end of the dimension zone                                  // move text to the left end of the dimension zone
413                                  cr->move_to(prevX + 3, y + 1);                                  cr->move_to(prevX + 3, y + (h - text_height) / 2);
414  #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
415                                  pango_cairo_show_layout(cr->cobj(), layout->gobj());                                  pango_cairo_show_layout(cr->cobj(), layout->gobj());
416  #else  #else
# Line 426  bool DimRegionChooser::on_draw(const Cai Line 423  bool DimRegionChooser::on_draw(const Cai
423                                  Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(context);                                  Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(context);
424                                  layout->set_text(Glib::Ascii::dtostr(j * 128/nbZones - 1));                                  layout->set_text(Glib::Ascii::dtostr(j * 128/nbZones - 1));
425                                  Gdk::Cairo::set_source_rgba(cr, black);                                  Gdk::Cairo::set_source_rgba(cr, black);
                                 Pango::Rectangle rect = layout->get_logical_extents();  
426                                  // get the text dimensions                                  // get the text dimensions
427                                  int text_width, text_height;                                  int text_width, text_height;
428                                  layout->get_pixel_size(text_width, text_height);                                  layout->get_pixel_size(text_width, text_height);
429                                  // move text to the left end of the dimension zone                                  // move text to the left end of the dimension zone
430                                  cr->move_to(x - 3 - text_width, y + 1);                                  cr->move_to(x - 3 - text_width, y + (h - text_height) / 2);
431  #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
432                                  pango_cairo_show_layout(cr->cobj(), layout->gobj());                                  pango_cairo_show_layout(cr->cobj(), layout->gobj());
433  #else  #else
# Line 469  void DimRegionChooser::set_region(gig::R Line 465  void DimRegionChooser::set_region(gig::R
465          }          }
466      }      }
467      dimregion_selected();      dimregion_selected();
468      set_size_request(800, region ? nbDimensions * 20 : 0);      set_size_request(800, region ? nbDimensions * h : 0);
469    
470      labels_changed = true;      labels_changed = true;
471      queue_resize();      queue_resize();
# Line 850  sigc::signal<void>& DimRegionChooser::si Line 846  sigc::signal<void>& DimRegionChooser::si
846    
847  bool DimRegionChooser::on_focus(Gtk::DirectionType direction)  bool DimRegionChooser::on_focus(Gtk::DirectionType direction)
848  {  {
849      // TODO: kolla att region finns osv, dvs att det går att sätta      // TODO: check that region exists etc, that is, that it's possible
850      // fokus.      // to set focus
851      if (direction == Gtk::DIR_TAB_FORWARD ||      if (direction == Gtk::DIR_TAB_FORWARD ||
852          direction == Gtk::DIR_DOWN) {          direction == Gtk::DIR_DOWN) {
853          if (!has_focus()) {          if (!has_focus()) {
# Line 883  bool DimRegionChooser::on_focus(Gtk::Dir Line 879  bool DimRegionChooser::on_focus(Gtk::Dir
879              }              }
880          }          }
881      } else if (!has_focus()) {      } else if (!has_focus()) {
882          // TODO: kolla att focus_line finns!          // TODO: check that focus_line exists
883          grab_focus();          grab_focus();
884          return true;          return true;
885      } else {      } else {
886          // TODO: öka eller minska värde!          // TODO: increase or decrease value
887      }      }
888        return false;
889  }  }
890    
891  void DimRegionChooser::split_dimension_zone() {      void DimRegionChooser::split_dimension_zone() {    
# Line 925  bool DimRegionChooser::onKeyPressed(GdkE Line 922  bool DimRegionChooser::onKeyPressed(GdkE
922      //printf("key down\n");      //printf("key down\n");
923      if (key->keyval == GDK_KEY_Control_L || key->keyval == GDK_KEY_Control_R)      if (key->keyval == GDK_KEY_Control_L || key->keyval == GDK_KEY_Control_R)
924          multiSelectKeyDown = true;          multiSelectKeyDown = true;
925        return false;
926  }  }
927    
928  bool DimRegionChooser::onKeyReleased(GdkEventKey* key) {  bool DimRegionChooser::onKeyReleased(GdkEventKey* key) {
929      //printf("key up\n");      //printf("key up\n");
930      if (key->keyval == GDK_KEY_Control_L || key->keyval == GDK_KEY_Control_R)      if (key->keyval == GDK_KEY_Control_L || key->keyval == GDK_KEY_Control_R)
931          multiSelectKeyDown = false;          multiSelectKeyDown = false;
932        return false;
933    }
934    
935    void DimRegionChooser::resetSelectedZones() {
936        this->dimzones.clear();
937        if (!region) {
938            queue_draw(); // redraw required parts
939            return;
940        }
941        if (maindimregno < 0 || maindimregno >= region->DimensionRegions) {
942            queue_draw(); // redraw required parts
943            return;
944        }
945        if (!region->pDimensionRegions[maindimregno]) {
946            queue_draw(); // redraw required parts
947            return;
948        }
949        gig::DimensionRegion* dimrgn = region->pDimensionRegions[maindimregno];
950    
951        bool isValidZone;
952        this->maindimcase = caseOfDimRegion(dimrgn, &isValidZone);
953        if (!isValidZone) {
954            queue_draw(); // redraw required parts
955            return;
956        }
957    
958        for (std::map<gig::dimension_t,int>::const_iterator it = this->maindimcase.begin();
959             it != this->maindimcase.end(); ++it)
960        {
961            this->dimzones[it->first].insert(it->second);
962        }
963    
964        // redraw required parts
965        queue_draw();
966    }
967    
968    bool DimRegionChooser::select_dimregion(gig::DimensionRegion* dimrgn) {
969        if (!region) return false; //.selection failed
970    
971        for (int dr = 0; dr < region->DimensionRegions && region->pDimensionRegions[dr]; ++dr) {
972            if (region->pDimensionRegions[dr] == dimrgn) {
973                // reset dim region zone selection to the requested specific dim region case
974                maindimregno = dr;
975                resetSelectedZones();
976    
977                // emit signal that dimregion selection has changed, for external entities
978                dimregion_selected();
979    
980                return true; // selection success
981            }
982        }
983    
984        return false; //.selection failed
985  }  }
986    
987  gig::DimensionRegion* DimRegionChooser::get_main_dimregion() const {  gig::DimensionRegion* DimRegionChooser::get_main_dimregion() const {

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

  ViewVC Help
Powered by ViewVC