summaryrefslogtreecommitdiff
path: root/scripts/main.scm
blob: 048c7eb8ec846d6308a4a1240606d91384a26bda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
(load "./scripts/keys.scm")
(load "./scripts/structs.scm")
(load "./scripts/utils.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 (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))
  )