[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [10730] trunk/blender/source/blender:
Brecht Van Lommel
brechtvanlommel at pandora.be
Thu May 17 19:15:26 CEST 2007
Revision: 10730
https://svn.blender.org//revision/?rev=10730&view=rev
Author: blendix
Date: 2007-05-17 19:15:22 +0200 (Thu, 17 May 2007)
Log Message:
-----------
Added highlighting of non-existant names and autocomplete for
specifying the uv layer name in a material.
Also added generic autocomplete_begin/do_name/end functions,
this code was copied five times.
Modified Paths:
--------------
trunk/blender/source/blender/include/BIF_interface.h
trunk/blender/source/blender/src/buttons_editing.c
trunk/blender/source/blender/src/buttons_object.c
trunk/blender/source/blender/src/buttons_shading.c
trunk/blender/source/blender/src/interface.c
Modified: trunk/blender/source/blender/include/BIF_interface.h
===================================================================
--- trunk/blender/source/blender/include/BIF_interface.h 2007-05-17 16:51:09 UTC (rev 10729)
+++ trunk/blender/source/blender/include/BIF_interface.h 2007-05-17 17:15:22 UTC (rev 10730)
@@ -36,6 +36,7 @@
struct ID;
struct ListBase;
struct ScrArea;
+struct AutoComplete;
/* uiBlock->dt */
#define UI_EMBOSS 0 /* use one of the themes for drawing */
@@ -319,5 +320,11 @@
void shade_buttons_change_3d(void);
+typedef struct AutoComplete AutoComplete;
+
+AutoComplete *autocomplete_begin(char *startname, int maxlen);
+void autocomplete_do_name(AutoComplete *autocpl, const char *name);
+void autocomplete_end(AutoComplete *autocpl, char *autoname);
+
#endif /* BIF_INTERFACE_H */
Modified: trunk/blender/source/blender/src/buttons_editing.c
===================================================================
--- trunk/blender/source/blender/src/buttons_editing.c 2007-05-17 16:51:09 UTC (rev 10729)
+++ trunk/blender/source/blender/src/buttons_editing.c 2007-05-17 17:15:22 UTC (rev 10730)
@@ -1179,72 +1179,31 @@
/* autocomplete callback for ID buttons */
void autocomplete_image(char *str, void *arg_v)
{
- char truncate[40] = {0};
-
/* search if str matches the beginning of an ID struct */
if(str[0]) {
+ AutoComplete *autocpl = autocomplete_begin(str, 22);
ID *id;
- for(id = G.main->image.first; id; id = id->next) {
- int a;
+ for(id = G.main->image.first; id; id = id->next)
+ autocomplete_do_name(autocpl, id->name+2);
- for(a = 0; a < 24 - 2; a++) {
- if(str[a] == 0 || str[a] != id->name[a + 2])
- break;
- }
- /* found a match */
- if(str[a] == 0) {
- /* first match */
- if(truncate[0] == 0)
- BLI_strncpy(truncate, id->name + 2, 24);
- else {
- /* remove from truncate what is not in id->name */
- for(a = 0; a < 23; a++) {
- if(truncate[a] != id->name[a])
- truncate[a] = 0;
- }
- }
- }
- }
- if(truncate[0])
- BLI_strncpy(str, truncate, 24);
+ autocomplete_end(autocpl, str);
}
}
/* autocomplete callback for ID buttons */
void autocomplete_meshob(char *str, void *arg_v)
{
- char truncate[40] = {0};
-
/* search if str matches the beginning of an ID struct */
if(str[0]) {
+ AutoComplete *autocpl = autocomplete_begin(str, 22);
ID *id;
- for(id = G.main->object.first; id; id = id->next) {
- int a;
+ for(id = G.main->object.first; id; id = id->next)
+ if(((Object *)id)->type == OB_MESH)
+ autocomplete_do_name(autocpl, id->name+2);
- if(((Object *)id)->type != OB_MESH) continue;
-
- for(a = 0; a < 24 - 2; a++) {
- if(str[a] == 0 || str[a] != id->name[a + 2])
- break;
- }
- /* found a match */
- if(str[a] == 0) {
- /* first match */
- if(truncate[0] == 0)
- BLI_strncpy(truncate, id->name + 2, 24);
- else {
- /* remove from truncate what is not in id->name */
- for(a = 0; a < 23; a++) {
- if(truncate[a] != id->name[a])
- truncate[a] = 0;
- }
- }
- }
- }
- if(truncate[0])
- BLI_strncpy(str, truncate, 24);
+ autocomplete_end(autocpl, str);
}
}
@@ -3740,38 +3699,18 @@
/* autocomplete callback for editbones */
static void autocomplete_editbone(char *str, void *arg_v)
{
- char truncate[40]= {0};
-
if(G.obedit==NULL) return;
/* search if str matches the beginning of an ID struct */
if(str[0]) {
+ AutoComplete *autocpl= autocomplete_begin(str, 32);
EditBone *ebone;
- for (ebone=G.edbo.first; ebone; ebone=ebone->next) {
- int a;
- if(ebone->name==str) continue;
-
- for(a=0; a<31; a++) {
- if(str[a]==0 || str[a]!=ebone->name[a])
- break;
- }
- /* found a match */
- if(str[a]==0) {
- /* first match */
- if(truncate[0]==0)
- BLI_strncpy(truncate, ebone->name, 32);
- else {
- /* remove from truncate what is not in bone->name */
- for(a=0; a<31; a++) {
- if(truncate[a] && truncate[a]!=ebone->name[a])
- truncate[a]= 0;
- }
- }
- }
- }
- if(truncate[0])
- BLI_strncpy(str, truncate, 32);
+ for (ebone=G.edbo.first; ebone; ebone=ebone->next)
+ if(ebone->name!=str)
+ autocomplete_do_name(autocpl, ebone->name);
+
+ autocomplete_end(autocpl, str);
}
}
Modified: trunk/blender/source/blender/src/buttons_object.c
===================================================================
--- trunk/blender/source/blender/src/buttons_object.c 2007-05-17 16:51:09 UTC (rev 10729)
+++ trunk/blender/source/blender/src/buttons_object.c 2007-05-17 17:15:22 UTC (rev 10730)
@@ -473,37 +473,18 @@
void autocomplete_bone(char *str, void *arg_v)
{
Object *ob= (Object *)arg_v;
- char truncate[40]= {0};
if(ob==NULL || ob->pose==NULL) return;
/* search if str matches the beginning of name */
if(str[0]) {
+ AutoComplete *autocpl= autocomplete_begin(str, 32);
bPoseChannel *pchan;
- for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
- int a;
-
- for(a=0; a<31; a++) {
- if(str[a]==0 || str[a]!=pchan->name[a])
- break;
- }
- /* found a match */
- if(str[a]==0) {
- /* first match */
- if(truncate[0]==0)
- BLI_strncpy(truncate, pchan->name, 32);
- else {
- /* remove from truncate what is not in bone->name */
- for(a=0; a<31; a++) {
- if(truncate[a]!=pchan->name[a])
- truncate[a]= 0;
- }
- }
- }
- }
- if(truncate[0])
- BLI_strncpy(str, truncate, 32);
+ for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next)
+ autocomplete_do_name(autocpl, pchan->name);
+
+ autocomplete_end(autocpl, str);
}
}
@@ -511,38 +492,19 @@
void autocomplete_vgroup(char *str, void *arg_v)
{
Object *ob= (Object *)arg_v;
- char truncate[40]= {0};
if(ob==NULL) return;
/* search if str matches the beginning of a name */
if(str[0]) {
+ AutoComplete *autocpl= autocomplete_begin(str, 32);
bDeformGroup *dg;
- for(dg= ob->defbase.first; dg; dg= dg->next) {
- int a;
- if(dg->name==str) continue;
-
- for(a=0; a<31; a++) {
- if(str[a]==0 || str[a]!=dg->name[a])
- break;
- }
- /* found a match */
- if(str[a]==0) {
- /* first match */
- if(truncate[0]==0)
- BLI_strncpy(truncate, dg->name, 32);
- else {
- /* remove from truncate what is not in bone->name */
- for(a=0; a<31; a++) {
- if(truncate[a]!=dg->name[a])
- truncate[a]= 0;
- }
- }
- }
- }
- if(truncate[0])
- BLI_strncpy(str, truncate, 32);
+ for(dg= ob->defbase.first; dg; dg= dg->next)
+ if(dg->name!=str)
+ autocomplete_do_name(autocpl, dg->name);
+
+ autocomplete_end(autocpl, str);
}
}
Modified: trunk/blender/source/blender/src/buttons_shading.c
===================================================================
--- trunk/blender/source/blender/src/buttons_shading.c 2007-05-17 16:51:09 UTC (rev 10729)
+++ trunk/blender/source/blender/src/buttons_shading.c 2007-05-17 17:15:22 UTC (rev 10730)
@@ -43,9 +43,11 @@
#include "DNA_brush_types.h"
#include "DNA_curve_types.h"
+#include "DNA_customdata_types.h"
#include "DNA_image_types.h"
#include "DNA_lamp_types.h"
#include "DNA_material_types.h"
+#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
#include "DNA_node_types.h"
@@ -3019,10 +3021,51 @@
uiDefButF(block, NUMSLI, B_MATPRV, "fac ", 195,10,115,19, &(mtex->warpfac), 0.0, 1.0, 0, 0, "Sets the amount the texture affects texture coordinates of next channels");
}
+/* autocomplete callback for buttons */
+static void autocomplete_uv(char *str, void *arg_v)
+{
+ Mesh *me;
+ CustomDataLayer *layer;
+ AutoComplete *autocpl;
+ int a;
+ if(str[0]==0)
+ return;
+
+ autocpl= autocomplete_begin(str, 32);
+
+ /* search if str matches the beginning of name */
+ for(me= G.main->mesh.first; me; me=me->id.next)
+ for(a=0, layer= me->fdata.layers; a<me->fdata.totlayer; a++, layer++)
+ if(layer->type == CD_MTFACE)
+ autocomplete_do_name(autocpl, layer->name);
+
+ autocomplete_end(autocpl, str);
+}
+
+static int verify_valid_uv_name(char *str)
+{
+ Mesh *me;
+ CustomDataLayer *layer;
+ int a;
+
+ if(str[0]==0)
+ return 1;
+
+ /* search if str matches the name */
+ for(me= G.main->mesh.first; me; me=me->id.next)
+ for(a=0, layer= me->fdata.layers; a<me->fdata.totlayer; a++, layer++)
+ if(layer->type == CD_MTFACE)
+ if(strcmp(layer->name, str)==0)
+ return 1;
+
+ return 0;
+}
+
static void material_panel_map_input(Object *ob, Material *ma)
{
uiBlock *block;
+ uiBut *but;
MTex *mtex;
int b;
@@ -3042,8 +3085,13 @@
uiBlockBeginAlign(block);
uiDefButS(block, ROW, B_MATPRV, "Glob", 630,180,45,18, &(mtex->texco), 4.0, (float)TEXCO_GLOB, 0, 0, "Uses global coordinates for the texture coordinates");
uiDefButS(block, ROW, B_MATPRV, "Object", 675,180,75,18, &(mtex->texco), 4.0, (float)TEXCO_OBJECT, 0, 0, "Uses linked object's coordinates for texture coordinates");
- if(mtex->texco == TEXCO_UV)
- uiDefBut(block, TEX, B_MATPRV, "UV:", 750,180,158,18, mtex->uvname, 0, 31, 0, 0, "Set name of UV layer to use, default is active UV layer");
+ if(mtex->texco == TEXCO_UV) {
+ if(!verify_valid_uv_name(mtex->uvname))
+ uiBlockSetCol(block, TH_REDALERT);
+ but=uiDefBut(block, TEX, B_MATPRV, "UV:", 750,180,158,18, mtex->uvname, 0, 31, 0, 0, "Set name of UV layer to use, default is active UV layer");
+ uiButSetCompleteFunc(but, autocomplete_uv, NULL);
+ uiBlockSetCol(block, TH_AUTO);
+ }
else
uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_MATPRV, "Ob:",750,180,158,18, &(mtex->object), "");
Modified: trunk/blender/source/blender/src/interface.c
===================================================================
--- trunk/blender/source/blender/src/interface.c 2007-05-17 16:51:09 UTC (rev 10729)
+++ trunk/blender/source/blender/src/interface.c 2007-05-17 17:15:22 UTC (rev 10730)
@@ -5932,42 +5932,78 @@
}
}
+/* autocomplete helper functions */
+struct AutoComplete {
+ int maxlen;
+ char *truncate;
+ char *startname;
+};
+
+AutoComplete *autocomplete_begin(char *startname, int maxlen)
+{
+ AutoComplete *autocpl;
+
+ autocpl= MEM_callocN(sizeof(AutoComplete), "AutoComplete");
+ autocpl->maxlen= maxlen;
+ autocpl->truncate= MEM_callocN(sizeof(char)*maxlen, "AutoCompleteTruncate");
+ autocpl->startname= startname;
+
+ return autocpl;
+}
+
+void autocomplete_do_name(AutoComplete *autocpl, const char *name)
+{
+ char *truncate= autocpl->truncate;
+ char *startname= autocpl->startname;
+ int a;
+
+ for(a=0; a<autocpl->maxlen-1; a++) {
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list