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)
This commit is contained in:
Ton Roosendaal 2012-12-18 19:35:54 +00:00
parent edf826d924
commit 8168fba972
8 changed files with 65 additions and 40 deletions

@ -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/bmonofont.ttf")
data_to_c_simple("release/datafiles/splash.png") 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/prvicons.png")
data_to_c_simple("release/datafiles/brushicons/add.png") data_to_c_simple("release/datafiles/brushicons/add.png")

Binary file not shown.

After

Width:  |  Height:  |  Size: 216 KiB

Before

Width:  |  Height:  |  Size: 539 KiB

After

Width:  |  Height:  |  Size: 539 KiB

@ -46,7 +46,8 @@ if(WITH_BLENDER)
# images # images
data_to_c_simple(../../../../release/datafiles/splash.png SRC) 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) data_to_c_simple(../../../../release/datafiles/prvicons.png SRC)
# brushes # brushes

@ -40,7 +40,8 @@ sources.extend((
os.path.join(env['DATA_SOURCES'], "bmonofont.ttf.c"), os.path.join(env['DATA_SOURCES'], "bmonofont.ttf.c"),
os.path.join(env['DATA_SOURCES'], "splash.png.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'], "prvicons.png.c"),
os.path.join(env['DATA_SOURCES'], "startup.blend.c"), os.path.join(env['DATA_SOURCES'], "startup.blend.c"),

@ -36,8 +36,11 @@
extern int datatoc_startup_blend_size; extern int datatoc_startup_blend_size;
extern char datatoc_startup_blend[]; extern char datatoc_startup_blend[];
extern int datatoc_blender_icons_png_size; extern int datatoc_blender_icons16_png_size;
extern char datatoc_blender_icons_png[]; 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 int datatoc_prvicons_png_size;
extern char datatoc_prvicons_png[]; extern char datatoc_prvicons_png[];

@ -511,13 +511,15 @@ static void init_brush_icons(void)
static void init_internal_icons(void) static void init_internal_icons(void)
{ {
bTheme *btheme = UI_GetTheme(); // bTheme *btheme = UI_GetTheme();
ImBuf *bbuf = NULL; ImBuf *b16buf = NULL, *b32buf = NULL;
int x, y, icontype; int x, y, icontype;
char iconfilestr[FILE_MAX];
#if 0 // temp disabled
if ((btheme != NULL) && btheme->tui.iconfile[0]) { if ((btheme != NULL) && btheme->tui.iconfile[0]) {
char *icondir = BLI_get_folder(BLENDER_DATAFILES, "icons"); char *icondir = BLI_get_folder(BLENDER_DATAFILES, "icons");
char iconfilestr[FILE_MAX];
if (icondir) { if (icondir) {
BLI_join_dirfile(iconfilestr, sizeof(iconfilestr), icondir, btheme->tui.iconfile); 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 */ 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__); printf("%s: 'icons' data path not found, continuing\n", __func__);
} }
} }
if (bbuf == NULL) #endif
bbuf = IMB_ibImageFromMemory((unsigned char *)datatoc_blender_icons_png, if (b16buf == NULL)
datatoc_blender_icons_png_size, IB_rect, NULL, "<blender icons>"); b16buf = IMB_ibImageFromMemory((unsigned char *)datatoc_blender_icons16_png,
datatoc_blender_icons16_png_size, IB_rect, NULL, "<blender icons>");
if (bbuf) { if (b32buf == NULL)
b32buf = IMB_ibImageFromMemory((unsigned char *)datatoc_blender_icons32_png,
datatoc_blender_icons32_png_size, IB_rect, NULL, "<blender icons>");
if (b16buf && b32buf) {
/* free existing texture if any */ /* free existing texture if any */
if (icongltex.id) { if (icongltex.id) {
glDeleteTextures(1, &icongltex.id); glDeleteTextures(1, &icongltex.id);
@ -547,17 +554,29 @@ static void init_internal_icons(void)
glGenTextures(1, &icongltex.id); glGenTextures(1, &icongltex.id);
if (icongltex.id) { if (icongltex.id) {
icongltex.w = bbuf->x; int level = 2;
icongltex.h = bbuf->y;
icongltex.invw = 1.0f / bbuf->x; icongltex.w = b32buf->x;
icongltex.invh = 1.0f / bbuf->y; icongltex.h = b32buf->y;
icongltex.invw = 1.0f / b32buf->x;
icongltex.invh = 1.0f / b32buf->y;
glBindTexture(GL_TEXTURE_2D, icongltex.id); 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); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, b32buf->x, b32buf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, b32buf->rect);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 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); glBindTexture(GL_TEXTURE_2D, 0);
if (glGetError() == GL_OUT_OF_MEMORY) { if (glGetError() == GL_OUT_OF_MEMORY) {
glDeleteTextures(1, &icongltex.id); glDeleteTextures(1, &icongltex.id);
icongltex.id = 0; icongltex.id = 0;
@ -571,10 +590,10 @@ static void init_internal_icons(void)
else else
icontype = ICON_TYPE_BUFFER; icontype = ICON_TYPE_BUFFER;
if (bbuf) { if (b16buf) {
for (y = 0; y < ICON_GRID_ROWS; y++) { for (y = 0; y < ICON_GRID_ROWS; y++) {
for (x = 0; x < ICON_GRID_COLS; x++) { 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, x * (ICON_GRID_W + ICON_GRID_MARGIN) + ICON_GRID_MARGIN,
y * (ICON_GRID_H + ICON_GRID_MARGIN) + ICON_GRID_MARGIN, ICON_GRID_W, y * (ICON_GRID_H + ICON_GRID_MARGIN) + ICON_GRID_MARGIN, ICON_GRID_W,
icontype); icontype);
@ -593,7 +612,9 @@ static void init_internal_icons(void)
def_internal_vicon(VICO_X_VEC, vicon_x_draw); def_internal_vicon(VICO_X_VEC, vicon_x_draw);
def_internal_vicon(VICO_SMALL_TRI_RIGHT_VEC, vicon_small_tri_right_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 */ #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 */ /* first allocate imbuf for scaling and copy preview into it */
ima = IMB_allocImBuf(rw, rh, 32, IB_rect); ima = IMB_allocImBuf(rw, rh, 32, IB_rect);
memcpy(ima->rect, rect, rw * rh * sizeof(unsigned int)); 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; rect = ima->rect;
} }

@ -874,13 +874,9 @@ static void widget_draw_icon(uiBut *but, BIFIconID icon, float alpha, const rcti
/* this icon doesn't need draw... */ /* this icon doesn't need draw... */
if (icon == ICON_BLANK1 && (but->flag & UI_ICON_SUBMENU) == 0) return; if (icon == ICON_BLANK1 && (but->flag & UI_ICON_SUBMENU) == 0) return;
/* XXX remove hack when new icons are made */ aspect = but->block->aspect / UI_DPI_FAC;
if ( icon == ICON_LAYER_ACTIVE || icon == ICON_LAYER_USED) height = ICON_DEFAULT_HEIGHT / aspect;
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;
/* calculate blend color */ /* calculate blend color */
if (ELEM4(but->type, TOG, ROW, TOGN, LISTROW)) { if (ELEM4(but->type, TOG, ROW, TOGN, LISTROW)) {
if (but->flag & UI_SELECT) {} 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); glEnable(GL_BLEND);
if (icon && icon != ICON_BLANK1) { if (icon && icon != ICON_BLANK1) {
float ofs = 1.0f / aspect;
if (but->flag & UI_ICON_LEFT) { if (but->flag & UI_ICON_LEFT) {
if (but->type == BUT_TOGDUAL) { if (but->type == BUT_TOGDUAL) {
if (but->drawstr[0]) { if (but->drawstr[0]) {
xs = rect->xmin - 1.0f * aspect; xs = rect->xmin - ofs;
} }
else { else {
xs = (rect->xmin + rect->xmax - height) / 2.0f; 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) { else if (but->block->flag & UI_BLOCK_LOOP) {
if (but->type == SEARCH_MENU) if (but->type == SEARCH_MENU)
xs = rect->xmin + 4.0f * aspect; xs = rect->xmin + 4.0f * ofs;
else else
xs = rect->xmin + 1.0f * aspect; xs = rect->xmin + ofs;
} }
else if ((but->type == ICONROW) || (but->type == ICONTEXTROW)) { else if ((but->type == ICONROW) || (but->type == ICONTEXTROW)) {
xs = rect->xmin + 3.0f * aspect; xs = rect->xmin + 3.0f * ofs;
} }
else { else {
xs = rect->xmin + 4.0f * aspect; xs = rect->xmin + 4.0f * ofs;
} }
ys = (rect->ymin + rect->ymax - height) / 2.0f; 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 */ /* to indicate draggable */
if (but->dragpoin && (but->flag & UI_ACTIVE)) { if (but->dragpoin && (but->flag & UI_ACTIVE)) {
float rgb[3] = {1.25f, 1.25f, 1.25f}; 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 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)) { if (ui_but_draw_menu_icon(but)) {
xs = rect->xmax - UI_DPI_ICON_SIZE - aspect; xs = rect->xmax - UI_DPI_ICON_SIZE - aspect;
ys = (rect->ymin + rect->ymax - height) / 2.0f; 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); glDisable(GL_BLEND);