summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scripts/main.scm44
-rw-r--r--scripts/prompt.scm48
-rw-r--r--sources/main.c12
-rw-r--r--sources/rl/core.h (renamed from sources/core.h)8
-rw-r--r--sources/rl/shapes.h (renamed from sources/shapes.h)2
-rw-r--r--sources/rl/text.h (renamed from sources/text.h)2
-rw-r--r--sources/rl/texture.h (renamed from sources/texture.h)0
-rw-r--r--sources/rl/types.h (renamed from sources/types.h)2
-rw-r--r--sources/s7/s7.c (renamed from sources/s7.c)0
-rw-r--r--sources/s7/s7.h (renamed from sources/s7.h)0
10 files changed, 68 insertions, 50 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))
+ ))
+ )
diff --git a/sources/main.c b/sources/main.c
index 5556460..b248f24 100644
--- a/sources/main.c
+++ b/sources/main.c
@@ -4,12 +4,12 @@
#endif
#include "raylib.h"
-#include "s7.h"
-#include "types.h"
-#include "text.h"
-#include "texture.h"
-#include "core.h"
-#include "shapes.h"
+#include "s7/s7.h"
+#include "rl/types.h"
+#include "rl/text.h"
+#include "rl/texture.h"
+#include "rl/core.h"
+#include "rl/shapes.h"
#include <math.h>
#include <stdio.h>
diff --git a/sources/core.h b/sources/rl/core.h
index 3717a60..09c5555 100644
--- a/sources/core.h
+++ b/sources/rl/core.h
@@ -1,5 +1,5 @@
#include "raylib.h"
-#include "s7.h"
+#include "s7/s7.h"
#include <stdio.h>
#include <stdlib.h>
@@ -22,8 +22,14 @@ static s7_pointer rl_get_char_pressed(s7_scheme *s7, s7_pointer args) {
return(s7_make_integer(s7, key));
}
+static s7_pointer rl_get_key_pressed(s7_scheme *s7, s7_pointer args) {
+ int key = GetKeyPressed();
+ return(s7_make_integer(s7, key));
+}
+
static void rl_core_define_methods(s7_scheme *s7) {
s7_define_function(s7, "rl-is-key-down", rl_is_key_down, 1, 0, false, "(rl-is-key-down KEY)");
s7_define_function(s7, "rl-get-mouse-position", rl_get_mouse_position, 0, 0, false, "(rl-get-mouse-position)");
s7_define_function(s7, "rl-get-char-pressed", rl_get_char_pressed, 0, 0, false, "(rl-get-char-pressed)");
+ s7_define_function(s7, "rl-get-key-pressed", rl_get_key_pressed, 0, 0, false, "(rl-get-key-pressed)");
}
diff --git a/sources/shapes.h b/sources/rl/shapes.h
index dc73011..0033a5b 100644
--- a/sources/shapes.h
+++ b/sources/rl/shapes.h
@@ -1,5 +1,5 @@
#include "raylib.h"
-#include "s7.h"
+#include "s7/s7.h"
#include <stdio.h>
#include <stdlib.h>
diff --git a/sources/text.h b/sources/rl/text.h
index 0759d2f..6fd53e2 100644
--- a/sources/text.h
+++ b/sources/rl/text.h
@@ -1,5 +1,5 @@
#include "raylib.h"
-#include "s7.h"
+#include "s7/s7.h"
#include <stdio.h>
#include <stdlib.h>
diff --git a/sources/texture.h b/sources/rl/texture.h
index 8dfb996..8dfb996 100644
--- a/sources/texture.h
+++ b/sources/rl/texture.h
diff --git a/sources/types.h b/sources/rl/types.h
index 7f8acc4..4a7244f 100644
--- a/sources/types.h
+++ b/sources/rl/types.h
@@ -1,5 +1,5 @@
#include "raylib.h"
-#include "s7.h"
+#include "s7/s7.h"
#include <stdio.h>
#include <stdlib.h>
diff --git a/sources/s7.c b/sources/s7/s7.c
index a13d857..a13d857 100644
--- a/sources/s7.c
+++ b/sources/s7/s7.c
diff --git a/sources/s7.h b/sources/s7/s7.h
index 97008da..97008da 100644
--- a/sources/s7.h
+++ b/sources/s7/s7.h