graphics.scm 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. ;; Copyright (c) 2001-2003 by Norbert Frese, David Frese
  2. ;; *** copy areas ****************************************************
  3. (import-xlib-function copy-area
  4. (display src dest gc src-x src-y width height dest-x dest-y)
  5. "scx_Copy_Area")
  6. (import-xlib-function copy-plane
  7. (display src dest gc src-x src-y width height dest-x dest-y plane)
  8. "scx_Copy_Plane")
  9. ;; *** draw points ***************************************************
  10. (define-enumerated-type coord-mode :coord-mode
  11. coord-mode? coord-modes coord-mode-name coord-mode-index
  12. (origin previous))
  13. (define-exported-binding "scx-coord-mode" :coord-mode)
  14. (import-xlib-function draw-point (display drawable gc x y)
  15. "scx_Draw_Point")
  16. ;; points has to be a list of (x . y) pairs
  17. (import-xlib-function draw-points (display drawable gc points mode)
  18. "scx_Draw_Points")
  19. ;; *** draw lines, polygons ******************************************
  20. (import-xlib-function draw-line (display drawable gc x1 y1 x2 y2)
  21. "scx_Draw_Line")
  22. ;; points has to be a list of (x . y) pairs
  23. (import-xlib-function draw-lines (display drawable gc points mode)
  24. "scx_Draw_Lines")
  25. (import-xlib-function draw-segments (display drawable gc segments)
  26. "scx_Draw_Segments")
  27. (define-record-type segment :segment
  28. (make-segment x1 y1 x2 y2)
  29. segment?
  30. (x1 segment:x1 set-segment:x1!)
  31. (y1 segment:y1 set-segment:y1!)
  32. (x2 segment:x2 set-segment:x2!)
  33. (y2 segment:y2 set-segment:y2!))
  34. (define-exported-binding "scx-segment" :segment)
  35. ;; *** draw rectangles ***********************************************
  36. (import-xlib-function draw-rectangle
  37. (display drawable gc x y width height)
  38. "scx_Draw_Rectangle")
  39. (define-record-type rectangle :rectangle
  40. (make-rectangle x y width height)
  41. rectangle?
  42. (x rectangle:x set-rectangle:x!)
  43. (y rectangle:y set-rectangle:y!)
  44. (width rectangle:width set-rectangle:width!)
  45. (height rectangle:height set-rectangle:height!))
  46. (define-record-discloser :rectangle
  47. (lambda (r)
  48. `(Rectangle ,(rectangle:x r) ,(rectangle:y r)
  49. ,(rectangle:width r) ,(rectangle:height r))))
  50. (define-exported-binding "scx-rectangle" :rectangle)
  51. (import-xlib-function draw-rectangles (display drawable gc rectangles)
  52. "scx_Draw_Rectangles")
  53. ;; *** draw arcs *****************************************************
  54. (import-xlib-function draw-arc
  55. (display drawable gc x y width height angle1 angle2)
  56. "scx_Draw_Arc")
  57. (define-record-type arc :arc
  58. (make-arc x y width height angle1 angle2)
  59. arc?
  60. (x arc:x set-arc:x!)
  61. (y arc:y set-arc:y!)
  62. (width arc:width set-arc:width!)
  63. (height arc:height set-arc:height!)
  64. (angle1 arc:angle1 set-arc:angle1!)
  65. (angle2 arc:angle2 set-arc:angle2!))
  66. (define-exported-binding "scx-arc" :arc)
  67. (import-xlib-function draw-arcs (display drawable gc arcs)
  68. "scx_Draw_Arcs")
  69. ;; *** fill rectangles, polygons, or arcs ****************************
  70. (import-xlib-function fill-rectangle
  71. (display drawable gc x y width height)
  72. "scx_Fill_Rectangle")
  73. (import-xlib-function fill-rectangles (display drawable gc rectangles)
  74. "scx_Fill_Rectangles")
  75. (define-enumerated-type polygon-shape :polygon-shape
  76. polygon-shape? polygon-shapes polygon-shape-name polygon-shape-index
  77. (complex non-convex convex))
  78. (define-exported-binding "scx-polygon-shape" :polygon-shape)
  79. (import-xlib-function fill-polygon (display drawable gc points shape mode)
  80. "scx_Fill_Polygon")
  81. (import-xlib-function fill-arc
  82. (display drawable gc x y width height angle1 angle2)
  83. "scx_Fill_Arc")
  84. ;; arcs has to be a list of (x y width height angle1 angle2) lists.
  85. (import-xlib-function fill-arcs (display drawable gc arcs)
  86. "scx_Fill_Arcs")
  87. ;; *** auxiliary functions *******************************************
  88. (define (bounds x1 y1 x2 y2)
  89. (make-rectangle x1 y1 (- x2 x1) (- y2 y1)))
  90. (define (grow-rectangle r dw dh . maybe-centric?)
  91. (if (or (null? maybe-centric?) (not (car maybe-centric?)))
  92. (make-rectangle (rectangle:x r) (rectangle:y r)
  93. (+ (rectangle:width r) dw)
  94. (+ (rectangle:height r) dh))
  95. (make-rectangle (- (rectangle:x r) (quotient dw 2))
  96. (- (rectangle:y r) (quotient dh 2))
  97. (+ (rectangle:width r) dw)
  98. (+ (rectangle:height r) dh))))
  99. (define (move/resize-rectangle r dx dy dw dh)
  100. (make-rectangle (+ (rectangle:x r) dx)
  101. (+ (rectangle:y r) dy)
  102. (+ (rectangle:width r) dw)
  103. (+ (rectangle:height r) dh)))