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

Diff of /gigedit/trunk/src/gigedit/regionchooser.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 3148 by schoenebeck, Thu May 4 11:47:45 2017 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2015 Andreas Persson   * Copyright (C) 2006-2017 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 20  Line 20 
20  #include "regionchooser.h"  #include "regionchooser.h"
21    
22  #include <algorithm>  #include <algorithm>
23    #include <assert.h>
24    
25  #include <cairomm/context.h>  #include <cairomm/context.h>
26  #include <gdkmm/general.h>  #include <gdkmm/general.h>
# Line 89  RegionChooser::RegionChooser() : Line 90  RegionChooser::RegionChooser() :
90      white("white"),      white("white"),
91      black("black"),      black("black"),
92      m_VirtKeybModeChoice(_("Virtual Keyboard Mode")),      m_VirtKeybModeChoice(_("Virtual Keyboard Mode")),
93      currentActiveKey(-1)      currentActiveKey(-1),
94        modifyallregions(false)
95  {  {
96      set_size_request(500, KEYBOARD_HEIGHT + REGION_BLOCK_HEIGHT);      set_size_request(500, KEYBOARD_HEIGHT + REGION_BLOCK_HEIGHT);
97    
98      loadBuiltInPix();      loadBuiltInPix();
99    
100        // create gray blue hatched pattern
101        {
102            const int width = grayBlueHatchedPattern->get_width();
103            const int height = grayBlueHatchedPattern->get_height();
104            const int stride = grayBlueHatchedPattern->get_rowstride();
105    
106            // manually convert from RGBA to ARGB
107            this->grayBlueHatchedPatternARGB = grayBlueHatchedPattern->copy();
108            const int pixelSize = stride / width;
109            const int totalPixels = width * height;
110            assert(pixelSize == 4);
111            unsigned char* ptr = this->grayBlueHatchedPatternARGB->get_pixels();
112            for (int iPixel = 0; iPixel < totalPixels; ++iPixel, ptr += pixelSize) {
113                const unsigned char r = ptr[0];
114                const unsigned char g = ptr[1];
115                const unsigned char b = ptr[2];
116                const unsigned char a = ptr[3];
117                ptr[0] = b;
118                ptr[1] = g;
119                ptr[2] = r;
120                ptr[3] = a;
121            }
122    
123            Cairo::RefPtr<Cairo::ImageSurface> imageSurface = Cairo::ImageSurface::create(
124                this->grayBlueHatchedPatternARGB->get_pixels(), Cairo::FORMAT_ARGB32, width, height, stride
125            );
126            this->grayBlueHatchedSurfacePattern = Cairo::SurfacePattern::create(imageSurface);
127            this->grayBlueHatchedSurfacePattern->set_extend(Cairo::EXTEND_REPEAT);
128        }
129    
130      instrument = 0;      instrument = 0;
131      region = 0;      region = 0;
132      resize.active = false;      resize.active = false;
# Line 184  RegionChooser::~RegionChooser() Line 216  RegionChooser::~RegionChooser()
216  {  {
217  }  }
218    
219    void RegionChooser::setModifyAllRegions(bool b) {
220        modifyallregions = b;
221        // redraw required parts
222        queue_draw();
223    }
224    
225  void RegionChooser::invalidate_key(int key) {  void RegionChooser::invalidate_key(int key) {
226      const int h = KEYBOARD_HEIGHT;      const int h = KEYBOARD_HEIGHT;
227      const int w = get_width() - 1;      const int w = get_width() - 1;
# Line 334  void RegionChooser::draw_regions(const C Line 372  void RegionChooser::draw_regions(const C
372                  cr->line_to(x3, h1 - 0.5);                  cr->line_to(x3, h1 - 0.5);
373                  cr->stroke();                  cr->stroke();
374    
375                  Gdk::Cairo::set_source_rgba(cr, region == r ? blue : white);                  if (region == r)
376                        Gdk::Cairo::set_source_rgba(cr, blue);
377                    else if (modifyallregions)
378                        cr->set_source(grayBlueHatchedSurfacePattern);
379                    else
380                        Gdk::Cairo::set_source_rgba(cr, white);
381    
382                  cr->rectangle(x3 + 1, 1, x2 - x3 - 1, h1 - 2);                  cr->rectangle(x3 + 1, 1, x2 - x3 - 1, h1 - 2);
383                  cr->fill();                  cr->fill();
384                  Gdk::Cairo::set_source_rgba(cr, black);                  Gdk::Cairo::set_source_rgba(cr, black);

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

  ViewVC Help
Powered by ViewVC