/[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 2168 by persson, Sun Nov 21 12:38:41 2010 UTC revision 2169 by persson, Sun Mar 6 07:51:04 2011 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2010 Andreas Persson   * Copyright (C) 2006-2011 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 24  Line 24 
24    
25  #include "global.h"  #include "global.h"
26    
27  #include "global.h"  DimRegionChooser::DimRegionChooser() :
28        red("#8070ff"),
29  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 10) || GTKMM_MAJOR_VERSION < 2      black("black"),
30        white("white")
 #define create_cairo_context()                                          \  
     gobj() ? Cairo::RefPtr<Cairo::Context>(                             \  
         new Cairo::Context(gdk_cairo_create(get_window()->gobj()))) :   \  
     Cairo::RefPtr<Cairo::Context>()  
   
 namespace Gdk {  
     namespace Cairo {  
         void set_source_color(const ::Cairo::RefPtr< ::Cairo::Context >& cr,  
                               const Gdk::Color& color);  
     }  
 }  
 #endif  
   
 DimRegionChooser::DimRegionChooser()  
31  {  {
     // get_window() would return 0 because the Gdk::Window has not yet been realized  
     // So we can only allocate the colors here - the rest will happen in on_realize().  
     Glib::RefPtr<Gdk::Colormap> colormap = get_default_colormap();  
   
     black = Gdk::Color("black");  
     white = Gdk::Color("white");  
     red = Gdk::Color("#8070ff");  
     blue = Gdk::Color("blue");  
     green = Gdk::Color("green");  
   
     colormap->alloc_color(black);  
     colormap->alloc_color(white);  
     colormap->alloc_color(red);  
     colormap->alloc_color(blue);  
     colormap->alloc_color(green);  
32      instrument = 0;      instrument = 0;
33      region = 0;      region = 0;
34      dimregno = -1;      dimregno = -1;
# Line 65  DimRegionChooser::DimRegionChooser() Line 36  DimRegionChooser::DimRegionChooser()
36      resize.active = false;      resize.active = false;
37      cursor_is_resize = false;      cursor_is_resize = false;
38      h = 20;      h = 20;
 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 18) || GTKMM_MAJOR_VERSION < 2  
     set_flags(Gtk::CAN_FOCUS);  
 #else  
39      set_can_focus();      set_can_focus();
 #endif  
40      add_events(Gdk::BUTTON_PRESS_MASK | Gdk::POINTER_MOTION_MASK |      add_events(Gdk::BUTTON_PRESS_MASK | Gdk::POINTER_MOTION_MASK |
41                 Gdk::POINTER_MOTION_HINT_MASK);                 Gdk::POINTER_MOTION_HINT_MASK);
42    
# Line 80  DimRegionChooser::~DimRegionChooser() Line 47  DimRegionChooser::~DimRegionChooser()
47  {  {
48  }  }
49    
50  bool DimRegionChooser::on_expose_event(GdkEventExpose* event)  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
51    bool DimRegionChooser::on_expose_event(GdkEventExpose* e)
52    {
53        return on_draw(get_window()->create_cairo_context());
54    }
55    #endif
56    
57    bool DimRegionChooser::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
58  {  {
59      if (!region) return true;      if (!region) return true;
60    
61      // This is where we draw on the window      // This is where we draw on the window
62      int w = get_width();      int w = get_width();
     Glib::RefPtr<Gdk::Window> window = get_window();  
63      Glib::RefPtr<Pango::Context> context = get_pango_context();      Glib::RefPtr<Pango::Context> context = get_pango_context();
64    
65      Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(context);      Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(context);
     Cairo::RefPtr<Cairo::Context> cr = get_window()->create_cairo_context();  
66      cr->set_line_width(1);      cr->set_line_width(1);
67    
     window->clear();  
   
68      // draw labels on the left (reflecting the dimension type)      // draw labels on the left (reflecting the dimension type)
69      int y = 0;      int y = 0;
70      double maxwidth = 0;      double maxwidth = 0;
# Line 150  bool DimRegionChooser::on_expose_event(G Line 120  bool DimRegionChooser::on_expose_event(G
120              double text_w = double(rectangle.get_width()) / Pango::SCALE;              double text_w = double(rectangle.get_width()) / Pango::SCALE;
121              if (text_w > maxwidth) maxwidth = text_w;              if (text_w > maxwidth) maxwidth = text_w;
122              double text_h = double(rectangle.get_height()) / Pango::SCALE;              double text_h = double(rectangle.get_height()) / Pango::SCALE;
123    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
124              const Gdk::Color fg = get_style()->get_fg(get_state());              const Gdk::Color fg = get_style()->get_fg(get_state());
125              Gdk::Cairo::set_source_color(cr, fg);  #else
126                const Gdk::RGBA fg = get_style_context()->get_color(get_state_flags());
127    #endif
128                Gdk::Cairo::set_source_rgba(cr, fg);
129              cr->move_to(4, int(y + (h - text_h) / 2 + 0.5));              cr->move_to(4, int(y + (h - text_h) / 2 + 0.5));
130  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 16) || GTKMM_MAJOR_VERSION < 2  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 16) || GTKMM_MAJOR_VERSION < 2
131              pango_cairo_show_layout(cr->cobj(), layout->gobj());              pango_cairo_show_layout(cr->cobj(), layout->gobj());
# Line 171  bool DimRegionChooser::on_expose_event(G Line 145  bool DimRegionChooser::on_expose_event(G
145          if (nbZones) {          if (nbZones) {
146              // draw focus rectangle around dimension's label and zones              // draw focus rectangle around dimension's label and zones
147              if (has_focus() && focus_line == i) {              if (has_focus() && focus_line == i) {
148    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
149                  Gdk::Rectangle farea(0, y, 150, 20);                  Gdk::Rectangle farea(0, y, 150, 20);
150                  get_style()->paint_focus(window, get_state(), farea, *this, "",                  get_style()->paint_focus(get_window(), get_state(), farea, *this, "",
151                                           0, y, label_width, 20);                                           0, y, label_width, 20);
152    #else
153                    get_style_context()->render_focus(cr, 0, y, label_width, 20);
154    #endif
155              }              }
156    
157              // draw top and bottom lines of dimension's zones              // draw top and bottom lines of dimension's zones
158              Gdk::Cairo::set_source_color(cr, black);              Gdk::Cairo::set_source_rgba(cr, black);
159              cr->move_to(label_width, y + 0.5);              cr->move_to(label_width, y + 0.5);
160              cr->line_to(w, y + 0.5);              cr->line_to(w, y + 0.5);
161              cr->move_to(w, y + h - 0.5);              cr->move_to(w, y + h - 0.5);
# Line 185  bool DimRegionChooser::on_expose_event(G Line 163  bool DimRegionChooser::on_expose_event(G
163              cr->stroke();              cr->stroke();
164    
165              // erase whole dimension's zones area              // erase whole dimension's zones area
166              Gdk::Cairo::set_source_color(cr, white);              Gdk::Cairo::set_source_rgba(cr, white);
167              cr->rectangle(label_width + 1, y + 1, (w - label_width - 2), h - 2);              cr->rectangle(label_width + 1, y + 1, (w - label_width - 2), h - 2);
168              cr->fill();              cr->fill();
169    
# Line 201  bool DimRegionChooser::on_expose_event(G Line 179  bool DimRegionChooser::on_expose_event(G
179                   region->pDimensionRegions[c]->VelocityUpperLimit));                   region->pDimensionRegions[c]->VelocityUpperLimit));
180    
181              // draw dimension's zone borders              // draw dimension's zone borders
182              Gdk::Cairo::set_source_color(cr, black);              Gdk::Cairo::set_source_rgba(cr, black);
183              if (customsplits) {              if (customsplits) {
184                  cr->move_to(label_width + 0.5, y + 1);                  cr->move_to(label_width + 0.5, y + 1);
185                  cr->line_to(label_width + 0.5, y + h - 1);                  cr->line_to(label_width + 0.5, y + h - 1);
# Line 226  bool DimRegionChooser::on_expose_event(G Line 204  bool DimRegionChooser::on_expose_event(G
204    
205              // draw fill for currently selected zone              // draw fill for currently selected zone
206              if (dimregno >= 0) {              if (dimregno >= 0) {
207                  Gdk::Cairo::set_source_color(cr, red);                  Gdk::Cairo::set_source_rgba(cr, red);
208                  int dr = (dimregno >> bitpos) & ((1 << region->pDimensionDefinitions[i].bits) - 1);                  int dr = (dimregno >> bitpos) & ((1 << region->pDimensionDefinitions[i].bits) - 1);
209                  if (customsplits) {                  if (customsplits) {
210                      int x1 = 0;                      int x1 = 0;
# Line 263  bool DimRegionChooser::on_expose_event(G Line 241  bool DimRegionChooser::on_expose_event(G
241      return true;      return true;
242  }  }
243    
 void DimRegionChooser::on_size_request(GtkRequisition* requisition)  
 {  
     *requisition = GtkRequisition();  
     requisition->height = region ? nbDimensions * 20 : 0;  
     requisition->width = 800;  
 }  
   
244  void DimRegionChooser::set_region(gig::Region* region)  void DimRegionChooser::set_region(gig::Region* region)
245  {  {
246      this->region = region;      this->region = region;
# Line 291  void DimRegionChooser::set_region(gig::R Line 262  void DimRegionChooser::set_region(gig::R
262          dimreg = 0;          dimreg = 0;
263      }      }
264      dimregion_selected();      dimregion_selected();
265        set_size_request(800, region ? nbDimensions * 20 : 0);
266    
267      queue_resize();      queue_resize();
268  }  }
269    
# Line 321  void DimRegionChooser::get_dimregions(co Line 294  void DimRegionChooser::get_dimregions(co
294  bool DimRegionChooser::on_button_release_event(GdkEventButton* event)  bool DimRegionChooser::on_button_release_event(GdkEventButton* event)
295  {  {
296      if (resize.active) {      if (resize.active) {
297    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
298          get_window()->pointer_ungrab(event->time);          get_window()->pointer_ungrab(event->time);
299    #else
300            Glib::wrap(event->device, true)->ungrab(event->time);
301    #endif
302          resize.active = false;          resize.active = false;
303    
304          if (region->pDimensionDefinitions[resize.dimension].dimension == gig::dimension_velocity) {          if (region->pDimensionDefinitions[resize.dimension].dimension == gig::dimension_velocity) {
# Line 412  bool DimRegionChooser::on_button_press_e Line 389  bool DimRegionChooser::on_button_press_e
389          event->x >= label_width && event->x < w) {          event->x >= label_width && event->x < w) {
390    
391          if (is_in_resize_zone(event->x, event->y)) {          if (is_in_resize_zone(event->x, event->y)) {
392              Gdk::Cursor double_arrow(Gdk::SB_H_DOUBLE_ARROW);  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
393              get_window()->pointer_grab(false,              get_window()->pointer_grab(false,
394                                         Gdk::BUTTON_RELEASE_MASK |                                         Gdk::BUTTON_RELEASE_MASK |
395                                         Gdk::POINTER_MOTION_MASK |                                         Gdk::POINTER_MOTION_MASK |
396                                         Gdk::POINTER_MOTION_HINT_MASK,                                         Gdk::POINTER_MOTION_HINT_MASK,
397                                         double_arrow, event->time);                                         Gdk::Cursor(Gdk::SB_H_DOUBLE_ARROW),
398                                           event->time);
399    #else
400                Glib::wrap(event->device, true)->grab(get_window(),
401                                                      Gdk::OWNERSHIP_NONE,
402                                                      false,
403                                                      Gdk::BUTTON_RELEASE_MASK |
404                                                      Gdk::POINTER_MOTION_MASK |
405                                                      Gdk::POINTER_MOTION_HINT_MASK,
406                                                      Gdk::Cursor::create(Gdk::SB_H_DOUBLE_ARROW),
407                                                      event->time);
408    #endif
409              resize.active = true;              resize.active = true;
410          } else {          } else {
411              int ydim = int(event->y / h);              int ydim = int(event->y / h);
# Line 508  bool DimRegionChooser::on_motion_notify_ Line 496  bool DimRegionChooser::on_motion_notify_
496    
497              if (resize.selected == resize.none) {              if (resize.selected == resize.none) {
498                  if (resize.pos != resize.min && resize.pos != resize.max) {                  if (resize.pos != resize.min && resize.pos != resize.max) {
499                      Gdk::Cairo::set_source_color(cr, white);                      Gdk::Cairo::set_source_rgba(cr, white);
500                      cr->move_to(prevx + 0.5, y + 1);                      cr->move_to(prevx + 0.5, y + 1);
501                      cr->line_to(prevx + 0.5, y + h - 1);                      cr->line_to(prevx + 0.5, y + h - 1);
502                      cr->stroke();                      cr->stroke();
503                  }                  }
504              } else {              } else {
505                  Gdk::Color left;                  Gdk::RGBA left;
506                  Gdk::Color right;                  Gdk::RGBA right;
507                  if (resize.selected == resize.left) {                  if (resize.selected == resize.left) {
508                      left = red;                      left = red;
509                      right = white;                      right = white;
# Line 526  bool DimRegionChooser::on_motion_notify_ Line 514  bool DimRegionChooser::on_motion_notify_
514    
515                  if (k > resize.pos) {                  if (k > resize.pos) {
516                      int xx = resize.pos == resize.min ? 1 : 0;                      int xx = resize.pos == resize.min ? 1 : 0;
517                      Gdk::Cairo::set_source_color(cr, left);                      Gdk::Cairo::set_source_rgba(cr, left);
518                      cr->rectangle(prevx + xx, y + 1, x - prevx - xx, h - 2);                      cr->rectangle(prevx + xx, y + 1, x - prevx - xx, h - 2);
519                  } else {                  } else {
520                      int xx = resize.pos == resize.max ? 0 : 1;                      int xx = resize.pos == resize.max ? 0 : 1;
521                      Gdk::Cairo::set_source_color(cr, right);                      Gdk::Cairo::set_source_rgba(cr, right);
522                      cr->rectangle(x, y + 1, prevx - x + xx, h - 2);                      cr->rectangle(x, y + 1, prevx - x + xx, h - 2);
523                  }                  }
524                  cr->fill();                  cr->fill();
525              }              }
526              Gdk::Cairo::set_source_color(cr, black);              Gdk::Cairo::set_source_rgba(cr, black);
527              cr->move_to(x + 0.5, y + 1);              cr->move_to(x + 0.5, y + 1);
528              cr->line_to(x + 0.5, y + h - 1);              cr->line_to(x + 0.5, y + h - 1);
529              cr->stroke();              cr->stroke();
# Line 545  bool DimRegionChooser::on_motion_notify_ Line 533  bool DimRegionChooser::on_motion_notify_
533      } else {      } else {
534          if (is_in_resize_zone(x, y)) {          if (is_in_resize_zone(x, y)) {
535              if (!cursor_is_resize) {              if (!cursor_is_resize) {
536                  Gdk::Cursor double_arrow(Gdk::SB_H_DOUBLE_ARROW);  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
537                  window->set_cursor(double_arrow);                  window->set_cursor(Gdk::Cursor(Gdk::SB_H_DOUBLE_ARROW));
538    #else
539                    window->set_cursor(Gdk::Cursor::create(Gdk::SB_H_DOUBLE_ARROW));
540    #endif
541                  cursor_is_resize = true;                  cursor_is_resize = true;
542              }              }
543          } else if (cursor_is_resize) {          } else if (cursor_is_resize) {

Legend:
Removed from v.2168  
changed lines
  Added in v.2169

  ViewVC Help
Powered by ViewVC