From 94e1881676e39bd8b8e6a8ee98e541102b380549 Mon Sep 17 00:00:00 2001 From: Henrique Alves Date: Sun, 28 Apr 2024 22:20:26 +0300 Subject: prototyping runtime code evaluation --- scripts/main.scm | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) (limited to 'scripts/main.scm') diff --git a/scripts/main.scm b/scripts/main.scm index 0e98e7a..048c7eb 100644 --- a/scripts/main.scm +++ b/scripts/main.scm @@ -7,27 +7,48 @@ (define text-box (make-rect 30 180 250 80)) (define mouse-on-text #f) +(define prompt-text "") (define (update) -;; (cond ((rl-is-key-down KEY_RIGHT) (set! b (rl-load-texture))) ;; right -;; ((rl-is-key-down KEY_LEFT) (set! a (+ a 1))) ;; left -;; ((rl-is-key-down KEY_DOWN) (gc)) ;; down -;; ) -;; (display (rl-get-mouse-position)) -;; (newline) + ;; (cond ((rl-is-key-down KEY_RIGHT) (set! b (rl-load-texture))) ;; right + ;; ((rl-is-key-down KEY_LEFT) (set! a (+ a 1))) ;; left + ;; ((rl-is-key-down KEY_DOWN) (gc)) ;; down + ;; ) + ;; (display (rl-get-mouse-position)) + ;; (newline) (define mouse-pos (rl-get-mouse-position)) (define mouse-pos-point (make-point (mouse-pos 0) (mouse-pos 1))) (set! mouse-on-text (is-point-inside-rect? mouse-pos-point text-box)) - + (if mouse-on-text + (let ((key (rl-get-char-pressed))) + (cond ((and (>= key 32) (<= key 125)) + (set! prompt-text + (string-append prompt-text (string (integer->char key))))) + ) + )) + + (if (rl-is-key-down KEY_ENTER) + (begin + (eval-string prompt-text))) + #f ) (define (draw) - (rl-draw-rectangle (rect-x text-box) (rect-y text-box) (rect-width text-box) (rect-height text-box) (make-color 190 100 255)) + (rl-draw-rectangle + (rect-x text-box) + (rect-y text-box) + (rect-width text-box) + (rect-height text-box) + (make-color 190 100 255)) - (rl-draw-text (format #f "~A" mouse-on-text) 100 100 30 (make-color 100 100 100)) - #f + (rl-draw-text + (format #f "~A" mouse-on-text) 100 100 30 (make-color 100 100 100)) + + (rl-draw-text prompt-text 30 180 20 (make-color 0 0 0)) ) + + -- cgit v1.2.3