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
diff options
context:
space:
mode:
authorAndrea Weikert <elubie@gmx.net>2005-12-22 01:21:43 +0300
committerAndrea Weikert <elubie@gmx.net>2005-12-22 01:21:43 +0300
commit80eb4d3b9e851c19638599b1821a083dc5a2f635 (patch)
treebfb42679c33f19c498d3f682924ffc3e40a5d482 /source/blender/blenkernel
parent15766e1612040c41ed66fe618af1d28ab3c6d1ec (diff)
Big commit in orange: Interface icons for materials, textures
world and lamp. Also for images in pupmenus. Also preparation for work on using preview images in imagebrowser. -- Andrea
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/BKE_icons.h75
-rw-r--r--source/blender/blenkernel/SConscript1
-rw-r--r--source/blender/blenkernel/intern/icons.c197
-rw-r--r--source/blender/blenkernel/intern/image.c3
-rw-r--r--source/blender/blenkernel/intern/library.c16
-rw-r--r--source/blender/blenkernel/intern/material.c4
-rw-r--r--source/blender/blenkernel/intern/object.c4
-rw-r--r--source/blender/blenkernel/intern/texture.c3
-rw-r--r--source/blender/blenkernel/intern/world.c3
9 files changed, 306 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_icons.h b/source/blender/blenkernel/BKE_icons.h
new file mode 100644
index 00000000000..315c7dc7a53
--- /dev/null
+++ b/source/blender/blenkernel/BKE_icons.h
@@ -0,0 +1,75 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. The Blender
+ * Foundation also sells licenses for use in proprietary software under
+ * the Blender License. See http://www.blender.org/BL/ for information
+ * about this.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL/BL DUAL LICENSE BLOCK *****
+ */
+
+#ifndef BKE_ICONS_H
+#define BKE_ICONS_H
+
+/*
+ Resizable Icons for Blender
+*/
+
+typedef void (*DrawInfoFreeFP) (void *drawinfo);
+
+struct Icon
+{
+ void *drawinfo;
+ void *obj;
+ short type;
+ short changed;
+ DrawInfoFreeFP drawinfo_free;
+};
+
+typedef struct Icon Icon;
+
+void BKE_icons_init(int first_dyn_id);
+
+/* return icon id for library object or create new icon if not found */
+int BKE_icon_getid(struct ID* id);
+
+/* retrieve icon for id */
+struct Icon* BKE_icon_get(int icon_id);
+
+/* set icon for id if not already defined */
+/* used for inserting the internal icons */
+void BKE_icon_set(int icon_id, struct Icon* icon);
+
+/* remove icon and free date if library object becomes invalid */
+void BKE_icon_delete(struct ID* id);
+
+/* report changes - icon needs to be recalculated */
+void BKE_icon_changed(int icon_id);
+
+/* free all icons */
+void BKE_icons_free();
+
+
+#endif /* BKE_ICONS_H */
diff --git a/source/blender/blenkernel/SConscript b/source/blender/blenkernel/SConscript
index 11baca6ffca..7d1b45f69f1 100644
--- a/source/blender/blenkernel/SConscript
+++ b/source/blender/blenkernel/SConscript
@@ -8,6 +8,7 @@ source_files = ['intern/constraint.c',
'intern/depsgraph.c',
'intern/DerivedMesh.c',
'intern/group.c',
+ 'intern/icons.c',
'intern/material.c',
'intern/sca.c',
'intern/world.c',
diff --git a/source/blender/blenkernel/intern/icons.c b/source/blender/blenkernel/intern/icons.c
new file mode 100644
index 00000000000..ca0a81b063c
--- /dev/null
+++ b/source/blender/blenkernel/intern/icons.c
@@ -0,0 +1,197 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. The Blender
+ * Foundation also sells licenses for use in proprietary software under
+ * the Blender License. See http://www.blender.org/BL/ for information
+ * about this.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL/BL DUAL LICENSE BLOCK *****
+ */
+
+#include <math.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_ID.h"
+
+#include "BLI_ghash.h"
+
+#include "BKE_icons.h"
+
+#define GS(a) (*((short *)(a)))
+
+/* GLOBALS */
+
+static GHash* gIcons = 0;
+
+static int gNextIconId = 1;
+
+static int gFirstIconId = 1;
+
+
+static void icon_free(void *val)
+{
+ Icon* icon = val;
+
+ if (icon)
+ {
+ if (icon->drawinfo_free) {
+ icon->drawinfo_free(icon->drawinfo);
+ }
+ else if (icon->drawinfo) {
+ MEM_freeN(icon->drawinfo);
+ }
+ MEM_freeN(icon);
+ }
+}
+
+/* create an id for a new icon and make sure that ids from deleted icons get reused
+ after the integer number range is used up */
+static int get_next_free_id()
+{
+ int startId = gFirstIconId;
+
+ /* if we haven't used up the int number range, we just return the next int */
+ if (gNextIconId>=gFirstIconId)
+ return gNextIconId++;
+
+ /* now we try to find the smallest icon id not stored in the gIcons hash */
+ while (BLI_ghash_lookup(gIcons, (void *)startId) && startId>=gFirstIconId)
+ startId++;
+
+ /* if we found a suitable one that isnt used yet, return it */
+ if (startId>=gFirstIconId)
+ return startId;
+
+ /* fail */
+ return 0;
+}
+
+void BKE_icons_init(int first_dyn_id)
+{
+ gNextIconId = first_dyn_id;
+ gFirstIconId = first_dyn_id;
+
+ if (!gIcons)
+ gIcons = BLI_ghash_new(BLI_ghashutil_inthash, BLI_ghashutil_intcmp);
+}
+
+void BKE_icons_free()
+{
+ BLI_ghash_free(gIcons, 0, icon_free);
+ gIcons = 0;
+}
+
+
+void BKE_icon_changed(int id)
+{
+ Icon* icon = 0;
+
+ if (!id) return;
+
+ icon = BLI_ghash_lookup(gIcons, (void *)id);
+
+ if (icon)
+ {
+ icon->changed = 1;
+ }
+}
+
+int BKE_icon_getid(struct ID* id)
+{
+ Icon* new_icon = 0;
+
+ if (!id)
+ return 0;
+
+ if (id->icon_id)
+ return id->icon_id;
+
+ id->icon_id = get_next_free_id();
+
+ if (!id->icon_id){
+ printf("BKE_icon_getid: Internal error - not enough IDs\n");
+ return 0;
+ }
+
+ new_icon = MEM_callocN(sizeof(Icon), "texicon");
+
+ new_icon->obj = id;
+ new_icon->type = GS(id->name);
+
+ /* next two lines make sure image gets created */
+ new_icon->drawinfo = 0;
+ new_icon->drawinfo_free = 0;
+ new_icon->changed = 1;
+
+ BLI_ghash_insert(gIcons, (void *)id->icon_id, new_icon);
+
+ return id->icon_id;
+}
+
+Icon* BKE_icon_get(int icon_id)
+{
+ Icon* icon = 0;
+
+ icon = BLI_ghash_lookup(gIcons, (void*)icon_id);
+
+ if (!icon) {
+ printf("BKE_icon_get: Internal error, no icon for icon ID: %d\n", icon_id);
+ return 0;
+ }
+
+ return icon;
+}
+
+void BKE_icon_set(int icon_id, struct Icon* icon)
+{
+ Icon* old_icon = 0;
+
+ old_icon = BLI_ghash_lookup(gIcons, (void*)icon_id);
+
+ if (old_icon)
+ {
+ printf("BKE_icon_set: Internal error, icon already set: %d\n", icon_id);
+ return;
+ }
+
+ BLI_ghash_insert(gIcons, (void *)icon_id, icon);
+}
+
+void BKE_icon_delete(struct ID* id)
+{
+ Icon* new_icon = 0;
+
+ if (!id->icon_id) return; /* no icon defined for library object */
+
+ BLI_ghash_remove(gIcons, (void*)id->icon_id, 0, icon_free);
+ id->icon_id = 0;
+}
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index c09f68643ce..151f818250d 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -61,6 +61,7 @@
#include "BKE_library.h"
#include "BKE_global.h"
#include "BKE_main.h"
+#include "BKE_icons.h"
#include "BKE_image.h"
#include "BKE_scene.h"
#include "BKE_texture.h"
@@ -103,6 +104,8 @@ void free_image(Image *ima)
freePackedFile(ima->packedfile);
ima->packedfile = NULL;
}
+ BKE_icon_delete(ima);
+ ima->id.icon_id = 0;
}
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index 2dad108e320..ad41e9a7fb7 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -93,6 +93,7 @@
#include "BKE_text.h"
#include "BKE_texture.h"
#include "BKE_scene.h"
+#include "BKE_icons.h"
#include "BKE_image.h"
#include "BKE_ipo.h"
#include "BKE_key.h"
@@ -334,6 +335,7 @@ void *alloc_libblock(ListBase *lb, short type, char *name)
if(id) {
BLI_addtail(lb, id);
id->us= 1;
+ id->icon_id = 0;
*( (short *)id->name )= type;
new_id(lb, id, name);
/* alphabetic insterion: is in new_id */
@@ -573,6 +575,20 @@ static void IDnames_to_dyn_pupstring(DynStr *pupds, ListBase *lb, ID *link, shor
sprintf(buf, "%%x%d", i+1);
BLI_dynstr_append(pupds, buf);
+ switch(GS(id->name))
+ {
+ case ID_MA: /* fall through */
+ case ID_TE: /* fall through */
+ case ID_IM: /* fall through */
+ case ID_WO: /* fall through */
+ case ID_LA: /* fall through */
+ sprintf(buf, "%%i%d", BKE_icon_getid(id) );
+ BLI_dynstr_append(pupds, buf);
+ break;
+ default:
+ break;
+ }
+
if(id->next)
BLI_dynstr_append(pupds, "|");
}
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index b0c57eef25d..47b3f1e34ea 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -50,6 +50,7 @@
#include "BKE_blender.h"
#include "BKE_displist.h"
#include "BKE_global.h"
+#include "BKE_icons.h"
#include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_material.h"
@@ -76,6 +77,9 @@ void free_material(Material *ma)
if(ma->ramp_col) MEM_freeN(ma->ramp_col);
if(ma->ramp_spec) MEM_freeN(ma->ramp_spec);
+ BKE_icon_delete((struct ID*)ma);
+ ma->id.icon_id = 0;
+
for(ml= ma->layers.first; ml; ml= ml->next)
if(ml->mat) ml->mat->id.us--;
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 68eebdbee7d..49b73cff77c 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -91,6 +91,7 @@
#include "BKE_displist.h"
#include "BKE_effect.h"
#include "BKE_group.h"
+#include "BKE_icons.h"
#include "BKE_ipo.h"
#include "BKE_key.h"
#include "BKE_lattice.h"
@@ -674,6 +675,9 @@ void free_lamp(Lamp *la)
if(mtex) MEM_freeN(mtex);
}
la->ipo= 0;
+
+ BKE_icon_delete(la);
+ la->id.icon_id = 0;
}
void *add_wave()
diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c
index a228e3cad04..7873340f7d8 100644
--- a/source/blender/blenkernel/intern/texture.c
+++ b/source/blender/blenkernel/intern/texture.c
@@ -74,6 +74,7 @@
#include "BKE_material.h"
#include "BKE_texture.h"
#include "BKE_key.h"
+#include "BKE_icons.h"
#include "BKE_ipo.h"
@@ -336,6 +337,8 @@ void free_texture(Tex *tex)
free_plugin_tex(tex->plugin);
if(tex->coba) MEM_freeN(tex->coba);
if(tex->env) RE_free_envmap(tex->env);
+ BKE_icon_delete((struct ID*)tex);
+ tex->id.icon_id = 0;
}
/* ------------------------------------------------------------------------- */
diff --git a/source/blender/blenkernel/intern/world.c b/source/blender/blenkernel/intern/world.c
index 9f46b697cab..1f71b01d33a 100644
--- a/source/blender/blenkernel/intern/world.c
+++ b/source/blender/blenkernel/intern/world.c
@@ -55,6 +55,7 @@
#include "BKE_world.h"
#include "BKE_global.h"
#include "BKE_main.h"
+#include "BKE_icons.h"
#include "BPY_extern.h"
@@ -75,6 +76,8 @@ void free_world(World *wrld)
if(mtex) MEM_freeN(mtex);
}
wrld->ipo= 0;
+ BKE_icon_delete((struct ID*)wrld);
+ wrld->id.icon_id = 0;
}