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:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2007-05-17 21:15:22 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2007-05-17 21:15:22 +0400
commit53b434919b769ff49c30642d5f93023c8a267e42 (patch)
tree5b1d1233400385cfe9c891bcfa6b925ad76fcd2e
parent33466557fcfab8e54447c5a5362f141dea90ee06 (diff)
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.
-rw-r--r--source/blender/include/BIF_interface.h7
-rw-r--r--source/blender/src/buttons_editing.c91
-rw-r--r--source/blender/src/buttons_object.c60
-rw-r--r--source/blender/src/buttons_shading.c52
-rw-r--r--source/blender/src/interface.c84
5 files changed, 143 insertions, 151 deletions
diff --git a/source/blender/include/BIF_interface.h b/source/blender/include/BIF_interface.h
index e8d25cfd14f..ad2c8988343 100644
--- a/source/blender/include/BIF_interface.h
+++ b/source/blender/include/BIF_interface.h
@@ -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 @@ extern void *uiSetCurFont_ext(float aspect);
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 */
diff --git a/source/blender/src/buttons_editing.c b/source/blender/src/buttons_editing.c
index 80dd4a034c7..3760b17f039 100644
--- a/source/blender/src/buttons_editing.c
+++ b/source/blender/src/buttons_editing.c
@@ -1179,72 +1179,31 @@ static void modifier_testImage(char *name, ID **idpp)
/* 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;
-
- if(((Object *)id)->type != OB_MESH) continue;
+ for(id = G.main->object.first; id; id = id->next)
+ if(((Object *)id)->type == OB_MESH)
+ 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);
}
}
@@ -3740,38 +3699,18 @@ static void editing_panel_armature_visuals(Object *ob, bArmature *arm)
/* 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);
}
}
diff --git a/source/blender/src/buttons_object.c b/source/blender/src/buttons_object.c
index 07e57762db2..e47a80fe9fa 100644
--- a/source/blender/src/buttons_object.c
+++ b/source/blender/src/buttons_object.c
@@ -473,37 +473,18 @@ static void constraint_moveDown(void *ob_v, void *con_v)
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_bone(char *str, void *arg_v)
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);
}
}
diff --git a/source/blender/src/buttons_shading.c b/source/blender/src/buttons_shading.c
index 0d1a783ddea..0ae601c074b 100644
--- a/source/blender/src/buttons_shading.c
+++ b/source/blender/src/buttons_shading.c
@@ -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 @@ static void material_panel_map_to(Material *ma, int from_nodes)
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 @@ static void material_panel_map_input(Object *ob, Material *ma)
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), "");
diff --git a/source/blender/src/interface.c b/source/blender/src/interface.c
index 60a5a59643d..56e2c6326b7 100644
--- a/source/blender/src/interface.c
+++ b/source/blender/src/interface.c
@@ -5932,42 +5932,78 @@ static int findBitIndex(unsigned int x) {
}
}
+/* 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++) {
+ if(startname[a]==0 || startname[a]!=name[a])
+ break;
+ }
+ /* found a match */
+ if(startname[a]==0) {
+ /* first match */
+ if(truncate[0]==0)
+ BLI_strncpy(truncate, name, autocpl->maxlen);
+ else {
+ /* remove from truncate what is not in bone->name */
+ for(a=0; a<autocpl->maxlen-1; a++) {
+ if(truncate[a]!=name[a])
+ truncate[a]= 0;
+ }
+ }
+ }
+}
+
+void autocomplete_end(AutoComplete *autocpl, char *autoname)
+{
+ if(autocpl->truncate[0])
+ BLI_strncpy(autoname, autocpl->truncate, autocpl->maxlen);
+ else
+ BLI_strncpy(autoname, autocpl->startname, autocpl->maxlen);
+
+ MEM_freeN(autocpl->truncate);
+ MEM_freeN(autocpl);
+}
+
/* autocomplete callback for ID buttons */
static void autocomplete_id(char *str, void *arg_v)
{
int blocktype= (long)arg_v;
ListBase *listb= wich_libbase(G.main, blocktype);
- char truncate[32]= {0};
if(listb==NULL) return;
/* search if str matches the beginning of an ID struct */
if(str[0]) {
+ AutoComplete *autocpl= autocomplete_begin(str, 22);
ID *id;
- for(id= listb->first; id; id= id->next) {
- int a;
-
- for(a=0; a<21; 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)
- strcpy(truncate, id->name+2);
- else {
- /* remove from truncate what is not in id->name */
- for(a=0; a<21; a++) {
- if(truncate[a]!=id->name[a+2])
- truncate[a]= 0;
- }
- }
- }
- }
- if(truncate[0])
- BLI_strncpy(str, truncate, 21);
+ for(id= listb->first; id; id= id->next)
+ autocomplete_do_name(autocpl, id->name+2);
+
+ autocomplete_end(autocpl, str);
}
}