Browse Source

Use task system to offload theme function

This function can take a while when wallpapers are 4K+. Use the snazzy
new Task System to easily thread this, then set the colors once it's
all done. Amazing stuff!
filter-focus
Macoy Madson 8 months ago
parent
commit
5816dc565e
  1. 3
      .gitmodules
  2. 2
      Dependencies/cakelisp
  3. 1
      Dependencies/enkiTS
  4. 2
      Dependencies/gamelib
  5. 11
      src/FileHelper.cake
  6. 151
      src/ImGuiAutoColor.cake

3
.gitmodules

@ -25,3 +25,6 @@
[submodule "Dependencies/auto-color"]
path = Dependencies/auto-color
url = gitea@macoy.me:macoy/auto-color.git
[submodule "Dependencies/enkiTS"]
path = Dependencies/enkiTS
url = https://github.com/dougbinks/enkiTS

2
Dependencies/cakelisp

@ -1 +1 @@
Subproject commit 0beaf00d3d7f66c260a9a1f1e20a69a3bfe8a1aa
Subproject commit 2950bc66ee76039f83cc4b65bf94cffc6cec9e2d

1
Dependencies/enkiTS

@ -0,0 +1 @@
Subproject commit 7e9a83aadd71e76904c63f00e86f02e1198bee74

2
Dependencies/gamelib

@ -1 +1 @@
Subproject commit d75b3f7aa95cd86b0b07ed26da3e3a17299b5a24
Subproject commit 9acb7b72db04f3ae7157c24040d429f692eadfc8

11
src/FileHelper.cake

@ -2,6 +2,7 @@
(import
;; From GameLib
"Introspection.cake" "SDL.cake" "ImGui.cake" "DynamicArray.cake" "Dictionary.cake" "Math.cake"
"TaskSystem.cake"
;; From File Helper
"FileSystem.cake" "LoadSave.cake" "Export.cake" "Utilities.cake"
"Treemap.cake" "TreemapOpenGL.cake" "TreemapFileSystem.cake" "License.cake"
@ -1217,6 +1218,9 @@
(while (not (IsDebuggerPresent))
(Sleep 100)))))
;; TODO Need infect
(add-c-search-directory-module "Dependencies/enkiTS/src")
(make-imgui-sdl-gl3-application
file-helper
"File Helper"
@ -1224,6 +1228,8 @@
(timing-zone-start initialize-zone "User initialization")
(SDL_Log "%s" g-copyright-string)
(task-system-initialize)
(var pref-path (* char) (SDL_GetPrefPath "Macoy Madson Software" "File Helper"))
(dynarray-clear g-userdata-output-dir)
(dynstring-append (addr g-userdata-output-dir) pref-path)
@ -1352,6 +1358,8 @@
(SDL_Log "error: failed to save state"))
(set last-time-saved (SDL_GetPerformanceCounter)))
(task-system-run-thread-pinned-tasks)
;; Get keyboard input
(var num-sdl-keys int 0)
(var key-states (* (const (unsigned char)))
@ -1640,7 +1648,8 @@ Depending on the error, open the UserData.cakedata file in a text editor and see
(treemap-opengl-shutdown)
(free-treemap-file-system-multithreaded-state g-treemap-multithreaded-state)
(dynarray-free g-userdata-output-dir)))
(dynarray-free g-userdata-output-dir)
(task-system-shutdown)))
;;
;; Introspection helpers

151
src/ImGuiAutoColor.cake

@ -1,7 +1,12 @@
(import "ImGui.cake" "AutoColor.cake")
(import "ImGui.cake" "TaskSystem.cake"
"AutoColor.cake"
&comptime-only "CHelpers.cake")
;; TODO Need infect
(add-c-search-directory-module "Dependencies/enkiTS/src")
;; TODO: ImGui.cake import should handle this via export/auto-infect
(c-import "imgui.h")
(c-import "imgui.h" "<stdlib.h>" "<stdio.h>")
(add-c-search-directory-module "Dependencies/imgui")
(defun-local auto-color-to-imgui-color (color auto-color &return ImVec4)
@ -11,71 +16,79 @@
(/ (at 2 color) 255.f)
1.00f)))
(defun imgui-colors-from-current-background ()
(scope
(var base16-colors ([] 16 auto-color) (array 0))
(when (auto-color-pick-from-current-background base16-colors)
(var colors (* ImVec4) (field (imgui-call GetStyle) Colors))
(set (at ImGuiCol_Text colors) (auto-color-to-imgui-color (at 5 base16-colors)))
(set (at ImGuiCol_TextDisabled colors) (auto-color-to-imgui-color (at 3 base16-colors)))
(set (at ImGuiCol_WindowBg colors) (auto-color-to-imgui-color (at 0 base16-colors)))
(set (at ImGuiCol_ChildBg colors) (auto-color-to-imgui-color (at 0 base16-colors)))
(set (at ImGuiCol_PopupBg colors) (auto-color-to-imgui-color (at 0 base16-colors)))
(set (at ImGuiCol_Border colors) (auto-color-to-imgui-color (at 0 base16-colors)))
(set (at ImGuiCol_BorderShadow colors) (auto-color-to-imgui-color (at 14 base16-colors)))
(set (at ImGuiCol_FrameBg colors) (auto-color-to-imgui-color (at 1 base16-colors)))
(set (at ImGuiCol_FrameBgHovered colors) (auto-color-to-imgui-color (at 1 base16-colors)))
(set (at ImGuiCol_FrameBgActive colors) (auto-color-to-imgui-color (at 0 base16-colors)))
(set (at ImGuiCol_TitleBg colors) (auto-color-to-imgui-color (at 1 base16-colors)))
(set (at ImGuiCol_TitleBgActive colors) (auto-color-to-imgui-color (at 2 base16-colors)))
(set (at ImGuiCol_TitleBgCollapsed colors) (auto-color-to-imgui-color (at 0 base16-colors)))
(set (at ImGuiCol_MenuBarBg colors) (auto-color-to-imgui-color (at 0 base16-colors)))
(set (at ImGuiCol_ScrollbarBg colors) (auto-color-to-imgui-color (at 0 base16-colors)))
(set (at ImGuiCol_ScrollbarGrab colors) (auto-color-to-imgui-color (at 13 base16-colors)))
(set (at ImGuiCol_ScrollbarGrabHovered colors) (auto-color-to-imgui-color (at 14 base16-colors)))
(set (at ImGuiCol_ScrollbarGrabActive colors) (auto-color-to-imgui-color (at 15 base16-colors)))
(set (at ImGuiCol_CheckMark colors) (auto-color-to-imgui-color (at 5 base16-colors)))
(set (at ImGuiCol_SliderGrab colors) (auto-color-to-imgui-color (at 12 base16-colors)))
(set (at ImGuiCol_SliderGrabActive colors) (auto-color-to-imgui-color (at 6 base16-colors)))
(set (at ImGuiCol_Button colors) (auto-color-to-imgui-color (at 1 base16-colors)))
(set (at ImGuiCol_ButtonHovered colors) (auto-color-to-imgui-color (at 2 base16-colors)))
(set (at ImGuiCol_ButtonActive colors) (auto-color-to-imgui-color (at 6 base16-colors)))
(set (at ImGuiCol_Header colors) (auto-color-to-imgui-color (at 1 base16-colors)))
(set (at ImGuiCol_HeaderHovered colors) (auto-color-to-imgui-color (at 2 base16-colors)))
(set (at ImGuiCol_HeaderActive colors) (auto-color-to-imgui-color (at 9 base16-colors)))
(set (at ImGuiCol_Separator colors) (auto-color-to-imgui-color (at 10 base16-colors)))
(set (at ImGuiCol_SeparatorHovered colors) (auto-color-to-imgui-color (at 5 base16-colors)))
(set (at ImGuiCol_SeparatorActive colors) (auto-color-to-imgui-color (at 5 base16-colors)))
(set (at ImGuiCol_ResizeGrip colors) (auto-color-to-imgui-color (at 11 base16-colors)))
(set (at ImGuiCol_ResizeGripHovered colors) (auto-color-to-imgui-color (at 5 base16-colors)))
(set (at ImGuiCol_ResizeGripActive colors) (auto-color-to-imgui-color (at 5 base16-colors)))
(set (at ImGuiCol_Tab colors) (auto-color-to-imgui-color (at 2 base16-colors)))
(set (at ImGuiCol_TabHovered colors) (auto-color-to-imgui-color (at 1 base16-colors)))
(set (at ImGuiCol_TabActive colors) (auto-color-to-imgui-color (at 0 base16-colors)))
(set (at ImGuiCol_TabUnfocused colors) (auto-color-to-imgui-color (at 2 base16-colors)))
(set (at ImGuiCol_TabUnfocusedActive colors) (auto-color-to-imgui-color (at 1 base16-colors)))
(set (at ImGuiCol_DockingPreview colors) (auto-color-to-imgui-color (at 2 base16-colors)))
(set (at ImGuiCol_DockingEmptyBg colors) (auto-color-to-imgui-color (at 0 base16-colors)))
(set (at ImGuiCol_PlotLines colors) (auto-color-to-imgui-color (at 5 base16-colors)))
(set (at ImGuiCol_PlotLinesHovered colors) (auto-color-to-imgui-color (at 13 base16-colors)))
(set (at ImGuiCol_PlotHistogram colors) (auto-color-to-imgui-color (at 5 base16-colors)))
(set (at ImGuiCol_PlotHistogramHovered colors) (auto-color-to-imgui-color (at 5 base16-colors)))
(set (at ImGuiCol_TableHeaderBg colors) (auto-color-to-imgui-color (at 1 base16-colors)))
(set (at ImGuiCol_TableBorderStrong colors) (auto-color-to-imgui-color (at 1 base16-colors)))
(set (at ImGuiCol_TableBorderLight colors) (auto-color-to-imgui-color (at 1 base16-colors)))
(set (at ImGuiCol_TableRowBg colors) (auto-color-to-imgui-color (at 1 base16-colors)))
(set (at ImGuiCol_TableRowBgAlt colors) (auto-color-to-imgui-color (at 8 base16-colors)))
(set (at ImGuiCol_TextSelectedBg colors) (auto-color-to-imgui-color (at 2 base16-colors)))
(set (at ImGuiCol_DragDropTarget colors) (auto-color-to-imgui-color (at 7 base16-colors)))
(set (at ImGuiCol_NavHighlight colors) (auto-color-to-imgui-color (at 9 base16-colors)))
(set (at ImGuiCol_NavWindowingHighlight colors) (auto-color-to-imgui-color (at 2 base16-colors)))
(set (at ImGuiCol_NavWindowingDimBg colors) (auto-color-to-imgui-color (at 1 base16-colors)))
(set (at ImGuiCol_ModalWindowDimBg colors) (auto-color-to-imgui-color (at 2 base16-colors)))
(def-task set-imgui-colors-from-base16 (base16-colors (* auto-color)
succeeded (* bool))
(when (deref succeeded)
(var colors (* ImVec4) (field (imgui-call GetStyle) Colors))
(set (at ImGuiCol_Text colors) (auto-color-to-imgui-color (at 5 base16-colors)))
(set (at ImGuiCol_TextDisabled colors) (auto-color-to-imgui-color (at 3 base16-colors)))
(set (at ImGuiCol_WindowBg colors) (auto-color-to-imgui-color (at 0 base16-colors)))
(set (at ImGuiCol_ChildBg colors) (auto-color-to-imgui-color (at 0 base16-colors)))
(set (at ImGuiCol_PopupBg colors) (auto-color-to-imgui-color (at 0 base16-colors)))
(set (at ImGuiCol_Border colors) (auto-color-to-imgui-color (at 0 base16-colors)))
(set (at ImGuiCol_BorderShadow colors) (auto-color-to-imgui-color (at 14 base16-colors)))
(set (at ImGuiCol_FrameBg colors) (auto-color-to-imgui-color (at 1 base16-colors)))
(set (at ImGuiCol_FrameBgHovered colors) (auto-color-to-imgui-color (at 1 base16-colors)))
(set (at ImGuiCol_FrameBgActive colors) (auto-color-to-imgui-color (at 0 base16-colors)))
(set (at ImGuiCol_TitleBg colors) (auto-color-to-imgui-color (at 1 base16-colors)))
(set (at ImGuiCol_TitleBgActive colors) (auto-color-to-imgui-color (at 2 base16-colors)))
(set (at ImGuiCol_TitleBgCollapsed colors) (auto-color-to-imgui-color (at 0 base16-colors)))
(set (at ImGuiCol_MenuBarBg colors) (auto-color-to-imgui-color (at 0 base16-colors)))
(set (at ImGuiCol_ScrollbarBg colors) (auto-color-to-imgui-color (at 0 base16-colors)))
(set (at ImGuiCol_ScrollbarGrab colors) (auto-color-to-imgui-color (at 13 base16-colors)))
(set (at ImGuiCol_ScrollbarGrabHovered colors) (auto-color-to-imgui-color (at 14 base16-colors)))
(set (at ImGuiCol_ScrollbarGrabActive colors) (auto-color-to-imgui-color (at 15 base16-colors)))
(set (at ImGuiCol_CheckMark colors) (auto-color-to-imgui-color (at 5 base16-colors)))
(set (at ImGuiCol_SliderGrab colors) (auto-color-to-imgui-color (at 12 base16-colors)))
(set (at ImGuiCol_SliderGrabActive colors) (auto-color-to-imgui-color (at 6 base16-colors)))
(set (at ImGuiCol_Button colors) (auto-color-to-imgui-color (at 1 base16-colors)))
(set (at ImGuiCol_ButtonHovered colors) (auto-color-to-imgui-color (at 2 base16-colors)))
(set (at ImGuiCol_ButtonActive colors) (auto-color-to-imgui-color (at 6 base16-colors)))
(set (at ImGuiCol_Header colors) (auto-color-to-imgui-color (at 1 base16-colors)))
(set (at ImGuiCol_HeaderHovered colors) (auto-color-to-imgui-color (at 2 base16-colors)))
(set (at ImGuiCol_HeaderActive colors) (auto-color-to-imgui-color (at 9 base16-colors)))
(set (at ImGuiCol_Separator colors) (auto-color-to-imgui-color (at 10 base16-colors)))
(set (at ImGuiCol_SeparatorHovered colors) (auto-color-to-imgui-color (at 5 base16-colors)))
(set (at ImGuiCol_SeparatorActive colors) (auto-color-to-imgui-color (at 5 base16-colors)))
(set (at ImGuiCol_ResizeGrip colors) (auto-color-to-imgui-color (at 11 base16-colors)))
(set (at ImGuiCol_ResizeGripHovered colors) (auto-color-to-imgui-color (at 5 base16-colors)))
(set (at ImGuiCol_ResizeGripActive colors) (auto-color-to-imgui-color (at 5 base16-colors)))
(set (at ImGuiCol_Tab colors) (auto-color-to-imgui-color (at 2 base16-colors)))
(set (at ImGuiCol_TabHovered colors) (auto-color-to-imgui-color (at 1 base16-colors)))
(set (at ImGuiCol_TabActive colors) (auto-color-to-imgui-color (at 0 base16-colors)))
(set (at ImGuiCol_TabUnfocused colors) (auto-color-to-imgui-color (at 2 base16-colors)))
(set (at ImGuiCol_TabUnfocusedActive colors) (auto-color-to-imgui-color (at 1 base16-colors)))
(set (at ImGuiCol_DockingPreview colors) (auto-color-to-imgui-color (at 2 base16-colors)))
(set (at ImGuiCol_DockingEmptyBg colors) (auto-color-to-imgui-color (at 0 base16-colors)))
(set (at ImGuiCol_PlotLines colors) (auto-color-to-imgui-color (at 5 base16-colors)))
(set (at ImGuiCol_PlotLinesHovered colors) (auto-color-to-imgui-color (at 13 base16-colors)))
(set (at ImGuiCol_PlotHistogram colors) (auto-color-to-imgui-color (at 5 base16-colors)))
(set (at ImGuiCol_PlotHistogramHovered colors) (auto-color-to-imgui-color (at 5 base16-colors)))
(set (at ImGuiCol_TableHeaderBg colors) (auto-color-to-imgui-color (at 1 base16-colors)))
(set (at ImGuiCol_TableBorderStrong colors) (auto-color-to-imgui-color (at 1 base16-colors)))
(set (at ImGuiCol_TableBorderLight colors) (auto-color-to-imgui-color (at 1 base16-colors)))
(set (at ImGuiCol_TableRowBg colors) (auto-color-to-imgui-color (at 1 base16-colors)))
(set (at ImGuiCol_TableRowBgAlt colors) (auto-color-to-imgui-color (at 8 base16-colors)))
(set (at ImGuiCol_TextSelectedBg colors) (auto-color-to-imgui-color (at 2 base16-colors)))
(set (at ImGuiCol_DragDropTarget colors) (auto-color-to-imgui-color (at 7 base16-colors)))
(set (at ImGuiCol_NavHighlight colors) (auto-color-to-imgui-color (at 9 base16-colors)))
(set (at ImGuiCol_NavWindowingHighlight colors) (auto-color-to-imgui-color (at 2 base16-colors)))
(set (at ImGuiCol_NavWindowingDimBg colors) (auto-color-to-imgui-color (at 1 base16-colors)))
(set (at ImGuiCol_ModalWindowDimBg colors) (auto-color-to-imgui-color (at 2 base16-colors))))
;; (set (at ImGuiCol_Text colors) (auto-color-to-imgui-color (at 5 base16-colors)))
;; (set (at ImGuiCol_WindowBg colors) (auto-color-to-imgui-color (at 0 base16-colors)))
;; (set (at ImGuiCol_FrameBg colors) (auto-color-to-imgui-color (at 1 base16-colors)))
;; (set (at ImGuiCol_TitleBgActive colors) (auto-color-to-imgui-color (at 2 base16-colors)))
;; (set (at ImGuiCol_TitleBgCollapsed colors) (auto-color-to-imgui-color (at 3 base16-colors)))
;; (set (at ImGuiCol_Button colors) (auto-color-to-imgui-color (at 1 base16-colors)))
)))
(free succeeded)
(free base16-colors))
(def-task pick-colors-from-background (base16-colors (* auto-color)
succeeded-out (* bool))
(fprintf stderr "Picking colors\n")
(set (deref succeeded-out) (auto-color-pick-from-current-background base16-colors))
(fprintf stderr "Picking colors: %s\n" (? (deref succeeded-out) "succeeded" "failed")))
(defun imgui-colors-from-current-background ()
(var-cast-to base16-colors (* auto-color) (calloc 16 (sizeof (type auto-color))))
(var-cast-to succeeded (* bool) (malloc (sizeof (type bool))))
(task-system-execute
(pick-colors-from-background base16-colors succeeded)
(set-imgui-colors-from-base16 :pin-to-main-thread base16-colors succeeded)))

Loading…
Cancel
Save