[Lemon-commits] [lemon_svn] ladanyi: r1917 - hugo/trunk/gui
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:48:46 CET 2006
Author: ladanyi
Date: Thu Jun 2 01:30:13 2005
New Revision: 1917
Modified:
hugo/trunk/gui/graph_displayer_canvas.cc
hugo/trunk/gui/graph_displayer_canvas.h
hugo/trunk/gui/main_win.cc
hugo/trunk/gui/main_win.h
Log:
- added toolbar
- added ScrolledWindow for the canvas
- zooming
Modified: hugo/trunk/gui/graph_displayer_canvas.cc
==============================================================================
--- hugo/trunk/gui/graph_displayer_canvas.cc (original)
+++ hugo/trunk/gui/graph_displayer_canvas.cc Thu Jun 2 01:30:13 2005
@@ -3,6 +3,7 @@
GraphDisplayerCanvas::GraphDisplayerCanvas(Graph & gr, CoordinatesMap & cm, MapStorage & ms):g(gr),nodesmap(g),edgesmap(g),edgetextmap(g),displayed_graph(*(root()), 0, 0),mapstorage(ms),isbutton(false),active_item(NULL)
{
+ //set_center_scroll_region(true);
//first edges are drawn, to hide joining with nodes later
@@ -50,6 +51,7 @@
(nodesmap[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),i));
}
+/*
//setting zoom to be able to see the whole graph on the canvas
double biggest_x=(abs(maxx)>abs(minx))?(abs(maxx)+80):(abs(minx)+80);
@@ -59,7 +61,8 @@
std::cout<<abs(maxx)<<" "<<abs(minx)<<" big x "<<biggest_x<<" "<<abs(maxy)<<" "<<abs(miny)<<" big y "<<biggest_y<<std::endl;
std::cout<<maxx<<" "<<minx<<" big x "<<biggest_x<<" "<<maxy<<" "<<miny<<" big y "<<biggest_y<<std::endl;
std::cout<<"dx "<<(maxx-minx)<<" dy "<<(maxy-miny)<<" xrate "<<((maxx-minx)/WIN_WIDTH)<<" yrate "<<((maxy-miny)/WIN_HEIGHT)<<std::endl;
-
+*/
+ updateScrollRegion();
}
GraphDisplayerCanvas::~GraphDisplayerCanvas()
@@ -173,48 +176,6 @@
return 0;
};
-
-int GraphDisplayerCanvas::rezoom ()
-{
-
- //searches for the minimum and the maximum
- //value of the coordinates of the nodes to
- //set the pixel rpo unit to a value to be
- //able to see the whole graph in the canvas
- //\todo does not work properly
-
- double x1, x2, y1, y2;
- int x,y;
-
- NodeIt i(g);
- nodesmap[i]->get_bounds(x1, y1, x2, y2);
-
- x=(int)((x1+x2)/2);
- y=(int)((y1+y2)/2);
-
- int maxx=0, maxy=0, minx=(int)x, miny=(int)y;
-
- for (; i!=INVALID; ++i)
- {
- nodesmap[i]->get_bounds(x1, y1, x2, y2);
-
- x=(int)((x1+x2)/2);
- y=(int)((y1+y2)/2);
-
- if(x>maxx)maxx=x;
- if(y>maxy)maxy=y;
- if(x<minx)minx=x;
- if(y<miny)miny=y;
- }
-
- double biggest_x=(abs(maxx)>abs(minx))?(abs(maxx)+80):(abs(minx)+80);
- double biggest_y=(abs(maxy)>abs(miny))?(abs(maxy)+80):(abs(miny)+80);
-
- set_pixels_per_unit((biggest_x-WIN_WIDTH>biggest_y-WIN_HEIGHT)?(WIN_WIDTH/biggest_x/2):(WIN_HEIGHT/biggest_y/2));
- return 0;
-};
-
-
bool GraphDisplayerCanvas::event_handler(GdkEvent* e, Node n)
{
switch(e->type)
@@ -300,3 +261,61 @@
//rezoom();
return true;
}
+
+void GraphDisplayerCanvas::zoomIn()
+{
+ set_pixels_per_unit(
+ (1.0 + (double) zoom_step / 100.0) * get_pixels_per_unit());
+}
+
+void GraphDisplayerCanvas::zoomOut()
+{
+ set_pixels_per_unit(
+ (1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit());
+}
+
+void GraphDisplayerCanvas::zoomFit()
+{
+ // get the height and width of the canvas
+ Gtk::Allocation a = get_allocation();
+ int aw = a.get_width();
+ int ah = a.get_height();
+ // add some space
+ aw -= 5; if (aw < 0) aw = 0;
+ ah -= 5; if (ah < 0) ah = 0;
+ //std::cout << "aw=" << aw << " ah=" << ah << std::endl;
+
+ // get the bounding box of the graph
+ set_pixels_per_unit(1.0); // I don't really understand why this is necessary
+ double wx1, wy1, wx2, wy2;
+ double cx1, cy1, cx2, cy2;
+ Gnome::Canvas::Item* pCanvasItem = root();
+ pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
+ //std::cout << "root bounds: " << wx1 << " " << wy1 << " " << wx2 << " " << wy2 << std::endl;
+ w2c(wx1, wy1, cx1, cy1);
+ w2c(wx2, wy2, cx2, cy2);
+ //std::cout << "root bounds (c): " << cx1 << " " << cy1 << " " << cx2 << " " << cy2 << std::endl;
+ //std::cout << "cx2 - cx1=" << fabs(cx2 - cx1) << " cy2 - cy1=" << fabs(cy2 - cy1) << std::endl;
+
+ // fit the graph to the window
+ double ppu1 = (double) aw / fabs(cx2 - cx1);
+ double ppu2 = (double) ah / fabs(cy2 - cy1);
+ //std::cout << "ppu1=" << ppu1 << " ppu2=" << ppu2 << std::endl;
+ (ppu1 < ppu2) ? set_pixels_per_unit(ppu1) : set_pixels_per_unit(ppu2);
+}
+
+void GraphDisplayerCanvas::zoom100()
+{
+ set_pixels_per_unit(1.0);
+}
+
+void GraphDisplayerCanvas::updateScrollRegion()
+{
+ double wx1, wy1, wx2, wy2;
+ int cx1, cy1, cx2, cy2;
+ Gnome::Canvas::Item* pCanvasItem = root();
+ pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
+ w2c(wx1, wy1, cx1, cy1);
+ w2c(wx2, wy2, cx2, cy2);
+ set_scroll_region(cx1, cy1, cx2, cy2);
+}
Modified: hugo/trunk/gui/graph_displayer_canvas.h
==============================================================================
--- hugo/trunk/gui/graph_displayer_canvas.h (original)
+++ hugo/trunk/gui/graph_displayer_canvas.h Thu Jun 2 01:30:13 2005
@@ -29,8 +29,16 @@
///\param mapname is the name of the map which contains the new values
int changeText (std::string mapname);
- ///Changes the dot-pro-pixel to be able to show the whole graph.
- int rezoom();
+ ///Callback for 'ViewZoomIn' action.
+ virtual void zoomIn();
+ ///Callback for 'ViewZoomOut' action.
+ virtual void zoomOut();
+ ///Callback for 'ViewZoomFit' action.
+ virtual void zoomFit();
+ ///Callback for 'ViewZoom100' action.
+ virtual void zoom100();
+ ///Sets the scroll region of the convas to the bounding box of the graph.
+ void updateScrollRegion();
protected:
@@ -75,7 +83,7 @@
///2. we would like to handle only ony item per movement, therefore quering it is not a working solution
Gnome::Canvas::Item * active_item;
-
+ static const int zoom_step = 5;
};
#endif //GRAPH_DISPLAYER_CANVAS_H
Modified: hugo/trunk/gui/main_win.cc
==============================================================================
--- hugo/trunk/gui/main_win.cc (original)
+++ hugo/trunk/gui/main_win.cc Thu Jun 2 01:30:13 2005
@@ -1,18 +1,39 @@
#include <main_win.h>
-MainWin::MainWin(const std::string& title, Graph & graph, CoordinatesMap & cm, MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),gd_canvas(graph, cm, ms)
+MainWin::MainWin(const std::string& title, Graph & graph, CoordinatesMap & cm,
+ MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),gd_canvas(graph, cm, ms)
{
set_title (title);
set_default_size(WIN_WIDTH,WIN_HEIGHT);
add(vbox);
ag=Gtk::ActionGroup::create();
- ag->add( Gtk::Action::create("ShowMenu", "_Show") );
- ag->add( Gtk::Action::create("ShowMaps", "_Maps"), sigc::mem_fun(*this, &MainWin::showMaps));
+
ag->add( Gtk::Action::create("FileMenu", "_File") );
- ag->add( Gtk::Action::create("FileQuit", "_Quit"), sigc::mem_fun(*this, &MainWin::quit));
- ag->add( Gtk::Action::create("ZoomMenu", "_Zoom") );
- ag->add( Gtk::Action::create("ZoomRezoom", "_Rezoom"), sigc::mem_fun(*this, &MainWin::rezoom)); //!!!!!!
+ ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
+ sigc::mem_fun(*this, &MainWin::newFile));
+ ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN),
+ sigc::mem_fun(*this, &MainWin::openFile));
+ ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE),
+ sigc::mem_fun(*this, &MainWin::saveFile));
+ ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS),
+ sigc::mem_fun(*this, &MainWin::saveFileAs));
+ ag->add( Gtk::Action::create("FileQuit", Gtk::Stock::QUIT),
+ sigc::mem_fun(*this, &MainWin::quit));
+
+ ag->add( Gtk::Action::create("ViewMenu", "_View") );
+ ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN),
+ sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomIn));
+ ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT),
+ sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomOut));
+ ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT),
+ sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomFit));
+ ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
+ sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoom100));
+
+ ag->add( Gtk::Action::create("ShowMenu", "_Show") );
+ ag->add( Gtk::Action::create("ShowMaps", "_Maps"),
+ sigc::mem_fun(*this, &MainWin::showMaps));
uim=Gtk::UIManager::create();
uim->insert_action_group(ag);
@@ -25,15 +46,32 @@
"<ui>"
" <menubar name='MenuBar'>"
" <menu action='FileMenu'>"
+ " <menuitem action='FileNew'/>"
+ " <menuitem action='FileOpen'/>"
+ " <menuitem action='FileSave'/>"
+ " <menuitem action='FileSaveAs'/>"
" <menuitem action='FileQuit'/>"
" </menu>"
+ " <menu action='ViewMenu'>"
+ " <menuitem action='ViewZoomIn' />"
+ " <menuitem action='ViewZoomOut' />"
+ " <menuitem action='ViewZoomFit' />"
+ " <menuitem action='ViewZoom100' />"
+ " </menu>"
" <menu action='ShowMenu'>"
" <menuitem action='ShowMaps'/>"
" </menu>"
- " <menu action='ZoomMenu'>"
- " <menuitem action='ZoomRezoom'/>"
- " </menu>"
" </menubar>"
+ " <toolbar name='ToolBar'>"
+ " <toolitem action='FileNew' />"
+ " <toolitem action='FileOpen' />"
+ " <toolitem action='FileSave' />"
+ " <separator />"
+ " <toolitem action='ViewZoomIn' />"
+ " <toolitem action='ViewZoomOut' />"
+ " <toolitem action='ViewZoomFit' />"
+ " <toolitem action='ViewZoom100' />"
+ " </toolbar>"
"</ui>";
uim->add_ui_from_string(ui_info);
@@ -45,9 +83,21 @@
}
Gtk::Widget* menubar = uim->get_widget("/MenuBar");
- if(menubar)vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
+ if (menubar){
+ vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
+ }
+
+ Gtk::Widget* toolbar = uim->get_widget("/ToolBar");
+ if (toolbar)
+ {
+ static_cast<Gtk::Toolbar*>(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS);
+ vbox.pack_start(*toolbar, Gtk::PACK_SHRINK);
+ }
- vbox.pack_start(gd_canvas);
+ Gtk::ScrolledWindow* pScrolledWindow = manage(new Gtk::ScrolledWindow());
+ pScrolledWindow->add(gd_canvas);
+ vbox.pack_start(*pScrolledWindow);
+ //vbox.pack_start(gd_canvas);
show_all_children();
}
@@ -62,8 +112,22 @@
hide();
}
-void MainWin::rezoom()
+void MainWin::newFile()
{
- gd_canvas.rezoom();
+ std::cerr << "MainWin::newFile(): not yet implemented" << std::endl;
}
+void MainWin::openFile()
+{
+ std::cerr << "MainWin::openFile(): not yet implemented" << std::endl;
+}
+
+void MainWin::saveFile()
+{
+ std::cerr << "MainWin::saveFile(): not yet implemented" << std::endl;
+}
+
+void MainWin::saveFileAs()
+{
+ std::cerr << "MainWin::saveFileAs(): not yet implemented" << std::endl;
+}
Modified: hugo/trunk/gui/main_win.h
==============================================================================
--- hugo/trunk/gui/main_win.h (original)
+++ hugo/trunk/gui/main_win.h Thu Jun 2 01:30:13 2005
@@ -39,13 +39,16 @@
///This function makes map-setup window popped up.
virtual void showMaps();
-
- ///Exit
+ ///Callback for 'FileNew' action.
+ virtual void newFile();
+ ///Callback for 'FileOpen' action.
+ virtual void openFile();
+ ///Callback for 'FileSave' action.
+ virtual void saveFile();
+ ///Callback for 'FileSaveAs' action.
+ virtual void saveFileAs();
+ ///Callback for 'Quit' action.
virtual void quit();
-
- ///Refit screen to be able to show the whole graph.
- virtual void rezoom();
-
};
#endif //MAIN_WIN_H
More information about the Lemon-commits
mailing list