/[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 3123 by schoenebeck, Tue Apr 25 20:45:54 2017 UTC revision 3202 by persson, Mon May 22 18:58:46 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 17  Line 17 
17   * 02110-1301 USA.   * 02110-1301 USA.
18   */   */
19    
20    #include "global.h"
21  #include "regionchooser.h"  #include "regionchooser.h"
22    
23  #include <algorithm>  #include <algorithm>
24    #include <assert.h>
25    
26  #include <cairomm/context.h>  #include <cairomm/context.h>
27  #include <gdkmm/general.h>  #include <gdkmm/general.h>
28  #include <gdkmm/cursor.h>  #include <gdkmm/cursor.h>
29    #include <gtkmm/stock.h>
30  #include <gdkmm/pixbuf.h>  #include <gdkmm/pixbuf.h>
31  #include <gtkmm/spinbutton.h>  #include <gtkmm/spinbutton.h>
32  #include <gtkmm/dialog.h>  #include <gtkmm/dialog.h>
33    
 #include "global.h"  
34  #include "Settings.h"  #include "Settings.h"
35  #include "gfx/builtinpix.h"  #include "gfx/builtinpix.h"
36    
# Line 84  gig::Region* SortedRegions::next() { Line 86  gig::Region* SortedRegions::next() {
86    
87  RegionChooser::RegionChooser() :  RegionChooser::RegionChooser() :
88      activeKeyColor("red"),      activeKeyColor("red"),
89      red("#8070ff"),      blue("#4796ff"),
90      grey1("grey69"),      grey1("grey69"),
91      white("white"),      white("white"),
92      black("black"),      black("black"),
93      m_VirtKeybModeChoice(_("Virtual Keyboard Mode")),      m_VirtKeybModeChoice(_("Virtual Keyboard Mode")),
94      currentActiveKey(-1)      currentActiveKey(-1),
95        modifyallregions(false)
96  {  {
97      set_size_request(500, KEYBOARD_HEIGHT + REGION_BLOCK_HEIGHT);      set_size_request(500, KEYBOARD_HEIGHT + REGION_BLOCK_HEIGHT);
98    
99      loadBuiltInPix();      loadBuiltInPix();
100    
101        // create gray blue hatched pattern
102        {
103            const int width = grayBlueHatchedPattern->get_width();
104            const int height = grayBlueHatchedPattern->get_height();
105            const int stride = grayBlueHatchedPattern->get_rowstride();
106    
107            // manually convert from RGBA to ARGB
108            this->grayBlueHatchedPatternARGB = grayBlueHatchedPattern->copy();
109            const int pixelSize = stride / width;
110            const int totalPixels = width * height;
111            assert(pixelSize == 4);
112            unsigned char* ptr = this->grayBlueHatchedPatternARGB->get_pixels();
113            for (int iPixel = 0; iPixel < totalPixels; ++iPixel, ptr += pixelSize) {
114                const unsigned char r = ptr[0];
115                const unsigned char g = ptr[1];
116                const unsigned char b = ptr[2];
117                const unsigned char a = ptr[3];
118                ptr[0] = b;
119                ptr[1] = g;
120                ptr[2] = r;
121                ptr[3] = a;
122            }
123    
124            Cairo::RefPtr<Cairo::ImageSurface> imageSurface = Cairo::ImageSurface::create(
125                this->grayBlueHatchedPatternARGB->get_pixels(), Cairo::FORMAT_ARGB32, width, height, stride
126            );
127            this->grayBlueHatchedSurfacePattern = Cairo::SurfacePattern::create(imageSurface);
128            this->grayBlueHatchedSurfacePattern->set_extend(Cairo::EXTEND_REPEAT);
129        }
130    
131      instrument = 0;      instrument = 0;
132      region = 0;      region = 0;
133      resize.active = false;      resize.active = false;
# Line 127  RegionChooser::RegionChooser() : Line 160  RegionChooser::RegionChooser() :
160      for (int i = 0 ; i < 128 ; i++) key_pressed[i] = false;      for (int i = 0 ; i < 128 ; i++) key_pressed[i] = false;
161    
162      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
163      actionGroup->add(Gtk::Action::create("Properties", _("_Properties")),      actionGroup->add(Gtk::Action::create("Properties",
164                                             Gtk::Stock::PROPERTIES),
165                       sigc::mem_fun(*this,                       sigc::mem_fun(*this,
166                                     &RegionChooser::show_region_properties));                                     &RegionChooser::show_region_properties));
167      actionGroup->add(Gtk::Action::create("Remove", _("_Remove")),      actionGroup->add(Gtk::Action::create("Remove", Gtk::Stock::REMOVE),
168                       sigc::mem_fun(*this, &RegionChooser::delete_region));                       sigc::mem_fun(*this, &RegionChooser::delete_region));
169      actionGroup->add(Gtk::Action::create("Add", _("_Add")),      actionGroup->add(Gtk::Action::create("Add", Gtk::Stock::ADD),
170                       sigc::mem_fun(*this, &RegionChooser::add_region));                       sigc::mem_fun(*this, &RegionChooser::add_region));
171      actionGroup->add(Gtk::Action::create("Dimensions", _("Dimensions...")),      actionGroup->add(Gtk::Action::create("Dimensions", _("Dimensions...")),
172                       sigc::mem_fun(*this, &RegionChooser::manage_dimensions));                       sigc::mem_fun(*this, &RegionChooser::manage_dimensions));
# Line 184  RegionChooser::~RegionChooser() Line 218  RegionChooser::~RegionChooser()
218  {  {
219  }  }
220    
221    void RegionChooser::setModifyAllRegions(bool b) {
222        modifyallregions = b;
223        // redraw required parts
224        queue_draw();
225    }
226    
227  void RegionChooser::invalidate_key(int key) {  void RegionChooser::invalidate_key(int key) {
228      const int h = KEYBOARD_HEIGHT;      const int h = KEYBOARD_HEIGHT;
229      const int w = get_width() - 1;      const int w = get_width() - 1;
# Line 334  void RegionChooser::draw_regions(const C Line 374  void RegionChooser::draw_regions(const C
374                  cr->line_to(x3, h1 - 0.5);                  cr->line_to(x3, h1 - 0.5);
375                  cr->stroke();                  cr->stroke();
376    
377                  Gdk::Cairo::set_source_rgba(cr, region == r ? red : white);                  if (region == r)
378                        Gdk::Cairo::set_source_rgba(cr, blue);
379                    else if (modifyallregions)
380                        cr->set_source(grayBlueHatchedSurfacePattern);
381                    else
382                        Gdk::Cairo::set_source_rgba(cr, white);
383    
384                  cr->rectangle(x3 + 1, 1, x2 - x3 - 1, h1 - 2);                  cr->rectangle(x3 + 1, 1, x2 - x3 - 1, h1 - 2);
385                  cr->fill();                  cr->fill();
386                  Gdk::Cairo::set_source_rgba(cr, black);                  Gdk::Cairo::set_source_rgba(cr, black);
# Line 405  void RegionChooser::draw_regions(const C Line 451  void RegionChooser::draw_regions(const C
451          layout->set_width(get_width() * Pango::SCALE);          layout->set_width(get_width() * Pango::SCALE);
452          //layout->set_height(get_height() * Pango::SCALE);          //layout->set_height(get_height() * Pango::SCALE);
453          layout->set_spacing(10);          layout->set_spacing(10);
454          Gdk::Cairo::set_source_rgba(cr, red);                  Gdk::Cairo::set_source_rgba(cr, blue);
455          // get the text dimensions          // get the text dimensions
456          int text_width, text_height;          int text_width, text_height;
457          layout->get_pixel_size(text_width, text_height);          layout->get_pixel_size(text_width, text_height);
# Line 1016  void RegionChooser::show_region_properti Line 1062  void RegionChooser::show_region_properti
1062      dialog.get_vbox()->pack_start(spinBox);      dialog.get_vbox()->pack_start(spinBox);
1063      spinBox.show();      spinBox.show();
1064      // add OK and CANCEL buttons to the dialog      // add OK and CANCEL buttons to the dialog
1065      dialog.add_button(_("_OK"), 0);      dialog.add_button(Gtk::Stock::OK, 0);
1066      dialog.add_button(_("_Cancel"), 1);      dialog.add_button(Gtk::Stock::CANCEL, 1);
1067      dialog.show_all_children();      dialog.show_all_children();
1068      if (!dialog.run()) { // OK selected ...      if (!dialog.run()) { // OK selected ...
1069          region->KeyGroup =          region->KeyGroup =

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

  ViewVC Help
Powered by ViewVC