/[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 2246 by persson, Fri Aug 19 10:55:41 2011 UTC revision 2845 by persson, Sun Sep 20 10:18:22 2015 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2011 Andreas Persson   * Copyright (C) 2006-2015 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>
 #include <sstream>  
23    
24  #include <cairomm/context.h>  #include <cairomm/context.h>
25  #include <gdkmm/general.h>  #include <gdkmm/general.h>
26  #include <gdkmm/cursor.h>  #include <gdkmm/cursor.h>
 #include <gtkmm/stock.h>  
27  #include <gtkmm/spinbutton.h>  #include <gtkmm/spinbutton.h>
28  #include <gtkmm/dialog.h>  #include <gtkmm/dialog.h>
29    
30  #include "global.h"  #include "global.h"
31    #include "Settings.h"
32    
33  #define REGION_BLOCK_HEIGHT             20  #define REGION_BLOCK_HEIGHT             30
34  #define KEYBOARD_HEIGHT                 40  #define KEYBOARD_HEIGHT                 40
35    
36  void SortedRegions::update(gig::Instrument* instrument) {  void SortedRegions::update(gig::Instrument* instrument) {
# Line 55  gig::Region* SortedRegions::first() { Line 54  gig::Region* SortedRegions::first() {
54  }  }
55    
56  gig::Region* SortedRegions::next() {  gig::Region* SortedRegions::next() {
57      region_iterator++;      ++region_iterator;
58      return region_iterator == regions.end() ? 0 : *region_iterator;      return region_iterator == regions.end() ? 0 : *region_iterator;
59  }  }
60    
# Line 104  RegionChooser::RegionChooser() : Line 103  RegionChooser::RegionChooser() :
103      for (int i = 0 ; i < 128 ; i++) key_pressed[i] = false;      for (int i = 0 ; i < 128 ; i++) key_pressed[i] = false;
104    
105      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
106      actionGroup->add(Gtk::Action::create("Properties",      actionGroup->add(Gtk::Action::create("Properties", _("_Properties")),
                                          Gtk::Stock::PROPERTIES),  
107                       sigc::mem_fun(*this,                       sigc::mem_fun(*this,
108                                     &RegionChooser::show_region_properties));                                     &RegionChooser::show_region_properties));
109      actionGroup->add(Gtk::Action::create("Remove", Gtk::Stock::REMOVE),      actionGroup->add(Gtk::Action::create("Remove", _("_Remove")),
110                       sigc::mem_fun(*this, &RegionChooser::delete_region));                       sigc::mem_fun(*this, &RegionChooser::delete_region));
111      actionGroup->add(Gtk::Action::create("Add", Gtk::Stock::ADD),      actionGroup->add(Gtk::Action::create("Add", _("_Add")),
112                       sigc::mem_fun(*this, &RegionChooser::add_region));                       sigc::mem_fun(*this, &RegionChooser::add_region));
113      actionGroup->add(Gtk::Action::create("Dimensions", _("Dimensions...")),      actionGroup->add(Gtk::Action::create("Dimensions", _("Dimensions...")),
114                       sigc::mem_fun(*this, &RegionChooser::manage_dimensions));                       sigc::mem_fun(*this, &RegionChooser::manage_dimensions));
# Line 155  RegionChooser::RegionChooser() : Line 153  RegionChooser::RegionChooser() :
153      keyboard_key_released_signal.connect(      keyboard_key_released_signal.connect(
154          sigc::mem_fun(*this, &RegionChooser::on_note_off_event)          sigc::mem_fun(*this, &RegionChooser::on_note_off_event)
155      );      );
156        set_tooltip_text(_("Right click here for adding new region. Use mouse pointer for moving (dragging) or resizing existing regions (by pointing at region's boundary). Right click on an existing region for more actions."));
157  }  }
158    
159  RegionChooser::~RegionChooser()  RegionChooser::~RegionChooser()
160  {  {
161  }  }
162    
 template<class T> inline std::string ToString(T o) {  
     std::stringstream ss;  
     ss << o;  
     return ss.str();  
 }  
   
163  void RegionChooser::invalidate_key(int key) {  void RegionChooser::invalidate_key(int key) {
164      const int h = KEYBOARD_HEIGHT;      const int h = KEYBOARD_HEIGHT;
165      const int w = get_width() - 1;      const int w = get_width() - 1;
# Line 219  bool RegionChooser::on_draw(const Cairo: Line 212  bool RegionChooser::on_draw(const Cairo:
212      Gdk::Cairo::set_source_rgba(cr, bg);      Gdk::Cairo::set_source_rgba(cr, bg);
213      cr->paint();      cr->paint();
214    
     const int w = get_width() - 1;  
   
215      if (clipy2 > h1) {      if (clipy2 > h1) {
216          draw_keyboard(cr, clipx1, clipx2);          draw_keyboard(cr, clipx1, clipx2);
217      }      }
# Line 338  void RegionChooser::draw_regions(const C Line 329  void RegionChooser::draw_regions(const C
329          cr->line_to(x + 0.5, h1 - 1);          cr->line_to(x + 0.5, h1 - 1);
330          cr->stroke();          cr->stroke();
331      }      }
332    
333        // if there is no region yet, show the user some hint text that he may
334        // right click on this area to create a new region
335        if (!regions.first()) {
336            Glib::RefPtr<Pango::Context> context = get_pango_context();
337            Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(context);
338            layout->set_alignment(Pango::ALIGN_CENTER);
339            layout->set_text(Glib::ustring("*** ") + _("Right click here to create a region.") + " ***");
340            layout->set_width(get_width() * Pango::SCALE);
341            //layout->set_height(get_height() * Pango::SCALE);
342            layout->set_spacing(10);
343            Gdk::Cairo::set_source_rgba(cr, red);        
344            // get the text dimensions
345            int text_width, text_height;
346            layout->get_pixel_size(text_width, text_height);
347            cr->move_to(0, (REGION_BLOCK_HEIGHT - text_height) / 2);
348    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 16) || GTKMM_MAJOR_VERSION < 2
349            pango_cairo_show_layout(cr->cobj(), layout->gobj());
350    #else
351            layout->show_in_cairo_context(cr);
352    #endif
353        }
354  }  }
355    
356  bool RegionChooser::is_black_key(int key) {  bool RegionChooser::is_black_key(int key) {
# Line 500  void RegionChooser::update_after_resize( Line 513  void RegionChooser::update_after_resize(
513  void RegionChooser::update_after_move(int pos)  void RegionChooser::update_after_move(int pos)
514  {  {
515      instrument_struct_to_be_changed_signal.emit(instrument);      instrument_struct_to_be_changed_signal.emit(instrument);
516      region->SetKeyRange(pos, pos + region->KeyRange.high -      const int range = region->KeyRange.high - region->KeyRange.low;
517                          region->KeyRange.low);      const int diff  = pos - int(region->KeyRange.low);
518        region->SetKeyRange(pos, pos + range);
519        if (Settings::singleton()->moveRootNoteWithRegionMoved) {
520            for (int i = 0; i < 256; ++i) {
521                gig::DimensionRegion* dimrgn = region->pDimensionRegions[i];
522                if (!dimrgn || !dimrgn->pSample || !dimrgn->PitchTrack) continue;
523                dimrgn->UnityNote += diff;
524            }
525        }
526      regions.update(instrument);      regions.update(instrument);
527      instrument_changed.emit();      instrument_changed.emit();
528      instrument_struct_changed_signal.emit(instrument);      instrument_struct_changed_signal.emit(instrument);
# Line 523  bool RegionChooser::on_button_press_even Line 544  bool RegionChooser::on_button_press_even
544          }          }
545      }      }
546    
547        // left mouse button double click
548        if (event->type == GDK_2BUTTON_PRESS && event->button == 1) {
549            if (event->y < REGION_BLOCK_HEIGHT) {
550                // show dimension manager dialog for this region
551                manage_dimensions();
552            }
553        }
554    
555      if (event->y >= REGION_BLOCK_HEIGHT) return true;      if (event->y >= REGION_BLOCK_HEIGHT) return true;
556      if (event->type == GDK_BUTTON_PRESS && event->button == 3) {      if (event->type == GDK_BUTTON_PRESS && event->button == 3) {
557          gig::Region* r = get_region(k);          gig::Region* r = get_region(k);
# Line 598  gig::Region* RegionChooser::get_region(i Line 627  gig::Region* RegionChooser::get_region(i
627      return 0;      return 0;
628  }  }
629    
630    void RegionChooser::set_region(gig::Region* region) {
631        this->region = region;
632        queue_draw();
633        region_selected();
634        dimensionManager.set_region(region);
635    }
636    
637  void RegionChooser::motion_resize_region(int x, int y)  void RegionChooser::motion_resize_region(int x, int y)
638  {  {
639      const int w = get_width() - 1;      const int w = get_width() - 1;
# Line 860  void RegionChooser::show_region_properti Line 896  void RegionChooser::show_region_properti
896      dialog.get_vbox()->pack_start(spinBox);      dialog.get_vbox()->pack_start(spinBox);
897      spinBox.show();      spinBox.show();
898      // add OK and CANCEL buttons to the dialog      // add OK and CANCEL buttons to the dialog
899      dialog.add_button(Gtk::Stock::OK, 0);      dialog.add_button(_("_OK"), 0);
900      dialog.add_button(Gtk::Stock::CANCEL, 1);      dialog.add_button(_("_Cancel"), 1);
901      dialog.show_all_children();      dialog.show_all_children();
902      if (!dialog.run()) { // OK selected ...      if (!dialog.run()) { // OK selected ...
903          region->KeyGroup =          region->KeyGroup =

Legend:
Removed from v.2246  
changed lines
  Added in v.2845

  ViewVC Help
Powered by ViewVC