graph_displayer_canvas.h
author hegyi
Mon, 06 Jun 2005 17:01:12 +0000
branchgui
changeset 8 abac0179a26a
parent 5 b7c36be1e35c
child 9 0bb1675306cb
permissions -rw-r--r--
Maps are now selectable through ComboBoxes, and Escape makes MapWin disappeared.
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
ladanyi@6
    43
protected:
ladanyi@6
    44
ladanyi@6
    45
  //maximizing, minimizing, restoring window, etc. 
ladanyi@6
    46
  virtual bool on_expose_event(GdkEventExpose *);
ladanyi@6
    47
ladanyi@6
    48
private:
ladanyi@6
    49
ladanyi@6
    50
  ///This function is responsible for the correct
ladanyi@6
    51
  ///reaction of any action happened in the territory
ladanyi@6
    52
  ///of the canvas
ladanyi@6
    53
  bool event_handler(GdkEvent* e, Node n);
ladanyi@6
    54
ladanyi@6
    55
  ///The graph, on which we work
ladanyi@6
    56
  Graph g;
ladanyi@6
    57
ladanyi@6
    58
  ///Map of nodes of graph
ladanyi@6
    59
  Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap;
ladanyi@6
    60
ladanyi@6
    61
  ///Map of edges of graph
ladanyi@6
    62
  Graph::EdgeMap<Gnome::Canvas::Line *> edgesmap;
ladanyi@6
    63
ladanyi@6
    64
  ///Map of texts to write on edges
ladanyi@6
    65
  Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap;
ladanyi@6
    66
ladanyi@6
    67
  ///Group of graphical elements of displayed_graph
ladanyi@6
    68
  Gnome::Canvas::Group displayed_graph;
ladanyi@6
    69
ladanyi@6
    70
  ///Here we store the maps that can be displayed through properties.
ladanyi@6
    71
  MapStorage mapstorage;
ladanyi@6
    72
ladanyi@6
    73
  ///Indicates whether the button of mouse is pressed or not
ladanyi@6
    74
  bool isbutton;
ladanyi@6
    75
ladanyi@6
    76
  ///At this location was the mousebutton pressed.
ladanyi@6
    77
  ///It helps to calculate the distance of dragging.
ladanyi@6
    78
  double clicked_x, clicked_y;
ladanyi@6
    79
ladanyi@6
    80
  ///Remembers which Gnome::Canvas::Item was pressed.
ladanyi@6
    81
  ///this variable is needed, because
ladanyi@6
    82
  ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault
ladanyi@6
    83
  ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution
ladanyi@6
    84
  Gnome::Canvas::Item * active_item;
ladanyi@6
    85
ladanyi@6
    86
  static const int zoom_step = 5;
ladanyi@6
    87
};
ladanyi@6
    88
ladanyi@6
    89
#endif //GRAPH_DISPLAYER_CANVAS_H