diff options
Diffstat (limited to 'source')
44 files changed, 1885 insertions, 1545 deletions
diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h index 212e9f08c35..e598394cc60 100644 --- a/source/blender/blenkernel/BKE_library.h +++ b/source/blender/blenkernel/BKE_library.h @@ -61,6 +61,7 @@ void free_main(struct Main *mainvar); void splitIDname(char *name, char *left, int *nr); void rename_id(struct ID *id, char *name); void test_idbutton(char *name); +void text_idbutton(struct ID *id, char *text); void all_local(struct Library *lib, int untagged_only); struct ID *find_id(char *type, char *name); void clear_id_newpoins(void); diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h index 8ac3b4b0b51..4797616a471 100644 --- a/source/blender/blenkernel/BKE_screen.h +++ b/source/blender/blenkernel/BKE_screen.h @@ -38,6 +38,7 @@ struct bScreen; struct ListBase; struct Panel; struct Header; +struct Menu; struct ScrArea; struct SpaceType; struct wmNotifier; @@ -136,6 +137,9 @@ typedef struct ARegionType { /* header type definitions */ ListBase headertypes; + /* menu type definitions */ + ListBase menutypes; + /* hardcoded constraints, smaller than these values region is not visible */ int minsizex, minsizey; /* default keymaps to add */ @@ -183,6 +187,27 @@ typedef struct HeaderType { void (*py_free)(void *py_data); } HeaderType; +/* menu types */ + +typedef struct MenuType { + struct MenuType *next, *prev; + + char idname[BKE_ST_MAXNAME]; /* unique name */ + char label[BKE_ST_MAXNAME]; /* for button text */ + int space_type; + + /* verify if the menu should draw or not */ + int (*poll)(const struct bContext *, struct MenuType *); + /* draw entirely, view changes should be handled here */ + void (*draw)(const struct bContext *, struct Menu *); + + /* python integration */ + void *py_data; + struct StructRNA *py_srna; + int (*py_call)(struct PointerRNA *, struct FunctionRNA *, struct ParameterList *); + void (*py_free)(void *py_data); +} MenuType; + /* spacetypes */ struct SpaceType *BKE_spacetype_from_id(int spaceid); struct ARegionType *BKE_regiontype_from_id(struct SpaceType *st, int regionid); diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 5728b844a88..d0e4c1a15bc 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -1102,6 +1102,27 @@ void test_idbutton(char *name) if(idtest) if( new_id(lb, idtest, name)==0 ) sort_alpha_id(lb, idtest); } +void text_idbutton(struct ID *id, char *text) +{ + if(id) { + if(GS(id->name)==ID_SCE) + strcpy(text, "SCE: "); + else if(GS(id->name)==ID_SCE) + strcpy(text, "SCR: "); + else if(GS(id->name)==ID_MA && ((Material*)id)->use_nodes) + strcpy(text, "NT: "); + else { + text[0]= id->name[0]; + text[1]= id->name[1]; + text[2]= ':'; + text[3]= ' '; + text[4]= 0; + } + } + else + strcpy(text, ""); +} + void rename_id(ID *id, char *name) { ListBase *lb; diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c index f43dc287062..e25e4be90c8 100644 --- a/source/blender/blenkernel/intern/screen.c +++ b/source/blender/blenkernel/intern/screen.c @@ -54,6 +54,8 @@ static void spacetype_free(SpaceType *st) { ARegionType *art; PanelType *pt; + HeaderType *ht; + MenuType *mt; for(art= st->regiontypes.first; art; art= art->next) { BLI_freelistN(&art->drawcalls); @@ -62,8 +64,17 @@ static void spacetype_free(SpaceType *st) if(pt->py_free) pt->py_free(pt->py_data); + for(ht= art->headertypes.first; ht; ht= ht->next) + if(ht->py_free) + ht->py_free(ht->py_data); + + for(mt= art->menutypes.first; mt; mt= mt->next) + if(mt->py_free) + mt->py_free(mt->py_data); + BLI_freelistN(&art->paneltypes); BLI_freelistN(&art->headertypes); + BLI_freelistN(&art->menutypes); } BLI_freelistN(&st->regiontypes); diff --git a/source/blender/editors/animation/keyframing.c b/source/blender/editors/animation/keyframing.c index c341e32db8c..b09cc3b78e1 100644 --- a/source/blender/editors/animation/keyframing.c +++ b/source/blender/editors/animation/keyframing.c @@ -989,22 +989,24 @@ static int insert_key_menu_invoke (bContext *C, wmOperator *op, wmEvent *event) { Scene *scene= CTX_data_scene(C); KeyingSet *ks; - uiMenuItem *head; + uiPopupMenu *pup; + uiLayout *layout; int i = 0; - head= uiPupMenuBegin("Insert Keyframe", 0); + pup= uiPupMenuBegin("Insert Keyframe", 0); + layout= uiPupMenuLayout(pup); /* active Keying Set */ - uiMenuItemIntO(head, "Active Keying Set", 0, "ANIM_OT_insert_keyframe_menu", "type", i++); - uiMenuSeparator(head); + uiItemIntO(layout, "Active Keying Set", 0, "ANIM_OT_insert_keyframe_menu", "type", i++); + uiItemS(layout); /* user-defined Keying Sets * - these are listed in the order in which they were defined for the active scene */ if (scene->keyingsets.first) { for (ks= scene->keyingsets.first; ks; ks= ks->next) - uiMenuItemIntO(head, ks->name, 0, "ANIM_OT_insert_keyframe_menu", "type", i++); - uiMenuSeparator(head); + uiItemIntO(layout, ks->name, 0, "ANIM_OT_insert_keyframe_menu", "type", i++); + uiItemS(layout); } /* builtin Keying Sets */ @@ -1013,11 +1015,11 @@ static int insert_key_menu_invoke (bContext *C, wmOperator *op, wmEvent *event) for (ks= builtin_keyingsets.first; ks; ks= ks->next) { /* only show KeyingSet if context is suitable */ if (keyingset_context_ok_poll(C, ks)) { - uiMenuItemIntO(head, ks->name, 0, "ANIM_OT_insert_keyframe_menu", "type", i--); + uiItemIntO(layout, ks->name, 0, "ANIM_OT_insert_keyframe_menu", "type", i--); } } - uiPupMenuEnd(C, head); + uiPupMenuEnd(C, pup); return OPERATOR_CANCELLED; } diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c index 80f51f3797c..ca0694a7ece 100644 --- a/source/blender/editors/armature/editarmature.c +++ b/source/blender/editors/armature/editarmature.c @@ -3460,11 +3460,13 @@ void ARMATURE_OT_subdivide_multi(wmOperatorType *ot) static int armature_subdivs_invoke(bContext *C, wmOperator *op, wmEvent *event) { - uiMenuItem *head; + uiPopupMenu *pup; + uiLayout *layout; - head= uiPupMenuBegin("Subdivision Type", 0); - uiMenuItemsEnumO(head, "ARMATURE_OT_subdivs", "type"); - uiPupMenuEnd(C, head); + pup= uiPupMenuBegin("Subdivision Type", 0); + layout= uiPupMenuLayout(pup); + uiItemsEnumO(layout, "ARMATURE_OT_subdivs", "type"); + uiPupMenuEnd(C, pup); return OPERATOR_CANCELLED; } @@ -3744,7 +3746,8 @@ static int armature_parent_set_exec(bContext *C, wmOperator *op) static int armature_parent_set_invoke(bContext *C, wmOperator *op, wmEvent *event) { EditBone *actbone = CTX_data_active_bone(C); - uiMenuItem *head= uiPupMenuBegin("Make Parent ", 0); + uiPopupMenu *pup= uiPupMenuBegin("Make Parent ", 0); + uiLayout *layout= uiPupMenuLayout(pup); int allchildbones = 0; CTX_DATA_BEGIN(C, EditBone *, ebone, selected_editable_bones) { @@ -3754,13 +3757,13 @@ static int armature_parent_set_invoke(bContext *C, wmOperator *op, wmEvent *even } CTX_DATA_END; - uiMenuItemEnumO(head, "", 0, "ARMATURE_OT_parent_set", "type", ARM_PAR_CONNECT); + uiItemEnumO(layout, NULL, 0, "ARMATURE_OT_parent_set", "type", ARM_PAR_CONNECT); /* ob becomes parent, make the associated menus */ if (allchildbones) - uiMenuItemEnumO(head, "", 0, "ARMATURE_OT_parent_set", "type", ARM_PAR_OFFSET); + uiItemEnumO(layout, NULL, 0, "ARMATURE_OT_parent_set", "type", ARM_PAR_OFFSET); - uiPupMenuEnd(C, head); + uiPupMenuEnd(C, pup); return OPERATOR_CANCELLED; } diff --git a/source/blender/editors/armature/poselib.c b/source/blender/editors/armature/poselib.c index fc5b98b1690..9b4a9d63439 100644 --- a/source/blender/editors/armature/poselib.c +++ b/source/blender/editors/armature/poselib.c @@ -301,7 +301,7 @@ static void poselib_get_builtin_keyingsets (void) /* ----- */ -static void poselib_add_menu_invoke__replacemenu (bContext *C, uiMenuItem *head, void *arg) +static void poselib_add_menu_invoke__replacemenu (bContext *C, uiLayout *layout, void *arg) { Object *ob= CTX_data_active_object(C); bAction *act= ob->poselib; @@ -309,7 +309,7 @@ static void poselib_add_menu_invoke__replacemenu (bContext *C, uiMenuItem *head, /* add each marker to this menu */ for (marker= act->markers.first; marker; marker= marker->next) - uiMenuItemIntO(head, marker->name, ICON_ARMATURE_DATA, "POSELIB_OT_pose_add", "frame", marker->frame); + uiItemIntO(layout, marker->name, ICON_ARMATURE_DATA, "POSELIB_OT_pose_add", "frame", marker->frame); } static int poselib_add_menu_invoke (bContext *C, wmOperator *op, wmEvent *evt) @@ -318,29 +318,31 @@ static int poselib_add_menu_invoke (bContext *C, wmOperator *op, wmEvent *evt) Object *ob= CTX_data_active_object(C); bArmature *arm= (ob) ? ob->data : NULL; bPose *pose= (ob) ? ob->pose : NULL; - uiMenuItem *head; + uiPopupMenu *pup; + uiLayout *layout; /* sanity check */ if (ELEM3(NULL, ob, arm, pose)) return OPERATOR_CANCELLED; /* start building */ - head= uiPupMenuBegin(op->type->name, 0); - uiMenuContext(head, WM_OP_EXEC_DEFAULT); + pup= uiPupMenuBegin(op->type->name, 0); + layout= uiPupMenuLayout(pup); + uiLayoutContext(layout, WM_OP_EXEC_DEFAULT); /* add new (adds to the first unoccupied frame) */ - uiMenuItemIntO(head, "Add New", 0, "POSELIB_OT_pose_add", "frame", poselib_get_free_index(ob->poselib)); + uiItemIntO(layout, "Add New", 0, "POSELIB_OT_pose_add", "frame", poselib_get_free_index(ob->poselib)); /* check if we have any choices to add a new pose in any other way */ if ((ob->poselib) && (ob->poselib->markers.first)) { /* add new (on current frame) */ - uiMenuItemIntO(head, "Add New (Current Frame)", 0, "POSELIB_OT_pose_add", "frame", CFRA); + uiItemIntO(layout, "Add New (Current Frame)", 0, "POSELIB_OT_pose_add", "frame", CFRA); /* replace existing - submenu */ - uiMenuLevel(head, "Replace Existing...", poselib_add_menu_invoke__replacemenu); + uiItemLevel(layout, "Replace Existing...", 0, poselib_add_menu_invoke__replacemenu); } - uiPupMenuEnd(C, head); + uiPupMenuEnd(C, pup); /* this operator is only for a menu, not used further */ return OPERATOR_CANCELLED; @@ -449,7 +451,8 @@ static int poselib_stored_pose_menu_invoke (bContext *C, wmOperator *op, wmEvent Object *ob= CTX_data_active_object(C); bAction *act= (ob) ? ob->poselib : NULL; TimeMarker *marker; - uiMenuItem *head; + uiPopupMenu *pup; + uiLayout *layout; int i; /* sanity check */ @@ -457,14 +460,15 @@ static int poselib_stored_pose_menu_invoke (bContext *C, wmOperator *op, wmEvent return OPERATOR_CANCELLED; /* start building */ - head= uiPupMenuBegin(op->type->name, 0); - uiMenuContext(head, WM_OP_EXEC_DEFAULT); + pup= uiPupMenuBegin(op->type->name, 0); + layout= uiPupMenuLayout(pup); + uiLayoutContext(layout, WM_OP_EXEC_DEFAULT); /* add each marker to this menu */ for (marker=act->markers.first, i=0; marker; marker= marker->next, i++) - uiMenuItemIntO(head, marker->name, ICON_ARMATURE_DATA, op->idname, "index", i); + uiItemIntO(layout, marker->name, ICON_ARMATURE_DATA, op->idname, "index", i); - uiPupMenuEnd(C, head); + uiPupMenuEnd(C, pup); /* this operator is only for a menu, not used further */ return OPERATOR_CANCELLED; diff --git a/source/blender/editors/curve/curve_ops.c b/source/blender/editors/curve/curve_ops.c index c27c498f55e..49d86d08db2 100644 --- a/source/blender/editors/curve/curve_ops.c +++ b/source/blender/editors/curve/curve_ops.c @@ -67,16 +67,18 @@ static int specials_menu_invoke(bContext *C, wmOperator *op, wmEvent *event) { - uiMenuItem *head; - - head= uiPupMenuBegin("Specials", 0); - uiMenuItemO(head, 0, "CURVE_OT_subdivide"); - uiMenuItemO(head, 0, "CURVE_OT_switch_direction"); - uiMenuItemO(head, 0, "CURVE_OT_spline_weight_set"); - uiMenuItemO(head, 0, "CURVE_OT_radius_set"); - uiMenuItemO(head, 0, "CURVE_OT_smooth"); - uiMenuItemO(head, 0, "CURVE_OT_smooth_radius"); - uiPupMenuEnd(C, head); + uiPopupMenu *pup; + uiLayout *layout; + + pup= uiPupMenuBegin("Specials", 0); + layout= uiPupMenuLayout(pup); + uiItemO(layout, NULL, 0, "CURVE_OT_subdivide"); + uiItemO(layout, NULL, 0, "CURVE_OT_switch_direction"); + uiItemO(layout, NULL, 0, "CURVE_OT_spline_weight_set"); + uiItemO(layout, NULL, 0, "CURVE_OT_radius_set"); + uiItemO(layout, NULL, 0, "CURVE_OT_smooth"); + uiItemO(layout, NULL, 0, "CURVE_OT_smooth_radius"); + uiPupMenuEnd(C, pup); return OPERATOR_CANCELLED; } diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index 72806a79c50..78b86ad7f32 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -3562,15 +3562,17 @@ static int toggle_cyclic_invoke(bContext *C, wmOperator *op, wmEvent *event) { Object *obedit= CTX_data_edit_object(C); ListBase *editnurb= curve_get_editcurve(obedit); - uiMenuItem *head; + uiPopupMenu *pup; + uiLayout *layout; Nurb *nu; for(nu= editnurb->first; nu; nu= nu->next) { if(nu->pntsu>1 || nu->pntsv>1) { if(nu->type==CU_NURBS) { - head= uiPupMenuBegin("Direction", 0); - uiMenuItemsEnumO(head, op->type->idname, "direction"); - uiPupMenuEnd(C, head); + pup= uiPupMenuBegin("Direction", 0); + layout= uiPupMenuLayout(pup); + uiItemsEnumO(layout, op->type->idname, "direction"); + uiPupMenuEnd(C, pup); return OPERATOR_CANCELLED; } } @@ -4507,18 +4509,21 @@ static int delete_exec(bContext *C, wmOperator *op) static int delete_invoke(bContext *C, wmOperator *op, wmEvent *event) { Object *obedit= CTX_data_edit_object(C); - uiMenuItem *head; + uiPopupMenu *pup; + uiLayout *layout; if(obedit->type==OB_SURF) { - head= uiPupMenuBegin("Delete", 0); - uiMenuItemEnumO(head, "", 0, op->type->idname, "type", 0); - uiMenuItemEnumO(head, "", 0, op->type->idname, "type", 2); - uiPupMenuEnd(C, head); + pup= uiPupMenuBegin("Delete", 0); + layout= uiPupMenuLayout(pup); + uiItemEnumO(layout, NULL, 0, op->type->idname, "type", 0); + uiItemEnumO(layout, NULL, 0, op->type->idname, "type", 2); + uiPupMenuEnd(C, pup); } else { - head= uiPupMenuBegin("Delete", 0); - uiMenuItemsEnumO(head, op->type->idname, "type"); - uiPupMenuEnd(C, head); + pup= uiPupMenuBegin("Delete", 0); + layout= uiPupMenuLayout(pup); + uiItemsEnumO(layout, op->type->idname, "type"); + uiPupMenuEnd(C, pup); } return OPERATOR_CANCELLED; diff --git a/source/blender/editors/include/BIF_transform.h b/source/blender/editors/include/BIF_transform.h index d16ac563eb3..e02202eb8e0 100644 --- a/source/blender/editors/include/BIF_transform.h +++ b/source/blender/editors/include/BIF_transform.h @@ -37,7 +37,7 @@ struct ListBase; struct wmEvent; struct bContext; struct Object; -struct uiMenuItem; +struct uiLayout; void transform_keymap_for_space(struct wmWindowManager *wm, struct ListBase *keymap, int spaceid); void transform_operatortypes(void); @@ -114,7 +114,7 @@ int BIF_menuselectTransformOrientation(void); void BIF_selectTransformOrientation(struct bContext *C, struct TransformOrientation *ts); void BIF_selectTransformOrientationValue(struct bContext *C, int orientation); -void BIF_menuTransformOrientation(struct bContext *C, struct uiMenuItem *head, void *arg); +void BIF_menuTransformOrientation(struct bContext *C, struct uiLayout *layout, void *arg); char * BIF_menustringTransformOrientation(const struct bContext *C, char *title); /* the returned value was allocated and needs to be freed after use */ int BIF_countTransformOrientation(const struct bContext *C); diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 5a827a2311b..c491dee6ba6 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -53,6 +53,7 @@ struct uiFontStyle; typedef struct uiBut uiBut; typedef struct uiBlock uiBlock; typedef struct uiPopupBlockHandle uiPopupBlockHandle; +typedef struct uiLayout uiLayout; /* Defines */ @@ -199,51 +200,23 @@ void uiRoundRect(float minx, float miny, float maxx, float maxy, float rad); void uiDrawMenuBox(float minx, float miny, float maxx, float maxy, short flag, short direction); void uiDrawBoxShadow(unsigned char alpha, float minx, float miny, float maxx, float maxy); -/* Menus - * - * These functions are used by popup menus, toolbox and header menus. They - * assume uiMenuItem head is already created, which is done by uiMenuButton - * for header menus, or can be done with uiPupMenuBegin for popups. These - * functions do not use uiDefBut functions in order to simplify creating - * them, and to permit other types of menus (radial, ..) in the future. */ - -typedef struct uiMenuItem uiMenuItem; +/* Menu Callbacks */ -typedef void (*uiMenuCreateFunc)(struct bContext *C, uiMenuItem *head, void *arg1); +typedef void (*uiMenuCreateFunc)(struct bContext *C, struct uiLayout *layout, void *arg1); typedef void (*uiMenuHandleFunc)(struct bContext *C, void *arg, int event); -void uiMenuFunc(uiMenuItem *head, uiMenuHandleFunc handlefunc, void *argv); -void uiMenuContext(uiMenuItem *head, int opcontext); - -void uiMenuItemVal(uiMenuItem *head, const char *name, int icon, int argval); - -void uiMenuItemEnumO(uiMenuItem *head, const char *name, int icon, char *opname, char *propname, int value); -void uiMenuItemBooleanO(uiMenuItem *head, const char *name, int icon, char *opname, char *propname, int value); -void uiMenuItemsEnumO(uiMenuItem *head, char *opname, char *propname); -void uiMenuItemIntO(uiMenuItem *head, const char *name, int icon, char *opname, char *propname, int value); -void uiMenuItemFloatO(uiMenuItem *head, const char *name, int icon, char *opname, char *propname, float value); -void uiMenuItemStringO(uiMenuItem *head, const char *name, int icon, char *opname, char *propname, char *value); -void uiMenuItemO(uiMenuItem *head, int icon, char *opname); - -void uiMenuItemBooleanR(uiMenuItem *head, struct PointerRNA *ptr, char *propname); -void uiMenuItemEnumR(uiMenuItem *head, struct PointerRNA *ptr, char *propname, int value); -void uiMenuItemsEnumR(uiMenuItem *head, struct PointerRNA *ptr, char *propname); - -void uiMenuLevel(uiMenuItem *head, const char *name, uiMenuCreateFunc newlevel); -void uiMenuLevelEnumO(uiMenuItem *head, char *opname, char *propname); -void uiMenuLevelEnumR(uiMenuItem *head, struct PointerRNA *ptr, char *propname); - -void uiMenuSeparator(uiMenuItem *head); - /* Popup Menus * * Functions used to create popup menus. For more extended menus the * uiPupMenuBegin/End functions can be used to define own items with - * the uiMenu functions inbetween. If it is a simple confirmation menu + * the uiItem functions inbetween. If it is a simple confirmation menu * or similar, popups can be created with a single function call. */ -uiMenuItem *uiPupMenuBegin(const char *title, int icon); -void uiPupMenuEnd(struct bContext *C, struct uiMenuItem *head); +typedef struct uiPopupMenu uiPopupMenu; + +uiPopupMenu *uiPupMenuBegin(const char *title, int icon); +void uiPupMenuEnd(struct bContext *C, struct uiPopupMenu *head); +struct uiLayout *uiPupMenuLayout(uiPopupMenu *head); void uiPupMenuOkee(struct bContext *C, char *opname, char *str, ...); void uiPupMenuSaveOver(struct bContext *C, struct wmOperator *op, char *filename); @@ -555,12 +528,16 @@ uiBut *uiDefMenuTogR(uiBlock *block, struct PointerRNA *ptr, char *propname, cha #define UI_LAYOUT_HORIZONTAL 0 #define UI_LAYOUT_VERTICAL 1 -typedef struct uiLayout uiLayout; +#define UI_LAYOUT_PANEL 0 +#define UI_LAYOUT_HEADER 1 +#define UI_LAYOUT_MENU 2 -uiLayout *uiLayoutBegin(int dir, int x, int y, int size, int em); -void uiLayoutContext(uiLayout *layout, int opcontext); +uiLayout *uiLayoutBegin(int dir, int type, int x, int y, int size, int em); void uiLayoutEnd(const struct bContext *C, uiBlock *block, uiLayout *layout, int *x, int *y); +void uiLayoutContext(uiLayout *layout, int opcontext); +void uiLayoutFunc(uiLayout *layout, uiMenuHandleFunc handlefunc, void *argv); + /* layout specifiers */ void uiLayoutRow(uiLayout *layout); void uiLayoutColumn(uiLayout *layout); @@ -570,10 +547,9 @@ uiLayout *uiLayoutBox(uiLayout *layout); uiLayout *uiLayoutSub(uiLayout *layout, int n); /* templates */ -void uiTemplateHeaderMenus(uiLayout *layout); -void uiTemplateHeaderButtons(uiLayout *layout); -void uiTemplateHeaderID(uiLayout *layout, struct PointerRNA *ptr, char *propname, int flag, uiIDPoinFunc func); -void uiTemplateSetColor(uiLayout *layout, int color); +void uiTemplateHeader(uiLayout *layout); +void uiTemplateHeaderID(uiLayout *layout, struct PointerRNA *ptr, char *propname, + char *newop, char *openop, char *unlinkop); /* items */ void uiItemO(uiLayout *layout, char *name, int icon, char *opname); @@ -586,11 +562,18 @@ void uiItemStringO(uiLayout *layout, char *name, int icon, char *opname, char *p void uiItemFullO(uiLayout *layout, char *name, int icon, char *idname, struct IDProperty *properties, int context); void uiItemR(uiLayout *layout, char *name, int icon, struct PointerRNA *ptr, char *propname, int expand); -void uiItemFullR(uiLayout *layout, char *name, int icon, struct PointerRNA *ptr, struct PropertyRNA *prop, int index, int expand); - -void uiItemL(uiLayout *layout, char *name, int icon); - -void uiItemM(uiLayout *layout, char *name, int icon, uiMenuCreateFunc func); +void uiItemFullR(uiLayout *layout, char *name, int icon, struct PointerRNA *ptr, struct PropertyRNA *prop, int index, int value, int expand); +void uiItemEnumR(uiLayout *layout, char *name, int icon, struct PointerRNA *ptr, char *propname, int value); +void uiItemsEnumR(uiLayout *layout, struct PointerRNA *ptr, char *propname); + +void uiItemL(uiLayout *layout, char *name, int icon); /* label */ +void uiItemM(uiLayout *layout, char *name, int icon, char *menuname); /* menu */ +void uiItemV(uiLayout *layout, char *name, int icon, int argval); /* value */ +void uiItemS(uiLayout *layout); /* separator */ + +void uiItemLevel(uiLayout *layout, char *name, int icon, uiMenuCreateFunc func); +void uiItemLevelEnumO(uiLayout *layout, char *name, int icon, char *opname, char *propname); +void uiItemLevelEnumR(uiLayout *layout, char *name, int icon, struct PointerRNA *ptr, char *propname); /* utilities */ #define UI_PANEL_WIDTH 340 diff --git a/source/blender/editors/interface/interface_anim.c b/source/blender/editors/interface/interface_anim.c index 6775a639597..af8aa91f358 100644 --- a/source/blender/editors/interface/interface_anim.c +++ b/source/blender/editors/interface/interface_anim.c @@ -114,44 +114,46 @@ void ui_but_anim_remove_driver(bContext *C) // TODO: refine the logic for adding/removing drivers... void ui_but_anim_menu(bContext *C, uiBut *but) { - uiMenuItem *head; + uiPopupMenu *pup; + uiLayout *layout; int length; if(but->rnapoin.data && but->rnaprop) { - head= uiPupMenuBegin(RNA_property_ui_name(but->rnaprop), 0); + pup= uiPupMenuBegin(RNA_property_ui_name(but->rnaprop), 0); + layout= uiPupMenuLayout(pup); length= RNA_property_array_length(but->rnaprop); if(but->flag & UI_BUT_ANIMATED_KEY) { if(length) { - uiMenuItemBooleanO(head, "Delete Keyframes", 0, "ANIM_OT_delete_keyframe_button", "all", 1); - uiMenuItemBooleanO(head, "Delete Single Keyframe", 0, "ANIM_OT_delete_keyframe_button", "all", 0); + uiItemBooleanO(layout, "Delete Keyframes", 0, "ANIM_OT_delete_keyframe_button", "all", 1); + uiItemBooleanO(layout, "Delete Single Keyframe", 0, "ANIM_OT_delete_keyframe_button", "all", 0); - uiMenuItemBooleanO(head, "Remove Driver", 0, "ANIM_OT_remove_driver_button", "all", 1); - uiMenuItemBooleanO(head, "Remove Single Driver", 0, "ANIM_OT_remove_driver_button", "all", 0); + uiItemBooleanO(layout, "Remove Driver", 0, "ANIM_OT_remove_driver_button", "all", 1); + uiItemBooleanO(layout, "Remove Single Driver", 0, "ANIM_OT_remove_driver_button", "all", 0); } else { - uiMenuItemBooleanO(head, "Delete Keyframe", 0, "ANIM_OT_delete_keyframe_button", "all", 0); + uiItemBooleanO(layout, "Delete Keyframe", 0, "ANIM_OT_delete_keyframe_button", "all", 0); - uiMenuItemBooleanO(head, "Remove Driver", 0, "ANIM_OT_remove_driver_button", "all", 0); + uiItemBooleanO(layout, "Remove Driver", 0, "ANIM_OT_remove_driver_button", "all", 0); } } else if(RNA_property_animateable(&but->rnapoin, but->rnaprop)) { if(length) { - uiMenuItemBooleanO(head, "Insert Keyframes", 0, "ANIM_OT_insert_keyframe_button", "all", 1); - uiMenuItemBooleanO(head, "Insert Single Keyframe", 0, "ANIM_OT_insert_keyframe_button", "all", 0); + uiItemBooleanO(layout, "Insert Keyframes", 0, "ANIM_OT_insert_keyframe_button", "all", 1); + uiItemBooleanO(layout, "Insert Single Keyframe", 0, "ANIM_OT_insert_keyframe_button", "all", 0); - uiMenuItemBooleanO(head, "Add Driver", 0, "ANIM_OT_add_driver_button", "all", 1); - uiMenuItemBooleanO(head, "Add Single Driver", 0, "ANIM_OT_add_driver_button", "all", 0); + uiItemBooleanO(layout, "Add Driver", 0, "ANIM_OT_add_driver_button", "all", 1); + uiItemBooleanO(layout, "Add Single Driver", 0, "ANIM_OT_add_driver_button", "all", 0); } else { - uiMenuItemBooleanO(head, "Insert Keyframe", 0, "ANIM_OT_insert_keyframe_button", "all", 0); + uiItemBooleanO(layout, "Insert Keyframe", 0, "ANIM_OT_insert_keyframe_button", "all", 0); - uiMenuItemBooleanO(head, "Add Driver", 0, "ANIM_OT_add_driver_button", "all", 0); + uiItemBooleanO(layout, "Add Driver", 0, "ANIM_OT_add_driver_button", "all", 0); } } - uiPupMenuEnd(C, head); + uiPupMenuEnd(C, pup); } } diff --git a/source/blender/editors/interface/interface_api.c b/source/blender/editors/interface/interface_api.c index a184655df83..3153f13bd0b 100644 --- a/source/blender/editors/interface/interface_api.c +++ b/source/blender/editors/interface/interface_api.c @@ -40,6 +40,15 @@ static void api_ui_item_common(FunctionRNA *func) RNA_def_int(func, "icon", 0, 0, INT_MAX, "", "Override automatic icon of the item.", 0, INT_MAX); } +static void api_ui_item_op_common(FunctionRNA *func) +{ + PropertyRNA *parm; + + api_ui_item_common(func); + parm= RNA_def_string(func, "operator", "", 0, "", "Identifier of the operator."); + RNA_def_property_flag(parm, PROP_REQUIRED); +} + void RNA_api_ui_layout(StructRNA *srna) { FunctionRNA *func; @@ -68,9 +77,6 @@ void RNA_api_ui_layout(StructRNA *srna) parm= RNA_def_pointer(func, "layout", "UILayout", "", "Sub-layout to put items in."); RNA_def_function_return(func, parm); - func= RNA_def_function(srna, "template_header_menus", "uiTemplateHeaderMenus"); - //func= RNA_def_function(srna, "template_header_ID", "uiTemplateHeaderID"); - /* items */ func= RNA_def_function(srna, "itemR", "uiItemR"); api_ui_item_common(func); @@ -80,12 +86,97 @@ void RNA_api_ui_layout(StructRNA *srna) RNA_def_property_flag(parm, PROP_REQUIRED); RNA_def_boolean(func, "expand", 0, "", "Expand button to show more detail."); - func= RNA_def_function(srna, "itemO", "uiItemO"); + func= RNA_def_function(srna, "items_enumR", "uiItemsEnumR"); + parm= RNA_def_pointer(func, "data", "AnyType", "", "Data from which to take property."); + RNA_def_property_flag(parm, PROP_REQUIRED); + parm= RNA_def_string(func, "property", "", 0, "", "Identifier of property in data."); + RNA_def_property_flag(parm, PROP_REQUIRED); + + func= RNA_def_function(srna, "item_level_enumR", "uiItemLevelEnumR"); + api_ui_item_common(func); + parm= RNA_def_pointer(func, "data", "AnyType", "", "Data from which to take property."); + RNA_def_property_flag(parm, PROP_REQUIRED); + parm= RNA_def_string(func, "property", "", 0, "", "Identifier of property in data."); + RNA_def_property_flag(parm, PROP_REQUIRED); + + /*func= RNA_def_function(srna, "item_enumR", "uiItemEnumR"); api_ui_item_common(func); + parm= RNA_def_pointer(func, "data", "AnyType", "", "Data from which to take property."); + RNA_def_property_flag(parm, PROP_REQUIRED); + parm= RNA_def_string(func, "property", "", 0, "", "Identifier of property in data."); + RNA_def_property_flag(parm, PROP_REQUIRED); + parm= RNA_def_string(func, "value", "", 0, "", "Enum property value."); + RNA_def_property_flag(parm, PROP_REQUIRED);*/ + + func= RNA_def_function(srna, "itemO", "uiItemO"); + api_ui_item_op_common(func); + + /*func= RNA_def_function(srna, "item_enumO", "uiItemEnumO"); + api_ui_item_op_common(func); + parm= RNA_def_string(func, "property", "", 0, "", "Identifier of property in operator."); + RNA_def_property_flag(parm, PROP_REQUIRED); + parm= RNA_def_string(func, "value", "", 0, "", "Enum property value."); + RNA_def_property_flag(parm, PROP_REQUIRED);*/ + + func= RNA_def_function(srna, "items_enumO", "uiItemsEnumO"); parm= RNA_def_string(func, "operator", "", 0, "", "Identifier of the operator."); RNA_def_property_flag(parm, PROP_REQUIRED); + parm= RNA_def_string(func, "property", "", 0, "", "Identifier of property in operator."); + RNA_def_property_flag(parm, PROP_REQUIRED); + + func= RNA_def_function(srna, "item_level_enumO", "uiItemLevelEnumO"); + api_ui_item_op_common(func); + parm= RNA_def_string(func, "property", "", 0, "", "Identifier of property in operator."); + RNA_def_property_flag(parm, PROP_REQUIRED); + + func= RNA_def_function(srna, "item_booleanO", "uiItemBooleanO"); + api_ui_item_op_common(func); + parm= RNA_def_string(func, "property", "", 0, "", "Identifier of property in operator."); + RNA_def_property_flag(parm, PROP_REQUIRED); + parm= RNA_def_boolean(func, "value", 0, "", "Value of the property to call the operator with."); + RNA_def_property_flag(parm, PROP_REQUIRED); + + func= RNA_def_function(srna, "item_intO", "uiItemIntO"); + api_ui_item_op_common(func); + parm= RNA_def_string(func, "property", "", 0, "", "Identifier of property in operator."); + RNA_def_property_flag(parm, PROP_REQUIRED); + parm= RNA_def_int(func, "value", 0, INT_MIN, INT_MAX, "", "Value of the property to call the operator with.", INT_MIN, INT_MAX); + RNA_def_property_flag(parm, PROP_REQUIRED); + + func= RNA_def_function(srna, "item_floatO", "uiItemFloatO"); + api_ui_item_op_common(func); + parm= RNA_def_string(func, "property", "", 0, "", "Identifier of property in operator."); + RNA_def_property_flag(parm, PROP_REQUIRED); + parm= RNA_def_float(func, "value", 0, -FLT_MAX, FLT_MAX, "", "Value of the property to call the operator with.", -FLT_MAX, FLT_MAX); + RNA_def_property_flag(parm, PROP_REQUIRED); + + func= RNA_def_function(srna, "item_stringO", "uiItemStringO"); + api_ui_item_op_common(func); + parm= RNA_def_string(func, "property", "", 0, "", "Identifier of property in operator."); + RNA_def_property_flag(parm, PROP_REQUIRED); + parm= RNA_def_string(func, "value", "", 0, "", "Value of the property to call the operator with."); + RNA_def_property_flag(parm, PROP_REQUIRED); func= RNA_def_function(srna, "itemL", "uiItemL"); api_ui_item_common(func); + + func= RNA_def_function(srna, "itemM", "uiItemM"); + api_ui_item_common(func); + parm= RNA_def_string(func, "menu", "", 0, "", "Identifier of the menu."); + RNA_def_property_flag(parm, PROP_REQUIRED); + + func= RNA_def_function(srna, "itemS", "uiItemS"); + + /* templates */ + func= RNA_def_function(srna, "template_header", "uiTemplateHeader"); + + func= RNA_def_function(srna, "template_header_ID", "uiTemplateHeaderID"); + parm= RNA_def_pointer(func, "data", "AnyType", "", "Data from which to take property."); + RNA_def_property_flag(parm, PROP_REQUIRED); + parm= RNA_def_string(func, "property", "", 0, "", "Identifier of pointer property in data."); + RNA_def_property_flag(parm, PROP_REQUIRED); + RNA_def_string(func, "new", "", 0, "", "Operator identifier to create a new ID block."); + RNA_def_string(func, "open", "", 0, "", "Operator identifier to open a new ID block."); + RNA_def_string(func, "unlink", "", 0, "", "Operator identifier to unlink the ID block."); } diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index e0059041774..56acd755205 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -12,10 +12,12 @@ #include "DNA_windowmanager_types.h" #include "BLI_listbase.h" +#include "BLI_string.h" #include "BKE_context.h" #include "BKE_global.h" #include "BKE_idprop.h" +#include "BKE_library.h" #include "BKE_screen.h" #include "BKE_utildefines.h" @@ -38,16 +40,12 @@ /************************ Structs and Defines *************************/ -#define COLUMN_SPACE 5 -#define TEMPLATE_SPACE 5 -#define BOX_SPACE 5 -#define BUTTON_SPACE_X 5 -#define BUTTON_SPACE_Y 2 - #define RNA_NO_INDEX -1 +#define RNA_ENUM_VALUE -2 #define EM_UNIT_X XIC #define EM_UNIT_Y YIC +#define EM_SEPR_Y 6 /* Item */ @@ -55,7 +53,9 @@ typedef enum uiItemType { ITEM_OPERATOR, ITEM_RNA_PROPERTY, ITEM_MENU, - ITEM_LABEL + ITEM_LABEL, + ITEM_VALUE, + ITEM_SEPARATOR } uiItemType; enum uiItemFlag { @@ -69,7 +69,9 @@ typedef struct uiItem { int slot; char *name; + char namestr[UI_MAX_NAME_STR]; int icon; + int disabled; } uiItem; typedef struct uiItemRNA { @@ -77,7 +79,7 @@ typedef struct uiItemRNA { PointerRNA ptr; PropertyRNA *prop; - int index; + int index, value; int expand; } uiItemRNA; @@ -89,11 +91,19 @@ typedef struct uiItemOp { int context; } uiItemOp; -typedef struct uiItemLMenu { +typedef struct uiItemMenu { uiItem item; + char *menuname; uiMenuCreateFunc func; -} uiItemLMenu; + void *arg, *argN; +} uiItemMenu; + +typedef struct uiItemValue { + uiItem item; + + int argval; +} uiItemValue; /* Template */ @@ -104,8 +114,7 @@ typedef enum uiTemplateType { TEMPLATE_SPLIT, TEMPLATE_BOX, - TEMPLATE_HEADER_MENUS, - TEMPLATE_HEADER_BUTTONS, + TEMPLATE_HEADER, TEMPLATE_HEADER_ID } uiTemplateType; @@ -114,7 +123,7 @@ typedef struct uiTemplate { uiTemplateType type; ListBase items; - int color, slot; + int slot; } uiTemplate; typedef struct uiTemplateFlow { @@ -138,9 +147,13 @@ typedef struct uiTemplateHeadID { uiTemplate template; PointerRNA ptr; - char *propname; + PropertyRNA *prop; + int flag; - uiIDPoinFunc func; + short browse; + char *newop; + char *openop; + char *unlinkop; } uiTemplateHeadID; /* Layout */ @@ -148,9 +161,18 @@ typedef struct uiTemplateHeadID { struct uiLayout { ListBase templates; int opcontext; - int dir; + int dir, type; int x, y, w, h; int emw, emh; + + int column_space; + int template_space; + int box_space; + int button_space_x; + int button_space_y; + + uiMenuHandleFunc handlefunc; + void *argv; }; void ui_layout_free(uiLayout *layout); @@ -158,6 +180,14 @@ void ui_layout_end(const bContext *C, uiBlock *block, uiLayout *layout, int *x, /************************** Item ***************************/ +static void ui_item_name(uiItem *item, char *name) +{ + if(!item->name && name) { + BLI_strncpy(item->namestr, name, sizeof(item->namestr)); + item->name= item->namestr; + } +} + #define UI_FIT_EXPAND 1 static int ui_item_fit(int item, int pos, int all, int available, int spacing, int last, int flag) @@ -183,11 +213,10 @@ static int ui_item_fit(int item, int pos, int all, int available, int spacing, i } /* create buttons for an item with an RNA array */ -static void ui_item_array(uiBlock *block, uiItemRNA *rnaitem, int len, int x, int y, int w, int h) +static void ui_item_array(uiLayout *layout, uiBlock *block, uiItemRNA *rnaitem, int len, int x, int y, int w, int h) { PropertyType type; PropertySubType subtype; - char *name; int a; /* retrieve type and subtype */ @@ -195,13 +224,8 @@ static void ui_item_array(uiBlock *block, uiItemRNA *rnaitem, int len, int x, in subtype= RNA_property_subtype(rnaitem->prop); /* create label */ - if(rnaitem->item.name) - name= (char*)rnaitem->item.name; - else - name= (char*)RNA_property_ui_name(rnaitem->prop); - - if(strcmp(name, "") != 0) - uiDefBut(block, LABEL, 0, name, x, y + h - EM_UNIT_Y, w, EM_UNIT_Y, NULL, 0.0, 0.0, 0, 0, ""); + if(strcmp(rnaitem->item.name, "") != 0) + uiDefBut(block, LABEL, 0, rnaitem->item.name, x, y + h - EM_UNIT_Y, w, EM_UNIT_Y, NULL, 0.0, 0.0, 0, 0, ""); /* create buttons */ uiBlockBeginAlign(block); @@ -210,7 +234,7 @@ static void ui_item_array(uiBlock *block, uiItemRNA *rnaitem, int len, int x, in /* special check for layer layout */ int butw, buth; - butw= ui_item_fit(EM_UNIT_X, 0, EM_UNIT_X*10 + BUTTON_SPACE_X, w, 0, 0, UI_FIT_EXPAND); + butw= ui_item_fit(EM_UNIT_X, 0, EM_UNIT_X*10 + layout->button_space_x, w, 0, 0, UI_FIT_EXPAND); buth= MIN2(EM_UNIT_Y, butw); y += 2*(EM_UNIT_Y - buth); @@ -222,7 +246,7 @@ static void ui_item_array(uiBlock *block, uiItemRNA *rnaitem, int len, int x, in uiDefAutoButR(block, &rnaitem->ptr, rnaitem->prop, a+10, "", ICON_BLANK1, x + butw*a, y, butw, buth); uiBlockEndAlign(block); - x += 5*butw + BUTTON_SPACE_X; + x += 5*butw + layout->button_space_x; uiBlockBeginAlign(block); for(a=0; a<5; a++) @@ -305,16 +329,9 @@ static void ui_item_enum_row(uiBlock *block, uiItemRNA *rnaitem, int x, int y, i /* create label + button for RNA property */ static void ui_item_with_label(uiBlock *block, uiItemRNA *rnaitem, int x, int y, int w, int h) { - char *name; - - if(rnaitem->item.name) - name= (char*)rnaitem->item.name; - else - name= (char*)RNA_property_ui_name(rnaitem->prop); - - if(strcmp(name, "") != 0) { + if(strcmp(rnaitem->item.name, "") != 0) { w= w/2; - uiDefBut(block, LABEL, 0, name, x, y, w, h, NULL, 0.0, 0.0, 0, 0, ""); + uiDefBut(block, LABEL, 0, rnaitem->item.name, x, y, w, h, NULL, 0.0, 0.0, 0, 0, ""); x += w; } @@ -322,7 +339,7 @@ static void ui_item_with_label(uiBlock *block, uiItemRNA *rnaitem, int x, int y, } /* create buttons for an arbitrary item */ -static void ui_item_buts(uiBlock *block, uiItem *item, int x, int y, int w, int h) +static void ui_item_buts(uiLayout *layout, uiBlock *block, uiItem *item, int x, int y, int w, int h) { if(item->type == ITEM_RNA_PROPERTY) { /* RNA property */ @@ -336,7 +353,18 @@ static void ui_item_buts(uiBlock *block, uiItem *item, int x, int y, int w, int /* array property */ if(rnaitem->index == RNA_NO_INDEX && len > 0) - ui_item_array(block, rnaitem, len, x, y, w, h); + ui_item_array(layout, block, rnaitem, len, x, y, w, h); + /* enum item */ + else if(type == PROP_ENUM && rnaitem->index == RNA_ENUM_VALUE) { + char *identifier= (char*)RNA_property_identifier(rnaitem->prop); + + if(item->icon && strcmp(item->name, "") != 0) + uiDefIconTextButR(block, ROW, 0, item->icon, item->name, x, y, w, h, &rnaitem->ptr, identifier, -1, 0, rnaitem->value, -1, -1, NULL); + else if(item->icon) + uiDefIconButR(block, ROW, 0, item->icon, x, y, w, h, &rnaitem->ptr, identifier, -1, 0, rnaitem->value, -1, -1, NULL); + else + uiDefButR(block, ROW, 0, item->name, x, y, w, h, &rnaitem->ptr, identifier, -1, 0, rnaitem->value, -1, -1, NULL); + } /* expanded enum */ else if(type == PROP_ENUM && rnaitem->expand) ui_item_enum_row(block, rnaitem, x, y, w, h); @@ -352,7 +380,7 @@ static void ui_item_buts(uiBlock *block, uiItem *item, int x, int y, int w, int uiItemOp *opitem= (uiItemOp*)item; uiBut *but; - if(item->icon && item->name) + if(item->icon && strcmp(item->name, "") != 0) but= uiDefIconTextButO(block, BUT, opitem->ot->idname, opitem->context, item->icon, (char*)item->name, x, y, w, h, NULL); else if(item->icon) but= uiDefIconButO(block, BUT, opitem->ot->idname, opitem->context, item->icon, x, y, w, h, NULL); @@ -369,19 +397,53 @@ static void ui_item_buts(uiBlock *block, uiItem *item, int x, int y, int w, int } else if(item->type == ITEM_MENU) { /* menu */ - uiItemLMenu *menuitem= (uiItemLMenu*)item; + uiBut *but; + uiItemMenu *menuitem= (uiItemMenu*)item; - uiDefMenuBut(block, menuitem->func, NULL, (char*)item->name, x, y-2, w-3, h+4, ""); + if(layout->type == UI_LAYOUT_HEADER) { /* ugly .. */ + y -= 2; + w -= 3; + h += 4; + } + + if(item->icon) + but= uiDefIconTextMenuBut(block, menuitem->func, menuitem->arg, item->icon, (char*)item->name, x, y, w, h, ""); + else + but= uiDefMenuBut(block, menuitem->func, menuitem->arg, (char*)item->name, x, y, w, h, ""); + + if(menuitem->argN) { /* ugly .. */ + but->poin= (char*)but; + but->func_argN= menuitem->argN; + } } else if(item->type == ITEM_LABEL) { /* label */ + uiBut *but; - if(item->icon && item->name) - uiDefIconTextBut(block, LABEL, 0, item->icon, (char*)item->name, x, y, w, h, NULL, 0.0, 0.0, 0, 0, ""); + if(item->icon && strcmp(item->name, "") != 0) + but= uiDefIconTextBut(block, LABEL, 0, item->icon, (char*)item->name, x, y, w, h, NULL, 0.0, 0.0, 0, 0, ""); else if(item->icon) - uiDefIconBut(block, LABEL, 0, item->icon, x, y, w, h, NULL, 0.0, 0.0, 0, 0, ""); - else if((char*)item->name) - uiDefBut(block, LABEL, 0, (char*)item->name, x, y, w, h, NULL, 0.0, 0.0, 0, 0, ""); + but= uiDefIconBut(block, LABEL, 0, item->icon, x, y, w, h, NULL, 0.0, 0.0, 0, 0, ""); + else + but= uiDefBut(block, LABEL, 0, (char*)item->name, x, y, w, h, NULL, 0.0, 0.0, 0, 0, ""); + + if(item->disabled) { + but->flag |= UI_BUT_DISABLED; + but->lock = 1; + but->lockstr = ""; + } + } + else if(item->type == ITEM_VALUE) { + /* label */ + uiItemValue *vitem= (uiItemValue*)item; + float *retvalue= (block->handle)? &block->handle->retvalue: NULL; + + if(item->icon && strcmp(item->name, "") != 0) + uiDefIconTextButF(block, BUTM, 0, item->icon, (char*)item->name, x, y, w, h, retvalue, 0.0, 0.0, 0, vitem->argval, ""); + else if(item->icon) + uiDefIconButF(block, BUTM, 0, item->icon, x, y, w, h, retvalue, 0.0, 0.0, 0, vitem->argval, ""); + else + uiDefButF(block, BUTM, 0, (char*)item->name, x, y, w, h, retvalue, 0.0, 0.0, 0, vitem->argval, ""); } else { /* separator */ @@ -390,18 +452,21 @@ static void ui_item_buts(uiBlock *block, uiItem *item, int x, int y, int w, int } /* estimated size of text + icon */ -static int ui_text_icon_width(char *name, int icon) +static int ui_text_icon_width(char *name, int icon, int variable) { - if(icon && name && strcmp(name, "") == 0) + if(icon && strcmp(name, "") == 0) return EM_UNIT_X; /* icon only */ else if(icon) - return 10*EM_UNIT_X; /* icon + text */ + return (variable)? UI_GetStringWidth(name) + EM_UNIT_X: 10*EM_UNIT_X; /* icon + text */ else - return 10*EM_UNIT_X; /* text only */ + return (variable)? UI_GetStringWidth(name) + EM_UNIT_X: 10*EM_UNIT_X; /* text only */ } /* estimated size of an item */ -static void ui_item_size(uiItem *item, int *r_w, int *r_h) +#define UI_ITEM_VARY_X 1 +#define UI_ITEM_VARY_Y 2 + +static void ui_item_size(uiItem *item, int *r_w, int *r_h, int flag) { int w, h; @@ -412,7 +477,7 @@ static void ui_item_size(uiItem *item, int *r_w, int *r_h) PropertySubType subtype; int len; - w= ui_text_icon_width(item->name, item->icon); + w= ui_text_icon_width(item->name, item->icon, flag & UI_ITEM_VARY_X); h= EM_UNIT_Y; /* arbitrary extended width by type */ @@ -425,7 +490,7 @@ static void ui_item_size(uiItem *item, int *r_w, int *r_h) /* increase height for arrays */ if(rnaitem->index == RNA_NO_INDEX && len > 0) { - if(item->name && strcmp(item->name, "") == 0 && item->icon == 0) + if(strcmp(item->name, "") == 0 && item->icon == 0) h= 0; if(type == PROP_BOOLEAN && len == 20) @@ -435,11 +500,15 @@ static void ui_item_size(uiItem *item, int *r_w, int *r_h) else h += len*EM_UNIT_Y; } + else if(flag & UI_ITEM_VARY_X) { + if(type == PROP_BOOLEAN && strcmp(item->name, "") != 0) + w += EM_UNIT_X; + } } else { /* other */ - w= ui_text_icon_width(item->name, item->icon); - h= EM_UNIT_Y; + w= ui_text_icon_width(item->name, item->icon, flag & UI_ITEM_VARY_X); + h= (item->type == ITEM_SEPARATOR)? EM_SEPR_Y: EM_UNIT_Y; } if(r_w) *r_w= w; @@ -458,6 +527,25 @@ static void ui_item_free(uiItem *item) } } +/* disabled item */ +static void ui_item_disabled(uiLayout *layout, char *name) +{ + uiTemplate *template= layout->templates.last; + uiItem *item; + + if(!template) + return; + + item= MEM_callocN(sizeof(uiItem), "uiItem"); + + ui_item_name(item, name); + item->disabled= 1; + item->type= ITEM_LABEL; + item->slot= template->slot; + + BLI_addtail(&template->items, item); +} + /* operator items */ void uiItemFullO(uiLayout *layout, char *name, int icon, char *idname, IDProperty *properties, int context) { @@ -467,12 +555,14 @@ void uiItemFullO(uiLayout *layout, char *name, int icon, char *idname, IDPropert if(!template) return; - if(!ot) + if(!ot) { + ui_item_disabled(layout, idname); return; + } opitem= MEM_callocN(sizeof(uiItemOp), "uiItemOp"); - opitem->item.name= name; + ui_item_name(&opitem->item, name); opitem->item.icon= icon; opitem->item.type= ITEM_OPERATOR; opitem->item.slot= template->slot; @@ -484,6 +574,33 @@ void uiItemFullO(uiLayout *layout, char *name, int icon, char *idname, IDPropert BLI_addtail(&template->items, opitem); } +static char *ui_menu_enumpropname(char *opname, char *propname, int retval) +{ + wmOperatorType *ot= WM_operatortype_find(opname); + PointerRNA ptr; + PropertyRNA *prop; + + if(!ot || !ot->srna) + return ""; + + RNA_pointer_create(NULL, ot->srna, NULL, &ptr); + prop= RNA_struct_find_property(&ptr, propname); + + if(prop) { + const EnumPropertyItem *item; + int totitem, i; + + RNA_property_enum_items(&ptr, prop, &item, &totitem); + + for (i=0; i<totitem; i++) { + if(item[i].value==retval) + return (char*)item[i].name; + } + } + + return ""; +} + void uiItemEnumO(uiLayout *layout, char *name, int icon, char *opname, char *propname, int value) { PointerRNA ptr; @@ -491,6 +608,9 @@ void uiItemEnumO(uiLayout *layout, char *name, int icon, char *opname, char *pro WM_operator_properties_create(&ptr, opname); RNA_enum_set(&ptr, propname, value); + if(!name) + name= ui_menu_enumpropname(opname, propname, value); + uiItemFullO(layout, name, icon, opname, ptr.data, layout->opcontext); } @@ -500,8 +620,10 @@ void uiItemsEnumO(uiLayout *layout, char *opname, char *propname) PointerRNA ptr; PropertyRNA *prop; - if(!ot || !ot->srna) + if(!ot || !ot->srna) { + ui_item_disabled(layout, opname); return; + } RNA_pointer_create(NULL, ot->srna, NULL, &ptr); prop= RNA_struct_find_property(&ptr, propname); @@ -513,7 +635,7 @@ void uiItemsEnumO(uiLayout *layout, char *opname, char *propname) RNA_property_enum_items(&ptr, prop, &item, &totitem); for(i=0; i<totitem; i++) - uiItemEnumO(layout, "", 0, opname, propname, item[i].value); + uiItemEnumO(layout, NULL, 0, opname, propname, item[i].value); } } @@ -563,7 +685,7 @@ void uiItemO(uiLayout *layout, char *name, int icon, char *opname) } /* RNA property items */ -void uiItemFullR(uiLayout *layout, char *name, int icon, PointerRNA *ptr, PropertyRNA *prop, int index, int expand) +void uiItemFullR(uiLayout *layout, char *name, int icon, PointerRNA *ptr, PropertyRNA *prop, int index, int value, int expand) { uiTemplate *template= layout->templates.last; uiItemRNA *rnaitem; @@ -575,7 +697,7 @@ void uiItemFullR(uiLayout *layout, char *name, int icon, PointerRNA *ptr, Proper rnaitem= MEM_callocN(sizeof(uiItemRNA), "uiItemRNA"); - rnaitem->item.name= name; + ui_item_name(&rnaitem->item, name); rnaitem->item.icon= icon; rnaitem->item.type= ITEM_RNA_PROPERTY; rnaitem->item.slot= template->slot; @@ -583,6 +705,7 @@ void uiItemFullR(uiLayout *layout, char *name, int icon, PointerRNA *ptr, Proper rnaitem->ptr= *ptr; rnaitem->prop= prop; rnaitem->index= index; + rnaitem->value= value; rnaitem->expand= expand; BLI_addtail(&template->items, rnaitem); @@ -592,35 +715,90 @@ void uiItemR(uiLayout *layout, char *name, int icon, PointerRNA *ptr, char *prop { PropertyRNA *prop; + if(!ptr->data || !propname) + return; + prop= RNA_struct_find_property(ptr, propname); - if(!ptr->data) + if(!prop) { + ui_item_disabled(layout, propname); + printf("uiItemR: property not found: %s\n", propname); return; + } + + uiItemFullR(layout, name, icon, ptr, prop, RNA_NO_INDEX, 0, expand); +} + +void uiItemEnumR(uiLayout *layout, char *name, int icon, struct PointerRNA *ptr, char *propname, int value) +{ + PropertyRNA *prop; + + if(!ptr->data || !propname) + return; + + prop= RNA_struct_find_property(ptr, propname); + if(!prop) { - printf("uiItemR: property not found: %s\n",propname); + ui_item_disabled(layout, propname); + printf("uiItemEnumR: property not found: %s\n", propname); return; } - uiItemFullR(layout, name, icon, ptr, prop, RNA_NO_INDEX, expand); + uiItemFullR(layout, name, icon, ptr, prop, RNA_ENUM_VALUE, value, 0); +} + +void uiItemsEnumR(uiLayout *layout, struct PointerRNA *ptr, char *propname) +{ + PropertyRNA *prop; + + prop= RNA_struct_find_property(ptr, propname); + + if(!prop) { + ui_item_disabled(layout, propname); + return; + } + + if(RNA_property_type(prop) == PROP_ENUM) { + const EnumPropertyItem *item; + int totitem, i; + + RNA_property_enum_items(ptr, prop, &item, &totitem); + + for(i=0; i<totitem; i++) + uiItemEnumR(layout, (char*)item[i].name, 0, ptr, propname, item[i].value); + } } /* menu item */ -void uiItemM(uiLayout *layout, char *name, int icon, uiMenuCreateFunc func) +static void ui_item_menutype_func(bContext *C, uiLayout *layout, void *arg_mt) +{ + MenuType *mt= (MenuType*)arg_mt; + Menu menu = {0}; + + menu.type= mt; + menu.layout= layout; + mt->draw(C, &menu); +} + +void uiItemM(uiLayout *layout, char *name, int icon, char *menuname) { uiTemplate *template= layout->templates.last; - uiItemLMenu *menuitem; + uiItemMenu *menuitem; if(!template) return; + if(!menuname) + return; - menuitem= MEM_callocN(sizeof(uiItemLMenu), "uiItemLMenu"); + menuitem= MEM_callocN(sizeof(uiItemMenu), "uiItemMenu"); - menuitem->item.name= name; + ui_item_name(&menuitem->item, name); menuitem->item.icon= icon; menuitem->item.type= ITEM_MENU; menuitem->item.slot= template->slot; - menuitem->func= func; + menuitem->func= ui_item_menutype_func; + menuitem->menuname= menuname; BLI_addtail(&template->items, menuitem); } @@ -636,7 +814,7 @@ void uiItemL(uiLayout *layout, char *name, int icon) item= MEM_callocN(sizeof(uiItem), "uiItem"); - item->name= name; + ui_item_name(item, name); item->icon= icon; item->type= ITEM_LABEL; item->slot= template->slot; @@ -644,6 +822,168 @@ void uiItemL(uiLayout *layout, char *name, int icon) BLI_addtail(&template->items, item); } +/* value item */ +void uiItemV(uiLayout *layout, char *name, int icon, int argval) +{ + uiTemplate *template= layout->templates.last; + uiItemValue *vitem; + + if(!template) + return; + + vitem= MEM_callocN(sizeof(uiItemValue), "uiItemValue"); + + vitem->item.name= name; + vitem->item.icon= icon; + vitem->item.type= ITEM_VALUE; + vitem->item.slot= template->slot; + vitem->argval= argval; + + BLI_addtail(&template->items, vitem); +} + +/* separator item */ +void uiItemS(uiLayout *layout) +{ + uiTemplate *template= layout->templates.last; + uiItem *item; + + if(!template) + return; + + item= MEM_callocN(sizeof(uiItem), "uiItem"); + + item->type= ITEM_SEPARATOR; + item->slot= template->slot; + + BLI_addtail(&template->items, item); +} + +/* level items */ +void uiItemLevel(uiLayout *layout, char *name, int icon, uiMenuCreateFunc func) +{ + uiTemplate *template= layout->templates.last; + uiItemMenu *menuitem; + + if(!template) + return; + if(!func) + return; + + menuitem= MEM_callocN(sizeof(uiItemMenu), "uiItemMenu"); + + if(!icon) + icon= ICON_RIGHTARROW_THIN, + + ui_item_name(&menuitem->item, name); + menuitem->item.icon= icon; + menuitem->item.type= ITEM_MENU; + menuitem->item.slot= template->slot; + + menuitem->func= func; + + BLI_addtail(&template->items, menuitem); +} + +typedef struct MenuItemLevel { + int opcontext; + char *opname; + char *propname; + PointerRNA rnapoin; +} MenuItemLevel; + +static void menu_item_enum_opname_menu(bContext *C, uiLayout *layout, void *arg) +{ + MenuItemLevel *lvl= (MenuItemLevel*)(((uiBut*)arg)->func_argN); + + uiLayoutContext(layout, lvl->opcontext); + uiItemsEnumO(layout, lvl->opname, lvl->propname); +} + +void uiItemLevelEnumO(uiLayout *layout, char *name, int icon, char *opname, char *propname) +{ + wmOperatorType *ot= WM_operatortype_find(opname); + uiTemplate *template= layout->templates.last; + uiItemMenu *menuitem; + MenuItemLevel *lvl; + + if(!ot || !ot->srna) { + ui_item_disabled(layout, opname); + return; + } + if(!template) + return; + + menuitem= MEM_callocN(sizeof(uiItemMenu), "uiItemMenu"); + + if(!icon) + icon= ICON_RIGHTARROW_THIN; + if(!name) + name= ot->name; + + ui_item_name(&menuitem->item, name); + menuitem->item.icon= icon; + menuitem->item.type= ITEM_MENU; + menuitem->item.slot= template->slot; + + lvl= MEM_callocN(sizeof(MenuItemLevel), "MenuItemLevel"); + lvl->opname= opname; + lvl->propname= propname; + lvl->opcontext= layout->opcontext; + + menuitem->func= menu_item_enum_opname_menu; + menuitem->argN= lvl; + + BLI_addtail(&template->items, menuitem); +} + +static void menu_item_enum_rna_menu(bContext *C, uiLayout *layout, void *arg) +{ + MenuItemLevel *lvl= (MenuItemLevel*)(((uiBut*)arg)->func_argN); + + uiLayoutContext(layout, lvl->opcontext); + uiItemsEnumR(layout, &lvl->rnapoin, lvl->propname); +} + +void uiItemLevelEnumR(uiLayout *layout, char *name, int icon, struct PointerRNA *ptr, char *propname) +{ + uiTemplate *template= layout->templates.last; + uiItemMenu *menuitem; + MenuItemLevel *lvl; + PropertyRNA *prop; + + if(!template) + return; + + prop= RNA_struct_find_property(ptr, propname); + if(!prop) { + ui_item_disabled(layout, propname); + return; + } + + menuitem= MEM_callocN(sizeof(uiItemMenu), "uiItemMenu"); + + if(!icon) + icon= ICON_RIGHTARROW_THIN; + if(!name) + name= (char*)RNA_property_ui_name(prop); + + ui_item_name(&menuitem->item, name); + menuitem->item.icon= icon; + menuitem->item.type= ITEM_MENU; + menuitem->item.slot= template->slot; + + lvl= MEM_callocN(sizeof(MenuItemLevel), "MenuItemLevel"); + lvl->rnapoin= *ptr; + lvl->propname= propname; + lvl->opcontext= layout->opcontext; + + menuitem->func= menu_item_enum_rna_menu; + menuitem->argN= lvl; + + BLI_addtail(&template->items, menuitem); +} + /**************************** Template ***************************/ /* single row layout */ @@ -654,7 +994,7 @@ static void ui_layout_row(uiLayout *layout, uiBlock *block, uiTemplate *template /* estimate total width of buttons */ for(item=template->items.first; item; item=item->next) { - ui_item_size(item, &itemw, &itemh); + ui_item_size(item, &itemw, &itemh, UI_ITEM_VARY_Y); totw += itemw; maxh= MAX2(maxh, itemh); tot++; @@ -668,11 +1008,11 @@ static void ui_layout_row(uiLayout *layout, uiBlock *block, uiTemplate *template w= layout->w; for(item=template->items.first; item; item=item->next) { - ui_item_size(item, &itemw, &itemh); - itemw= ui_item_fit(itemw, x, totw, w, (tot-1)*BUTTON_SPACE_X, !item->next, UI_FIT_EXPAND); + ui_item_size(item, &itemw, &itemh, UI_ITEM_VARY_Y); + itemw= ui_item_fit(itemw, x, totw, w, (tot-1)*layout->button_space_x, !item->next, UI_FIT_EXPAND); - ui_item_buts(block, item, layout->x+x, layout->y-itemh, itemw, itemh); - x += itemw+BUTTON_SPACE_X; + ui_item_buts(layout, block, item, layout->x+x, layout->y-itemh, itemw, itemh); + x += itemw+layout->button_space_x; } layout->y -= maxh; @@ -699,20 +1039,20 @@ static void ui_layout_column(uiLayout *layout, uiBlock *block, uiTemplate *templ for(col=0; col<totcol; col++) { y= 0; - itemw= ui_item_fit(1, x, totcol, w, (totcol-1)*COLUMN_SPACE, col == totcol-1, UI_FIT_EXPAND); + itemw= ui_item_fit(1, x, totcol, w, (totcol-1)*layout->column_space, col == totcol-1, UI_FIT_EXPAND); for(item=template->items.first; item; item=item->next) { if(item->slot != col) continue; - ui_item_size(item, NULL, &itemh); + ui_item_size(item, NULL, &itemh, UI_ITEM_VARY_Y); y -= itemh; - ui_item_buts(block, item, layout->x+x, layout->y+y, itemw, itemh); - y -= BUTTON_SPACE_Y; + ui_item_buts(layout, block, item, layout->x+x, layout->y+y, itemw, itemh); + y -= layout->button_space_y; } - x += itemw + COLUMN_SPACE; + x += itemw + layout->column_space; miny= MIN2(miny, y); } @@ -731,7 +1071,7 @@ static void ui_layout_column_flow(uiLayout *layout, uiBlock *block, uiTemplate * toth= 0; totitem= 0; for(item=template->items.first; item; item=item->next) { - ui_item_size(item, &itemw, &itemh); + ui_item_size(item, &itemw, &itemh, UI_ITEM_VARY_Y); maxw= MAX2(maxw, itemw); toth += itemh; totitem++; @@ -760,18 +1100,18 @@ static void ui_layout_column_flow(uiLayout *layout, uiBlock *block, uiTemplate * /* create column per column */ col= 0; for(item=template->items.first; item; item=item->next) { - ui_item_size(item, NULL, &itemh); - itemw= ui_item_fit(1, x, totcol, w, (totcol-1)*COLUMN_SPACE, col == totcol-1, UI_FIT_EXPAND); + ui_item_size(item, NULL, &itemh, UI_ITEM_VARY_Y); + itemw= ui_item_fit(1, x, totcol, w, (totcol-1)*layout->column_space, col == totcol-1, UI_FIT_EXPAND); y -= itemh; emy -= itemh; - ui_item_buts(block, item, layout->x+x, layout->y+y, itemw, itemh); - y -= BUTTON_SPACE_Y; + ui_item_buts(layout, block, item, layout->x+x, layout->y+y, itemw, itemh); + y -= layout->button_space_y; miny= MIN2(miny, y); /* decide to go to next one */ if(col < totcol-1 && emy <= -emh) { - x += itemw + COLUMN_SPACE; + x += itemw + layout->column_space; y= 0; col++; } @@ -789,7 +1129,7 @@ static void ui_layout_split(uiLayout *layout, uiBlock *block, uiTemplate *templa /* estimate total width of buttons */ for(item=template->items.first; item; item=item->next) { - ui_item_size(item, &itemw, &itemh); + ui_item_size(item, &itemw, &itemh, UI_ITEM_VARY_Y); totw += itemw; maxh= MAX2(maxh, itemh); tot++; @@ -801,20 +1141,20 @@ static void ui_layout_split(uiLayout *layout, uiBlock *block, uiTemplate *templa /* create buttons starting from left and right */ lx= 0; rx= 0; - w= layout->w - BUTTON_SPACE_X*(tot-1) + BUTTON_SPACE_X; + w= layout->w - layout->button_space_x*(tot-1) + layout->button_space_x; for(item=template->items.first; item; item=item->next) { - ui_item_size(item, &itemw, &itemh); + ui_item_size(item, &itemw, &itemh, UI_ITEM_VARY_Y); if(item->slot == UI_TSLOT_LR_LEFT) { itemw= ui_item_fit(itemw, lx, totw, w, 0, 0); - ui_item_buts(block, item, layout->x+lx, layout->y-itemh, itemw, itemh); - lx += itemw + BUTTON_SPACE_X; + ui_item_buts(layout, block, item, layout->x+lx, layout->y-itemh, itemw, itemh); + lx += itemw + layout->button_space_x; } else { itemw= ui_item_fit(itemw, totw + rx, totw, w, 0, 0); - rx -= itemw + BUTTON_SPACE_X; - ui_item_buts(block, item, layout->x+layout->w+rx, layout->y-itemh, itemw, itemh); + rx -= itemw + layout->button_space_x; + ui_item_buts(layout, block, item, layout->x+layout->w+rx, layout->y-itemh, itemw, itemh); } } @@ -836,7 +1176,7 @@ static void ui_layout_split(const bContext *C, uiLayout *layout, uiBlock *block, for(a=0; a<split->number; a++) { sublayout= split->sublayout[a]; - splitw= ui_item_fit(1, x, split->number, w, (split->number-1)*COLUMN_SPACE, a == split->number-1, UI_FIT_EXPAND); + splitw= ui_item_fit(1, x, split->number, w, (split->number-1)*layout->column_space, a == split->number-1, UI_FIT_EXPAND); sublayout->x= layout->x + x; sublayout->w= splitw; sublayout->y= layout->y; @@ -849,7 +1189,7 @@ static void ui_layout_split(const bContext *C, uiLayout *layout, uiBlock *block, ui_layout_end(C, block, sublayout, NULL, &y); miny= MIN2(y, miny); - x += splitw + COLUMN_SPACE; + x += splitw + layout->column_space; } layout->y= miny; @@ -865,9 +1205,9 @@ static void ui_layout_box(const bContext *C, uiLayout *layout, uiBlock *block, u starty= layout->y; /* some extra padding */ - box->sublayout->x= layout->x + BOX_SPACE; - box->sublayout->w= w - 2*BOX_SPACE; - box->sublayout->y= layout->y - BOX_SPACE; + box->sublayout->x= layout->x + layout->box_space; + box->sublayout->w= w - 2*layout->box_space; + box->sublayout->y= layout->y - layout->box_space; box->sublayout->h= h; box->sublayout->emw= layout->emw; @@ -888,15 +1228,15 @@ static void ui_layout_header_buttons(uiLayout *layout, uiBlock *block, uiTemplat uiBlockBeginAlign(block); for(item=template->items.first; item; item=item->next) { - ui_item_size(item, &itemw, &itemh); - ui_item_buts(block, item, layout->x, layout->y, itemw, itemh); + ui_item_size(item, &itemw, &itemh, UI_ITEM_VARY_X); + ui_item_buts(layout, block, item, layout->x, layout->y, itemw, itemh); layout->x += itemw; } uiBlockEndAlign(block); } -static void ui_layout_header_menus(const bContext *C, uiLayout *layout, uiBlock *block, uiTemplate *template) +static void ui_layout_header(const bContext *C, uiLayout *layout, uiBlock *block, uiTemplate *template) { ScrArea *sa= CTX_wm_area(C); @@ -910,16 +1250,127 @@ static void ui_layout_header_menus(const bContext *C, uiLayout *layout, uiBlock uiBlockSetEmboss(block, UI_EMBOSS); } +static void header_id_cb(bContext *C, void *arg_template, void *arg_event) +{ + uiTemplateHeadID *idtemplate= (uiTemplateHeadID*)arg_template; + PointerRNA idptr= RNA_property_pointer_get(&idtemplate->ptr, idtemplate->prop); + ID *idtest, *id= idptr.data; + ListBase *lb= wich_libbase(CTX_data_main(C), ID_TXT); // XXX + int nr, event= GET_INT_FROM_POINTER(arg_event); + + if(event == UI_ID_BROWSE && idtemplate->browse == 32767) + event= UI_ID_ADD_NEW; + else if(event == UI_ID_BROWSE && idtemplate->browse == 32766) + event= UI_ID_OPEN; + + switch(event) { + case UI_ID_BROWSE: { + if(id==0) id= lb->first; + if(id==0) return; + + if(idtemplate->browse== -2) { + /* XXX implement or find a replacement + * activate_databrowse((ID *)G.buts->lockpoin, GS(id->name), 0, B_MESHBROWSE, &idtemplate->browse, do_global_buttons); */ + return; + } + if(idtemplate->browse < 0) + return; + + for(idtest=lb->first, nr=1; idtest; idtest=idtest->next, nr++) { + if(nr==idtemplate->browse) { + if(id == idtest) + return; + + id= idtest; + RNA_id_pointer_create(id, &idptr); + RNA_property_pointer_set(&idtemplate->ptr, idtemplate->prop, idptr); + RNA_property_update(C, &idtemplate->ptr, idtemplate->prop); + /* XXX */ + + break; + } + } + break; + } +#if 0 + case UI_ID_DELETE: + id= NULL; + break; + case UI_ID_FAKE_USER: + if(id) { + if(id->flag & LIB_FAKEUSER) id->us++; + else id->us--; + } + else return; + break; +#endif + case UI_ID_PIN: + break; + case UI_ID_ADD_NEW: + WM_operator_name_call(C, idtemplate->newop, WM_OP_INVOKE_REGION_WIN, NULL); + break; + case UI_ID_OPEN: + WM_operator_name_call(C, idtemplate->openop, WM_OP_INVOKE_REGION_WIN, NULL); + break; +#if 0 + case UI_ID_ALONE: + if(!id || id->us < 1) + return; + break; + case UI_ID_LOCAL: + if(!id || id->us < 1) + return; + break; + case UI_ID_AUTO_NAME: + break; +#endif + } +} + static void ui_layout_header_id(const bContext *C, uiLayout *layout, uiBlock *block, uiTemplate *template) { - uiTemplateHeadID *idtemplate= (uiTemplateHeadID*)template; - PointerRNA idptr; + uiTemplateHeadID *duptemplate, *idtemplate= (uiTemplateHeadID*)template; + uiBut *but; + PointerRNA idptr= RNA_property_pointer_get(&idtemplate->ptr, idtemplate->prop); + ListBase *lb= wich_libbase(CTX_data_main(C), ID_TXT); // XXX + + if(idtemplate->flag & UI_ID_BROWSE) { + char *extrastr, *str; + + if((idtemplate->flag & UI_ID_ADD_NEW) && (idtemplate->flag && UI_ID_OPEN)) + extrastr= "OPEN NEW %x 32766 |ADD NEW %x 32767"; + else if(idtemplate->flag & UI_ID_ADD_NEW) + extrastr= "ADD NEW %x 32767"; + else if(idtemplate->flag & UI_ID_OPEN) + extrastr= "OPEN NEW %x 32766"; + else + extrastr= NULL; - idptr= RNA_pointer_get(&idtemplate->ptr, idtemplate->propname); + duptemplate= MEM_dupallocN(idtemplate); + IDnames_to_pupstring(&str, NULL, extrastr, lb, idptr.data, &duptemplate->browse); - layout->x= uiDefIDPoinButs(block, CTX_data_main(C), NULL, (ID*)idptr.data, ID_TXT, NULL, - layout->x, layout->y, idtemplate->func, - UI_ID_BROWSE|UI_ID_RENAME|UI_ID_ADD_NEW|UI_ID_OPEN|UI_ID_DELETE); + but= uiDefButS(block, MENU, 0, str, layout->x, layout->y, EM_UNIT_X, EM_UNIT_Y, &duptemplate->browse, 0, 0, 0, 0, "Browse existing choices, or add new"); + uiButSetNFunc(but, header_id_cb, duptemplate, SET_INT_IN_POINTER(UI_ID_BROWSE)); + layout->x+= EM_UNIT_X; + + MEM_freeN(str); + } + + /* text button with name */ + if(idptr.data) { + char name[64]; + + text_idbutton(idptr.data, name); + but= uiDefButR(block, TEX, 0, name, layout->x, layout->y, EM_UNIT_X*6, EM_UNIT_Y, &idptr, "name", -1, 0, 0, -1, -1, NULL); + uiButSetNFunc(but, header_id_cb, MEM_dupallocN(idtemplate), SET_INT_IN_POINTER(UI_ID_RENAME)); + layout->x += EM_UNIT_X*6; + + /* delete button */ + if(idtemplate->flag & UI_ID_DELETE) { + but= uiDefIconButO(block, BUT, idtemplate->unlinkop, WM_OP_EXEC_REGION_WIN, ICON_X, layout->x, layout->y, EM_UNIT_X, EM_UNIT_Y, NULL); + layout->x += EM_UNIT_X; + } + } } void ui_template_free(uiTemplate *template) @@ -982,7 +1433,7 @@ uiLayout *uiLayoutBox(uiLayout *layout) box= MEM_callocN(sizeof(uiTemplateBx), "uiTemplateBx"); box->template.type= TEMPLATE_BOX; - box->sublayout= uiLayoutBegin(layout->dir, 0, 0, 0, 0); + box->sublayout= uiLayoutBegin(layout->dir, layout->type, 0, 0, 0, 0); BLI_addtail(&layout->templates, box); return box->sublayout; @@ -1000,7 +1451,7 @@ void uiLayoutSplit(uiLayout *layout, int number, int lr) split->sublayout= MEM_callocN(sizeof(uiLayout*)*number, "uiTemplateSpltSub"); for(a=0; a<number; a++) - split->sublayout[a]= uiLayoutBegin(layout->dir, 0, 0, 0, 0); + split->sublayout[a]= uiLayoutBegin(layout->dir, layout->type, 0, 0, 0, 0); BLI_addtail(&layout->templates, split); } @@ -1026,46 +1477,51 @@ uiLayout *uiLayoutSub(uiLayout *layout, int n) return NULL; } -void uiTemplateHeaderMenus(uiLayout *layout) +void uiTemplateHeader(uiLayout *layout) { uiTemplate *template; template= MEM_callocN(sizeof(uiTemplate), "uiTemplate"); - template->type= TEMPLATE_HEADER_MENUS; + template->type= TEMPLATE_HEADER; BLI_addtail(&layout->templates, template); } -void uiTemplateHeaderButtons(uiLayout *layout) +void uiTemplateHeaderID(uiLayout *layout, PointerRNA *ptr, char *propname, char *newop, char *openop, char *unlinkop) { - uiTemplate *template; + uiTemplateHeadID *idtemplate; + PropertyRNA *prop; - template= MEM_callocN(sizeof(uiTemplate), "uiTemplate"); - template->type= TEMPLATE_HEADER_BUTTONS; + if(!ptr->data) + return; - BLI_addtail(&layout->templates, template); -} + prop= RNA_struct_find_property(ptr, propname); -void uiTemplateHeaderID(uiLayout *layout, PointerRNA *ptr, char *propname, int flag, uiIDPoinFunc func) -{ - uiTemplateHeadID *idtemplate; + if(!prop) { + printf("uiTemplateHeaderID: property not found: %s\n", propname); + return; + } idtemplate= MEM_callocN(sizeof(uiTemplateHeadID), "uiTemplateHeadID"); idtemplate->template.type= TEMPLATE_HEADER_ID; idtemplate->ptr= *ptr; - idtemplate->propname= propname; - idtemplate->flag= flag; - idtemplate->func= func; + idtemplate->prop= prop; + idtemplate->flag= UI_ID_BROWSE|UI_ID_RENAME; - BLI_addtail(&layout->templates, idtemplate); -} - -void uiTemplateSetColor(uiLayout *layout, int color) -{ - uiTemplate *template= layout->templates.last; + if(newop) { + idtemplate->flag |= UI_ID_ADD_NEW; + idtemplate->newop= newop; + } + if(openop) { + idtemplate->flag |= UI_ID_OPEN; + idtemplate->openop= openop; + } + if(unlinkop) { + idtemplate->flag |= UI_ID_DELETE; + idtemplate->unlinkop= unlinkop; + } - if(template) - template->color= color; + BLI_addtail(&layout->templates, idtemplate); } void uiTemplateSlot(uiLayout *layout, int slot) @@ -1078,35 +1534,88 @@ void uiTemplateSlot(uiLayout *layout, int slot) /********************** Layout *******************/ +static void ui_layout_init_items(const bContext *C, uiLayout *layout) +{ + ARegion *ar= CTX_wm_region(C); + MenuType *mt; + uiTemplate *template; + uiItem *item; + uiItemMenu *menuitem; + uiItemRNA *rnaitem; + uiItemOp *opitem; + PropertyType type; + + for(template=layout->templates.first; template; template=template->next) { + for(item=template->items.first; item; item=item->next) { + /* initialize buttons names */ + if(item->type == ITEM_MENU) { + menuitem= (uiItemMenu*)item; + + if(menuitem->menuname) { + for(mt=ar->type->menutypes.first; mt; mt=mt->next) { + if(strcmp(menuitem->menuname, mt->idname) == 0) { + menuitem->arg= mt; + ui_item_name(item, mt->label); + break; + } + } + } + } + else if(item->type == ITEM_RNA_PROPERTY) { + rnaitem= (uiItemRNA*)item; + ui_item_name(item, (char*)RNA_property_ui_name(rnaitem->prop)); + } + else if(item->type == ITEM_OPERATOR) { + opitem= (uiItemOp*)item; + ui_item_name(item, opitem->ot->name); + } + + ui_item_name(item, ""); + + /* initialize icons */ + if(layout->type == UI_LAYOUT_MENU) { + if(item->type == ITEM_RNA_PROPERTY) { + rnaitem= (uiItemRNA*)item; + type= RNA_property_type(rnaitem->prop); + + if(type == PROP_BOOLEAN) + item->icon= (RNA_property_boolean_get(&rnaitem->ptr, rnaitem->prop))? ICON_CHECKBOX_HLT: ICON_CHECKBOX_DEHLT; + else if(type == PROP_ENUM && rnaitem->index == RNA_ENUM_VALUE) + item->icon= (RNA_property_enum_get(&rnaitem->ptr, rnaitem->prop) == rnaitem->value)? ICON_CHECKBOX_HLT: ICON_CHECKBOX_DEHLT; + } + + if(!item->icon) + item->icon= ICON_BLANK1; + } + } + } +} + static void ui_layout_templates(const bContext *C, uiBlock *block, uiLayout *layout) { uiTemplate *template; + ui_layout_init_items(C, layout); + if(layout->dir == UI_LAYOUT_HORIZONTAL) { for(template=layout->templates.first; template; template=template->next) { switch(template->type) { - case TEMPLATE_HEADER_MENUS: - ui_layout_header_menus(C, layout, block, template); + case TEMPLATE_HEADER: + ui_layout_header(C, layout, block, template); break; case TEMPLATE_HEADER_ID: ui_layout_header_id(C, layout, block, template); break; - case TEMPLATE_HEADER_BUTTONS: default: ui_layout_header_buttons(layout, block, template); break; } - } - layout->x += TEMPLATE_SPACE; + layout->x += layout->template_space; + } } else { for(template=layout->templates.first; template; template=template->next) { - if(template->color) { - // XXX oldcolor= uiBlockGetCol(block); - // XXX uiBlockSetCol(block, template->color); - } - switch(template->type) { case TEMPLATE_ROW: ui_layout_row(layout, block, template); @@ -1126,16 +1635,16 @@ static void ui_layout_templates(const bContext *C, uiBlock *block, uiLayout *lay break; } - // XXX if(template->color) - // XXX uiBlockSetCol(block, oldcolor); - - layout->y -= TEMPLATE_SPACE; + layout->y -= layout->template_space; } } } void ui_layout_end(const bContext *C, uiBlock *block, uiLayout *layout, int *x, int *y) { + if(layout->handlefunc) + uiBlockSetButmFunc(block, layout->handlefunc, layout->argv); + ui_layout_templates(C, block, layout); if(x) *x= layout->x; @@ -1154,16 +1663,23 @@ void ui_layout_free(uiLayout *layout) MEM_freeN(layout); } -uiLayout *uiLayoutBegin(int dir, int x, int y, int size, int em) +uiLayout *uiLayoutBegin(int dir, int type, int x, int y, int size, int em) { uiLayout *layout; layout= MEM_callocN(sizeof(uiLayout), "uiLayout"); layout->opcontext= WM_OP_INVOKE_REGION_WIN; layout->dir= dir; + layout->type= type; layout->x= x; layout->y= y; + layout->column_space= 5; + layout->template_space= 5; + layout->box_space= 5; + layout->button_space_x= 5; + layout->button_space_y= 2; + if(dir == UI_LAYOUT_HORIZONTAL) { layout->h= size; layout->emh= em*EM_UNIT_Y; @@ -1181,6 +1697,12 @@ void uiLayoutContext(uiLayout *layout, int opcontext) layout->opcontext= opcontext; } +void uiLayoutFunc(uiLayout *layout, uiMenuHandleFunc handlefunc, void *argv) +{ + layout->handlefunc= handlefunc; + layout->argv= argv; +} + void uiLayoutEnd(const bContext *C, uiBlock *block, uiLayout *layout, int *x, int *y) { ui_layout_end(C, block, layout, x, y); @@ -1229,7 +1751,7 @@ void uiRegionPanelLayout(const bContext *C, ARegion *ar, int vertical, char *con } panel->type= pt; - panel->layout= uiLayoutBegin(UI_LAYOUT_VERTICAL, PNL_SAFETY, 0, w-2*PNL_SAFETY, em); + panel->layout= uiLayoutBegin(UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, PNL_SAFETY, 0, w-2*PNL_SAFETY, em); pt->draw(C, panel); @@ -1286,7 +1808,7 @@ void uiRegionHeaderLayout(const bContext *C, ARegion *ar) /* draw all headers types */ for(ht= ar->type->headertypes.first; ht; ht= ht->next) { block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS); - layout= uiLayoutBegin(UI_LAYOUT_HORIZONTAL, xco, yco, 24, 1); + layout= uiLayoutBegin(UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER, xco, yco, 24, 1); if(ht->draw) { header.type= ht; diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index 181513b58bc..7bc7e2e3c19 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -1643,30 +1643,14 @@ static uiBlock *ui_block_func_MENU_ITEM(bContext *C, uiPopupBlockHandle *handle, #define MENU_ITEM_LEVEL_OPNAME_ENUM 31 #define MENU_ITEM_LEVEL_RNA_ENUM 32 -struct uiMenuItem { - struct uiMenuItem *next, *prev; - - int type; +struct uiPopupMenu { + uiLayout *layout; int icon; char name[MAX_MENU_STR]; - - char *opname; /* static string */ - char *propname; /* static string */ - - int retval, enumval, boolval, intval; - float fltval; - char *strval; - int opcontext; - uiMenuHandleFunc eventfunc; - void *argv; - uiMenuCreateFunc newlevel; - PointerRNA rnapoin; - - ListBase items; }; typedef struct uiMenuInfo { - uiMenuItem *head; + uiPopupMenu *pup; int mx, my, popup, slideout; int startx, starty; } uiMenuInfo; @@ -1707,201 +1691,49 @@ typedef struct MenuItemLevel { PointerRNA rnapoin; } MenuItemLevel; -/* make a menu level from enum properties */ -static void menu_item_enum_opname_menu(bContext *C, uiMenuItem *head, void *arg) -{ - MenuItemLevel *lvl= (MenuItemLevel*)(((uiBut*)arg)->func_argN); - - head->opcontext= lvl->opcontext; - uiMenuItemsEnumO(head, lvl->opname, lvl->propname); -} - -static void menu_item_enum_rna_menu(bContext *C, uiMenuItem *head, void *arg) -{ - MenuItemLevel *lvl= (MenuItemLevel*)(((uiBut*)arg)->func_argN); - - head->opcontext= lvl->opcontext; - uiMenuItemsEnumR(head, &lvl->rnapoin, lvl->propname); -} - static uiBlock *ui_block_func_MENU_ITEM(bContext *C, uiPopupBlockHandle *handle, void *arg_info) { uiBlock *block; uiBut *but; uiMenuInfo *info= arg_info; - uiMenuItem *head, *item; - MenuItemLevel *lvl; + uiPopupMenu *pup; ScrArea *sa; ARegion *ar; static int counter= 0; - int width, height, icon; - int startx, starty, x1, y1; char str[16]; - head= info->head; - height= 0; + pup= info->pup; /* block stuff first, need to know the font */ sprintf(str, "tb %d", counter++); block= uiBeginBlock(C, handle->region, str, UI_EMBOSSP); - uiBlockSetButmFunc(block, head->eventfunc, head->argv); block->direction= UI_DOWN; - width= 50; // fixed with, uiMenuPopupBoundsBlock will compute actual width - - for(item= head->items.first; item; item= item->next) { - if(0) height+= PUP_LABELH; // XXX sepr line - else height+= MENU_BUTTON_HEIGHT; - } - - startx= 0; - starty= 0; - /* here we go! */ - if(head->name[0]) { + if(pup->name[0]) { char titlestr[256]; - if(head->icon) { - width+= 20; - sprintf(titlestr, " %s", head->name); - uiDefIconTextBut(block, LABEL, 0, head->icon, titlestr, startx, (short)(starty+height), width, MENU_BUTTON_HEIGHT, NULL, 0.0, 0.0, 0, 0, ""); + if(pup->icon) { + sprintf(titlestr, " %s", pup->name); + uiDefIconTextBut(block, LABEL, 0, pup->icon, titlestr, 0, 0, 200, MENU_BUTTON_HEIGHT, NULL, 0.0, 0.0, 0, 0, ""); } else { - but= uiDefBut(block, LABEL, 0, head->name, startx, (short)(starty+height), width, MENU_BUTTON_HEIGHT, NULL, 0.0, 0.0, 0, 0, ""); + but= uiDefBut(block, LABEL, 0, pup->name, 0, 0, 200, MENU_BUTTON_HEIGHT, NULL, 0.0, 0.0, 0, 0, ""); but->flag= UI_TEXT_LEFT; } //uiDefBut(block, SEPR, 0, "", startx, (short)(starty+height)-MENU_SEPR_HEIGHT, width, MENU_SEPR_HEIGHT, NULL, 0.0, 0.0, 0, 0, ""); } - x1= startx; - y1= starty + height - MENU_BUTTON_HEIGHT; // - MENU_SEPR_HEIGHT; - - for(item= head->items.first; item; item= item->next) { - - if(item->type==MENU_ITEM_LEVEL) { - uiDefIconTextMenuBut(block, item->newlevel, NULL, ICON_RIGHTARROW_THIN, item->name, x1, y1, width+16, MENU_BUTTON_HEIGHT-1, NULL); - y1 -= MENU_BUTTON_HEIGHT; - } - else if(item->type==MENU_ITEM_LEVEL_OPNAME_ENUM) { - but= uiDefIconTextMenuBut(block, menu_item_enum_opname_menu, NULL, ICON_RIGHTARROW_THIN, item->name, x1, y1, width+16, MENU_BUTTON_HEIGHT-1, NULL); - - /* XXX warning, abuse of func_arg! */ - lvl= MEM_callocN(sizeof(MenuItemLevel), "MenuItemLevel"); - lvl->opname= item->opname; - lvl->propname= item->propname; - lvl->opcontext= item->opcontext; - - but->poin= (char*)but; - but->func_argN= lvl; - - y1 -= MENU_BUTTON_HEIGHT; - } - else if(item->type==MENU_ITEM_LEVEL_RNA_ENUM) { - but= uiDefIconTextMenuBut(block, menu_item_enum_rna_menu, NULL, ICON_RIGHTARROW_THIN, item->name, x1, y1, width+16, MENU_BUTTON_HEIGHT-1, NULL); - - /* XXX warning, abuse of func_arg! */ - lvl= MEM_callocN(sizeof(MenuItemLevel), "MenuItemLevel"); - lvl->rnapoin= item->rnapoin; - lvl->propname= item->propname; - lvl->opcontext= item->opcontext; - - but->poin= (char*)but; - but->func_argN= lvl; - - y1 -= MENU_BUTTON_HEIGHT; - } - else if(item->type==MENU_ITEM_OPNAME_BOOL) { - but= uiDefIconTextButO(block, BUTM, item->opname, item->opcontext, item->icon, item->name, x1, y1, width+16, MENU_BUTTON_HEIGHT-1, ""); - RNA_boolean_set(uiButGetOperatorPtrRNA(but), item->propname, item->boolval); - - y1 -= MENU_BUTTON_HEIGHT; - } - else if(item->type==MENU_ITEM_OPNAME_ENUM) { - const char *name; - char bname[64]; - - /* If no name is given, use the enum name */ - if (item->name[0] == '\0') - name= ui_menu_enumpropname(item->opname, item->propname, item->enumval); - else - name= item->name; - - BLI_strncpy(bname, name, sizeof(bname)); - - but= uiDefIconTextButO(block, BUTM, item->opname, item->opcontext, item->icon, bname, x1, y1, width+16, MENU_BUTTON_HEIGHT-1, ""); - RNA_enum_set(uiButGetOperatorPtrRNA(but), item->propname, item->enumval); - - y1 -= MENU_BUTTON_HEIGHT; - } - else if(item->type==MENU_ITEM_OPNAME_INT) { - but= uiDefIconTextButO(block, BUTM, item->opname, head->opcontext, item->icon, item->name, x1, y1, width+16, MENU_BUTTON_HEIGHT-1, ""); - RNA_int_set(uiButGetOperatorPtrRNA(but), item->propname, item->intval); - - y1 -= MENU_BUTTON_HEIGHT; - } - else if(item->type==MENU_ITEM_OPNAME_FLOAT) { - but= uiDefIconTextButO(block, BUTM, item->opname, item->opcontext, item->icon, item->name, x1, y1, width+16, MENU_BUTTON_HEIGHT-1, ""); - RNA_float_set(uiButGetOperatorPtrRNA(but), item->propname, item->fltval); - - y1 -= MENU_BUTTON_HEIGHT; - } - else if(item->type==MENU_ITEM_OPNAME_STRING) { - but= uiDefIconTextButO(block, BUTM, item->opname, item->opcontext, item->icon, item->name, x1, y1, width+16, MENU_BUTTON_HEIGHT-1, ""); - RNA_string_set(uiButGetOperatorPtrRNA(but), item->propname, item->strval); - - y1 -= MENU_BUTTON_HEIGHT; - } - else if(item->type==MENU_ITEM_OPNAME) { - uiDefIconTextButO(block, BUTM, item->opname, item->opcontext, item->icon, NULL, x1, y1, width+16, MENU_BUTTON_HEIGHT-1, NULL); - y1 -= MENU_BUTTON_HEIGHT; - } - else if(item->type==MENU_ITEM_RNA_BOOL) { - PropertyRNA *prop= RNA_struct_find_property(&item->rnapoin, item->propname); - - if(prop && RNA_property_type(prop) == PROP_BOOLEAN) { - icon= (RNA_property_boolean_get(&item->rnapoin, prop))? ICON_CHECKBOX_HLT: ICON_CHECKBOX_DEHLT; - uiDefIconTextButR(block, TOG, 0, icon, NULL, x1, y1, width+16, MENU_BUTTON_HEIGHT-1, &item->rnapoin, item->propname, 0, 0, 0, 0, 0, NULL); - } - else { - uiBlockSetButLock(block, 1, ""); - uiDefIconTextBut(block, BUT, 0, ICON_BLANK1, item->propname, x1, y1, width+16, MENU_BUTTON_HEIGHT-1, NULL, 0.0, 0.0, 0, 0, ""); - uiBlockClearButLock(block); - } - - y1 -= MENU_BUTTON_HEIGHT; - } - else if(item->type==MENU_ITEM_RNA_ENUM) { - PropertyRNA *prop= RNA_struct_find_property(&item->rnapoin, item->propname); - - if(prop && RNA_property_type(prop) == PROP_ENUM) { - icon= (RNA_property_enum_get(&item->rnapoin, prop) == item->enumval)? ICON_CHECKBOX_HLT: ICON_CHECKBOX_DEHLT; - uiDefIconTextButR(block, ROW, 0, icon, NULL, x1, y1, width+16, MENU_BUTTON_HEIGHT-1, &item->rnapoin, item->propname, 0, 0, item->enumval, 0, 0, NULL); - } - else { - uiBlockSetButLock(block, 1, ""); - uiDefIconTextBut(block, BUT, 0, ICON_BLANK1, item->propname, x1, y1, width+16, MENU_BUTTON_HEIGHT-1, NULL, 0.0, 0.0, 0, 0, ""); - uiBlockClearButLock(block); - } - - y1 -= MENU_BUTTON_HEIGHT; - } - else if(item->type == MENU_ITEM_ITEM) { - uiDefIconTextButF(block, BUTM, B_NOP, item->icon, item->name, x1, y1, width+16, MENU_BUTTON_HEIGHT-1, &handle->retvalue, 0.0, 0.0, 0, item->retval, ""); - y1 -= MENU_BUTTON_HEIGHT; - } - else { - uiDefBut(block, SEPR, 0, "", x1, y1, width+16, MENU_SEPR_HEIGHT-1, NULL, 0.0, 0.0, 0, 0, ""); - y1 -= MENU_SEPR_HEIGHT; - } - } + block->handle= handle; + uiLayoutEnd(C, block, pup->layout, NULL, NULL); if(info->popup) { uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_NUMSELECT|UI_BLOCK_RET_1); uiBlockSetDirection(block, UI_DOWN); /* here we set an offset for the mouse position */ - uiMenuPopupBoundsBlock(block, 1, 0, -height+MENU_BUTTON_HEIGHT/2); + uiMenuPopupBoundsBlock(block, 1, 0, MENU_BUTTON_HEIGHT/2); } else { /* for a header menu we set the direction automatic */ @@ -1932,262 +1764,51 @@ static uiBlock *ui_block_func_MENU_ITEM(bContext *C, uiPopupBlockHandle *handle, uiPopupBlockHandle *ui_popup_menu_create(bContext *C, ARegion *butregion, uiBut *but, uiMenuCreateFunc menu_func, void *arg) { uiPopupBlockHandle *handle; - uiMenuItem *head; + uiPopupMenu *pup; uiMenuInfo info; - head= MEM_callocN(sizeof(uiMenuItem), "menu dummy"); - head->opcontext= WM_OP_INVOKE_REGION_WIN; + pup= MEM_callocN(sizeof(uiPopupMenu), "menu dummy"); + pup->layout= uiLayoutBegin(UI_LAYOUT_VERTICAL, UI_LAYOUT_MENU, 0, 0, 200, 0); + uiLayoutContext(pup->layout, WM_OP_INVOKE_REGION_WIN); + uiLayoutColumn(pup->layout); - menu_func(C, head, arg); + menu_func(C, pup->layout, arg); memset(&info, 0, sizeof(info)); - info.head= head; + info.pup= pup; info.slideout= (but && (but->block->flag & UI_BLOCK_LOOP)); handle= ui_popup_block_create(C, butregion, but, NULL, ui_block_func_MENU_ITEM, &info); - BLI_freelistN(&head->items); - MEM_freeN(head); + MEM_freeN(pup); return handle; } /*************************** Menu Creating API **************************/ -/* internal add func */ -static uiMenuItem *ui_menu_add_item(uiMenuItem *head, const char *name, int icon, int argval) -{ - uiMenuItem *item= MEM_callocN(sizeof(uiMenuItem), "menu item"); - - BLI_strncpy(item->name, name, MAX_MENU_STR); - if(icon) - item->icon= icon; - else - item->icon= ICON_BLANK1; - item->retval= argval; - - item->opcontext= head->opcontext; - - BLI_addtail(&head->items, item); - - return item; -} - -/* set callback for regular items */ -void uiMenuFunc(uiMenuItem *head, void (*eventfunc)(bContext *, void *, int), void *argv) -{ - head->eventfunc= eventfunc; - head->argv= argv; -} - -/* optionally set different context for all items in one level */ -void uiMenuContext(uiMenuItem *head, int opcontext) -{ - head->opcontext= opcontext; -} - - -/* regular item, with retval */ -void uiMenuItemVal(uiMenuItem *head, const char *name, int icon, int argval) -{ - uiMenuItem *item= ui_menu_add_item(head, name, icon, argval); - - item->type = MENU_ITEM_ITEM; -} - -/* regular operator item */ -void uiMenuItemO(uiMenuItem *head, int icon, char *opname) -{ - uiMenuItem *item= ui_menu_add_item(head, "", icon, 0); - - item->opname= opname; // static! - item->type = MENU_ITEM_OPNAME; -} - -/* single operator item with property */ -void uiMenuItemEnumO(uiMenuItem *head, const char *name, int icon, char *opname, char *propname, int value) -{ - uiMenuItem *item= ui_menu_add_item(head, name, icon, 0); - - item->opname= opname; // static! - item->propname= propname; // static! - item->enumval= value; - item->type = MENU_ITEM_OPNAME_ENUM; -} - -/* single operator item with property */ -void uiMenuItemIntO(uiMenuItem *head, const char *name, int icon, char *opname, char *propname, int value) -{ - uiMenuItem *item= ui_menu_add_item(head, name, icon, 0); - - item->opname= opname; // static! - item->propname= propname; // static! - item->intval= value; - item->type = MENU_ITEM_OPNAME_INT; -} - -/* single operator item with property */ -void uiMenuItemFloatO(uiMenuItem *head, const char *name, int icon, char *opname, char *propname, float value) -{ - uiMenuItem *item= ui_menu_add_item(head, name, icon, 0); - - item->opname= opname; // static! - item->propname= propname; // static! - item->fltval= value; - item->type = MENU_ITEM_OPNAME_FLOAT; -} - -/* single operator item with property */ -void uiMenuItemBooleanO(uiMenuItem *head, const char *name, int icon, char *opname, char *propname, int value) -{ - uiMenuItem *item= ui_menu_add_item(head, name, icon, 0); - - item->opname= opname; // static! - item->propname= propname; // static! - item->boolval= value; - item->type = MENU_ITEM_OPNAME_BOOL; -} - -/* single operator item with property */ -void uiMenuItemStringO(uiMenuItem *head, const char *name, int icon, char *opname, char *propname, char *value) -{ - uiMenuItem *item= ui_menu_add_item(head, name, icon, 0); - - item->opname= opname; // static! - item->propname= propname; // static! - item->strval= value; - item->type = MENU_ITEM_OPNAME_STRING; -} - -/* add all operator items with property */ -void uiMenuItemsEnumO(uiMenuItem *head, char *opname, char *propname) -{ - wmOperatorType *ot= WM_operatortype_find(opname); - PointerRNA ptr; - PropertyRNA *prop; - - if(!ot || !ot->srna) - return; - - RNA_pointer_create(NULL, ot->srna, NULL, &ptr); - prop= RNA_struct_find_property(&ptr, propname); - - if(prop && RNA_property_type(prop) == PROP_ENUM) { - const EnumPropertyItem *item; - int totitem, i; - - RNA_property_enum_items(&ptr, prop, &item, &totitem); - - for (i=0; i<totitem; i++) - uiMenuItemEnumO(head, "", 0, opname, propname, item[i].value); - } -} - -/* rna property toggle */ -void uiMenuItemBooleanR(uiMenuItem *head, PointerRNA *ptr, char *propname) -{ - uiMenuItem *item= ui_menu_add_item(head, "", 0, 0); - - item->propname= propname; // static! - item->rnapoin= *ptr; - item->type = MENU_ITEM_RNA_BOOL; -} - -void uiMenuItemEnumR(uiMenuItem *head, PointerRNA *ptr, char *propname, int value) -{ - uiMenuItem *item= ui_menu_add_item(head, "", 0, 0); - - item->propname= propname; // static! - item->rnapoin= *ptr; - item->enumval= value; - item->type = MENU_ITEM_RNA_ENUM; -} - -/* add all rna items with property */ -void uiMenuItemsEnumR(uiMenuItem *head, PointerRNA *ptr, char *propname) -{ - PropertyRNA *prop; - - prop= RNA_struct_find_property(ptr, propname); - - if(prop && RNA_property_type(prop) == PROP_ENUM) { - const EnumPropertyItem *item; - int totitem, i; - - RNA_property_enum_items(ptr, prop, &item, &totitem); - - for (i=0; i<totitem; i++) - uiMenuItemEnumR(head, ptr, propname, item[i].value); - } -} - -/* generic new menu level */ -void uiMenuLevel(uiMenuItem *head, const char *name, uiMenuCreateFunc newlevel) -{ - uiMenuItem *item= ui_menu_add_item(head, name, 0, 0); - - item->type = MENU_ITEM_LEVEL; - item->newlevel= newlevel; -} - -/* make a new level from enum properties */ -void uiMenuLevelEnumO(uiMenuItem *head, char *opname, char *propname) -{ - uiMenuItem *item= ui_menu_add_item(head, "", 0, 0); - wmOperatorType *ot; - - item->type = MENU_ITEM_LEVEL_OPNAME_ENUM; - ot= WM_operatortype_find(opname); - if(ot) - BLI_strncpy(item->name, ot->name, MAX_MENU_STR); - - item->opname= opname; // static! - item->propname= propname; // static! -} - -/* make a new level from enum properties */ -void uiMenuLevelEnumR(uiMenuItem *head, PointerRNA *ptr, char *propname) -{ - uiMenuItem *item= ui_menu_add_item(head, "", 0, 0); - PropertyRNA *prop; - - item->type = MENU_ITEM_LEVEL_RNA_ENUM; - prop= RNA_struct_find_property(ptr, propname); - if(prop) - BLI_strncpy(item->name, RNA_property_ui_name(prop), MAX_MENU_STR); - - item->rnapoin= *ptr; - item->propname= propname; // static! -} - -/* separator */ -void uiMenuSeparator(uiMenuItem *head) -{ - uiMenuItem *item= ui_menu_add_item(head, "", 0, 0); - - item->type = MENU_ITEM_SEPARATOR; -} /*************************** Popup Menu API **************************/ /* only return handler, and set optional title */ -uiMenuItem *uiPupMenuBegin(const char *title, int icon) +uiPopupMenu *uiPupMenuBegin(const char *title, int icon) { - uiMenuItem *item= MEM_callocN(sizeof(uiMenuItem), "menu start"); + uiPopupMenu *pup= MEM_callocN(sizeof(uiPopupMenu), "menu start"); - item->type = MENU_ITEM_TITLE; - item->opcontext= WM_OP_EXEC_REGION_WIN; - item->icon= icon; + pup->icon= icon; + pup->layout= uiLayoutBegin(UI_LAYOUT_VERTICAL, UI_LAYOUT_MENU, 0, 0, 200, 0); + uiLayoutContext(pup->layout, WM_OP_EXEC_REGION_WIN); + uiLayoutColumn(pup->layout); /* NULL is no title */ if(title) - BLI_strncpy(item->name, title, MAX_MENU_STR); + BLI_strncpy(pup->name, title, MAX_MENU_STR); - return item; + return pup; } /* set the whole structure to work */ -void uiPupMenuEnd(bContext *C, uiMenuItem *head) +void uiPupMenuEnd(bContext *C, uiPopupMenu *pup) { wmWindow *window= CTX_wm_window(C); uiMenuInfo info; @@ -2197,7 +1818,7 @@ void uiPupMenuEnd(bContext *C, uiMenuItem *head) info.popup= 1; info.mx= window->eventstate->x; info.my= window->eventstate->y; - info.head= head; + info.pup= pup; menu= ui_popup_block_create(C, NULL, NULL, NULL, ui_block_func_MENU_ITEM, &info); menu->popup= 1; @@ -2205,8 +1826,12 @@ void uiPupMenuEnd(bContext *C, uiMenuItem *head) UI_add_popup_handlers(C, &window->handlers, menu); WM_event_add_mousemove(C); - BLI_freelistN(&head->items); - MEM_freeN(head); + MEM_freeN(pup); +} + +uiLayout *uiPupMenuLayout(uiPopupMenu *pup) +{ + return pup->layout; } /* ************** standard pupmenus *************** */ diff --git a/source/blender/editors/interface/interface_utils.c b/source/blender/editors/interface/interface_utils.c index 5ef1e68bd59..3bb7581b16c 100644 --- a/source/blender/editors/interface/interface_utils.c +++ b/source/blender/editors/interface/interface_utils.c @@ -297,7 +297,7 @@ int uiDefAutoButsRNA(const bContext *C, uiBlock *block, PointerRNA *ptr) char *name; int x= 0, y= 0; - layout= uiLayoutBegin(UI_LAYOUT_VERTICAL, x, y, DEF_BUT_WIDTH*2, 20); + layout= uiLayoutBegin(UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, x, y, DEF_BUT_WIDTH*2, 20); uiLayoutColumn(layout); uiItemL(layout, (char*)RNA_struct_ui_name(ptr->type), 0); @@ -317,7 +317,7 @@ int uiDefAutoButsRNA(const bContext *C, uiBlock *block, PointerRNA *ptr) uiLayoutColumn(uiLayoutSub(layout, 0)); uiItemL(uiLayoutSub(layout, 0), name, 0); uiLayoutColumn(uiLayoutSub(layout, 1)); - uiItemFullR(uiLayoutSub(layout, 1), "", 0, ptr, prop, -1, 0); + uiItemFullR(uiLayoutSub(layout, 1), "", 0, ptr, prop, -1, 0, 0); } RNA_property_collection_end(&iter); @@ -506,18 +506,7 @@ int uiDefIDPoinButs(uiBlock *block, Main *bmain, ID *parid, ID *id, int id_code, uiBlockSetButLock(block, id->lib!=0, "Can't edit external libdata"); /* name button */ - if(GS(id->name)==ID_SCE) - strcpy(str1, "SCE:"); - else if(GS(id->name)==ID_SCE) - strcpy(str1, "SCR:"); - else if(GS(id->name)==ID_MA && ((Material*)id)->use_nodes) - strcpy(str1, "NT:"); - else { - str1[0]= id->name[0]; - str1[1]= id->name[1]; - str1[2]= ':'; - str1[3]= 0; - } + text_idbutton(id, str1); if(GS(id->name)==ID_IP) len= 110; else if((y) && (GS(id->name)==ID_AC)) len= 100; // comes from button panel (poselib) diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index f3868b1f01c..90b26d0f425 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -6587,11 +6587,13 @@ void MESH_OT_subdivide_smooth(wmOperatorType *ot) static int subdivs_invoke(bContext *C, wmOperator *op, wmEvent *event) { - uiMenuItem *head; + uiPopupMenu *pup; + uiLayout *layout; - head= uiPupMenuBegin("Subdivision Type", 0); - uiMenuItemsEnumO(head, "MESH_OT_subdivs", "type"); - uiPupMenuEnd(C, head); + pup= uiPupMenuBegin("Subdivision Type", 0); + layout= uiPupMenuLayout(pup); + uiItemsEnumO(layout, "MESH_OT_subdivs", "type"); + uiPupMenuEnd(C, pup); return OPERATOR_CANCELLED; } diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index eeba0ad22ae..1a3b3e5e031 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -462,14 +462,16 @@ static int object_add_curve_exec(bContext *C, wmOperator *op) static int object_add_curve_invoke(bContext *C, wmOperator *op, wmEvent *event) { Object *obedit= CTX_data_edit_object(C); - uiMenuItem *head; + uiPopupMenu *pup; + uiLayout *layout; - head= uiPupMenuBegin(op->type->name, 0); + pup= uiPupMenuBegin(op->type->name, 0); + layout= uiPupMenuLayout(pup); if(!obedit || obedit->type == OB_CURVE) - uiMenuItemsEnumO(head, op->type->idname, "type"); + uiItemsEnumO(layout, op->type->idname, "type"); else - uiMenuItemsEnumO(head, "OBJECT_OT_surface_add", "type"); - uiPupMenuEnd(C, head); + uiItemsEnumO(layout, "OBJECT_OT_surface_add", "type"); + uiPupMenuEnd(C, pup); return OPERATOR_CANCELLED; } @@ -632,20 +634,21 @@ void OBJECT_OT_armature_add(wmOperatorType *ot) static int object_primitive_add_invoke(bContext *C, wmOperator *op, wmEvent *event) { - uiMenuItem *head= uiPupMenuBegin("Add Object", 0); + uiPopupMenu *pup= uiPupMenuBegin("Add Object", 0); + uiLayout *layout= uiPupMenuLayout(pup); - uiMenuLevelEnumO(head, "OBJECT_OT_mesh_add", "type"); - uiMenuLevelEnumO(head, "OBJECT_OT_curve_add", "type"); - uiMenuLevelEnumO(head, "OBJECT_OT_surface_add", "type"); - uiMenuItemO(head, 0, "OBJECT_OT_text_add"); - uiMenuItemEnumO(head, "", 0, "OBJECT_OT_object_add", "type", OB_MBALL); - uiMenuItemEnumO(head, "", 0, "OBJECT_OT_object_add", "type", OB_CAMERA); - uiMenuItemEnumO(head, "", 0, "OBJECT_OT_object_add", "type", OB_LAMP); - uiMenuItemEnumO(head, "", 0, "OBJECT_OT_object_add", "type", OB_EMPTY); - uiMenuItemO(head, 0, "OBJECT_OT_armature_add"); - uiMenuItemEnumO(head, "", 0, "OBJECT_OT_object_add", "type", OB_LATTICE); + uiItemLevelEnumO(layout, NULL, 0, "OBJECT_OT_mesh_add", "type"); + uiItemLevelEnumO(layout, NULL, 0, "OBJECT_OT_curve_add", "type"); + uiItemLevelEnumO(layout, NULL, 0, "OBJECT_OT_surface_add", "type"); + uiItemO(layout, NULL, 0, "OBJECT_OT_text_add"); + uiItemEnumO(layout, NULL, 0, "OBJECT_OT_object_add", "type", OB_MBALL); + uiItemEnumO(layout, NULL, 0, "OBJECT_OT_object_add", "type", OB_CAMERA); + uiItemEnumO(layout, NULL, 0, "OBJECT_OT_object_add", "type", OB_LAMP); + uiItemEnumO(layout, NULL, 0, "OBJECT_OT_object_add", "type", OB_EMPTY); + uiItemO(layout, NULL, 0, "OBJECT_OT_armature_add"); + uiItemEnumO(layout, NULL, 0, "OBJECT_OT_object_add", "type", OB_LATTICE); - uiPupMenuEnd(C, head); + uiPupMenuEnd(C, pup); /* this operator is only for a menu, not used further */ return OPERATOR_CANCELLED; @@ -2622,26 +2625,27 @@ static int parent_set_exec(bContext *C, wmOperator *op) static int parent_set_invoke(bContext *C, wmOperator *op, wmEvent *event) { Object *ob= CTX_data_active_object(C); - uiMenuItem *head= uiPupMenuBegin("Set Parent To", 0); + uiPopupMenu *pup= uiPupMenuBegin("Set Parent To", 0); + uiLayout *layout= uiPupMenuLayout(pup); - uiMenuContext(head, WM_OP_EXEC_DEFAULT); - uiMenuItemEnumO(head, "", 0, "OBJECT_OT_parent_set", "type", PAR_OBJECT); + uiLayoutContext(layout, WM_OP_EXEC_DEFAULT); + uiItemEnumO(layout, NULL, 0, "OBJECT_OT_parent_set", "type", PAR_OBJECT); /* ob becomes parent, make the associated menus */ if(ob->type==OB_ARMATURE) { - uiMenuItemEnumO(head, "", 0, "OBJECT_OT_parent_set", "type", PAR_ARMATURE); - uiMenuItemEnumO(head, "", 0, "OBJECT_OT_parent_set", "type", PAR_BONE); + uiItemEnumO(layout, NULL, 0, "OBJECT_OT_parent_set", "type", PAR_ARMATURE); + uiItemEnumO(layout, NULL, 0, "OBJECT_OT_parent_set", "type", PAR_BONE); } else if(ob->type==OB_CURVE) { - uiMenuItemEnumO(head, "", 0, "OBJECT_OT_parent_set", "type", PAR_CURVE); - uiMenuItemEnumO(head, "", 0, "OBJECT_OT_parent_set", "type", PAR_FOLLOW); - uiMenuItemEnumO(head, "", 0, "OBJECT_OT_parent_set", "type", PAR_PATH_CONST); + uiItemEnumO(layout, NULL, 0, "OBJECT_OT_parent_set", "type", PAR_CURVE); + uiItemEnumO(layout, NULL, 0, "OBJECT_OT_parent_set", "type", PAR_FOLLOW); + uiItemEnumO(layout, NULL, 0, "OBJECT_OT_parent_set", "type", PAR_PATH_CONST); } else if(ob->type == OB_LATTICE) { - uiMenuItemEnumO(head, "", 0, "OBJECT_OT_parent_set", "type", PAR_LATTICE); + uiItemEnumO(layout, NULL, 0, "OBJECT_OT_parent_set", "type", PAR_LATTICE); } - uiPupMenuEnd(C, head); + uiPupMenuEnd(C, pup); return OPERATOR_CANCELLED; } diff --git a/source/blender/editors/physics/editparticle.c b/source/blender/editors/physics/editparticle.c index 96f3ad2f8df..0d58a0bfdcd 100644 --- a/source/blender/editors/physics/editparticle.c +++ b/source/blender/editors/physics/editparticle.c @@ -3839,19 +3839,21 @@ void PE_change_act_psys(Scene *scene, Object *ob, ParticleSystem *psys) static int specials_menu_invoke(bContext *C, wmOperator *op, wmEvent *event) { Scene *scene= CTX_data_scene(C); - uiMenuItem *head; + uiPopupMenu *pup; + uiLayout *layout; - head= uiPupMenuBegin("Specials", 0); + pup= uiPupMenuBegin("Specials", 0); + layout= uiPupMenuLayout(pup); - uiMenuItemO(head, 0, "PARTICLE_OT_rekey"); + uiItemO(layout, NULL, 0, "PARTICLE_OT_rekey"); if(scene->selectmode & SCE_SELECT_POINT) { - uiMenuItemO(head, 0, "PARTICLE_OT_subdivide"); - uiMenuItemO(head, 0, "PARTICLE_OT_select_first"); - uiMenuItemO(head, 0, "PARTICLE_OT_select_last"); + uiItemO(layout, NULL, 0, "PARTICLE_OT_subdivide"); + uiItemO(layout, NULL, 0, "PARTICLE_OT_select_first"); + uiItemO(layout, NULL, 0, "PARTICLE_OT_select_last"); } - uiMenuItemO(head, 0, "PARTICLE_OT_remove_doubles"); + uiItemO(layout, NULL, 0, "PARTICLE_OT_remove_doubles"); - uiPupMenuEnd(C, head); + uiPupMenuEnd(C, pup); return OPERATOR_CANCELLED; } diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index bf57e2e7d52..ce7022d8176 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -1573,19 +1573,21 @@ static int repeat_history_invoke(bContext *C, wmOperator *op, wmEvent *event) { wmWindowManager *wm= CTX_wm_manager(C); wmOperator *lastop; - uiMenuItem *head; + uiPopupMenu *pup; + uiLayout *layout; int items, i; items= BLI_countlist(&wm->operators); if(items==0) return OPERATOR_CANCELLED; - head= uiPupMenuBegin(op->type->name, 0); + pup= uiPupMenuBegin(op->type->name, 0); + layout= uiPupMenuLayout(pup); for (i=items-1, lastop= wm->operators.last; lastop; lastop= lastop->prev, i--) - uiMenuItemIntO(head, lastop->type->name, 0, op->type->idname, "index", i); + uiItemIntO(layout, lastop->type->name, 0, op->type->idname, "index", i); - uiPupMenuEnd(C, head); + uiPupMenuEnd(C, pup); return OPERATOR_CANCELLED; } @@ -1813,27 +1815,28 @@ static void testfunc(bContext *C, void *argv, int arg) printf("arg %d\n", arg); } -static void newlevel1(bContext *C, uiMenuItem *head, void *arg) +static void newlevel1(bContext *C, uiLayout *layout, void *arg) { - uiMenuFunc(head, testfunc, NULL); + uiLayoutFunc(layout, testfunc, NULL); - uiMenuItemVal(head, "First", ICON_PROP_ON, 1); - uiMenuItemVal(head, "Second", ICON_PROP_CON, 2); - uiMenuItemVal(head, "Third", ICON_SMOOTHCURVE, 3); - uiMenuItemVal(head, "Fourth", ICON_SHARPCURVE, 4); + uiItemV(layout, "First", ICON_PROP_ON, 1); + uiItemV(layout, "Second", ICON_PROP_CON, 2); + uiItemV(layout, "Third", ICON_SMOOTHCURVE, 3); + uiItemV(layout, "Fourth", ICON_SHARPCURVE, 4); } static int testing123(bContext *C, wmOperator *op, wmEvent *event) { - uiMenuItem *head= uiPupMenuBegin("Hello world", 0); + uiPopupMenu *pup= uiPupMenuBegin("Hello world", 0); + uiLayout *layout= uiPupMenuLayout(pup); - uiMenuContext(head, WM_OP_EXEC_DEFAULT); - uiMenuItemO(head, ICON_PROP_ON, "SCREEN_OT_region_flip"); - uiMenuItemO(head, ICON_PROP_CON, "SCREEN_OT_screen_full_area"); - uiMenuItemO(head, ICON_SMOOTHCURVE, "SCREEN_OT_region_foursplit"); - uiMenuLevel(head, "Submenu", newlevel1); + uiLayoutContext(layout, WM_OP_EXEC_DEFAULT); + uiItemO(layout, NULL, ICON_PROP_ON, "SCREEN_OT_region_flip"); + uiItemO(layout, NULL, ICON_PROP_CON, "SCREEN_OT_screen_full_area"); + uiItemO(layout, NULL, ICON_SMOOTHCURVE, "SCREEN_OT_region_foursplit"); + uiItemLevel(layout, "Submenu", 0, newlevel1); - uiPupMenuEnd(C, head); + uiPupMenuEnd(C, pup); /* this operator is only for a menu, not used further */ return OPERATOR_CANCELLED; diff --git a/source/blender/editors/space_buttons/buttons_header.c b/source/blender/editors/space_buttons/buttons_header.c index 53fb4c388d3..5ca8330694e 100644 --- a/source/blender/editors/space_buttons/buttons_header.c +++ b/source/blender/editors/space_buttons/buttons_header.c @@ -29,6 +29,7 @@ #include <string.h> #include <stdio.h> +#include "DNA_object_types.h" #include "DNA_space_types.h" #include "DNA_scene_types.h" #include "DNA_screen_types.h" @@ -40,6 +41,7 @@ #include "BKE_context.h" #include "BKE_screen.h" +#include "BKE_utildefines.h" #include "ED_screen.h" #include "ED_types.h" @@ -133,8 +135,9 @@ void buttons_header_buttons(const bContext *C, ARegion *ar) { ScrArea *sa= CTX_wm_area(C); SpaceButs *sbuts= (SpaceButs*)CTX_wm_space_data(C); + Object *ob= CTX_data_active_object(C); uiBlock *block; - int xco, yco= 3; + int xco, yco= 3, dataicon= ICON_OBJECT_DATA; block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS); uiBlockSetHandleFunc(block, do_buttons_buttons, NULL); @@ -150,6 +153,22 @@ void buttons_header_buttons(const bContext *C, ARegion *ar) xco+=XIC+xmax; } + + if(ob) { + switch(ob->type) { + case OB_EMPTY: dataicon= ICON_OUTLINER_OB_EMPTY; break; + case OB_MESH: dataicon= ICON_OUTLINER_OB_MESH; break; + case OB_CURVE: dataicon= ICON_OUTLINER_OB_CURVE; break; + case OB_SURF: dataicon= ICON_OUTLINER_OB_SURFACE; break; + case OB_FONT: dataicon= ICON_OUTLINER_OB_FONT; break; + case OB_MBALL: dataicon= ICON_OUTLINER_OB_META; break; + case OB_LAMP: dataicon= ICON_OUTLINER_OB_LAMP; break; + case OB_CAMERA: dataicon= ICON_OUTLINER_OB_CAMERA; break; + case OB_LATTICE: dataicon= ICON_OUTLINER_OB_LATTICE; break; + case OB_ARMATURE: dataicon= ICON_OUTLINER_OB_ARMATURE; break; + default: break; + } + } uiBlockSetEmboss(block, UI_EMBOSS); @@ -157,10 +176,12 @@ void buttons_header_buttons(const bContext *C, ARegion *ar) uiDefIconButS(block, ROW, B_CONTEXT_SWITCH, ICON_SCENE, xco, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_SCENE, 0, 0, "Scene"); uiDefIconButS(block, ROW, B_CONTEXT_SWITCH, ICON_WORLD, xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_WORLD, 0, 0, "World"); uiDefIconButS(block, ROW, B_CONTEXT_SWITCH, ICON_OBJECT_DATA, xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_OBJECT, 0, 0, "Object"); - uiDefIconButS(block, ROW, B_CONTEXT_SWITCH, ICON_EDIT, xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_GAME, 0, 0, "Object Data"); - uiDefIconButS(block, ROW, B_BUTSPREVIEW, ICON_MATERIAL, xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_MATERIAL, 0, 0, "Material"); + uiDefIconButS(block, ROW, B_CONTEXT_SWITCH, dataicon, xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_DATA, 0, 0, "Object Data"); + if(ELEM5(ob->type, OB_MESH, OB_SURF, OB_MBALL, OB_CURVE, OB_FONT)) + uiDefIconButS(block, ROW, B_BUTSPREVIEW, ICON_MATERIAL, xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_MATERIAL, 0, 0, "Material"); uiDefIconButS(block, ROW, B_BUTSPREVIEW, ICON_TEXTURE, xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_TEXTURE, 0, 0, "Texture"); - uiDefIconButS(block, ROW, B_CONTEXT_SWITCH, ICON_PARTICLES, xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_PARTICLE, 0, 0, "Particles"); + if(ELEM5(ob->type, OB_MESH, OB_SURF, OB_MBALL, OB_CURVE, OB_FONT)) + uiDefIconButS(block, ROW, B_CONTEXT_SWITCH, ICON_PARTICLES, xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_PARTICLE, 0, 0, "Particles"); uiDefIconButS(block, ROW, B_CONTEXT_SWITCH, ICON_PHYSICS, xco+=XIC, yco, XIC, YIC, &(sbuts->mainb), 0.0, (float)BCONTEXT_PHYSICS, 0, 0, "Physics"); xco+= XIC; diff --git a/source/blender/editors/space_image/image_header.c b/source/blender/editors/space_image/image_header.c index 288fc76d8e4..7e009dfc479 100644 --- a/source/blender/editors/space_image/image_header.c +++ b/source/blender/editors/space_image/image_header.c @@ -86,21 +86,21 @@ #define B_SIMA_RECORD 8 #define B_SIMA_PLAY 9 -static void image_view_viewnavmenu(bContext *C, uiMenuItem *head, void *arg_unused) +static void image_view_viewnavmenu(bContext *C, uiLayout *layout, void *arg_unused) { int a; - uiMenuItemO(head, 0, "IMAGE_OT_view_zoom_in"); - uiMenuItemO(head, 0, "IMAGE_OT_view_zoom_out"); + uiItemO(layout, NULL, 0, "IMAGE_OT_view_zoom_in"); + uiItemO(layout, NULL, 0, "IMAGE_OT_view_zoom_out"); - uiMenuSeparator(head); + uiItemS(layout); for(a=0; a<7; a++) { const int ratios[7][2] = {{1, 8}, {1, 4}, {1, 2}, {1, 1}, {2, 1}, {4, 1}, {8, 1}}; char namestr[128]; sprintf(namestr, "Zoom %d:%d", ratios[a][0], ratios[a][1]); - uiMenuItemFloatO(head, namestr, 0, "IMAGE_OT_view_zoom_ratio", "ratio", (float)ratios[a][0]/(float)ratios[a][1]); + uiItemFloatO(layout, namestr, 0, "IMAGE_OT_view_zoom_ratio", "ratio", (float)ratios[a][0]/(float)ratios[a][1]); } } @@ -123,7 +123,7 @@ static void do_viewmenu(bContext *C, void *arg, int event) } #endif -static void image_viewmenu(bContext *C, uiMenuItem *head, void *arg_unused) +static void image_viewmenu(bContext *C, uiLayout *layout, void *arg_unused) { bScreen *sc= CTX_wm_screen(C); ScrArea *sa= CTX_wm_area(C); @@ -140,44 +140,44 @@ static void image_viewmenu(bContext *C, uiMenuItem *head, void *arg_unused) show_uvedit= ED_space_image_show_uvedit(sima, CTX_data_edit_object(C)); /* create menu */ - uiMenuItemO(head, ICON_MENU_PANEL, "IMAGE_OT_toggle_view_properties_panel"); // View Properties... - uiMenuItemO(head, ICON_MENU_PANEL, "IMAGE_OT_toggle_image_properties_panel"); // Image Properties...|N - uiMenuItemO(head, ICON_MENU_PANEL, "IMAGE_OT_toggle_realtime_properties_panel"); // Real-time properties... - if(show_paint) uiMenuItemO(head, ICON_MENU_PANEL, "IMAGE_OT_toggle_paint_panel"); // Paint Tool...|C - uiMenuItemO(head, ICON_MENU_PANEL, "IMAGE_OT_toggle_curves_panel"); // Curves Tool... - if(show_render) uiMenuItemO(head, ICON_MENU_PANEL, "IMAGE_OT_toggle_compositing_preview_panel"); // Compositing Preview...|Shift P - uiMenuItemO(head, ICON_MENU_PANEL, "IMAGE_OT_toggle_grease_pencil_panel"); // Grease Pencil... + uiItemO(layout, NULL, ICON_MENU_PANEL, "IMAGE_OT_toggle_view_properties_panel"); // View Properties... + uiItemO(layout, NULL, ICON_MENU_PANEL, "IMAGE_OT_toggle_image_properties_panel"); // Image Properties...|N + uiItemO(layout, NULL, ICON_MENU_PANEL, "IMAGE_OT_toggle_realtime_properties_panel"); // Real-time properties... + if(show_paint) uiItemO(layout, NULL, ICON_MENU_PANEL, "IMAGE_OT_toggle_paint_panel"); // Paint Tool...|C + uiItemO(layout, NULL, ICON_MENU_PANEL, "IMAGE_OT_toggle_curves_panel"); // Curves Tool... + if(show_render) uiItemO(layout, NULL, ICON_MENU_PANEL, "IMAGE_OT_toggle_compositing_preview_panel"); // Compositing Preview...|Shift P + uiItemO(layout, NULL, ICON_MENU_PANEL, "IMAGE_OT_toggle_grease_pencil_panel"); // Grease Pencil... - uiMenuSeparator(head); + uiItemS(layout); - uiMenuItemBooleanR(head, &spaceptr, "update_automatically"); - // XXX if(show_uvedit) uiMenuItemBooleanR(head, &uvptr, "local_view"); // "UV Local View", Numpad / + uiItemR(layout, NULL, 0, &spaceptr, "update_automatically", 0); + // XXX if(show_uvedit) uiItemR(layout, NULL, 0, &uvptr, "local_view", 0); // "UV Local View", Numpad / - uiMenuSeparator(head); + uiItemS(layout); - uiMenuLevel(head, "View Navigation", image_view_viewnavmenu); - if(show_uvedit) uiMenuItemO(head, 0, "IMAGE_OT_view_selected"); - uiMenuItemO(head, 0, "IMAGE_OT_view_all"); + uiItemLevel(layout, "View Navigation", 0, image_view_viewnavmenu); + if(show_uvedit) uiItemO(layout, NULL, 0, "IMAGE_OT_view_selected"); + uiItemO(layout, NULL, 0, "IMAGE_OT_view_all"); - if(sa->full) uiMenuItemO(head, 0, "SCREEN_OT_screen_full_area"); // "Tile Window", Ctrl UpArrow - else uiMenuItemO(head, 0, "SCREEN_OT_screen_full_area"); // "Maximize Window", Ctr DownArrow + if(sa->full) uiItemO(layout, NULL, 0, "SCREEN_OT_screen_full_area"); // "Tile Window", Ctrl UpArrow + else uiItemO(layout, NULL, 0, "SCREEN_OT_screen_full_area"); // "Maximize Window", Ctr DownArrow } -static void image_selectmenu(bContext *C, uiMenuItem *head, void *arg_unused) +static void image_selectmenu(bContext *C, uiLayout *layout, void *arg_unused) { - uiMenuItemO(head, 0, "UV_OT_select_border"); - uiMenuItemBooleanO(head, "Border Select Pinned", 0, "UV_OT_select_border", "pinned", 1); // Border Select Pinned|Shift B + uiItemO(layout, NULL, 0, "UV_OT_select_border"); + uiItemBooleanO(layout, "Border Select Pinned", 0, "UV_OT_select_border", "pinned", 1); // Border Select Pinned|Shift B - uiMenuSeparator(head); + uiItemS(layout); - uiMenuItemO(head, 0, "UV_OT_select_all_toggle"); - uiMenuItemO(head, 0, "UV_OT_select_invert"); - uiMenuItemO(head, 0, "UV_OT_unlink_selection"); + uiItemO(layout, NULL, 0, "UV_OT_select_all_toggle"); + uiItemO(layout, NULL, 0, "UV_OT_select_invert"); + uiItemO(layout, NULL, 0, "UV_OT_unlink_selection"); - uiMenuSeparator(head); + uiItemS(layout); - uiMenuItemO(head, 0, "UV_OT_select_pinned"); - uiMenuItemO(head, 0, "UV_OT_select_linked"); + uiItemO(layout, NULL, 0, "UV_OT_select_pinned"); + uiItemO(layout, NULL, 0, "UV_OT_select_linked"); } #if 0 @@ -190,7 +190,7 @@ static void do_image_imagemenu(void *arg, int event) } #endif -static void image_imagemenu(bContext *C, uiMenuItem *head, void *arg_unused) +static void image_imagemenu(bContext *C, uiLayout *layout, void *arg_unused) { bScreen *sc= CTX_wm_screen(C); SpaceImage *sima= (SpaceImage*)CTX_wm_space_data(C); @@ -208,37 +208,37 @@ static void image_imagemenu(bContext *C, uiMenuItem *head, void *arg_unused) RNA_pointer_create(&sc->id, &RNA_SpaceImageEditor, sima, &spaceptr); /* create menu */ - uiMenuItemO(head, 0, "IMAGE_OT_new"); // New... - uiMenuItemO(head, 0, "IMAGE_OT_open"); // Open... + uiItemO(layout, NULL, 0, "IMAGE_OT_new"); // New... + uiItemO(layout, NULL, 0, "IMAGE_OT_open"); // Open... if(ima) { if(!show_render) { - uiMenuItemO(head, 0, "IMAGE_OT_replace"); // Replace... - uiMenuItemO(head, 0, "IMAGE_OT_reload"); // Reload... + uiItemO(layout, NULL, 0, "IMAGE_OT_replace"); // Replace... + uiItemO(layout, NULL, 0, "IMAGE_OT_reload"); // Reload... } - uiMenuItemO(head, 0, "IMAGE_OT_save"); // Save - uiMenuItemO(head, 0, "IMAGE_OT_save_as"); // Save As... + uiItemO(layout, NULL, 0, "IMAGE_OT_save"); // Save + uiItemO(layout, NULL, 0, "IMAGE_OT_save_as"); // Save As... if(ima->source == IMA_SRC_SEQUENCE) - uiMenuItemO(head, 0, "IMAGE_OT_save_sequence"); // Save Changed Sequence Images + uiItemO(layout, NULL, 0, "IMAGE_OT_save_sequence"); // Save Changed Sequence Images if(!show_render) { - uiMenuSeparator(head); + uiItemS(layout); - if(ima->packedfile) uiMenuItemO(head, 0, "IMAGE_OT_unpack"); // Unpack Image... - else uiMenuItemO(head, 0, "IMAGE_OT_pack"); // Pack Image + if(ima->packedfile) uiItemO(layout, NULL, 0, "IMAGE_OT_unpack"); // Unpack Image... + else uiItemO(layout, NULL, 0, "IMAGE_OT_pack"); // Pack Image /* only for dirty && specific image types : XXX poll? */ if(ibuf && (ibuf->userflags & IB_BITMAPDIRTY)) if(ELEM(ima->source, IMA_SRC_FILE, IMA_SRC_GENERATED) && ima->type != IMA_TYPE_MULTILAYER) - uiMenuItemBooleanO(head, "Pack As PNG", 0, "IMAGE_OT_pack", "as_png", 1); // Pack Image As PNG + uiItemBooleanO(layout, "Pack As PNG", 0, "IMAGE_OT_pack", "as_png", 1); // Pack Image As PNG - uiMenuSeparator(head); + uiItemS(layout); - uiMenuItemBooleanR(head, &spaceptr, "image_painting"); + uiItemR(layout, NULL, 0, &spaceptr, "image_painting", 0); /* move to realtime properties panel */ RNA_id_pointer_create(&ima->id, &imaptr); - uiMenuLevelEnumR(head, &imaptr, "mapping"); + uiItemLevelEnumR(layout, NULL, 0, &imaptr, "mapping"); } } @@ -260,30 +260,30 @@ static void image_imagemenu(bContext *C, uiMenuItem *head, void *arg_unused) #endif } -static void image_uvs_showhidemenu(bContext *C, uiMenuItem *head, void *arg_unused) +static void image_uvs_showhidemenu(bContext *C, uiLayout *layout, void *arg_unused) { - uiMenuItemO(head, 0, "UV_OT_reveal"); - uiMenuItemO(head, 0, "UV_OT_hide"); - uiMenuItemBooleanO(head, "Hide Unselected", 0, "UV_OT_hide", "unselected", 1); + uiItemO(layout, NULL, 0, "UV_OT_reveal"); + uiItemO(layout, NULL, 0, "UV_OT_hide"); + uiItemBooleanO(layout, "Hide Unselected", 0, "UV_OT_hide", "unselected", 1); } -static void image_uvs_transformmenu(bContext *C, uiMenuItem *head, void *arg_unused) +static void image_uvs_transformmenu(bContext *C, uiLayout *layout, void *arg_unused) { - uiMenuItemEnumO(head, "", 0, "TFM_OT_transform", "mode", TFM_TRANSLATION); - uiMenuItemEnumO(head, "", 0, "TFM_OT_transform", "mode", TFM_ROTATION); - uiMenuItemEnumO(head, "", 0, "TFM_OT_transform", "mode", TFM_RESIZE); + uiItemEnumO(layout, NULL, 0, "TFM_OT_transform", "mode", TFM_TRANSLATION); + uiItemEnumO(layout, NULL, 0, "TFM_OT_transform", "mode", TFM_ROTATION); + uiItemEnumO(layout, NULL, 0, "TFM_OT_transform", "mode", TFM_RESIZE); } -static void image_uvs_mirrormenu(bContext *C, uiMenuItem *head, void *arg_unused) +static void image_uvs_mirrormenu(bContext *C, uiLayout *layout, void *arg_unused) { - uiMenuItemEnumO(head, "", 0, "UV_OT_mirror", "axis", 'x'); // "X Axis", M, 1 - uiMenuItemEnumO(head, "", 0, "UV_OT_mirror", "axis", 'y'); // "Y Axis", M, 2 + uiItemEnumO(layout, NULL, 0, "UV_OT_mirror", "axis", 'x'); // "X Axis", M, 1 + uiItemEnumO(layout, NULL, 0, "UV_OT_mirror", "axis", 'y'); // "Y Axis", M, 2 } -static void image_uvs_weldalignmenu(bContext *C, uiMenuItem *head, void *arg_unused) +static void image_uvs_weldalignmenu(bContext *C, uiLayout *layout, void *arg_unused) { - uiMenuItemO(head, 0, "UV_OT_weld"); // W, 1 - uiMenuItemsEnumO(head, "UV_OT_align", "axis"); // W, 2/3/4 + uiItemO(layout, NULL, 0, "UV_OT_weld"); // W, 1 + uiItemsEnumO(layout, "UV_OT_align", "axis"); // W, 2/3/4 } #if 0 @@ -321,7 +321,7 @@ static void image_uvs_scriptsmenu (void *args_unused) #endif /* DISABLE_PYTHON */ #endif -static void image_uvsmenu(bContext *C, uiMenuItem *head, void *arg_unused) +static void image_uvsmenu(bContext *C, uiLayout *layout, void *arg_unused) { bScreen *sc= CTX_wm_screen(C); Scene *scene= CTX_data_scene(C); @@ -338,43 +338,43 @@ static void image_uvsmenu(bContext *C, uiMenuItem *head, void *arg_unused) RNA_id_pointer_create(&scene->id, &sceneptr); /* create menu */ - uiMenuItemBooleanR(head, &uvptr, "snap_to_pixels"); - uiMenuItemBooleanR(head, &uvptr, "constrain_to_image_bounds"); + uiItemR(layout, NULL, 0, &uvptr, "snap_to_pixels", 0); + uiItemR(layout, NULL, 0, &uvptr, "constrain_to_image_bounds", 0); - uiMenuSeparator(head); + uiItemS(layout); - uiMenuItemBooleanR(head, &uvptr, "live_unwrap"); - uiMenuItemO(head, 0, "UV_OT_unwrap"); - uiMenuItemBooleanO(head, "Unpin", 0, "UV_OT_pin", "clear", 1); - uiMenuItemO(head, 0, "UV_OT_pin"); + uiItemR(layout, NULL, 0, &uvptr, "live_unwrap", 0); + uiItemO(layout, NULL, 0, "UV_OT_unwrap"); + uiItemBooleanO(layout, "Unpin", 0, "UV_OT_pin", "clear", 1); + uiItemO(layout, NULL, 0, "UV_OT_pin"); - uiMenuSeparator(head); + uiItemS(layout); - uiMenuItemO(head, 0, "UV_OT_pack_islands"); - uiMenuItemO(head, 0, "UV_OT_average_islands_scale"); - uiMenuItemO(head, 0, "UV_OT_minimize_stretch"); - uiMenuItemO(head, 0, "UV_OT_stitch"); + uiItemO(layout, NULL, 0, "UV_OT_pack_islands"); + uiItemO(layout, NULL, 0, "UV_OT_average_islands_scale"); + uiItemO(layout, NULL, 0, "UV_OT_minimize_stretch"); + uiItemO(layout, NULL, 0, "UV_OT_stitch"); - uiMenuSeparator(head); + uiItemS(layout); - uiMenuLevel(head, "Transform", image_uvs_transformmenu); - uiMenuLevel(head, "Mirror", image_uvs_mirrormenu); - uiMenuLevel(head, "Weld/Align", image_uvs_weldalignmenu); + uiItemLevel(layout, "Transform", 0, image_uvs_transformmenu); + uiItemLevel(layout, "Mirror", 0, image_uvs_mirrormenu); + uiItemLevel(layout, "Weld/Align", 0, image_uvs_weldalignmenu); - uiMenuSeparator(head); + uiItemS(layout); - uiMenuItemBooleanR(head, &sceneptr, "proportional_editing"); - uiMenuLevelEnumR(head, &sceneptr, "proportional_editing_falloff"); + uiItemR(layout, NULL, 0, &sceneptr, "proportional_editing", 0); + uiItemLevelEnumR(layout, NULL, 0, &sceneptr, "proportional_editing_falloff"); - uiMenuSeparator(head); + uiItemS(layout); - uiMenuLevel(head, "Show/Hide Faces", image_uvs_showhidemenu); + uiItemLevel(layout, "Show/Hide Faces", 0, image_uvs_showhidemenu); #if 0 #ifndef DISABLE_PYTHON - uiMenuSeparator(head); + uiItemS(layout); - uiMenuLevel(head, "Scripts", image_uvs_scriptsmenu); + uiItemLevel(layout, "Scripts", image_uvs_scriptsmenu); #endif #endif } @@ -939,19 +939,21 @@ static int toolbox_invoke(bContext *C, wmOperator *op, wmEvent *event) { SpaceImage *sima= (SpaceImage*)CTX_wm_space_data(C); Object *obedit= CTX_data_edit_object(C); - uiMenuItem *head; + uiPopupMenu *pup; + uiLayout *layout; int show_uvedit; show_uvedit= ED_space_image_show_uvedit(sima, obedit); - head= uiPupMenuBegin("Toolbox", 0); + pup= uiPupMenuBegin("Toolbox", 0); + layout= uiPupMenuLayout(pup); - uiMenuLevel(head, "View", image_viewmenu); - if(show_uvedit) uiMenuLevel(head, "Select", image_selectmenu); - uiMenuLevel(head, "Image", image_imagemenu); - if(show_uvedit) uiMenuLevel(head, "UVs", image_uvsmenu); + uiItemLevel(layout, "View", 0, image_viewmenu); + if(show_uvedit) uiItemLevel(layout, "Select", 0, image_selectmenu); + uiItemLevel(layout, "Image", 0, image_imagemenu); + if(show_uvedit) uiItemLevel(layout, "UVs", 0, image_uvsmenu); - uiPupMenuEnd(C, head); + uiPupMenuEnd(C, pup); return OPERATOR_CANCELLED; } diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index fcafcd22a3d..908b24bd84d 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -1125,16 +1125,18 @@ static int pack_invoke(bContext *C, wmOperator *op, wmEvent *event) { SpaceImage *sima= (SpaceImage*)CTX_wm_space_data(C); ImBuf *ibuf= ED_space_image_buffer(sima); - uiMenuItem *head; + uiPopupMenu *pup; + uiLayout *layout; int as_png= RNA_boolean_get(op->ptr, "as_png"); if(!pack_test(C, op)) return OPERATOR_CANCELLED; if(!as_png && (ibuf && (ibuf->userflags & IB_BITMAPDIRTY))) { - head= uiPupMenuBegin("OK", ICON_HELP); - uiMenuItemBooleanO(head, "Can't pack edited image from disk. Pack as internal PNG?", 0, op->idname, "as_png", 1); - uiPupMenuEnd(C, head); + pup= uiPupMenuBegin("OK", ICON_HELP); + layout= uiPupMenuLayout(pup); + uiItemBooleanO(layout, "Can't pack edited image from disk. Pack as internal PNG?", 0, op->idname, "as_png", 1); + uiPupMenuEnd(C, pup); return OPERATOR_CANCELLED; } diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c index fab9317bbd0..5f743afd65d 100644 --- a/source/blender/editors/space_image/space_image.c +++ b/source/blender/editors/space_image/space_image.c @@ -47,6 +47,7 @@ #include "BKE_colortools.h" #include "BKE_context.h" #include "BKE_image.h" +#include "BKE_mesh.h" #include "BKE_screen.h" #include "BKE_utildefines.h" diff --git a/source/blender/editors/space_info/info_header.c b/source/blender/editors/space_info/info_header.c index 8b940bd6ca8..af792d0b22c 100644 --- a/source/blender/editors/space_info/info_header.c +++ b/source/blender/editors/space_info/info_header.c @@ -258,22 +258,22 @@ uiBlock *info_externalfiles(bContext *C, ARegion *ar, void *arg_unused) -static void info_filemenu(bContext *C, uiMenuItem *head, void *arg_unused) +static void info_filemenu(bContext *C, uiLayout *layout, void *arg_unused) { - uiMenuContext(head, WM_OP_EXEC_AREA); - uiMenuItemO(head, 0, "WM_OT_read_homefile"); - uiMenuContext(head, WM_OP_INVOKE_AREA); - uiMenuItemO(head, 0, "WM_OT_open_mainfile"); + uiLayoutContext(layout, WM_OP_EXEC_AREA); + uiItemO(layout, NULL, 0, "WM_OT_read_homefile"); + uiLayoutContext(layout, WM_OP_INVOKE_AREA); + uiItemO(layout, NULL, 0, "WM_OT_open_mainfile"); // uiDefIconTextBlockBut(block, info_openrecentmenu, NULL, ICON_RIGHTARROW_THIN, "Open Recent",0, yco-=20, 120, 19, ""); // uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Recover Last Session", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 15, ""); - uiMenuSeparator(head); + uiItemS(layout); - uiMenuContext(head, WM_OP_EXEC_AREA); - uiMenuItemO(head, 0, "WM_OT_save_mainfile"); - uiMenuContext(head, WM_OP_INVOKE_AREA); - uiMenuItemO(head, 0, "WM_OT_save_as_mainfile"); + uiLayoutContext(layout, WM_OP_EXEC_AREA); + uiItemO(layout, NULL, 0, "WM_OT_save_mainfile"); + uiLayoutContext(layout, WM_OP_INVOKE_AREA); + uiItemO(layout, NULL, 0, "WM_OT_save_as_mainfile"); #if 0 if(U.flag & USER_FILECOMPRESS) { diff --git a/source/blender/editors/space_sequencer/sequencer_header.c b/source/blender/editors/space_sequencer/sequencer_header.c index aee589cb982..c8dc4cc006a 100644 --- a/source/blender/editors/space_sequencer/sequencer_header.c +++ b/source/blender/editors/space_sequencer/sequencer_header.c @@ -144,22 +144,22 @@ static uiBlock *seq_viewmenu(bContext *C, ARegion *ar, void *arg_unused) } //static uiBlock *seq_selectmenu(bContext *C, ARegion *ar, void *arg_unused) -static void seq_selectmenu(bContext *C, uiMenuItem *head, void *arg_unused) +static void seq_selectmenu(bContext *C, uiLayout *layout, void *arg_unused) { - uiMenuContext(head, WM_OP_INVOKE_REGION_WIN); - - uiMenuItemEnumO(head, "Strips to the Left", 0, "SEQUENCER_OT_select_active_side", "side", SEQ_SIDE_LEFT); - uiMenuItemEnumO(head, "Strips to the Right", 0, "SEQUENCER_OT_select_active_side", "side", SEQ_SIDE_RIGHT); - uiMenuSeparator(head); - uiMenuItemEnumO(head, "Surrounding Handles", 0, "SEQUENCER_OT_select_handles", "side", SEQ_SIDE_BOTH); - uiMenuItemEnumO(head, "Left Handles", 0, "SEQUENCER_OT_select_handles", "side", SEQ_SIDE_LEFT); - uiMenuItemEnumO(head, "Right Handles", 0, "SEQUENCER_OT_select_handles", "side", SEQ_SIDE_RIGHT); - uiMenuSeparator(head); - uiMenuItemO(head, 0, "SEQUENCER_OT_select_linked"); - uiMenuSeparator(head); - uiMenuItemO(head, 0, "SEQUENCER_OT_select_linked"); - uiMenuItemO(head, 0, "SEQUENCER_OT_select_all_toggle"); - uiMenuItemO(head, 0, "SEQUENCER_OT_select_invert"); + uiLayoutContext(layout, WM_OP_INVOKE_REGION_WIN); + + uiItemEnumO(layout, "Strips to the Left", 0, "SEQUENCER_OT_select_active_side", "side", SEQ_SIDE_LEFT); + uiItemEnumO(layout, "Strips to the Right", 0, "SEQUENCER_OT_select_active_side", "side", SEQ_SIDE_RIGHT); + uiItemS(layout); + uiItemEnumO(layout, "Surrounding Handles", 0, "SEQUENCER_OT_select_handles", "side", SEQ_SIDE_BOTH); + uiItemEnumO(layout, "Left Handles", 0, "SEQUENCER_OT_select_handles", "side", SEQ_SIDE_LEFT); + uiItemEnumO(layout, "Right Handles", 0, "SEQUENCER_OT_select_handles", "side", SEQ_SIDE_RIGHT); + uiItemS(layout); + uiItemO(layout, NULL, 0, "SEQUENCER_OT_select_linked"); + uiItemS(layout); + uiItemO(layout, NULL, 0, "SEQUENCER_OT_select_linked"); + uiItemO(layout, NULL, 0, "SEQUENCER_OT_select_all_toggle"); + uiItemO(layout, NULL, 0, "SEQUENCER_OT_select_invert"); } static uiBlock *seq_markermenu(bContext *C, ARegion *ar, void *arg_unused) @@ -210,114 +210,113 @@ static uiBlock *seq_markermenu(bContext *C, ARegion *ar, void *arg_unused) } //static uiBlock *seq_addmenu_effectmenu(bContext *C, ARegion *ar, void *arg_unused) -static void seq_addmenu_effectmenu(bContext *C, uiMenuItem *head, void *arg_unused) +static void seq_addmenu_effectmenu(bContext *C, uiLayout *layout, void *arg_unused) { - uiMenuContext(head, WM_OP_INVOKE_REGION_WIN); + uiLayoutContext(layout, WM_OP_INVOKE_REGION_WIN); - uiMenuItemEnumO(head, "", 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_ADD); - uiMenuItemEnumO(head, "", 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_SUB); - uiMenuItemEnumO(head, "", 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_MUL); - uiMenuItemEnumO(head, "", 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_CROSS); - uiMenuItemEnumO(head, "", 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_GAMCROSS); - uiMenuItemEnumO(head, "", 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_ALPHAOVER); - uiMenuItemEnumO(head, "", 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_ALPHAUNDER); - uiMenuItemEnumO(head, "", 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_OVERDROP); - uiMenuItemEnumO(head, "", 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_WIPE); - uiMenuItemEnumO(head, "", 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_GLOW); - uiMenuItemEnumO(head, "", 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_TRANSFORM); + uiItemEnumO(layout, NULL, 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_ADD); + uiItemEnumO(layout, NULL, 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_SUB); + uiItemEnumO(layout, NULL, 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_MUL); + uiItemEnumO(layout, NULL, 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_CROSS); + uiItemEnumO(layout, NULL, 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_GAMCROSS); + uiItemEnumO(layout, NULL, 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_ALPHAOVER); + uiItemEnumO(layout, NULL, 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_ALPHAUNDER); + uiItemEnumO(layout, NULL, 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_OVERDROP); + uiItemEnumO(layout, NULL, 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_WIPE); + uiItemEnumO(layout, NULL, 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_GLOW); + uiItemEnumO(layout, NULL, 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_TRANSFORM); /* Color is an effect but moved to the other menu since its not that exciting */ - uiMenuItemEnumO(head, "", 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_SPEED); - uiMenuSeparator(head); - uiMenuItemEnumO(head, "", 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_PLUGIN); + uiItemEnumO(layout, NULL, 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_SPEED); + uiItemS(layout); + uiItemEnumO(layout, NULL, 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_PLUGIN); } //static uiBlock *seq_addmenu(bContext *C, ARegion *ar, void *arg_unused) -static void seq_addmenu(bContext *C, uiMenuItem *head, void *arg_unused) +static void seq_addmenu(bContext *C, uiLayout *layout, void *arg_unused) { - uiMenuLevel(head, "Effects...", seq_addmenu_effectmenu); - uiMenuSeparator(head); + uiItemLevel(layout, "Effects...", 0, seq_addmenu_effectmenu); + uiItemS(layout); - uiMenuContext(head, WM_OP_INVOKE_REGION_WIN); + uiLayoutContext(layout, WM_OP_INVOKE_REGION_WIN); #ifdef WITH_FFMPEG - uiMenuItemBooleanO(head, "Audio (RAM)", 0, "SEQUENCER_OT_sound_strip_add", "hd", FALSE); - uiMenuItemBooleanO(head, "Audio (HD)", 0, "SEQUENCER_OT_sound_strip_add", "hd", TRUE); + uiItemBooleanO(layout, "Audio (RAM)", 0, "SEQUENCER_OT_sound_strip_add", "hd", FALSE); + uiItemBooleanO(layout, "Audio (HD)", 0, "SEQUENCER_OT_sound_strip_add", "hd", TRUE); #else - uiMenuItemO(head, 0, "SEQUENCER_OT_sound_strip_add"); + uiItemO(layout, NULL, 0, "SEQUENCER_OT_sound_strip_add"); #endif - uiMenuItemEnumO(head, "Add Color Strip", 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_COLOR); + uiItemEnumO(layout, "Add Color Strip", 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_COLOR); - uiMenuItemO(head, 0, "SEQUENCER_OT_image_strip_add"); - uiMenuItemO(head, 0, "SEQUENCER_OT_movie_strip_add"); - uiMenuItemO(head, 0, "SEQUENCER_OT_scene_strip_add"); + uiItemO(layout, NULL, 0, "SEQUENCER_OT_image_strip_add"); + uiItemO(layout, NULL, 0, "SEQUENCER_OT_movie_strip_add"); + uiItemO(layout, NULL, 0, "SEQUENCER_OT_scene_strip_add"); #ifdef WITH_FFMPEG - uiMenuItemBooleanO(head, "Movie and Sound", 0, "SEQUENCER_OT_movie_strip_add", "sound", TRUE); + uiItemBooleanO(layout, "Movie and Sound", 0, "SEQUENCER_OT_movie_strip_add", "sound", TRUE); #endif } //static uiBlock *seq_editmenu(bContext *C, ARegion *ar, void *arg_unused) -static void seq_editmenu(bContext *C, uiMenuItem *head, void *arg_unused) +static void seq_editmenu(bContext *C, uiLayout *layout, void *arg_unused) { - Scene *scene= CTX_data_scene(C); Editing *ed= seq_give_editing(scene, FALSE); - uiMenuContext(head, WM_OP_INVOKE_REGION_WIN); + uiLayoutContext(layout, WM_OP_INVOKE_REGION_WIN); - uiMenuItemEnumO(head, "", 0, "TFM_OT_transform", "mode", TFM_TRANSLATION); - uiMenuItemEnumO(head, "", 0, "TFM_OT_transform", "mode", TFM_TIME_EXTEND); + uiItemEnumO(layout, NULL, 0, "TFM_OT_transform", "mode", TFM_TRANSLATION); + uiItemEnumO(layout, NULL, 0, "TFM_OT_transform", "mode", TFM_TIME_EXTEND); - // uiMenuItemO(head, 0, "SEQUENCER_OT_strip_snap"); // TODO - add this operator + // uiItemO(layout, NULL, 0, "SEQUENCER_OT_strip_snap"); // TODO - add this operator - uiMenuItemEnumO(head, "Cut Hard", 0, "SEQUENCER_OT_cut", "type", SEQ_CUT_HARD); - uiMenuItemEnumO(head, "Cut Soft", 0, "SEQUENCER_OT_cut", "type", SEQ_CUT_SOFT); + uiItemEnumO(layout, "Cut Hard", 0, "SEQUENCER_OT_cut", "type", SEQ_CUT_HARD); + uiItemEnumO(layout, "Cut Soft", 0, "SEQUENCER_OT_cut", "type", SEQ_CUT_SOFT); - uiMenuItemO(head, 0, "SEQUENCER_OT_images_separate"); - uiMenuSeparator(head); - uiMenuItemO(head, 0, "SEQUENCER_OT_duplicate_add"); - uiMenuItemO(head, 0, "SEQUENCER_OT_delete"); + uiItemO(layout, NULL, 0, "SEQUENCER_OT_images_separate"); + uiItemS(layout); + uiItemO(layout, NULL, 0, "SEQUENCER_OT_duplicate_add"); + uiItemO(layout, NULL, 0, "SEQUENCER_OT_delete"); if (ed && ed->act_seq) { switch(ed->act_seq->type) { case SEQ_EFFECT: - uiMenuSeparator(head); - uiMenuItemO(head, 0, "SEQUENCER_OT_effect_change"); - uiMenuItemO(head, 0, "SEQUENCER_OT_effect_reassign_inputs"); + uiItemS(layout); + uiItemO(layout, NULL, 0, "SEQUENCER_OT_effect_change"); + uiItemO(layout, NULL, 0, "SEQUENCER_OT_effect_reassign_inputs"); break; case SEQ_IMAGE: - uiMenuSeparator(head); - uiMenuItemO(head, 0, "SEQUENCER_OT_image_change"); // Change Scene... + uiItemS(layout); + uiItemO(layout, NULL, 0, "SEQUENCER_OT_image_change"); // Change Scene... break; case SEQ_SCENE: - uiMenuSeparator(head); - uiMenuItemO(head, 0, "SEQUENCER_OT_scene_change"); // Remap Paths... + uiItemS(layout); + uiItemO(layout, NULL, 0, "SEQUENCER_OT_scene_change"); // Remap Paths... break; case SEQ_MOVIE: - uiMenuSeparator(head); - uiMenuItemO(head, 0, "SEQUENCER_OT_movie_change"); // Remap Paths... + uiItemS(layout); + uiItemO(layout, NULL, 0, "SEQUENCER_OT_movie_change"); // Remap Paths... break; } } - uiMenuSeparator(head); + uiItemS(layout); - uiMenuItemO(head, 0, "SEQUENCER_OT_meta_make"); - uiMenuItemO(head, 0, "SEQUENCER_OT_meta_separate"); + uiItemO(layout, NULL, 0, "SEQUENCER_OT_meta_make"); + uiItemO(layout, NULL, 0, "SEQUENCER_OT_meta_separate"); if (ed && (ed->metastack.first || (ed->act_seq && ed->act_seq->type == SEQ_META))) { - uiMenuSeparator(head); - uiMenuItemO(head, 0, "SEQUENCER_OT_meta_toggle"); + uiItemS(layout); + uiItemO(layout, NULL, 0, "SEQUENCER_OT_meta_toggle"); } - uiMenuSeparator(head); - uiMenuItemO(head, 0, "SEQUENCER_OT_reload"); - uiMenuSeparator(head); - uiMenuItemO(head, 0, "SEQUENCER_OT_lock"); - uiMenuItemO(head, 0, "SEQUENCER_OT_unlock"); - uiMenuItemO(head, 0, "SEQUENCER_OT_mute"); - uiMenuItemO(head, 0, "SEQUENCER_OT_unmute"); - - uiMenuItemEnumO(head, "Mute Deselected Strips", 0, "SEQUENCER_OT_mute", "type", SEQ_UNSELECTED); + uiItemS(layout); + uiItemO(layout, NULL, 0, "SEQUENCER_OT_reload"); + uiItemS(layout); + uiItemO(layout, NULL, 0, "SEQUENCER_OT_lock"); + uiItemO(layout, NULL, 0, "SEQUENCER_OT_unlock"); + uiItemO(layout, NULL, 0, "SEQUENCER_OT_mute"); + uiItemO(layout, NULL, 0, "SEQUENCER_OT_unmute"); + + uiItemEnumO(layout, "Mute Deselected Strips", 0, "SEQUENCER_OT_mute", "type", SEQ_UNSELECTED); } void sequencer_header_buttons(const bContext *C, ARegion *ar) diff --git a/source/blender/editors/space_text/space_text.c b/source/blender/editors/space_text/space_text.c index 89852955ca3..577dae433c1 100644 --- a/source/blender/editors/space_text/space_text.c +++ b/source/blender/editors/space_text/space_text.c @@ -127,13 +127,17 @@ static void text_listener(ScrArea *sa, wmNotifier *wmn) if(!wmn->reference || wmn->reference == st->text) { ED_area_tag_redraw(sa); - if(wmn->data == ND_CURSOR) { + if(wmn->data == ND_CURSOR || wmn->action == NA_EDITED) { ARegion *ar; for(ar=sa->regionbase.first; ar; ar= ar->next) if(ar->regiontype==RGN_TYPE_WINDOW) text_update_cursor_moved(st, ar); } + + if(wmn->action == NA_EDITED) + if(st->text) + text_update_edited(st->text); } else if(wmn->data == ND_DISPLAY) ED_area_tag_redraw(sa); @@ -147,6 +151,7 @@ static void text_operatortypes(void) WM_operatortype_append(TEXT_OT_new); WM_operatortype_append(TEXT_OT_open); WM_operatortype_append(TEXT_OT_reload); + WM_operatortype_append(TEXT_OT_unlink); WM_operatortype_append(TEXT_OT_save); WM_operatortype_append(TEXT_OT_save_as); WM_operatortype_append(TEXT_OT_make_internal); @@ -401,9 +406,6 @@ void ED_spacetype_text(void) art->init= text_properties_area_init; art->draw= text_properties_area_draw; - - text_properties_register(art); - BLI_addhead(&st->regiontypes, art); /* regions: header */ diff --git a/source/blender/editors/space_text/text_header.c b/source/blender/editors/space_text/text_header.c index 0ab43cbf455..a3b62adf6c8 100644 --- a/source/blender/editors/space_text/text_header.c +++ b/source/blender/editors/space_text/text_header.c @@ -155,44 +155,46 @@ static uiBlock *text_plugin_scriptsmenu(bContext *C, void *args_unused) } #endif -static void text_editmenu_viewmenu(bContext *C, uiMenuItem *head, void *arg_unused) +static void text_editmenu_viewmenu(bContext *C, uiLayout *layout, void *arg_unused) { - uiMenuItemEnumO(head, "Top of File", 0, "TEXT_OT_move", "type", FILE_TOP); - uiMenuItemEnumO(head, "Bottom of File", 0, "TEXT_OT_move", "type", FILE_BOTTOM); + uiItemEnumO(layout, "Top of File", 0, "TEXT_OT_move", "type", FILE_TOP); + uiItemEnumO(layout, "Bottom of File", 0, "TEXT_OT_move", "type", FILE_BOTTOM); } -static void text_editmenu_selectmenu(bContext *C, uiMenuItem *head, void *arg_unused) +static void text_editmenu_selectmenu(bContext *C, uiLayout *layout, void *arg_unused) { - uiMenuItemO(head, 0, "TEXT_OT_select_all"); - uiMenuItemO(head, 0, "TEXT_OT_select_line"); + uiItemO(layout, NULL, 0, "TEXT_OT_select_all"); + uiItemO(layout, NULL, 0, "TEXT_OT_select_line"); } -static void text_editmenu_markermenu(bContext *C, uiMenuItem *head, void *arg_unused) +static void text_editmenu_markermenu(bContext *C, uiLayout *layout, void *arg_unused) { - uiMenuItemO(head, 0, "TEXT_OT_markers_clear"); - uiMenuItemO(head, 0, "TEXT_OT_next_marker"); - uiMenuItemO(head, 0, "TEXT_OT_previous_marker"); + uiItemO(layout, NULL, 0, "TEXT_OT_markers_clear"); + uiItemO(layout, NULL, 0, "TEXT_OT_next_marker"); + uiItemO(layout, NULL, 0, "TEXT_OT_previous_marker"); } -static void text_formatmenu(bContext *C, uiMenuItem *head, void *arg_unused) +static void text_formatmenu(const bContext *C, Menu *menu) { - uiMenuItemO(head, 0, "TEXT_OT_indent"); - uiMenuItemO(head, 0, "TEXT_OT_unindent"); + uiLayout *layout= menu->layout; - uiMenuSeparator(head); + uiItemO(layout, NULL, 0, "TEXT_OT_indent"); + uiItemO(layout, NULL, 0, "TEXT_OT_unindent"); - uiMenuItemO(head, 0, "TEXT_OT_comment"); - uiMenuItemO(head, 0, "TEXT_OT_uncomment"); + uiItemS(layout); - uiMenuSeparator(head); + uiItemO(layout, NULL, 0, "TEXT_OT_comment"); + uiItemO(layout, NULL, 0, "TEXT_OT_uncomment"); - uiMenuLevelEnumO(head, "TEXT_OT_convert_whitespace", "type"); + uiItemS(layout); + + uiItemLevelEnumO(layout, NULL, 0, "TEXT_OT_convert_whitespace", "type"); } -static void text_editmenu_to3dmenu(bContext *C, uiMenuItem *head, void *arg_unused) +static void text_editmenu_to3dmenu(bContext *C, uiLayout *layout, void *arg_unused) { - uiMenuItemBooleanO(head, "One Object", 0, "TEXT_OT_to_3d_object", "split_lines", 0); - uiMenuItemBooleanO(head, "One Object Per Line", 0, "TEXT_OT_to_3d_object", "split_lines", 1); + uiItemBooleanO(layout, "One Object", 0, "TEXT_OT_to_3d_object", "split_lines", 0); + uiItemBooleanO(layout, "One Object Per Line", 0, "TEXT_OT_to_3d_object", "split_lines", 1); } static int text_menu_edit_poll(bContext *C) @@ -200,308 +202,56 @@ static int text_menu_edit_poll(bContext *C) return (CTX_data_edit_text(C) != NULL); } -static void text_editmenu(bContext *C, uiMenuItem *head, void *arg_unused) +static void text_editmenu(const bContext *C, Menu *menu) { - uiMenuItemO(head, 0, "ED_OT_undo"); - uiMenuItemO(head, 0, "ED_OT_redo"); - - uiMenuSeparator(head); - - uiMenuItemO(head, 0, "TEXT_OT_cut"); - uiMenuItemO(head, 0, "TEXT_OT_copy"); - uiMenuItemO(head, 0, "TEXT_OT_paste"); - - uiMenuSeparator(head); - - uiMenuLevel(head, "View", text_editmenu_viewmenu); - uiMenuLevel(head, "Select", text_editmenu_selectmenu); - uiMenuLevel(head, "Markers", text_editmenu_markermenu); - - uiMenuSeparator(head); - - uiMenuItemO(head, 0, "TEXT_OT_jump"); - uiMenuItemO(head, 0, "TEXT_OT_properties"); - - uiMenuSeparator(head); - - uiMenuLevel(head, "Text to 3D Object", text_editmenu_to3dmenu); -} + uiLayout *layout= menu->layout; -static void text_filemenu(bContext *C, uiMenuItem *head, void *arg_unused) -{ - SpaceText *st= (SpaceText*)CTX_wm_space_data(C); - Text *text= st->text; - - uiMenuItemO(head, 0, "TEXT_OT_new"); - uiMenuItemO(head, 0, "TEXT_OT_open"); - - if(text) { - uiMenuItemO(head, 0, "TEXT_OT_reload"); - - uiMenuSeparator(head); - - uiMenuItemO(head, 0, "TEXT_OT_save"); - uiMenuItemO(head, 0, "TEXT_OT_save_as"); - - if(text->name) - uiMenuItemO(head, 0, "TEXT_OT_make_internal"); - - uiMenuSeparator(head); - - uiMenuItemO(head, 0, "TEXT_OT_run_script"); + uiItemO(layout, NULL, 0, "ED_OT_undo"); + uiItemO(layout, NULL, 0, "ED_OT_redo"); -#ifndef DISABLE_PYTHON - if(BPY_is_pyconstraint(text)) - uiMenuItemO(head, 0, "TEXT_OT_refresh_pyconstraints"); -#endif - } + uiItemS(layout); -#ifndef DISABLE_PYTHON - // XXX uiMenuSeparator(head); + uiItemO(layout, NULL, 0, "TEXT_OT_cut"); + uiItemO(layout, NULL, 0, "TEXT_OT_copy"); + uiItemO(layout, NULL, 0, "TEXT_OT_paste"); - // XXX uiDefIconTextBlockBut(block, text_template_scriptsmenu, NULL, ICON_RIGHTARROW_THIN, "Script Templates", 0, yco-=20, 120, 19, ""); - // XXX uiDefIconTextBlockBut(block, text_plugin_scriptsmenu, NULL, ICON_RIGHTARROW_THIN, "Text Plugins", 0, yco-=20, 120, 19, ""); -#endif -} + uiItemS(layout); -/*********************** datablock browse *************************/ + uiItemLevel(layout, "View", 0, text_editmenu_viewmenu); + uiItemLevel(layout, "Select", 0, text_editmenu_selectmenu); + uiItemLevel(layout, "Markers", 0, text_editmenu_markermenu); -static void text_unlink(Main *bmain, Text *text) -{ - bScreen *scr; - ScrArea *area; - SpaceLink *sl; + uiItemS(layout); - /* XXX this ifdef is in fact dangerous, if python is - * disabled it will leave invalid pointers in files! */ + uiItemO(layout, NULL, 0, "TEXT_OT_jump"); + uiItemO(layout, NULL, 0, "TEXT_OT_properties"); -#ifndef DISABLE_PYTHON - // XXX BPY_clear_bad_scriptlinks(text); - // XXX BPY_free_pyconstraint_links(text); - // XXX free_text_controllers(text); - // XXX free_dome_warp_text(text); - - /* check if this text was used as script link: - * this check function unsets the pointers and returns how many - * script links used this Text */ - if(0) // XXX BPY_text_check_all_scriptlinks (text)) - ; // XXX notifier: allqueue(REDRAWBUTSSCRIPT, 0); - - /* equivalently for pynodes: */ - if(0) // XXX nodeDynamicUnlinkText ((ID*)text)) - ; // XXX notifier: allqueue(REDRAWNODE, 0); -#endif - - for(scr= bmain->screen.first; scr; scr= scr->id.next) { - for(area= scr->areabase.first; area; area= area->next) { - for(sl= area->spacedata.first; sl; sl= sl->next) { - if(sl->spacetype==SPACE_TEXT) { - SpaceText *st= (SpaceText*) sl; - - if(st->text==text) { - st->text= NULL; - st->top= 0; - - if(st==area->spacedata.first) - ED_area_tag_redraw(area); - } - } - } - } - } + uiItemS(layout); - free_libblock(&bmain->text, text); -} - -static void text_idpoin_handle(bContext *C, ID *id, int event) -{ - SpaceText *st= (SpaceText*)CTX_wm_space_data(C); - Text *text; - - switch(event) { - case UI_ID_BROWSE: - st->text= (Text*)id; - st->top= 0; - - text_update_edited(st->text); - WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, st->text); - - ED_undo_push(C, "Browse Text"); - break; - case UI_ID_DELETE: - text= st->text; - - /* make the previous text active, if its not there make the next text active */ - if(text->id.prev) { - st->text = text->id.prev; - WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, st->text); - } - else if(text->id.next) { - st->text = text->id.next; - WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, st->text); - } - - text_unlink(CTX_data_main(C), text); - WM_event_add_notifier(C, NC_TEXT|NA_REMOVED, text); - - ED_undo_push(C, "Delete Text"); - break; - case UI_ID_RENAME: - break; - case UI_ID_ADD_NEW: - WM_operator_name_call(C, "TEXT_OT_new", WM_OP_INVOKE_REGION_WIN, NULL); - break; - case UI_ID_OPEN: - WM_operator_name_call(C, "TEXT_OT_open", WM_OP_INVOKE_REGION_WIN, NULL); - break; - } + uiItemLevel(layout, "Text to 3D Object", 0, text_editmenu_to3dmenu); } /********************** header buttons ***********************/ -static void text_header_draw(const bContext *C, Header *header) -{ - bScreen *sc= CTX_wm_screen(C); - SpaceText *st= (SpaceText*)CTX_wm_space_data(C); - PointerRNA spaceptr; - Text *text= st->text; - uiLayout *layout= header->layout; - - RNA_pointer_create(&sc->id, &RNA_SpaceTextEditor, st, &spaceptr); - - uiTemplateHeaderMenus(layout); - uiItemM(layout, "Text", 0, text_filemenu); - if(text) { - uiItemM(layout, "Edit", 0, text_editmenu); - uiItemM(layout, "Format", 0, text_formatmenu); - } - - /* warning button if text is out of date */ - if(text && text_file_modified(text)) { - uiTemplateHeaderButtons(layout); - uiTemplateSetColor(layout, TH_REDALERT); - uiItemO(layout, "", ICON_HELP, "TEXT_OT_resolve_conflict"); - } - - uiTemplateHeaderButtons(layout); - uiItemR(layout, "", ICON_LINENUMBERS_OFF, &spaceptr, "line_numbers", 0); - uiItemR(layout, "", ICON_WORDWRAP_OFF, &spaceptr, "word_wrap", 0); - uiItemR(layout, "", ICON_SYNTAX_OFF, &spaceptr, "syntax_highlight", 0); - // XXX uiItemR(layout, "", ICON_SCRIPTPLUGINS, &spaceptr, "do_python_plugins", 0); - - uiTemplateHeaderID(layout, &spaceptr, "text", - UI_ID_BROWSE|UI_ID_RENAME|UI_ID_ADD_NEW|UI_ID_OPEN|UI_ID_DELETE, - text_idpoin_handle); - - /* file info */ - if(text) { - char fname[HEADER_PATH_MAX]; - static char headtxt[HEADER_PATH_MAX+17]; - int len; - - if(text->name) { - len = strlen(text->name); - if(len > HEADER_PATH_MAX-1) - len = HEADER_PATH_MAX-1; - strncpy(fname, text->name, len); - fname[len]='\0'; - if(text->flags & TXT_ISDIRTY) - sprintf(headtxt, "File: *%s (unsaved)", fname); - else - sprintf(headtxt, "File: %s", fname); - } - else - sprintf(headtxt, text->id.lib? "Text: External": "Text: Internal"); - - uiTemplateHeaderButtons(layout); - uiItemL(layout, headtxt, 0); - } -} - void text_header_register(ARegionType *art) { - HeaderType *ht; - - /* header */ - ht= MEM_callocN(sizeof(HeaderType), "spacetype text header"); - strcpy(ht->idname, "TEXT_HT_header"); - ht->draw= text_header_draw; - BLI_addhead(&art->headertypes, ht); + MenuType *mt; + + mt= MEM_callocN(sizeof(MenuType), "spacetype text menu edit"); + strcpy(mt->idname, "TEXT_MT_edit"); + strcpy(mt->label, "Edit"); + mt->draw= text_editmenu; + BLI_addhead(&art->menutypes, mt); + + mt= MEM_callocN(sizeof(MenuType), "spacetype text menu format"); + strcpy(mt->idname, "TEXT_MT_format"); + strcpy(mt->label, "Format"); + mt->draw= text_formatmenu; + BLI_addhead(&art->menutypes, mt); } /************************** properties ******************************/ -static void text_properties_panel_draw(const bContext *C, Panel *panel) -{ - bScreen *sc= CTX_wm_screen(C); - SpaceText *st= CTX_wm_space_text(C); - uiLayout *layout= panel->layout; - PointerRNA spaceptr; - - RNA_pointer_create(&sc->id, &RNA_SpaceTextEditor, st, &spaceptr); - - uiLayoutColumn(layout); - uiItemR(layout, NULL, ICON_LINENUMBERS_OFF, &spaceptr, "line_numbers", 0); - uiItemR(layout, NULL, ICON_WORDWRAP_OFF, &spaceptr, "word_wrap", 0); - uiItemR(layout, NULL, ICON_SYNTAX_OFF, &spaceptr, "syntax_highlight", 0); - - uiLayoutColumn(layout); - uiItemR(layout, NULL, 0, &spaceptr, "font_size", 0); - uiItemR(layout, NULL, 0, &spaceptr, "tab_width", 0); -} - -static void text_find_panel_draw(const bContext *C, Panel *panel) -{ - bScreen *sc= CTX_wm_screen(C); - SpaceText *st= CTX_wm_space_text(C); - uiLayout *layout= panel->layout; - PointerRNA spaceptr; - - RNA_pointer_create(&sc->id, &RNA_SpaceTextEditor, st, &spaceptr); - - /* find */ - uiLayoutRow(layout); - uiItemR(layout, "", 0, &spaceptr, "find_text", 0); - uiItemO(layout, "", ICON_TEXT, "TEXT_OT_find_set_selected"); - uiLayoutColumn(layout); - uiItemO(layout, NULL, 0, "TEXT_OT_find"); - - /* replace */ - uiLayoutRow(layout); - uiItemR(layout, "", 0, &spaceptr, "replace_text", 0); - uiItemO(layout, "", ICON_TEXT, "TEXT_OT_replace_set_selected"); - uiLayoutColumn(layout); - uiItemO(layout, NULL, 0, "TEXT_OT_replace"); - - /* mark */ - uiLayoutColumn(layout); - uiItemO(layout, NULL, 0, "TEXT_OT_mark_all"); - - /* settings */ - uiLayoutColumnFlow(layout, 0); - uiItemR(layout, "Wrap", 0, &spaceptr, "find_wrap", 0); - uiItemR(layout, "All", 0, &spaceptr, "find_all", 0); -} - -void text_properties_register(ARegionType *art) -{ - PanelType *pt; - - /* panels: properties */ - pt= MEM_callocN(sizeof(PanelType), "spacetype text panel"); - strcpy(pt->idname, "TEXT_PT_properties"); - strcpy(pt->label, "Properties"); - pt->draw= text_properties_panel_draw; - BLI_addtail(&art->paneltypes, pt); - - /* panels: find */ - pt= MEM_callocN(sizeof(PanelType), "spacetype text panel"); - strcpy(pt->idname, "TEXT_PT_find"); - strcpy(pt->label, "Find"); - pt->draw= text_find_panel_draw; - BLI_addtail(&art->paneltypes, pt); -} - ARegion *text_has_properties_region(ScrArea *sa) { ARegion *ar, *arnew; @@ -570,75 +320,75 @@ void TEXT_OT_properties(wmOperatorType *ot) { // RMB - uiMenuItem *head; + uiPopupMenu *pup; if(text) { - head= uiPupMenuBegin("Text", 0); + pup= uiPupMenuBegin("Text", 0); if(txt_has_sel(text)) { - uiMenuItemO(head, 0, "TEXT_OT_cut"); - uiMenuItemO(head, 0, "TEXT_OT_copy"); + uiItemO(layout, NULL, 0, "TEXT_OT_cut"); + uiItemO(layout, NULL, 0, "TEXT_OT_copy"); } - uiMenuItemO(head, 0, "TEXT_OT_paste"); - uiMenuItemO(head, 0, "TEXT_OT_new"); - uiMenuItemO(head, 0, "TEXT_OT_open"); - uiMenuItemO(head, 0, "TEXT_OT_save"); - uiMenuItemO(head, 0, "TEXT_OT_save_as"); - uiMenuItemO(head, 0, "TEXT_OT_run_script"); - uiPupMenuEnd(C, head); + uiItemO(layout, NULL, 0, "TEXT_OT_paste"); + uiItemO(layout, NULL, 0, "TEXT_OT_new"); + uiItemO(layout, NULL, 0, "TEXT_OT_open"); + uiItemO(layout, NULL, 0, "TEXT_OT_save"); + uiItemO(layout, NULL, 0, "TEXT_OT_save_as"); + uiItemO(layout, NULL, 0, "TEXT_OT_run_script"); + uiPupMenuEnd(C, pup); } else { - head= uiPupMenuBegin("File", 0); - uiMenuItemO(head, 0, "TEXT_OT_new"); - uiMenuItemO(head, 0, "TEXT_OT_open"); - uiPupMenuEnd(C, head); + pup= uiPupMenuBegin("File", 0); + uiItemO(layout, NULL, 0, "TEXT_OT_new"); + uiItemO(layout, NULL, 0, "TEXT_OT_open"); + uiPupMenuEnd(C, pup); } } { // Alt+Shift+E - uiMenuItem *head; + uiPopupMenu *pup; - head= uiPupMenuBegin("Edit", 0); - uiMenuItemO(head, 0, "TEXT_OT_cut"); - uiMenuItemO(head, 0, "TEXT_OT_copy"); - uiMenuItemO(head, 0, "TEXT_OT_paste"); - uiPupMenuEnd(C, head); + pup= uiPupMenuBegin("Edit", 0); + uiItemO(layout, NULL, 0, "TEXT_OT_cut"); + uiItemO(layout, NULL, 0, "TEXT_OT_copy"); + uiItemO(layout, NULL, 0, "TEXT_OT_paste"); + uiPupMenuEnd(C, pup); } { // Alt+Shift+F - uiMenuItem *head; + uiPopupMenu *pup; if(text) { - head= uiPupMenuBegin("Text", 0); - uiMenuItemO(head, 0, "TEXT_OT_new"); - uiMenuItemO(head, 0, "TEXT_OT_open"); - uiMenuItemO(head, 0, "TEXT_OT_save"); - uiMenuItemO(head, 0, "TEXT_OT_save_as"); - uiMenuItemO(head, 0, "TEXT_OT_run_script"); - uiPupMenuEnd(C, head); + pup= uiPupMenuBegin("Text", 0); + uiItemO(layout, NULL, 0, "TEXT_OT_new"); + uiItemO(layout, NULL, 0, "TEXT_OT_open"); + uiItemO(layout, NULL, 0, "TEXT_OT_save"); + uiItemO(layout, NULL, 0, "TEXT_OT_save_as"); + uiItemO(layout, NULL, 0, "TEXT_OT_run_script"); + uiPupMenuEnd(C, pup); } else { - head= uiPupMenuBegin("File", 0); - uiMenuItemO(head, 0, "TEXT_OT_new"); - uiMenuItemO(head, 0, "TEXT_OT_open"); - uiPupMenuEnd(C, head); + pup= uiPupMenuBegin("File", 0); + uiItemO(layout, NULL, 0, "TEXT_OT_new"); + uiItemO(layout, NULL, 0, "TEXT_OT_open"); + uiPupMenuEnd(C, pup); } } { // Alt+Shift+V - uiMenuItem *head; + uiPopupMenu *pup; - head= uiPupMenuBegin("Text", 0); - uiMenuItemEnumO(head, "Top of File", 0, "TEXT_OT_move", "type", FILE_TOP); - uiMenuItemEnumO(head, "Bottom of File", 0, "TEXT_OT_move", "type", FILE_BOTTOM); - uiMenuItemEnumO(head, "Page Up", 0, "TEXT_OT_move", "type", PREV_PAGE); - uiMenuItemEnumO(head, "Page Down", 0, "TEXT_OT_move", "type", NEXT_PAGE); - uiPupMenuEnd(C, head); + pup= uiPupMenuBegin("Text", 0); + uiItemEnumO(layout, "Top of File", 0, "TEXT_OT_move", "type", FILE_TOP); + uiItemEnumO(layout, "Bottom of File", 0, "TEXT_OT_move", "type", FILE_BOTTOM); + uiItemEnumO(layout, "Page Up", 0, "TEXT_OT_move", "type", PREV_PAGE); + uiItemEnumO(layout, "Page Down", 0, "TEXT_OT_move", "type", NEXT_PAGE); + uiPupMenuEnd(C, pup); } #endif diff --git a/source/blender/editors/space_text/text_intern.h b/source/blender/editors/space_text/text_intern.h index 7ec75e292ce..50109ba8c42 100644 --- a/source/blender/editors/space_text/text_intern.h +++ b/source/blender/editors/space_text/text_intern.h @@ -43,7 +43,6 @@ struct wmOperatorType; struct wmWindowManager; /* text_header.c */ -void text_properties_register(struct ARegionType *art); void text_header_register(struct ARegionType *art); /* text_draw.c */ @@ -106,6 +105,7 @@ enum { DEL_NEXT_CHAR, DEL_PREV_CHAR, DEL_NEXT_WORD, DEL_PREV_WORD }; void TEXT_OT_new(struct wmOperatorType *ot); void TEXT_OT_open(struct wmOperatorType *ot); void TEXT_OT_reload(struct wmOperatorType *ot); +void TEXT_OT_unlink(struct wmOperatorType *ot); void TEXT_OT_save(struct wmOperatorType *ot); void TEXT_OT_save_as(struct wmOperatorType *ot); void TEXT_OT_make_internal(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index c7fe02975ef..913bd307ab2 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -49,6 +49,7 @@ #include "BKE_context.h" #include "BKE_depsgraph.h" #include "BKE_global.h" +#include "BKE_library.h" #include "BKE_main.h" #include "BKE_report.h" #include "BKE_suggestions.h" @@ -269,6 +270,90 @@ void TEXT_OT_reload(wmOperatorType *ot) ot->poll= text_edit_poll; } +/******************* delete operator *********************/ + +static void text_unlink(Main *bmain, Text *text) +{ + bScreen *scr; + ScrArea *area; + SpaceLink *sl; + + /* XXX this ifdef is in fact dangerous, if python is + * disabled it will leave invalid pointers in files! */ + +#ifndef DISABLE_PYTHON + // XXX BPY_clear_bad_scriptlinks(text); + // XXX BPY_free_pyconstraint_links(text); + // XXX free_text_controllers(text); + // XXX free_dome_warp_text(text); + + /* check if this text was used as script link: + * this check function unsets the pointers and returns how many + * script links used this Text */ + if(0) // XXX BPY_text_check_all_scriptlinks (text)) + ; // XXX notifier: allqueue(REDRAWBUTSSCRIPT, 0); + + /* equivalently for pynodes: */ + if(0) // XXX nodeDynamicUnlinkText ((ID*)text)) + ; // XXX notifier: allqueue(REDRAWNODE, 0); +#endif + + for(scr= bmain->screen.first; scr; scr= scr->id.next) { + for(area= scr->areabase.first; area; area= area->next) { + for(sl= area->spacedata.first; sl; sl= sl->next) { + if(sl->spacetype==SPACE_TEXT) { + SpaceText *st= (SpaceText*) sl; + + if(st->text==text) { + st->text= NULL; + st->top= 0; + + if(st==area->spacedata.first) + ED_area_tag_redraw(area); + } + } + } + } + } + + free_libblock(&bmain->text, text); +} + +static int unlink_exec(bContext *C, wmOperator *op) +{ + SpaceText *st= CTX_wm_space_text(C); + Text *text= CTX_data_edit_text(C); + + /* make the previous text active, if its not there make the next text active */ + if(st) { + if(text->id.prev) { + st->text = text->id.prev; + WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, st->text); + } + else if(text->id.next) { + st->text = text->id.next; + WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, st->text); + } + } + + text_unlink(CTX_data_main(C), text); + WM_event_add_notifier(C, NC_TEXT|NA_REMOVED, text); + + return OPERATOR_FINISHED; +} + +void TEXT_OT_unlink(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Unlink"; + ot->idname= "TEXT_OT_unlink"; + + /* api callbacks */ + ot->exec= unlink_exec; + ot->invoke= WM_operator_confirm; + ot->poll= text_edit_poll; +} + /******************* make internal operator *********************/ static int make_internal_exec(bContext *C, wmOperator *op) @@ -2448,31 +2533,35 @@ static int resolve_conflict_exec(bContext *C, wmOperator *op) static int resolve_conflict_invoke(bContext *C, wmOperator *op, wmEvent *event) { Text *text= CTX_data_edit_text(C); - uiMenuItem *head; + uiPopupMenu *pup; + uiLayout *layout; switch(text_file_modified(text)) { case 1: if(text->flags & TXT_ISDIRTY) { /* modified locally and externally, ahhh. offer more possibilites. */ - head= uiPupMenuBegin("File Modified Outside and Inside Blender", 0); - uiMenuItemEnumO(head, "Reload from disk (ignore local changes)", 0, op->type->idname, "resolution", RESOLVE_RELOAD); - uiMenuItemEnumO(head, "Save to disk (ignore outside changes)", 0, op->type->idname, "resolution", RESOLVE_SAVE); - uiMenuItemEnumO(head, "Make text internal (separate copy)", 0, op->type->idname, "resolution", RESOLVE_MAKE_INTERNAL); - uiPupMenuEnd(C, head); + pup= uiPupMenuBegin("File Modified Outside and Inside Blender", 0); + layout= uiPupMenuLayout(pup); + uiItemEnumO(layout, "Reload from disk (ignore local changes)", 0, op->type->idname, "resolution", RESOLVE_RELOAD); + uiItemEnumO(layout, "Save to disk (ignore outside changes)", 0, op->type->idname, "resolution", RESOLVE_SAVE); + uiItemEnumO(layout, "Make text internal (separate copy)", 0, op->type->idname, "resolution", RESOLVE_MAKE_INTERNAL); + uiPupMenuEnd(C, pup); } else { - head= uiPupMenuBegin("File Modified Outside Blender", 0); - uiMenuItemEnumO(head, "Reload from disk", 0, op->type->idname, "resolution", RESOLVE_RELOAD); - uiMenuItemEnumO(head, "Make text internal (separate copy)", 0, op->type->idname, "resolution", RESOLVE_MAKE_INTERNAL); - uiMenuItemEnumO(head, "Ignore", 0, op->type->idname, "resolution", RESOLVE_IGNORE); - uiPupMenuEnd(C, head); + pup= uiPupMenuBegin("File Modified Outside Blender", 0); + layout= uiPupMenuLayout(pup); + uiItemEnumO(layout, "Reload from disk", 0, op->type->idname, "resolution", RESOLVE_RELOAD); + uiItemEnumO(layout, "Make text internal (separate copy)", 0, op->type->idname, "resolution", RESOLVE_MAKE_INTERNAL); + uiItemEnumO(layout, "Ignore", 0, op->type->idname, "resolution", RESOLVE_IGNORE); + uiPupMenuEnd(C, pup); } break; case 2: - head= uiPupMenuBegin("File Deleted Outside Blender", 0); - uiMenuItemEnumO(head, "Make text internal", 0, op->type->idname, "resolution", RESOLVE_MAKE_INTERNAL); - uiMenuItemEnumO(head, "Recreate file", 0, op->type->idname, "resolution", RESOLVE_SAVE); - uiPupMenuEnd(C, head); + pup= uiPupMenuBegin("File Deleted Outside Blender", 0); + layout= uiPupMenuLayout(pup); + uiItemEnumO(layout, "Make text internal", 0, op->type->idname, "resolution", RESOLVE_MAKE_INTERNAL); + uiItemEnumO(layout, "Recreate file", 0, op->type->idname, "resolution", RESOLVE_SAVE); + uiPupMenuEnd(C, pup); break; } diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c index 5d149fb2f9b..e968756b11a 100644 --- a/source/blender/editors/space_view3d/view3d_header.c +++ b/source/blender/editors/space_view3d/view3d_header.c @@ -620,82 +620,82 @@ static void do_view3d_viewmenu(bContext *C, void *arg, int event) } #endif -static void view3d_view_viewnavmenu(bContext *C, uiMenuItem *head, void *arg_unused) +static void view3d_view_viewnavmenu(bContext *C, uiLayout *layout, void *arg_unused) { -// uiMenuItemO(head, 0, "VIEW3D_OT_view_fly_mode"); +// uiItemO(layout, NULL, 0, "VIEW3D_OT_view_fly_mode"); -// uiMenuSeparator(head); +// uiItemS(layout); - uiMenuItemsEnumO(head, "VIEW3D_OT_view_orbit", "type"); + uiItemsEnumO(layout, "VIEW3D_OT_view_orbit", "type"); - uiMenuSeparator(head); + uiItemS(layout); - uiMenuItemsEnumO(head, "VIEW3D_OT_view_pan", "type"); + uiItemsEnumO(layout, "VIEW3D_OT_view_pan", "type"); - uiMenuSeparator(head); + uiItemS(layout); - uiMenuItemFloatO(head, "Zoom in", 0, "VIEW3D_OT_zoom", "delta", 1.0f); - uiMenuItemFloatO(head, "Zoom out", 0, "VIEW3D_OT_zoom", "delta", -1.0f); + uiItemFloatO(layout, "Zoom in", 0, "VIEW3D_OT_zoom", "delta", 1.0f); + uiItemFloatO(layout, "Zoom out", 0, "VIEW3D_OT_zoom", "delta", -1.0f); } -static void view3d_view_alignviewmenu(bContext *C, uiMenuItem *head, void *arg_unused) +static void view3d_view_alignviewmenu(bContext *C, uiLayout *layout, void *arg_unused) { } -static void view3d_viewmenu(bContext *C, uiMenuItem *head, void *arg_unused) +static void view3d_viewmenu(bContext *C, uiLayout *layout, void *arg_unused) { ScrArea *sa= CTX_wm_area(C); -// uiMenuItemO(head, ICON_MENU_PANEL, "VIEW3D_OT_toggle_transform_orientations_panel"); // Transform Orientations... -// uiMenuItemO(head, ICON_MENU_PANEL, "VIEW3D_OT_toggle_render_preview_panel"); // render preview... -// uiMenuItemO(head, ICON_MENU_PANEL, "VIEW3D_OT_toggle_view_properties_panel"); // View Properties.... -// uiMenuItemO(head, ICON_MENU_PANEL, "VIEW3D_OT_toggle_background_image_panel"); // Background Image.... -// uiMenuItemO(head, ICON_MENU_PANEL, "VIEW3D_OT_toggle_grease_pencil_panel"); // Grease Pencil.... +// uiItemO(layout, ICON_MENU_PANEL, "VIEW3D_OT_toggle_transform_orientations_panel"); // Transform Orientations... +// uiItemO(layout, ICON_MENU_PANEL, "VIEW3D_OT_toggle_render_preview_panel"); // render preview... +// uiItemO(layout, ICON_MENU_PANEL, "VIEW3D_OT_toggle_view_properties_panel"); // View Properties.... +// uiItemO(layout, ICON_MENU_PANEL, "VIEW3D_OT_toggle_background_image_panel"); // Background Image.... +// uiItemO(layout, ICON_MENU_PANEL, "VIEW3D_OT_toggle_grease_pencil_panel"); // Grease Pencil.... -// uiMenuSeparator(head); +// uiItemS(layout); - uiMenuItemEnumO(head, "", 0, "VIEW3D_OT_viewnumpad", "type", V3D_VIEW_CAMERA); - uiMenuItemEnumO(head, "", 0, "VIEW3D_OT_viewnumpad", "type", V3D_VIEW_TOP); - uiMenuItemEnumO(head, "", 0, "VIEW3D_OT_viewnumpad", "type", V3D_VIEW_FRONT); - uiMenuItemEnumO(head, "", 0, "VIEW3D_OT_viewnumpad", "type", V3D_VIEW_RIGHT); + uiItemEnumO(layout, NULL, 0, "VIEW3D_OT_viewnumpad", "type", V3D_VIEW_CAMERA); + uiItemEnumO(layout, NULL, 0, "VIEW3D_OT_viewnumpad", "type", V3D_VIEW_TOP); + uiItemEnumO(layout, NULL, 0, "VIEW3D_OT_viewnumpad", "type", V3D_VIEW_FRONT); + uiItemEnumO(layout, NULL, 0, "VIEW3D_OT_viewnumpad", "type", V3D_VIEW_RIGHT); - //uiMenuLevel(head, "Cameras", view3d_view_camerasmenu); + //uiItemLevel(layout, "Cameras", view3d_view_camerasmenu); - uiMenuSeparator(head); + uiItemS(layout); - uiMenuItemO(head, 0, "VIEW3D_OT_view_persportho"); + uiItemO(layout, NULL, 0, "VIEW3D_OT_view_persportho"); - uiMenuSeparator(head); + uiItemS(layout); -// uiMenuItemO(head, 0, "VIEW3D_OT_view_show_all_layers"); +// uiItemO(layout, NULL, 0, "VIEW3D_OT_view_show_all_layers"); -// uiMenuSeparator(head); +// uiItemS(layout); -// uiMenuItemO(head, 0, "VIEW3D_OT_view_local_view"); -// uiMenuItemO(head, 0, "VIEW3D_OT_view_global_view"); +// uiItemO(layout, NULL, 0, "VIEW3D_OT_view_local_view"); +// uiItemO(layout, NULL, 0, "VIEW3D_OT_view_global_view"); -// uiMenuSeparator(head); +// uiItemS(layout); - uiMenuLevel(head, "View Navigation", view3d_view_viewnavmenu); - uiMenuLevel(head, "Align View", view3d_view_alignviewmenu); + uiItemLevel(layout, "View Navigation", 0, view3d_view_viewnavmenu); + uiItemLevel(layout, "Align View", 0, view3d_view_alignviewmenu); - uiMenuSeparator(head); + uiItemS(layout); - uiMenuContext(head, WM_OP_INVOKE_REGION_WIN); + uiLayoutContext(layout, WM_OP_INVOKE_REGION_WIN); - uiMenuItemO(head, 0, "VIEW3D_OT_clipping"); - uiMenuItemO(head, 0, "VIEW3D_OT_zoom_border"); + uiItemO(layout, NULL, 0, "VIEW3D_OT_clipping"); + uiItemO(layout, NULL, 0, "VIEW3D_OT_zoom_border"); - uiMenuSeparator(head); + uiItemS(layout); - uiMenuItemO(head, 0, "VIEW3D_OT_viewcenter"); - uiMenuItemO(head, 0, "VIEW3D_OT_viewhome"); + uiItemO(layout, NULL, 0, "VIEW3D_OT_viewcenter"); + uiItemO(layout, NULL, 0, "VIEW3D_OT_viewhome"); - uiMenuSeparator(head); + uiItemS(layout); - if(sa->full) uiMenuItemO(head, 0, "SCREEN_OT_screen_full_area"); // "Tile Window", Ctrl UpArrow - else uiMenuItemO(head, 0, "SCREEN_OT_screen_full_area"); // "Maximize Window", Ctr DownArrow + if(sa->full) uiItemO(layout, NULL, 0, "SCREEN_OT_screen_full_area"); // "Tile Window", Ctrl UpArrow + else uiItemO(layout, NULL, 0, "SCREEN_OT_screen_full_area"); // "Maximize Window", Ctr DownArrow } #if 0 static uiBlock *view3d_viewmenu(bContext *C, ARegion *ar, void *arg_unused) @@ -1208,39 +1208,39 @@ static uiBlock *view3d_select_meshmenu(bContext *C, ARegion *ar, void *arg_unuse return block; } -static void view3d_select_curvemenu(bContext *C, uiMenuItem *head, void *arg_unused) +static void view3d_select_curvemenu(bContext *C, uiLayout *layout, void *arg_unused) { Object *obedit= CTX_data_edit_object(C); - uiMenuItemO(head, 0, "VIEW3D_OT_select_border"); - uiMenuItemO(head, 0, "VIEW3D_OT_select_circle"); + uiItemO(layout, NULL, 0, "VIEW3D_OT_select_border"); + uiItemO(layout, NULL, 0, "VIEW3D_OT_select_circle"); - uiMenuSeparator(head); + uiItemS(layout); - uiMenuItemO(head, 0, "CURVE_OT_select_all_toggle"); - uiMenuItemO(head, 0, "CURVE_OT_select_invert"); - uiMenuItemO(head, 0, "CURVE_OT_select_random"); // Random... - uiMenuItemO(head, 0, "CURVE_OT_select_every_nth"); // Every Nth.. + uiItemO(layout, NULL, 0, "CURVE_OT_select_all_toggle"); + uiItemO(layout, NULL, 0, "CURVE_OT_select_invert"); + uiItemO(layout, NULL, 0, "CURVE_OT_select_random"); // Random... + uiItemO(layout, NULL, 0, "CURVE_OT_select_every_nth"); // Every Nth.. - uiMenuSeparator(head); + uiItemS(layout); if(obedit->type == OB_SURF) { - uiMenuItemO(head, 0, "CURVE_OT_select_row"); + uiItemO(layout, NULL, 0, "CURVE_OT_select_row"); } else { - uiMenuItemO(head, 0, "CURVE_OT_de_select_first"); - uiMenuItemO(head, 0, "CURVE_OT_de_select_last"); - uiMenuItemO(head, 0, "CURVE_OT_select_next"); - uiMenuItemO(head, 0, "CURVE_OT_select_previous"); + uiItemO(layout, NULL, 0, "CURVE_OT_de_select_first"); + uiItemO(layout, NULL, 0, "CURVE_OT_de_select_last"); + uiItemO(layout, NULL, 0, "CURVE_OT_select_next"); + uiItemO(layout, NULL, 0, "CURVE_OT_select_previous"); } - uiMenuSeparator(head); + uiItemS(layout); - uiMenuItemO(head, 0, "CURVE_OT_select_more"); - uiMenuItemO(head, 0, "CURVE_OT_select_less"); + uiItemO(layout, NULL, 0, "CURVE_OT_select_more"); + uiItemO(layout, NULL, 0, "CURVE_OT_select_less"); /* commented out because it seems to only like the LKEY method - based on mouse pointer position :( */ - /* uiMenuItemO(head, 0, "CURVE_OT_select_linked"); */ + /* uiItemO(layout, NULL, 0, "CURVE_OT_select_linked"); */ #if 0 G.qual |= LR_CTRLKEY; @@ -3288,44 +3288,44 @@ static uiBlock *view3d_edit_meshmenu(bContext *C, ARegion *ar, void *arg_unused) return block; } -static void view3d_edit_curve_controlpointsmenu(bContext *C, uiMenuItem *head, void *arg_unused) +static void view3d_edit_curve_controlpointsmenu(bContext *C, uiLayout *layout, void *arg_unused) { Object *obedit= CTX_data_edit_object(C); if(obedit->type == OB_CURVE) { - uiMenuItemEnumO(head, "", 0, "TFM_OT_transform", "mode", TFM_TILT); - uiMenuItemO(head, 0, "CURVE_OT_tilt_clear"); - uiMenuItemO(head, 0, "CURVE_OT_separate"); + uiItemEnumO(layout, NULL, 0, "TFM_OT_transform", "mode", TFM_TILT); + uiItemO(layout, NULL, 0, "CURVE_OT_tilt_clear"); + uiItemO(layout, NULL, 0, "CURVE_OT_separate"); - uiMenuSeparator(head); + uiItemS(layout); - uiMenuItemEnumO(head, "", 0, "CURVE_OT_handle_type_set", "type", 1); - uiMenuItemEnumO(head, "", 0, "CURVE_OT_handle_type_set", "type", 3); - uiMenuItemEnumO(head, "", 0, "CURVE_OT_handle_type_set", "type", 2); + uiItemEnumO(layout, NULL, 0, "CURVE_OT_handle_type_set", "type", 1); + uiItemEnumO(layout, NULL, 0, "CURVE_OT_handle_type_set", "type", 3); + uiItemEnumO(layout, NULL, 0, "CURVE_OT_handle_type_set", "type", 2); - uiMenuSeparator(head); + uiItemS(layout); } - // XXX uiMenuItemO(head, 0, "OBJECT_OT_make_vertex_parent"); Make VertexParent|Ctrl P + // XXX uiItemO(layout, NULL, 0, "OBJECT_OT_make_vertex_parent"); Make VertexParent|Ctrl P // make_parent() - // XXX uiMenuItemO(head, 0, "OBJECT_OT_add_hook"); Add Hook| Ctrl H + // XXX uiItemO(layout, NULL, 0, "OBJECT_OT_add_hook"); Add Hook| Ctrl H // add_hook_menu() } -static void view3d_edit_curve_segmentsmenu(bContext *C, uiMenuItem *head, void *arg_unused) +static void view3d_edit_curve_segmentsmenu(bContext *C, uiLayout *layout, void *arg_unused) { - uiMenuItemO(head, 0, "CURVE_OT_subdivide"); - uiMenuItemO(head, 0, "CURVE_OT_switch_direction"); + uiItemO(layout, NULL, 0, "CURVE_OT_subdivide"); + uiItemO(layout, NULL, 0, "CURVE_OT_switch_direction"); } -static void view3d_edit_curve_showhidemenu(bContext *C, uiMenuItem *head, void *arg_unused) +static void view3d_edit_curve_showhidemenu(bContext *C, uiLayout *layout, void *arg_unused) { - uiMenuItemO(head, 0, "CURVE_OT_reveal"); - uiMenuItemO(head, 0, "CURVE_OT_hide"); - uiMenuItemBooleanO(head, "Hide Unselected", 0, "CURVE_OT_hide", "unselected", 1); + uiItemO(layout, NULL, 0, "CURVE_OT_reveal"); + uiItemO(layout, NULL, 0, "CURVE_OT_hide"); + uiItemBooleanO(layout, "Hide Unselected", 0, "CURVE_OT_hide", "unselected", 1); } -static void view3d_edit_curvemenu(bContext *C, uiMenuItem *head, void *arg_unused) +static void view3d_edit_curvemenu(bContext *C, uiLayout *layout, void *arg_unused) { PointerRNA sceneptr; Scene *scene= CTX_data_scene(C); @@ -3338,7 +3338,7 @@ static void view3d_edit_curvemenu(bContext *C, uiMenuItem *head, void *arg_unuse uiDefIconTextBlockBut(block, view3d_edit_mirrormenu, NULL, ICON_RIGHTARROW_THIN, "Mirror", 0, yco-=20, menuwidth, 19, ""); uiDefIconTextBlockBut(block, view3d_edit_snapmenu, NULL, ICON_RIGHTARROW_THIN, "Snap", 0, yco-=20, 120, 19, ""); - uiMenuSeparator(head); + uiItemS(layout); #endif // XXX uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Insert Keyframe|I", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, ""); @@ -3347,26 +3347,26 @@ static void view3d_edit_curvemenu(bContext *C, uiMenuItem *head, void *arg_unuse // common_deletekey(); - uiMenuItemO(head, 0, "CURVE_OT_extrude"); - uiMenuItemO(head, 0, "CURVE_OT_duplicate"); - uiMenuItemO(head, 0, "CURVE_OT_separate"); - uiMenuItemO(head, 0, "CURVE_OT_make_segment"); - uiMenuItemO(head, 0, "CURVE_OT_cyclic_toggle"); - uiMenuItemO(head, 0, "CURVE_OT_delete"); // Delete... + uiItemO(layout, NULL, 0, "CURVE_OT_extrude"); + uiItemO(layout, NULL, 0, "CURVE_OT_duplicate"); + uiItemO(layout, NULL, 0, "CURVE_OT_separate"); + uiItemO(layout, NULL, 0, "CURVE_OT_make_segment"); + uiItemO(layout, NULL, 0, "CURVE_OT_cyclic_toggle"); + uiItemO(layout, NULL, 0, "CURVE_OT_delete"); // Delete... - uiMenuSeparator(head); + uiItemS(layout); - uiMenuLevel(head, "Control Points", view3d_edit_curve_controlpointsmenu); - uiMenuLevel(head, "Segments", view3d_edit_curve_segmentsmenu); + uiItemLevel(layout, "Control Points", 0, view3d_edit_curve_controlpointsmenu); + uiItemLevel(layout, "Segments", 0, view3d_edit_curve_segmentsmenu); - uiMenuSeparator(head); + uiItemS(layout); - uiMenuItemBooleanR(head, &sceneptr, "proportional_editing"); // |O - uiMenuLevelEnumR(head, &sceneptr, "proportional_editing_falloff"); + uiItemR(layout, NULL, 0, &sceneptr, "proportional_editing", 0); // |O + uiItemLevelEnumR(layout, NULL, 0, &sceneptr, "proportional_editing_falloff"); - uiMenuSeparator(head); + uiItemS(layout); - uiMenuLevel(head, "Show/Hide Control Points", view3d_edit_curve_showhidemenu); + uiItemLevel(layout, "Show/Hide Control Points", 0, view3d_edit_curve_showhidemenu); } static void do_view3d_edit_mball_showhidemenu(bContext *C, void *arg, int event) @@ -3477,43 +3477,43 @@ static uiBlock *view3d_edit_metaballmenu(bContext *C, ARegion *ar, void *arg_unu return block; } -static void view3d_edit_text_charsmenu(bContext *C, uiMenuItem *head, void *arg_unused) +static void view3d_edit_text_charsmenu(bContext *C, uiLayout *layout, void *arg_unused) { /* the character codes are specified in UTF-8 */ - uiMenuItemStringO(head, "Copyright|Alt C", 0, "FONT_OT_text_insert", "text", "\xC2\xA9"); - uiMenuItemStringO(head, "Registered Trademark|Alt R", 0, "FONT_OT_text_insert", "text", "\xC2\xAE"); + uiItemStringO(layout, "Copyright|Alt C", 0, "FONT_OT_text_insert", "text", "\xC2\xA9"); + uiItemStringO(layout, "Registered Trademark|Alt R", 0, "FONT_OT_text_insert", "text", "\xC2\xAE"); - uiMenuSeparator(head); + uiItemS(layout); - uiMenuItemStringO(head, "Degree Sign|Alt G", 0, "FONT_OT_text_insert", "text", "\xC2\xB0"); - uiMenuItemStringO(head, "Multiplication Sign|Alt x", 0, "FONT_OT_text_insert", "text", "\xC3\x97"); - uiMenuItemStringO(head, "Circle|Alt .", 0, "FONT_OT_text_insert", "text", "\xC2\x8A"); - uiMenuItemStringO(head, "Superscript 1|Alt 1", 0, "FONT_OT_text_insert", "text", "\xC2\xB9"); - uiMenuItemStringO(head, "Superscript 2|Alt 2", 0, "FONT_OT_text_insert", "text", "\xC2\xB2"); - uiMenuItemStringO(head, "Superscript 3|Alt 3", 0, "FONT_OT_text_insert", "text", "\xC2\xB3"); - uiMenuItemStringO(head, "Double >>|Alt >", 0, "FONT_OT_text_insert", "text", "\xC2\xBB"); - uiMenuItemStringO(head, "Double <<|Alt <", 0, "FONT_OT_text_insert", "text", "\xC2\xAB"); - uiMenuItemStringO(head, "Promillage|Alt %", 0, "FONT_OT_text_insert", "text", "\xE2\x80\xB0"); + uiItemStringO(layout, "Degree Sign|Alt G", 0, "FONT_OT_text_insert", "text", "\xC2\xB0"); + uiItemStringO(layout, "Multiplication Sign|Alt x", 0, "FONT_OT_text_insert", "text", "\xC3\x97"); + uiItemStringO(layout, "Circle|Alt .", 0, "FONT_OT_text_insert", "text", "\xC2\x8A"); + uiItemStringO(layout, "Superscript 1|Alt 1", 0, "FONT_OT_text_insert", "text", "\xC2\xB9"); + uiItemStringO(layout, "Superscript 2|Alt 2", 0, "FONT_OT_text_insert", "text", "\xC2\xB2"); + uiItemStringO(layout, "Superscript 3|Alt 3", 0, "FONT_OT_text_insert", "text", "\xC2\xB3"); + uiItemStringO(layout, "Double >>|Alt >", 0, "FONT_OT_text_insert", "text", "\xC2\xBB"); + uiItemStringO(layout, "Double <<|Alt <", 0, "FONT_OT_text_insert", "text", "\xC2\xAB"); + uiItemStringO(layout, "Promillage|Alt %", 0, "FONT_OT_text_insert", "text", "\xE2\x80\xB0"); - uiMenuSeparator(head); + uiItemS(layout); - uiMenuItemStringO(head, "Dutch Florin|Alt F", 0, "FONT_OT_text_insert", "text", "\xC2\xA4"); - uiMenuItemStringO(head, "British Pound|Alt L", 0, "FONT_OT_text_insert", "text", "\xC2\xA3"); - uiMenuItemStringO(head, "Japanese Yen|Alt Y", 0, "FONT_OT_text_insert", "text", "\xC2\xA5"); + uiItemStringO(layout, "Dutch Florin|Alt F", 0, "FONT_OT_text_insert", "text", "\xC2\xA4"); + uiItemStringO(layout, "British Pound|Alt L", 0, "FONT_OT_text_insert", "text", "\xC2\xA3"); + uiItemStringO(layout, "Japanese Yen|Alt Y", 0, "FONT_OT_text_insert", "text", "\xC2\xA5"); - uiMenuSeparator(head); + uiItemS(layout); - uiMenuItemStringO(head, "German S|Alt S", 0, "FONT_OT_text_insert", "text", "\xC3\x9F"); - uiMenuItemStringO(head, "Spanish Question Mark|Alt ?", 0, "FONT_OT_text_insert", "text", "\xC2\xBF"); - uiMenuItemStringO(head, "Spanish Exclamation Mark|Alt !", 0, "FONT_OT_text_insert", "text", "\xC2\xA1"); + uiItemStringO(layout, "German S|Alt S", 0, "FONT_OT_text_insert", "text", "\xC3\x9F"); + uiItemStringO(layout, "Spanish Question Mark|Alt ?", 0, "FONT_OT_text_insert", "text", "\xC2\xBF"); + uiItemStringO(layout, "Spanish Exclamation Mark|Alt !", 0, "FONT_OT_text_insert", "text", "\xC2\xA1"); } -static void view3d_edit_textmenu(bContext *C, uiMenuItem *head, void *arg_unused) +static void view3d_edit_textmenu(bContext *C, uiLayout *layout, void *arg_unused) { - uiMenuItemO(head, 0, "FONT_OT_file_paste"); - uiMenuSeparator(head); - uiMenuLevel(head, "Special Characters", view3d_edit_text_charsmenu); + uiItemO(layout, NULL, 0, "FONT_OT_file_paste"); + uiItemS(layout); + uiItemLevel(layout, "Special Characters", 0, view3d_edit_text_charsmenu); } static void do_view3d_edit_latticemenu(bContext *C, void *arg, int event) @@ -4527,7 +4527,7 @@ uiBlock *view3d_sculpt_inputmenu(bContext *C, ARegion *ar, void *arg_unused) return block; } -static void view3d_sculpt_menu(bContext *C, uiMenuItem *head, void *arg_unused) +static void view3d_sculpt_menu(bContext *C, uiLayout *layout, void *arg_unused) { bScreen *sc= CTX_wm_screen(C); Sculpt *s = CTX_data_tool_settings(C)->sculpt; @@ -4535,30 +4535,30 @@ static void view3d_sculpt_menu(bContext *C, uiMenuItem *head, void *arg_unused) RNA_pointer_create(&sc->id, &RNA_Sculpt, s, &rna); - uiMenuItemBooleanR(head, &rna, "symmetry_x"); - uiMenuItemBooleanR(head, &rna, "symmetry_y"); - uiMenuItemBooleanR(head, &rna, "symmetry_z"); - uiMenuItemBooleanR(head, &rna, "lock_x"); - uiMenuItemBooleanR(head, &rna, "lock_y"); - uiMenuItemBooleanR(head, &rna, "lock_z"); + uiItemR(layout, NULL, 0, &rna, "symmetry_x", 0); + uiItemR(layout, NULL, 0, &rna, "symmetry_y", 0); + uiItemR(layout, NULL, 0, &rna, "symmetry_z", 0); + uiItemR(layout, NULL, 0, &rna, "lock_x", 0); + uiItemR(layout, NULL, 0, &rna, "lock_y", 0); + uiItemR(layout, NULL, 0, &rna, "lock_z", 0); /* Brush settings */ RNA_pointer_create(&sc->id, &RNA_Brush, s->brush, &rna); /* Curve */ - uiMenuSeparator(head); - uiMenuItemEnumO(head, "", 0, "SCULPT_OT_brush_curve_preset", "mode", BRUSH_PRESET_SHARP); - uiMenuItemEnumO(head, "", 0, "SCULPT_OT_brush_curve_preset", "mode", BRUSH_PRESET_SMOOTH); - uiMenuItemEnumO(head, "", 0, "SCULPT_OT_brush_curve_preset", "mode", BRUSH_PRESET_MAX); + uiItemS(layout); + uiItemEnumO(layout, NULL, 0, "SCULPT_OT_brush_curve_preset", "mode", BRUSH_PRESET_SHARP); + uiItemEnumO(layout, NULL, 0, "SCULPT_OT_brush_curve_preset", "mode", BRUSH_PRESET_SMOOTH); + uiItemEnumO(layout, NULL, 0, "SCULPT_OT_brush_curve_preset", "mode", BRUSH_PRESET_MAX); - uiMenuSeparator(head); + uiItemS(layout); - uiMenuItemBooleanR(head, &rna, "airbrush"); - uiMenuItemBooleanR(head, &rna, "rake"); - uiMenuItemBooleanR(head, &rna, "anchored"); - uiMenuItemBooleanR(head, &rna, "space"); + uiItemR(layout, NULL, 0, &rna, "airbrush", 0); + uiItemR(layout, NULL, 0, &rna, "rake", 0); + uiItemR(layout, NULL, 0, &rna, "anchored", 0); + uiItemR(layout, NULL, 0, &rna, "space", 0); - uiMenuItemBooleanR(head, &rna, "flip_direction"); + uiItemR(layout, NULL, 0, &rna, "flip_direction", 0); } uiBlock *view3d_sculptmenu(bContext *C, ARegion *ar, void *arg_unused) @@ -4695,59 +4695,59 @@ static uiBlock *view3d_faceselmenu(bContext *C, ARegion *ar, void *arg_unused) return block; } -static void view3d_select_particlemenu(bContext *C, uiMenuItem *head, void *arg_unused) +static void view3d_select_particlemenu(bContext *C, uiLayout *layout, void *arg_unused) { Scene *scene= CTX_data_scene(C); - uiMenuItemO(head, 0, "VIEW3D_OT_select_border"); + uiItemO(layout, NULL, 0, "VIEW3D_OT_select_border"); - uiMenuSeparator(head); + uiItemS(layout); - uiMenuItemO(head, 0, "PARTICLE_OT_select_all_toggle"); - uiMenuItemO(head, 0, "PARTICLE_OT_select_linked"); + uiItemO(layout, NULL, 0, "PARTICLE_OT_select_all_toggle"); + uiItemO(layout, NULL, 0, "PARTICLE_OT_select_linked"); if(scene->selectmode & SCE_SELECT_POINT) { - uiMenuItemO(head, 0, "PARTICLE_OT_select_last"); // |W, 4 - uiMenuItemO(head, 0, "PARTICLE_OT_select_first"); // |W, 3 + uiItemO(layout, NULL, 0, "PARTICLE_OT_select_last"); // |W, 4 + uiItemO(layout, NULL, 0, "PARTICLE_OT_select_first"); // |W, 3 } - uiMenuSeparator(head); + uiItemS(layout); - uiMenuItemO(head, 0, "PARTICLE_OT_select_more"); - uiMenuItemO(head, 0, "PARTICLE_OT_select_less"); + uiItemO(layout, NULL, 0, "PARTICLE_OT_select_more"); + uiItemO(layout, NULL, 0, "PARTICLE_OT_select_less"); } -static void view3d_particle_showhidemenu(bContext *C, uiMenuItem *head, void *arg_unused) +static void view3d_particle_showhidemenu(bContext *C, uiLayout *layout, void *arg_unused) { - uiMenuItemO(head, 0, "PARTICLE_OT_reveal"); - uiMenuItemO(head, 0, "PARTICLE_OT_hide"); - uiMenuItemBooleanO(head, "Hide Unselected", 0, "PARTICLE_OT_hide", "unselected", 1); + uiItemO(layout, NULL, 0, "PARTICLE_OT_reveal"); + uiItemO(layout, NULL, 0, "PARTICLE_OT_hide"); + uiItemBooleanO(layout, "Hide Unselected", 0, "PARTICLE_OT_hide", "unselected", 1); } -static void view3d_particlemenu(bContext *C, uiMenuItem *head, void *arg_unused) +static void view3d_particlemenu(bContext *C, uiLayout *layout, void *arg_unused) { Scene *scene= CTX_data_scene(C); // XXX uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "Particle Edit Properties|N", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, ""); // add_blockhandler(sa, VIEW3D_HANDLER_OBJECT, UI_PNL_UNSTOW); - // XXX uiMenuSeparator(head); + // XXX uiItemS(layout); // // XXX uiDefIconTextBut(block, BUTM, 1, (pset->flag & PE_X_MIRROR)? ICON_CHECKBOX_HLT: ICON_CHECKBOX_DEHLT, "X-Axis Mirror Editing", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, ""); // pset->flag ^= PE_X_MIRROR; - uiMenuItemO(head, 0, "PARTICLE_OT_mirror"); // |Ctrl M + uiItemO(layout, NULL, 0, "PARTICLE_OT_mirror"); // |Ctrl M - uiMenuSeparator(head); + uiItemS(layout); - uiMenuItemO(head, 0, "PARTICLE_OT_remove_doubles"); // |W, 5 - uiMenuItemO(head, 0, "PARTICLE_OT_delete"); + uiItemO(layout, NULL, 0, "PARTICLE_OT_remove_doubles"); // |W, 5 + uiItemO(layout, NULL, 0, "PARTICLE_OT_delete"); if(scene->selectmode & SCE_SELECT_POINT) - uiMenuItemO(head, 0, "PARTICLE_OT_subdivide"); // |W, 2 - uiMenuItemO(head, 0, "PARTICLE_OT_rekey"); // |W, 1 + uiItemO(layout, NULL, 0, "PARTICLE_OT_subdivide"); // |W, 2 + uiItemO(layout, NULL, 0, "PARTICLE_OT_rekey"); // |W, 1 - uiMenuSeparator(head); + uiItemS(layout); - uiMenuLevel(head, "Show/Hide Particles", view3d_particle_showhidemenu); + uiItemLevel(layout, "Show/Hide Particles", 0, view3d_particle_showhidemenu); } static char *view3d_modeselect_pup(Scene *scene) @@ -5553,18 +5553,20 @@ void view3d_header_buttons(const bContext *C, ARegion *ar) /* edit face toolbox */ static int editmesh_face_toolbox_invoke(bContext *C, wmOperator *op, wmEvent *event) { - uiMenuItem *head; + uiPopupMenu *pup; + uiLayout *layout; - head= uiPupMenuBegin("Edit Faces", 0); + pup= uiPupMenuBegin("Edit Faces", 0); + layout= uiPupMenuLayout(pup); - uiMenuItemO(head, 0, "MESH_OT_fill"); - uiMenuItemO(head, 0, "MESH_OT_beauty_fill"); - uiMenuItemO(head, 0, "MESH_OT_quads_convert_to_tris"); - uiMenuItemO(head, 0, "MESH_OT_tris_convert_to_quads"); - uiMenuItemO(head, 0, "MESH_OT_edge_flip"); - uiMenuItemO(head, 0, "MESH_OT_faces_shade_smooth"); - uiMenuItemO(head, 0, "MESH_OT_faces_shade_solid"); - uiPupMenuEnd(C, head); + uiItemO(layout, NULL, 0, "MESH_OT_fill"); + uiItemO(layout, NULL, 0, "MESH_OT_beauty_fill"); + uiItemO(layout, NULL, 0, "MESH_OT_quads_convert_to_tris"); + uiItemO(layout, NULL, 0, "MESH_OT_tris_convert_to_quads"); + uiItemO(layout, NULL, 0, "MESH_OT_edge_flip"); + uiItemO(layout, NULL, 0, "MESH_OT_faces_shade_smooth"); + uiItemO(layout, NULL, 0, "MESH_OT_faces_shade_solid"); + uiPupMenuEnd(C, pup); return OPERATOR_CANCELLED; } diff --git a/source/blender/editors/space_view3d/view3d_snap.c b/source/blender/editors/space_view3d/view3d_snap.c index ad9d3f85538..7b417c94a73 100644 --- a/source/blender/editors/space_view3d/view3d_snap.c +++ b/source/blender/editors/space_view3d/view3d_snap.c @@ -1113,17 +1113,18 @@ int minmax_verts(Object *obedit, float *min, float *max) static int snap_menu_invoke(bContext *C, wmOperator *unused, wmEvent *event) { - uiMenuItem *head= uiPupMenuBegin("Snap", 0); + uiPopupMenu *pup= uiPupMenuBegin("Snap", 0); + uiLayout *layout= uiPupMenuLayout(pup); - uiMenuItemO(head, 0, "VIEW3D_OT_snap_selected_to_grid"); - uiMenuItemO(head, 0, "VIEW3D_OT_snap_selected_to_cursor"); - uiMenuItemO(head, 0, "VIEW3D_OT_snap_selected_to_center"); - uiMenuSeparator(head); - uiMenuItemO(head, 0, "VIEW3D_OT_snap_cursor_to_selected"); - uiMenuItemO(head, 0, "VIEW3D_OT_snap_cursor_to_grid"); - uiMenuItemO(head, 0, "VIEW3D_OT_snap_cursor_to_active"); + uiItemO(layout, NULL, 0, "VIEW3D_OT_snap_selected_to_grid"); + uiItemO(layout, NULL, 0, "VIEW3D_OT_snap_selected_to_cursor"); + uiItemO(layout, NULL, 0, "VIEW3D_OT_snap_selected_to_center"); + uiItemS(layout); + uiItemO(layout, NULL, 0, "VIEW3D_OT_snap_cursor_to_selected"); + uiItemO(layout, NULL, 0, "VIEW3D_OT_snap_cursor_to_grid"); + uiItemO(layout, NULL, 0, "VIEW3D_OT_snap_cursor_to_active"); - uiPupMenuEnd(C, head); + uiPupMenuEnd(C, pup); /* this operator is only for a menu, not used further */ return OPERATOR_CANCELLED; diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c index f5a581fc4fd..46a6f121990 100644 --- a/source/blender/editors/transform/transform_ops.c +++ b/source/blender/editors/transform/transform_ops.c @@ -119,11 +119,13 @@ static int select_orientation_exec(bContext *C, wmOperator *op) static int select_orientation_invoke(bContext *C, wmOperator *op, wmEvent *event) { - uiMenuItem *head; + uiPopupMenu *pup; + uiLayout *layout; - head= uiPupMenuBegin("Orientation", 0); - BIF_menuTransformOrientation(C, head, NULL); - uiPupMenuEnd(C, head); + pup= uiPupMenuBegin("Orientation", 0); + layout= uiPupMenuLayout(pup); + BIF_menuTransformOrientation(C, layout, NULL); + uiPupMenuEnd(C, pup); return OPERATOR_CANCELLED; } diff --git a/source/blender/editors/transform/transform_orientations.c b/source/blender/editors/transform/transform_orientations.c index df785f92166..06fc7d99659 100644 --- a/source/blender/editors/transform/transform_orientations.c +++ b/source/blender/editors/transform/transform_orientations.c @@ -354,19 +354,19 @@ void BIF_selectTransformOrientationValue(bContext *C, int orientation) { v3d->twmode = orientation; } -void BIF_menuTransformOrientation(bContext *C, uiMenuItem *head, void *arg) +void BIF_menuTransformOrientation(bContext *C, uiLayout *layout, void *arg) { ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces; TransformOrientation *ts; int i= V3D_MANIP_CUSTOM; - uiMenuItemEnumO(head, "", 0, "TFM_OT_select_orientation", "orientation", V3D_MANIP_GLOBAL); - uiMenuItemEnumO(head, "", 0, "TFM_OT_select_orientation", "orientation", V3D_MANIP_LOCAL); - uiMenuItemEnumO(head, "", 0, "TFM_OT_select_orientation", "orientation", V3D_MANIP_NORMAL); - uiMenuItemEnumO(head, "", 0, "TFM_OT_select_orientation", "orientation", V3D_MANIP_VIEW); + uiItemEnumO(layout, NULL, 0, "TFM_OT_select_orientation", "orientation", V3D_MANIP_GLOBAL); + uiItemEnumO(layout, NULL, 0, "TFM_OT_select_orientation", "orientation", V3D_MANIP_LOCAL); + uiItemEnumO(layout, NULL, 0, "TFM_OT_select_orientation", "orientation", V3D_MANIP_NORMAL); + uiItemEnumO(layout, NULL, 0, "TFM_OT_select_orientation", "orientation", V3D_MANIP_VIEW); for(ts = transform_spaces->first; ts; ts = ts->next) - uiMenuItemIntO(head, ts->name, 0, "TFM_OT_select_orientation", "custom_index", i++); + uiItemIntO(layout, ts->name, 0, "TFM_OT_select_orientation", "custom_index", i++); } char * BIF_menustringTransformOrientation(const bContext *C, char *title) { diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c b/source/blender/editors/uvedit/uvedit_unwrap_ops.c index 4d12700d98c..be571c132ab 100644 --- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c +++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c @@ -1284,18 +1284,22 @@ void UV_OT_cube_project(wmOperatorType *ot) static int mapping_menu_invoke(bContext *C, wmOperator *op, wmEvent *event) { - uiMenuItem *head; - - head= uiPupMenuBegin("UV Mapping", 0); - uiMenuItemO(head, 0, "UV_OT_unwrap"); - uiMenuSeparator(head); - uiMenuItemO(head, 0, "UV_OT_cube_project"); - uiMenuItemO(head, 0, "UV_OT_cylinder_project"); - uiMenuItemO(head, 0, "UV_OT_sphere_project"); - uiMenuItemO(head, 0, "UV_OT_project_from_view"); - uiMenuSeparator(head); - uiMenuItemO(head, 0, "UV_OT_reset"); - uiPupMenuEnd(C, head); + uiPopupMenu *pup; + uiLayout *layout; + + pup= uiPupMenuBegin("UV Mapping", 0); + layout= uiPupMenuLayout(pup); + + uiItemO(layout, NULL, 0, "UV_OT_unwrap"); + uiItemS(layout); + uiItemO(layout, NULL, 0, "UV_OT_cube_project"); + uiItemO(layout, NULL, 0, "UV_OT_cylinder_project"); + uiItemO(layout, NULL, 0, "UV_OT_sphere_project"); + uiItemO(layout, NULL, 0, "UV_OT_project_from_view"); + uiItemS(layout); + uiItemO(layout, NULL, 0, "UV_OT_reset"); + + uiPupMenuEnd(C, pup); /* XXX python */ #ifndef DISABLE_PYTHON diff --git a/source/blender/makesdna/DNA_screen_types.h b/source/blender/makesdna/DNA_screen_types.h index d131bfc2081..77b0d6e2d49 100644 --- a/source/blender/makesdna/DNA_screen_types.h +++ b/source/blender/makesdna/DNA_screen_types.h @@ -110,6 +110,11 @@ typedef struct Header { struct uiLayout *layout; /* runtime for drawing */ } Header; +typedef struct Menu { + struct MenuType *type; /* runtime */ + struct uiLayout *layout; /* runtime for drawing */ +} Menu; + typedef struct ScrArea { struct ScrArea *next, *prev; diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h index a3dc657217a..0e19a6845da 100644 --- a/source/blender/makesdna/DNA_space_types.h +++ b/source/blender/makesdna/DNA_space_types.h @@ -137,9 +137,9 @@ typedef struct SpaceButs { short re_align; short oldkeypress; /* for keeping track of the sub tab key cycling */ - char pad, flag; + char flag, texact; - char texact, tab[7]; /* storing tabs for each context */ + char tab[8]; /* storing tabs for each context */ } SpaceButs; @@ -418,8 +418,8 @@ typedef struct SpaceImaSel { /* **************** SPACE DEFINES ********************* */ -/* button defines */ -/* warning: the values of these defines are used in sbuts->tabs[7] */ +/* button defines (deprecated) */ +/* warning: the values of these defines are used in sbuts->tabs[8] */ /* sbuts->mainb new */ #define CONTEXT_SCENE 0 #define CONTEXT_OBJECT 1 @@ -429,7 +429,7 @@ typedef struct SpaceImaSel { #define CONTEXT_SCRIPT 5 #define CONTEXT_LOGIC 6 -/* sbuts->mainb old */ +/* sbuts->mainb old (deprecated) */ #define BUTS_VIEW 0 #define BUTS_LAMP 1 #define BUTS_MAT 2 @@ -446,7 +446,7 @@ typedef struct SpaceImaSel { #define BUTS_CONSTRAINT 13 #define BUTS_EFFECTS 14 -/* sbuts->tab new */ +/* sbuts->tab new (deprecated) */ #define TAB_SHADING_MAT 0 #define TAB_SHADING_TEX 1 #define TAB_SHADING_RAD 2 diff --git a/source/blender/makesrna/intern/rna_context.c b/source/blender/makesrna/intern/rna_context.c index d3089917649..ece5b6cc1f9 100644 --- a/source/blender/makesrna/intern/rna_context.c +++ b/source/blender/makesrna/intern/rna_context.c @@ -37,31 +37,31 @@ static PointerRNA rna_Context_manager_get(PointerRNA *ptr) { bContext *C= (bContext*)ptr->data; - return rna_pointer_inherit_refine(ptr, &RNA_Region, CTX_wm_manager(C)); + return rna_pointer_inherit_refine(ptr, &RNA_WindowManager, CTX_wm_manager(C)); } /*static PointerRNA rna_Context_window_get(PointerRNA *ptr) { bContext *C= (bContext*)ptr->data; - return rna_pointer_inherit_refine(ptr, &RNA_Region, CTX_wm_window(C)); + return rna_pointer_inherit_refine(ptr, &RNA_Window, CTX_wm_window(C)); }*/ static PointerRNA rna_Context_screen_get(PointerRNA *ptr) { bContext *C= (bContext*)ptr->data; - return rna_pointer_inherit_refine(ptr, &RNA_Region, CTX_wm_screen(C)); + return rna_pointer_inherit_refine(ptr, &RNA_Screen, CTX_wm_screen(C)); } static PointerRNA rna_Context_area_get(PointerRNA *ptr) { bContext *C= (bContext*)ptr->data; - return rna_pointer_inherit_refine(ptr, &RNA_Region, CTX_wm_area(C)); + return rna_pointer_inherit_refine(ptr, &RNA_Area, CTX_wm_area(C)); } static PointerRNA rna_Context_space_data_get(PointerRNA *ptr) { bContext *C= (bContext*)ptr->data; - return rna_pointer_inherit_refine(ptr, &RNA_Region, CTX_wm_space_data(C)); + return rna_pointer_inherit_refine(ptr, &RNA_Space, CTX_wm_space_data(C)); } static PointerRNA rna_Context_region_get(PointerRNA *ptr) @@ -73,7 +73,7 @@ static PointerRNA rna_Context_region_get(PointerRNA *ptr) /*static PointerRNA rna_Context_region_data_get(PointerRNA *ptr) { bContext *C= (bContext*)ptr->data; - return rna_pointer_inherit_refine(ptr, &RNA_Region, CTX_wm_region_data(C)); + return rna_pointer_inherit_refine(ptr, &RNA_RegionData, CTX_wm_region_data(C)); }*/ static PointerRNA rna_Context_main_get(PointerRNA *ptr) diff --git a/source/blender/makesrna/intern/rna_screen.c b/source/blender/makesrna/intern/rna_screen.c index 5be3130609c..034fd603367 100644 --- a/source/blender/makesrna/intern/rna_screen.c +++ b/source/blender/makesrna/intern/rna_screen.c @@ -37,7 +37,7 @@ EnumPropertyItem region_type_items[] = { {RGN_TYPE_HEADER, "HEADER", "Header", ""}, {RGN_TYPE_CHANNELS, "CHANNELS", "Channels", ""}, {RGN_TYPE_TEMPORARY, "TEMPORARY", "Temporary", ""}, - {RGN_TYPE_UI, "BUTTONS_WINDOW", "Window", ""}, + {RGN_TYPE_UI, "UI", "UI", ""}, {0, NULL, NULL, NULL}}; #ifdef RNA_RUNTIME diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index 9950d70af24..229a260efce 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -341,7 +341,7 @@ static void rna_def_space_text(BlenderRNA *brna) RNA_def_property_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Text", "Text displayed and edited in this space."); RNA_def_property_pointer_funcs(prop, NULL, "rna_SpaceTextEditor_text_set"); - RNA_def_property_update(prop, NC_TEXT|ND_CURSOR, NULL); + RNA_def_property_update(prop, NC_TEXT|NA_EDITED, NULL); /* display */ prop= RNA_def_property(srna, "syntax_highlight", PROP_BOOLEAN, PROP_NONE); diff --git a/source/blender/makesrna/intern/rna_text.c b/source/blender/makesrna/intern/rna_text.c index 838822119e8..3dacd4c0898 100644 --- a/source/blender/makesrna/intern/rna_text.c +++ b/source/blender/makesrna/intern/rna_text.c @@ -40,6 +40,8 @@ #ifdef RNA_RUNTIME +int text_file_modified(Text *text); + static void rna_Text_filename_get(PointerRNA *ptr, char *value) { Text *text= (Text*)ptr->data; @@ -69,6 +71,12 @@ static void rna_Text_filename_set(PointerRNA *ptr, const char *value) text->name= NULL; } +static int rna_Text_modified_get(PointerRNA *ptr) +{ + Text *text= (Text*)ptr->data; + return text_file_modified(text); +} + static void rna_TextLine_line_get(PointerRNA *ptr, char *value) { TextLine *line= (TextLine*)ptr->data; @@ -174,6 +182,11 @@ static void rna_def_text(BlenderRNA *brna) RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Dirty", "Text file has been edited since last save."); + prop= RNA_def_property(srna, "modified", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_boolean_funcs(prop, "rna_Text_modified_get", NULL); + RNA_def_property_ui_text(prop, "Modified", "Text file on disk is different than the one in memory."); + prop= RNA_def_property(srna, "memory", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flags", TXT_ISMEM); RNA_def_property_clear_flag(prop, PROP_EDITABLE); diff --git a/source/blender/makesrna/intern/rna_ui.c b/source/blender/makesrna/intern/rna_ui.c index 4ad5273dd5d..405ae9a0f74 100644 --- a/source/blender/makesrna/intern/rna_ui.c +++ b/source/blender/makesrna/intern/rna_ui.c @@ -276,6 +276,121 @@ static StructRNA* rna_Header_refine(struct PointerRNA *htr) return (hdr->type)? hdr->type->py_srna: &RNA_Header; } +/* Menu */ + +static int menu_poll(const bContext *C, MenuType *pt) +{ + PointerRNA ptr; + ParameterList *list; + FunctionRNA *func; + void *ret; + int visible; + + RNA_pointer_create(NULL, pt->py_srna, NULL, &ptr); /* dummy */ + func= RNA_struct_find_function(&ptr, "poll"); + + list= RNA_parameter_list_create(&ptr, func); + RNA_parameter_set_lookup(list, "context", &C); + pt->py_call(&ptr, func, list); + + RNA_parameter_get_lookup(list, "visible", &ret); + visible= *(int*)ret; + + RNA_parameter_list_free(list); + + return visible; +} + +static void menu_draw(const bContext *C, Menu *hdr) +{ + PointerRNA mtr; + ParameterList *list; + FunctionRNA *func; + + RNA_pointer_create(&CTX_wm_screen(C)->id, hdr->type->py_srna, hdr, &mtr); + func= RNA_struct_find_function(&mtr, "draw"); + + list= RNA_parameter_list_create(&mtr, func); + RNA_parameter_set_lookup(list, "context", &C); + hdr->type->py_call(&mtr, func, list); + + RNA_parameter_list_free(list); +} + +static void rna_Menu_unregister(const bContext *C, StructRNA *type) +{ + ARegionType *art; + MenuType *mt= RNA_struct_blender_type_get(type); + + if(!mt) + return; + if(!(art=region_type_find(NULL, mt->space_type, RGN_TYPE_HEADER))) + return; + + BLI_freelinkN(&art->menutypes, mt); + RNA_struct_free(&BLENDER_RNA, type); + + /* update while blender is running */ + if(C) + WM_event_add_notifier(C, NC_SCREEN|NA_EDITED, NULL); +} + +static StructRNA *rna_Menu_register(const bContext *C, ReportList *reports, void *data, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free) +{ + ARegionType *art; + MenuType *mt, dummymt = {0}; + Menu dummymenu= {0}; + PointerRNA dummymtr; + int have_function[2]; + + /* setup dummy menu & menu type to store static properties in */ + dummymenu.type= &dummymt; + RNA_pointer_create(NULL, &RNA_Menu, &dummymenu, &dummymtr); + + /* validate the python class */ + if(validate(&dummymtr, data, have_function) != 0) + return NULL; + + if(!(art=region_type_find(reports, dummymt.space_type, RGN_TYPE_HEADER))) + return NULL; + + /* check if we have registered this menu type before, and remove it */ + for(mt=art->menutypes.first; mt; mt=mt->next) { + if(strcmp(mt->idname, dummymt.idname) == 0) { + if(mt->py_srna) + rna_Menu_unregister(C, mt->py_srna); + break; + } + } + + /* create a new menu type */ + mt= MEM_callocN(sizeof(MenuType), "python buttons menu"); + memcpy(mt, &dummymt, sizeof(dummymt)); + + mt->py_srna= RNA_def_struct(&BLENDER_RNA, mt->idname, "Menu"); + mt->py_data= data; + mt->py_call= call; + mt->py_free= free; + RNA_struct_blender_type_set(mt->py_srna, mt); + + mt->poll= (have_function[0])? menu_poll: NULL; + mt->draw= (have_function[1])? menu_draw: NULL; + + BLI_addtail(&art->menutypes, mt); + + /* update while blender is running */ + if(C) + WM_event_add_notifier(C, NC_SCREEN|NA_EDITED, NULL); + + return mt->py_srna; +} + +static StructRNA* rna_Menu_refine(struct PointerRNA *mtr) +{ + Menu *hdr= (Menu*)mtr->data; + return (hdr->type)? hdr->type->py_srna: &RNA_Menu; +} + #else static void rna_def_ui_layout(BlenderRNA *brna) @@ -373,11 +488,55 @@ static void rna_def_header(BlenderRNA *brna) RNA_def_property_flag(prop, PROP_REGISTER); } +static void rna_def_menu(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + FunctionRNA *func; + + srna= RNA_def_struct(brna, "Menu", NULL); + RNA_def_struct_ui_text(srna, "Menu", "Editor menu containing buttons."); + RNA_def_struct_sdna(srna, "Menu"); + RNA_def_struct_refine_func(srna, "rna_Menu_refine"); + RNA_def_struct_register_funcs(srna, "rna_Menu_register", "rna_Menu_unregister"); + + /* poll */ + func= RNA_def_function(srna, "poll", NULL); + RNA_def_function_ui_description(func, "Test if the menu is visible or not."); + RNA_def_function_flag(func, FUNC_REGISTER|FUNC_REGISTER_OPTIONAL); + RNA_def_function_return(func, RNA_def_boolean(func, "visible", 1, "", "")); + RNA_def_pointer(func, "context", "Context", "", ""); + + /* draw */ + func= RNA_def_function(srna, "draw", NULL); + RNA_def_function_ui_description(func, "Draw buttons into the menu UI layout."); + RNA_def_function_flag(func, FUNC_REGISTER); + RNA_def_pointer(func, "context", "Context", "", ""); + + prop= RNA_def_property(srna, "layout", PROP_POINTER, PROP_NONE); + RNA_def_property_struct_type(prop, "UILayout"); + + /* registration */ + prop= RNA_def_property(srna, "idname", PROP_STRING, PROP_NONE); + RNA_def_property_string_sdna(prop, NULL, "type->idname"); + RNA_def_property_flag(prop, PROP_REGISTER); + + prop= RNA_def_property(srna, "label", PROP_STRING, PROP_NONE); + RNA_def_property_string_sdna(prop, NULL, "type->label"); + RNA_def_property_flag(prop, PROP_REGISTER); + + prop= RNA_def_property(srna, "space_type", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "type->space_type"); + RNA_def_property_enum_items(prop, space_type_items); + RNA_def_property_flag(prop, PROP_REGISTER); +} + void RNA_def_ui(BlenderRNA *brna) { rna_def_ui_layout(brna); rna_def_panel(brna); rna_def_header(brna); + rna_def_menu(brna); } #endif diff --git a/source/blender/python/intern/bpy_ui.c b/source/blender/python/intern/bpy_ui.c index e7143e8f84c..0959cf0b6b6 100644 --- a/source/blender/python/intern/bpy_ui.c +++ b/source/blender/python/intern/bpy_ui.c @@ -63,20 +63,6 @@ static PyObject *Method_pupMenuEnd( PyObject * self, PyObject * args ) Py_RETURN_NONE; } -static PyObject *Method_menuItemO( PyObject * self, PyObject * args ) -{ - PyObject *py_head; - char *opname; - int icon; - - if( !PyArg_ParseTuple( args, "O!is:menuItemO", &PyCObject_Type, &py_head, &icon, &opname)) - return NULL; - - uiMenuItemO(PyCObject_AsVoidPtr(py_head), icon, opname); - - Py_RETURN_NONE; -} - static PyObject *Method_defButO( PyObject * self, PyObject * args ) { uiBut *but; @@ -405,7 +391,6 @@ static PyObject *Method_getWindowPtr( PyObject * self ) static struct PyMethodDef ui_methods[] = { {"pupMenuBegin", (PyCFunction)Method_pupMenuBegin, METH_VARARGS, ""}, {"pupMenuEnd", (PyCFunction)Method_pupMenuEnd, METH_VARARGS, ""}, - {"menuItemO", (PyCFunction)Method_menuItemO, METH_VARARGS, ""}, {"defButO", (PyCFunction)Method_defButO, METH_VARARGS, ""}, {"defAutoButR", (PyCFunction)Method_defAutoButR, METH_VARARGS, ""}, {"pupBlock", (PyCFunction)Method_pupBlock, METH_VARARGS, ""}, diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index c8a0dbd018a..5a10aa4490e 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -201,7 +201,8 @@ void WM_operator_properties_free(PointerRNA *ptr) int WM_menu_invoke(bContext *C, wmOperator *op, wmEvent *event) { PropertyRNA *prop= RNA_struct_find_property(op->ptr, "type"); - uiMenuItem *head; + uiPopupMenu *pup; + uiLayout *layout; if(prop==NULL) { printf("WM_menu_invoke: %s has no \"type\" enum property\n", op->type->idname); @@ -210,9 +211,10 @@ int WM_menu_invoke(bContext *C, wmOperator *op, wmEvent *event) printf("WM_menu_invoke: %s \"type\" is not an enum property\n", op->type->idname); } else { - head= uiPupMenuBegin(op->type->name, 0); - uiMenuItemsEnumO(head, op->type->idname, "type"); - uiPupMenuEnd(C, head); + pup= uiPupMenuBegin(op->type->name, 0); + layout= uiPupMenuLayout(pup); + uiItemsEnumO(layout, op->type->idname, "type"); + uiPupMenuEnd(C, pup); } return OPERATOR_CANCELLED; @@ -221,11 +223,13 @@ int WM_menu_invoke(bContext *C, wmOperator *op, wmEvent *event) /* op->invoke */ int WM_operator_confirm(bContext *C, wmOperator *op, wmEvent *event) { - uiMenuItem *head; + uiPopupMenu *pup; + uiLayout *layout; - head= uiPupMenuBegin("OK?", ICON_HELP); - uiMenuItemO(head, 0, op->type->idname); - uiPupMenuEnd(C, head); + pup= uiPupMenuBegin("OK?", ICON_HELP); + layout= uiPupMenuLayout(pup); + uiItemO(layout, NULL, 0, op->type->idname); + uiPupMenuEnd(C, pup); return OPERATOR_CANCELLED; } @@ -370,21 +374,23 @@ static int recentfile_exec(bContext *C, wmOperator *op) static int wm_recentfile_invoke(bContext *C, wmOperator *op, wmEvent *event) { struct RecentFile *recent; - uiMenuItem *head; + uiPopupMenu *pup; + uiLayout *layout; int i, ofs= 0; - head= uiPupMenuBegin("Open Recent", 0); + pup= uiPupMenuBegin("Open Recent", 0); + layout= uiPupMenuLayout(pup); if(G.sce[0]) { - uiMenuItemIntO(head, G.sce, 0, op->type->idname, "nr", 1); + uiItemIntO(layout, G.sce, 0, op->type->idname, "nr", 1); ofs = 1; } for(recent = G.recent_files.first, i=0; (i<U.recent_files) && (recent); recent = recent->next, i++) if(strcmp(recent->filename, G.sce)) - uiMenuItemIntO(head, recent->filename, 0, op->type->idname, "nr", i+ofs+1); + uiItemIntO(layout, recent->filename, 0, op->type->idname, "nr", i+ofs+1); - uiPupMenuEnd(C, head); + uiPupMenuEnd(C, pup); return OPERATOR_CANCELLED; } |