summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/main.scm44
-rw-r--r--scripts/prompt.scm48
2 files changed, 52 insertions, 40 deletions
diff --git a/scripts/main.scm b/scripts/main.scm
index 048c7eb..1a5ebb1 100644
--- a/scripts/main.scm
+++ b/scripts/main.scm
@@ -1,54 +1,18 @@
(load "./scripts/keys.scm")
(load "./scripts/structs.scm")
(load "./scripts/utils.scm")
+(load "./scripts/prompt.scm")
;; (define a 0)
;; (define b (rl-load-texture))
-(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)
-
- (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 (update)
+ (prompt-update)
)
(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-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))
+ (prompt-draw)
)
diff --git a/scripts/prompt.scm b/scripts/prompt.scm
new file mode 100644
index 0000000..738cd42
--- /dev/null
+++ b/scripts/prompt.scm
@@ -0,0 +1,48 @@
+(define prompt-active #f)
+(define prompt-box (make-rect 0 0 800 20))
+(define prompt-text "")
+
+(define (prompt-update)
+ (let ((key-pressed (rl-get-key-pressed)))
+
+
+ (if (eq? key-pressed 161)
+ (set! prompt-active (not prompt-active))
+ )
+
+ (if prompt-active
+ (begin
+ (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)
+ (set! prompt-text "")
+ ))
+
+ (if (eq? key-pressed KEY_BACKSPACE)
+ (let ((n (string-length prompt-text)))
+ (cond ((>= n 1)
+ (set! prompt-text (substring prompt-text 0 (- n 1))))
+ )))
+
+ ))
+ )
+ )
+
+(define (prompt-draw)
+ (if prompt-active
+ (begin
+ (rl-draw-rectangle
+ (rect-x prompt-box)
+ (rect-y prompt-box)
+ (rect-width prompt-box)
+ (rect-height prompt-box)
+ (make-color 190 100 255))
+ (rl-draw-text prompt-text 0 0 20 (make-color 0 0 0))
+ ))
+ )