/[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 2150 by persson, Sun May 10 09:35:56 2009 UTC revision 2151 by persson, Sun Nov 21 12:38:41 2010 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2009 Andreas Persson   * Copyright (C) 2006-2010 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 18  Line 18 
18   */   */
19    
20  #include "regionchooser.h"  #include "regionchooser.h"
21    
22  #include <algorithm>  #include <algorithm>
23    #include <cmath>
24    #include <sstream>
25    
26    #include <cairomm/context.h>
27    #include <gdkmm/general.h>
28  #include <gdkmm/cursor.h>  #include <gdkmm/cursor.h>
29  #include <gtkmm/stock.h>  #include <gtkmm/stock.h>
30  #include <gtkmm/spinbutton.h>  #include <gtkmm/spinbutton.h>
31  #include <gtkmm/dialog.h>  #include <gtkmm/dialog.h>
 #include <math.h>  
 #include <sstream>  
32    
33  #include "global.h"  #include "global.h"
34    
35    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 10) || GTKMM_MAJOR_VERSION < 2
36    
37    #define create_cairo_context()                                          \
38        gobj() ? Cairo::RefPtr<Cairo::Context>(                             \
39            new Cairo::Context(gdk_cairo_create(get_window()->gobj()))) :   \
40        Cairo::RefPtr<Cairo::Context>()
41    
42    namespace Gdk {
43        namespace Cairo {
44            void set_source_color(const ::Cairo::RefPtr< ::Cairo::Context >& cr,
45                                  const Gdk::Color& color) {
46                gdk_cairo_set_source_color(cr->cobj(),
47                                           const_cast<GdkColor*>(color.gobj()));
48            }
49        }
50    }
51    #endif
52    
53  #define REGION_BLOCK_HEIGHT             20  #define REGION_BLOCK_HEIGHT             20
54  #define KEYBOARD_HEIGHT                 40  #define KEYBOARD_HEIGHT                 40
55    
# Line 37  void SortedRegions::update(gig::Instrume Line 59  void SortedRegions::update(gig::Instrume
59      // RegionChooser code needs a sorted list of regions.      // RegionChooser code needs a sorted list of regions.
60      regions.clear();      regions.clear();
61      if (instrument) {      if (instrument) {
62          for (gig::Region *r = instrument->GetFirstRegion() ;          for (gig::Region* r = instrument->GetFirstRegion() ;
63               r ;               r ;
64               r = instrument->GetNextRegion()) {               r = instrument->GetNextRegion()) {
65              regions.push_back(r);              regions.push_back(r);
# Line 62  RegionChooser::RegionChooser() : Line 84  RegionChooser::RegionChooser() :
84      m_VirtKeybModeChoice(_("Virtual Keyboard Mode")),      m_VirtKeybModeChoice(_("Virtual Keyboard Mode")),
85      currentActiveKey(-1)      currentActiveKey(-1)
86  {  {
     Glib::RefPtr<Gdk::Colormap> colormap = get_default_colormap();  
   
87      red = Gdk::Color("#8070ff");      red = Gdk::Color("#8070ff");
88      grey1 = Gdk::Color("#b0b0b0");      grey1 = Gdk::Color("#b0b0b0");
89      activeKeyColor = Gdk::Color("#ff0000");      activeKeyColor = Gdk::Color("#ff0000");
90      white = Gdk::Color("#ffffff");      white = Gdk::Color("#ffffff");
91      black = Gdk::Color("#000000");      black = Gdk::Color("#000000");
92    
     colormap->alloc_color(red);  
     colormap->alloc_color(grey1);  
     colormap->alloc_color(activeKeyColor);  
     colormap->alloc_color(white);  
     colormap->alloc_color(black);  
93      instrument = 0;      instrument = 0;
94      region = 0;      region = 0;
95      resize.active = false;      resize.active = false;
# Line 170  template<class T> inline std::string ToS Line 185  template<class T> inline std::string ToS
185  }  }
186    
187  void RegionChooser::on_note_on_event(int key, int velocity) {  void RegionChooser::on_note_on_event(int key, int velocity) {
188      draw_region(key, key+1, activeKeyColor);      draw_key(key, activeKeyColor);
189      m_VirtKeybVelocityLabel.set_text(ToString(velocity));      m_VirtKeybVelocityLabel.set_text(ToString(velocity));
190  }  }
191    
192  void RegionChooser::on_note_off_event(int key, int velocity) {  void RegionChooser::on_note_off_event(int key, int velocity) {
193      if (is_black_key(key)) {      if (is_black_key(key)) {
194          draw_region(key, key+1, black);          draw_key(key, black);
195      } else {      } else {
196          draw_region(key, key+1, key >= 21 && key <= 108 ? white : grey1);          draw_key(key, key >= 21 && key <= 108 ? white : grey1);
197      }      }
198      m_VirtKeybOffVelocityLabel.set_text(ToString(velocity));      m_VirtKeybOffVelocityLabel.set_text(ToString(velocity));
199  }  }
200    
 void RegionChooser::on_realize()  
 {  
     // We need to call the base on_realize()  
     Gtk::DrawingArea::on_realize();  
   
     // Now we can allocate any additional resources we need  
     Glib::RefPtr<Gdk::Window> window = get_window();  
     gc = Gdk::GC::create(window);  
     window->clear();  
 }  
201    
202  bool RegionChooser::on_expose_event(GdkEventExpose* event)  bool RegionChooser::on_expose_event(GdkEventExpose* event)
203  {  {
204      Glib::RefPtr<Gdk::Window> window = get_window();      Glib::RefPtr<Gdk::Window> window = get_window();
205      window->clear();      if (window) {
206      const int h = KEYBOARD_HEIGHT;          Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
207      const int w = get_width() - 1;          if (event) {
208      const int bh = int(h * 0.55);              cr->rectangle(event->area.x, event->area.y,
209                              event->area.width, event->area.height);
210      Glib::RefPtr<const Gdk::GC> black = get_style()->get_black_gc();              cr->clip();
211      Glib::RefPtr<const Gdk::GC> white = get_style()->get_white_gc();          }
212            const int h = KEYBOARD_HEIGHT;
213            const int w = get_width() - 1;
214            const int bh = int(h * 0.55);
215    
216            cr->save();
217            cr->set_line_width(1);
218    
219            const Gdk::Color bg = get_style()->get_bg(Gtk::STATE_NORMAL);
220            Gdk::Cairo::set_source_color(cr, bg);
221            cr->paint();
222    
223            Gdk::Cairo::set_source_color(cr, black);
224            cr->rectangle(0.5, h1 + 0.5, w, h - 1);
225            cr->stroke();
226    
227            int x1 = int(w * 20.5 / 128.0 + 0.5);
228            int x2 = int(w * 109.5 / 128.0 + 0.5);
229    
230            Gdk::Cairo::set_source_color(cr, grey1);
231            cr->rectangle(1, h1 + 1, x1 - 1, h - 2);
232            cr->fill();
233    
234            Gdk::Cairo::set_source_color(cr, white);
235            cr->rectangle(x1 + 1, h1 + 1, x2 - x1 - 1, h - 2);
236            cr->fill();
237    
238            Gdk::Cairo::set_source_color(cr, grey1);
239            cr->rectangle(x2 + 1, h1 + 1, w - x2 - 1, h - 2);
240            cr->fill();
241    
242            Gdk::Cairo::set_source_color(cr, black);
243            for (int i = 0 ; i < 128 ; i++) {
244                int note = (i + 3) % 12;
245                int x = int(w * i / 128.0 + 0.5);
246    
247                if (note == 1 || note == 4 || note == 6 ||
248                    note == 9 || note == 11) {
249                    int x2 = int(w * (i + 0.5) / 128.0 + 0.5);
250                    cr->move_to(x2 + 0.5, h1 + bh + 0.5);
251                    cr->line_to(x2 + 0.5, h1 + h - 1);
252                    cr->stroke();
253    
254                    int x3 = int(w * (i + 1) / 128.0 + 0.5);
255                    cr->rectangle(x, h1 + 1, x3 - x + 1, bh);
256                    cr->fill();
257                } else if (note == 3 || note == 8) {
258                    cr->move_to(x + 0.5, h1 + 1);
259                    cr->line_to(x + 0.5, h1 + h - 1);
260                    cr->stroke();
261    
262      window->draw_rectangle(black, false, 0, h1, w, h - 1);                  if (note == 3) draw_digit(i);
263      gc->set_foreground(grey1);              }
     int x1 = int(w * 20.5 / 128.0 + 0.5);  
     int x2 = int(w * 109.5 / 128.0 + 0.5);  
     window->draw_rectangle(gc, true, 1, h1 + 1,  
                            x1 - 1, h - 2);  
     window->draw_rectangle(white, true, x1 + 1, h1 + 1, x2 - x1 - 1, h - 2);  
     window->draw_rectangle(gc, true, x2 + 1, h1 + 1,  
                            w - x2 - 1, h - 2);  
     for (int i = 0 ; i < 128 ; i++) {  
         int note = (i + 3) % 12;  
         int x = int(w * i / 128.0 + 0.5);  
   
         if (note == 1 || note == 4 || note == 6 || note == 9 || note == 11) {  
             int x2 = int(w * (i + 0.5) / 128.0 + 0.5);  
             window->draw_line(black, x2, h1 + bh, x2, h1 + h);  
   
             int x3 = int(w * (i + 1) / 128.0 + 0.5);  
             window->draw_rectangle(black, true, x, h1 + 1, x3 - x + 1, bh);  
         } else if (note == 3 || note == 8) {  
             window->draw_line(black, x, h1 + 1, x, h1 + h);  
264          }          }
         if (note == 3) draw_digit(i);  
     }  
265    
266      if (instrument) {          if (instrument) {
267          int i = 0;              int i = 0;
268          gig::Region *next_region;              gig::Region* next_region;
269          int x3 = -1;              int x3 = -1;
270          for (gig::Region *r = regions.first() ; r ; r = next_region) {              for (gig::Region* r = regions.first() ; r ; r = next_region) {
271    
272              if (x3 < 0) x3 = int(w * (r->KeyRange.low) / 128.0 + 0.5);                  if (x3 < 0) x3 = int(w * (r->KeyRange.low) / 128.0 + 0.5);
273              next_region = regions.next();                  next_region = regions.next();
274              if (!next_region || r->KeyRange.high + 1 != next_region->KeyRange.low) {                  if (!next_region ||
275                  int x2 = int(w * (r->KeyRange.high + 1) / 128.0 + 0.5);                      r->KeyRange.high + 1 != next_region->KeyRange.low) {
276                  window->draw_line(black, x3, 0, x2, 0);                      int x2 = int(w * (r->KeyRange.high + 1) / 128.0 + 0.5);
277                  window->draw_line(black, x3, h1 - 1, x2, h1 - 1);                      cr->move_to(x3, 0.5);
278                  window->draw_line(black, x2, 1, x2, h1 - 2);                      cr->line_to(x2 + 0.5, 0.5);
279                  window->draw_rectangle(white, true, x3 + 1, 1, x2 - x3 - 1, h1 - 2);                      cr->line_to(x2 + 0.5, h1 - 0.5);
280                  x3 = -1;                      cr->line_to(x3, h1 - 0.5);
281              }                      cr->stroke();
282              i++;  
283          }                      Gdk::Cairo::set_source_color(cr, white);
284                        cr->rectangle(x3 + 1, 1, x2 - x3 - 1, h1 - 2);
285          for (gig::Region *r = regions.first() ; r ; r = regions.next()) {                      cr->fill();
286              int x = int(w * (r->KeyRange.low) / 128.0 + 0.5);                      Gdk::Cairo::set_source_color(cr, black);
287              window->draw_line(black, x, 1, x, h1 - 2);  
288          }                      x3 = -1;
289                    }
290          if (region) {                  i++;
291              int x1 = int(w * (region->KeyRange.low) / 128.0 + 0.5);              }
292              int x2 = int(w * (region->KeyRange.high + 1) / 128.0 + 0.5);  
293              gc->set_foreground(red);              for (gig::Region* r = regions.first() ; r ; r = regions.next()) {
294              window->draw_rectangle(gc, true, x1 + 1, 1, x2 - x1 - 1, h1 - 2);                  int x = int(w * (r->KeyRange.low) / 128.0 + 0.5);
295                    cr->move_to(x + 0.5, 1);
296                    cr->line_to(x + 0.5, h1 - 1);
297                    cr->stroke();
298                }
299    
300                if (region) {
301                    int x1 = int(w * (region->KeyRange.low) / 128.0 + 0.5);
302                    int x2 = int(w * (region->KeyRange.high + 1) / 128.0 + 0.5);
303                    Gdk::Cairo::set_source_color(cr, red);
304                    cr->rectangle(x1 + 1, 1, x2 - x1 - 1, h1 - 2);
305                    cr->fill();
306                }
307          }          }
308    
309            cr->restore();
310      }      }
311    
312      return true;      return true;
313  }  }
314    
# Line 288  void RegionChooser::draw_digit(int key) Line 336  void RegionChooser::draw_digit(int key)
336      double text_w = double(rectangle.get_width()) / Pango::SCALE;      double text_w = double(rectangle.get_width()) / Pango::SCALE;
337      double text_h = double(rectangle.get_height()) / Pango::SCALE;      double text_h = double(rectangle.get_height()) / Pango::SCALE;
338      double x = w * (key + 0.75) / 128.0;      double x = w * (key + 0.75) / 128.0;
339      get_window()->draw_layout(get_style()->get_black_gc(), int(x - text_w / 2 + 1),      Cairo::RefPtr<Cairo::Context> cr = get_window()->create_cairo_context();
340                                int(h1 + h - text_h + 0.5), layout);      Gdk::Cairo::set_source_color(cr, black);
341        cr->move_to(int(x - text_w / 2 + 1), int(h1 + h - text_h + 0.5));
342    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 16) || GTKMM_MAJOR_VERSION < 2
343        pango_cairo_show_layout(cr->cobj(), layout->gobj());
344    #else
345        layout->show_in_cairo_context(cr);
346    #endif
347  }  }
348    
349  void RegionChooser::draw_region(int from, int to, const Gdk::Color& color)  void RegionChooser::draw_key(int key, const Gdk::Color& color)
350  {  {
351      const int h = KEYBOARD_HEIGHT;      const int h = KEYBOARD_HEIGHT;
352      const int w = get_width() - 1;      const int w = get_width() - 1;
353      const int bh = int(h * 0.55);      const int bh = int(h * 0.55);
354    
355      Glib::RefPtr<Gdk::Window> window = get_window();      Cairo::RefPtr<Cairo::Context> cr = get_window()->create_cairo_context();
356      gc->set_foreground(color);      Gdk::Cairo::set_source_color(cr, color);
357    
358      for (int i = from ; i < to ; i++) {      int note = (key + 3) % 12;
359          int note = (i + 3) % 12;      int x = int(w * key / 128.0 + 0.5) + 1;
360          int x = int(w * i / 128.0 + 0.5) + 1;      int x2 = int(w * (key + 1.5) / 128.0 + 0.5);
361          int x2 = int(w * (i + 1.5) / 128.0 + 0.5);      int x3 = int(w * (key + 1) / 128.0 + 0.5);
362          int x3 = int(w * (i + 1) / 128.0 + 0.5);      int x4 = int(w * (key - 0.5) / 128.0 + 0.5);
363          int x4 = int(w * (i - 0.5) / 128.0 + 0.5);      int w1 = x3 - x;
364          int w1 = x3 - x;      switch (note) {
365          switch (note) {      case 0: case 5: case 10:
366          case 0: case 5: case 10:          cr->rectangle(x, h1 + 1, w1, bh);
367              window->draw_rectangle(gc, true, x, h1 + 1, w1, bh);          cr->fill();
368              window->draw_rectangle(gc, true, x4 + 1, h1 + bh + 1, x2 - x4 - 1, h - bh - 2);          cr->rectangle(x4 + 1, h1 + bh + 1, x2 - x4 - 1, h - bh - 2);
369              break;          cr->fill();
370          case 2: case 7:          break;
371              window->draw_rectangle(gc, true, x, h1 + 1, w1, bh);      case 2: case 7:
372              window->draw_rectangle(gc, true, x4 + 1, h1 + bh + 1, x3 - x4 - 1, h - bh - 2);          cr->rectangle(x, h1 + 1, w1, bh);
373              break;          cr->fill();
374          case 3: case 8:          cr->rectangle(x4 + 1, h1 + bh + 1, x3 - x4 - 1, h - bh - 2);
375              window->draw_rectangle(gc, true, x, h1 + 1, w1, bh);          cr->fill();
376              window->draw_rectangle(gc, true, x, h1 + bh + 1, x2 - x, h - bh - 2);          break;
377              if (note == 3) draw_digit(i);      case 3: case 8:
378              break;          cr->rectangle(x, h1 + 1, w1, bh);
379          default:          cr->fill();
380              window->draw_rectangle(gc, true, x, h1 + 1, w1, bh - 1);          cr->rectangle(x, h1 + bh + 1, x2 - x, h - bh - 2);
381              break;          cr->fill();
382          }          if (note == 3) draw_digit(key);
383            break;
384        default:
385            cr->rectangle(x, h1 + 1, w1, bh - 1);
386            cr->fill();
387            break;
388      }      }
389  }  }
390    
# Line 480  gig::Region* RegionChooser::get_region(i Line 539  gig::Region* RegionChooser::get_region(i
539  {  {
540      gig::Region* prev_region = 0;      gig::Region* prev_region = 0;
541      gig::Region* next_region;      gig::Region* next_region;
542      for (gig::Region *r = regions.first() ; r ; r = next_region) {      for (gig::Region* r = regions.first() ; r ; r = next_region) {
543          next_region = regions.next();          next_region = regions.next();
544    
545          if (key < r->KeyRange.low) return 0;          if (key < r->KeyRange.low) return 0;
# Line 497  gig::Region* RegionChooser::get_region(i Line 556  gig::Region* RegionChooser::get_region(i
556  void RegionChooser::motion_resize_region(int x, int y)  void RegionChooser::motion_resize_region(int x, int y)
557  {  {
558      const int w = get_width() - 1;      const int w = get_width() - 1;
     Glib::RefPtr<Gdk::Window> window = get_window();  
559    
560      int k = int(double(x) / w * 128.0 + 0.5);      int k = int(double(x) / w * 128.0 + 0.5);
561    
# Line 505  void RegionChooser::motion_resize_region Line 563  void RegionChooser::motion_resize_region
563      else if (k > resize.max) k = resize.max;      else if (k > resize.max) k = resize.max;
564    
565      if (k != resize.pos) {      if (k != resize.pos) {
566            Cairo::RefPtr<Cairo::Context> cr = get_window()->create_cairo_context();
567            cr->set_line_width(1);
568    
569          if (resize.mode == resize.undecided) {          if (resize.mode == resize.undecided) {
570              if (k < resize.pos) {              if (k < resize.pos) {
571                  // edit high limit of prev_region                  // edit high limit of prev_region
# Line 517  void RegionChooser::motion_resize_region Line 578  void RegionChooser::motion_resize_region
578                  resize.mode = resize.moving_low_limit;                  resize.mode = resize.moving_low_limit;
579              }              }
580          }          }
581          Glib::RefPtr<const Gdk::GC> black = get_style()->get_black_gc();          const Gdk::Color white =
582          Glib::RefPtr<const Gdk::GC> white = get_style()->get_white_gc();              region == resize.region ? red : get_style()->get_white();
583          if (region == resize.region) {          const Gdk::Color bg = get_style()->get_bg(Gtk::STATE_NORMAL);
584              gc->set_foreground(red);  
             white = gc;  
         }  
         Glib::RefPtr<const Gdk::GC> bg = get_style()->get_bg_gc(Gtk::STATE_NORMAL);  
585          int prevx = int(w * resize.pos / 128.0 + 0.5);          int prevx = int(w * resize.pos / 128.0 + 0.5);
586          x = int(w * k / 128.0 + 0.5);          x = int(w * k / 128.0 + 0.5);
587    
588          if (resize.mode == resize.moving_high_limit) {          if (resize.mode == resize.moving_high_limit) {
589              if (k > resize.pos) {              if (k > resize.pos) {
590                  window->draw_rectangle(white, true, prevx, 1, x - prevx, h1 - 2);                  Gdk::Cairo::set_source_color(cr, white);
591                  window->draw_line(black, prevx, 0, x, 0);                  cr->rectangle(prevx, 1, x - prevx, h1 - 2);
592                  window->draw_line(black, prevx, h1 - 1, x, h1 - 1);                  cr->fill();
593    
594                    Gdk::Cairo::set_source_color(cr, black);
595                    cr->move_to(prevx, 0.5);
596                    cr->line_to(x + 1, 0.5);
597                    cr->move_to(prevx, h1 - 0.5);
598                    cr->line_to(x + 1, h1 - 0.5);
599                    cr->stroke();
600              } else {              } else {
601                  int xx = ((resize.pos == resize.max && resize.max != 128) ? 1 : 0);                  int xx = (resize.pos == resize.max &&
602                  window->draw_rectangle(bg, true, x + 1, 0, prevx - x - xx, h1);                            resize.max != 128) ? 1 : 0;
603                    Gdk::Cairo::set_source_color(cr, bg);
604                    cr->rectangle(x + 1, 0, prevx - x - xx, h1);
605                    cr->fill();
606              }              }
607          } else {          } else {
608              if (k < resize.pos) {              if (k < resize.pos) {
609                  window->draw_rectangle(white, true, x + 1, 1, prevx - x, h1 - 2);                  Gdk::Cairo::set_source_color(cr, white);
610                  window->draw_line(black, x, 0, prevx, 0);                  cr->rectangle(x + 1, 1, prevx - x, h1 - 2);
611                  window->draw_line(black, x, h1 - 1, prevx, h1 - 1);                  cr->fill();
612    
613                    Gdk::Cairo::set_source_color(cr, black);
614                    cr->move_to(x, 0.5);
615                    cr->line_to(prevx, 0.5);
616                    cr->move_to(x, h1 - 0.5);
617                    cr->line_to(prevx, h1 - 0.5);
618                    cr->stroke();
619              } else {              } else {
620                  int xx = ((resize.pos == resize.min && resize.min != 0) ? 1 : 0);                  int xx = (resize.pos == resize.min &&
621                  window->draw_rectangle(bg, true, prevx + xx, 0, x - prevx - xx, h1);                            resize.min != 0) ? 1 : 0;
622                    Gdk::Cairo::set_source_color(cr, bg);
623                    cr->rectangle(prevx + xx, 0, x - prevx - xx, h1);
624                    cr->fill();
625              }              }
626          }          }
627          window->draw_line(black, x, 1, x, h1 - 2);          Gdk::Cairo::set_source_color(cr, black);
628            cr->move_to(x + 0.5, 1);
629            cr->line_to(x + 0.5, h1 - 1);
630            cr->stroke();
631          resize.pos = k;          resize.pos = k;
632      }      }
633  }  }
# Line 554  void RegionChooser::motion_resize_region Line 635  void RegionChooser::motion_resize_region
635  void RegionChooser::motion_move_region(int x, int y)  void RegionChooser::motion_move_region(int x, int y)
636  {  {
637      const int w = get_width() - 1;      const int w = get_width() - 1;
638      Glib::RefPtr<Gdk::Window> window = get_window();      Cairo::RefPtr<Cairo::Context> cr = get_window()->create_cairo_context();
639        cr->set_line_width(1);
640    
641      int k = int(double(x - move.from_x) / w * 128.0 + 0.5);      int k = int(double(x - move.from_x) / w * 128.0 + 0.5);
642      if (k == move.pos) return;      if (k == move.pos) return;
# Line 627  void RegionChooser::motion_move_region(i Line 709  void RegionChooser::motion_move_region(i
709      k = new_k;      k = new_k;
710      if (k == move.pos) return;      if (k == move.pos) return;
711    
712      Glib::RefPtr<const Gdk::GC> bg = get_style()->get_bg_gc(Gtk::STATE_NORMAL);      const Gdk::Color bg = get_style()->get_bg(Gtk::STATE_NORMAL);
713      int prevx = int(w * (move.pos + region->KeyRange.low) / 128.0 + 0.5);      int prevx = int(w * (move.pos + region->KeyRange.low) / 128.0 + 0.5);
714      x = int(w * (k + region->KeyRange.low) / 128.0 + 0.5);      x = int(w * (k + region->KeyRange.low) / 128.0 + 0.5);
715      int prevx2 = int(w * (move.pos + region->KeyRange.high + 1) / 128.0 + 0.5);      int prevx2 = int(w * (move.pos + region->KeyRange.high + 1) / 128.0 + 0.5);
716      int x2 = int(w * (k + region->KeyRange.high + 1) / 128.0 + 0.5);      int x2 = int(w * (k + region->KeyRange.high + 1) / 128.0 + 0.5);
717      Glib::RefPtr<const Gdk::GC> black = get_style()->get_black_gc();      const Gdk::Color black = get_style()->get_black();
     gc->set_foreground(red);  
718    
719      if (!new_touch_left) window->draw_line(black, x, 1, x, h1 - 2);      if (!new_touch_left) {
720      if (!new_touch_right) window->draw_line(black, x2, 1, x2, h1 - 2);          Gdk::Cairo::set_source_color(cr, black);
721            cr->move_to(x + 0.5, 1);
722            cr->line_to(x + 0.5, h1 - 1);
723            cr->stroke();
724        }
725        if (!new_touch_right) {
726            Gdk::Cairo::set_source_color(cr, black);
727            cr->move_to(x2 + 0.5, 1);
728            cr->line_to(x2 + 0.5, h1 - 1);
729            cr->stroke();
730        }
731    
732      if (k > move.pos) {      if (k > move.pos) {
733          window->draw_rectangle(bg, true, prevx + (move.touch_left ? 1 : 0), 0,          Gdk::Cairo::set_source_color(cr, bg);
734                                 std::min(x, prevx2 + 1 - (move.touch_right ? 1 : 0)) -          cr->rectangle(prevx + (move.touch_left ? 1 : 0), 0,
735                                 (prevx + (move.touch_left ? 1 : 0)), h1);                        std::min(x, prevx2 + 1 - (move.touch_right ? 1 : 0)) -
736                          (prevx + (move.touch_left ? 1 : 0)), h1);
737          window->draw_line(black, std::max(x, prevx2 + 1), 0, x2, 0);          cr->fill();
738          window->draw_line(black, std::max(x, prevx2 + 1), h1 - 1, x2, h1 - 1);  
739          window->draw_rectangle(gc, true, std::max(x + 1, prevx2), 1,          Gdk::Cairo::set_source_color(cr, black);
740                                 x2 - std::max(x + 1, prevx2), h1 - 2);          cr->move_to(std::max(x, prevx2 + 1), 0.5);
741            cr->line_to(x2 + 1, 0.5);
742            cr->move_to(std::max(x, prevx2 + 1), h1 - 0.5);
743            cr->line_to(x2 + 1, h1 - 0.5);
744            cr->stroke();
745    
746            Gdk::Cairo::set_source_color(cr, red);
747            cr->rectangle(std::max(x + 1, prevx2), 1,
748                          x2 - std::max(x + 1, prevx2), h1 - 2);
749            cr->fill();
750      } else {      } else {
751          window->draw_rectangle(bg, true, std::max(x2 + 1, prevx + (move.touch_left ? 1 : 0)), 0,          Gdk::Cairo::set_source_color(cr, bg);
752                                 prevx2 + 1 - (move.touch_right ? 1 : 0) -          cr->rectangle(std::max(x2 + 1, prevx + (move.touch_left ? 1 : 0)), 0,
753                                 std::max(x2 + 1, prevx + (move.touch_left ? 1 : 0)), h1);                        prevx2 + 1 - (move.touch_right ? 1 : 0) -
754                          std::max(x2 + 1, prevx + (move.touch_left ? 1 : 0)), h1);
755          window->draw_line(black, x, 0, std::min(x2, prevx - 1), 0);          cr->fill();
756          window->draw_line(black, x, h1 - 1, std::min(x2, prevx - 1), h1 - 1);  
757            Gdk::Cairo::set_source_color(cr, black);
758          window->draw_rectangle(gc, true, x + 1, 1, std::min(x2 - 1, prevx) - x, h1 - 2);          cr->move_to(x, 0.5);
759            cr->line_to(std::min(x2, prevx - 1) + 1, 0.5);
760            cr->move_to(x, h1 - 0.5);
761            cr->line_to(std::min(x2, prevx - 1) + 1, h1 - 0.5);
762            cr->stroke();
763    
764            Gdk::Cairo::set_source_color(cr, red);
765            cr->rectangle(x + 1, 1, std::min(x2 - 1, prevx) - x, h1 - 2);
766            cr->fill();
767      }      }
768    
769      move.pos = k;      move.pos = k;

Legend:
Removed from v.2150  
changed lines
  Added in v.2151

  ViewVC Help
Powered by ViewVC