Cleanup: Avoid using macros to refer to theme global variables

Prefer slightly more verbose code to the use of macros where
they aren't really necessary and just add indirection.
This commit is contained in:
Hans Goudey 2022-11-25 17:11:44 -06:00
parent 248ee6270b
commit ed6e1381dc
1 changed files with 62 additions and 63 deletions

View File

@ -46,10 +46,6 @@ static struct bThemeState g_theme_state = {
RGN_TYPE_WINDOW,
};
#define theme_active g_theme_state.theme
#define theme_spacetype g_theme_state.spacetype
#define theme_regionid g_theme_state.regionid
void ui_resources_init(void)
{
UI_icons_init();
@ -75,7 +71,7 @@ const uchar *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid)
const uchar *cp = error;
/* ensure we're not getting a color after running BKE_blender_userdef_free */
BLI_assert(BLI_findindex(&U.themes, theme_active) != -1);
BLI_assert(BLI_findindex(&U.themes, g_theme_state.theme) != -1);
BLI_assert(colorid != TH_UNDEFINED);
if (btheme) {
@ -154,19 +150,19 @@ const uchar *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid)
switch (colorid) {
case TH_BACK:
if (ELEM(theme_regionid, RGN_TYPE_WINDOW, RGN_TYPE_PREVIEW)) {
if (ELEM(g_theme_state.regionid, RGN_TYPE_WINDOW, RGN_TYPE_PREVIEW)) {
cp = ts->back;
}
else if (theme_regionid == RGN_TYPE_CHANNELS) {
else if (g_theme_state.regionid == RGN_TYPE_CHANNELS) {
cp = ts->list;
}
else if (ELEM(theme_regionid, RGN_TYPE_HEADER, RGN_TYPE_FOOTER)) {
else if (ELEM(g_theme_state.regionid, RGN_TYPE_HEADER, RGN_TYPE_FOOTER)) {
cp = ts->header;
}
else if (theme_regionid == RGN_TYPE_NAV_BAR) {
else if (g_theme_state.regionid == RGN_TYPE_NAV_BAR) {
cp = ts->navigation_bar;
}
else if (theme_regionid == RGN_TYPE_EXECUTE) {
else if (g_theme_state.regionid == RGN_TYPE_EXECUTE) {
cp = ts->execution_buts;
}
else {
@ -174,7 +170,7 @@ const uchar *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid)
}
copy_v4_v4_uchar(back, cp);
if (!ED_region_is_overlap(spacetype, theme_regionid)) {
if (!ED_region_is_overlap(spacetype, g_theme_state.regionid)) {
back[3] = 255;
}
cp = back;
@ -188,13 +184,13 @@ const uchar *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid)
setting = ts->background_type;
break;
case TH_TEXT:
if (theme_regionid == RGN_TYPE_WINDOW) {
if (g_theme_state.regionid == RGN_TYPE_WINDOW) {
cp = ts->text;
}
else if (theme_regionid == RGN_TYPE_CHANNELS) {
else if (g_theme_state.regionid == RGN_TYPE_CHANNELS) {
cp = ts->list_text;
}
else if (ELEM(theme_regionid, RGN_TYPE_HEADER, RGN_TYPE_FOOTER)) {
else if (ELEM(g_theme_state.regionid, RGN_TYPE_HEADER, RGN_TYPE_FOOTER)) {
cp = ts->header_text;
}
else {
@ -202,13 +198,13 @@ const uchar *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid)
}
break;
case TH_TEXT_HI:
if (theme_regionid == RGN_TYPE_WINDOW) {
if (g_theme_state.regionid == RGN_TYPE_WINDOW) {
cp = ts->text_hi;
}
else if (theme_regionid == RGN_TYPE_CHANNELS) {
else if (g_theme_state.regionid == RGN_TYPE_CHANNELS) {
cp = ts->list_text_hi;
}
else if (ELEM(theme_regionid, RGN_TYPE_HEADER, RGN_TYPE_FOOTER)) {
else if (ELEM(g_theme_state.regionid, RGN_TYPE_HEADER, RGN_TYPE_FOOTER)) {
cp = ts->header_text_hi;
}
else {
@ -216,13 +212,13 @@ const uchar *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid)
}
break;
case TH_TITLE:
if (theme_regionid == RGN_TYPE_WINDOW) {
if (g_theme_state.regionid == RGN_TYPE_WINDOW) {
cp = ts->title;
}
else if (theme_regionid == RGN_TYPE_CHANNELS) {
else if (g_theme_state.regionid == RGN_TYPE_CHANNELS) {
cp = ts->list_title;
}
else if (ELEM(theme_regionid, RGN_TYPE_HEADER, RGN_TYPE_FOOTER)) {
else if (ELEM(g_theme_state.regionid, RGN_TYPE_HEADER, RGN_TYPE_FOOTER)) {
cp = ts->header_title;
}
else {
@ -1052,21 +1048,21 @@ void UI_SetTheme(int spacetype, int regionid)
{
if (spacetype) {
/* later on, a local theme can be found too */
theme_active = U.themes.first;
theme_spacetype = spacetype;
theme_regionid = regionid;
g_theme_state.theme = U.themes.first;
g_theme_state.spacetype = spacetype;
g_theme_state.regionid = regionid;
}
else if (regionid) {
/* popups */
theme_active = U.themes.first;
theme_spacetype = SPACE_PROPERTIES;
theme_regionid = regionid;
g_theme_state.theme = U.themes.first;
g_theme_state.spacetype = SPACE_PROPERTIES;
g_theme_state.regionid = regionid;
}
else {
/* for safety, when theme was deleted */
theme_active = U.themes.first;
theme_spacetype = SPACE_VIEW3D;
theme_regionid = RGN_TYPE_WINDOW;
g_theme_state.theme = U.themes.first;
g_theme_state.spacetype = SPACE_VIEW3D;
g_theme_state.regionid = RGN_TYPE_WINDOW;
}
}
@ -1087,7 +1083,7 @@ void UI_Theme_Restore(struct bThemeState *theme_state)
void UI_GetThemeColorShadeAlpha4ubv(int colorid, int coloffset, int alphaoffset, uchar col[4])
{
int r, g, b, a;
const uchar *cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid);
r = coloffset + (int)cp[0];
CLAMP(r, 0, 255);
g = coloffset + (int)cp[1];
@ -1105,8 +1101,8 @@ void UI_GetThemeColorShadeAlpha4ubv(int colorid, int coloffset, int alphaoffset,
void UI_GetThemeColorBlend3ubv(int colorid1, int colorid2, float fac, uchar col[3])
{
const uchar *cp1 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
const uchar *cp2 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
const uchar *cp1 = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid1);
const uchar *cp2 = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid2);
CLAMP(fac, 0.0f, 1.0f);
col[0] = floorf((1.0f - fac) * cp1[0] + fac * cp2[0]);
@ -1116,8 +1112,8 @@ void UI_GetThemeColorBlend3ubv(int colorid1, int colorid2, float fac, uchar col[
void UI_GetThemeColorBlend3f(int colorid1, int colorid2, float fac, float r_col[3])
{
const uchar *cp1 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
const uchar *cp2 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
const uchar *cp1 = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid1);
const uchar *cp2 = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid2);
CLAMP(fac, 0.0f, 1.0f);
r_col[0] = ((1.0f - fac) * cp1[0] + fac * cp2[0]) / 255.0f;
@ -1127,8 +1123,8 @@ void UI_GetThemeColorBlend3f(int colorid1, int colorid2, float fac, float r_col[
void UI_GetThemeColorBlend4f(int colorid1, int colorid2, float fac, float r_col[4])
{
const uchar *cp1 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
const uchar *cp2 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
const uchar *cp1 = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid1);
const uchar *cp2 = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid2);
CLAMP(fac, 0.0f, 1.0f);
r_col[0] = ((1.0f - fac) * cp1[0] + fac * cp2[0]) / 255.0f;
@ -1146,31 +1142,31 @@ void UI_FontThemeColor(int fontid, int colorid)
float UI_GetThemeValuef(int colorid)
{
const uchar *cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid);
return ((float)cp[0]);
}
int UI_GetThemeValue(int colorid)
{
const uchar *cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid);
return ((int)cp[0]);
}
float UI_GetThemeValueTypef(int colorid, int spacetype)
{
const uchar *cp = UI_ThemeGetColorPtr(theme_active, spacetype, colorid);
const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, spacetype, colorid);
return ((float)cp[0]);
}
int UI_GetThemeValueType(int colorid, int spacetype)
{
const uchar *cp = UI_ThemeGetColorPtr(theme_active, spacetype, colorid);
const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, spacetype, colorid);
return ((int)cp[0]);
}
void UI_GetThemeColor3fv(int colorid, float col[3])
{
const uchar *cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid);
col[0] = ((float)cp[0]) / 255.0f;
col[1] = ((float)cp[1]) / 255.0f;
col[2] = ((float)cp[2]) / 255.0f;
@ -1178,7 +1174,7 @@ void UI_GetThemeColor3fv(int colorid, float col[3])
void UI_GetThemeColor4fv(int colorid, float col[4])
{
const uchar *cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid);
col[0] = ((float)cp[0]) / 255.0f;
col[1] = ((float)cp[1]) / 255.0f;
col[2] = ((float)cp[2]) / 255.0f;
@ -1187,7 +1183,7 @@ void UI_GetThemeColor4fv(int colorid, float col[4])
void UI_GetThemeColorType4fv(int colorid, int spacetype, float col[4])
{
const uchar *cp = UI_ThemeGetColorPtr(theme_active, spacetype, colorid);
const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, spacetype, colorid);
col[0] = ((float)cp[0]) / 255.0f;
col[1] = ((float)cp[1]) / 255.0f;
col[2] = ((float)cp[2]) / 255.0f;
@ -1196,7 +1192,7 @@ void UI_GetThemeColorType4fv(int colorid, int spacetype, float col[4])
void UI_GetThemeColorShade3fv(int colorid, int offset, float col[3])
{
const uchar *cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid);
int r, g, b;
r = offset + (int)cp[0];
@ -1213,7 +1209,7 @@ void UI_GetThemeColorShade3fv(int colorid, int offset, float col[3])
void UI_GetThemeColorShade3ubv(int colorid, int offset, uchar col[3])
{
const uchar *cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid);
int r, g, b;
r = offset + (int)cp[0];
@ -1231,8 +1227,8 @@ void UI_GetThemeColorShade3ubv(int colorid, int offset, uchar col[3])
void UI_GetThemeColorBlendShade3ubv(
int colorid1, int colorid2, float fac, int offset, uchar col[3])
{
const uchar *cp1 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
const uchar *cp2 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
const uchar *cp1 = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid1);
const uchar *cp2 = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid2);
CLAMP(fac, 0.0f, 1.0f);
@ -1246,7 +1242,7 @@ void UI_GetThemeColorBlendShade3ubv(
void UI_GetThemeColorShade4ubv(int colorid, int offset, uchar col[4])
{
const uchar *cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid);
int r, g, b;
r = offset + (int)cp[0];
@ -1264,7 +1260,7 @@ void UI_GetThemeColorShade4ubv(int colorid, int offset, uchar col[4])
void UI_GetThemeColorShadeAlpha4fv(int colorid, int coloffset, int alphaoffset, float col[4])
{
const uchar *cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid);
int r, g, b, a;
r = coloffset + (int)cp[0];
@ -1284,8 +1280,8 @@ void UI_GetThemeColorShadeAlpha4fv(int colorid, int coloffset, int alphaoffset,
void UI_GetThemeColorBlendShade3fv(int colorid1, int colorid2, float fac, int offset, float col[3])
{
const uchar *cp1 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
const uchar *cp2 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
const uchar *cp1 = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid1);
const uchar *cp2 = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid2);
int r, g, b;
CLAMP(fac, 0.0f, 1.0f);
@ -1304,8 +1300,8 @@ void UI_GetThemeColorBlendShade3fv(int colorid1, int colorid2, float fac, int of
void UI_GetThemeColorBlendShade4fv(int colorid1, int colorid2, float fac, int offset, float col[4])
{
const uchar *cp1 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
const uchar *cp2 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
const uchar *cp1 = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid1);
const uchar *cp2 = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid2);
int r, g, b, a;
CLAMP(fac, 0.0f, 1.0f);
@ -1328,7 +1324,7 @@ void UI_GetThemeColorBlendShade4fv(int colorid1, int colorid2, float fac, int of
void UI_GetThemeColor3ubv(int colorid, uchar col[3])
{
const uchar *cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid);
col[0] = cp[0];
col[1] = cp[1];
col[2] = cp[2];
@ -1336,7 +1332,7 @@ void UI_GetThemeColor3ubv(int colorid, uchar col[3])
void UI_GetThemeColorShade4fv(int colorid, int offset, float col[4])
{
const uchar *cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid);
int r, g, b, a;
r = offset + (int)cp[0];
@ -1357,7 +1353,7 @@ void UI_GetThemeColorShade4fv(int colorid, int offset, float col[4])
void UI_GetThemeColor4ubv(int colorid, uchar col[4])
{
const uchar *cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid);
col[0] = cp[0];
col[1] = cp[1];
col[2] = cp[2];
@ -1366,7 +1362,7 @@ void UI_GetThemeColor4ubv(int colorid, uchar col[4])
void UI_GetThemeColorType3fv(int colorid, int spacetype, float col[3])
{
const uchar *cp = UI_ThemeGetColorPtr(theme_active, spacetype, colorid);
const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, spacetype, colorid);
col[0] = ((float)cp[0]) / 255.0f;
col[1] = ((float)cp[1]) / 255.0f;
col[2] = ((float)cp[2]) / 255.0f;
@ -1374,7 +1370,7 @@ void UI_GetThemeColorType3fv(int colorid, int spacetype, float col[3])
void UI_GetThemeColorType3ubv(int colorid, int spacetype, uchar col[3])
{
const uchar *cp = UI_ThemeGetColorPtr(theme_active, spacetype, colorid);
const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, spacetype, colorid);
col[0] = cp[0];
col[1] = cp[1];
col[2] = cp[2];
@ -1382,7 +1378,7 @@ void UI_GetThemeColorType3ubv(int colorid, int spacetype, uchar col[3])
void UI_GetThemeColorType4ubv(int colorid, int spacetype, uchar col[4])
{
const uchar *cp = UI_ThemeGetColorPtr(theme_active, spacetype, colorid);
const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, spacetype, colorid);
col[0] = cp[0];
col[1] = cp[1];
col[2] = cp[2];
@ -1397,16 +1393,19 @@ bool UI_GetIconThemeColor4ubv(int colorid, uchar col[4])
if (colorid == TH_ICON_FUND) {
/* Always color development fund icon. */
}
else if (!((theme_spacetype == SPACE_OUTLINER && theme_regionid == RGN_TYPE_WINDOW) ||
(theme_spacetype == SPACE_PROPERTIES && theme_regionid == RGN_TYPE_NAV_BAR) ||
(theme_spacetype == SPACE_FILE && theme_regionid == RGN_TYPE_WINDOW))) {
else if (!((g_theme_state.spacetype == SPACE_OUTLINER &&
g_theme_state.regionid == RGN_TYPE_WINDOW) ||
(g_theme_state.spacetype == SPACE_PROPERTIES &&
g_theme_state.regionid == RGN_TYPE_NAV_BAR) ||
(g_theme_state.spacetype == SPACE_FILE &&
g_theme_state.regionid == RGN_TYPE_WINDOW))) {
/* Only colored icons in specific places, overall UI is intended
* to stay monochrome and out of the way except a few places where it
* is important to communicate different data types. */
return false;
}
const uchar *cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid);
col[0] = cp[0];
col[1] = cp[1];
col[2] = cp[2];