Add color specifier to GLFWtheme.

Add color specifier parameter to glfwThemeGetColor and glfwThemeSetColor.
Add GLFW_THEME_COLOR_MAIN.
Remove GLFW_THEME_ATTRIBUTE_HAS_COLOR.
This commit is contained in:
ws909 2023-02-01 04:44:22 +01:00
parent afae2b0dfa
commit 5805c51eab
5 changed files with 42 additions and 35 deletions

View File

@ -5889,8 +5889,13 @@ GLFWAPI void glfwThemeSetVariation(GLFWtheme* theme, int value);
GLFWAPI int glfwThemeGetAttribute(const GLFWtheme* theme, int attribute);
GLFWAPI void glfwThemeSetAttribute(GLFWtheme* theme, int attribute, int value);
GLFWAPI void glfwThemeGetColor(const GLFWtheme* theme, float* red, float* green, float* blue, float* alpha);
GLFWAPI void glfwThemeSetColor(GLFWtheme* theme, float red, float green, float blue, float alpha);
GLFWAPI void glfwThemeGetColor(const GLFWtheme* theme,
int specifier,
float* red, float* green, float* blue, float* alpha);
GLFWAPI void glfwThemeSetColor(GLFWtheme* theme,
int specifier,
float red, float green, float blue, float alpha);
/*! @brief Theme variation type.
*
@ -5919,25 +5924,13 @@ GLFWAPI void glfwThemeSetColor(GLFWtheme* theme, float red, float green, float b
*/
#define GLFW_THEME_LIGHT 1
/*! @brief Theme attribute.
*
* Specifies that a theme provides a color. If this flag is set on a theme
* returned by GLFW, this theme contains a color. If this flag is set on a
* theme supplied to GLFW, GLFW applies this theme if the platform supports it.
* If the flag is unset, the theme's color is ignored.
*
* @ingroup theme
*/
#define GLFW_THEME_ATTRIBUTE_HAS_COLOR 1
/*! @brief Theme attribute.
*
* Specifies that a theme uses a high contrast mode.
*
* @ingroup theme
*/
#define GLFW_THEME_ATTRIBUTE_HIGH_CONTRAST 2
#define GLFW_THEME_ATTRIBUTE_HIGH_CONTRAST 1
/*! @brief Theme attribute.
*
@ -5945,7 +5938,18 @@ GLFWAPI void glfwThemeSetColor(GLFWtheme* theme, float red, float green, float b
*
* @ingroup theme
*/
#define GLFW_THEME_ATTRIBUTE_VIBRANT 4
#define GLFW_THEME_ATTRIBUTE_VIBRANT 2
/*! @brief Theme color attribute.
*
* This is both an attribute and color specifier. As an attribute, it specifies
* if this color is present in the theme or not. If this attribute is set on a theme
* returned by GLFW, that theme contains this color. If this attribute is set on a
* theme supplied to GLFW, GLFW applies this color if the platform supports it.
*
* @ingroup theme
*/
#define GLFW_THEME_COLOR_MAIN 4
/*! @brief Sets the system theme callback.
*

View File

@ -266,7 +266,7 @@ static void getSystemTheme(_GLFWtheme* theme)
NSColor* color = [[NSColor controlAccentColor] colorUsingColorSpace:NSColorSpace.genericRGBColorSpace];
theme->flags |= GLFW_THEME_ATTRIBUTE_HAS_COLOR;
theme->flags |= GLFW_THEME_COLOR_MAIN;
theme->color[0] = color.redComponent;
theme->color[1] = color.greenComponent;
theme->color[2] = color.blueComponent;

View File

@ -1948,7 +1948,7 @@ _GLFWtheme* _glfwGetThemeCocoa(_GLFWwindow* window)
NSColor* color = [[NSColor controlAccentColor] colorUsingColorSpace:NSColorSpace.genericRGBColorSpace];
// TODO: Cannot use the accent color directly, for window themes, because the accent color is never overridden.
theme->flags |= GLFW_THEME_ATTRIBUTE_HAS_COLOR;
theme->flags |= GLFW_THEME_COLOR_MAIN;
theme->color[0] = color.redComponent;
theme->color[1] = color.greenComponent;
theme->color[2] = color.blueComponent;

View File

@ -68,9 +68,9 @@ GLFWAPI void glfwThemeSetVariation(GLFWtheme* theme, int value)
GLFWAPI int glfwThemeGetAttribute(const GLFWtheme* theme, int attribute)
{
assert(theme != NULL);
assert((attribute & ~(GLFW_THEME_ATTRIBUTE_HAS_COLOR |
GLFW_THEME_ATTRIBUTE_HIGH_CONTRAST |
GLFW_THEME_ATTRIBUTE_VIBRANT)) == 0);
assert((attribute & ~(GLFW_THEME_ATTRIBUTE_HIGH_CONTRAST |
GLFW_THEME_ATTRIBUTE_VIBRANT |
GLFW_THEME_COLOR_MAIN)) == 0);
return ((_GLFWtheme*) theme)->flags & attribute ? GLFW_TRUE : GLFW_FALSE;
}
@ -79,9 +79,9 @@ GLFWAPI void glfwThemeSetAttribute(GLFWtheme* theme, int attribute, int value)
{
assert(theme != NULL);
assert(value == GLFW_TRUE || value == GLFW_FALSE);
assert((attribute & ~(GLFW_THEME_ATTRIBUTE_HAS_COLOR |
GLFW_THEME_ATTRIBUTE_HIGH_CONTRAST |
GLFW_THEME_ATTRIBUTE_VIBRANT)) == 0);
assert((attribute & ~(GLFW_THEME_ATTRIBUTE_HIGH_CONTRAST |
GLFW_THEME_ATTRIBUTE_VIBRANT |
GLFW_THEME_COLOR_MAIN)) == 0);
_GLFWtheme* _theme = (_GLFWtheme*) theme;
@ -91,9 +91,10 @@ GLFWAPI void glfwThemeSetAttribute(GLFWtheme* theme, int attribute, int value)
_theme->flags &= ~attribute;
}
GLFWAPI void glfwThemeGetColor(const GLFWtheme* theme, float* red, float* green, float* blue, float* alpha)
GLFWAPI void glfwThemeGetColor(const GLFWtheme* theme, int specifier, float* red, float* green, float* blue, float* alpha)
{
assert(theme != NULL);
assert(specifier == GLFW_THEME_COLOR_MAIN);
assert(red != NULL && green != NULL && blue != NULL && alpha != NULL);
const float* color = ((_GLFWtheme*) theme)->color;
@ -104,9 +105,10 @@ GLFWAPI void glfwThemeGetColor(const GLFWtheme* theme, float* red, float* green,
*alpha = color[3];
}
GLFWAPI void glfwThemeSetColor(GLFWtheme* theme, float red, float green, float blue, float alpha)
GLFWAPI void glfwThemeSetColor(GLFWtheme* theme, int specifier, float red, float green, float blue, float alpha)
{
assert(theme != NULL);
assert(specifier == GLFW_THEME_COLOR_MAIN);
float* color = ((_GLFWtheme*) theme)->color;

View File

@ -55,11 +55,11 @@ static void print_theme(GLFWtheme* theme, const char* title)
int n = 0;
printf("%s: {\n", title);
printf(" Base: %s\n", glfwThemeGetVariation(theme) == GLFW_THEME_LIGHT ? "light" : "dark");
printf(" Flags: [");
if (glfwThemeGetAttribute(theme, GLFW_THEME_ATTRIBUTE_HAS_COLOR))
printf(" Variation: %s\n", glfwThemeGetVariation(theme) == GLFW_THEME_LIGHT ? "light" : "dark");
printf(" Attributes: [");
if (glfwThemeGetAttribute(theme, GLFW_THEME_COLOR_MAIN))
{
printf(n++ > 0 ? ", %s" : "%s", "HAS_COLOR");
printf(n++ > 0 ? ", %s" : "%s", "COLOR_MAIN");
}
if (glfwThemeGetAttribute(theme, GLFW_THEME_ATTRIBUTE_VIBRANT))
{
@ -70,11 +70,11 @@ static void print_theme(GLFWtheme* theme, const char* title)
printf(n++ > 0 ? ", %s" : "%s", "HIGH_CONTRAST");
}
printf("]\n");
if (glfwThemeGetAttribute(theme, GLFW_THEME_ATTRIBUTE_HAS_COLOR))
if (glfwThemeGetAttribute(theme, GLFW_THEME_COLOR_MAIN))
{
float r, g, b, a;
glfwThemeGetColor(theme, &r, &g, &b, &a);
printf(" Color: [%f, %f, %f, %f]\n", r, g, b, a);
glfwThemeGetColor(theme, GLFW_THEME_COLOR_MAIN, &r, &g, &b, &a);
printf(" Main color: [%f, %f, %f, %f]\n", r, g, b, a);
}
printf("}\n");
}
@ -83,6 +83,7 @@ static void set_theme(GLFWwindow* window, int theme_color)
{
glfwThemeSetColor(
theme,
GLFW_THEME_COLOR_MAIN,
theme_colors[theme_color][0],
theme_colors[theme_color][1],
theme_colors[theme_color][2],
@ -90,9 +91,9 @@ static void set_theme(GLFWwindow* window, int theme_color)
);
if (theme_color == 6)
glfwThemeSetAttribute(theme, GLFW_THEME_ATTRIBUTE_HAS_COLOR, GLFW_FALSE);
glfwThemeSetAttribute(theme, GLFW_THEME_COLOR_MAIN, GLFW_FALSE);
else
glfwThemeSetAttribute(theme, GLFW_THEME_ATTRIBUTE_HAS_COLOR, GLFW_TRUE);
glfwThemeSetAttribute(theme, GLFW_THEME_COLOR_MAIN, GLFW_TRUE);
const char* title;