rmloveland

ezdish.scm

Jun 27th, 2020
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 29.08 KB | None | 0 0
  1. (module-extends javafx.application.Application)
  2.  
  3. (import (srfi 1)
  4.         (except (kawa base) match)
  5.         (srfi 9 records)
  6.         (class javafx.application Application)
  7.         (class javafx.scene Group Scene)
  8.         (class javafx.stage Stage)
  9.         (class javafx.scene.canvas Canvas)
  10.         (class javafx.scene.control Button)
  11.         (class javafx.print PrinterJob)
  12.         (class javafx.scene.layout VBox)
  13.         (class javafx.scene.layout HBox)
  14.         (class javafx.scene.canvas GraphicsContext)
  15.         (class javafx.scene.paint Color))
  16.  
  17. ;; Each 'window' is a JavaFX scenegraph
  18.  
  19. (define *windows* '())
  20.  
  21. (define *drawings* '())
  22.  
  23. (define-record-type window
  24.   (make-window name width height root)
  25.   window?
  26.   (name window-name set-window-name!)
  27.   (width window-width set-window-width!)
  28.   (height window-height set-window-height!)
  29.   (root window-root set-window-root!))
  30.  
  31. ;; A drawing is a JavaFX 2d Canvas
  32. (define-record-type drawing
  33.   (make-drawing canvas)
  34.   drawing?
  35.   (canvas drawing-canvas set-drawing-canvas!))
  36.  
  37. (define-record-type line
  38.   (make-line x0 y0 x1 y1)
  39.   line?
  40.   (x0 line-x0 set-line-x0!)
  41.   (x1 line-x1 set-line-x1!)
  42.   (y0 line-y0 set-line-y0!)
  43.   (y1 line-y1 set-line-y1!))
  44.  
  45. ;; Default drawing
  46. (define *ezd* (make-drawing (Canvas 800 800)))
  47.  
  48. (set! *drawings* (cons *ezd* *drawings*))
  49.  
  50. (define (ezd-one command)
  51.   ;; A COMMAND is an s-expression of the form:
  52.   ;; (command ...)
  53.   (let ((command-name (car command)))
  54.     (case command-name
  55.       ((window)
  56.        (match
  57.         command
  58.         ((_ name width height)
  59.          (let* ((name (Group))
  60.                 (scene (Scene name width height)))
  61.            (set! *windows* (cons name *windows*))))))
  62.       ((line)
  63.        (match
  64.         command
  65.         ((_ x0 y0 x1 y1)
  66.          (let* ((drawing (first *drawings*))
  67.                 (canvas (drawing-canvas drawing))
  68.                 (context (canvas:getGraphicsContext2D))
  69.                 (window (first *windows*))
  70.                 (children (window:getChildren))
  71.                 (lin (make-line x0 y0 x1 y1)))
  72.            (begin
  73.              (children:add canvas)
  74.              (context:moveTo (line-x0 lin) (line-y0 lin))
  75.              (context:lineTo (line-x1 lin) (line-y1 lin))))))))))
  76.  
  77. (define (start (stage ::Stage))
  78.   (begin
  79.     (ezd-one '(window popup 800 800))
  80.     (ezd-one '(line 0 0 400 400))
  81.     (display *windows*)))
  82.  
  83. (Application:launch (module-class))
  84.  
  85. ;; eof
  86.  
  87. ;; COMPILATION OUTPUT
  88.  
  89. ;; -*- mode: compilation; default-directory: "c:/Users/rml/Dropbox/Code/ezdfx/" -*-
  90. ;; Compilation started at Sat Jun 27 23:08:54
  91.  
  92. ;; cd .. && make ezdish
  93. ;; kawa test/ezdish.scm
  94.  
  95. ;; c:\Users\rml\Dropbox\Code\ezdfx>"c:/Program Files/AdoptOpenJDK/jdk-11.0.7.10-hotspot/bin/java.exe" --module-path "c:/Users/rml/Downloads/javafx-sdk-11.0.2/lib" --add-modules javafx.controls -classpath "C:\Users\rml\Dropbox\Code\personal\classpath\kawa.jar" kawa.repl --console  test/ezdish.scm
  96. ;; test/ezdish.scm:736:27: warning - no known slot 'getGraphicsContext2D' in java.lang.Object
  97. ;; test/ezdish.scm:738:28: warning - no known slot 'getChildren' in java.lang.Object
  98. ;; test/ezdish.scm:741:15: warning - no known slot 'add' in java.lang.Object
  99. ;; test/ezdish.scm:742:15: warning - no known slot 'moveTo' in java.lang.Object
  100. ;; test/ezdish.scm:743:15: warning - no known slot 'lineTo' in java.lang.Object
  101. ;; Exception in Application start method
  102. ;; java.lang.RuntimeException: Exception in Application start method
  103. ;;  at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
  104. ;;  at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
  105. ;;  at java.base/java.lang.Thread.run(Thread.java:834)
  106. ;; Caused by: Argument  (null) to 'car' has wrong type
  107. ;;  at gnu.mapping.CallContext.matchError(CallContext.java:185)
  108. ;;  at gnu.expr.GenericProc.applyToConsumerGP(GenericProc.java:132)
  109. ;;  at gnu.mapping.CallContext.runUntilDone(CallContext.java:586)
  110. ;;  at gnu.mapping.CallContext.runUntilValue(CallContext.java:669)
  111. ;;  at gnu.mapping.Procedure.apply1(Procedure.java:154)
  112. ;;  at test.ezdish.ezdOne(ezdish.scm:734)
  113. ;;  at test.ezdish.ezdOne$check(ezdish.scm:718)
  114. ;;  at gnu.mapping.CallContext.runUntilValue(CallContext.java:656)
  115. ;;  at gnu.mapping.Procedure.apply1(Procedure.java:154)
  116. ;;  at test.ezdish.start(ezdish.scm:748)
  117. ;;  at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
  118. ;;  at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
  119. ;;  at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
  120. ;;  at java.base/java.security.AccessController.doPrivileged(Native Method)
  121. ;;  at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
  122. ;;  at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
  123. ;;  at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
  124. ;;  at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
  125. ;;  ... 1 more
  126.  
  127. ;; c:\Users\rml\Dropbox\Code\ezdfx>rem "java.exe" -classpath "C:\Users\rml\Dropbox\Code\personal\classpath\kawa.jar" kawa.repl --console --no-inline --r5rs test/ezdish.scm
  128.  
  129. ;; c:\Users\rml\Dropbox\Code\ezdfx>rem -Dkawa.import.path=".:./lib/"
  130.  
  131. ;; Compilation finished at Sat Jun 27 23:08:58
Add Comment
Please, Sign In to add comment