- new menu type; with icon support!

(the one you make with uIDefBut(..., MENU, ...)
  add a %i<nr> to the string, and the item gets <nr> as icon.
- added this to the 'mode' selectors in 3dwin and ipowin
- cleaned up code for modeselector pup... that was a bad ass one! :)
This commit is contained in:
2003-10-25 23:57:58 +00:00
parent f9e231beb0
commit 6da544eeeb
3 changed files with 62 additions and 89 deletions

View File

@@ -447,56 +447,56 @@ static char *ipo_modeselect_pup(void)
char tmpstr[1024];
char formatstring[1024];
strcpy(string, "Display IPO type: %t");
strcpy(string, "Ipo type: %t");
strcpy(formatstring, "|%s %%x%d");
strcpy(formatstring, "|%s %%x%d %%i%d");
if(OBACT) {
sprintf(tmpstr,formatstring,"Object",ID_OB);
sprintf(tmpstr,formatstring,"Object",ID_OB, ICON_OBJECT);
strcat(string,tmpstr);
}
if(OBACT && give_current_material(OBACT, OBACT->actcol)) { // check for material
sprintf(tmpstr,formatstring,"Material",ID_MA);
sprintf(tmpstr,formatstring,"Material",ID_MA, ICON_MATERIAL);
strcat(string,tmpstr);
}
if(G.scene->world) {
sprintf(tmpstr,formatstring,"World",ID_WO);
sprintf(tmpstr,formatstring,"World",ID_WO, ICON_WORLD);
strcat(string,tmpstr);
}
if(OBACT && OBACT->type==OB_CURVE) {
sprintf(tmpstr,formatstring,"Curve",ID_WO);
sprintf(tmpstr,formatstring,"Curve",ID_CU, ICON_CURVE);
strcat(string,tmpstr);
}
if(OBACT && OBACT->type==OB_CAMERA) {
sprintf(tmpstr,formatstring,"Camera",ID_CA);
sprintf(tmpstr,formatstring,"Camera",ID_CA, ICON_CAMERA);
strcat(string,tmpstr);
}
if(OBACT && OBACT->type==OB_LAMP) {
sprintf(tmpstr,formatstring,"Lamp",ID_LA);
sprintf(tmpstr,formatstring,"Lamp",ID_LA, ICON_LAMP);
strcat(string,tmpstr);
}
if(OBACT){
if ELEM4(OBACT->type, OB_MESH, OB_CURVE, OB_SURF, OB_LATTICE) {
sprintf(tmpstr,formatstring,"Vertex",ID_KE);
sprintf(tmpstr,formatstring,"Vertex",ID_KE, ICON_EDIT);
strcat(string,tmpstr);
}
if (OBACT->action){
sprintf(tmpstr,formatstring,"Action",ID_AC);
sprintf(tmpstr,formatstring,"Action",ID_AC, ICON_ACTION);
strcat(string,tmpstr);
}
#ifdef __CON_IPO
sprintf(tmpstr,formatstring,"Constraint",IPO_CO);
sprintf(tmpstr,formatstring,"Constraint",IPO_CO, ICON_CONSTRAINT);
strcat(string,tmpstr);
#endif
}
sprintf(tmpstr,formatstring,"Sequence",ID_SEQ);
sprintf(tmpstr,formatstring,"Sequence",ID_SEQ, ICON_SEQUENCE);
strcat(string,tmpstr);
@@ -628,7 +628,7 @@ void ipo_buttons(void)
uiBlock *block;
short xco,xmax;
char naam[20];
int icon;
int icon=0;
sprintf(naam, "header %d", curarea->headwin);
block= uiNewBlock(&curarea->uiblocks, naam, UI_EMBOSS, UI_HELV, curarea->headwin);
@@ -682,7 +682,6 @@ void ipo_buttons(void)
uiSetButLock(G.sipo->pin, "Can't change because of pinned data");
ob= OBACT;
xco+= 10;
if (G.sipo->blocktype == ID_OB)
icon = ICON_OBJECT;
@@ -705,9 +704,10 @@ void ipo_buttons(void)
else if (G.sipo->blocktype == ID_SEQ)
icon = ICON_SEQUENCE;
uiDefIconTextButS(block, MENU, B_IPOMAIN, icon, ipo_modeselect_pup(), xco,0,120,20, &(G.sipo->blocktype), 0, 0, 0, 0, "Display IPO type");
xco+= 5;
uiDefIconTextButS(block, MENU, B_IPOMAIN, icon, ipo_modeselect_pup(), xco,0,100,20, &(G.sipo->blocktype), 0, 0, 0, 0, "Display IPO type");
xco += 110;
xco += 85;
if(G.sipo->blocktype==ID_MA) {
uiDefButS(block, NUM, B_IPOMAIN, "", xco+=XIC,0,XIC-4,YIC, &G.sipo->channel, 0.0, 7.0, 0, 0, "Displays Channel Number of the active Material texture. Click to change.");
@@ -747,8 +747,7 @@ void ipo_buttons(void)
xco+=XIC/2;
uiClearButLock();
/* ZOOM en BORDER */
uiDefIconButI(block, TOG, B_VIEW2DZOOM, ICON_VIEWZOOM, xco+=XIC,0,XIC,YIC, &viewmovetemp, 0, 0, 0, 0, "Zooms view (CTRL+MiddleMouse)");
/* ZOOMBORDER */
uiDefIconBut(block, BUT, B_IPOBORDER, ICON_BORDERMOVE, xco+=XIC,0,XIC,YIC, 0, 0, 0, 0, 0, "Zooms view to area");
/* draw LOCK */

View File

@@ -120,8 +120,8 @@
* This can be cleaned when I make some new 'mode' icons.
*/
#define V3D_OBJECTMODE_SEL ICON_ORTHO
#define V3D_EDITMODE_SEL ICON_EDITMODE_HLT
#define V3D_OBJECTMODE_SEL ICON_OBJECT
#define V3D_EDITMODE_SEL ICON_EDITMODE_HLT
#define V3D_FACESELECTMODE_SEL ICON_FACESEL_HLT
#define V3D_VERTEXPAINTMODE_SEL ICON_VPAINT_HLT
#define V3D_TEXTUREPAINTMODE_SEL ICON_TPAINT_HLT
@@ -2504,81 +2504,45 @@ static uiBlock *view3d_faceselmenu(void *arg_unused)
static char *view3d_modeselect_pup(void)
{
static char string[1024];
char formatstring[1024];
strcpy(formatstring, "Mode: %%t");
char formatstr[1024];
char tempstr[1024];
strcat(formatstring, "|%s %%x%d"); // add space in the menu for Object
strcpy(string, "Mode: %t");
strcpy(formatstr, "|%s %%x%d %%i%d");
/* if active object is an armature */
if (OBACT && OBACT->type==OB_ARMATURE) {
strcat(formatstring, "|%s %%x%d"); // add space in the menu for pose
}
/* if active object is a mesh */
if (OBACT && OBACT->type == OB_MESH) {
strcat(formatstring, "|%s %%x%d|%s %%x%d|%s %%x%d"); // add space in the menu for faceselect, vertex paint, texture paint
/* if active mesh has an armature */
if ((((Mesh*)(OBACT->data))->dvert)) {
strcat(formatstring, "|%s %%x%d"); // add space in the menu for weight paint
}
}
sprintf(tempstr, formatstr, "Object Mode", V3D_OBJECTMODE_SEL, ICON_OBJECT);
strcat(string, tempstr);
/* if active object is editable */
if (OBACT && ((OBACT->type == OB_MESH) || (OBACT->type == OB_ARMATURE)
|| (OBACT->type == OB_CURVE) || (OBACT->type == OB_SURF) || (OBACT->type == OB_FONT)
|| (OBACT->type == OB_MBALL) || (OBACT->type == OB_LATTICE))) {
strcat(formatstring, "|%s %%x%d"); // add space in the menu for Edit
|| (OBACT->type == OB_CURVE) || (OBACT->type == OB_SURF) || (OBACT->type == OB_FONT)
|| (OBACT->type == OB_MBALL) || (OBACT->type == OB_LATTICE))) {
sprintf(tempstr, formatstr, "Edit Mode", V3D_EDITMODE_SEL, ICON_EDITMODE_HLT);
strcat(string, tempstr);
}
/*
* fill in the spaces in the menu with appropriate mode choices depending on active object
*/
if (OBACT && OBACT->type == OB_MESH) {
sprintf(tempstr, formatstr, "UV FaceSelect", V3D_FACESELECTMODE_SEL, ICON_FACESEL_HLT);
strcat(string, tempstr);
sprintf(tempstr, formatstr, "Vertex Paint", V3D_VERTEXPAINTMODE_SEL, ICON_VPAINT_HLT);
strcat(string, tempstr);
sprintf(tempstr, formatstr, "Texture Paint", V3D_TEXTUREPAINTMODE_SEL, ICON_TPAINT_HLT);
strcat(string, tempstr);
if ( ((Mesh*)(OBACT->data))->dvert) {
sprintf(tempstr, formatstr, "Texture Paint", V3D_WEIGHTPAINTMODE_SEL, ICON_WPAINT_HLT);
strcat(string, tempstr);
}
}
/* if active object is an armature */
if (OBACT && OBACT->type==OB_ARMATURE) {
sprintf(string, formatstring,
"Object Mode", V3D_OBJECTMODE_SEL,
"Edit Mode", V3D_EDITMODE_SEL,
"Pose Mode", V3D_POSEMODE_SEL
);
}
/* if active object is a mesh with armature */
else if ((OBACT && OBACT->type == OB_MESH) && ((((Mesh*)(OBACT->data))->dvert))) {
sprintf(string, formatstring,
"Object Mode", V3D_OBJECTMODE_SEL,
"Edit Mode", V3D_EDITMODE_SEL,
"Face Select", V3D_FACESELECTMODE_SEL,
"Vertex Paint", V3D_VERTEXPAINTMODE_SEL,
"Texture Paint", V3D_TEXTUREPAINTMODE_SEL,
"Weight Paint", V3D_WEIGHTPAINTMODE_SEL
);
}
/* if active object is a mesh */
else if (OBACT && OBACT->type == OB_MESH) {
sprintf(string, formatstring,
"Object Mode", V3D_OBJECTMODE_SEL,
"Edit Mode", V3D_EDITMODE_SEL,
"Face Select", V3D_FACESELECTMODE_SEL,
"Vertex Paint", V3D_VERTEXPAINTMODE_SEL,
"Texture Paint", V3D_TEXTUREPAINTMODE_SEL
);
}
/* if active object is editable */
else if (OBACT && ((OBACT->type == OB_MESH) || (OBACT->type == OB_ARMATURE)
|| (OBACT->type == OB_CURVE) || (OBACT->type == OB_SURF) || (OBACT->type == OB_FONT)
|| (OBACT->type == OB_MBALL) || (OBACT->type == OB_LATTICE))) {
sprintf(string, formatstring,
"Object Mode", V3D_OBJECTMODE_SEL,
"Edit Mode", V3D_EDITMODE_SEL
);
}
/* if active object is not editable */
else {
sprintf(string, formatstring,
"Object Mode", V3D_OBJECTMODE_SEL
);
sprintf(tempstr, formatstr, "Pose Mode", V3D_POSEMODE_SEL, ICON_POSE_HLT);
strcat(string, tempstr);
}
return (string);

View File

@@ -655,6 +655,7 @@ void uiDrawBlock(uiBlock *block)
typedef struct {
char *str;
int retval;
int icon;
} MenuEntry;
typedef struct {
@@ -681,7 +682,7 @@ static void menudata_set_title(MenuData *md, char *title) {
md->title= title;
}
static void menudata_add_item(MenuData *md, char *str, int retval) {
static void menudata_add_item(MenuData *md, char *str, int retval, int icon) {
if (md->nitems==md->itemssize) {
int nsize= md->itemssize?(md->itemssize<<1):1;
MenuEntry *oitems= md->items;
@@ -697,6 +698,7 @@ static void menudata_add_item(MenuData *md, char *str, int retval) {
md->items[md->nitems].str= str;
md->items[md->nitems].retval= retval;
md->items[md->nitems].icon= icon;
md->nitems++;
}
@@ -724,7 +726,7 @@ static MenuData *decompose_menu_string(char *str)
char *instr= BLI_strdup(str);
MenuData *md= menudata_new(instr);
char *nitem= NULL, *s= instr;
int nretval= 1, nitem_is_title= 0;
int nicon=0, nretval= 1, nitem_is_title= 0;
while (1) {
char c= *s;
@@ -743,6 +745,9 @@ static MenuData *decompose_menu_string(char *str)
} else if (s[1]=='l') {
nitem= "%l";
s++;
} else if (s[1]=='i') {
nicon= atoi(s+2);
s++;
}
} else if (c=='|' || c=='\0') {
if (nitem) {
@@ -752,11 +757,12 @@ static MenuData *decompose_menu_string(char *str)
menudata_set_title(md, nitem);
nitem_is_title= 0;
} else {
menudata_add_item(md, nitem, nretval);
menudata_add_item(md, nitem, nretval, nicon);
nretval= md->nitems+1;
}
nitem= NULL;
nicon= 0;
}
if (c=='\0')
@@ -878,6 +884,10 @@ static int ui_do_but_MENU(uiBut *but)
if (strcmp(md->items[md->nitems-a-1].str, "%l")==0) {
uiDefBut(block, SEPR, B_NOP, "", x1, y1,(short)(width-(rows>1)), (short)(boxh-1), NULL, 0.0, 0.0, 0, 0, "");
}
else if(md->items[md->nitems-a-1].icon) {
uiBut *bt= uiDefIconTextBut(block, BUTM|but->pointype, but->retval, md->items[md->nitems-a-1].icon ,md->items[md->nitems-a-1].str, x1, y1,(short)(width-(rows>1)), (short)(boxh-1), but->poin, (float) md->items[md->nitems-a-1].retval, 0.0, 0, 0, "");
if(active==a) bt->flag |= UI_ACTIVE;
}
else {
uiBut *bt= uiDefBut(block, BUTM|but->pointype, but->retval, md->items[md->nitems-a-1].str, x1, y1,(short)(width-(rows>1)), (short)(boxh-1), but->poin, (float) md->items[md->nitems-a-1].retval, 0.0, 0, 0, "");
if(active==a) bt->flag |= UI_ACTIVE;