gui/graph_displayer_canvas.h
author ladanyi
Wed, 01 Jun 2005 23:30:13 +0000
changeset 1441 fd4b6f6d592a
parent 1440 3d2e3cfb2a6c
child 1442 1e3c69aa035b
permissions -rw-r--r--
- added toolbar
- added ScrolledWindow for the canvas
- zooming
ladanyi@1412
     1
// -*- C++ -*- //
ladanyi@1412
     2
ladanyi@1412
     3
#ifndef GRAPH_DISPLAYER_CANVAS_H
ladanyi@1412
     4
#define GRAPH_DISPLAYER_CANVAS_H
ladanyi@1412
     5
ladanyi@1412
     6
#include <all_include.h>
ladanyi@1412
     7
#include <mapstorage.h>
ladanyi@1412
     8
#include <libgnomecanvasmm.h>
ladanyi@1412
     9
#include <libgnomecanvasmm/polygon.h>
ladanyi@1412
    10
hegyi@1440
    11
///This class is the canvas, on which the graph can be drawn.
ladanyi@1412
    12
class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA
ladanyi@1412
    13
{
ladanyi@1412
    14
  typedef Gnome::Canvas::CanvasAA Parent;
ladanyi@1412
    15
ladanyi@1412
    16
public:
ladanyi@1412
    17
  GraphDisplayerCanvas(Graph &, CoordinatesMap &, MapStorage &);
ladanyi@1412
    18
  virtual ~GraphDisplayerCanvas();
ladanyi@1412
    19
hegyi@1440
    20
  ///Changes the linewidth attribute according to the given map.
hegyi@1440
    21
  ///\param mapname is the name of the map which contains the new values
ladanyi@1412
    22
  int changeLineWidth (std::string mapname);
hegyi@1440
    23
hegyi@1440
    24
  ///Changes the linecolor attribute according to the given map.
hegyi@1440
    25
  ///\param mapname is the name of the map which contains the new values
ladanyi@1412
    26
  int changeColor (std::string mapname);
hegyi@1440
    27
hegyi@1440
    28
  ///Changes the text of line attribute according to the given map.
hegyi@1440
    29
  ///\param mapname is the name of the map which contains the new values
ladanyi@1412
    30
  int changeText (std::string mapname);
hegyi@1440
    31
ladanyi@1441
    32
  ///Callback for 'ViewZoomIn' action.
ladanyi@1441
    33
  virtual void zoomIn();
ladanyi@1441
    34
  ///Callback for 'ViewZoomOut' action.
ladanyi@1441
    35
  virtual void zoomOut();
ladanyi@1441
    36
  ///Callback for 'ViewZoomFit' action.
ladanyi@1441
    37
  virtual void zoomFit();
ladanyi@1441
    38
  ///Callback for 'ViewZoom100' action.
ladanyi@1441
    39
  virtual void zoom100();
ladanyi@1441
    40
  ///Sets the scroll region of the convas to the bounding box of the graph.
ladanyi@1441
    41
  void updateScrollRegion();
ladanyi@1412
    42
ladanyi@1412
    43
protected:
ladanyi@1412
    44
hegyi@1440
    45
  //maximizing, minimizing, restoring window, etc. 
ladanyi@1412
    46
  virtual bool on_expose_event(GdkEventExpose *);
ladanyi@1412
    47
ladanyi@1412
    48
private:
ladanyi@1412
    49
hegyi@1440
    50
  ///This function is responsible for the correct
hegyi@1440
    51
  ///reaction of any action happened in the territory
hegyi@1440
    52
  ///of the canvas
ladanyi@1412
    53
  bool event_handler(GdkEvent* e, Node n);
ladanyi@1412
    54
ladanyi@1412
    55
  ///The graph, on which we work
ladanyi@1412
    56
  Graph g;
hegyi@1440
    57
hegyi@1440
    58
  ///Map of nodes of graph
ladanyi@1412
    59
  Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap;
hegyi@1440
    60
hegyi@1440
    61
  ///Map of edges of graph
ladanyi@1412
    62
  Graph::EdgeMap<Gnome::Canvas::Line *> edgesmap;
ladanyi@1412
    63
ladanyi@1412
    64
  ///Map of texts to write on edges
ladanyi@1412
    65
  Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap;
ladanyi@1412
    66
ladanyi@1412
    67
  ///Group of graphical elements of displayed_graph
ladanyi@1412
    68
  Gnome::Canvas::Group displayed_graph;
ladanyi@1412
    69
ladanyi@1412
    70
  ///Here we store the maps that can be displayed through properties.
ladanyi@1412
    71
  MapStorage mapstorage;
ladanyi@1412
    72
ladanyi@1412
    73
  ///Indicates whether the button of mouse is pressed or not
ladanyi@1412
    74
  bool isbutton;
ladanyi@1412
    75
ladanyi@1412
    76
  ///At this location was the mousebutton pressed.
ladanyi@1412
    77
  ///It helps to calculate the distance of dragging.
ladanyi@1412
    78
  double clicked_x, clicked_y;
ladanyi@1412
    79
ladanyi@1412
    80
  ///Remembers which Gnome::Canvas::Item was pressed.
ladanyi@1412
    81
  ///this variable is needed, because
ladanyi@1412
    82
  ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault
ladanyi@1412
    83
  ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution
ladanyi@1412
    84
  Gnome::Canvas::Item * active_item;
ladanyi@1412
    85
ladanyi@1441
    86
  static const int zoom_step = 5;
ladanyi@1412
    87
};
ladanyi@1412
    88
ladanyi@1412
    89
#endif //GRAPH_DISPLAYER_CANVAS_H