Guest User

Untitled

a guest
May 22nd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 30.81 KB | None | 0 0
  1. (module canvas-module
  2.   (import globals)
  3.   (import rooms-module)
  4.   (export
  5.    load-canvas))
  6.  
  7.  
  8.  
  9. (define (load-canvas)
  10.   ~(begin
  11.      (define activecolor "#FF0000")
  12.      (define shapes '())
  13.      (define drawwidth 10)
  14.      (define bordercolor "#000000")
  15.      (define borderwidth 10)
  16.      (define selectedshape '())
  17.      (define movableshape '())
  18.      (define disableclick #f)
  19.      (define selectedmode "draw")
  20.      (define resizableid '())
  21.      (define selectedid '())
  22.      (define xycord '())
  23.      
  24.      (define canvas-width 600)
  25.      (define canvas-height 400)
  26.      ;This represents the objects that can be drawn onto the canvas on the clientside.
  27.      (define (makeshape lid ltype lx ly lw lh lcolor lbw lbc)
  28.        (lambda (message)
  29.          (case message
  30.            ((id) lid)
  31.            ((type) ltype )
  32.            ((x) lx)
  33.            ((y)  ly)
  34.            ((w)  lw)
  35.            ((h) lh)
  36.            ((color)lcolor)
  37.            ((bw)  lbw)
  38.            ((bc)  lbc)
  39.            ((set-x!)
  40.             (lambda (new-value)
  41.               (set! lx new-value)  ;; do the assignment
  42.               lx))                ;; return the new value
  43.            ((set-y!)
  44.             (lambda (new-value)
  45.               (set! ly new-value)  ;; do the assignment
  46.               ly))                          
  47.            ((set-w!)
  48.             (lambda (new-value)
  49.               (set! lw new-value)
  50.               lw))                            
  51.            ((set-h!)
  52.             (lambda (new-value)
  53.               (set! lh new-value)
  54.               lh))                            
  55.            ((set-color!)
  56.             (lambda (new-value)
  57.               (set! lcolor new-value)
  58.               lcolor))                          
  59.            ((set-bw!)
  60.             (lambda (new-value)
  61.               (set! lbw new-value)
  62.               lbw))                          
  63.            ((set-bc!)
  64.             (lambda (new-value)
  65.               (set! lbc new-value)
  66.               lbc))              
  67.            (else (error "Shape: Unknown message ->" message)))))
  68.      
  69.      
  70.      
  71.      
  72.      ;***********************DRAWING FUNCTIONS************************  
  73.      
  74.      (define (draw-ellipse ctx x y width height)
  75.        (if (< width height)
  76.            (begin
  77.              (canvas-scale ctx 1 2)
  78.              (canvas-arc ctx x  (/ y 2) width 0 (* Math.PI 2) 1))
  79.            (begin
  80.              (canvas-scale ctx 2 1)
  81.              (canvas-arc ctx (/ x 2) y width 0 (* Math.PI 2) 1))))
  82.      
  83.      (define (iter-line-to p ctx)
  84.        (if (not (null? p))
  85.            (let ((np (car p)))
  86.              (canvas-line-to ctx (car np) (cdr np))
  87.              (iter-line-to (cdr p) ctx)))
  88.        )  
  89.      
  90.      ;Makes the path of the line
  91.      (define (make-path-line ctx x y width path)
  92.        (canvas-begin-path ctx)
  93.        (canvas-close-path ctx)
  94.        (if (null? (cdr path))    
  95.            (begin
  96.              (iter-line-to path ctx)
  97.              (canvas-line-to ctx x y))
  98.            
  99.            (iter-line-to path ctx))
  100.        )
  101.      
  102.      ;Makes the path a a polynome
  103.      (define (make-path-poly ctx x y width path)
  104.        
  105.        (canvas-begin-path ctx)
  106.        (iter-line-to  path ctx)
  107.        (canvas-close-path ctx)
  108.        )
  109.      
  110.      ;Makes the path of the ellipse
  111.      (define (make-path-ellipse ctx x y height width)
  112.        (canvas-save ctx)
  113.        (canvas-begin-path ctx)
  114.        (draw-ellipse ctx x y width height)
  115.        (canvas-close-path ctx)
  116.        (canvas-restore ctx))
  117.      
  118.      ;Makes the path of the rectangle
  119.      (define (make-path-rectangle ctx x y width height)
  120.        (canvas-begin-path ctx)
  121.        (ctx.rect x y width height)
  122.        (canvas-close-path ctx))
  123.      
  124.      ;If we have build the path we will fill in the canvas and stroke it to draw
  125.      (define (drawshape ctx)
  126.        (canvas-stroke ctx)
  127.        (canvas-fill ctx))
  128.      
  129.      
  130.      ;****************SET settings at runtime*************************
  131.      (define (initialise-settings)
  132.        ( canvas-properties-set! (canvas-get-context (dom-get-element-by-id "activecanvas") "2d")
  133.                                 :stroke-style drawwidth
  134.                                 :fill-style activecolor
  135.                                 :line-width borderwidth;
  136.                                 :font "20pt Arial"))
  137.      
  138.      
  139.      ;Will return the shape object with the corresponding id
  140.      (define (getshape id)
  141.        (define (iter shapes)
  142.          (if (eq? '() shapes)
  143.              '()
  144.              (let ((shape (car shapes)))
  145.                (if (eq? (shape 'id) id)
  146.                    shape
  147.                    (iter (cdr shapes))))))
  148.        (iter shapes))  
  149.      
  150.      ;Will remover the shape object with the corresponding id
  151.      (define (deleteshape id)
  152.        (define (iter shapes)
  153.          (if (eq? '() shapes)
  154.              '()
  155.              (let ((shape (car shapes)))
  156.                (if (eq? (shape 'id) id)
  157.                    (cdr shapes)
  158.                    (cons shape (iter (cdr shapes)))))))
  159.        (set! shapes (iter shapes)))
  160.      
  161.      
  162.      ;activates a shape based on its id
  163.      (define (select-shape x y)
  164.        (define (iter shapes)
  165.          (if (equal? shapes '())
  166.              (begin (set! disableclick #f)'())
  167.              (let ((shape (car shapes))
  168.                    (ctx (canvas-get-context (dom-get-element-by-id "activecanvas") "2d")))
  169.                (case (shape 'type)
  170.                  (("ellipse")
  171.                   (make-path-ellipse ctx (shape 'x) (shape 'y) (shape 'w) (shape 'h)))
  172.                  (("line")
  173.                   (make-path-line ctx (shape 'x) (shape 'y) (shape 'w) (shape 'h)))
  174.                  (("poly")
  175.                   (make-path-poly ctx (shape 'x) (shape 'y) (shape 'w) (shape 'h)))
  176.                  (("rectangle")
  177.                   (make-path-rectangle ctx (shape 'x) (shape 'y) (shape 'w) (shape 'h)))
  178.                  (else (cons shape(iter (cdr shapes)))))
  179.                (if (ctx.isPointInPath x y)
  180.                    (begin
  181.                      (set! disableclick #t)
  182.                      (set! selectedshape shape)
  183.                      (cdr shapes))
  184.                    (cons shape (iter (cdr shapes)))
  185.                    ))
  186.              ))
  187.        (if (null? selectedshape)
  188.            (set! shapes (iter shapes))
  189.            ;If there is a shape selected we need to check if we do not reselect it otherwise it has to join the other shapes.
  190.            (begin
  191.              (let ((temp selectedshape))
  192.                (set! selectedshape '())
  193.                (iter (list temp))
  194.                (if (null? selectedshape)
  195.                    (set! shapes (cons temp (iter shapes)))
  196.                    
  197.                    )))
  198.            ))
  199.      
  200.      
  201.      
  202.      ;Clears the canvas (statical size)
  203.      (define (canvas-clear)  (canvas-clear-rect (canvas-get-context (dom-get-element-by-id "activecanvas") "2d")  0 0 canvas-width canvas-height))
  204.      
  205.      
  206.      ;This will redraw the entire canvas
  207.      (define (redraw)
  208.        (canvas-clear)
  209.        (draw  shapes)
  210.        (if (not (null? selectedshape))
  211.            (begin
  212.              (convertcommand selectedshape 1))))
  213.      
  214.      ;This will draw shape by shape
  215.      (define (draw localshapes)
  216.        (if (equal? '() localshapes)
  217.            #t
  218.            (let ((shape (car localshapes)))
  219.              (convertcommand shape 0)
  220.              (draw (cdr localshapes))
  221.              )))
  222.      
  223.      ;This will convert the list from the server to shape objects we draw locally
  224.      (define (convertservershapes lst)
  225.        (define (iter loclst)
  226.          (if (eq? '() loclst)
  227.              '()
  228.              (begin
  229.                (cons (converttoshape (car loclst)) (iter(cdr loclst))))))
  230.        (iter lst))
  231.      
  232.      ;Replace an existing shape with the new one (same id)
  233.      (define (set-new replaceshape)
  234.        (define (iter lshapes)
  235.          (if (eq? lshapes '())
  236.              '()
  237.              (let ((shape (car lshapes)))
  238.                (if (eq? (replaceshape 'id)(shape 'id))
  239.                    (cons replaceshape (cdr lshapes))
  240.                    (cons shape (iter (cdr lshapes)))))))
  241.        (set! shapes (iter shapes))
  242.        )
  243.      
  244.      
  245.      
  246.      ; We update a shape with new values from a list
  247.      (define (change lst)
  248.        (if (and selectedshape (eq? (selectedshape 'id) (car lst)))
  249.            (begin
  250.              (set! selectedshape (converttoshape lst))
  251.              )
  252.            (set-new (converttoshape lst))
  253.            )
  254.        (redraw))
  255.      
  256.      
  257.      ;Make an object shape from a list given from the server
  258.      (define (converttoshape lst)
  259.        (apply makeshape lst)
  260.        )
  261.      
  262.      ;we convert a command (a shape) and draw it on the canvas
  263.      (define (convertcommand command selected)
  264.        (let* ((ctx (canvas-get-context (dom-get-element-by-id "activecanvas") "2d") )
  265.               (bw (command 'bw))
  266.               (bc (command 'bc))
  267.               (color (command 'color))
  268.               (todraw (list (command 'x)(command 'y)(command 'w)(command 'h)))
  269.               )
  270.          (if (eq? 1 selected )
  271.              (canvas-properties-set! ctx
  272.                                      :stroke-style "yellow"
  273.                                      :fill-style color
  274.                                      :line-width bw)
  275.              (canvas-properties-set! ctx
  276.                                      :stroke-style bc
  277.                                      :fill-style color
  278.                                      :line-width bw))
  279.          (if (equal? "rectangle" (command 'type))(begin (apply make-path-rectangle (cons ctx todraw))(drawshape ctx)))
  280.          (if (equal? "ellipse" (command 'type)) (begin (apply make-path-ellipse (cons ctx todraw)) (drawshape ctx)))
  281.          (if (equal? "poly" (command 'type)) (begin (apply make-path-poly (cons ctx todraw)) (drawshape ctx)))
  282.          (if (equal? "line" (command 'type)) (begin
  283.                                                (canvas-properties-set! ctx
  284.                                                                        :stroke-style color
  285.                                                                        :fill-style color
  286.                                                                        :line-width bw)
  287.                                                (apply make-path-line (cons ctx todraw)) (canvas-stroke ctx)))
  288.          ))
  289.      
  290.      
  291.      
  292.      
  293.      
  294.      
  295.      ;We update the coordinates of a complete path (for moving polynomes and lines
  296.      (define (update-coords path x y)
  297.        (define (iter p x y)
  298.          (if (null? p)
  299.              '()
  300.              (let* ((cord (car p))
  301.                     (inbetween (cons (+ (car cord) x) (+ (cdr cord) y))))
  302.                (cons inbetween (update-coords (cdr p) x y)))))
  303.        (iter path x y))
  304.      
  305.      ;This function will update the selected shape when required.
  306.      (define (updateselected c bw bc)
  307.        (with-hop ($change room
  308.                           (list (selectedshape 'id)
  309.                                 (selectedshape 'type)
  310.                                 (selectedshape 'x)
  311.                                 (selectedshape 'y)
  312.                                 (selectedshape 'w)
  313.                                 (selectedshape 'h)
  314.                                 c
  315.                                 bw
  316.                                 bc)
  317.                           )))
  318.      
  319.      
  320.      
  321.      
  322.      
  323.      (define (joinroom joinedroom)
  324.        (set! room joinedroom)
  325.        (let ((activecanvas (<CANVAS> :id "activecanvas"
  326.                                      :width canvas-width;
  327.                                      :height canvas-height;
  328.                                      :style "border: 1px solid black"))
  329.              (colorpicker1 "echo")
  330.              (serverevent (lambda (x)
  331.                             (let ((info (cdr x.value)))
  332.                               (case (car x.value)
  333.                                 (("change")
  334.                                  (change info ))
  335.                                 (("delete")
  336.                                  (if (and selectedshape (eq? (selectedshape 'id) info))
  337.                                      (set! selectedshape '())
  338.                                      (deleteshape info)))
  339.                                 (else
  340.                                  (set! shapes (cons (converttoshape x.value) shapes))))
  341.                               (redraw))
  342.                             )
  343.                           ))
  344.          
  345.          
  346.          
  347.          ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  348.          
  349.          ;Events definitions
  350.          (define (add-click)
  351.            (add-event-listener! activecanvas "click" (lambda (x)
  352.                                                        ;We check if we are in the click mode
  353.                                                        (if (and (equal? selectedmode "click") (null? selectedshape))
  354.                                                            (let* ((toextend (getshape selectedid))
  355.                                                                   (xcord (- (event-mouse-x x) activecanvas.offsetLeft))
  356.                                                                   (ycord (-  (event-mouse-y x) activecanvas.offsetTop)))
  357.                                                              (if (null? selectedid)
  358.                                                                  (with-hop ($broadcast room   (list  "poly" xcord ycord drawwidth
  359.                                                                                                      (list (cons (+ 1 xcord)(+ 1 ycord)))
  360.                                                                                                      activecolor borderwidth bordercolor))
  361.                                                                            (lambda (x)
  362.                                                                              (set! selectedid x) ))
  363.                                                                  ;If there is a selectedid (shape in making)
  364.                                                                  (with-hop ($change room
  365.                                                                                     (list (toextend 'id)(toextend 'type)(toextend 'x)
  366.                                                                                           (toextend 'y)(toextend 'w)
  367.                                                                                           (cons (cons xcord ycord) (toextend 'h))
  368.                                                                                           (toextend 'color) (toextend 'bw)(toextend 'bc))
  369.                                                                                     )))
  370.                                                              )
  371.                                                            (set! selectedid '())
  372.                                                            )) 1))
  373.          
  374.          (define (add-mousedown)
  375.            (add-event-listener! activecanvas "mousedown" (lambda (x)
  376.                                                            ;check to select
  377.                                                            (let ((xcord (- (event-mouse-x x) activecanvas.offsetLeft))
  378.                                                                  (ycord (-  (event-mouse-y x) activecanvas.offsetTop)))
  379.                                                              (select-shape xcord ycord)
  380.                                                              (set! movableshape selectedshape)
  381.                                                              ;(alert movableshape)
  382.                                                              (redraw)
  383.                                                              
  384.                                                              ;if none is selected
  385.                                                              (if (null? selectedshape)
  386.                                                                  (if (not disableclick)
  387.                                                                      (let ((lst (case selectedmode
  388.                                                                                   (("draw") (list  "line" xcord ycord drawwidth
  389.                                                                                                    (list (cons (+ 1 xcord) (+ 1 ycord)))
  390.                                                                                                    activecolor borderwidth bordercolor))
  391.                                                                                   (("ellipse") (list  "ellipse" xcord ycord drawwidth
  392.                                                                                                       drawwidth activecolor borderwidth bordercolor))
  393.                                                                                   (("rectangle") (list  "rectangle" xcord ycord 10 10
  394.                                                                                                         activecolor borderwidth bordercolor))
  395.                                                                                   (else '()))))
  396.                                                                        (if (not (null? lst))
  397.                                                                            (with-hop ($broadcast room lst)
  398.                                                                                      (lambda (x) (set! resizableid x)))))
  399.                                                                      (begin
  400.                                                                        (set! shapes (cons selectedshape shapes))
  401.                                                                        (set! selectedshape '())
  402.                                                                        (set! movableshape '())))
  403.                                                                  ;if a shape was selected
  404.                                                                  (begin (set! xycord (cons  xcord ycord))
  405.                                                                         (set! resizableid '()))
  406.                                                                  )))#t))
  407.          
  408.          
  409.          
  410.          
  411.          (define (add-mousemove)
  412.            (add-event-listener! activecanvas "mousemove" (lambda (x)
  413.                                                            (let ((xcord (- (event-mouse-x x) activecanvas.offsetLeft))
  414.                                                                  (ycord (-  (event-mouse-y x) activecanvas.offsetTop)))
  415.                                                              (if (not (null? resizableid))
  416.                                                                  (let* ((todrag (getshape resizableid))
  417.                                                                         (lst (case (todrag 'type)
  418.                                                                                (("rectangle")(list (- xcord (todrag 'x))
  419.                                                                                                    (- ycord (todrag 'y))))
  420.                                                                                (("ellipse")(list   (abs (- xcord (todrag 'x)) )
  421.                                                                                                    (abs (- ycord (todrag 'y)) )))
  422.                                                                                (("line")(list (todrag 'w)
  423.                                                                                               (cons (cons xcord ycord) (todrag 'h)))))
  424.                                                                              ))
  425.                                                                    (with-hop ($change room
  426.                                                                                       (append (list (todrag 'id)(todrag 'type)(todrag 'x)(todrag 'y))
  427.                                                                                               lst (list
  428.                                                                                                    (todrag 'color)(todrag 'bw)(todrag 'bc)))))
  429.                                                                    )
  430.                                                                  ;;;;;;;;;;;;;;;;;HERE IS THE CODE TO MOVE A SHAPE;;;;;;;;;;;;;;;;;
  431.                                                                  (if (and (not (null? movableshape)) (not (null? selectedshape)))
  432.                                                                      (let* ((offsetx (- xcord (car xycord)))
  433.                                                                             (offsety (- ycord (cdr xycord)))
  434.                                                                             (lst
  435.                                                                              (if  (or (equal? (movableshape 'type)"line")
  436.                                                                                       (equal? (movableshape 'type)"poly"))
  437.                                                                                   (list  (- (selectedshape 'x) offsetx)
  438.                                                                                          (- (selectedshape 'y) offsety)(selectedshape 'w)
  439.                                                                                          (update-coords (selectedshape 'h) offsetx offsety))
  440.                                                                                   (list   (+(selectedshape 'x) offsetx)(+(selectedshape 'y) offsety)
  441.                                                                                           (selectedshape 'w)(selectedshape 'h))
  442.                                                                                   )))
  443.                                                                        (set! movableshape selectedshape)
  444.                                                                        (with-hop ($change room
  445.                                                                                           (append (list (selectedshape 'id)
  446.                                                                                                         (selectedshape 'type))
  447.                                                                                                   lst
  448.                                                                                                   (list (selectedshape 'color)
  449.                                                                                                         (selectedshape 'bw)
  450.                                                                                                         (selectedshape 'bc)
  451.                                                                                                         ))
  452.                                                                                           ))
  453.                                                                        (set! xycord (cons xcord ycord))
  454.                                                                        ))))) #t))
  455.          
  456.          
  457.          (define (add-mouseup)
  458.            (add-event-listener! activecanvas "mouseup" (lambda (x)
  459.                                                          (set! resizableid '())
  460.                                                          (set! movableshape '()) ) #t))
  461.          
  462.          
  463.          
  464.          
  465.          ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  466.          
  467.          ;Now we draw the html page containg the toolbox and the canvas
  468.          (<DIV> (<H1> "Welcome in " joinedroom ", " user)
  469.                 (<DIV> id: "toolbox"
  470.                        (<P> "Draw Color:" (<BR>)
  471.                             colorpicker1
  472.                             (<COLORCHOOSER> :id "cc"
  473.                 (<INPUT> :type 'button :value "Set stroke color" :onclick (alert "click")))
  474.                            
  475.                            
  476.                             (<INPUT> :type "text" :id "color" :value activecolor :size 8 :onkeyup (begin
  477.                                                                                                     ; (alert this.value)
  478.                                                                                                     (set! activecolor this.value)
  479.                                                                                                     (updateselected activecolor (selectedshape 'bw)(selectedshape 'bc))
  480.                                                                                                     )))
  481.                        
  482.                        ;  (<P> "Draw width")
  483.                        ;  (<INPUT> :type "text" :id "thickness" :value drawwidth :onkeyup (begin
  484.                        ;                                                          (set! drawwidth (dom-get-element-by-id "thickness").value)
  485.                        ;                                                         ))
  486.                        
  487.                        
  488.                        (<P> "Border color"
  489.                             (<INPUT> :type "text" :id "bordercolor" :value bordercolor :onkeyup (begin
  490.                                                                                                   (set! bordercolor (dom-get-element-by-id "bordercolor").value)
  491.                                                                                                   (updateselected (selectedshape 'color) (selectedshape 'bw) bordercolor)
  492.                                                                                                   )))
  493.                        
  494.                        (<P> "Border thickness")
  495.                        (<INPUT> :type "text" :id "borderthickness" :value borderwidth :onkeyup(begin
  496.                                                                                                 (set! borderwidth (dom-get-element-by-id "borderthickness"))
  497.                                                                                                 (updateselected (selectedshape 'color) borderwidth (selectedshape 'bc))
  498.                                                                                                 ))
  499.                        
  500.                        (<P> "Draw mode"
  501.                             (<SELECT> :onchange (set! selectedmode this.value)
  502.                                       (<OPTION> :value "draw" "draw" )
  503.                                       (<OPTION> :value "click" "click" )
  504.                                       (<OPTION> :value "rectangle" "rectangle")
  505.                                       (<OPTION> :value "ellipse" "ellipse")
  506.                                       ))
  507.                        
  508.                        (<P> "Other: " (<BR>)
  509.                             (<INPUT> :type "button" :value "delete active" :onclick  (if (not (eq? '() selectedshape)) (with-hop ($deleteshape room ( selectedshape 'id)))))
  510.                             (<INPUT> :type "button" :value "end poly" :onclick  (if (not (eq? '() selectedid)) (set! selectedid '())))
  511.                            
  512.                            
  513.                            
  514.                             (<INPUT> :type "text" :id "savename" :value "")
  515.                             (<INPUT> :type "button" :value "savestate" :onclick
  516.                                      (let ((newname (dom-get-element-by-id "savename").value))
  517.                                        (if (not (equal? "" newname))
  518.                                            (with-hop ($savestate newname room)
  519.                                                      (lambda (x)
  520.                                                        (if (eq? x $FALSE)
  521.                                                            (begin
  522.                                                              (alert "name allready exists"))
  523.                                                            (alert "state succesfully saved"))
  524.                                                        ))
  525.                                            (alert "please give in a name"))))
  526.                             ))
  527.                 ;Toolbox end, starting canvas
  528.                 (<DIV> :id "canvas"                
  529.                        activecanvas
  530.                        (add-click)
  531.                        (add-mousedown)
  532.                        (add-mousemove)
  533.                        (add-mouseup)
  534.                        (add-event-listener! room "server" serverevent #f)
  535.                        )
  536.                
  537.                
  538.                 (<INPUT> :type "button"
  539.                          :value "quit room"
  540.                          :onclick (begin
  541.                                     ;this gives an error in safari
  542.                                     ;    (remove-event-listener! room "server" serverevent #f)
  543.                                    
  544.                                     (with-hop ($removeuserfromroom user room))
  545.                                     ;   (alert room user)
  546.                                     (set! room '())
  547.                                     (set! selectedshape '())
  548.                                     (set! shapes '())  
  549.                                     (set! selectedmode "draw")
  550.                                     (show-welcome)
  551.                                     ))
  552.                 )))            
  553.      
  554.      
  555.      (define (show-room joinedroom) (begin
  556.                                       (innerHTML-set! (dom-get-element-by-id "body") (joinroom joinedroom))
  557.                                       (with-hop ($getcontentfromserver joinedroom) (lambda (x)
  558.                                                                                      (if (not (equal? "()" x))
  559.                                                                                          (begin
  560.                                                                                            (set! shapes (convertservershapes x))
  561.                                                                                            (redraw)
  562.                                                                                            )
  563.                                                                                          ))
  564.                                                 )))))
  565.  
  566.  
  567. (define id 1)
  568.  
  569. (define(get-id)
  570.   (let ((temp id))
  571.     (set! id (+ id 1))
  572.     temp))
  573.  
  574.  
  575. (define-service (change roomname lst)
  576.   (tprint "we change " lst)
  577.   (changeonserver roomname lst)
  578.   (hop-event-broadcast! roomname (cons "change" lst)))
  579.  
  580. (define-service (deleteshape roomname shapeid)
  581.   (tprint "we delete " shapeid)
  582.   (deleteonserver roomname shapeid)
  583.   (hop-event-broadcast! roomname (cons "delete" shapeid)))
  584.  
  585. (define-service (broadcast roomname proc)
  586.   (let* ((newid (get-id))
  587.          (msg (cons  newid proc))
  588.          )
  589.     (tprint roomname " broadcasts " msg )
  590.     (findandaddcontent! roomname msg)
  591.     (hop-event-broadcast! roomname msg)
  592.     newid))
Add Comment
Please, Sign In to add comment