Browse Source

Get AutoColor building in C

* Exported and hand-edited AutoColor.h. I eventually want this to be
automatic, but I don't have time for now
* Include stdbool for C support
* Pack colors for C support
* Link to libm for pow, round
master
Macoy Madson 2 months ago
parent
commit
63762d670e
  1. 3
      .gitignore
  2. 1025
      AutoColor.h
  3. 3
      Build.sh
  4. 8
      ReadMe.org
  5. 9
      src/AutoColor.cake
  6. 9
      src/CreateSingleFileLib.cake
  7. 5
      test/Build.sh
  8. 13
      test/main.c

3
.gitignore

@ -42,4 +42,5 @@ lib/
imgui.ini
auto-color
auto-color
test/auto-color-test

1025
AutoColor.h

File diff suppressed because it is too large

3
Build.sh

@ -16,5 +16,6 @@ CAKELISP=./Dependencies/cakelisp/bin/cakelisp
$CAKELISP --execute --verbose-processes \
src/Config_Linux.cake \
src/AutoColorCLI.cake \
src/CreateSingleFileLib.cake \
|| exit $?
#src/CreateSingleFileLib.cake \

8
ReadMe.org

@ -14,7 +14,7 @@ Similar to musical notes, colors look best in context. Auto Color ensures the ap
* Applications
When included in a C/C++ project, the color values can be used to theme the application to match the user's background automatically.
In this example, an application I wrote using ImGui uses Auto Color to match the user's wallpaper at startup:
In this example, an application I wrote using ImGui uses Auto Color to theme to the user's wallpaper:
[[./images/ImGuiExample1.jpg]]
@ -49,12 +49,16 @@ Here's a simple usage example:
AutoColor base16Colors[16] = {0};
if (!autoColorPickFromCurrentBackground(base16Colors))
return 1;
fprintf(stderr "The first color is RGB %d, %d, %d\n"
fprintf(stderr, "The first color is RGB %d, %d, %d\n",
base16Colors[0][0], base16Colors[0][1], base16Colors[0][2]);
return 0;
}
#+END_SRC
See the ~test/~ directory for a buildable example.
Note that loading the wallpaper can take a relatively long time, depending on its resolution (long being around 200ms). If you are writing a real-time application, you should run ~autoColorPickFromCurrentBackground()~ on a separate thread than the render thread.
** Windows
The desktop background is retrieved by checking the registry.

9
src/AutoColor.cake

@ -3,7 +3,8 @@
(c-import "<stdio.h>" ;; fprintf, strncmp
"<stdlib.h>" ;; qsort
"<string.h>" ;; memcmp
"<math.h>") ;; sqrtf
"<math.h>" ;; sqrtf, round
&with-decls "stdbool.h") ;; bool
(var-global g-auto-color-copyright-string (* (const char))
#"#Auto Color
@ -301,7 +302,8 @@ OF THE POSSIBILITY OF SUCH DAMAGE.#"#)
(/ (- (field q w) (field q y))
(+ (* 6.0f c) color-conversion-epsilon))
(field q z))))
(return (array h c (field q x))))
(var packed-color auto-color-float (array h c (field q x)))
(return packed-color))
(defun-local auto-color-rgb-to-hsl (rgb auto-color-float &return auto-color-float)
(var HCV auto-color-float (auto-color-rgb-to-hcv rgb))
@ -309,7 +311,8 @@ OF THE POSSIBILITY OF SUCH DAMAGE.#"#)
(var S float (/ (field HCV y)
(+ (- 1.0f (fabs (- (* L 2.0f) 1.0f)))
color-conversion-epsilon)))
(return (array (field HCV x) S L)))
(var packed-color auto-color-float (array (field HCV x) S L))
(return packed-color))
(defun-local test--auto-color-conversions (&return int)
(var test-hsl auto-color-float (array 0.25f 0.8f 0.2f))

9
src/CreateSingleFileLib.cake

@ -1,5 +1,12 @@
(skip-build)
;; TODO Create Single File:
;; - Output module dependencies
;; - Output all headers first, then all source files
;; - File shouldn't include any headers except stdlib ones
;; - Cakelisp needs to export in C mode (typedef struct, NULL)
;; - Copy stb_image.h to be inline
;; - Remove #pragma once
(defun-comptime create-single-file-lib (manager (& ModuleManager) link-command (& ProcessCommand)
link-time-inputs (* ProcessCommandInput)
num-link-time-inputs int
@ -10,8 +17,6 @@
(Log "error: failed to open single file header for writing\n")
(return false))
(fprintf file-out "// Hello World\n")
(for-in module (* Module) (field manager modules)
(var standard-files-to-output ([] (* (const char)))
(array (call-on c_str (path module > headerOutputName))

5
test/Build.sh

@ -0,0 +1,5 @@
#!/bin/sh
gcc -c main.c -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I../ -I../Dependencies/stb || exit $?
gcc -o auto-color-test main.o -lglib-2.0 -lgio-2.0 -lgobject-2.0 -lm || exit $?
./auto-color-test

13
test/main.c

@ -0,0 +1,13 @@
#include <stdio.h>
#include "AutoColor.h"
int main()
{
AutoColor base16Colors[16] = {0};
if (!autoColorPickFromCurrentBackground(base16Colors))
return 1;
fprintf(stderr, "The first color is RGB %d, %d, %d\n", base16Colors[0][0], base16Colors[0][1],
base16Colors[0][2]);
return 0;
}
Loading…
Cancel
Save