COIN-OR::LEMON - Graph Library

Changeset 184:4e8704aae278 in glemon-0.x


Ignore:
Timestamp:
01/10/07 15:37:46 (17 years ago)
Author:
Akos Ladanyi
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/glemon/trunk@3125
Message:

Added support for setting the background form an image file.

Files:
2 added
2 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • Makefile.am

    r173 r184  
    5050        file_chooser_extra_widget.h \
    5151        file_chooser_extra_widget.cc \
    52         map_window.h \
    53         map_window.cc
     52        background_chooser_dialog.h \
     53        background_chooser_dialog.cc
    5454
    5555glemon_CXXFLAGS = $(GTK_CFLAGS) $(LEMON_CFLAGS)
  • graph_displayer_canvas.cc

    r180 r184  
    2626  isbutton(0), active_item(NULL), target_item(NULL), nodemap_to_edit(""),
    2727  edgemap_to_edit(""), autoscale(true), zoomtrack(false), radius_size(20), edge_width(10),
    28   was_redesigned(false), is_drawn(false), mytab(mainw)
     28  was_redesigned(false), is_drawn(false), mytab(mainw),
     29  background_set(false)
    2930{
    3031  //base event handler is move tool
     
    3536  active_edge=INVALID;
    3637  forming_edge=INVALID;
     38
     39  setBackground();
     40}
     41
     42void GraphDisplayerCanvas::setBackground()
     43{
     44  if (background_set)
     45  {
     46    delete background;
     47  }
     48  if (mytab.mapstorage.isBackgroundSet())
     49  {
     50    background_set = true;
     51    refBackground = Gdk::Pixbuf::create_from_file(
     52      mytab.mapstorage.getBackgroundFilename());
     53    background = new Gnome::Canvas::Pixbuf(
     54        *(root()),
     55        0.0 - refBackground->get_width() / 2.0,
     56        0.0 - refBackground->get_height() / 2.0,
     57        refBackground);
     58    background->lower_to_bottom();
     59  }
     60  else
     61  {
     62    background_set = false;
     63  }
    3764}
    3865
  • graph_displayer_canvas.h

    r179 r184  
    442442
    443443  XY calcArrowPos(XY, XY, XY, XY, int);
     444
     445  bool background_set;
     446  Glib::RefPtr<Gdk::Pixbuf> refBackground;
     447  Gnome::Canvas::Pixbuf *background;
     448public:
     449  void setBackground();
    444450};
    445451
  • main_win.cc

    r174 r184  
    2323#include "main_win.h"
    2424#include "guipixbufs.h"
     25#include "background_chooser_dialog.h"
    2526
    2627#include "i18n.h"
     
    114115  ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
    115116      sigc::mem_fun(*this, &MainWin::zoom100));
     117  ag->add( Gtk::Action::create("SetBackground", _("Set Background...")),
     118            sigc::mem_fun(*this, &MainWin::createBackgroundChooser));
    116119 
    117120  ag->add( Gtk::Action::create("ShowMenu", _("_Show")) );
     
    174177      "      <menuitem action='ViewZoom100' />"
    175178      "      <menuitem action='ViewZoomFit' />"
     179      "      <menuitem action='SetBackground' />"
    176180      "    </menu>"
    177181      "    <menu action='ShowMenu'>"
     
    581585  tabs[active_tab]->reDesignGraph();
    582586}
     587
     588void MainWin::createBackgroundChooser()
     589{
     590  BackgroundChooserDialog dialog(&(tabs[active_tab]->mapstorage));
     591  dialog.run();
     592}
  • main_win.h

    r174 r184  
    262262
    263263  virtual void reDesignGraph();
     264
     265  void createBackgroundChooser();
    264266};
    265267
  • mapstorage.cc

    r177 r184  
    1818
    1919#include "mapstorage.h"
     20#include "nbtab.h"
    2021#include "gui_writer.h"
    2122#include "gui_reader.h"
     
    2829const double p_d=40000;
    2930
    30 MapStorage::MapStorage() : modified(false), file_name(""), arrow_pos_read_ok(false), iterations(i_d), attraction(a_d), propulsation(p_d)
     31MapStorage::MapStorage(NoteBookTab& tab) : mytab(tab), modified(false), file_name(""), arrow_pos_read_ok(false), iterations(i_d), attraction(a_d), propulsation(p_d), background_set(false)
    3132{
    3233  nodemap_storage["coordinates_x"] = new Graph::NodeMap<double>(graph);
     
    553554  signal_design_win.emit(attraction, propulsation, iterations);
    554555}
     556
     557void MapStorage::setBackground(const std::string& file_name)
     558{
     559  if (file_name == background_file_name) return;
     560  if (file_name == "")
     561  {
     562    background_file_name = "";
     563    background_set = false;
     564  }
     565  else
     566  {
     567    background_file_name = file_name;
     568    background_set = true;
     569  }
     570  mytab.gd_canvas->setBackground();
     571}
     572
     573const std::string& MapStorage::getBackgroundFilename()
     574{
     575  return background_file_name;
     576}
     577
     578bool MapStorage::isBackgroundSet()
     579{
     580  return background_set;
     581}
     582
     583double MapStorage::getBackgroundScaling()
     584{
     585  return background_scaling;
     586}
     587
     588void MapStorage::setBackgroundScaling(double scaling)
     589{
     590  background_scaling = scaling;
     591}
  • mapstorage.h

    r177 r184  
    2525#include "xymap.h"
    2626#include <libgnomecanvasmm.h>
     27
     28class NoteBookTab;
    2729
    2830///class MapStorage handles NodeMaps and EdgeMaps.
     
    3941class MapStorage
    4042{
     43private:
     44  std::string background_file_name;
     45  bool background_set;
     46  double background_scaling;
     47  NoteBookTab& mytab;
    4148public:
    42   enum value {DOUBLE, STRING};
    43   enum type {NORMAL, GUI};
    44 
     49  void setBackground(const std::string& file_name);
     50  const std::string& getBackgroundFilename();
     51  bool isBackgroundSet();
     52  double getBackgroundScaling();
     53  void setBackgroundScaling(double scaling);
    4554  ///The graph for which the datas are stored.
    4655  Graph graph;
     
    123132  ///Its all activity is initializing default values
    124133  ///for different visualization attributes.
    125   MapStorage();
     134  MapStorage(NoteBookTab& tab);
    126135
    127136  ///Destructor of MapStorage
  • nbtab.cc

    r177 r184  
    2020#include "file_chooser_extra_widget.h"
    2121
    22 NoteBookTab::NoteBookTab():mapwinexists(false), designwinexists(false)
     22NoteBookTab::NoteBookTab():mapwinexists(false), designwinexists(false), mapstorage(*this)
    2323{
    2424  Gtk::ScrolledWindow *pScrolledWindow = manage(new Gtk::ScrolledWindow);
Note: See TracChangeset for help on using the changeset viewer.