[Bf-blender-cvs] [ed6e1381dc2] master: Cleanup: Avoid using macros to refer to theme global variables
Hans Goudey
noreply at git.blender.org
Sat Nov 26 00:46:56 CET 2022
Commit: ed6e1381dc285e6d0f9acc90422029c0524603b4
Author: Hans Goudey
Date: Fri Nov 25 17:11:44 2022 -0600
Branches: master
https://developer.blender.org/rBed6e1381dc285e6d0f9acc90422029c0524603b4
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.
===================================================================
M source/blender/editors/interface/resources.c
===================================================================
diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c
index 93b94d42d39..f6cd65fc6da 100644
--- a/source/blender/editors/interface/resources.c
+++ b/source/blender/editors/interface/resources.c
@@ -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, i
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list