Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorAndrea Weikert <elubie@gmx.net>2011-05-16 22:37:54 +0400
committerAndrea Weikert <elubie@gmx.net>2011-05-16 22:37:54 +0400
commit079caae727e56e2070f0d63aa030753f4ba1cbcd (patch)
tree199c09967469cad050d8cd9769a1d07055a51570 /source
parent4023427fe0df2afad4f18d74cb790a5b9f2f51a3 (diff)
code cleanup: icon creation
* changed stupid miplevel/MIPMAP naming in icon code, it was really the icon size (small icon or larger preview) that was meant there.
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/intern/icons.c8
-rw-r--r--source/blender/blenloader/intern/readfile.c2
-rw-r--r--source/blender/editors/interface/interface_icons.c76
-rw-r--r--source/blender/editors/space_file/filelist.c6
-rw-r--r--source/blender/makesdna/DNA_ID.h10
5 files changed, 53 insertions, 49 deletions
diff --git a/source/blender/blenkernel/intern/icons.c b/source/blender/blenkernel/intern/icons.c
index 09c189a8847..18eda831c47 100644
--- a/source/blender/blenkernel/intern/icons.c
+++ b/source/blender/blenkernel/intern/icons.c
@@ -125,7 +125,7 @@ struct PreviewImage* BKE_previewimg_create(void)
prv_img = MEM_callocN(sizeof(PreviewImage), "img_prv");
- for (i=0; i<PREVIEW_MIPMAPS; ++i) {
+ for (i=0; i<NUM_ICON_SIZES; ++i) {
prv_img->changed[i] = 1;
prv_img->changed_timestamp[i] = 0;
}
@@ -137,7 +137,7 @@ void BKE_previewimg_free(PreviewImage **prv)
if(prv && (*prv)) {
int i;
- for (i=0; i<PREVIEW_MIPMAPS;++i) {
+ for (i=0; i<NUM_ICON_SIZES;++i) {
if ((*prv)->rect[i]) {
MEM_freeN((*prv)->rect[i]);
(*prv)->rect[i] = NULL;
@@ -155,7 +155,7 @@ struct PreviewImage* BKE_previewimg_copy(PreviewImage *prv)
if (prv) {
prv_img = MEM_dupallocN(prv);
- for (i=0; i < PREVIEW_MIPMAPS; ++i) {
+ for (i=0; i < NUM_ICON_SIZES; ++i) {
if (prv->rect[i]) {
prv_img->rect[i] = MEM_dupallocN(prv->rect[i]);
} else {
@@ -237,7 +237,7 @@ void BKE_icon_changed(int id)
/* all previews changed */
if (prv) {
int i;
- for (i=0; i<PREVIEW_MIPMAPS; ++i) {
+ for (i=0; i<NUM_ICON_SIZES; ++i) {
prv->changed[i] = 1;
prv->changed_timestamp[i]++;
}
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 5543e842007..d6d9a4c88c9 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -1583,7 +1583,7 @@ static PreviewImage *direct_link_preview_image(FileData *fd, PreviewImage *old_p
if (prv) {
int i;
- for (i=0; i < PREVIEW_MIPMAPS; ++i) {
+ for (i=0; i < NUM_ICON_SIZES; ++i) {
if (prv->rect[i]) {
prv->rect[i] = newdataadr(fd, prv->rect[i]);
}
diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c
index 9507a1a07f4..037cc22f879 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -798,36 +798,39 @@ void UI_icons_init(int first_dyn_id)
init_brush_icons();
}
-/* Render size for preview images at level miplevel */
-static int preview_render_size(int miplevel)
+/* Render size for preview images and icons
+ */
+static int preview_render_size(enum eIconSizes size)
{
- switch (miplevel) {
- case 0: return 32;
- case 1: return PREVIEW_DEFAULT_HEIGHT;
+ switch (size) {
+ case ICON_SIZE_ICON: return 32;
+ case ICON_SIZE_PREVIEW: return PREVIEW_DEFAULT_HEIGHT;
}
return 0;
}
-static void icon_create_mipmap(struct PreviewImage* prv_img, int miplevel)
+/* Create rect for the icon
+ */
+static void icon_create_rect(struct PreviewImage* prv_img, enum eIconSizes size)
{
- unsigned int size = preview_render_size(miplevel);
+ unsigned int render_size = preview_render_size(size);
if (!prv_img) {
if (G.f & G_DEBUG)
printf("Error: requested preview image does not exist");
}
- if (!prv_img->rect[miplevel]) {
- prv_img->w[miplevel] = size;
- prv_img->h[miplevel] = size;
- prv_img->changed[miplevel] = 1;
- prv_img->changed_timestamp[miplevel] = 0;
- prv_img->rect[miplevel] = MEM_callocN(size*size*sizeof(unsigned int), "prv_rect");
+ if (!prv_img->rect[size]) {
+ prv_img->w[size] = render_size;
+ prv_img->h[size] = render_size;
+ prv_img->changed[size] = 1;
+ prv_img->changed_timestamp[size] = 0;
+ prv_img->rect[size] = MEM_callocN(render_size*render_size*sizeof(unsigned int), "prv_rect");
}
}
/* only called when icon has changed */
/* only call with valid pointer from UI_icon_draw */
-static void icon_set_image(bContext *C, ID *id, PreviewImage* prv_img, int miplevel)
+static void icon_set_image(bContext *C, ID *id, PreviewImage* prv_img, enum eIconSizes size)
{
if (!prv_img) {
if (G.f & G_DEBUG)
@@ -835,11 +838,10 @@ static void icon_set_image(bContext *C, ID *id, PreviewImage* prv_img, int miple
return;
}
- /* create the preview rect */
- icon_create_mipmap(prv_img, miplevel);
+ icon_create_rect(prv_img, size);
- ED_preview_icon_job(C, prv_img, id, prv_img->rect[miplevel],
- prv_img->w[miplevel], prv_img->h[miplevel]);
+ ED_preview_icon_job(C, prv_img, id, prv_img->rect[size],
+ prv_img->w[size], prv_img->h[size]);
}
static void icon_draw_rect(float x, float y, int w, int h, float UNUSED(aspect), int rw, int rh, unsigned int *rect, float alpha, float *rgb, short is_preview)
@@ -928,17 +930,17 @@ static void icon_draw_texture(float x, float y, float w, float h, int ix, int iy
glDisable(GL_TEXTURE_2D);
}
-/* Drawing size for preview images at level miplevel */
-static int preview_size(int miplevel)
+/* Drawing size for preview images */
+static int get_draw_size(enum eIconSizes size)
{
- switch (miplevel) {
- case 0: return ICON_DEFAULT_HEIGHT;
- case 1: return PREVIEW_DEFAULT_HEIGHT;
+ switch (size) {
+ case ICON_SIZE_ICON: return ICON_DEFAULT_HEIGHT;
+ case ICON_SIZE_PREVIEW: return PREVIEW_DEFAULT_HEIGHT;
}
return 0;
}
-static void icon_draw_size(float x, float y, int icon_id, float aspect, float alpha, float *rgb, int miplevel, int draw_size, int UNUSED(nocreate), int is_preview)
+static void icon_draw_size(float x, float y, int icon_id, float aspect, float alpha, float *rgb, enum eIconSizes size, int draw_size, int UNUSED(nocreate), int is_preview)
{
Icon *icon = NULL;
DrawInfo *di = NULL;
@@ -988,11 +990,11 @@ static void icon_draw_size(float x, float y, int icon_id, float aspect, float al
if(pi) {
/* no create icon on this level in code */
- if(!pi->rect[miplevel]) return; /* something has gone wrong! */
+ if(!pi->rect[size]) return; /* something has gone wrong! */
/* preview images use premul alpha ... */
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- icon_draw_rect(x, y, w, h, aspect, pi->w[miplevel], pi->h[miplevel], pi->rect[miplevel], 1.0f, NULL, is_preview);
+ icon_draw_rect(x, y, w, h, aspect, pi->w[size], pi->h[size], pi->rect[size], 1.0f, NULL, is_preview);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
}
@@ -1024,7 +1026,7 @@ static void ui_id_brush_render(bContext *C, ID *id)
if(!pi)
return;
- for(i = 0; i < PREVIEW_MIPMAPS; i++) {
+ for(i = 0; i < NUM_ICON_SIZES; i++) {
/* check if rect needs to be created; changed
only set by dynamic icons */
if((pi->changed[i] || !pi->rect[i])) {
@@ -1113,21 +1115,21 @@ int ui_id_icon_get(bContext *C, ID *id, int big)
return iconid;
}
-static void icon_draw_mipmap(float x, float y, int icon_id, float aspect, float alpha, int miplevel, int nocreate)
+static void icon_draw_at_size(float x, float y, int icon_id, float aspect, float alpha, enum eIconSizes size, int nocreate)
{
- int draw_size = preview_size(miplevel);
- icon_draw_size(x, y, icon_id, aspect, alpha, NULL, miplevel, draw_size, nocreate, FALSE);
+ int draw_size = get_draw_size(size);
+ icon_draw_size(x, y, icon_id, aspect, alpha, NULL, size, draw_size, nocreate, FALSE);
}
void UI_icon_draw_aspect(float x, float y, int icon_id, float aspect, float alpha)
{
- icon_draw_mipmap(x, y, icon_id, aspect, alpha, PREVIEW_MIPMAP_ZERO, 0);
+ icon_draw_at_size(x, y, icon_id, aspect, alpha, ICON_SIZE_ICON, 0);
}
void UI_icon_draw_aspect_color(float x, float y, int icon_id, float aspect, float *rgb)
{
- int draw_size = preview_size(PREVIEW_MIPMAP_ZERO);
- icon_draw_size(x, y, icon_id, aspect, 1.0f, rgb, PREVIEW_MIPMAP_ZERO, draw_size, FALSE, FALSE);
+ int draw_size = get_draw_size(ICON_SIZE_ICON);
+ icon_draw_size(x, y, icon_id, aspect, 1.0f, rgb, ICON_SIZE_ICON, draw_size, FALSE, FALSE);
}
void UI_icon_draw(float x, float y, int icon_id)
@@ -1137,21 +1139,21 @@ void UI_icon_draw(float x, float y, int icon_id)
void UI_icon_draw_size(float x, float y, int size, int icon_id, float alpha)
{
- icon_draw_size(x, y, icon_id, 1.0f, alpha, NULL, PREVIEW_MIPMAP_ZERO, size, TRUE, FALSE);
+ icon_draw_size(x, y, icon_id, 1.0f, alpha, NULL, ICON_SIZE_ICON, size, TRUE, FALSE);
}
void UI_icon_draw_preview(float x, float y, int icon_id)
{
- icon_draw_mipmap(x, y, icon_id, 1.0f, 1.0f, PREVIEW_MIPMAP_LARGE, 0);
+ icon_draw_at_size(x, y, icon_id, 1.0f, 1.0f, ICON_SIZE_PREVIEW, 0);
}
void UI_icon_draw_preview_aspect(float x, float y, int icon_id, float aspect)
{
- icon_draw_mipmap(x, y, icon_id, aspect, 1.0f, PREVIEW_MIPMAP_LARGE, 0);
+ icon_draw_at_size(x, y, icon_id, aspect, 1.0f, ICON_SIZE_PREVIEW, 0);
}
void UI_icon_draw_preview_aspect_size(float x, float y, int icon_id, float aspect, int size)
{
- icon_draw_size(x, y, icon_id, aspect, 1.0f, NULL, PREVIEW_MIPMAP_LARGE, size, FALSE, TRUE);
+ icon_draw_size(x, y, icon_id, aspect, 1.0f, NULL, ICON_SIZE_PREVIEW, size, FALSE, TRUE);
}
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index b097ad0f55e..155c19f0763 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -1070,9 +1070,9 @@ void filelist_from_library(struct FileList* filelist)
PreviewImage *img= l->link;
if (img) {
- unsigned int w = img->w[PREVIEW_MIPMAP_LARGE];
- unsigned int h = img->h[PREVIEW_MIPMAP_LARGE];
- unsigned int *rect = img->rect[PREVIEW_MIPMAP_LARGE];
+ unsigned int w = img->w[ICON_SIZE_PREVIEW];
+ unsigned int h = img->h[ICON_SIZE_PREVIEW];
+ unsigned int *rect = img->rect[ICON_SIZE_PREVIEW];
/* first allocate imbuf for copying preview into it */
if (w > 0 && h > 0 && rect) {
diff --git a/source/blender/makesdna/DNA_ID.h b/source/blender/makesdna/DNA_ID.h
index 267283ee47a..d8f254aa187 100644
--- a/source/blender/makesdna/DNA_ID.h
+++ b/source/blender/makesdna/DNA_ID.h
@@ -123,12 +123,14 @@ typedef struct Library {
struct Library *parent; /* set for indirectly linked libs, used in the outliner and while reading */
} Library;
-#define PREVIEW_MIPMAPS 2
-#define PREVIEW_MIPMAP_ZERO 0
-#define PREVIEW_MIPMAP_LARGE 1
+enum eIconSizes {
+ ICON_SIZE_ICON,
+ ICON_SIZE_PREVIEW,
+ NUM_ICON_SIZES
+};
typedef struct PreviewImage {
- /* All values of 2 are really PREVIEW_MIPMAPS */
+ /* All values of 2 are really NUM_ICON_SIZES */
unsigned int w[2];
unsigned int h[2];
short changed[2];