handle message working, mutation of self working, draw not working
This commit is contained in:
115
main.scm
115
main.scm
@@ -2,15 +2,114 @@
|
||||
|
||||
(load "ipc.scm")
|
||||
|
||||
(define handle-message (lambda (message)
|
||||
;placeholder
|
||||
;return either ('DoNothing) ('JustRedraw) or ('Request "string") clipboard copy request
|
||||
(cons (string->symbol "JustRedraw") '())
|
||||
(define-record-type flashcards (fields
|
||||
(mutable dimensions)
|
||||
(mutable input)
|
||||
;questions to ask, to be removed when correctly answered
|
||||
(mutable questions)
|
||||
;current question
|
||||
(mutable current)
|
||||
;correct answer(s)
|
||||
(mutable answers)
|
||||
;total questions correctly asked
|
||||
(mutable correct)
|
||||
;total questions asked
|
||||
(mutable total)
|
||||
;if false, command mode
|
||||
(mutable answer-mode)
|
||||
))
|
||||
|
||||
(define draw (lambda (theme-info)
|
||||
(define handle-message (lambda (self whole-message)
|
||||
;placeholder
|
||||
""
|
||||
(let* (
|
||||
[message (car whole-message)]
|
||||
[args (if (= (length whole-message) 1)
|
||||
'("")
|
||||
(cdr whole-message)
|
||||
)]
|
||||
[arg (join-string args "/")]
|
||||
) (cond
|
||||
[
|
||||
(or (string=? message "Init") (string=? message "ChangeDimensions"))
|
||||
(begin
|
||||
(flashcards-dimensions-set! self (map string->number (s-string->list (car args))))
|
||||
(list self "JustRedraw")
|
||||
)
|
||||
]
|
||||
[
|
||||
(string=? message "KeyPress")
|
||||
;arg is the char
|
||||
(cond
|
||||
[
|
||||
(is-escape arg)
|
||||
(let* (
|
||||
[answer-mode (flashcards-answer-mode self)]
|
||||
[change (if answer-mode
|
||||
#t
|
||||
(= (length questions) 0) ;if no questions, can't switch to answer mode
|
||||
)]
|
||||
) (if change
|
||||
(begin
|
||||
(flashcards-answer-mode-set! self (not answer-mode))
|
||||
(cons self '("JustRedraw"))
|
||||
)
|
||||
(list self "DoNothing")
|
||||
))
|
||||
]
|
||||
[
|
||||
(is-enter arg)
|
||||
;process flashcards.input
|
||||
(if (flashcards-answer-mode self)
|
||||
;check to see if answer is correct
|
||||
(display "placeholder")
|
||||
;
|
||||
;process command
|
||||
(display "placeholder")
|
||||
;
|
||||
)
|
||||
]
|
||||
[
|
||||
(is-backspace arg)
|
||||
(if (= (length (flashcards-input self)) 0)
|
||||
'(self '("DoNothing"))
|
||||
(let ([input (flashcards-input self)])
|
||||
(flashcards-input-set! self (substring input 0 (- (length input) 1)))
|
||||
(list self "JustRedraw")
|
||||
)
|
||||
)
|
||||
]
|
||||
[
|
||||
else
|
||||
(begin
|
||||
;add char to input
|
||||
(flashcards-input-set! self (string-append (flashcards-input self) arg))
|
||||
(list self "JustRedraw")
|
||||
)
|
||||
]
|
||||
)
|
||||
]
|
||||
;
|
||||
[
|
||||
else
|
||||
(list self "DoNothing")
|
||||
]
|
||||
))
|
||||
))
|
||||
|
||||
(define draw (lambda (self ti)
|
||||
;placeholder
|
||||
(let* (
|
||||
[coords (flashcards-dimensions self)]
|
||||
[width (car coords)]
|
||||
[height (car (cdr coords))]
|
||||
) (list
|
||||
(draw-instructions-text (list 5 (- height 15)) '("nimbus-roman") (string-append (if (flashcards-answer-mode self)
|
||||
"ANS: "
|
||||
"CMD: "
|
||||
) (flashcards-input self)) (theme-info-text ti) (theme-info-background ti) #f #f)
|
||||
"b"
|
||||
)
|
||||
)
|
||||
))
|
||||
|
||||
(define title (lambda ()
|
||||
@@ -22,7 +121,7 @@
|
||||
))
|
||||
|
||||
(define ideal-dimensions (lambda (_)
|
||||
'(300 300)
|
||||
'(420 300)
|
||||
))
|
||||
|
||||
(listen handle-message draw title resizable "Window" ideal-dimensions)
|
||||
(listen (make-flashcards '(0 0) "" '() "" '() 0 0 #f) handle-message draw title resizable "Window" ideal-dimensions)
|
||||
|
||||
Reference in New Issue
Block a user