add menu bg and buttons
This commit is contained in:
64
menu.sex
64
menu.sex
@@ -1,37 +1,63 @@
|
||||
(include raylib.h)
|
||||
(include raygui.h)
|
||||
(pub import pages)
|
||||
(import main)
|
||||
(import utils)
|
||||
|
||||
(pub record menu-state
|
||||
((app-state (* app-state))))
|
||||
|
||||
(pub fn mk-menu ((app-state (* app-state))) page
|
||||
(var state _ (mem-alloc menu-state))
|
||||
(= (. state app-state) app-state)
|
||||
(return (page/menu state)))
|
||||
|
||||
(pub fn rm-menu ((state (* menu-state))) void
|
||||
(free state)
|
||||
(return))
|
||||
((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)
|
||||
(DrawTriangleGradient
|
||||
#(Vector2 : (- (/ WIN-WIDTH 2) 100) (+ (/ WIN-HEIGHT 2) 100.0f))
|
||||
#(Vector2 : (+ (/ WIN-WIDTH 2) 100) (+ (/ WIN-HEIGHT 2) 100.0f))
|
||||
#(Vector2 : (/ WIN-WIDTH 2) (- (/ WIN-HEIGHT 2) 100))
|
||||
RED
|
||||
GREEN
|
||||
BLUE)
|
||||
(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 (IsMouseButtonReleased MOUSE-LEFT-BUTTON)
|
||||
(.change-page (. state app-state) (sum-type page game))))
|
||||
(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)))))
|
||||
|
||||
Reference in New Issue
Block a user