home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / leda / src / graphics / _win_out.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-15  |  8.8 KB  |  383 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  2.1.1                                                 11-15-1991
  4. +
  5. +
  6. +  _win_output.c
  7. +
  8. +
  9. +  Copyright (c) 1991  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15. #include <LEDA/window.h>
  16. #include "global.c"
  17. #include <math.h>
  18.  
  19.  
  20. //------------------------------------------------------------------------------
  21. // OUTPUT
  22. //------------------------------------------------------------------------------
  23.  
  24. // drawing segments
  25.  
  26. void window::draw_segment(double x1, double y1, double x2, double y2, color c )
  27. { x_draw_line(x1,y1,x2,y2,c); }
  28.  
  29. void window::draw_segment(point p, point q, color c )
  30. { window::draw_segment(p.xcoord(),p.ycoord(),q.xcoord(),q.ycoord(),c); }
  31.  
  32. void window::draw_segment(segment s, color c )
  33. { draw(s,c); }
  34.  
  35.  
  36. // drawing lines
  37.  
  38. void window::draw_line(double x1, double y1, double x2, double y2, color c )
  39. { window::draw_line(point(x1,y1), point(x2,y2),c); }
  40.  
  41. void window::draw_line(point p, point q, color c) 
  42. { draw(line(p,q),c); }
  43.  
  44. void window::draw_line(line l, color c) 
  45. { draw(l,c); }
  46.  
  47.  
  48. void window::draw_hline(double y, color c )
  49. { x_draw_line(x_draw_xmin,y,x_draw_xmax,y,c); }
  50.  
  51. void window::draw_vline(double x, color c )
  52. { x_draw_line(x,x_draw_ymin,x,x_draw_ymax,c); }
  53.  
  54.  
  55.  
  56. void window::draw_pix(double x, double y, color c ) 
  57. { x_draw_pix(x,y,c); }
  58.  
  59. void window::draw_pix(point p, color c ) 
  60. { draw_pix(p.xcoord(),p.ycoord(),c); }
  61.  
  62.  
  63.  
  64.  
  65. void window::draw_point(double x0,double y0,color c)
  66. { x_draw_point(x0,y0,c); }
  67.  
  68. void window::draw_point(point p,color c)
  69. { draw(p,c); }
  70.  
  71.  
  72.  
  73. // drawing nodes
  74.  
  75. void window::draw_node(double x0,double y0,color c) 
  76. { x_draw_node(x0,y0,c); }
  77.  
  78. void window::draw_node(point p, color c)
  79. { window::draw_node(p.xcoord(),p.ycoord(),c); }
  80.  
  81. void window::draw_filled_node(double x0,double y0,color c)
  82. { x_draw_filled_node(x0,y0,c); }
  83.  
  84. void window::draw_filled_node(point p, color c)
  85. { window::draw_filled_node(p.xcoord(),p.ycoord(),c); }
  86.  
  87. void window::draw_text_node(double x,double y,string s,color c)
  88. { x_draw_text_node(x,y,~s,c); }
  89.  
  90. void window::draw_text_node(point p ,string s,color c)
  91. { window::draw_text_node(p.xcoord(),p.ycoord(),~s,c); }
  92.  
  93. void window::draw_int_node(double x,double y,int i,color c)
  94. { x_draw_int_node(x,y,i,c); }
  95.  
  96. void window::draw_int_node(point p ,int i,color c)
  97. { window::draw_int_node(p.xcoord(),p.ycoord(),i,c); }
  98.  
  99.  
  100. //circles
  101.  
  102. void window::draw_circle(double x,double y,double r,color c)
  103. { x_draw_circle(x,y,r,c); }
  104.  
  105. void window::draw_circle(point p,double r,color c)
  106. { x_draw_circle(p.xcoord(),p.ycoord(),r,c); }
  107.  
  108. void window::draw_circle(circle C,color c)
  109. { point p = C.center();
  110.   double r = C.radius();
  111.   x_draw_circle(p.xcoord(),p.ycoord(),r,c); 
  112.  }
  113.  
  114.  
  115. //ellipses
  116.  
  117. void window::draw_ellipse(double x,double y,double a, double b, color c)
  118. { x_draw_ellipse(x,y,a,b,c); }
  119.  
  120. void window::draw_ellipse(point p, double a, double b, color c)
  121. { x_draw_ellipse(p.xcoord(),p.ycoord(),a,b,c); }
  122.  
  123.  
  124.  
  125.  
  126. void window::draw_disc(double x,double y,double r,color c)
  127. { x_draw_filled_circle(x,y,r,c); }
  128.  
  129. void window::draw_disc(point p,double r,color c)
  130. { window::draw_disc(p.xcoord(),p.ycoord(),r,c); }
  131.  
  132.  
  133.  
  134. //drawing polygons 
  135.  
  136. void window::draw_polygon(polygon P, color c )
  137. { draw(P,c); }
  138.  
  139.  
  140. void window::draw_filled_polygon(polygon P,color c )
  141. { window::draw_filled_polygon(P.vertices(),c); }
  142.  
  143.  
  144. void window::draw_rectangle(double a, double  b, double c, double d, color col)
  145. { x_draw_rectangle(a,b,c,d,col); }
  146.  
  147. void window::draw_filled_rectangle(double a, double  b, double c, double d, color col)
  148. { x_draw_filled_rectangle(a,b,c,d,col); }
  149.  
  150.  
  151. // miscellaneous
  152.  
  153. void window::copy_rect(double x1, double y1, double x2, double y2, double x, double y) 
  154. { x_draw_copy_rect(x1,y1,x2,y2,x,y); }
  155.  
  156.  
  157. /*  xview only
  158.  
  159. void window::move_rect(double x1, double y1, double x2, double y2, double x, double y) 
  160. { x_draw_move_rect(x1,y1,x2,y2,x,y); }
  161.  
  162. void window::copy(double x1, double y1, double x2, double y2, int i) 
  163. { x_draw_copy(x1,y1,x2,y2,i); }
  164.  
  165. void window::cut(double x1, double y1, double x2, double y2, int i) 
  166. { x_draw_cut(x1,y1,x2,y2,i); }
  167.  
  168. void window::paste(int i, double x, double y) { x_draw_paste(i,x,y); }
  169. void window::paste(double x, double y)        { x_draw_paste(0,x,y); }
  170. void window::clear_buf(int i)                 { x_draw_clear_buf(i); }
  171. */
  172.  
  173.  
  174. void window::clear(color c) { x_draw_clear(c); mesg_list.clear(); }
  175.  
  176. void window::show_window() { x_show_window(); }
  177.  
  178.  
  179. // text
  180.  
  181. void window::draw_text(double x, double y, string s, color c)
  182. { x_draw_text(x,y,~s,c); 
  183.  }
  184.  
  185. void window::draw_text(point p, string s, color c)
  186. { window::draw_text(p.xcoord(),p.ycoord(),s,c);  
  187.  }
  188.  
  189.  
  190. void window::draw_ctext(double x, double y, string s, color c)
  191. { x_draw_ctext(x,y,~s,c); 
  192.  }
  193.  
  194. void window::draw_ctext(point p, string s, color c)
  195. { window::draw_ctext(p.xcoord(),p.ycoord(),s,c); }
  196.  
  197.  
  198. // drawing functions
  199.  
  200. void window::plot_xy(double x0, double x1, draw_func_ptr f, color c)
  201. { x_draw_plot_xy(x0,x1,f,c); }
  202.  
  203. void window::plot_yx(double y0, double y1, draw_func_ptr f, color c)
  204. { x_draw_plot_yx(y0,y1,f,c); }
  205.  
  206.  
  207.  
  208. //------------------------------------------------------------------------------
  209. // messages
  210. //------------------------------------------------------------------------------
  211.  
  212. void window::add_message(string s) { mesg_list.append(s); };
  213. void window::clear_messages()      { mesg_list.clear(); };
  214.  
  215.  
  216. void window::message(string s)
  217. { mesg_list.append(s);
  218.   x_draw_message(mesg_list.length(),~s,black);
  219.  }
  220.  
  221.  
  222. void window::del_message()
  223. { while (!mesg_list.empty())
  224.   { x_draw_message(mesg_list.length(),~mesg_list.tail(),black);
  225.     mesg_list.Pop();
  226.    }
  227.  }
  228.  
  229. void window::show_message()
  230. { char** p = new char*[mesg_list.length()];
  231.   int    i = 0;
  232.   string s;
  233.   forall(s,mesg_list)  p[i++] = ~s;
  234.   x_draw_message_panel(i,p); 
  235. }
  236.  
  237. //------------------------------------------------------------------------------
  238.  
  239.  
  240.  
  241. void window::draw_arrow(double x0, double y0, double x1, double y1, color c)
  242. { draw_arrow(point(x0,y0),point(x1,y1),c); }
  243.  
  244. void window::draw_arrow(point p, point q, color c)
  245. { draw_arrow(segment(p,q),c); }
  246.  
  247. void window::draw_arrow(segment s, color c)
  248. {
  249.   point p = s.start();
  250.   point q = s.end();
  251.   double alpha = s.angle()-M_PI; 
  252.  
  253.   double d = 2*((get_line_width()+1)/2)/scale();;
  254.  
  255.   point l = q.translate(alpha+M_PI/6, 7*d);
  256.   point m = q.translate(alpha,        4*d);
  257.   point r = q.translate(alpha-M_PI/6, 7*d);
  258.  
  259.   list(point) L;
  260.  
  261.   L.append(q);
  262.   L.append(l);
  263.   L.append(m);
  264.   L.append(r);
  265.  
  266.   draw_segment(p,m,c);
  267.   draw_filled_polygon(L,c);
  268. }
  269.  
  270.  
  271. void window::draw_edge(double x1, double y1, double x2, double y2, color c)
  272. { draw_edge(point(x1,y1), point(x2,y2),c); }
  273.  
  274. void window::draw_edge(point p, point q, color c)
  275. { draw_edge(segment(p,q),c); }
  276.  
  277. void window::draw_edge(segment s, color c)
  278. { double alpha = s.angle();
  279.   point p = s.start().translate(alpha,get_node_width()/x_draw_scale);
  280.   point q = s.end().translate(alpha,-get_node_width()/x_draw_scale);
  281.   draw_segment(p,q,c); 
  282. }
  283.  
  284.  
  285.  
  286. void window::draw_edge_arrow(double x1,double y1,double x2,double y2,color c)
  287. { draw_edge_arrow(point(x1,y1), point(x2,y2),c); }
  288.  
  289. void window::draw_edge_arrow(point p, point q, color c)
  290. { draw_edge_arrow(segment(p,q),c); }
  291.  
  292. void window::draw_edge_arrow(segment s, color c)
  293. { double  alpha = s.angle();
  294.   point p = s.start().translate(alpha,get_node_width()/x_draw_scale);
  295.   point q = s.end().translate(alpha,-get_node_width()/x_draw_scale);
  296.   draw_arrow(p,q,c);
  297. }
  298.  
  299.  
  300.  
  301.  
  302. void window::draw_disc(circle C,color c)
  303. { draw_disc(C.center(),C.radius(),c); }
  304.  
  305.  
  306.  
  307.  
  308. window& window::draw(point p, color c)
  309. { draw_point(p.xcoord(),p.ycoord(),c); 
  310.   return *this;
  311.  }
  312.  
  313. window& window::draw(segment s, color c)
  314. { draw_segment(s.start(),s.end(),c);
  315.   return *this;
  316.  }
  317.  
  318. window& window::draw(line l, color c)
  319. {
  320.   list(segment) L;
  321.   list(point) P;
  322.  
  323.   segment top_line(xmin(),ymax(),xmax(),ymax());
  324.   segment bot_line(xmin(),ymin(),xmax(),ymin());
  325.   segment left_line(xmin(),ymin(),xmin(),ymax());
  326.   segment right_line(xmax(),ymin(),xmax(),ymax());
  327.  
  328.   L.append(top_line);
  329.   L.append(bot_line); 
  330.   L.append(left_line);
  331.   L.append(right_line);
  332.  
  333.   segment x;
  334.   point p;
  335.  
  336.   forall(x,L)
  337.     if (l.intersection(x,p)) P.append(p);
  338.  
  339.   draw_segment(P.head(),P.tail(),c);
  340.  
  341.   return *this;
  342. }
  343.  
  344. window& window::draw(circle C,color c)
  345. { draw_circle(C,c); 
  346.   return *this;
  347.  }
  348.  
  349. window& window::draw(polygon P,color c)
  350. { draw_polygon(P.vertices(),c); 
  351.   return *this;
  352.  }
  353.  
  354. void window::draw_polygon(list(point) lp, color c)
  355. { int n = lp.length();
  356.   double* X = new double[n];
  357.   double* Y = new double[n];
  358.   n = 0;
  359.   point p;
  360.   forall(p,lp) 
  361.   { X[n] = p.xcoord();
  362.     Y[n] = p.ycoord();
  363.     n++;
  364.    }
  365.   x_draw_polygon(n,X,Y,c);
  366. }
  367.  
  368. void window::draw_filled_polygon(list(point) lp, color c)
  369. { int n = lp.length();
  370.   double* X = new double[n];
  371.   double* Y = new double[n];
  372.   n = 0;
  373.   point p;
  374.   forall(p,lp) 
  375.   { X[n] = p.xcoord();
  376.     Y[n] = p.ycoord();
  377.     n++;
  378.    }
  379.   x_draw_filled_polygon(n,X,Y,c);
  380. }
  381.  
  382.