Browse Source

Move current color to global

master
Macoy Madson 1 year ago
parent
commit
e93f3756dd
  1. 20
      src/ImGuiAutoColor.cake

20
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)
@ -100,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 g-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))
(/ (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)
@ -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))
@ -157,12 +157,12 @@
(+ current-value
(* (- target-value current-value)
transition-speed)))
(set (at i component current-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))

Loading…
Cancel
Save