Files
catch-phase/menu.sex
2026-11-07 10:49:20 +03:00

64 lines
1.6 KiB
Scheme

(include raylib.h)
(include raygui.h)
(pub import pages)
(import main)
(import utils)
(pub record menu-state
((app-state (* app-state))
(bg Texture2D)
(btn-to-game int)
(btn-exit int)))
#-emscripten (define WIN-WIDTH 1440)
#-emscripten (define WIN-HEIGHT 900)
#+emscripten (define WIN-WIDTH 960)
#+emscripten (define WIN-HEIGHT 600)
(define BTN-WIDTH 320.0)
(define BTN-HEIGHT 72.0)
(pub fn mk-menu ((app-state (* app-state))) page
(var state _ (mem-alloc menu-state))
(= (. state app-state) app-state)
(= (. state btn-to-game) 0)
(= (. state btn-exit) 0)
(var img Image (LoadImage "res/img/menu.png"))
(ImageResize (& img) WIN-WIDTH WIN-HEIGHT)
(= (. state bg) (LoadTextureFromImage img))
(return (page/menu state)))
(pub fn rm-menu ((state (* menu-state))) void
(free state)
(return))
(pub fn render-menu ((state (* menu-state))) void
(BeginDrawing)
(ClearBackground BLACK)
(DrawTexture (. state bg) 0 0 WHITE)
(= (. state btn-to-game)
(GuiButton #(Rectangle : 80.0
(- WIN-HEIGHT 350.0)
BTN-WIDTH
BTN-HEIGHT) "To game"))
(= (. state btn-exit)
(GuiButton #(Rectangle : 80.0
(- WIN-HEIGHT 240.0)
BTN-WIDTH
BTN-HEIGHT) "Quit"))
(EndDrawing))
(pub fn process-input-menu ((state (* menu-state))) void
(if (== (. state btn-to-game) 1)
(do
(= (. state btn-to-game) 0)
(.change-page (. state app-state) (sum-type page game))))
(if (== (. state btn-exit) 1)
(do
(= (. state btn-exit) 0)
(.quit (. state app-state)))))