Many more raylib additions

This commit is contained in:
Joseph Ferano 2026-08-16 19:40:32 +07:00
parent 7044605f61
commit ca5877d9e5

View File

@ -49,9 +49,122 @@
[::mem/struct [[:base-size ::mem/int] [:glyph-count ::mem/int] [:glyph-padding ::mem/int] [::mem/struct [[:base-size ::mem/int] [:glyph-count ::mem/int] [:glyph-padding ::mem/int]
[:texture ::texture] [:recs ::mem/pointer] [:glyphs ::mem/pointer]]]) [:texture ::texture] [:recs ::mem/pointer] [:glyphs ::mem/pointer]]])
(defalias ::n-patch-info
[::mem/struct [[:source ::rectangle] [:left ::mem/int] [:top ::mem/int]
[:right ::mem/int] [:bottom ::mem/int] [:layout ::mem/int]]])
;;; ----------------------------------------------------------------- constants ;;; ----------------------------------------------------------------- constants
;; KeyboardKey, raylib.h.
(def ^:const key-null 0)
(def ^:const key-apostrophe 39)
(def ^:const key-comma 44)
(def ^:const key-minus 45)
(def ^:const key-period 46)
(def ^:const key-slash 47)
(def ^:const key-zero 48)
(def ^:const key-one 49)
(def ^:const key-two 50)
(def ^:const key-three 51)
(def ^:const key-four 52)
(def ^:const key-five 53)
(def ^:const key-six 54)
(def ^:const key-seven 55)
(def ^:const key-eight 56)
(def ^:const key-nine 57)
(def ^:const key-semicolon 59)
(def ^:const key-equal 61)
(def ^:const key-a 65)
(def ^:const key-b 66)
(def ^:const key-c 67)
(def ^:const key-d 68)
(def ^:const key-e 69)
(def ^:const key-f 70)
(def ^:const key-g 71)
(def ^:const key-h 72)
(def ^:const key-i 73)
(def ^:const key-j 74)
(def ^:const key-k 75)
(def ^:const key-l 76)
(def ^:const key-m 77)
(def ^:const key-n 78)
(def ^:const key-o 79)
(def ^:const key-p 80)
(def ^:const key-q 81)
(def ^:const key-r 82) (def ^:const key-r 82)
(def ^:const key-s 83)
(def ^:const key-t 84)
(def ^:const key-u 85)
(def ^:const key-v 86)
(def ^:const key-w 87)
(def ^:const key-x 88)
(def ^:const key-y 89)
(def ^:const key-z 90)
(def ^:const key-left-bracket 91)
(def ^:const key-backslash 92)
(def ^:const key-right-bracket 93)
(def ^:const key-grave 96)
(def ^:const key-space 32)
(def ^:const key-escape 256)
(def ^:const key-enter 257)
(def ^:const key-tab 258)
(def ^:const key-backspace 259)
(def ^:const key-insert 260)
(def ^:const key-delete 261)
(def ^:const key-right 262)
(def ^:const key-left 263)
(def ^:const key-down 264)
(def ^:const key-up 265)
(def ^:const key-page-up 266)
(def ^:const key-page-down 267)
(def ^:const key-home 268)
(def ^:const key-end 269)
(def ^:const key-caps-lock 280)
(def ^:const key-scroll-lock 281)
(def ^:const key-num-lock 282)
(def ^:const key-print-screen 283)
(def ^:const key-pause 284)
(def ^:const key-f1 290)
(def ^:const key-f2 291)
(def ^:const key-f3 292)
(def ^:const key-f4 293)
(def ^:const key-f5 294)
(def ^:const key-f6 295)
(def ^:const key-f7 296)
(def ^:const key-f8 297)
(def ^:const key-f9 298)
(def ^:const key-f10 299)
(def ^:const key-f11 300)
(def ^:const key-f12 301)
(def ^:const key-left-shift 340)
(def ^:const key-left-control 341)
(def ^:const key-left-alt 342)
(def ^:const key-left-super 343)
(def ^:const key-right-shift 344)
(def ^:const key-right-control 345)
(def ^:const key-right-alt 346)
(def ^:const key-right-super 347)
(def ^:const key-kb-menu 348)
(def ^:const key-kp-0 320)
(def ^:const key-kp-1 321)
(def ^:const key-kp-2 322)
(def ^:const key-kp-3 323)
(def ^:const key-kp-4 324)
(def ^:const key-kp-5 325)
(def ^:const key-kp-6 326)
(def ^:const key-kp-7 327)
(def ^:const key-kp-8 328)
(def ^:const key-kp-9 329)
(def ^:const key-kp-decimal 330)
(def ^:const key-kp-divide 331)
(def ^:const key-kp-multiply 332)
(def ^:const key-kp-subtract 333)
(def ^:const key-kp-add 334)
(def ^:const key-kp-enter 335)
(def ^:const key-kp-equal 336)
(def ^:const mouse-button-left 0) (def ^:const mouse-button-left 0)
(def ^:const log-warning 4) (def ^:const log-warning 4)
(def ^:const pixelformat-r8g8b8a8 7) (def ^:const pixelformat-r8g8b8a8 7)
@ -73,6 +186,7 @@
(defcfn key-pressed? "IsKeyPressed" [::mem/int] ::bool) (defcfn key-pressed? "IsKeyPressed" [::mem/int] ::bool)
(defcfn mouse-button-down? "IsMouseButtonDown" [::mem/int] ::bool) (defcfn mouse-button-down? "IsMouseButtonDown" [::mem/int] ::bool)
(defcfn mouse-button-pressed? "IsMouseButtonPressed" [::mem/int] ::bool)
(defcfn mouse-button-released? "IsMouseButtonReleased" [::mem/int] ::bool) (defcfn mouse-button-released? "IsMouseButtonReleased" [::mem/int] ::bool)
(defcfn get-mouse-position "GetMousePosition" [] ::vector-2) (defcfn get-mouse-position "GetMousePosition" [] ::vector-2)
@ -89,15 +203,51 @@
[x y w h color] [x y w h color]
(draw-rectangle-raw!* (int x) (int y) (int w) (int h) color)) (draw-rectangle-raw!* (int x) (int y) (int w) (int h) color))
(def ^:private draw-rectangle-lines-raw!*
(ffi/make-downcall "DrawRectangleLines"
[::mem/int ::mem/int ::mem/int ::mem/int ::color] ::mem/void))
(defn draw-rectangle-lines!*
[x y w h color]
(draw-rectangle-lines-raw!* (int x) (int y) (int w) (int h) color))
(def update-texture!* (def update-texture!*
(ffi/make-downcall "UpdateTexture" [::texture ::mem/pointer] ::mem/void)) (ffi/make-downcall "UpdateTexture" [::texture ::mem/pointer] ::mem/void))
(def ^:private draw-texture-raw!*
(ffi/make-downcall "DrawTexture" [::texture ::mem/int ::mem/int ::color] ::mem/void))
(defn draw-texture!*
[texture x y color]
(draw-texture-raw!* texture (int x) (int y) color))
(def draw-texture-v!*
(ffi/make-downcall "DrawTextureV" [::texture ::vector-2 ::color] ::mem/void))
(def ^:private draw-texture-ex-raw!*
(ffi/make-downcall "DrawTextureEx"
[::texture ::vector-2 ::mem/float ::mem/float ::color] ::mem/void))
(defn draw-texture-ex!*
[texture position rotation scale color]
(draw-texture-ex-raw!* texture position (float rotation) (float scale) color))
(def draw-texture-rec!*
(ffi/make-downcall "DrawTextureRec"
[::texture ::rectangle ::vector-2 ::color] ::mem/void))
(def draw-texture-pro!* (def draw-texture-pro!*
(ffi/make-downcall "DrawTexturePro" (ffi/make-downcall "DrawTexturePro"
[::texture ::rectangle ::rectangle ::vector-2 ::mem/float ::color] [::texture ::rectangle ::rectangle ::vector-2 ::mem/float ::color]
::mem/void)) ::mem/void))
(def draw-texture-n-patch!*
(ffi/make-downcall "DrawTextureNPatch"
[::texture ::n-patch-info ::rectangle ::vector-2 ::mem/float ::color]
::mem/void))
;; Called once at startup, so the map-taking form is fine. ;; Called once at startup, so the map-taking form is fine.
(defcfn load-texture-raw* "LoadTexture" [::mem/c-string] ::texture)
(defcfn load-texture-from-image "LoadTextureFromImage" [::image] ::texture) (defcfn load-texture-from-image "LoadTextureFromImage" [::image] ::texture)
(defcfn unload-texture! "UnloadTexture" [::texture] ::mem/void) (defcfn unload-texture! "UnloadTexture" [::texture] ::mem/void)
(defcfn set-texture-filter! "SetTextureFilter" [::texture ::mem/int] ::mem/void) (defcfn set-texture-filter! "SetTextureFilter" [::texture ::mem/int] ::mem/void)
@ -105,6 +255,10 @@
(defcfn measure-text "MeasureText" [::mem/c-string ::mem/int] ::mem/int) (defcfn measure-text "MeasureText" [::mem/c-string ::mem/int] ::mem/int)
(defn load-texture [path]
(let [tex (load-texture-raw* path)]
(assoc tex :seg (texture-seg tex))))
(def ^:private draw-text-raw!* (def ^:private draw-text-raw!*
(ffi/make-downcall "DrawText" (ffi/make-downcall "DrawText"
[::mem/c-string ::mem/int ::mem/int ::mem/int ::color] ::mem/void)) [::mem/c-string ::mem/int ::mem/int ::mem/int ::color] ::mem/void))
@ -135,17 +289,46 @@
(defn color-seg (defn color-seg
"Serialize a packed 0xRRGGBB int into a reusable native Color, once." "Serialize a packed 0xRRGGBB int into a reusable native Color, once."
[^long hex] ([^long hex] (color-seg hex 255))
(mem/serialize {:r (bit-and (bit-shift-right hex 16) 0xFF) ([^long hex ^long alpha]
:g (bit-and (bit-shift-right hex 8) 0xFF) (mem/serialize {:r (bit-and (bit-shift-right hex 16) 0xFF)
:b (bit-and hex 0xFF) :g (bit-and (bit-shift-right hex 8) 0xFF)
:a 255} :b (bit-and hex 0xFF)
::color arena)) :a alpha}
::color arena))
([^long r ^long g ^long b ^long a]
(mem/serialize {:r r :g g :b b :a a} ::color arena)))
(def black (color-seg 0x000000)) (def black (color-seg 0x000000))
(def white (color-seg 0xFFFFFF)) (def white (color-seg 0xFFFFFF))
(def cornflower-blue (color-seg 0x6495ED)) (def cornflower-blue (color-seg 0x6495ED))
;; raylib.h's named palette.
(def light-gray (color-seg 200 200 200 255))
(def gray (color-seg 130 130 130 255))
(def dark-gray (color-seg 80 80 80 255))
(def yellow (color-seg 253 249 0 255))
(def gold (color-seg 255 203 0 255))
(def orange (color-seg 255 161 0 255))
(def pink (color-seg 255 109 194 255))
(def red (color-seg 230 41 55 255))
(def maroon (color-seg 190 33 55 255))
(def green (color-seg 0 228 48 255))
(def lime (color-seg 0 158 47 255))
(def dark-green (color-seg 0 117 44 255))
(def sky-blue (color-seg 102 191 255 255))
(def blue (color-seg 0 121 241 255))
(def dark-blue (color-seg 0 82 172 255))
(def purple (color-seg 200 122 255 255))
(def violet (color-seg 135 60 190 255))
(def dark-purple (color-seg 112 31 126 255))
(def beige (color-seg 211 176 131 255))
(def brown (color-seg 127 106 79 255))
(def dark-brown (color-seg 76 63 47 255))
(def blank (color-seg 0 0 0 0))
(def magenta (color-seg 255 0 255 255))
(def ray-white (color-seg 245 245 245 255))
(defn rect-seg [x y w h] (defn rect-seg [x y w h]
(mem/serialize {:x (float x) :y (float y) :width (float w) :height (float h)} (mem/serialize {:x (float x) :y (float y) :width (float w) :height (float h)}
::rectangle arena)) ::rectangle arena))
@ -156,6 +339,11 @@
(defn texture-seg [tex] (defn texture-seg [tex]
(mem/serialize tex ::texture arena)) (mem/serialize tex ::texture arena))
(defn n-patch-info-seg [{:keys [source left top right bottom layout]}]
(mem/serialize {:source source :left (int left) :top (int top)
:right (int right) :bottom (int bottom) :layout (int layout)}
::n-patch-info arena))
(defn font-seg [font] (defn font-seg [font]
(mem/serialize font ::font arena)) (mem/serialize font ::font arena))