Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/resources.c
| Show First 20 Lines • Show All 1,029 Lines • ▼ Show 20 Lines | else { | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return (const uchar *)cp; | return (const uchar *)cp; | ||||
| } | } | ||||
| /** | |||||
| * Initialize default theme. | |||||
| * | |||||
| * \note When you add new colors, created & saved themes need initialized | |||||
| * use function below, #init_userdef_do_versions. | |||||
| */ | |||||
| void UI_theme_init_default(void) | void UI_theme_init_default(void) | ||||
| { | { | ||||
| /* we search for the theme with name Default */ | /* we search for the theme with name Default */ | ||||
| bTheme *btheme = BLI_findstring(&U.themes, "Default", offsetof(bTheme, name)); | bTheme *btheme = BLI_findstring(&U.themes, "Default", offsetof(bTheme, name)); | ||||
| if (btheme == NULL) { | if (btheme == NULL) { | ||||
| btheme = MEM_callocN(sizeof(bTheme), __func__); | btheme = MEM_callocN(sizeof(bTheme), __func__); | ||||
| BLI_addtail(&U.themes, btheme); | BLI_addtail(&U.themes, btheme); | ||||
| } | } | ||||
| Show All 34 Lines | void UI_SetTheme(int spacetype, int regionid) | ||||
| } | } | ||||
| } | } | ||||
| bTheme *UI_GetTheme(void) | bTheme *UI_GetTheme(void) | ||||
| { | { | ||||
| return U.themes.first; | return U.themes.first; | ||||
| } | } | ||||
| /** | |||||
| * For the rare case we need to temp swap in a different theme (off-screen render). | |||||
| */ | |||||
| void UI_Theme_Store(struct bThemeState *theme_state) | void UI_Theme_Store(struct bThemeState *theme_state) | ||||
| { | { | ||||
| *theme_state = g_theme_state; | *theme_state = g_theme_state; | ||||
| } | } | ||||
| void UI_Theme_Restore(struct bThemeState *theme_state) | void UI_Theme_Restore(struct bThemeState *theme_state) | ||||
| { | { | ||||
| g_theme_state = *theme_state; | g_theme_state = *theme_state; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | |||||
| void UI_FontThemeColor(int fontid, int colorid) | void UI_FontThemeColor(int fontid, int colorid) | ||||
| { | { | ||||
| uchar color[4]; | uchar color[4]; | ||||
| UI_GetThemeColor4ubv(colorid, color); | UI_GetThemeColor4ubv(colorid, color); | ||||
| BLF_color4ubv(fontid, color); | BLF_color4ubv(fontid, color); | ||||
| } | } | ||||
| /* get individual values, not scaled */ | |||||
| float UI_GetThemeValuef(int colorid) | float UI_GetThemeValuef(int colorid) | ||||
| { | { | ||||
| const uchar *cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid); | const uchar *cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid); | ||||
| return ((float)cp[0]); | return ((float)cp[0]); | ||||
| } | } | ||||
| /* get individual values, not scaled */ | |||||
| int UI_GetThemeValue(int colorid) | int UI_GetThemeValue(int colorid) | ||||
| { | { | ||||
| const uchar *cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid); | const uchar *cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid); | ||||
| return ((int)cp[0]); | return ((int)cp[0]); | ||||
| } | } | ||||
| /* versions of the function above, which take a space-type */ | |||||
| float UI_GetThemeValueTypef(int colorid, int spacetype) | float UI_GetThemeValueTypef(int colorid, int spacetype) | ||||
| { | { | ||||
| const uchar *cp = UI_ThemeGetColorPtr(theme_active, spacetype, colorid); | const uchar *cp = UI_ThemeGetColorPtr(theme_active, spacetype, colorid); | ||||
| return ((float)cp[0]); | return ((float)cp[0]); | ||||
| } | } | ||||
| int UI_GetThemeValueType(int colorid, int spacetype) | int UI_GetThemeValueType(int colorid, int spacetype) | ||||
| { | { | ||||
| const uchar *cp = UI_ThemeGetColorPtr(theme_active, spacetype, colorid); | const uchar *cp = UI_ThemeGetColorPtr(theme_active, spacetype, colorid); | ||||
| return ((int)cp[0]); | return ((int)cp[0]); | ||||
| } | } | ||||
| /* get the color, range 0.0-1.0 */ | |||||
| void UI_GetThemeColor3fv(int colorid, float col[3]) | void UI_GetThemeColor3fv(int colorid, float col[3]) | ||||
| { | { | ||||
| const uchar *cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid); | const uchar *cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid); | ||||
| col[0] = ((float)cp[0]) / 255.0f; | col[0] = ((float)cp[0]) / 255.0f; | ||||
| col[1] = ((float)cp[1]) / 255.0f; | col[1] = ((float)cp[1]) / 255.0f; | ||||
| col[2] = ((float)cp[2]) / 255.0f; | col[2] = ((float)cp[2]) / 255.0f; | ||||
| } | } | ||||
| Show All 10 Lines | |||||
| { | { | ||||
| const uchar *cp = UI_ThemeGetColorPtr(theme_active, spacetype, colorid); | const uchar *cp = UI_ThemeGetColorPtr(theme_active, spacetype, colorid); | ||||
| col[0] = ((float)cp[0]) / 255.0f; | col[0] = ((float)cp[0]) / 255.0f; | ||||
| col[1] = ((float)cp[1]) / 255.0f; | col[1] = ((float)cp[1]) / 255.0f; | ||||
| col[2] = ((float)cp[2]) / 255.0f; | col[2] = ((float)cp[2]) / 255.0f; | ||||
| col[3] = ((float)cp[3]) / 255.0f; | col[3] = ((float)cp[3]) / 255.0f; | ||||
| } | } | ||||
| /* get the color, range 0.0-1.0, complete with shading offset */ | |||||
| void UI_GetThemeColorShade3fv(int colorid, int offset, float col[3]) | 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(theme_active, theme_spacetype, colorid); | ||||
| int r, g, b; | int r, g, b; | ||||
| r = offset + (int)cp[0]; | r = offset + (int)cp[0]; | ||||
| CLAMP(r, 0, 255); | CLAMP(r, 0, 255); | ||||
| g = offset + (int)cp[1]; | g = offset + (int)cp[1]; | ||||
| ▲ Show 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | void UI_GetThemeColorBlendShade4fv(int colorid1, int colorid2, float fac, int offset, float col[4]) | ||||
| CLAMP(a, 0, 255); | CLAMP(a, 0, 255); | ||||
| col[0] = ((float)r) / 255.0f; | col[0] = ((float)r) / 255.0f; | ||||
| col[1] = ((float)g) / 255.0f; | col[1] = ((float)g) / 255.0f; | ||||
| col[2] = ((float)b) / 255.0f; | col[2] = ((float)b) / 255.0f; | ||||
| col[3] = ((float)a) / 255.0f; | col[3] = ((float)a) / 255.0f; | ||||
| } | } | ||||
| /* get the color, in char pointer */ | |||||
| void UI_GetThemeColor3ubv(int colorid, uchar col[3]) | void UI_GetThemeColor3ubv(int colorid, uchar col[3]) | ||||
| { | { | ||||
| const uchar *cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid); | const uchar *cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid); | ||||
| col[0] = cp[0]; | col[0] = cp[0]; | ||||
| col[1] = cp[1]; | col[1] = cp[1]; | ||||
| col[2] = cp[2]; | col[2] = cp[2]; | ||||
| } | } | ||||
| /* get the color, range 0.0-1.0, complete with shading offset */ | |||||
| void UI_GetThemeColorShade4fv(int colorid, int offset, float col[4]) | 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(theme_active, theme_spacetype, colorid); | ||||
| int r, g, b, a; | int r, g, b, a; | ||||
| r = offset + (int)cp[0]; | r = offset + (int)cp[0]; | ||||
| CLAMP(r, 0, 255); | CLAMP(r, 0, 255); | ||||
| g = offset + (int)cp[1]; | g = offset + (int)cp[1]; | ||||
| CLAMP(g, 0, 255); | CLAMP(g, 0, 255); | ||||
| b = offset + (int)cp[2]; | b = offset + (int)cp[2]; | ||||
| CLAMP(b, 0, 255); | CLAMP(b, 0, 255); | ||||
| a = (int)cp[3]; /* no shading offset... */ | a = (int)cp[3]; /* no shading offset... */ | ||||
| CLAMP(a, 0, 255); | CLAMP(a, 0, 255); | ||||
| col[0] = ((float)r) / 255.0f; | col[0] = ((float)r) / 255.0f; | ||||
| col[1] = ((float)g) / 255.0f; | col[1] = ((float)g) / 255.0f; | ||||
| col[2] = ((float)b) / 255.0f; | col[2] = ((float)b) / 255.0f; | ||||
| col[3] = ((float)a) / 255.0f; | col[3] = ((float)a) / 255.0f; | ||||
| } | } | ||||
| /* get the color, in char pointer */ | |||||
| void UI_GetThemeColor4ubv(int colorid, uchar 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(theme_active, theme_spacetype, colorid); | ||||
| col[0] = cp[0]; | col[0] = cp[0]; | ||||
| col[1] = cp[1]; | col[1] = cp[1]; | ||||
| col[2] = cp[2]; | col[2] = cp[2]; | ||||
| col[3] = cp[3]; | col[3] = cp[3]; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | void UI_GetColorPtrShade3ubv(const uchar cp[3], uchar col[3], int offset) | ||||
| CLAMP(g, 0, 255); | CLAMP(g, 0, 255); | ||||
| CLAMP(b, 0, 255); | CLAMP(b, 0, 255); | ||||
| col[0] = r; | col[0] = r; | ||||
| col[1] = g; | col[1] = g; | ||||
| col[2] = b; | col[2] = b; | ||||
| } | } | ||||
| /* get a 3 byte color, blended and shaded between two other char color pointers */ | |||||
| void UI_GetColorPtrBlendShade3ubv( | void UI_GetColorPtrBlendShade3ubv( | ||||
| const uchar cp1[3], const uchar cp2[3], uchar col[3], float fac, int offset) | const uchar cp1[3], const uchar cp2[3], uchar col[3], float fac, int offset) | ||||
| { | { | ||||
| int r, g, b; | int r, g, b; | ||||
| CLAMP(fac, 0.0f, 1.0f); | CLAMP(fac, 0.0f, 1.0f); | ||||
| r = offset + floor((1.0f - fac) * cp1[0] + fac * cp2[0]); | r = offset + floor((1.0f - fac) * cp1[0] + fac * cp2[0]); | ||||
| g = offset + floor((1.0f - fac) * cp1[1] + fac * cp2[1]); | g = offset + floor((1.0f - fac) * cp1[1] + fac * cp2[1]); | ||||
| ▲ Show 20 Lines • Show All 47 Lines • Show Last 20 Lines | |||||