Change GLFWtheme's public API flags to attributes

This commit is contained in:
ws909 2023-01-30 01:12:12 +01:00
parent b5758af155
commit d87fc99503
5 changed files with 42 additions and 36 deletions

View File

@ -5886,8 +5886,8 @@ GLFWAPI void glfwCopyTheme(const GLFWtheme* source, GLFWtheme* target);
GLFWAPI int glfwThemeGetVariation(const GLFWtheme* theme); GLFWAPI int glfwThemeGetVariation(const GLFWtheme* theme);
GLFWAPI void glfwThemeSetVariation(GLFWtheme* theme, int value); GLFWAPI void glfwThemeSetVariation(GLFWtheme* theme, int value);
GLFWAPI int glfwThemeGetFlags(const GLFWtheme* theme); GLFWAPI int glfwThemeGetAttribute(const GLFWtheme* theme, int attribute);
GLFWAPI void glfwThemeSetFlags(GLFWtheme* theme, int value); 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 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 glfwThemeSetColor(GLFWtheme* theme, float red, float green, float blue, float alpha);
@ -5920,7 +5920,7 @@ GLFWAPI void glfwThemeSetColor(GLFWtheme* theme, float red, float green, float b
#define GLFW_THEME_LIGHT 1 #define GLFW_THEME_LIGHT 1
/*! @brief Theme flag. /*! @brief Theme attribute.
* *
* Specifies that a theme provides a color. If this flag is set on a theme * 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 * returned by GLFW, this theme contains a color. If this flag is set on a
@ -5929,23 +5929,23 @@ GLFWAPI void glfwThemeSetColor(GLFWtheme* theme, float red, float green, float b
* *
* @ingroup theme * @ingroup theme
*/ */
#define GLFW_THEME_FLAG_HAS_COLOR 1 #define GLFW_THEME_ATTRIBUTE_HAS_COLOR 1
/*! @brief Theme flag. /*! @brief Theme attribute.
* *
* Specifies that a theme uses a high contrast mode. * Specifies that a theme uses a high contrast mode.
* *
* @ingroup theme * @ingroup theme
*/ */
#define GLFW_THEME_FLAG_HIGH_CONTRAST 2 #define GLFW_THEME_ATTRIBUTE_HIGH_CONTRAST 2
/*! @brief Theme flag. /*! @brief Theme attribute.
* *
* Specifies that a theme is vibrant. * Specifies that a theme is vibrant.
* *
* @ingroup theme * @ingroup theme
*/ */
#define GLFW_THEME_FLAG_VIBRANT 4 #define GLFW_THEME_ATTRIBUTE_VIBRANT 4
/*! @brief Sets the system theme callback. /*! @brief Sets the system theme callback.
* *

View File

@ -205,13 +205,13 @@ void nsAppearanceToGLFWTheme(NSAppearance* appearance, _GLFWtheme* theme)
if ([name isEqualToString:NSAppearanceNameVibrantLight]) if ([name isEqualToString:NSAppearanceNameVibrantLight])
{ {
theme->variation = GLFW_THEME_LIGHT; theme->variation = GLFW_THEME_LIGHT;
theme->flags |= GLFW_THEME_FLAG_VIBRANT; theme->flags |= GLFW_THEME_ATTRIBUTE_VIBRANT;
return; return;
} }
if ([name isEqualToString:NSAppearanceNameVibrantDark]) if ([name isEqualToString:NSAppearanceNameVibrantDark])
{ {
theme->variation = GLFW_THEME_DARK; theme->variation = GLFW_THEME_DARK;
theme->flags |= GLFW_THEME_FLAG_VIBRANT; theme->flags |= GLFW_THEME_ATTRIBUTE_VIBRANT;
return; return;
} }
} }
@ -226,25 +226,25 @@ void nsAppearanceToGLFWTheme(NSAppearance* appearance, _GLFWtheme* theme)
if ([name isEqualToString:NSAppearanceNameAccessibilityHighContrastAqua]) if ([name isEqualToString:NSAppearanceNameAccessibilityHighContrastAqua])
{ {
theme->variation = GLFW_THEME_LIGHT; theme->variation = GLFW_THEME_LIGHT;
theme->flags |= GLFW_THEME_FLAG_HIGH_CONTRAST; theme->flags |= GLFW_THEME_ATTRIBUTE_HIGH_CONTRAST;
return; return;
} }
if ([name isEqualToString:NSAppearanceNameAccessibilityHighContrastDarkAqua]) if ([name isEqualToString:NSAppearanceNameAccessibilityHighContrastDarkAqua])
{ {
theme->variation = GLFW_THEME_DARK; theme->variation = GLFW_THEME_DARK;
theme->flags |= GLFW_THEME_FLAG_HIGH_CONTRAST; theme->flags |= GLFW_THEME_ATTRIBUTE_HIGH_CONTRAST;
return; return;
} }
if ([name isEqualToString:NSAppearanceNameAccessibilityHighContrastVibrantLight]) if ([name isEqualToString:NSAppearanceNameAccessibilityHighContrastVibrantLight])
{ {
theme->variation = GLFW_THEME_LIGHT; theme->variation = GLFW_THEME_LIGHT;
theme->flags |= GLFW_THEME_FLAG_VIBRANT | GLFW_THEME_FLAG_HIGH_CONTRAST; theme->flags |= GLFW_THEME_ATTRIBUTE_VIBRANT | GLFW_THEME_ATTRIBUTE_HIGH_CONTRAST;
return; return;
} }
if ([name isEqualToString:NSAppearanceNameAccessibilityHighContrastVibrantDark]) if ([name isEqualToString:NSAppearanceNameAccessibilityHighContrastVibrantDark])
{ {
theme->variation = GLFW_THEME_DARK; theme->variation = GLFW_THEME_DARK;
theme->flags |= GLFW_THEME_FLAG_VIBRANT | GLFW_THEME_FLAG_HIGH_CONTRAST; theme->flags |= GLFW_THEME_ATTRIBUTE_VIBRANT | GLFW_THEME_ATTRIBUTE_HIGH_CONTRAST;
return; return;
} }
} }
@ -501,7 +501,7 @@ static GLFWbool initializeTIS(void)
NSColor* color = [[NSColor controlAccentColor] colorUsingColorSpace:NSColorSpace.genericRGBColorSpace]; NSColor* color = [[NSColor controlAccentColor] colorUsingColorSpace:NSColorSpace.genericRGBColorSpace];
theme.flags |= GLFW_THEME_FLAG_HAS_COLOR; theme.flags |= GLFW_THEME_ATTRIBUTE_HAS_COLOR;
theme.color[0] = color.redComponent; theme.color[0] = color.redComponent;
theme.color[1] = color.greenComponent; theme.color[1] = color.greenComponent;
theme.color[2] = color.blueComponent; theme.color[2] = color.blueComponent;

View File

@ -1898,7 +1898,7 @@ void _glfwSetThemeCocoa(_GLFWwindow* window, _GLFWtheme* theme)
if (theme->variation == GLFW_THEME_LIGHT) if (theme->variation == GLFW_THEME_LIGHT)
{ {
if (theme->flags & GLFW_THEME_FLAG_VIBRANT) if (theme->flags & GLFW_THEME_ATTRIBUTE_VIBRANT)
{ {
name = NSAppearanceNameVibrantLight; name = NSAppearanceNameVibrantLight;
} }
@ -1909,7 +1909,7 @@ void _glfwSetThemeCocoa(_GLFWwindow* window, _GLFWtheme* theme)
} }
else else
{ {
if (theme->flags & GLFW_THEME_FLAG_VIBRANT) if (theme->flags & GLFW_THEME_ATTRIBUTE_VIBRANT)
{ {
name = NSAppearanceNameVibrantDark; name = NSAppearanceNameVibrantDark;
} }
@ -1943,7 +1943,7 @@ _GLFWtheme* _glfwGetThemeCocoa(_GLFWwindow* window)
NSColor* color = [[NSColor controlAccentColor] colorUsingColorSpace:NSColorSpace.genericRGBColorSpace]; NSColor* color = [[NSColor controlAccentColor] colorUsingColorSpace:NSColorSpace.genericRGBColorSpace];
// TODO: Cannot use the accent color directly, for window themes, because the accent color is never overridden. // TODO: Cannot use the accent color directly, for window themes, because the accent color is never overridden.
theme->flags |= GLFW_THEME_FLAG_HAS_COLOR; theme->flags |= GLFW_THEME_ATTRIBUTE_HAS_COLOR;
theme->color[0] = color.redComponent; theme->color[0] = color.redComponent;
theme->color[1] = color.greenComponent; theme->color[1] = color.greenComponent;
theme->color[2] = color.blueComponent; theme->color[2] = color.blueComponent;

View File

@ -65,18 +65,30 @@ GLFWAPI void glfwThemeSetVariation(GLFWtheme* theme, int value)
((_GLFWtheme*) theme)->variation = value; ((_GLFWtheme*) theme)->variation = value;
} }
GLFWAPI int glfwThemeGetFlags(const GLFWtheme* theme) GLFWAPI int glfwThemeGetAttribute(const GLFWtheme* theme, int attribute)
{ {
assert(theme != NULL); assert(theme != NULL);
return ((_GLFWtheme*) theme)->flags; assert((attribute & ~(GLFW_THEME_ATTRIBUTE_HAS_COLOR |
GLFW_THEME_ATTRIBUTE_HIGH_CONTRAST |
GLFW_THEME_ATTRIBUTE_VIBRANT)) == 0);
return ((_GLFWtheme*) theme)->flags & attribute ? GLFW_TRUE : GLFW_FALSE;
} }
GLFWAPI void glfwThemeSetFlags(GLFWtheme* theme, int value) GLFWAPI void glfwThemeSetAttribute(GLFWtheme* theme, int attribute, int value)
{ {
assert(theme != NULL); assert(theme != NULL);
assert((value & ~(GLFW_THEME_FLAG_HAS_COLOR | GLFW_THEME_FLAG_HIGH_CONTRAST | GLFW_THEME_FLAG_VIBRANT)) == 0); assert(value == GLFW_TRUE || value == GLFW_FALSE);
assert((attribute & ~(GLFW_THEME_ATTRIBUTE_HAS_COLOR |
GLFW_THEME_ATTRIBUTE_HIGH_CONTRAST |
GLFW_THEME_ATTRIBUTE_VIBRANT)) == 0);
((_GLFWtheme*) theme)->flags = value; _GLFWtheme* _theme = (_GLFWtheme*) theme;
if (value == GLFW_TRUE)
_theme->flags |= attribute;
else
_theme->flags &= ~attribute;
} }
GLFWAPI void glfwThemeGetColor(const GLFWtheme* theme, float* red, float* green, float* blue, float* alpha) GLFWAPI void glfwThemeGetColor(const GLFWtheme* theme, float* red, float* green, float* blue, float* alpha)

View File

@ -52,26 +52,25 @@ static GLFWtheme* theme;
static void print_theme(GLFWtheme* theme, const char* title) static void print_theme(GLFWtheme* theme, const char* title)
{ {
const int flags = glfwThemeGetFlags(theme);
int n = 0; int n = 0;
printf("%s: {\n", title); printf("%s: {\n", title);
printf(" Base: %s\n", glfwThemeGetVariation(theme) == GLFW_THEME_LIGHT ? "light" : "dark"); printf(" Base: %s\n", glfwThemeGetVariation(theme) == GLFW_THEME_LIGHT ? "light" : "dark");
printf(" Flags: ["); printf(" Flags: [");
if (flags & GLFW_THEME_FLAG_HAS_COLOR) if (glfwThemeGetAttribute(theme, GLFW_THEME_ATTRIBUTE_HAS_COLOR))
{ {
printf(n++ > 0 ? ", %s" : "%s", "HAS_COLOR"); printf(n++ > 0 ? ", %s" : "%s", "HAS_COLOR");
} }
if (flags & GLFW_THEME_FLAG_VIBRANT) if (glfwThemeGetAttribute(theme, GLFW_THEME_ATTRIBUTE_VIBRANT))
{ {
printf(n++ > 0 ? ", %s" : "%s", "VIBRANT"); printf(n++ > 0 ? ", %s" : "%s", "VIBRANT");
} }
if (flags & GLFW_THEME_FLAG_HIGH_CONTRAST) if (glfwThemeGetAttribute(theme, GLFW_THEME_ATTRIBUTE_HIGH_CONTRAST))
{ {
printf(n++ > 0 ? ", %s" : "%s", "HIGH_CONTRAST"); printf(n++ > 0 ? ", %s" : "%s", "HIGH_CONTRAST");
} }
printf("]\n"); printf("]\n");
if (flags & GLFW_THEME_FLAG_HAS_COLOR) if (glfwThemeGetAttribute(theme, GLFW_THEME_ATTRIBUTE_HAS_COLOR))
{ {
float r, g, b, a; float r, g, b, a;
glfwThemeGetColor(theme, &r, &g, &b, &a); glfwThemeGetColor(theme, &r, &g, &b, &a);
@ -91,12 +90,9 @@ static void set_theme(GLFWwindow* window, int theme_color)
); );
if (theme_color == 6) if (theme_color == 6)
{ glfwThemeSetAttribute(theme, GLFW_THEME_ATTRIBUTE_HAS_COLOR, GLFW_FALSE);
glfwThemeSetFlags(theme, glfwThemeGetFlags(theme) & ~GLFW_THEME_FLAG_HAS_COLOR); else
} else glfwThemeSetAttribute(theme, GLFW_THEME_ATTRIBUTE_HAS_COLOR, GLFW_TRUE);
{
glfwThemeSetFlags(theme, glfwThemeGetFlags(theme) | GLFW_THEME_FLAG_HAS_COLOR);
}
const char* title; const char* title;
@ -183,8 +179,6 @@ int main(int argc, char** argv)
theme = glfwCreateTheme(); theme = glfwCreateTheme();
glfwThemeSetVariation(theme, GLFW_THEME_DEFAULT);
glfwThemeSetFlags(theme, 0);
glfwThemeSetColor(theme, 0, 0, 0, 0); glfwThemeSetColor(theme, 0, 0, 0, 0);
set_theme(window, cur_theme_color); set_theme(window, cur_theme_color);