Browse Source

Automatically update color theme

filter-focus
Macoy Madson 1 year ago
parent
commit
6e522d850e
  1. 2
      Dependencies/auto-color
  2. 35
      src/ImGuiAutoColor.cake

2
Dependencies/auto-color

@ -1 +1 @@
Subproject commit 82e3cf80b89dbae8d6b638bfd1ac6147a93e8810
Subproject commit 775ae4b3fe7bab81492c5b70171d5ee635fa1b7c

35
src/ImGuiAutoColor.cake

@ -104,7 +104,7 @@
(defun imgui-auto-color-initialize ()
(each-in-array current-base16-colors i
(each-in-range 3 component
(set (at (* 3 i) component current-interpolate-base16-colors)
(set (at i component current-interpolate-base16-colors)
(type-cast (at i component current-base16-colors) float))))
(memcpy target-base16-colors current-base16-colors (sizeof target-base16-colors))
(set-imgui-colors-from-base16 current-base16-colors))
@ -116,23 +116,46 @@
(free succeeded)
(free base16-colors))
;; Smoothly interpolate between current and target colors
(var last-background-path ([] 1024 char) (array 0))
(defun update-auto-color-theme ()
(unless target-set-time (return))
;; 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)
(var current-background-path ([] 1024 char) (array 0))
(var error-string (* (const char)) null)
(when (auto-color-get-current-background-filename current-background-path
(sizeof current-background-path)
(addr error-string))
;; Don't count the very first one, because the process will update the theme on startup anyways
(if (at 0 last-background-path)
(unless (= 0 (strcmp last-background-path current-background-path))
(fprintf stderr "Wallpaper changed: '%s' != '%s'\n"
last-background-path current-background-path)
(strncpy last-background-path current-background-path (sizeof last-background-path))
(imgui-colors-from-current-background-start))
(strncpy last-background-path current-background-path (sizeof last-background-path)))))
;; 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))
(var transition-speed float (* 0.5f (- target-set-time (get-time-since-startup))))
(var transition-speed float (* 0.5f (- target-set-time current-time)))
(each-in-array target-base16-colors i
(each-in-range 3 component
(var current-value float (at (* 3 i) component current-interpolate-base16-colors))
(var current-value float (at i component current-interpolate-base16-colors))
(var-cast-to target-value float (at i component target-base16-colors))
(set (at (* 3 i) component current-interpolate-base16-colors)
(set (at i component current-interpolate-base16-colors)
(+ current-value
(* transition-speed
(- current-value target-value))))
(set (at i component current-base16-colors)
(type-cast (round (at (* 3 i) component current-interpolate-base16-colors))
(type-cast (round (at i component current-interpolate-base16-colors))
(unsigned char)))))
(unless (= 0 (memcmp before-update-values current-base16-colors (sizeof before-update-values)))

Loading…
Cancel
Save