IUP

Check-in [62b8ff14c4]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Racket bindings for the IupMglPlot controls
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 62b8ff14c4417a46784f3972eba22e4da20583fa
User & Date: murphy 2015-05-01 17:00:13.270
Context
2015-05-01
17:08
Make mgllabel title argument optional check-in: 6d25af7227 user: murphy tags: trunk
17:00
Racket bindings for the IupMglPlot controls check-in: 62b8ff14c4 user: murphy tags: trunk
14:40
Switch from PLaneT to collections paths, ocumentation updates check-in: 9c1925379a user: murphy tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Added racket/mglplot.rkt.






























































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#lang racket
(require
 ffi/unsafe
 "base.rkt")

(define libiup-mglplot
  (case (system-type 'os)
    [(windows)
     (ffi-lib "iup_mglplot")]
    [else
     (ffi-lib "libiup_mglplot")]))

;; MglPlot controls

(define mglplot
  (make-constructor-procedure
   (get-ffi-obj
    "IupMglPlot" libiup-mglplot
    (_fun -> [handle : _ihandle]))))

(define mgllabel
  (make-constructor-procedure
   (get-ffi-obj
    "IupMglLabel" libiup-mglplot
    (_fun [title : _string/utf-8] -> [handle : _ihandle]))))

;; Plotting functions

(define call-with-mglplot
  (letrec ([mglplot-begin
            (get-ffi-obj
             "IupMglPlotBegin" libiup-mglplot
             (_fun [handle : _ihandle] [dimension : _int] -> _void))]
           [mglplot-end
            (get-ffi-obj
             "IupMglPlotEnd" libiup-mglplot
             (_fun [handle : _ihandle] -> _void))])
    (λ (handle proc #:dimension [dimension 2])
      (dynamic-wind
       (λ ()
         (mglplot-begin handle dimension))
       (λ ()
         (proc handle))
       (λ ()
         (mglplot-end handle))))))

(define mglplot-add!
  (letrec ([append/1d
            (get-ffi-obj
             "IupMglPlotAdd1D" libiup-mglplot
             (_fun [handle : _ihandle] [x : _string/utf-8] [y : _double]
                   -> _void))]
           [append/2d
            (get-ffi-obj
             "IupMglPlotAdd2D" libiup-mglplot
             (_fun [handle : _ihandle] [x : _double] [y : _double]
                   -> _void))]
           [append/3d
            (get-ffi-obj
             "IupMglPlotAdd3D" libiup-mglplot
             (_fun [handle : _ihandle] [x : _double] [y : _double] [z : _double]
                   -> _void))]
           [insert/1d
            (get-ffi-obj
             "IupMglPlotInsert1D" libiup-mglplot
             (_fun [handle : _ihandle] [index : _int] [sample-index : _int] [x : (_ptr i _string/utf-8)] [y : (_ptr i _double)] [count : _int = 1]
                   -> _void))]
           [insert/2d
            (get-ffi-obj
             "IupMglPlotInsert2D" libiup-mglplot
             (_fun [handle : _ihandle] [index : _int] [sample-index : _int] [x : (_ptr i _double)] [y : (_ptr i _double)] [count : _int = 1]
                   -> _void))]
           [insert/3d
            (get-ffi-obj
             "IupMglPlotInsert3D" libiup-mglplot
             (_fun [handle : _ihandle] [index : _int] [sample-index : _int] [x : (_ptr i _double)] [y : (_ptr i _double)] [z : (_ptr i _double)] [count : _int = 1]
                   -> _void))]
           [current-index
            (λ (handle)
              (string->number (attribute handle 'current)))])
    (λ (handle x y [z #f] [sample-index #f] [index #f])
      (cond
        [z
         (if sample-index
             (insert/3d handle (or index (current-index handle)) sample-index (exact->inexact x) (exact->inexact y) (exact->inexact z))
             (append/3d handle (exact->inexact x) (exact->inexact y) (exact->inexact z)))]
        [(string? x)
         (if sample-index
             (insert/1d handle (or index (current-index handle)) sample-index x (exact->inexact y))
             (append/1d handle x (exact->inexact y)))]
        [else
         (if sample-index
             (insert/2d handle (or index (current-index handle)) sample-index (exact->inexact x) (exact->inexact y))
             (append/2d handle (exact->inexact x) (exact->inexact y)))]))))

(define mglplot-x/y/z->pixel-x/y
  (get-ffi-obj
   "IupMglPlotTransform" libiup-mglplot
   (_fun (handle x y [z 0.0])
         :: [handle : _ihandle]
            [mglplot-x : _double = (exact->inexact x)] [mglplot-y : _double = (exact->inexact y)] [mglplot-z : _double = (exact->inexact z)]
            [pixel-x : (_ptr o _int)] [pixel-y : (_ptr o _int)]
         -> _void
         -> (values pixel-x pixel-y))))

(define mglplot-paint-to
  (get-ffi-obj
   "IupMglPlotPaintTo" libiup-mglplot
   (_fun (handle format file [width 0] [height 0] [dpi 0])
         :: [handle : _ihandle] [format : _string/utf-8]
            [width : _int] [height : _int] [dpi : _int]
            [file : _string]
         -> _void)))

;; Library setup

(letrec ([open
          (get-ffi-obj
           "IupMglPlotOpen" libiup-mglplot
           (_fun -> _void))])
  (open))

(provide
 mglplot mgllabel
 call-with-mglplot mglplot-add!
 mglplot-x/y/z->pixel-x/y
 mglplot-paint-to)