From 8168fba97213d985669a6cc37c477590a6b45d01 Mon Sep 17 00:00:00 2001 From: Ton Roosendaal Date: Tue, 18 Dec 2012 19:35:54 +0000 Subject: Icons now draw good again! - Exported via Inkscape a 16 and 32 pixel bitmap version - Use these as mipmap levels for OpenGL texture drawing. - Changed code to get right sizes for drawing icons - better than last week's method. Todo: - Custom icons don't work yet (old one) - Missing icons in the svg - The .sh script for inkscape needs changed to support this (now do manual saving) --- SConstruct | 3 +- release/datafiles/blender_icons.png | Bin 551824 -> 0 bytes release/datafiles/blender_icons16.png | Bin 0 -> 221713 bytes release/datafiles/blender_icons32.png | Bin 0 -> 551824 bytes source/blender/editors/datafiles/CMakeLists.txt | 3 +- source/blender/editors/datafiles/SConscript | 3 +- source/blender/editors/include/ED_datafiles.h | 7 ++- source/blender/editors/interface/interface_icons.c | 61 ++++++++++++++------- .../blender/editors/interface/interface_widgets.c | 28 +++++----- 9 files changed, 65 insertions(+), 40 deletions(-) delete mode 100644 release/datafiles/blender_icons.png create mode 100644 release/datafiles/blender_icons16.png create mode 100644 release/datafiles/blender_icons32.png diff --git a/SConstruct b/SConstruct index 97d4a334d5c..4630b7b8c87 100644 --- a/SConstruct +++ b/SConstruct @@ -532,7 +532,8 @@ data_to_c_simple("release/datafiles/bfont.ttf") data_to_c_simple("release/datafiles/bmonofont.ttf") data_to_c_simple("release/datafiles/splash.png") -data_to_c_simple("release/datafiles/blender_icons.png") +data_to_c_simple("release/datafiles/blender_icons16.png") +data_to_c_simple("release/datafiles/blender_icons32.png") data_to_c_simple("release/datafiles/prvicons.png") data_to_c_simple("release/datafiles/brushicons/add.png") diff --git a/release/datafiles/blender_icons.png b/release/datafiles/blender_icons.png deleted file mode 100644 index 18926a75f9f..00000000000 Binary files a/release/datafiles/blender_icons.png and /dev/null differ diff --git a/release/datafiles/blender_icons16.png b/release/datafiles/blender_icons16.png new file mode 100644 index 00000000000..81e412b8062 Binary files /dev/null and b/release/datafiles/blender_icons16.png differ diff --git a/release/datafiles/blender_icons32.png b/release/datafiles/blender_icons32.png new file mode 100644 index 00000000000..18926a75f9f Binary files /dev/null and b/release/datafiles/blender_icons32.png differ diff --git a/source/blender/editors/datafiles/CMakeLists.txt b/source/blender/editors/datafiles/CMakeLists.txt index ec20e2d3d09..6d6b7ecdd82 100644 --- a/source/blender/editors/datafiles/CMakeLists.txt +++ b/source/blender/editors/datafiles/CMakeLists.txt @@ -46,7 +46,8 @@ if(WITH_BLENDER) # images data_to_c_simple(../../../../release/datafiles/splash.png SRC) - data_to_c_simple(../../../../release/datafiles/blender_icons.png SRC) + data_to_c_simple(../../../../release/datafiles/blender_icons16.png SRC) + data_to_c_simple(../../../../release/datafiles/blender_icons32.png SRC) data_to_c_simple(../../../../release/datafiles/prvicons.png SRC) # brushes diff --git a/source/blender/editors/datafiles/SConscript b/source/blender/editors/datafiles/SConscript index fcc610eeee1..cb6fe11dbb2 100644 --- a/source/blender/editors/datafiles/SConscript +++ b/source/blender/editors/datafiles/SConscript @@ -40,7 +40,8 @@ sources.extend(( os.path.join(env['DATA_SOURCES'], "bmonofont.ttf.c"), os.path.join(env['DATA_SOURCES'], "splash.png.c"), - os.path.join(env['DATA_SOURCES'], "blender_icons.png.c"), + os.path.join(env['DATA_SOURCES'], "blender_icons16.png.c"), + os.path.join(env['DATA_SOURCES'], "blender_icons32.png.c"), os.path.join(env['DATA_SOURCES'], "prvicons.png.c"), os.path.join(env['DATA_SOURCES'], "startup.blend.c"), diff --git a/source/blender/editors/include/ED_datafiles.h b/source/blender/editors/include/ED_datafiles.h index 8ad36397ce5..6d7bcecc630 100644 --- a/source/blender/editors/include/ED_datafiles.h +++ b/source/blender/editors/include/ED_datafiles.h @@ -36,8 +36,11 @@ extern int datatoc_startup_blend_size; extern char datatoc_startup_blend[]; -extern int datatoc_blender_icons_png_size; -extern char datatoc_blender_icons_png[]; +extern int datatoc_blender_icons16_png_size; +extern char datatoc_blender_icons16_png[]; + +extern int datatoc_blender_icons32_png_size; +extern char datatoc_blender_icons32_png[]; extern int datatoc_prvicons_png_size; extern char datatoc_prvicons_png[]; diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c index 1369f399c89..2dc77e96678 100644 --- a/source/blender/editors/interface/interface_icons.c +++ b/source/blender/editors/interface/interface_icons.c @@ -511,13 +511,15 @@ static void init_brush_icons(void) static void init_internal_icons(void) { - bTheme *btheme = UI_GetTheme(); - ImBuf *bbuf = NULL; +// bTheme *btheme = UI_GetTheme(); + ImBuf *b16buf = NULL, *b32buf = NULL; int x, y, icontype; - char iconfilestr[FILE_MAX]; - + +#if 0 // temp disabled if ((btheme != NULL) && btheme->tui.iconfile[0]) { char *icondir = BLI_get_folder(BLENDER_DATAFILES, "icons"); + char iconfilestr[FILE_MAX]; + if (icondir) { BLI_join_dirfile(iconfilestr, sizeof(iconfilestr), icondir, btheme->tui.iconfile); bbuf = IMB_loadiffname(iconfilestr, IB_rect, NULL); /* if the image is missing bbuf will just be NULL */ @@ -531,11 +533,16 @@ static void init_internal_icons(void) printf("%s: 'icons' data path not found, continuing\n", __func__); } } - if (bbuf == NULL) - bbuf = IMB_ibImageFromMemory((unsigned char *)datatoc_blender_icons_png, - datatoc_blender_icons_png_size, IB_rect, NULL, ""); +#endif + if (b16buf == NULL) + b16buf = IMB_ibImageFromMemory((unsigned char *)datatoc_blender_icons16_png, + datatoc_blender_icons16_png_size, IB_rect, NULL, ""); - if (bbuf) { + if (b32buf == NULL) + b32buf = IMB_ibImageFromMemory((unsigned char *)datatoc_blender_icons32_png, + datatoc_blender_icons32_png_size, IB_rect, NULL, ""); + + if (b16buf && b32buf) { /* free existing texture if any */ if (icongltex.id) { glDeleteTextures(1, &icongltex.id); @@ -547,17 +554,29 @@ static void init_internal_icons(void) glGenTextures(1, &icongltex.id); if (icongltex.id) { - icongltex.w = bbuf->x; - icongltex.h = bbuf->y; - icongltex.invw = 1.0f / bbuf->x; - icongltex.invh = 1.0f / bbuf->y; + int level = 2; + + icongltex.w = b32buf->x; + icongltex.h = b32buf->y; + icongltex.invw = 1.0f / b32buf->x; + icongltex.invh = 1.0f / b32buf->y; glBindTexture(GL_TEXTURE_2D, icongltex.id); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bbuf->x, bbuf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, bbuf->rect); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, b32buf->x, b32buf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, b32buf->rect); + glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, b16buf->x, b16buf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, b16buf->rect); + + while (b16buf->x > 1) { + b16buf = IMB_onehalf(b16buf); + glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, b16buf->x, b16buf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, b16buf->rect); + level++; + } + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glBindTexture(GL_TEXTURE_2D, 0); - + if (glGetError() == GL_OUT_OF_MEMORY) { glDeleteTextures(1, &icongltex.id); icongltex.id = 0; @@ -571,10 +590,10 @@ static void init_internal_icons(void) else icontype = ICON_TYPE_BUFFER; - if (bbuf) { + if (b16buf) { for (y = 0; y < ICON_GRID_ROWS; y++) { for (x = 0; x < ICON_GRID_COLS; x++) { - def_internal_icon(bbuf, BIFICONID_FIRST + y * ICON_GRID_COLS + x, + def_internal_icon(b32buf, BIFICONID_FIRST + y * ICON_GRID_COLS + x, x * (ICON_GRID_W + ICON_GRID_MARGIN) + ICON_GRID_MARGIN, y * (ICON_GRID_H + ICON_GRID_MARGIN) + ICON_GRID_MARGIN, ICON_GRID_W, icontype); @@ -593,7 +612,9 @@ static void init_internal_icons(void) def_internal_vicon(VICO_X_VEC, vicon_x_draw); def_internal_vicon(VICO_SMALL_TRI_RIGHT_VEC, vicon_small_tri_right_draw); - IMB_freeImBuf(bbuf); + IMB_freeImBuf(b16buf); + IMB_freeImBuf(b32buf); + } #endif /* WITH_HEADLESS */ @@ -887,7 +908,7 @@ static void icon_draw_rect(float x, float y, int w, int h, float UNUSED(aspect), /* first allocate imbuf for scaling and copy preview into it */ ima = IMB_allocImBuf(rw, rh, 32, IB_rect); memcpy(ima->rect, rect, rw * rh * sizeof(unsigned int)); - IMB_scalefastImBuf(ima, w, h); /* scale it */ + IMB_scaleImBuf(ima, w, h); /* scale it */ rect = ima->rect; } diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index 9f125b39c23..f003889464e 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -874,13 +874,9 @@ static void widget_draw_icon(uiBut *but, BIFIconID icon, float alpha, const rcti /* this icon doesn't need draw... */ if (icon == ICON_BLANK1 && (but->flag & UI_ICON_SUBMENU) == 0) return; - /* XXX remove hack when new icons are made */ - if ( icon == ICON_LAYER_ACTIVE || icon == ICON_LAYER_USED) - height = 1.2f * BLI_rcti_size_y(rect); else - /* icons are 80% of height of button (16 pixels inside 20 height) */ - height = 0.8f * BLI_rcti_size_y(rect); - aspect = height / ICON_DEFAULT_HEIGHT; - + aspect = but->block->aspect / UI_DPI_FAC; + height = ICON_DEFAULT_HEIGHT / aspect; + /* calculate blend color */ if (ELEM4(but->type, TOG, ROW, TOGN, LISTROW)) { if (but->flag & UI_SELECT) {} @@ -894,10 +890,12 @@ static void widget_draw_icon(uiBut *but, BIFIconID icon, float alpha, const rcti glEnable(GL_BLEND); if (icon && icon != ICON_BLANK1) { + float ofs = 1.0f / aspect; + if (but->flag & UI_ICON_LEFT) { if (but->type == BUT_TOGDUAL) { if (but->drawstr[0]) { - xs = rect->xmin - 1.0f * aspect; + xs = rect->xmin - ofs; } else { xs = (rect->xmin + rect->xmax - height) / 2.0f; @@ -905,15 +903,15 @@ static void widget_draw_icon(uiBut *but, BIFIconID icon, float alpha, const rcti } else if (but->block->flag & UI_BLOCK_LOOP) { if (but->type == SEARCH_MENU) - xs = rect->xmin + 4.0f * aspect; + xs = rect->xmin + 4.0f * ofs; else - xs = rect->xmin + 1.0f * aspect; + xs = rect->xmin + ofs; } else if ((but->type == ICONROW) || (but->type == ICONTEXTROW)) { - xs = rect->xmin + 3.0f * aspect; + xs = rect->xmin + 3.0f * ofs; } else { - xs = rect->xmin + 4.0f * aspect; + xs = rect->xmin + 4.0f * ofs; } ys = (rect->ymin + rect->ymax - height) / 2.0f; } @@ -925,17 +923,17 @@ static void widget_draw_icon(uiBut *but, BIFIconID icon, float alpha, const rcti /* to indicate draggable */ if (but->dragpoin && (but->flag & UI_ACTIVE)) { float rgb[3] = {1.25f, 1.25f, 1.25f}; - UI_icon_draw_aspect_color(xs, ys, icon, 1.0f / aspect, rgb); + UI_icon_draw_aspect_color(xs, ys, icon, aspect, rgb); } else - UI_icon_draw_aspect(xs, ys, icon, 1.0f / aspect, alpha); + UI_icon_draw_aspect(xs, ys, icon, aspect, alpha); } if (ui_but_draw_menu_icon(but)) { xs = rect->xmax - UI_DPI_ICON_SIZE - aspect; ys = (rect->ymin + rect->ymax - height) / 2.0f; - UI_icon_draw_aspect(xs, ys, ICON_RIGHTARROW_THIN, 1.0f / aspect, alpha); + UI_icon_draw_aspect(xs, ys, ICON_RIGHTARROW_THIN, aspect, alpha); } glDisable(GL_BLEND); -- cgit v1.2.3