Browse Source

Checkbox for using theme on treemap

filter-focus
Macoy Madson 1 year ago
parent
commit
0207615a0e
  1. 16
      src/FileHelper.cake
  2. 6
      src/ImGuiAutoColor.cake
  3. 11
      src/TreemapOpenGL.cake

16
src/FileHelper.cake

@ -50,6 +50,8 @@
(var-global g-userdata-dict (* directory-entry-userdata) null)
(var g-treemap-use-theme-for-colorization bool true)
;; Is SDL_Scancode, but I don't want to have to include SDL in every file that wants these
(def-type-alias-global category-keybind (unsigned int))
(defstruct category-available-keybind
@ -1130,6 +1132,8 @@
(imgui-refresh-button null)
(imgui-call SameLine)
(imgui-call Text "to see changes")
(imgui-call SameLine)
(imgui-call Checkbox "Use colors from theme" (addr g-treemap-use-theme-for-colorization))
(imgui-call Separator)
(each-item-addr-in-dynarray g-file-colorizers i colorizer (* file-colorizer)
@ -1605,6 +1609,15 @@ Depending on the error, open the UserData.cakedata file in a text editor and see
(SDL_GetWindowSize window (addr application-window-width) (addr application-window-height))
(assert (and application-window-width application-window-height))
(var treemap-color-palette (* float)
(type-cast current-interpolate-base16-colors (* float)))
(var colorizer-user-palette ([] (* 16 3) float) (array 0)) ;; TODO hardcoded
(unless g-treemap-use-theme-for-colorization
(each-item-addr-in-dynarray g-file-colorizers i colorizer (* file-colorizer)
(memcpy (addr (at (* i 3) colorizer-user-palette))
(path colorizer > color)
(sizeof (path colorizer > color))))
(set treemap-color-palette (type-cast colorizer-user-palette (* float))))
(var-cast-to
treemap-texture ImTextureID
(treemap-opengl-render
@ -1615,7 +1628,8 @@ Depending on the error, open the UserData.cakedata file in a text editor and see
(get-treemap-transform (get-current-treemap-layout-size g-treemap-multithreaded-state))
picked-rectangle-index
;; TODO: Only dim after some threshold of time
(= treemap-running-state-done treemap-status)))
(= treemap-running-state-done treemap-status)
treemap-color-palette))
;; Invert the V
(imgui-call Image treemap-texture treemap-texture-size (ImVec2 0 1) (ImVec2 1 0))

6
src/ImGuiAutoColor.cake

@ -31,6 +31,7 @@
(array 0x5a 0xa8 0xf0)
(array 0x77 0x8e 0xae)))
;; Colors are in range 0 to 1.f
(var-global current-interpolate-base16-colors ([] 16 ([] 3 float)) (array 0))
(var target-set-time float 0.f)
@ -105,7 +106,7 @@
(each-in-array 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))))
(/ (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))
@ -150,12 +151,13 @@
(each-in-range 3 component
(var current-value float (at i component 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)
(+ current-value
(* transition-speed
(- current-value target-value))))
(set (at i component current-base16-colors)
(type-cast (round (at i component current-interpolate-base16-colors))
(type-cast (round (* 255.f (at i component current-interpolate-base16-colors)))
(unsigned char)))))
(unless (= 0 (memcmp before-update-values current-base16-colors (sizeof before-update-values)))

11
src/TreemapOpenGL.cake

@ -203,9 +203,9 @@ uniform float colorPalette[16 * 3];
void main()
{
// TODO: Why do I need this cast?
vec3 paletteColor = vec3(colorPalette[int((float(colorPaletteIndex) * 3) + 0)] / 255.f,
colorPalette[int((float(colorPaletteIndex) * 3) + 1)] / 255.f,
colorPalette[int((float(colorPaletteIndex) * 3) + 2)] / 255.f);
vec3 paletteColor = vec3(colorPalette[int((float(colorPaletteIndex) * 3) + 0)],
colorPalette[int((float(colorPaletteIndex) * 3) + 1)],
colorPalette[int((float(colorPaletteIndex) * 3) + 2)]);
const float minBrightness = 0.05f;
float thisColorMaxBrightness = max(paletteColor.x, max(paletteColor.y, paletteColor.z));
if (thisColorMaxBrightness < minBrightness)
@ -281,6 +281,8 @@ void main()
treemap-width int treemap-height int
transform mat4 picked-rectangle-index int
is-treemap-valid bool
;; Size should equal g-max-num-classification-colors
color-palette (* float)
&return int) ;; Returns texture ID
(scope-timed "Render visible" ;; Render visible treemap to frame buffer
(glViewport 0 0 treemap-width treemap-height)
@ -305,8 +307,7 @@ void main()
(var color-palette-uniform int
(glGetUniformLocation (field g-treemap-opengl shader-program) "colorPalette"))
(glUniform1fv color-palette-uniform (* 16 3) ;; TODO don't hard-code
(type-cast current-interpolate-base16-colors (* float)))
(glUniform1fv color-palette-uniform (* g-max-num-classification-colors 3) color-palette)
(glBindVertexArray (field g-treemap-opengl mesh-array-object))
(glDrawElements GL_TRIANGLES (field g-treemap-opengl num-indices) GL_UNSIGNED_INT

Loading…
Cancel
Save