mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2025-12-31 06:30:52 +00:00
update color things
This commit is contained in:
@@ -21,6 +21,13 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
MWDECL MwLLColor MwParseColor(MwWidget handle, const char* text);
|
MWDECL MwLLColor MwParseColor(MwWidget handle, const char* text);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Parses a color text
|
||||||
|
* @param text Color text
|
||||||
|
* @param rgb RGB
|
||||||
|
*/
|
||||||
|
MWDECL void MwParseColorNoAllocate(const char* text, MwRGB* rgb);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Lighten a color
|
* @brief Lighten a color
|
||||||
* @param handle Widget
|
* @param handle Widget
|
||||||
@@ -120,12 +127,12 @@ MWDECL MwLLPixmap MwLoadRaw(MwWidget handle, unsigned char* rgb, int width, int
|
|||||||
/*!
|
/*!
|
||||||
* @brief Creates a pixmap from raw data
|
* @brief Creates a pixmap from raw data
|
||||||
* @param handle Widget
|
* @param handle Widget
|
||||||
|
* @param pixmap Pixmap to update
|
||||||
* @param rgb RGBA data
|
* @param rgb RGBA data
|
||||||
* @param width Width
|
* @param width Width
|
||||||
* @param height Height
|
* @param height Height
|
||||||
* @return Pixmap
|
|
||||||
*/
|
*/
|
||||||
MWDECL void MwReloadRaw(MwWidget handle, unsigned char* rgb, int width, int height, MwLLPixmap pixmap);
|
MWDECL void MwReloadRaw(MwWidget handle, MwLLPixmap pixmap, unsigned char* rgb, int width, int height);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Creates a pixmap from XPM data
|
* @brief Creates a pixmap from XPM data
|
||||||
@@ -191,6 +198,13 @@ MWDECL int MwTextHeight(MwWidget handle, const char* text);
|
|||||||
*/
|
*/
|
||||||
MWDECL MwLLColor MwParseColorName(MwWidget handle, const char* color);
|
MWDECL MwLLColor MwParseColorName(MwWidget handle, const char* color);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Parses a color name
|
||||||
|
* @param color Color name
|
||||||
|
* @param rgb RGB
|
||||||
|
*/
|
||||||
|
MWDECL void MwParseColorNameNoAllocate(const char* color, MwRGB* rgb);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -580,7 +580,7 @@ static void MwLLSetTitleImpl(MwLL handle, const char* title) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data, int width, int height) {
|
static MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data, int width, int height) {
|
||||||
MwLLPixmap r = malloc(sizeof(*r));
|
MwLLPixmap r = malloc(sizeof(*r));
|
||||||
int evbase, erbase;
|
int evbase, erbase;
|
||||||
XWindowAttributes attr;
|
XWindowAttributes attr;
|
||||||
|
|
||||||
@@ -605,7 +605,7 @@ static MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data, int wid
|
|||||||
r->x11.mask = XCreateImage(handle->x11.display, DefaultVisual(handle->x11.display, DefaultScreen(handle->x11.display)), 1, ZPixmap, 0, NULL, width, height, 32, 0);
|
r->x11.mask = XCreateImage(handle->x11.display, DefaultVisual(handle->x11.display, DefaultScreen(handle->x11.display)), 1, ZPixmap, 0, NULL, width, height, 32, 0);
|
||||||
|
|
||||||
r->x11.image->data = malloc(r->x11.image->bytes_per_line * height);
|
r->x11.image->data = malloc(r->x11.image->bytes_per_line * height);
|
||||||
r->x11.mask->data = malloc(r->x11.mask->bytes_per_line * height);
|
r->x11.mask->data = malloc(r->x11.mask->bytes_per_line * height);
|
||||||
|
|
||||||
MwLLPixmapUpdate(r);
|
MwLLPixmapUpdate(r);
|
||||||
return r;
|
return r;
|
||||||
|
|||||||
5484
src/color.c
5484
src/color.c
File diff suppressed because it is too large
Load Diff
71
src/draw.c
71
src/draw.c
@@ -37,28 +37,35 @@ static int hex(const char* txt, int len) {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
MwLLColor MwParseColor(MwWidget handle, const char* text) {
|
void MwParseColorNoAllocate(const char* text, MwRGB* rgb) {
|
||||||
int r;
|
|
||||||
int g;
|
|
||||||
int b;
|
|
||||||
|
|
||||||
if(text[0] == '#' && strlen(text) == 4) {
|
if(text[0] == '#' && strlen(text) == 4) {
|
||||||
r = hex(text + 1, 1);
|
rgb->red = hex(text + 1, 1);
|
||||||
g = hex(text + 2, 1);
|
rgb->green = hex(text + 2, 1);
|
||||||
b = hex(text + 3, 1);
|
rgb->blue = hex(text + 3, 1);
|
||||||
|
|
||||||
r |= r << 4;
|
rgb->red |= rgb->red << 4;
|
||||||
g |= g << 4;
|
rgb->green |= rgb->green << 4;
|
||||||
b |= b << 4;
|
rgb->blue |= rgb->blue << 4;
|
||||||
} else if(text[0] == '#' && strlen(text) == 7) {
|
} else if(text[0] == '#' && strlen(text) == 7) {
|
||||||
r = hex(text + 1, 2);
|
rgb->red = hex(text + 1, 2);
|
||||||
g = hex(text + 3, 2);
|
rgb->green = hex(text + 3, 2);
|
||||||
b = hex(text + 5, 2);
|
rgb->blue = hex(text + 5, 2);
|
||||||
} else {
|
} else {
|
||||||
return MwParseColorName(handle, text);
|
MwParseColorNameNoAllocate(text, rgb);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return MwLLAllocColor(handle->lowlevel, r, g, b);
|
MwLLColor MwParseColor(MwWidget handle, const char* text) {
|
||||||
|
MwRGB rgb;
|
||||||
|
|
||||||
|
rgb.red = 0;
|
||||||
|
rgb.green = 0;
|
||||||
|
rgb.blue = 0;
|
||||||
|
|
||||||
|
MwParseColorNoAllocate(text, &rgb);
|
||||||
|
|
||||||
|
return MwLLAllocColor(handle->lowlevel, rgb.red, rgb.green, rgb.blue);
|
||||||
}
|
}
|
||||||
|
|
||||||
MwLLColor MwLightenColor(MwWidget handle, MwLLColor color, int r, int g, int b) {
|
MwLLColor MwLightenColor(MwWidget handle, MwLLColor color, int r, int g, int b) {
|
||||||
@@ -649,40 +656,14 @@ MwLLPixmap MwLoadImage(MwWidget handle, const char* path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MwLLPixmap MwLoadRaw(MwWidget handle, unsigned char* rgb, int width, int height) {
|
MwLLPixmap MwLoadRaw(MwWidget handle, unsigned char* rgb, int width, int height) {
|
||||||
MwLLPixmap px;
|
MwLLPixmap px = MwLLCreatePixmap(handle->lowlevel, rgb, width, height);
|
||||||
unsigned char* out = malloc(width * height * 4);
|
|
||||||
int i;
|
|
||||||
MwLLColor base = handle->bgcolor == NULL ? MwParseColor(handle, MwGetText(handle, MwNbackground)) : handle->bgcolor;
|
|
||||||
|
|
||||||
memset(out, 0, width * height * 4);
|
MwReloadRaw(handle, px, rgb, width, height);
|
||||||
for(i = 0; i < width * height; i++) {
|
|
||||||
unsigned char* pin = &rgb[i * 4];
|
|
||||||
unsigned char* pout = &out[i * 4];
|
|
||||||
double a = pin[3];
|
|
||||||
|
|
||||||
a /= 255;
|
|
||||||
if(a != 0) {
|
|
||||||
pout[0] = pin[0] * a;
|
|
||||||
pout[1] = pin[1] * a;
|
|
||||||
pout[2] = pin[2] * a;
|
|
||||||
|
|
||||||
pout[0] += base->common.red * (1 - a);
|
|
||||||
pout[1] += base->common.green * (1 - a);
|
|
||||||
pout[2] += base->common.blue * (1 - a);
|
|
||||||
pout[3] = 255;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(handle->bgcolor == NULL) MwLLFreeColor(base);
|
|
||||||
|
|
||||||
px = MwLLCreatePixmap(handle->lowlevel, out, width, height);
|
|
||||||
|
|
||||||
free(out);
|
|
||||||
|
|
||||||
return px;
|
return px;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MwReloadRaw(MwWidget handle, unsigned char* rgb, int width, int height, MwLLPixmap px) {
|
void MwReloadRaw(MwWidget handle, MwLLPixmap px, unsigned char* rgb, int width, int height) {
|
||||||
int i;
|
int i;
|
||||||
MwLLColor base = handle->bgcolor == NULL ? MwParseColor(handle, MwGetText(handle, MwNbackground)) : handle->bgcolor;
|
MwLLColor base = handle->bgcolor == NULL ? MwParseColor(handle, MwGetText(handle, MwNbackground)) : handle->bgcolor;
|
||||||
|
|
||||||
|
|||||||
@@ -5,15 +5,29 @@ 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 "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 " MwParseColorNameNoAllocate(color, &rgb);\n");
|
||||||
|
print(OUT
|
||||||
|
" return MwLLAllocColor(handle->lowlevel, rgb.red, rgb.green, rgb.blue);\n"
|
||||||
|
);
|
||||||
|
print(OUT "}\n");
|
||||||
|
print(OUT "\n");
|
||||||
|
print(OUT "void MwParseColorNameNoAllocate(const char* color, MwRGB* rgb){\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
|
print(OUT " if(strcmp(color, \"$4\") == 0){\n");
|
||||||
" if(strcmp(color, \"$4\") == 0) return MwLLAllocColor(handle->lowlevel, $1, $2, $3);\n"
|
print(OUT " rgb->red = $1;\n");
|
||||||
);
|
print(OUT " rgb->green = $2;\n");
|
||||||
|
print(OUT " rgb->green = $3;\n");
|
||||||
|
print(OUT " return;\n");
|
||||||
|
print(OUT " }\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
print(OUT " return MwLLAllocColor(handle->lowlevel, 0, 0, 0);\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);
|
||||||
|
|||||||
Reference in New Issue
Block a user