/[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 2556 by schoenebeck, Fri May 16 23:19:23 2014 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2011 Andreas Persson   * Copyright (C) 2006-2014 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 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    #include <gtkmm/stock.h>
26    #include <glibmm/ustring.h>
27    #include <gtkmm/messagedialog.h>
28    
29  #include "global.h"  #include "global.h"
30    
# Line 37  DimRegionChooser::DimRegionChooser() : Line 41  DimRegionChooser::DimRegionChooser() :
41      cursor_is_resize = false;      cursor_is_resize = false;
42      h = 20;      h = 20;
43      set_can_focus();      set_can_focus();
44    
45        actionGroup = Gtk::ActionGroup::create();
46        actionGroup->add(
47            Gtk::Action::create("SplitDimZone", _("Split Dimensions Zone")),
48            sigc::mem_fun(*this, &DimRegionChooser::split_dimension_zone)
49        );
50        actionGroup->add(
51            Gtk::Action::create("DeleteDimZone", _("Delete Dimension Zone")),
52            sigc::mem_fun(*this, &DimRegionChooser::delete_dimension_zone)
53        );
54    
55        uiManager = Gtk::UIManager::create();
56        uiManager->insert_action_group(actionGroup);
57        Glib::ustring ui_info =
58            "<ui>"
59            "  <popup name='PopupMenuInsideDimRegion'>"
60            "    <menuitem action='SplitDimZone'/>"
61            "    <menuitem action='DeleteDimZone'/>"
62            "  </popup>"
63    //         "  <popup name='PopupMenuOutsideDimRegion'>"
64    //         "    <menuitem action='Add'/>"
65    //         "  </popup>"
66            "</ui>";
67        uiManager->add_ui_from_string(ui_info);
68    
69        popup_menu_inside_dimregion = dynamic_cast<Gtk::Menu*>(
70            uiManager->get_widget("/PopupMenuInsideDimRegion"));
71    //     popup_menu_outside_dimregion = dynamic_cast<Gtk::Menu*>(
72    //         uiManager->get_widget("/PopupMenuOutsideDimRegion"));
73    
74      add_events(Gdk::BUTTON_PRESS_MASK | Gdk::POINTER_MOTION_MASK |      add_events(Gdk::BUTTON_PRESS_MASK | Gdk::POINTER_MOTION_MASK |
75                 Gdk::POINTER_MOTION_HINT_MASK);                 Gdk::POINTER_MOTION_HINT_MASK);
76    
77      for (int i = 0 ; i < 256 ; i++) dimvalue[i] = 0;      for (int i = 0 ; i < 256 ; i++) dimvalue[i] = 0;
78      labels_changed = true;      labels_changed = true;
79    
80        set_tooltip_text(_("Right click here for options on altering dimension zones."));
81  }  }
82    
83  DimRegionChooser::~DimRegionChooser()  DimRegionChooser::~DimRegionChooser()
# Line 256  bool DimRegionChooser::on_draw(const Cai Line 292  bool DimRegionChooser::on_draw(const Cai
292                      Gdk::Cairo::set_source_rgba(cr, red);                      Gdk::Cairo::set_source_rgba(cr, red);
293                      int dr = (dimregno >> bitpos) &                      int dr = (dimregno >> bitpos) &
294                          ((1 << region->pDimensionDefinitions[i].bits) - 1);                          ((1 << region->pDimensionDefinitions[i].bits) - 1);
295                        
296                        int x1 = -1, x2 = -1;
297                      if (customsplits) {                      if (customsplits) {
298                          int x1 = label_width;                          x1 = label_width;
299                          for (int j = 0 ; j < nbZones && x1 + 1 < clipx2 ; j++) {                          for (int j = 0 ; j < nbZones && x1 + 1 < clipx2 ; j++) {
300                              gig::DimensionRegion* d =                              gig::DimensionRegion* d =
301                                  region->pDimensionRegions[c + (j << bitpos)];                                  region->pDimensionRegions[c + (j << bitpos)];
# Line 266  bool DimRegionChooser::on_draw(const Cai Line 304  bool DimRegionChooser::on_draw(const Cai
304                                  upperLimit = d->VelocityUpperLimit;                                  upperLimit = d->VelocityUpperLimit;
305                              }                              }
306                              int v = upperLimit + 1;                              int v = upperLimit + 1;
307                              int x2 = int((w - label_width - 1) * v / 128.0 +                              x2 = int((w - label_width - 1) * v / 128.0 +
308                                           0.5) + label_width;                                       0.5) + label_width;
309                              if (j == dr && x1 < x2) {                              if (j == dr && x1 < x2) {
310                                  cr->rectangle(x1 + 1, y + 1,                                  cr->rectangle(x1 + 1, y + 1,
311                                                (x2 - x1) - 1, h - 2);                                                (x2 - x1) - 1, h - 2);
# Line 278  bool DimRegionChooser::on_draw(const Cai Line 316  bool DimRegionChooser::on_draw(const Cai
316                          }                          }
317                      } else {                      } else {
318                          if (dr < nbZones) {                          if (dr < nbZones) {
319                              int x1 = int((w - label_width - 1) * dr /                              x1 = int((w - label_width - 1) * dr /
320                                           double(nbZones) + 0.5);                                       double(nbZones) + 0.5);
321                              int x2 = int((w - label_width - 1) * (dr + 1) /                              x2 = int((w - label_width - 1) * (dr + 1) /
322                                           double(nbZones) + 0.5);                                       double(nbZones) + 0.5);
323                              cr->rectangle(label_width + x1 + 1, y + 1,                              cr->rectangle(label_width + x1 + 1, y + 1,
324                                            (x2 - x1) - 1, h - 2);                                            (x2 - x1) - 1, h - 2);
325                              cr->fill();                              cr->fill();
326                          }                          }
327                      }                      }
328    
329                        // draw text showing the beginning of the dimension zone
330                        // as numeric value to the user
331                        if (x1 >= 0) {
332                            Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(context);
333                            int v = roundf(float(x1 - label_width) / float(w - label_width) * 127.f);
334                            if (dr > 0) v++;
335                            layout->set_text(Glib::Ascii::dtostr(v));
336                            Gdk::Cairo::set_source_rgba(cr, black);
337                            Pango::Rectangle rect = layout->get_logical_extents();
338                            
339                            int text_width, text_height;
340                            // get the text dimensions
341                            layout->get_pixel_size(text_width, text_height);
342                            // move text to the right end of the dimension zone
343                            cr->move_to(x1 + 1, y + 1);
344    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 16) || GTKMM_MAJOR_VERSION < 2
345                            pango_cairo_show_layout(cr->cobj(), layout->gobj());
346    #else
347                            layout->show_in_cairo_context(cr);
348    #endif
349                        }
350                        // draw text showing the end of the dimension zone
351                        // as numeric value to the user
352                        if (x2 >= 0) {
353                            Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(context);
354                            const int v = roundf(float(x2 - label_width) / float(w - label_width) * 127.f);
355                            layout->set_text(Glib::Ascii::dtostr(v));
356                            Gdk::Cairo::set_source_rgba(cr, black);
357                            Pango::Rectangle rect = layout->get_logical_extents();
358                            
359                            int text_width, text_height;
360                            // get the text dimensions
361                            layout->get_pixel_size(text_width, text_height);
362                            // move text to the right end of the dimension zone
363                            cr->move_to(x2 - text_width - 1, y + 1);
364    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 16) || GTKMM_MAJOR_VERSION < 2
365                            pango_cairo_show_layout(cr->cobj(), layout->gobj());
366    #else
367                            layout->show_in_cairo_context(cr);
368    #endif
369                        }
370                  }                  }
371              }              }
372    
# Line 325  void DimRegionChooser::set_region(gig::R Line 405  void DimRegionChooser::set_region(gig::R
405      queue_resize();      queue_resize();
406  }  }
407    
408    void DimRegionChooser::refresh_all() {
409        set_region(region);
410    }
411    
412  void DimRegionChooser::get_dimregions(const gig::Region* region, bool stereo,  void DimRegionChooser::get_dimregions(const gig::Region* region, bool stereo,
413                                        std::set<gig::DimensionRegion*>& dimregs) const                                        std::set<gig::DimensionRegion*>& dimregs) const
# Line 521  bool DimRegionChooser::on_button_press_e Line 604  bool DimRegionChooser::on_button_press_e
604    
605              dimregno = c | (z << bitpos);              dimregno = c | (z << bitpos);
606    
607                this->dimtype = dim;
608                this->dimzone = z;
609    
610              focus_line = dim;              focus_line = dim;
611              if (has_focus()) queue_draw();              if (has_focus()) queue_draw();
612              else grab_focus();              else grab_focus();
613              dimreg = region->pDimensionRegions[dimregno];              dimreg = region->pDimensionRegions[dimregno];
614              dimregion_selected();              dimregion_selected();
615    
616                if (event->button == 3) {
617                    printf("dimregion right click\n");
618                    popup_menu_inside_dimregion->popup(event->button, event->time);
619                }
620          }          }
621      }      }
622      return true;      return true;
# Line 705  bool DimRegionChooser::on_focus(Gtk::Dir Line 796  bool DimRegionChooser::on_focus(Gtk::Dir
796          // TODO: öka eller minska värde!          // TODO: öka eller minska värde!
797      }      }
798  }  }
799    
800    void DimRegionChooser::split_dimension_zone() {
801        printf("split_dimension_zone() type=%d, zone=%d\n", dimtype, dimzone);
802        try {
803            region->SplitDimensionZone(
804                region->pDimensionDefinitions[dimtype].dimension,
805                dimzone
806            );
807        } catch (RIFF::Exception e) {
808            Gtk::MessageDialog msg(e.Message, false, Gtk::MESSAGE_ERROR);
809            msg.run();
810        } catch (...) {
811            Glib::ustring txt = _("An unknown exception occurred!");
812            Gtk::MessageDialog msg(txt, false, Gtk::MESSAGE_ERROR);
813            msg.run();
814        }
815        refresh_all();
816    }
817    
818    void DimRegionChooser::delete_dimension_zone() {
819        printf("delete_dimension_zone() type=%d, zone=%d\n", dimtype, dimzone);
820        try {
821            region->DeleteDimensionZone(
822                region->pDimensionDefinitions[dimtype].dimension,
823                dimzone
824            );
825        } catch (RIFF::Exception e) {
826            Gtk::MessageDialog msg(e.Message, false, Gtk::MESSAGE_ERROR);
827            msg.run();
828        } catch (...) {
829            Glib::ustring txt = _("An unknown exception occurred!");
830            Gtk::MessageDialog msg(txt, false, Gtk::MESSAGE_ERROR);
831            msg.run();
832        }
833        refresh_all();
834    }

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

  ViewVC Help
Powered by ViewVC