tsukundere-menu-exmaple/run.scm

115 lines
4.1 KiB
Scheme
Raw Normal View History

2020-12-14 17:46:49 +01:00
(use-modules (tsukundere)
(sdl2)
(sdl2 ttf)
(ice-9 match)
(tsukundere menu button))
2020-12-14 17:46:49 +01:00
(define (load)
(let* ((scene
(make-scene '(background
text
menu)))
(paper (load-image "paper.png"))
(texture (load-image "unchecked_box.png"))
(selected (load-image "checked_box.png"))
(radio (load-image "unselected_radio_button.png"))
(radio-selected (load-image "selected_radio_button.png"))
(simple (load-image "round_button_normal.png"))
(simple-hover (load-image "round_button_hover.png"))
(simple-pressed (load-image "round_button_mouse_down.png"))
(font (load-font "JuliaMono.ttf" 18))
2020-12-15 01:14:27 +01:00
(colors
`((none . ,(make-color 80 225 100 255))
2021-01-05 21:03:34 +01:00
(selected . ,(make-color 255 0 0 255))
2020-12-15 01:14:27 +01:00
(pressed . ,(make-color 0 0 255 255))))
(textures
`((none . ,texture)
(pressed . ,selected)))
2020-12-14 17:46:49 +01:00
(textures-radio
`((none . ,radio)
(pressed . ,radio-selected)))
(textures-button
`((none . ,simple)
2021-01-05 21:03:34 +01:00
(selected . ,simple-hover)
2020-12-14 17:46:49 +01:00
(pressed . ,simple-pressed)))
(checkbox-button
(make-button (s32vector 0 0) "" 0 font textures
2021-01-09 14:06:57 +01:00
#:dimensions (s32vector 25 25)
2020-12-14 17:46:49 +01:00
#:text-colors colors
2021-01-09 14:06:57 +01:00
#:anchor 'center
#:text-pos (s32vector 30 -7)
2020-12-15 01:14:27 +01:00
#:text-alignment '(left . top)
2020-12-14 17:46:49 +01:00
#:callback checkbox-button-callback))
(radio-button
(make-button (s32vector 0 0) "" 0 font textures-radio
#:text-colors colors
#:dimensions (s32vector 200 20)
2021-01-09 14:06:57 +01:00
#:anchor 'top-left
2020-12-15 01:14:27 +01:00
#:text-alignment '(left . top)
#:text-pos (s32vector 30 0)
2020-12-14 17:46:49 +01:00
#:callback radio-button-callback))
(simple-button
(make-button (s32vector 0 0) "" 0 font textures-button
#:text-colors colors
2020-12-15 01:14:27 +01:00
;; Put text at the center of the button
#:text-pos (s32vector 0 0)
#:anchor 'center
#:text-alignment '(center . center)
#:callback simple-button-callback))
(nixo (make-speaker "nixo")))
2020-12-14 17:46:49 +01:00
(init-script!
(lambda ()
(script
(begin
(background paper)
(nixo "This is not an exam!"))
(nixo "Choose one and press enter!")
(nixo
(format #f "You chose: ~a\n"
(menu
'(("Select me!")
("Or me!")
("No, select me!"))
#:prototype radio-button)))
(nixo "Choose as many as you want!")
(nixo
(format #f "You chose ~a\n"
(menu '(("A" 0)
("B" 1)
("C" 2))
#:prototype checkbox-button
#:seed '() #:pressed cons)))
(nixo "Choose as many as you want!")
(nixo
(format #f "You chose ~a\n"
(menu '(("A" 0 (pressed))
("B" 1 (selected))
("C" 2 (pressed)))
#:prototype checkbox-button
#:seed '() #:pressed cons)))
(nixo "Click it!")
(nixo
(format #f "You chose the element number: ~a\n"
(menu
'("Yes" "Maybe" "No way"))))
(nixo "Click it again!")
(nixo
(format #f "You chose the element: ~a\n"
(menu
'(("Yes") ("Maybe") ("No way")))))
(nixo "Once more!")
(nixo
(format #f "You chose the element: ~a\n"
(menu
'(("Yes" . yep) ("Maybe" . maybe) ("No way" . nope)))))
*unspecified*))
2020-12-14 17:46:49 +01:00
scene)
2021-01-05 21:11:36 +01:00
(init-menu! #s32(100 100) #s32(0 50) simple-button #:scene scene)
(init-text! 10 300 280 font font #:scene scene)))
2020-12-14 17:46:49 +01:00
(run-game
#:game-name ".tsukundere-example-buttons"
#:window-width 400
#:window-height 400
#:init! load)