graph_displayer_canvas.cc
author hegyi
Fri, 10 Jun 2005 12:11:50 +0000
branchgui
changeset 10 43ddd0c9d881
parent 7 6a9399f56813
child 11 09b2a893fc9d
permissions -rwxr-xr-x
Sorry, forgot to commit two new files.
ladanyi@6
     1
#include <graph_displayer_canvas.h>
ladanyi@6
     2
#include <math.h>
ladanyi@6
     3
ladanyi@6
     4
GraphDisplayerCanvas::GraphDisplayerCanvas(Graph & gr, CoordinatesMap & cm, MapStorage & ms):g(gr),nodesmap(g),edgesmap(g),edgetextmap(g),displayed_graph(*(root()), 0, 0),mapstorage(ms),isbutton(false),active_item(NULL)
ladanyi@6
     5
{
hegyi@9
     6
  Gnome::Canvas::Ellipse * origo=new Gnome::Canvas::Ellipse(displayed_graph, 0-20, 0-20, 0+20, 0+20);
hegyi@9
     7
  *origo << Gnome::Canvas::Properties::fill_color("black");
hegyi@9
     8
  *origo << Gnome::Canvas::Properties::outline_color("black");
hegyi@9
     9
  
hegyi@9
    10
  actual_handler=/*displayed_graph.*/signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_node_event_handler), false);
hegyi@9
    11
ladanyi@6
    12
  //set_center_scroll_region(true);
ladanyi@6
    13
ladanyi@6
    14
  //first edges are drawn, to hide joining with nodes later
ladanyi@6
    15
ladanyi@6
    16
  for (EdgeIt i(g); i!=INVALID; ++i)
ladanyi@6
    17
  {
ladanyi@6
    18
ladanyi@6
    19
    //drawing green lines, coordinates are from cm
ladanyi@6
    20
ladanyi@6
    21
    Gnome::Canvas::Points coos;
ladanyi@6
    22
    coos.push_back(Gnome::Art::Point(cm[g.source(i)].x,cm[g.source(i)].y));
ladanyi@6
    23
    coos.push_back(Gnome::Art::Point(cm[g.target(i)].x,cm[g.target(i)].y));
ladanyi@6
    24
    
ladanyi@6
    25
    edgesmap[i]=new Gnome::Canvas::Line(displayed_graph, coos);
ladanyi@6
    26
    *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
ladanyi@6
    27
    edgesmap[i]->property_width_pixels().set_value(10);    
ladanyi@6
    28
    
ladanyi@6
    29
    //initializing edge-text as well, to empty string
ladanyi@6
    30
ladanyi@6
    31
    double x1, x2, y1, y2;
ladanyi@6
    32
    edgesmap[i]->get_bounds(x1, y1, x2, y2);
ladanyi@6
    33
    
ladanyi@6
    34
    edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph,(x1+x2)/2, (y1+y2)/2, "");
ladanyi@6
    35
    edgetextmap[i]->property_fill_color().set_value("black");
ladanyi@6
    36
  }
ladanyi@6
    37
ladanyi@6
    38
  //afterwards nodes come to be drawn
ladanyi@6
    39
ladanyi@6
    40
  NodeIt i(g);
ladanyi@6
    41
  int maxx=0, maxy=0, minx=(int)cm[i].x, miny=(int)cm[i].y;
ladanyi@6
    42
ladanyi@6
    43
  for (; i!=INVALID; ++i)
ladanyi@6
    44
  {
ladanyi@6
    45
    //minimum and maximum is gathered to be able to zoom to the graph correctly (whole figure should be seen)
ladanyi@6
    46
ladanyi@6
    47
    if(cm[i].x>maxx)maxx=(int)cm[i].x;
ladanyi@6
    48
    if(cm[i].y>maxy)maxy=(int)cm[i].y;
ladanyi@6
    49
    if(cm[i].x<minx)minx=(int)cm[i].x;
ladanyi@6
    50
    if(cm[i].y<miny)miny=(int)cm[i].y;
ladanyi@6
    51
ladanyi@6
    52
    //drawing bule nodes, with black line around them
ladanyi@6
    53
ladanyi@6
    54
    nodesmap[i]=new Gnome::Canvas::Ellipse(displayed_graph, cm[i].x-20, cm[i].y-20, cm[i].x+20, cm[i].y+20);
ladanyi@6
    55
    *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
ladanyi@6
    56
    *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
hegyi@9
    57
    //!!!!!!! (nodesmap[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),i));
ladanyi@6
    58
  }
ladanyi@6
    59
ladanyi@6
    60
  updateScrollRegion();
ladanyi@6
    61
}
ladanyi@6
    62
ladanyi@6
    63
GraphDisplayerCanvas::~GraphDisplayerCanvas()
ladanyi@6
    64
{
ladanyi@6
    65
ladanyi@6
    66
  //writing out the end state of the graph
ladanyi@6
    67
  //\todo all the maps has to be write out!
ladanyi@6
    68
ladanyi@6
    69
  Graph::NodeMap <int> id(g);
ladanyi@6
    70
  Graph::NodeMap <double> xc(g);
ladanyi@6
    71
  Graph::NodeMap <double> yc(g);
ladanyi@6
    72
  
ladanyi@6
    73
  int j=1;
ladanyi@6
    74
  
ladanyi@6
    75
  for (NodeIt i(g); i!=INVALID; ++i)
ladanyi@6
    76
  {
ladanyi@6
    77
    double x1,y1,x2,y2;
ladanyi@6
    78
    nodesmap[i]->get_bounds(x1, y1, x2, y2);
ladanyi@6
    79
    
ladanyi@6
    80
    id[i]=j++;
ladanyi@6
    81
    xc[i]=(x1+x2)/2;
ladanyi@6
    82
    yc[i]=(y1+y2)/2;
ladanyi@6
    83
  }
ladanyi@6
    84
ladanyi@6
    85
  GraphWriter<Graph> writer(std::cout,g);
ladanyi@6
    86
  
ladanyi@6
    87
  writer.writeNodeMap("id", id);
ladanyi@6
    88
  writer.writeNodeMap("coordinates_x", xc);
ladanyi@6
    89
  writer.writeNodeMap("coordinates_y", yc);
ladanyi@6
    90
  writer.run();
ladanyi@6
    91
}
ladanyi@6
    92
ladanyi@6
    93
int GraphDisplayerCanvas::changeLineWidth (std::string mapname)
ladanyi@6
    94
{
ladanyi@6
    95
  for (EdgeIt i(g); i!=INVALID; ++i)
ladanyi@6
    96
  {
ladanyi@6
    97
    int w=(int)(*(mapstorage.edgemap_storage)[mapname])[i];
ladanyi@6
    98
    edgesmap[i]->property_width_pixels().set_value(w);
ladanyi@6
    99
  }
ladanyi@6
   100
  return 0;
ladanyi@6
   101
};
ladanyi@6
   102
ladanyi@6
   103
int GraphDisplayerCanvas::changeColor (std::string mapname)
ladanyi@6
   104
{  
ladanyi@6
   105
ladanyi@6
   106
  //function maps the range of the maximum and
ladanyi@6
   107
  //the minimum of the nodemap to the range of
ladanyi@6
   108
  //green in RGB
ladanyi@6
   109
ladanyi@6
   110
  for (EdgeIt i(g); i!=INVALID; ++i)
ladanyi@6
   111
  {
ladanyi@6
   112
    double w=(*(mapstorage.edgemap_storage)[mapname])[i];
ladanyi@6
   113
    double max=mapstorage.maxOfEdgeMap(mapname);
ladanyi@6
   114
    double min=mapstorage.minOfEdgeMap(mapname);
ladanyi@6
   115
      
ladanyi@6
   116
    //std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl;
ladanyi@6
   117
    Gdk::Color color;
ladanyi@6
   118
    if(max!=min)
ladanyi@6
   119
    {
ladanyi@6
   120
      color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
ladanyi@6
   121
    }
ladanyi@6
   122
    else
ladanyi@6
   123
    {
ladanyi@6
   124
      color.set_rgb_p (0, 100, 0);
ladanyi@6
   125
    }
ladanyi@6
   126
ladanyi@6
   127
    edgesmap[i]->property_fill_color_gdk().set_value(color);
ladanyi@6
   128
  }
ladanyi@6
   129
  return 0;
ladanyi@6
   130
};
ladanyi@6
   131
ladanyi@6
   132
int GraphDisplayerCanvas::changeText (std::string mapname)
ladanyi@6
   133
{
ladanyi@6
   134
ladanyi@6
   135
  //the number in the map will be written on the edge
ladanyi@6
   136
  //EXCEPT when the name of the map is Text, because
ladanyi@6
   137
  //in that case empty string will be written, because
ladanyi@6
   138
  //that is the deleter map
ladanyi@6
   139
  //\todo isn't it a bit woodcutter?
ladanyi@6
   140
ladanyi@6
   141
  for (EdgeIt i(g); i!=INVALID; ++i)
ladanyi@6
   142
  {
ladanyi@6
   143
    if(mapname!="Text")
ladanyi@6
   144
    {
ladanyi@6
   145
      double number=(*(mapstorage.edgemap_storage)[mapname])[i];
ladanyi@6
   146
      int length=(int)(floor(log(number)/log(10)))+1;
ladanyi@6
   147
      int maxpos=(int)(pow(10,length-1));
ladanyi@6
   148
      int strl=length+1+RANGE;
ladanyi@6
   149
      char * str=new char[strl];
ladanyi@6
   150
      str[length]='.';
ladanyi@6
   151
      str[strl]='\0';
ladanyi@6
   152
      
ladanyi@6
   153
      for(int j=0;j<strl;j++)
ladanyi@6
   154
      {
ladanyi@6
   155
	if(j!=length)
ladanyi@6
   156
        {
ladanyi@6
   157
	  int digit=(int)(number/maxpos);
ladanyi@6
   158
	  str[j]=(digit+'0');
ladanyi@6
   159
	  number-=digit*maxpos;
ladanyi@6
   160
	  number*=10;
ladanyi@6
   161
        }
ladanyi@6
   162
      }
ladanyi@6
   163
      
ladanyi@6
   164
      edgetextmap[i]->property_text().set_value(str);
ladanyi@6
   165
    }
ladanyi@6
   166
    else
ladanyi@6
   167
    {
ladanyi@6
   168
      edgetextmap[i]->property_text().set_value("");
ladanyi@6
   169
    }
ladanyi@6
   170
  }
ladanyi@6
   171
  return 0;
ladanyi@6
   172
};
ladanyi@6
   173
ladanyi@6
   174
bool GraphDisplayerCanvas::event_handler(GdkEvent* e, Node n)
ladanyi@6
   175
{
ladanyi@6
   176
  switch(e->type)
ladanyi@6
   177
  {
ladanyi@6
   178
    case GDK_BUTTON_PRESS:
ladanyi@6
   179
      //we mark the location of the event to be able to calculate parameters of dragging
ladanyi@6
   180
      clicked_x=e->button.x;
ladanyi@6
   181
      clicked_y=e->button.y;
ladanyi@6
   182
      active_item=(get_item_at(e->button.x, e->button.y));
ladanyi@6
   183
      isbutton=true;
ladanyi@6
   184
      break;
ladanyi@6
   185
    case GDK_BUTTON_RELEASE:
ladanyi@6
   186
      isbutton=false;
ladanyi@6
   187
      active_item=NULL;
ladanyi@7
   188
      updateScrollRegion();
ladanyi@6
   189
      break;
ladanyi@6
   190
    case GDK_MOTION_NOTIFY:
ladanyi@6
   191
      //we only have to do sg. if the mouse button is pressed
ladanyi@6
   192
      if(isbutton)
ladanyi@6
   193
      {
ladanyi@6
   194
	//new coordinates will be the old values,
ladanyi@6
   195
	//because the item will be moved to the
ladanyi@6
   196
	//new coordinate therefore the new movement
ladanyi@6
   197
	//has to be calculated from here
ladanyi@6
   198
ladanyi@6
   199
        double dx=e->motion.x-clicked_x;
ladanyi@6
   200
        double dy=e->motion.y-clicked_y;
ladanyi@6
   201
        active_item->move(dx, dy);
ladanyi@6
   202
        clicked_x=e->motion.x;
ladanyi@6
   203
        clicked_y=e->motion.y;
ladanyi@6
   204
ladanyi@6
   205
	//all the edges connected to the moved point has to be redrawn
ladanyi@6
   206
ladanyi@6
   207
        EdgeIt e;
ladanyi@6
   208
        g.firstOut(e,n);
ladanyi@6
   209
        for(;e!=INVALID;g.nextOut(e))
ladanyi@6
   210
        {
ladanyi@6
   211
            Gnome::Canvas::Points coos;
ladanyi@6
   212
            double x1, x2, y1, y2;
ladanyi@6
   213
ladanyi@6
   214
            nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
ladanyi@6
   215
            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
ladanyi@6
   216
ladanyi@6
   217
            nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
ladanyi@6
   218
            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
ladanyi@6
   219
ladanyi@6
   220
            edgesmap[e]->property_points().set_value(coos);
ladanyi@6
   221
ladanyi@6
   222
	    edgesmap[e]->get_bounds(x1, y1, x2, y2);
ladanyi@6
   223
ladanyi@6
   224
	    edgetextmap[e]->property_x().set_value((x1+x2)/2);
ladanyi@6
   225
	    edgetextmap[e]->property_y().set_value((y1+y2)/2);
ladanyi@6
   226
        }
ladanyi@6
   227
ladanyi@6
   228
        g.firstIn(e,n);
ladanyi@6
   229
        for(;e!=INVALID;g.nextIn(e))
ladanyi@6
   230
        {
ladanyi@6
   231
            Gnome::Canvas::Points coos;
ladanyi@6
   232
            double x1, x2, y1, y2;
ladanyi@6
   233
ladanyi@6
   234
            nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
ladanyi@6
   235
            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
ladanyi@6
   236
ladanyi@6
   237
            nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
ladanyi@6
   238
            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
ladanyi@6
   239
ladanyi@6
   240
            edgesmap[e]->property_points().set_value(coos);
ladanyi@6
   241
ladanyi@6
   242
	    edgesmap[e]->get_bounds(x1, y1, x2, y2);
ladanyi@6
   243
ladanyi@6
   244
	    edgetextmap[e]->property_x().set_value((x1+x2)/2);
ladanyi@6
   245
	    edgetextmap[e]->property_y().set_value((y1+y2)/2);
ladanyi@6
   246
        }
ladanyi@6
   247
      }
ladanyi@6
   248
    default: break;
ladanyi@6
   249
  }
ladanyi@6
   250
  return true;
ladanyi@6
   251
}
ladanyi@6
   252
ladanyi@6
   253
bool GraphDisplayerCanvas::on_expose_event(GdkEventExpose *event)
ladanyi@6
   254
{
ladanyi@6
   255
  Gnome::Canvas::CanvasAA::on_expose_event(event);
ladanyi@6
   256
  //usleep(10000);
ladanyi@6
   257
  //rezoom();
ladanyi@6
   258
  return true;
ladanyi@6
   259
}
ladanyi@6
   260
ladanyi@6
   261
void GraphDisplayerCanvas::zoomIn()
ladanyi@6
   262
{
ladanyi@6
   263
  set_pixels_per_unit(
ladanyi@6
   264
      (1.0 + (double) zoom_step / 100.0) * get_pixels_per_unit());
ladanyi@6
   265
}
ladanyi@6
   266
ladanyi@6
   267
void GraphDisplayerCanvas::zoomOut()
ladanyi@6
   268
{
ladanyi@6
   269
  set_pixels_per_unit(
ladanyi@6
   270
      (1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit());
ladanyi@6
   271
}
ladanyi@6
   272
ladanyi@6
   273
void GraphDisplayerCanvas::zoomFit()
ladanyi@6
   274
{
ladanyi@6
   275
  // get the height and width of the canvas
ladanyi@6
   276
  Gtk::Allocation a = get_allocation();
ladanyi@6
   277
  int aw = a.get_width();
ladanyi@6
   278
  int ah = a.get_height();
ladanyi@6
   279
  // add some space
ladanyi@6
   280
  aw -= 5; if (aw < 0) aw = 0;
ladanyi@6
   281
  ah -= 5; if (ah < 0) ah = 0;
ladanyi@6
   282
ladanyi@6
   283
  // get the bounding box of the graph
ladanyi@6
   284
  double wx1, wy1, wx2, wy2;
ladanyi@6
   285
  Gnome::Canvas::Item* pCanvasItem = root();
ladanyi@6
   286
  pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
ladanyi@6
   287
ladanyi@6
   288
  // fit the graph to the window
ladanyi@7
   289
  double ppu1 = (double) aw / fabs(wx2 - wx1);
ladanyi@7
   290
  double ppu2 = (double) ah / fabs(wy2 - wy1);
ladanyi@7
   291
  set_pixels_per_unit((ppu1 < ppu2) ? ppu1 : ppu2);
ladanyi@6
   292
}
ladanyi@6
   293
ladanyi@6
   294
void GraphDisplayerCanvas::zoom100()
ladanyi@6
   295
{
ladanyi@6
   296
  set_pixels_per_unit(1.0);
ladanyi@6
   297
}
ladanyi@6
   298
ladanyi@6
   299
void GraphDisplayerCanvas::updateScrollRegion()
ladanyi@6
   300
{
ladanyi@6
   301
  double wx1, wy1, wx2, wy2;
ladanyi@6
   302
  Gnome::Canvas::Item* pCanvasItem = root();
ladanyi@6
   303
  pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
ladanyi@7
   304
  set_scroll_region(wx1, wy1, wx2, wy2);
ladanyi@6
   305
}
hegyi@9
   306
hegyi@9
   307
void GraphDisplayerCanvas::changeEditorialTool(int newtool)
hegyi@9
   308
{
hegyi@9
   309
  actual_handler.disconnect();
hegyi@9
   310
hegyi@9
   311
  switch(newtool)
hegyi@9
   312
    {
hegyi@9
   313
    case MOVE:
hegyi@9
   314
      actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::move_event_handler), false);
hegyi@9
   315
      break;
hegyi@9
   316
    case CREATE_NODE:
hegyi@9
   317
      actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_node_event_handler), false);
hegyi@9
   318
      break;
hegyi@9
   319
    case CREATE_EDGE:
hegyi@9
   320
      actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_edge_event_handler), false);
hegyi@9
   321
      break;
hegyi@9
   322
    default:
hegyi@9
   323
      break;
hegyi@9
   324
    }
hegyi@9
   325
}
hegyi@9
   326
hegyi@9
   327
bool GraphDisplayerCanvas::move_event_handler(GdkEvent* e)
hegyi@9
   328
{
hegyi@9
   329
  switch(e->type)
hegyi@9
   330
  {
hegyi@9
   331
    case GDK_BUTTON_PRESS:
hegyi@9
   332
      //we mark the location of the event to be able to calculate parameters of dragging
hegyi@9
   333
      clicked_x=e->button.x;
hegyi@9
   334
      clicked_y=e->button.y;
hegyi@9
   335
      active_item=(get_item_at(e->button.x, e->button.y));
hegyi@9
   336
      active_node=INVALID;
hegyi@9
   337
      for (NodeIt i(g); i!=INVALID; ++i)
hegyi@9
   338
	{
hegyi@9
   339
	  if(nodesmap[i]==active_item)
hegyi@9
   340
	    {
hegyi@9
   341
	      active_node=i;
hegyi@9
   342
	    }
hegyi@9
   343
	}
hegyi@9
   344
      isbutton=true;
hegyi@9
   345
      break;
hegyi@9
   346
    case GDK_BUTTON_RELEASE:
hegyi@9
   347
      isbutton=false;
hegyi@9
   348
      active_item=NULL;
hegyi@9
   349
      updateScrollRegion();
hegyi@9
   350
      break;
hegyi@9
   351
    case GDK_MOTION_NOTIFY:
hegyi@9
   352
      //we only have to do sg. if the mouse button is pressed
hegyi@9
   353
      if(isbutton)
hegyi@9
   354
      {
hegyi@9
   355
	//new coordinates will be the old values,
hegyi@9
   356
	//because the item will be moved to the
hegyi@9
   357
	//new coordinate therefore the new movement
hegyi@9
   358
	//has to be calculated from here
hegyi@9
   359
hegyi@9
   360
        double dx=e->motion.x-clicked_x;
hegyi@9
   361
        double dy=e->motion.y-clicked_y;
hegyi@9
   362
hegyi@9
   363
        active_item->move(dx, dy);
hegyi@9
   364
hegyi@9
   365
        clicked_x=e->motion.x;
hegyi@9
   366
        clicked_y=e->motion.y;
hegyi@9
   367
hegyi@9
   368
	//all the edges connected to the moved point has to be redrawn
hegyi@9
   369
hegyi@9
   370
        EdgeIt e;
hegyi@9
   371
hegyi@9
   372
        g.firstOut(e,active_node);
hegyi@9
   373
hegyi@9
   374
        for(;e!=INVALID;g.nextOut(e))
hegyi@9
   375
        {
hegyi@9
   376
            Gnome::Canvas::Points coos;
hegyi@9
   377
            double x1, x2, y1, y2;
hegyi@9
   378
hegyi@9
   379
            nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
hegyi@9
   380
            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
hegyi@9
   381
hegyi@9
   382
            nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
hegyi@9
   383
            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
hegyi@9
   384
hegyi@9
   385
            edgesmap[e]->property_points().set_value(coos);
hegyi@9
   386
hegyi@9
   387
	    edgesmap[e]->get_bounds(x1, y1, x2, y2);
hegyi@9
   388
hegyi@9
   389
	    edgetextmap[e]->property_x().set_value((x1+x2)/2);
hegyi@9
   390
	    edgetextmap[e]->property_y().set_value((y1+y2)/2);
hegyi@9
   391
        }
hegyi@9
   392
hegyi@9
   393
        g.firstIn(e,active_node);
hegyi@9
   394
        for(;e!=INVALID;g.nextIn(e))
hegyi@9
   395
        {
hegyi@9
   396
            Gnome::Canvas::Points coos;
hegyi@9
   397
            double x1, x2, y1, y2;
hegyi@9
   398
hegyi@9
   399
            nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
hegyi@9
   400
            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
hegyi@9
   401
hegyi@9
   402
            nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
hegyi@9
   403
            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
hegyi@9
   404
hegyi@9
   405
            edgesmap[e]->property_points().set_value(coos);
hegyi@9
   406
hegyi@9
   407
	    edgesmap[e]->get_bounds(x1, y1, x2, y2);
hegyi@9
   408
hegyi@9
   409
	    edgetextmap[e]->property_x().set_value((x1+x2)/2);
hegyi@9
   410
	    edgetextmap[e]->property_y().set_value((y1+y2)/2);
hegyi@9
   411
        }
hegyi@9
   412
      }
hegyi@9
   413
    default: break;
hegyi@9
   414
  }
hegyi@9
   415
hegyi@9
   416
  return true;
hegyi@9
   417
}
hegyi@9
   418
hegyi@9
   419
bool GraphDisplayerCanvas::create_node_event_handler(GdkEvent* e)
hegyi@9
   420
{
hegyi@9
   421
  switch(e->type)
hegyi@9
   422
    {
hegyi@9
   423
    case GDK_BUTTON_PRESS:
hegyi@9
   424
      isbutton=true;
hegyi@9
   425
hegyi@9
   426
      active_node=NodeIt(g,g.addNode());
hegyi@9
   427
hegyi@9
   428
      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
hegyi@9
   429
hegyi@9
   430
      nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);
hegyi@9
   431
      active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]);
hegyi@9
   432
      *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
hegyi@9
   433
      *(nodesmap[active_node]) << Gnome::Canvas::Properties::outline_color("black");
hegyi@9
   434
      (nodesmap[active_node])->show();
hegyi@9
   435
      break;
hegyi@9
   436
    case GDK_MOTION_NOTIFY:
hegyi@9
   437
      {
hegyi@9
   438
	double world_motion_x, world_motion_y;
hegyi@9
   439
	GdkEvent * generated=new GdkEvent();
hegyi@9
   440
	window_to_world (e->motion.x, e->motion.y, world_motion_x, world_motion_y);
hegyi@9
   441
	generated->motion.x=world_motion_x;
hegyi@9
   442
	generated->motion.y=world_motion_y;
hegyi@9
   443
	generated->type=GDK_MOTION_NOTIFY;
hegyi@9
   444
	move_event_handler(generated);      
hegyi@9
   445
	break;
hegyi@9
   446
      }
hegyi@9
   447
    case GDK_BUTTON_RELEASE:
hegyi@9
   448
      isbutton=false;
hegyi@9
   449
      *active_item << Gnome::Canvas::Properties::fill_color("blue");
hegyi@9
   450
      active_item=NULL;
hegyi@9
   451
      updateScrollRegion();
hegyi@9
   452
      break;
hegyi@9
   453
    default:
hegyi@9
   454
      break;
hegyi@9
   455
    }
hegyi@9
   456
  return false;
hegyi@9
   457
}
hegyi@9
   458
hegyi@9
   459
bool GraphDisplayerCanvas::create_edge_event_handler(GdkEvent* e)
hegyi@9
   460
{
hegyi@9
   461
  e=e;
hegyi@9
   462
  return false;
hegyi@9
   463
}
hegyi@9
   464