color
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good

This commit is contained in:
Nishi 2026-05-21 10:56:12 +09:00
commit 2e2833f57b
6 changed files with 844 additions and 4712 deletions

View file

@ -28,6 +28,12 @@ MWDECL MwLLColor MWAPI MwParseColor(MwWidget handle, const char* text);
*/ */
MWDECL void MWAPI MwParseColorNoAllocate(const char* text, MwRGB* rgb); MWDECL void MWAPI MwParseColorNoAllocate(const char* text, MwRGB* rgb);
/*!
* @brief Initialize color table
* @warning This is called in MwLibraryInit - you do not have to call this
*/
MWDECL void MWAPI MwColorTableInit(void);
/*! /*!
* @brief Lighten a color * @brief Lighten a color
* @param handle Widget * @param handle Widget

File diff suppressed because it is too large Load diff

View file

@ -998,6 +998,8 @@ int MwLibraryInit(void) {
NULL}; NULL};
int i; int i;
MwColorTableInit();
MwFLSetup(); MwFLSetup();
for(i = 0; calls[i] != NULL; i++) { for(i = 0; calls[i] != NULL; i++) {

View file

@ -4,6 +4,15 @@ open(OUT, ">", "src/color.c");
print(OUT "#include <Mw/Milsko.h>\n"); print(OUT "#include <Mw/Milsko.h>\n");
print(OUT "\n"); print(OUT "\n");
print(OUT "#include \"../external/stb_ds.h\"\n");
print(OUT "\n");
print(OUT "struct color {\n");
print(OUT " char* key;\n");
print(OUT " MwU32 value;\n");
print(OUT "};\n");
print(OUT "\n");
print(OUT "static struct color* colors = NULL;\n");
print(OUT "\n");
print(OUT "MwLLColor MwParseColorName(MwWidget handle, const char* color){\n"); print(OUT "MwLLColor MwParseColorName(MwWidget handle, const char* color){\n");
print(OUT " MwRGB rgb;\n"); print(OUT " MwRGB rgb;\n");
print(OUT " MwParseColorNameNoAllocate(color, &rgb);\n"); print(OUT " MwParseColorNameNoAllocate(color, &rgb);\n");
@ -13,21 +22,26 @@ print(OUT
print(OUT "}\n"); print(OUT "}\n");
print(OUT "\n"); print(OUT "\n");
print(OUT "void MwParseColorNameNoAllocate(const char* color, MwRGB* rgb){\n"); print(OUT "void MwParseColorNameNoAllocate(const char* color, MwRGB* rgb){\n");
print(OUT " MwU32 v = shget(colors, color);");
print(OUT " rgb->red = (v >> 16) & 0xff;");
print(OUT " rgb->green = (v >> 8) & 0xff;");
print(OUT " rgb->blue = (v >> 0) & 0xff;");
print(OUT "}\n");
print(OUT "\n");
print(OUT "static void add_color(const char* name, int red, int green, int blue){\n");
print(OUT " MwU32 v = (red << 16) | (green << 8) | (blue << 0);\n");
print(OUT " shput(colors, name, v);\n");
print(OUT "}\n");
print(OUT "\n");
print(OUT "void MwColorTableInit(void){\n");
print(OUT " sh_new_strdup(colors);\n");
print(OUT " shdefault(colors, 0);\n");
while (my $l = <IN>) { while (my $l = <IN>) {
$l =~ s/\r?\n$//; $l =~ s/\r?\n$//;
if ($l =~ /^[ \t]*([0-9]+)[ \t]+([0-9]+)[ \t]+([0-9]+)[ \t]+(.+)$/) { if ($l =~ /^[ \t]*([0-9]+)[ \t]+([0-9]+)[ \t]+([0-9]+)[ \t]+(.+)$/) {
print(OUT " if(strcmp(color, \"$4\") == 0){\n"); print(OUT " add_color(\"$4\", $1, $2, $3);\n");
print(OUT " rgb->red = $1;\n");
print(OUT " rgb->green = $2;\n");
print(OUT " rgb->blue = $3;\n");
print(OUT " return;\n");
print(OUT " }\n");
} }
} }
print(OUT " rgb->red = 0;\n");
print(OUT " rgb->green = 0;\n");
print(OUT " rgb->blue = 0;\n");
print(OUT "}\n"); print(OUT "}\n");
close(OUT); close(OUT);