Browse Source

Merge branch 'master' of macoy.me:macoy/gamelib

master
Macoy Madson 3 months ago
parent
commit
ba45d0989e
  1. 46
      src/ImGuiAutoColor.cake
  2. 4
      src/Introspection.cake

46
src/ImGuiAutoColor.cake

@ -6,9 +6,9 @@
(c-import "<stdlib.h>" "<stdio.h>" "<math.h>")
(var target-base16-colors ([] 16 auto-color))
(var target-base16-colors ([] 16 ([] 3 (unsigned char))))
(var current-base16-colors ([] 16 auto-color)
(var-global g-current-base16-colors ([] 16 ([] 3 (unsigned char)))
(array
(array 0x08 0x07 0x07)
(array 0x1c 0x18 0x19)
@ -28,7 +28,8 @@
(array 0x7a 0x74 0x71)))
;; Colors are in range 0 to 1.f
(var-global current-interpolate-base16-colors ([] 16 ([] 3 float)) (array 0))
(var-global g-current-interpolate-base16-colors ([] 16 ([] 3 float)) (array 0))
(var check-for-background-change-rate (const float) 5.f)
(var target-set-time float 0.f)
@ -53,8 +54,8 @@
(set (at ImGuiCol_FrameBgHovered colors) (auto-color-to-imgui-color (at 6 base16-colors) 1.f))
(set (at ImGuiCol_FrameBgActive colors) (auto-color-to-imgui-color (at 2 base16-colors) 1.f))
(set (at ImGuiCol_TitleBg colors) (auto-color-to-imgui-color (at 1 base16-colors) 1.f))
(set (at ImGuiCol_TitleBgActive colors) (auto-color-to-imgui-color (at 2 base16-colors) 1.f))
(set (at ImGuiCol_TitleBgCollapsed colors) (auto-color-to-imgui-color (at 6 base16-colors) 1.f))
(set (at ImGuiCol_TitleBgActive colors) (auto-color-to-imgui-color (at 6 base16-colors) 1.f))
(set (at ImGuiCol_TitleBgCollapsed colors) (auto-color-to-imgui-color (at 2 base16-colors) 1.f))
(set (at ImGuiCol_MenuBarBg colors) (auto-color-to-imgui-color (at 0 base16-colors) 1.f))
(set (at ImGuiCol_ScrollbarBg colors) (auto-color-to-imgui-color (at 0 base16-colors) 1.f))
(set (at ImGuiCol_ScrollbarGrab colors) (auto-color-to-imgui-color (at 13 base16-colors) 1.f))
@ -75,11 +76,11 @@
(set (at ImGuiCol_ResizeGrip colors) (auto-color-to-imgui-color (at 11 base16-colors) 1.f))
(set (at ImGuiCol_ResizeGripHovered colors) (auto-color-to-imgui-color (at 5 base16-colors) 1.f))
(set (at ImGuiCol_ResizeGripActive colors) (auto-color-to-imgui-color (at 5 base16-colors) 1.f))
(set (at ImGuiCol_Tab colors) (auto-color-to-imgui-color (at 6 base16-colors) 1.f))
(set (at ImGuiCol_TabHovered colors) (auto-color-to-imgui-color (at 3 base16-colors) 1.f))
(set (at ImGuiCol_TabActive colors) (auto-color-to-imgui-color (at 3 base16-colors) 1.f))
(set (at ImGuiCol_TabUnfocused colors) (auto-color-to-imgui-color (at 6 base16-colors) 1.f))
(set (at ImGuiCol_TabUnfocusedActive colors) (auto-color-to-imgui-color (at 7 base16-colors) 1.f))
(set (at ImGuiCol_Tab colors) (auto-color-to-imgui-color (at 1 base16-colors) 1.f))
(set (at ImGuiCol_TabHovered colors) (auto-color-to-imgui-color (at 0 base16-colors) 1.f))
(set (at ImGuiCol_TabActive colors) (auto-color-to-imgui-color (at 0 base16-colors) 1.f))
(set (at ImGuiCol_TabUnfocused colors) (auto-color-to-imgui-color (at 2 base16-colors) 1.f))
(set (at ImGuiCol_TabUnfocusedActive colors) (auto-color-to-imgui-color (at 0 base16-colors) 1.f))
(set (at ImGuiCol_DockingPreview colors) (auto-color-to-imgui-color (at 6 base16-colors) 1.f))
(set (at ImGuiCol_DockingEmptyBg colors) (auto-color-to-imgui-color (at 0 base16-colors) 1.f))
(set (at ImGuiCol_PlotLines colors) (auto-color-to-imgui-color (at 5 base16-colors) 1.f))
@ -99,12 +100,12 @@
(set (at ImGuiCol_ModalWindowDimBg colors) (auto-color-to-imgui-color (at 2 base16-colors) 0.8f)))
(defun imgui-auto-color-initialize ()
(each-in-array current-base16-colors i
(each-in-array g-current-base16-colors i
(each-in-range 3 component
(set (at i component current-interpolate-base16-colors)
(/ (type-cast (at i component current-base16-colors) float) 255.f))))
(memcpy target-base16-colors current-base16-colors (sizeof target-base16-colors))
(set-imgui-colors-from-base16 current-base16-colors))
(set (at i component g-current-interpolate-base16-colors)
(/ (type-cast (at i component g-current-base16-colors) float) 255.f))))
(memcpy target-base16-colors g-current-base16-colors (sizeof target-base16-colors))
(set-imgui-colors-from-base16 g-current-base16-colors))
(def-task set-target-base16-colors (base16-colors (* auto-color) succeeded (* bool))
(when (deref succeeded)
@ -121,7 +122,6 @@
;; Automatically update the theme on background change
(var current-time float (get-time-since-startup))
(var-static last-background-changed-check float current-time)
(var check-for-background-change-rate (const float) 1.f)
(when (> (- current-time last-background-changed-check)
check-for-background-change-rate)
(set last-background-changed-check current-time)
@ -141,7 +141,7 @@
;; Smoothly interpolate between current and target colors
(var before-update-values ([] 16 auto-color))
(memcpy before-update-values current-base16-colors (sizeof before-update-values))
(memcpy before-update-values g-current-base16-colors (sizeof before-update-values))
(var time-delta float (- current-time target-set-time))
(var transition-total-time float 0.5f)
(var transition-speed float (/ time-delta transition-total-time))
@ -150,19 +150,19 @@
(each-in-array target-base16-colors i
(each-in-range 3 component
(var current-value float (at i component current-interpolate-base16-colors))
(var current-value float (at i component g-current-interpolate-base16-colors))
(var-cast-to target-value float (at i component target-base16-colors))
(set target-value (/ target-value 255.f))
(set (at i component current-interpolate-base16-colors)
(set (at i component g-current-interpolate-base16-colors)
(+ current-value
(* (- target-value current-value)
transition-speed)))
(set (at i component current-base16-colors)
(type-cast (round (* 255.f (at i component current-interpolate-base16-colors)))
(set (at i component g-current-base16-colors)
(type-cast (round (* 255.f (at i component g-current-interpolate-base16-colors)))
(unsigned char)))))
(unless (= 0 (memcmp before-update-values current-base16-colors (sizeof before-update-values)))
(set-imgui-colors-from-base16 current-base16-colors)))
(unless (= 0 (memcmp before-update-values g-current-base16-colors (sizeof before-update-values)))
(set-imgui-colors-from-base16 g-current-base16-colors)))
(def-task pick-colors-from-background (base16-colors (* auto-color)
succeeded-out (* bool))

4
src/Introspection.cake

@ -1196,8 +1196,8 @@
(var value-argument-start (* (const char)) argument-start)
(var value-argument-end (* (const char)) argument-end)
(when (path current-field > count) ;; Handle (array)
(var array-keyword-length int 6) ;; Length of "array "
(when (!= 0 (strncmp (+ 1 argument-start) "array " array-keyword-length))
(var array-keyword-length int 5) ;; Length of "array "
(when (!= 0 (strncmp (+ 1 argument-start) "array" array-keyword-length))
(fprintf stderr "error: expected (array) for field %s, got "
(path current-field > name))
(print-string-range argument-start argument-end true)

Loading…
Cancel
Save