/[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 3158 by schoenebeck, Mon May 8 18:05:35 2017 UTC revision 3305 by schoenebeck, Mon Jul 10 20:27:44 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 29  Line 30 
30  #include <gtkmm/messagedialog.h>  #include <gtkmm/messagedialog.h>
31  #include <assert.h>  #include <assert.h>
32    
 #include "global.h"  
33  #include "gfx/builtinpix.h"  #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!
# Line 80  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 110  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      // create gray blue hatched pattern
144      {      {
145          const int width = grayBlueHatchedPattern->get_width();          const int width = grayBlueHatchedPattern->get_width();
# Line 234  void DimRegionChooser::setModifyAllRegio Line 264  void DimRegionChooser::setModifyAllRegio
264      queue_draw();      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);
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
327  bool DimRegionChooser::on_expose_event(GdkEventExpose* e)  bool DimRegionChooser::on_expose_event(GdkEventExpose* e)
328  {  {
# Line 451  bool DimRegionChooser::on_draw(const Cai Line 540  bool DimRegionChooser::on_draw(const Cai
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(blueHatchedSurfacePattern);                              cr->set_source(blueHatchedSurfacePattern2);
544                          else if (isCheckBoxSelected)                          else if (isCheckBoxSelected)
545                              cr->set_source(grayBlueHatchedSurfacePattern);                              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 512  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 =
# Line 524  bool DimRegionChooser::on_draw(const Cai Line 620  bool DimRegionChooser::on_draw(const Cai
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(blueHatchedSurfacePattern);                                  cr->set_source(blueHatchedSurfacePattern2);
624                              else if (isCheckBoxSelected)                              else if (isCheckBoxSelected)
625                                  cr->set_source(grayBlueHatchedSurfacePattern);                                  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                              {                              {

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

  ViewVC Help
Powered by ViewVC