PageRenderTime 59ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/otherlibs/graph/draw.c

https://bitbucket.org/HongboZhang/ocaml
C | 123 lines | 96 code | 14 blank | 13 comment | 8 complexity | 98012bd18d261eee6001797761c77464 MD5 | raw file
Possible License(s): LGPL-2.0, GPL-2.0
  1. /***********************************************************************/
  2. /* */
  3. /* OCaml */
  4. /* */
  5. /* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
  6. /* */
  7. /* Copyright 1996 Institut National de Recherche en Informatique et */
  8. /* en Automatique. All rights reserved. This file is distributed */
  9. /* under the terms of the GNU Library General Public License, with */
  10. /* the special exception on linking described in file ../../LICENSE. */
  11. /* */
  12. /***********************************************************************/
  13. /* $Id$ */
  14. #include "libgraph.h"
  15. #include <alloc.h>
  16. value caml_gr_plot(value vx, value vy)
  17. {
  18. int x = Int_val(vx);
  19. int y = Int_val(vy);
  20. caml_gr_check_open();
  21. if(caml_gr_remember_modeflag)
  22. XDrawPoint(caml_gr_display, caml_gr_bstore.win, caml_gr_bstore.gc, x, Bcvt(y));
  23. if(caml_gr_display_modeflag) {
  24. XDrawPoint(caml_gr_display, caml_gr_window.win, caml_gr_window.gc, x, Wcvt(y));
  25. XFlush(caml_gr_display);
  26. }
  27. return Val_unit;
  28. }
  29. value caml_gr_moveto(value vx, value vy)
  30. {
  31. caml_gr_x = Int_val(vx);
  32. caml_gr_y = Int_val(vy);
  33. return Val_unit;
  34. }
  35. value caml_gr_current_x(void)
  36. {
  37. return Val_int(caml_gr_x);
  38. }
  39. value caml_gr_current_y(void)
  40. {
  41. return Val_int(caml_gr_y);
  42. }
  43. value caml_gr_lineto(value vx, value vy)
  44. {
  45. int x = Int_val(vx);
  46. int y = Int_val(vy);
  47. caml_gr_check_open();
  48. if(caml_gr_remember_modeflag)
  49. XDrawLine(caml_gr_display, caml_gr_bstore.win, caml_gr_bstore.gc,
  50. caml_gr_x, Bcvt(caml_gr_y), x, Bcvt(y));
  51. if(caml_gr_display_modeflag) {
  52. XDrawLine(caml_gr_display, caml_gr_window.win, caml_gr_window.gc,
  53. caml_gr_x, Wcvt(caml_gr_y), x, Wcvt(y));
  54. XFlush(caml_gr_display);
  55. }
  56. caml_gr_x = x;
  57. caml_gr_y = y;
  58. return Val_unit;
  59. }
  60. value caml_gr_draw_rect(value vx, value vy, value vw, value vh)
  61. {
  62. int x = Int_val(vx);
  63. int y = Int_val(vy);
  64. int w = Int_val(vw);
  65. int h = Int_val(vh);
  66. caml_gr_check_open();
  67. if(caml_gr_remember_modeflag)
  68. XDrawRectangle(caml_gr_display, caml_gr_bstore.win, caml_gr_bstore.gc,
  69. x, Bcvt(y) - h, w, h);
  70. if(caml_gr_display_modeflag) {
  71. XDrawRectangle(caml_gr_display, caml_gr_window.win, caml_gr_window.gc,
  72. x, Wcvt(y) - h, w, h);
  73. XFlush(caml_gr_display);
  74. }
  75. return Val_unit;
  76. }
  77. value caml_gr_draw_arc_nat(value vx, value vy, value vrx, value vry, value va1, value va2)
  78. {
  79. int x = Int_val(vx);
  80. int y = Int_val(vy);
  81. int rx = Int_val(vrx);
  82. int ry = Int_val(vry);
  83. int a1 = Int_val(va1);
  84. int a2 = Int_val(va2);
  85. caml_gr_check_open();
  86. if(caml_gr_remember_modeflag)
  87. XDrawArc(caml_gr_display, caml_gr_bstore.win, caml_gr_bstore.gc,
  88. x - rx, Bcvt(y) - ry, rx * 2, ry * 2, a1 * 64, (a2 - a1) * 64);
  89. if(caml_gr_display_modeflag) {
  90. XDrawArc(caml_gr_display, caml_gr_window.win, caml_gr_window.gc,
  91. x - rx, Wcvt(y) - ry, rx * 2, ry * 2, a1 * 64, (a2 - a1) * 64);
  92. XFlush(caml_gr_display);
  93. }
  94. return Val_unit;
  95. }
  96. value caml_gr_draw_arc(value *argv, int argc)
  97. {
  98. return caml_gr_draw_arc_nat(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]);
  99. }
  100. value caml_gr_set_line_width(value vwidth)
  101. {
  102. int width = Int_val(vwidth);
  103. caml_gr_check_open();
  104. XSetLineAttributes(caml_gr_display, caml_gr_window.gc,
  105. width, LineSolid, CapRound, JoinRound);
  106. XSetLineAttributes(caml_gr_display, caml_gr_bstore.gc,
  107. width, LineSolid, CapRound, JoinRound);
  108. return Val_unit;
  109. }