Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/resources.cc
- This file was moved from source/blender/editors/interface/resources.c.
| Context not available. | |||||
| * \ingroup edinterface | * \ingroup edinterface | ||||
| */ | */ | ||||
| #include <math.h> | #include <cmath> | ||||
| #include <stdlib.h> | #include <cstdlib> | ||||
| #include <string.h> | #include <cstring> | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| Context not available. | |||||
| #include "GPU_framebuffer.h" | #include "GPU_framebuffer.h" | ||||
| #include "interface_intern.h" | #include "interface_intern.h" | ||||
| /* global for themes */ | |||||
| typedef void (*VectorDrawFunc)(int x, int y, int w, int h, float alpha); | |||||
| /* be sure to keep 'bThemeState' in sync */ | /* be sure to keep 'bThemeState' in sync */ | ||||
| static struct bThemeState g_theme_state = { | static bThemeState g_theme_state = { | ||||
| NULL, | nullptr, | ||||
| SPACE_VIEW3D, | SPACE_VIEW3D, | ||||
| RGN_TYPE_WINDOW, | RGN_TYPE_WINDOW, | ||||
| }; | }; | ||||
| void ui_resources_init(void) | void ui_resources_init() | ||||
| { | { | ||||
| UI_icons_init(); | UI_icons_init(); | ||||
| } | } | ||||
| void ui_resources_free(void) | void ui_resources_free() | ||||
| { | { | ||||
| UI_icons_free(); | UI_icons_free(); | ||||
| } | } | ||||
| Context not available. | |||||
| const uchar *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid) | const uchar *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid) | ||||
| { | { | ||||
| ThemeSpace *ts = NULL; | ThemeSpace *ts = nullptr; | ||||
| static uchar error[4] = {240, 0, 240, 255}; | static uchar error[4] = {240, 0, 240, 255}; | ||||
| static uchar alert[4] = {240, 60, 60, 255}; | static uchar alert[4] = {240, 60, 60, 255}; | ||||
| static uchar header_active[4] = {0, 0, 0, 255}; | static uchar header_active[4] = {0, 0, 0, 255}; | ||||
| Context not available. | |||||
| cp = ts->header; | cp = ts->header; | ||||
| break; | break; | ||||
| case TH_HEADER_ACTIVE: | case TH_HEADER_ACTIVE: { | ||||
| cp = ts->header; | cp = ts->header; | ||||
| const int factor = 5; | const int factor = 5; | ||||
| /* Lighten the header color when editor is active. */ | /* Lighten the header color when editor is active. */ | ||||
| Context not available. | |||||
| header_active[3] = cp[3]; | header_active[3] = cp[3]; | ||||
| cp = header_active; | cp = header_active; | ||||
| break; | break; | ||||
| } | |||||
| case TH_HEADER_TEXT: | case TH_HEADER_TEXT: | ||||
| cp = ts->header_text; | cp = ts->header_text; | ||||
| break; | break; | ||||
| Context not available. | |||||
| return (const uchar *)cp; | return (const uchar *)cp; | ||||
| } | } | ||||
| void UI_theme_init_default(void) | void UI_theme_init_default() | ||||
| { | { | ||||
| /* 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 = static_cast<bTheme *>( | ||||
| if (btheme == NULL) { | BLI_findstring(&U.themes, "Default", offsetof(bTheme, name))); | ||||
| btheme = MEM_callocN(sizeof(bTheme), __func__); | if (btheme == nullptr) { | ||||
| btheme = MEM_cnew<bTheme>(__func__); | |||||
| BLI_addtail(&U.themes, btheme); | BLI_addtail(&U.themes, btheme); | ||||
| } | } | ||||
| Context not available. | |||||
| btheme->active_theme_area = active_theme_area; | btheme->active_theme_area = active_theme_area; | ||||
| } | } | ||||
| void UI_style_init_default(void) | void UI_style_init_default() | ||||
| { | { | ||||
| BLI_freelistN(&U.uistyles); | BLI_freelistN(&U.uistyles); | ||||
| /* gets automatically re-allocated */ | /* gets automatically re-allocated */ | ||||
| Context not available. | |||||
| { | { | ||||
| if (spacetype) { | if (spacetype) { | ||||
| /* later on, a local theme can be found too */ | /* later on, a local theme can be found too */ | ||||
| g_theme_state.theme = U.themes.first; | g_theme_state.theme = static_cast<bTheme *>(U.themes.first); | ||||
| g_theme_state.spacetype = spacetype; | g_theme_state.spacetype = spacetype; | ||||
| g_theme_state.regionid = regionid; | g_theme_state.regionid = regionid; | ||||
| } | } | ||||
| else if (regionid) { | else if (regionid) { | ||||
| /* popups */ | /* popups */ | ||||
| g_theme_state.theme = U.themes.first; | g_theme_state.theme = static_cast<bTheme *>(U.themes.first); | ||||
| g_theme_state.spacetype = SPACE_PROPERTIES; | g_theme_state.spacetype = SPACE_PROPERTIES; | ||||
| g_theme_state.regionid = regionid; | g_theme_state.regionid = regionid; | ||||
| } | } | ||||
| else { | else { | ||||
| /* for safety, when theme was deleted */ | /* for safety, when theme was deleted */ | ||||
| g_theme_state.theme = U.themes.first; | g_theme_state.theme = static_cast<bTheme *>(U.themes.first); | ||||
| g_theme_state.spacetype = SPACE_VIEW3D; | g_theme_state.spacetype = SPACE_VIEW3D; | ||||
| g_theme_state.regionid = RGN_TYPE_WINDOW; | g_theme_state.regionid = RGN_TYPE_WINDOW; | ||||
| } | } | ||||
| } | } | ||||
| bTheme *UI_GetTheme(void) | bTheme *UI_GetTheme() | ||||
| { | { | ||||
| return U.themes.first; | return static_cast<bTheme *>(U.themes.first); | ||||
| } | } | ||||
| void UI_Theme_Store(struct bThemeState *theme_state) | void UI_Theme_Store(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(bThemeState *theme_state) | ||||
| { | { | ||||
| g_theme_state = *theme_state; | g_theme_state = *theme_state; | ||||
| } | } | ||||
| Context not available. | |||||
| { | { | ||||
| int r, g, b, a; | int r, g, b, a; | ||||
| const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid); | const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid); | ||||
| r = coloffset + (int)cp[0]; | r = coloffset + int(cp[0]); | ||||
| CLAMP(r, 0, 255); | CLAMP(r, 0, 255); | ||||
| g = coloffset + (int)cp[1]; | g = coloffset + int(cp[1]); | ||||
| CLAMP(g, 0, 255); | CLAMP(g, 0, 255); | ||||
| b = coloffset + (int)cp[2]; | b = coloffset + int(cp[2]); | ||||
| CLAMP(b, 0, 255); | CLAMP(b, 0, 255); | ||||
| a = alphaoffset + (int)cp[3]; | a = alphaoffset + int(cp[3]); | ||||
| CLAMP(a, 0, 255); | CLAMP(a, 0, 255); | ||||
| col[0] = r; | col[0] = r; | ||||
| Context not available. | |||||
| float UI_GetThemeValuef(int colorid) | float UI_GetThemeValuef(int colorid) | ||||
| { | { | ||||
| const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid); | const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid); | ||||
| return ((float)cp[0]); | return (float(cp[0])); | ||||
| } | } | ||||
| int UI_GetThemeValue(int colorid) | int UI_GetThemeValue(int colorid) | ||||
| { | { | ||||
| const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid); | const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid); | ||||
| return ((int)cp[0]); | return (int(cp[0])); | ||||
| } | } | ||||
| float UI_GetThemeValueTypef(int colorid, int spacetype) | float UI_GetThemeValueTypef(int colorid, int spacetype) | ||||
| { | { | ||||
| const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, spacetype, colorid); | const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, 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(g_theme_state.theme, spacetype, colorid); | const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, spacetype, colorid); | ||||
| return ((int)cp[0]); | return (int(cp[0])); | ||||
| } | } | ||||
| void UI_GetThemeColor3fv(int colorid, float col[3]) | void UI_GetThemeColor3fv(int colorid, float col[3]) | ||||
| { | { | ||||
| const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid); | const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.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; | ||||
| } | } | ||||
| void UI_GetThemeColor4fv(int colorid, float col[4]) | void UI_GetThemeColor4fv(int colorid, float col[4]) | ||||
| { | { | ||||
| const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid); | const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.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; | ||||
| } | } | ||||
| void UI_GetThemeColorType4fv(int colorid, int spacetype, float col[4]) | void UI_GetThemeColorType4fv(int colorid, int spacetype, float col[4]) | ||||
| { | { | ||||
| const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, spacetype, colorid); | const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.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; | ||||
| col[3] = ((float)cp[3]) / 255.0f; | col[3] = (float(cp[3])) / 255.0f; | ||||
| } | } | ||||
| void UI_GetThemeColorShade3fv(int colorid, int offset, float col[3]) | void UI_GetThemeColorShade3fv(int colorid, int offset, float col[3]) | ||||
| Context not available. | |||||
| const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid); | const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.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]); | ||||
| 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); | ||||
| 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; | ||||
| } | } | ||||
| void UI_GetThemeColorShade3ubv(int colorid, int offset, uchar col[3]) | void UI_GetThemeColorShade3ubv(int colorid, int offset, uchar col[3]) | ||||
| Context not available. | |||||
| const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid); | const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.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]); | ||||
| 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); | ||||
| col[0] = r; | col[0] = r; | ||||
| Context not available. | |||||
| const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid); | const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.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]); | ||||
| 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); | ||||
| col[0] = r; | col[0] = r; | ||||
| Context not available. | |||||
| const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid); | const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid); | ||||
| int r, g, b, a; | int r, g, b, a; | ||||
| r = coloffset + (int)cp[0]; | r = coloffset + int(cp[0]); | ||||
| CLAMP(r, 0, 255); | CLAMP(r, 0, 255); | ||||
| g = coloffset + (int)cp[1]; | g = coloffset + int(cp[1]); | ||||
| CLAMP(g, 0, 255); | CLAMP(g, 0, 255); | ||||
| b = coloffset + (int)cp[2]; | b = coloffset + int(cp[2]); | ||||
| CLAMP(b, 0, 255); | CLAMP(b, 0, 255); | ||||
| a = alphaoffset + (int)cp[3]; | a = alphaoffset + int(cp[3]); | ||||
| 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; | ||||
| } | } | ||||
| void UI_GetThemeColorBlendShade3fv(int colorid1, int colorid2, float fac, int offset, float col[3]) | void UI_GetThemeColorBlendShade3fv(int colorid1, int colorid2, float fac, int offset, float col[3]) | ||||
| Context not available. | |||||
| b = offset + floorf((1.0f - fac) * cp1[2] + fac * cp2[2]); | b = offset + floorf((1.0f - fac) * cp1[2] + fac * cp2[2]); | ||||
| CLAMP(b, 0, 255); | CLAMP(b, 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; | ||||
| } | } | ||||
| void UI_GetThemeColorBlendShade4fv(int colorid1, int colorid2, float fac, int offset, float col[4]) | void UI_GetThemeColorBlendShade4fv(int colorid1, int colorid2, float fac, int offset, float col[4]) | ||||
| Context not available. | |||||
| a = floorf((1.0f - fac) * cp1[3] + fac * cp2[3]); /* No shading offset. */ | a = floorf((1.0f - fac) * cp1[3] + fac * cp2[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; | ||||
| } | } | ||||
| void UI_GetThemeColor3ubv(int colorid, uchar col[3]) | void UI_GetThemeColor3ubv(int colorid, uchar col[3]) | ||||
| Context not available. | |||||
| const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.spacetype, colorid); | const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, g_theme_state.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; | ||||
| } | } | ||||
| void UI_GetThemeColor4ubv(int colorid, uchar col[4]) | void UI_GetThemeColor4ubv(int colorid, uchar col[4]) | ||||
| Context not available. | |||||
| void UI_GetThemeColorType3fv(int colorid, int spacetype, float col[3]) | void UI_GetThemeColorType3fv(int colorid, int spacetype, float col[3]) | ||||
| { | { | ||||
| const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.theme, spacetype, colorid); | const uchar *cp = UI_ThemeGetColorPtr(g_theme_state.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; | ||||
| } | } | ||||
| void UI_GetThemeColorType3ubv(int colorid, int spacetype, uchar col[3]) | void UI_GetThemeColorType3ubv(int colorid, int spacetype, uchar col[3]) | ||||
| Context not available. | |||||
| { | { | ||||
| int r, g, b; | int r, g, b; | ||||
| r = offset + (int)cp[0]; | r = offset + int(cp[0]); | ||||
| g = offset + (int)cp[1]; | g = offset + int(cp[1]); | ||||
| b = offset + (int)cp[2]; | b = offset + int(cp[2]); | ||||
| CLAMP(r, 0, 255); | CLAMP(r, 0, 255); | ||||
| CLAMP(g, 0, 255); | CLAMP(g, 0, 255); | ||||
| Context not available. | |||||
| GPU_clear_color(col[0], col[1], col[2], 1.0f); | GPU_clear_color(col[0], col[1], col[2], 1.0f); | ||||
| } | } | ||||
| int UI_ThemeMenuShadowWidth(void) | int UI_ThemeMenuShadowWidth() | ||||
| { | { | ||||
| bTheme *btheme = UI_GetTheme(); | bTheme *btheme = UI_GetTheme(); | ||||
| return (int)(btheme->tui.menu_shadow_width * UI_DPI_FAC); | return int(btheme->tui.menu_shadow_width * UI_DPI_FAC); | ||||
| } | } | ||||
| void UI_make_axis_color(const uchar src_col[3], uchar dst_col[3], const char axis) | void UI_make_axis_color(const uchar src_col[3], uchar dst_col[3], const char axis) | ||||
| Context not available. | |||||