/[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 3123 by schoenebeck, Tue Apr 25 20:45:54 2017 UTC revision 3158 by schoenebeck, Mon May 8 18:05:35 2017 UTC
# Line 20  Line 20 
20  #include <gtkmm/box.h>  #include <gtkmm/box.h>
21  #include "dimregionchooser.h"  #include "dimregionchooser.h"
22  #include <cairomm/context.h>  #include <cairomm/context.h>
23    #include <cairomm/surface.h>
24  #include <gdkmm/cursor.h>  #include <gdkmm/cursor.h>
25  #include <gdkmm/general.h>  #include <gdkmm/general.h>
26  #include <glibmm/stringutils.h>  #include <glibmm/stringutils.h>
27    #include <gtkmm/stock.h>
28  #include <glibmm/ustring.h>  #include <glibmm/ustring.h>
29  #include <gtkmm/messagedialog.h>  #include <gtkmm/messagedialog.h>
30  #include <assert.h>  #include <assert.h>
31    
32  #include "global.h"  #include "global.h"
33    #include "gfx/builtinpix.h"
34    
35  //TODO: this function and dimensionCaseOf() from global.h are duplicates, eliminate either one of them!  //TODO: this function and dimensionCaseOf() from global.h are duplicates, eliminate either one of them!
36  static DimensionCase caseOfDimRegion(gig::DimensionRegion* dr, bool* isValidZone) {  static DimensionCase caseOfDimRegion(gig::DimensionRegion* dr, bool* isValidZone) {
# Line 69  static DimensionCase caseOfDimRegion(gig Line 72  static DimensionCase caseOfDimRegion(gig
72  }  }
73    
74  DimRegionChooser::DimRegionChooser(Gtk::Window& window) :  DimRegionChooser::DimRegionChooser(Gtk::Window& window) :
75      red("#8070ff"),      red("#ff476e"),
76        blue("#4796ff"),
77      black("black"),      black("black"),
78      white("white")      white("white")
79  {  {
80        // make sure blue hatched pattern pixmap is loaded
81        loadBuiltInPix();
82    
83        // create blue hatched pattern
84        {
85            const int width = blueHatchedPattern->get_width();
86            const int height = blueHatchedPattern->get_height();
87            const int stride = blueHatchedPattern->get_rowstride();
88    
89            // manually convert from RGBA to ARGB
90            this->blueHatchedPatternARGB = blueHatchedPattern->copy();
91            const int pixelSize = stride / width;
92            const int totalPixels = width * height;
93            assert(pixelSize == 4);
94            unsigned char* ptr = this->blueHatchedPatternARGB->get_pixels();
95            for (int iPixel = 0; iPixel < totalPixels; ++iPixel, ptr += pixelSize) {
96                const unsigned char r = ptr[0];
97                const unsigned char g = ptr[1];
98                const unsigned char b = ptr[2];
99                const unsigned char a = ptr[3];
100                ptr[0] = b;
101                ptr[1] = g;
102                ptr[2] = r;
103                ptr[3] = a;
104            }
105    
106            Cairo::RefPtr<Cairo::ImageSurface> imageSurface = Cairo::ImageSurface::create(
107                this->blueHatchedPatternARGB->get_pixels(), Cairo::FORMAT_ARGB32, width, height, stride
108            );
109            this->blueHatchedSurfacePattern = Cairo::SurfacePattern::create(imageSurface);
110            this->blueHatchedSurfacePattern->set_extend(Cairo::EXTEND_REPEAT);
111        }
112    
113        // create gray blue hatched pattern
114        {
115            const int width = grayBlueHatchedPattern->get_width();
116            const int height = grayBlueHatchedPattern->get_height();
117            const int stride = grayBlueHatchedPattern->get_rowstride();
118    
119            // manually convert from RGBA to ARGB
120            this->grayBlueHatchedPatternARGB = grayBlueHatchedPattern->copy();
121            const int pixelSize = stride / width;
122            const int totalPixels = width * height;
123            assert(pixelSize == 4);
124            unsigned char* ptr = this->grayBlueHatchedPatternARGB->get_pixels();
125            for (int iPixel = 0; iPixel < totalPixels; ++iPixel, ptr += pixelSize) {
126                const unsigned char r = ptr[0];
127                const unsigned char g = ptr[1];
128                const unsigned char b = ptr[2];
129                const unsigned char a = ptr[3];
130                ptr[0] = b;
131                ptr[1] = g;
132                ptr[2] = r;
133                ptr[3] = a;
134            }
135    
136            Cairo::RefPtr<Cairo::ImageSurface> imageSurface = Cairo::ImageSurface::create(
137                this->grayBlueHatchedPatternARGB->get_pixels(), Cairo::FORMAT_ARGB32, width, height, stride
138            );
139            this->grayBlueHatchedSurfacePattern = Cairo::SurfacePattern::create(imageSurface);
140            this->grayBlueHatchedSurfacePattern->set_extend(Cairo::EXTEND_REPEAT);
141        }
142    
143      instrument = 0;      instrument = 0;
144      region = 0;      region = 0;
145      maindimregno = -1;      maindimregno = -1;
# Line 82  DimRegionChooser::DimRegionChooser(Gtk:: Line 149  DimRegionChooser::DimRegionChooser(Gtk::
149      cursor_is_resize = false;      cursor_is_resize = false;
150      h = 24;      h = 24;
151      multiSelectKeyDown = false;      multiSelectKeyDown = false;
152        primaryKeyDown = false;
153        shiftKeyDown = false;
154      modifybothchannels = modifyalldimregs = modifybothchannels = false;      modifybothchannels = modifyalldimregs = modifybothchannels = false;
155      set_can_focus();      set_can_focus();
156    
# Line 145  DimRegionChooser::~DimRegionChooser() Line 214  DimRegionChooser::~DimRegionChooser()
214    
215  void DimRegionChooser::setModifyBothChannels(bool b) {  void DimRegionChooser::setModifyBothChannels(bool b) {
216      modifybothchannels = b;      modifybothchannels = b;
217        // redraw required parts
218        queue_draw();
219  }  }
220    
221  void DimRegionChooser::setModifyAllDimensionRegions(bool b) {  void DimRegionChooser::setModifyAllDimensionRegions(bool b) {
222      modifyalldimregs = b;      modifyalldimregs = b;
223        // redraw required parts
224        queue_draw();
225  }  }
226    
227  void DimRegionChooser::setModifyAllRegions(bool b) {  void DimRegionChooser::setModifyAllRegions(bool b) {
# Line 156  void DimRegionChooser::setModifyAllRegio Line 229  void DimRegionChooser::setModifyAllRegio
229    
230      actionDeleteDimZone->set_label(b ? _("Delete Dimension Zone [ALL REGIONS]") : _("Delete Dimension Zone"));      actionDeleteDimZone->set_label(b ? _("Delete Dimension Zone [ALL REGIONS]") : _("Delete Dimension Zone"));
231      actionSplitDimZone->set_label(b ? _("Split Dimensions Zone [ALL REGIONS]") : _("Split Dimensions Zone"));      actionSplitDimZone->set_label(b ? _("Split Dimensions Zone [ALL REGIONS]") : _("Split Dimensions Zone"));
232    
233        // redraw required parts
234        queue_draw();
235  }  }
236    
237  #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
# Line 246  bool DimRegionChooser::on_draw(const Cai Line 322  bool DimRegionChooser::on_draw(const Cai
322                      dstr = dstrbuf;                      dstr = dstrbuf;
323                      break;                      break;
324                  }                  }
                 layout->set_text(dstr);  
325    
326                    // Since bold font yields in larger label width, we first always
327                    // set the bold text variant, retrieve its dimensions (as worst
328                    // case dimensions of the label) ...
329                    layout->set_markup("<b>" + Glib::ustring(dstr) + "</b>");
330                  Pango::Rectangle rectangle = layout->get_logical_extents();                  Pango::Rectangle rectangle = layout->get_logical_extents();
331                    // ... and then reset the label to regular font style in case
332                    // the line is not selected. Otherwise the right hand side
333                    // actual dimension zones would jump around on selection change.
334                    bool isSelectedLine = (focus_line == i);
335                    if (!isSelectedLine)
336                        layout->set_markup(dstr);
337    
338                  double text_w = double(rectangle.get_width()) / Pango::SCALE;                  double text_w = double(rectangle.get_width()) / Pango::SCALE;
339                  if (text_w > maxwidth) maxwidth = text_w;                  if (text_w > maxwidth) maxwidth = text_w;
340    
# Line 355  bool DimRegionChooser::on_draw(const Cai Line 441  bool DimRegionChooser::on_draw(const Cai
441    
442                          // draw fill for zone                          // draw fill for zone
443                          bool isSelectedZone = this->dimzones[dimension].count(j);                          bool isSelectedZone = this->dimzones[dimension].count(j);
444                          Gdk::Cairo::set_source_rgba(cr, isSelectedZone ? red : white);                          bool isMainSelection =
445                                this->maindimcase.find(dimension) != this->maindimcase.end() &&
446                                this->maindimcase[dimension] == j;
447                            bool isCheckBoxSelected =
448                                modifyalldimregs ||
449                                (modifybothchannels &&
450                                    dimension == gig::dimension_samplechannel);
451                            if (isMainSelection)
452                                Gdk::Cairo::set_source_rgba(cr, blue);
453                            else if (isSelectedZone)
454                                cr->set_source(blueHatchedSurfacePattern);
455                            else if (isCheckBoxSelected)
456                                cr->set_source(grayBlueHatchedSurfacePattern);
457                            else
458                                Gdk::Cairo::set_source_rgba(cr, white);
459    
460                          cr->rectangle(prevX + 1, y + 1, x - prevX - 1, h - 1);                          cr->rectangle(prevX + 1, y + 1, x - prevX - 1, h - 1);
461                          cr->fill();                          cr->fill();
462    
# Line 413  bool DimRegionChooser::on_draw(const Cai Line 514  bool DimRegionChooser::on_draw(const Cai
514                          if (j != 0) {                          if (j != 0) {
515                              // draw fill for zone                              // draw fill for zone
516                              bool isSelectedZone = this->dimzones[dimension].count(j-1);                              bool isSelectedZone = this->dimzones[dimension].count(j-1);
517                              Gdk::Cairo::set_source_rgba(cr, isSelectedZone ? red : white);                              bool isMainSelection =
518                                    this->maindimcase.find(dimension) != this->maindimcase.end() &&
519                                    this->maindimcase[dimension] == (j-1);
520                                bool isCheckBoxSelected =
521                                    modifyalldimregs ||
522                                    (modifybothchannels &&
523                                        dimension == gig::dimension_samplechannel);
524                                if (isMainSelection)
525                                    Gdk::Cairo::set_source_rgba(cr, blue);
526                                else if (isSelectedZone)
527                                    cr->set_source(blueHatchedSurfacePattern);
528                                else if (isCheckBoxSelected)
529                                    cr->set_source(grayBlueHatchedSurfacePattern);
530                                else
531                                    Gdk::Cairo::set_source_rgba(cr, white);
532                              cr->rectangle(prevX + 1, y + 1, x - prevX - 1, h - 1);                              cr->rectangle(prevX + 1, y + 1, x - prevX - 1, h - 1);
533                              cr->fill();                              cr->fill();
534    
# Line 1130  void DimRegionChooser::delete_dimension_ Line 1245  void DimRegionChooser::delete_dimension_
1245      refresh_all();      refresh_all();
1246  }  }
1247    
1248    // Cmd key on Mac, Ctrl key on all other OSs
1249    static const guint primaryKeyL =
1250        #if defined(__APPLE__)
1251        GDK_KEY_Meta_L;
1252        #else
1253        GDK_KEY_Control_L;
1254        #endif
1255    
1256    static const guint primaryKeyR =
1257        #if defined(__APPLE__)
1258        GDK_KEY_Meta_R;
1259        #else
1260        GDK_KEY_Control_R;
1261        #endif
1262    
1263  bool DimRegionChooser::onKeyPressed(GdkEventKey* key) {  bool DimRegionChooser::onKeyPressed(GdkEventKey* key) {
1264      //printf("key down 0x%x\n", key->keyval);      //printf("key down 0x%x\n", key->keyval);
1265      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)
1266          multiSelectKeyDown = true;          multiSelectKeyDown = true;
1267        if (key->keyval == primaryKeyL || key->keyval == primaryKeyR)
1268            primaryKeyDown = true;
1269        if (key->keyval == GDK_KEY_Shift_L || key->keyval == GDK_KEY_Shift_R)
1270            shiftKeyDown = true;
1271    
1272      //FIXME: hmm, for some reason GDKMM does not fire arrow key down events, so we are doing those handlers in the key up handler instead for now      //FIXME: hmm, for some reason GDKMM does not fire arrow key down events, so we are doing those handlers in the key up handler instead for now
1273      /*if (key->keyval == GDK_KEY_Left)      /*if (key->keyval == GDK_KEY_Left)
1274          select_prev_dimzone();          select_prev_dimzone();
# Line 1150  bool DimRegionChooser::onKeyReleased(Gdk Line 1285  bool DimRegionChooser::onKeyReleased(Gdk
1285      //printf("key up 0x%x\n", key->keyval);      //printf("key up 0x%x\n", key->keyval);
1286      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)
1287          multiSelectKeyDown = false;          multiSelectKeyDown = false;
1288        if (key->keyval == primaryKeyL || key->keyval == primaryKeyR)
1289            primaryKeyDown = false;
1290        if (key->keyval == GDK_KEY_Shift_L || key->keyval == GDK_KEY_Shift_R)
1291            shiftKeyDown = false;
1292    
1293      if (!has_focus()) return false;      if (!has_focus()) return false;
1294    
1295        // avoid conflict with Ctrl+Left and Ctrl+Right accelerators on mainwindow
1296        // (which is supposed to switch between regions)
1297        if (primaryKeyDown) return false;
1298    
1299        // avoid conflict with Alt+Shift+Left and Alt+Shift+Right accelerators on
1300        // mainwindow
1301        if (shiftKeyDown) return false;
1302    
1303      if (key->keyval == GDK_KEY_Left)      if (key->keyval == GDK_KEY_Left)
1304          select_prev_dimzone();          select_prev_dimzone();
1305      if (key->keyval == GDK_KEY_Right)      if (key->keyval == GDK_KEY_Right)
# Line 1213  bool DimRegionChooser::select_dimregion( Line 1360  bool DimRegionChooser::select_dimregion(
1360      return false; //.selection failed      return false; //.selection failed
1361  }  }
1362    
1363  void DimRegionChooser::select_next_dimzone() {  void DimRegionChooser::select_next_dimzone(bool add) {
1364      select_dimzone_by_dir(+1);      select_dimzone_by_dir(+1, add);
1365  }  }
1366    
1367  void DimRegionChooser::select_prev_dimzone() {  void DimRegionChooser::select_prev_dimzone(bool add) {
1368      select_dimzone_by_dir(-1);      select_dimzone_by_dir(-1, add);
1369  }  }
1370    
1371  void DimRegionChooser::select_dimzone_by_dir(int dir) {  void DimRegionChooser::select_dimzone_by_dir(int dir, bool add) {
1372      if (!region) return;      if (!region) return;
1373      if (!region->Dimensions) return;      if (!region->Dimensions) return;
1374      if (focus_line < 0) focus_line = 0;      if (focus_line < 0) focus_line = 0;
# Line 1256  void DimRegionChooser::select_dimzone_by Line 1403  void DimRegionChooser::select_dimzone_by
1403    
1404      maindimregno = getDimensionRegionIndex(dr);      maindimregno = getDimensionRegionIndex(dr);
1405    
1406      // reset selected dimregion zones      if (!add) {
1407      dimzones.clear();          // reset selected dimregion zones
1408            dimzones.clear();
1409        }
1410      for (DimensionCase::const_iterator it = maindimcase.begin();      for (DimensionCase::const_iterator it = maindimcase.begin();
1411           it != maindimcase.end(); ++it)           it != maindimcase.end(); ++it)
1412      {      {

Legend:
Removed from v.3123  
changed lines
  Added in v.3158

  ViewVC Help
Powered by ViewVC