NewMapWin has become Dialog instead of Window. Therefore it is created dynamically, when there is need for it, instead of keeping one instance in memory. This solution is slower, but more correct than before.
3 #ifndef GRAPH_DISPLAYER_CANVAS_H
4 #define GRAPH_DISPLAYER_CANVAS_H
6 class GraphDisplayerCanvas;
8 #include "all_include.h"
9 #include "mapstorage.h"
11 #include <libgnomecanvasmm.h>
12 #include <libgnomecanvasmm/polygon.h>
15 ///This class is the canvas, on which the graph can be drawn.
16 class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA
18 class BrokenEdge : public Gnome::Canvas::Line
20 GraphDisplayerCanvas & gdc;
21 Gnome::Canvas::Polygon * arrow;
22 Gnome::Art::Point * my_points;
25 ///Indicates whether the button of mouse is pressed or not
28 ///At this location was the mousebutton pressed.
29 ///It helps to calculate the distance of dragging.
30 double clicked_x, clicked_y;
32 ///event handler for forming edges
33 bool edgeFormerEventHandler(GdkEvent*);
35 BrokenEdge(Gnome::Canvas::Group &, Gnome::Canvas::Points, GraphDisplayerCanvas &);
37 void setPoints(Gnome::Canvas::Points, bool move=false);
38 xy<double> getArrowPos();
40 typedef Gnome::Canvas::CanvasAA Parent;
43 GraphDisplayerCanvas(MapStorage &, MapWin &, Gtk::Window *);
44 virtual ~GraphDisplayerCanvas();
46 ///Changes the linewidth attribute according to the given map.
47 ///\param mapname is the name of the map which contains the new values
48 int changeEdgeWidth (std::string mapname, Edge new_item=INVALID);
49 int resetEdgeWidth (Edge new_item=INVALID);
51 ///Changes the linecolor attribute according to the given map.
52 ///\param mapname is the name of the map which contains the new values
53 int changeEdgeColor (std::string mapname, Edge new_item=INVALID);
54 int resetEdgeColor (Edge new_item=INVALID);
56 ///Changes the text of line attribute according to the given map.
57 ///\param mapname is the name of the map which contains the new values
58 int changeEdgeText (std::string mapname, Edge new_item=INVALID);
59 int resetEdgeText (Edge new_item=INVALID);
61 ///Changes the linewidth attribute according to the given map.
62 ///\param mapname is the name of the map which contains the new values
63 int changeNodeRadius (std::string mapname, Node new_item=INVALID);
64 int resetNodeRadius (Node new_item=INVALID);
66 ///Changes the linecolor attribute according to the given map.
67 ///\param mapname is the name of the map which contains the new values
68 int changeNodeColor (std::string mapname, Node new_item=INVALID);
69 int resetNodeColor (Node new_item=INVALID);
71 ///Changes the text of line attribute according to the given map.
72 ///\param mapname is the name of the map which contains the new values
73 int changeNodeText (std::string mapname, Node new_item=INVALID);
74 int resetNodeText (Node new_item=INVALID);
76 ///Callback for 'ViewZoomIn' action.
77 virtual void zoomIn();
78 ///Callback for 'ViewZoomOut' action.
79 virtual void zoomOut();
80 ///Callback for 'ViewZoomFit' action.
81 virtual void zoomFit();
82 ///Callback for 'ViewZoom100' action.
83 virtual void zoom100();
84 ///Sets the scroll region of the convas to the bounding box of the graph.
85 void updateScrollRegion();
87 ///This function changes the tool in the graph-editor's hand
88 void changeEditorialTool(int);
92 //maximizing, minimizing, restoring window, etc.
93 virtual bool on_expose_event(GdkEventExpose *);
97 ///This function is responsible for the correct
98 ///reaction of any action happened in the territory
101 bool eventHandler(GdkEvent* e, Node n);
103 ///actual event handler
105 ///Actual event handler should be stored, to be able to disconnect it and later reconnect it.
106 sigc::connection actual_handler;
108 ///event handler for the case when move-tool is active
109 bool moveEventHandler(GdkEvent*);
110 ///event handler for the case when create_node-tool is active
111 bool createNodeEventHandler(GdkEvent*);
112 ///event handler for the case when create_edge-tool is active
113 bool createEdgeEventHandler(GdkEvent*);
114 ///event handler for the case when eraser-tool is active
115 bool eraserEventHandler(GdkEvent*);
116 ///event handler for the case when edge map editor tool is active
117 bool edgeMapEditEventHandler(GdkEvent*);
118 ///event handler for the case when node map editor tool is active
119 bool nodeMapEditEventHandler(GdkEvent*);
122 ///Moves the text to new place
123 void textReposition(xy<double>);
124 ///Activates an edge belonging to a BrokenEdge
126 ///After we have activated an edge this way,
127 ///the GDC object will know, which edge is under forming
128 ///therefore it can redraw the necessarz elementy on the canvas,
129 ///for example the text belonging to the \ref BrokenEdge can be
130 ///redrawn (\ref textReposition).
131 void toggleEdgeActivity(BrokenEdge*, bool);
134 ///\return the actual tool in hand
140 ///creates a new Nodemap
141 int addNewNodeMap(double,std::string);
142 ///creates a new Edgemap
143 int addNewEdgeMap(double,std::string);
146 ///Deletes the given element.
147 void deleteItem(Node);
148 ///Deletes the given element.
149 void deleteItem(Edge);
153 ///Map of nodes of graph
154 Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap;
156 ///Map of edges of graph
157 Graph::EdgeMap<BrokenEdge *> edgesmap;
159 ///Map of texts to write on edges
160 Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap;
162 ///Map of texts to write on nodes
163 Graph::NodeMap<Gnome::Canvas::Text *> nodetextmap;
165 ///Group of graphical elements of displayed_graph
166 Gnome::Canvas::Group displayed_graph;
169 ///Here we store the maps that can be displayed through properties.
170 MapStorage & mapstorage;
173 ///Indicates whether the button of mouse is pressed or not
176 ///Stores the actual tool in hand
179 ///At this location was the mousebutton pressed.
180 ///It helps to calculate the distance of dragging.
181 double clicked_x, clicked_y;
183 ///Remembers which Gnome::Canvas::Item was pressed.
184 ///this variable is needed, because
185 ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault
186 ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution
187 Gnome::Canvas::Item * active_item, * target_item;
192 std::string nodemap_to_edit, edgemap_to_edit;
194 static const int zoom_step = 5;
197 ///We need to store mapwin, to be able to ask the appropriate values for properties of new items.
202 ///pointer to the parent window
203 Gtk::Window * parentwin;
207 #endif //GRAPH_DISPLAYER_CANVAS_H