/[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 2246 by persson, Fri Aug 19 10:55:41 2011 UTC revision 2470 by persson, Sun Sep 15 13:31:04 2013 UTC
# Line 21  Line 21 
21  #include <cairomm/context.h>  #include <cairomm/context.h>
22  #include <gdkmm/cursor.h>  #include <gdkmm/cursor.h>
23  #include <gdkmm/general.h>  #include <gdkmm/general.h>
24    #include <glibmm/stringutils.h>
25    
26  #include "global.h"  #include "global.h"
27    
# Line 256  bool DimRegionChooser::on_draw(const Cai Line 257  bool DimRegionChooser::on_draw(const Cai
257                      Gdk::Cairo::set_source_rgba(cr, red);                      Gdk::Cairo::set_source_rgba(cr, red);
258                      int dr = (dimregno >> bitpos) &                      int dr = (dimregno >> bitpos) &
259                          ((1 << region->pDimensionDefinitions[i].bits) - 1);                          ((1 << region->pDimensionDefinitions[i].bits) - 1);
260                        
261                        int x1 = -1, x2 = -1;
262                      if (customsplits) {                      if (customsplits) {
263                          int x1 = label_width;                          x1 = label_width;
264                          for (int j = 0 ; j < nbZones && x1 + 1 < clipx2 ; j++) {                          for (int j = 0 ; j < nbZones && x1 + 1 < clipx2 ; j++) {
265                              gig::DimensionRegion* d =                              gig::DimensionRegion* d =
266                                  region->pDimensionRegions[c + (j << bitpos)];                                  region->pDimensionRegions[c + (j << bitpos)];
# Line 266  bool DimRegionChooser::on_draw(const Cai Line 269  bool DimRegionChooser::on_draw(const Cai
269                                  upperLimit = d->VelocityUpperLimit;                                  upperLimit = d->VelocityUpperLimit;
270                              }                              }
271                              int v = upperLimit + 1;                              int v = upperLimit + 1;
272                              int x2 = int((w - label_width - 1) * v / 128.0 +                              x2 = int((w - label_width - 1) * v / 128.0 +
273                                           0.5) + label_width;                                       0.5) + label_width;
274                              if (j == dr && x1 < x2) {                              if (j == dr && x1 < x2) {
275                                  cr->rectangle(x1 + 1, y + 1,                                  cr->rectangle(x1 + 1, y + 1,
276                                                (x2 - x1) - 1, h - 2);                                                (x2 - x1) - 1, h - 2);
# Line 278  bool DimRegionChooser::on_draw(const Cai Line 281  bool DimRegionChooser::on_draw(const Cai
281                          }                          }
282                      } else {                      } else {
283                          if (dr < nbZones) {                          if (dr < nbZones) {
284                              int x1 = int((w - label_width - 1) * dr /                              x1 = int((w - label_width - 1) * dr /
285                                           double(nbZones) + 0.5);                                       double(nbZones) + 0.5);
286                              int x2 = int((w - label_width - 1) * (dr + 1) /                              x2 = int((w - label_width - 1) * (dr + 1) /
287                                           double(nbZones) + 0.5);                                       double(nbZones) + 0.5);
288                              cr->rectangle(label_width + x1 + 1, y + 1,                              cr->rectangle(label_width + x1 + 1, y + 1,
289                                            (x2 - x1) - 1, h - 2);                                            (x2 - x1) - 1, h - 2);
290                              cr->fill();                              cr->fill();
291                          }                          }
292                      }                      }
293    
294                        // draw text showing the beginning of the dimension zone
295                        // as numeric value to the user
296                        if (x1 >= 0) {
297                            Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(context);
298                            int v = roundf(float(x1 - label_width) / float(w - label_width) * 127.f);
299                            if (dr > 0) v++;
300                            layout->set_text(Glib::Ascii::dtostr(v));
301                            Gdk::Cairo::set_source_rgba(cr, black);
302                            Pango::Rectangle rect = layout->get_logical_extents();
303                            
304                            int text_width, text_height;
305                            // get the text dimensions
306                            layout->get_pixel_size(text_width, text_height);
307                            // move text to the right end of the dimension zone
308                            cr->move_to(x1 + 1, y + 1);
309    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 16) || GTKMM_MAJOR_VERSION < 2
310                            pango_cairo_show_layout(cr->cobj(), layout->gobj());
311    #else
312                            layout->show_in_cairo_context(cr);
313    #endif
314                        }
315                        // draw text showing the end of the dimension zone
316                        // as numeric value to the user
317                        if (x2 >= 0) {
318                            Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(context);
319                            const int v = roundf(float(x2 - label_width) / float(w - label_width) * 127.f);
320                            layout->set_text(Glib::Ascii::dtostr(v));
321                            Gdk::Cairo::set_source_rgba(cr, black);
322                            Pango::Rectangle rect = layout->get_logical_extents();
323                            
324                            int text_width, text_height;
325                            // get the text dimensions
326                            layout->get_pixel_size(text_width, text_height);
327                            // move text to the right end of the dimension zone
328                            cr->move_to(x2 - text_width - 1, y + 1);
329    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 16) || GTKMM_MAJOR_VERSION < 2
330                            pango_cairo_show_layout(cr->cobj(), layout->gobj());
331    #else
332                            layout->show_in_cairo_context(cr);
333    #endif
334                        }
335                  }                  }
336              }              }
337    

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

  ViewVC Help
Powered by ViewVC