/[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 3131 by schoenebeck, Thu Apr 27 17:28:01 2017 UTC revision 3340 by schoenebeck, Mon Jul 31 11:20:18 2017 UTC
# Line 17  Line 17 
17   * 02110-1301 USA.   * 02110-1301 USA.
18   */   */
19    
20    #include "global.h"
21  #include <gtkmm/box.h>  #include <gtkmm/box.h>
22  #include "dimregionchooser.h"  #include "dimregionchooser.h"
23  #include <cairomm/context.h>  #include <cairomm/context.h>
# Line 24  Line 25 
25  #include <gdkmm/cursor.h>  #include <gdkmm/cursor.h>
26  #include <gdkmm/general.h>  #include <gdkmm/general.h>
27  #include <glibmm/stringutils.h>  #include <glibmm/stringutils.h>
28    #include <gtkmm/stock.h>
29  #include <glibmm/ustring.h>  #include <glibmm/ustring.h>
30  #include <gtkmm/messagedialog.h>  #include <gtkmm/messagedialog.h>
31  #include <assert.h>  #include <assert.h>
32    
33  #include "global.h"  #include "gfx/builtinpix.h"
 #include "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 79  DimRegionChooser::DimRegionChooser(Gtk:: Line 80  DimRegionChooser::DimRegionChooser(Gtk::
80      // make sure blue hatched pattern pixmap is loaded      // make sure blue hatched pattern pixmap is loaded
81      loadBuiltInPix();      loadBuiltInPix();
82    
83      // create blue hatched pattern      // create blue hatched pattern 1
84      {      {
85          const int width = blueHatchedPattern->get_width();          const int width = blueHatchedPattern->get_width();
86          const int height = blueHatchedPattern->get_height();          const int height = blueHatchedPattern->get_height();
# Line 109  DimRegionChooser::DimRegionChooser(Gtk:: Line 110  DimRegionChooser::DimRegionChooser(Gtk::
110          this->blueHatchedSurfacePattern->set_extend(Cairo::EXTEND_REPEAT);          this->blueHatchedSurfacePattern->set_extend(Cairo::EXTEND_REPEAT);
111      }      }
112    
113        // create blue hatched pattern 2
114        {
115            const int width = blueHatchedPattern2->get_width();
116            const int height = blueHatchedPattern2->get_height();
117            const int stride = blueHatchedPattern2->get_rowstride();
118    
119            // manually convert from RGBA to ARGB
120            this->blueHatchedPattern2ARGB = blueHatchedPattern2->copy();
121            const int pixelSize = stride / width;
122            const int totalPixels = width * height;
123            assert(pixelSize == 4);
124            unsigned char* ptr = this->blueHatchedPattern2ARGB->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->blueHatchedPattern2ARGB->get_pixels(), Cairo::FORMAT_ARGB32, width, height, stride
138            );
139            this->blueHatchedSurfacePattern2 = Cairo::SurfacePattern::create(imageSurface);
140            this->blueHatchedSurfacePattern2->set_extend(Cairo::EXTEND_REPEAT);
141        }
142    
143        // create gray blue hatched pattern
144        {
145            const int width = grayBlueHatchedPattern->get_width();
146            const int height = grayBlueHatchedPattern->get_height();
147            const int stride = grayBlueHatchedPattern->get_rowstride();
148    
149            // manually convert from RGBA to ARGB
150            this->grayBlueHatchedPatternARGB = grayBlueHatchedPattern->copy();
151            const int pixelSize = stride / width;
152            const int totalPixels = width * height;
153            assert(pixelSize == 4);
154            unsigned char* ptr = this->grayBlueHatchedPatternARGB->get_pixels();
155            for (int iPixel = 0; iPixel < totalPixels; ++iPixel, ptr += pixelSize) {
156                const unsigned char r = ptr[0];
157                const unsigned char g = ptr[1];
158                const unsigned char b = ptr[2];
159                const unsigned char a = ptr[3];
160                ptr[0] = b;
161                ptr[1] = g;
162                ptr[2] = r;
163                ptr[3] = a;
164            }
165    
166            Cairo::RefPtr<Cairo::ImageSurface> imageSurface = Cairo::ImageSurface::create(
167                this->grayBlueHatchedPatternARGB->get_pixels(), Cairo::FORMAT_ARGB32, width, height, stride
168            );
169            this->grayBlueHatchedSurfacePattern = Cairo::SurfacePattern::create(imageSurface);
170            this->grayBlueHatchedSurfacePattern->set_extend(Cairo::EXTEND_REPEAT);
171        }
172    
173      instrument = 0;      instrument = 0;
174      region = 0;      region = 0;
175      maindimregno = -1;      maindimregno = -1;
# Line 183  DimRegionChooser::~DimRegionChooser() Line 244  DimRegionChooser::~DimRegionChooser()
244    
245  void DimRegionChooser::setModifyBothChannels(bool b) {  void DimRegionChooser::setModifyBothChannels(bool b) {
246      modifybothchannels = b;      modifybothchannels = b;
247        // redraw required parts
248        queue_draw();
249  }  }
250    
251  void DimRegionChooser::setModifyAllDimensionRegions(bool b) {  void DimRegionChooser::setModifyAllDimensionRegions(bool b) {
252      modifyalldimregs = b;      modifyalldimregs = b;
253        // redraw required parts
254        queue_draw();
255  }  }
256    
257  void DimRegionChooser::setModifyAllRegions(bool b) {  void DimRegionChooser::setModifyAllRegions(bool b) {
# Line 194  void DimRegionChooser::setModifyAllRegio Line 259  void DimRegionChooser::setModifyAllRegio
259    
260      actionDeleteDimZone->set_label(b ? _("Delete Dimension Zone [ALL REGIONS]") : _("Delete Dimension Zone"));      actionDeleteDimZone->set_label(b ? _("Delete Dimension Zone [ALL REGIONS]") : _("Delete Dimension Zone"));
261      actionSplitDimZone->set_label(b ? _("Split Dimensions Zone [ALL REGIONS]") : _("Split Dimensions Zone"));      actionSplitDimZone->set_label(b ? _("Split Dimensions Zone [ALL REGIONS]") : _("Split Dimensions Zone"));
262    
263        // redraw required parts
264        queue_draw();
265    }
266    
267    void DimRegionChooser::drawIconsFor(
268        gig::dimension_t dimension, uint zone,
269        const Cairo::RefPtr<Cairo::Context>& cr,
270        int x, int y, int w, int h)
271    {
272        DimensionCase dimCase;
273        dimCase[dimension] = zone;
274    
275        std::vector<gig::DimensionRegion*> dimregs =
276            dimensionRegionsMatching(dimCase, region, true);
277    
278        if (dimregs.empty()) return;
279    
280        int iSampleRefs = 0;
281        int iLoops = 0;
282    
283        for (uint i = 0; i < dimregs.size(); ++i) {
284            if (dimregs[i]->pSample) iSampleRefs++;
285            if (dimregs[i]->SampleLoops) iLoops++;
286        }
287    
288        bool bShowLoopSymbol = (iLoops > 0);
289        bool bShowSampleRefSymbol = (iSampleRefs < dimregs.size());
290    
291        if (bShowLoopSymbol || bShowSampleRefSymbol) {
292            const int margin = 1;
293    
294            cr->save();
295            cr->set_line_width(1);
296            cr->rectangle(x, y + margin, w, h - 2*margin);
297            cr->clip();
298            if (bShowSampleRefSymbol) {
299                const int wPic = 8;
300                const int hPic = 8;
301                Gdk::Cairo::set_source_pixbuf(
302                    cr, (iSampleRefs) ? yellowDot : redDot,
303                    x + (w-wPic)/2.f,
304                    y + (
305                        (bShowLoopSymbol) ? margin : (h-hPic)/2.f
306                    )
307                );
308                cr->paint();
309            }
310            if (bShowLoopSymbol) {
311                const int wPic = 12;
312                const int hPic = 14;
313                Gdk::Cairo::set_source_pixbuf(
314                    cr, (iLoops == dimregs.size()) ? blackLoop : grayLoop,
315                    x + (w-wPic)/2.f,
316                    y + (
317                        (bShowSampleRefSymbol) ? h - hPic - margin : (h-hPic)/2.f
318                    )
319                );
320                cr->paint();
321            }
322            cr->restore();
323        }
324  }  }
325    
326  #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 406  bool DimRegionChooser::on_draw(const Cai Line 533  bool DimRegionChooser::on_draw(const Cai
533                          bool isMainSelection =                          bool isMainSelection =
534                              this->maindimcase.find(dimension) != this->maindimcase.end() &&                              this->maindimcase.find(dimension) != this->maindimcase.end() &&
535                              this->maindimcase[dimension] == j;                              this->maindimcase[dimension] == j;
536                            bool isCheckBoxSelected =
537                                modifyalldimregs ||
538                                (modifybothchannels &&
539                                    dimension == gig::dimension_samplechannel);
540                          if (isMainSelection)                          if (isMainSelection)
541                              Gdk::Cairo::set_source_rgba(cr, blue);                              Gdk::Cairo::set_source_rgba(cr, blue);
542                          else if (isSelectedZone)                          else if (isSelectedZone)
543                                cr->set_source(blueHatchedSurfacePattern2);
544                            else if (isCheckBoxSelected)
545                              cr->set_source(blueHatchedSurfacePattern);                              cr->set_source(blueHatchedSurfacePattern);
546                          else                          else
547                              Gdk::Cairo::set_source_rgba(cr, white);                              Gdk::Cairo::set_source_rgba(cr, white);
548    
549                          cr->rectangle(prevX + 1, y + 1, x - prevX - 1, h - 1);                          const int wZone = x - prevX - 1;
550    
551                            cr->rectangle(prevX + 1, y + 1, wZone, h - 1);
552                          cr->fill();                          cr->fill();
553    
554                            // draw icons
555                            drawIconsFor(dimension, j, cr, prevX, y, wZone, h);
556    
557                          // draw text showing the beginning of the dimension zone                          // draw text showing the beginning of the dimension zone
558                          // as numeric value to the user                          // as numeric value to the user
559                          {                          {
# Line 468  bool DimRegionChooser::on_draw(const Cai Line 606  bool DimRegionChooser::on_draw(const Cai
606                          cr->stroke();                          cr->stroke();
607    
608                          if (j != 0) {                          if (j != 0) {
609                                const int wZone = x - prevX - 1;
610    
611                              // draw fill for zone                              // draw fill for zone
612                              bool isSelectedZone = this->dimzones[dimension].count(j-1);                              bool isSelectedZone = this->dimzones[dimension].count(j-1);
613                              bool isMainSelection =                              bool isMainSelection =
614                                  this->maindimcase.find(dimension) != this->maindimcase.end() &&                                  this->maindimcase.find(dimension) != this->maindimcase.end() &&
615                                  this->maindimcase[dimension] == (j-1);                                  this->maindimcase[dimension] == (j-1);
616                                bool isCheckBoxSelected =
617                                    modifyalldimregs ||
618                                    (modifybothchannels &&
619                                        dimension == gig::dimension_samplechannel);
620                              if (isMainSelection)                              if (isMainSelection)
621                                  Gdk::Cairo::set_source_rgba(cr, blue);                                  Gdk::Cairo::set_source_rgba(cr, blue);
622                              else if (isSelectedZone)                              else if (isSelectedZone)
623                                    cr->set_source(blueHatchedSurfacePattern2);
624                                else if (isCheckBoxSelected)
625                                  cr->set_source(blueHatchedSurfacePattern);                                  cr->set_source(blueHatchedSurfacePattern);
626                              else                              else
627                                  Gdk::Cairo::set_source_rgba(cr, white);                                  Gdk::Cairo::set_source_rgba(cr, white);
628                              cr->rectangle(prevX + 1, y + 1, x - prevX - 1, h - 1);                              cr->rectangle(prevX + 1, y + 1, wZone, h - 1);
629                              cr->fill();                              cr->fill();
630    
631                                // draw icons
632                                drawIconsFor(dimension, j - 1, cr, prevX, y, wZone, h);
633    
634                              // draw text showing the beginning of the dimension zone                              // draw text showing the beginning of the dimension zone
635                              // as numeric value to the user                              // as numeric value to the user
636                              {                              {
# Line 1246  bool DimRegionChooser::onKeyReleased(Gdk Line 1395  bool DimRegionChooser::onKeyReleased(Gdk
1395      // (which is supposed to switch between regions)      // (which is supposed to switch between regions)
1396      if (primaryKeyDown) return false;      if (primaryKeyDown) return false;
1397    
1398        // avoid conflict with Alt+Shift+Left and Alt+Shift+Right accelerators on
1399        // mainwindow
1400        if (shiftKeyDown) return false;
1401    
1402      if (key->keyval == GDK_KEY_Left)      if (key->keyval == GDK_KEY_Left)
1403          select_prev_dimzone();          select_prev_dimzone();
1404      if (key->keyval == GDK_KEY_Right)      if (key->keyval == GDK_KEY_Right)
# Line 1306  bool DimRegionChooser::select_dimregion( Line 1459  bool DimRegionChooser::select_dimregion(
1459      return false; //.selection failed      return false; //.selection failed
1460  }  }
1461    
1462  void DimRegionChooser::select_next_dimzone() {  void DimRegionChooser::select_next_dimzone(bool add) {
1463      select_dimzone_by_dir(+1);      select_dimzone_by_dir(+1, add);
1464  }  }
1465    
1466  void DimRegionChooser::select_prev_dimzone() {  void DimRegionChooser::select_prev_dimzone(bool add) {
1467      select_dimzone_by_dir(-1);      select_dimzone_by_dir(-1, add);
1468  }  }
1469    
1470  void DimRegionChooser::select_dimzone_by_dir(int dir) {  void DimRegionChooser::select_dimzone_by_dir(int dir, bool add) {
1471      if (!region) return;      if (!region) return;
1472      if (!region->Dimensions) return;      if (!region->Dimensions) return;
1473      if (focus_line < 0) focus_line = 0;      if (focus_line < 0) focus_line = 0;
# Line 1326  void DimRegionChooser::select_dimzone_by Line 1479  void DimRegionChooser::select_dimzone_by
1479          return;          return;
1480      }      }
1481    
1482      if (maindimcase.empty()) {      // commented out: re-evaluate maindimcase, since it might not been reset from a previous instrument which causes errors if it got different dimension types
1483        //if (maindimcase.empty()) {
1484          maindimcase = dimensionCaseOf(region->pDimensionRegions[maindimregno]);          maindimcase = dimensionCaseOf(region->pDimensionRegions[maindimregno]);
1485          if (maindimcase.empty()) {          if (maindimcase.empty()) {
1486              printf("caseOfDimregion(%d) -> empty\n", maindimregno);              printf("caseOfDimregion(%d) -> empty\n", maindimregno);
1487              return;              return;
1488          }          }
1489      }      //}
1490    
1491      int z = (dir > 0) ? maindimcase[maindimtype] + 1 : maindimcase[maindimtype] - 1;      int z = (dir > 0) ? maindimcase[maindimtype] + 1 : maindimcase[maindimtype] - 1;
1492      if (z < 0) z = 0;      if (z < 0) z = 0;
# Line 1349  void DimRegionChooser::select_dimzone_by Line 1503  void DimRegionChooser::select_dimzone_by
1503    
1504      maindimregno = getDimensionRegionIndex(dr);      maindimregno = getDimensionRegionIndex(dr);
1505    
1506      // reset selected dimregion zones      if (!add) {
1507      dimzones.clear();          // reset selected dimregion zones
1508            dimzones.clear();
1509        }
1510      for (DimensionCase::const_iterator it = maindimcase.begin();      for (DimensionCase::const_iterator it = maindimcase.begin();
1511           it != maindimcase.end(); ++it)           it != maindimcase.end(); ++it)
1512      {      {

Legend:
Removed from v.3131  
changed lines
  Added in v.3340

  ViewVC Help
Powered by ViewVC