[6] | 1 | // -*- C++ -*- // |
---|
| 2 | |
---|
| 3 | #ifndef GRAPH_DISPLAYER_CANVAS_H |
---|
| 4 | #define GRAPH_DISPLAYER_CANVAS_H |
---|
| 5 | |
---|
| 6 | #include <all_include.h> |
---|
| 7 | #include <mapstorage.h> |
---|
| 8 | #include <libgnomecanvasmm.h> |
---|
| 9 | #include <libgnomecanvasmm/polygon.h> |
---|
| 10 | |
---|
| 11 | ///This class is the canvas, on which the graph can be drawn. |
---|
| 12 | class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA |
---|
| 13 | { |
---|
| 14 | typedef Gnome::Canvas::CanvasAA Parent; |
---|
| 15 | |
---|
| 16 | public: |
---|
| 17 | GraphDisplayerCanvas(Graph &, CoordinatesMap &, MapStorage &); |
---|
| 18 | virtual ~GraphDisplayerCanvas(); |
---|
| 19 | |
---|
| 20 | ///Changes the linewidth attribute according to the given map. |
---|
| 21 | ///\param mapname is the name of the map which contains the new values |
---|
| 22 | int changeLineWidth (std::string mapname); |
---|
| 23 | |
---|
| 24 | ///Changes the linecolor attribute according to the given map. |
---|
| 25 | ///\param mapname is the name of the map which contains the new values |
---|
| 26 | int changeColor (std::string mapname); |
---|
| 27 | |
---|
| 28 | ///Changes the text of line attribute according to the given map. |
---|
| 29 | ///\param mapname is the name of the map which contains the new values |
---|
| 30 | int changeText (std::string mapname); |
---|
| 31 | |
---|
| 32 | ///Callback for 'ViewZoomIn' action. |
---|
| 33 | virtual void zoomIn(); |
---|
| 34 | ///Callback for 'ViewZoomOut' action. |
---|
| 35 | virtual void zoomOut(); |
---|
| 36 | ///Callback for 'ViewZoomFit' action. |
---|
| 37 | virtual void zoomFit(); |
---|
| 38 | ///Callback for 'ViewZoom100' action. |
---|
| 39 | virtual void zoom100(); |
---|
| 40 | ///Sets the scroll region of the convas to the bounding box of the graph. |
---|
| 41 | void updateScrollRegion(); |
---|
| 42 | |
---|
[9] | 43 | ///This function changes the tool in the graph-editor's hand |
---|
| 44 | void changeEditorialTool(int); |
---|
| 45 | |
---|
[6] | 46 | protected: |
---|
| 47 | |
---|
| 48 | //maximizing, minimizing, restoring window, etc. |
---|
| 49 | virtual bool on_expose_event(GdkEventExpose *); |
---|
| 50 | |
---|
| 51 | private: |
---|
| 52 | |
---|
| 53 | ///This function is responsible for the correct |
---|
| 54 | ///reaction of any action happened in the territory |
---|
| 55 | ///of the canvas |
---|
| 56 | bool event_handler(GdkEvent* e, Node n); |
---|
| 57 | |
---|
[9] | 58 | ///actual event handler |
---|
| 59 | /// |
---|
| 60 | ///Actual event handler should be stored, to be able to disconnect it and later reconnect it. |
---|
| 61 | sigc::connection actual_handler; |
---|
| 62 | |
---|
| 63 | ///event handler for the case when move-tool is active |
---|
| 64 | bool move_event_handler(GdkEvent*); |
---|
| 65 | ///event handler for the case when create_node-tool is active |
---|
| 66 | bool create_node_event_handler(GdkEvent*); |
---|
| 67 | ///event handler for the case when create_edge-tool is active |
---|
| 68 | bool create_edge_event_handler(GdkEvent*); |
---|
[13] | 69 | ///event handler for the case when eraser-tool is active |
---|
| 70 | bool eraser_event_handler(GdkEvent*); |
---|
| 71 | |
---|
| 72 | ///Deletes the given item. |
---|
| 73 | void delete_item(Gnome::Canvas::Item *); |
---|
[9] | 74 | |
---|
[6] | 75 | ///The graph, on which we work |
---|
| 76 | Graph g; |
---|
| 77 | |
---|
| 78 | ///Map of nodes of graph |
---|
| 79 | Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap; |
---|
| 80 | |
---|
| 81 | ///Map of edges of graph |
---|
| 82 | Graph::EdgeMap<Gnome::Canvas::Line *> edgesmap; |
---|
| 83 | |
---|
| 84 | ///Map of texts to write on edges |
---|
| 85 | Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap; |
---|
| 86 | |
---|
| 87 | ///Group of graphical elements of displayed_graph |
---|
| 88 | Gnome::Canvas::Group displayed_graph; |
---|
| 89 | |
---|
| 90 | ///Here we store the maps that can be displayed through properties. |
---|
| 91 | MapStorage mapstorage; |
---|
| 92 | |
---|
| 93 | ///Indicates whether the button of mouse is pressed or not |
---|
| 94 | bool isbutton; |
---|
| 95 | |
---|
| 96 | ///At this location was the mousebutton pressed. |
---|
| 97 | ///It helps to calculate the distance of dragging. |
---|
| 98 | double clicked_x, clicked_y; |
---|
| 99 | |
---|
| 100 | ///Remembers which Gnome::Canvas::Item was pressed. |
---|
| 101 | ///this variable is needed, because |
---|
| 102 | ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault |
---|
| 103 | ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution |
---|
[11] | 104 | Gnome::Canvas::Item * active_item, * target_item; |
---|
[9] | 105 | Graph::NodeIt active_node; |
---|
[11] | 106 | Graph::EdgeIt active_edge; |
---|
[6] | 107 | |
---|
| 108 | static const int zoom_step = 5; |
---|
| 109 | }; |
---|
| 110 | |
---|
| 111 | #endif //GRAPH_DISPLAYER_CANVAS_H |
---|