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