Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTon Roosendaal <ton@blender.org>2009-01-25 23:22:05 +0300
committerTon Roosendaal <ton@blender.org>2009-01-25 23:22:05 +0300
commit3c088f3434f7900d430b01d2e210a0aa529c93bc (patch)
treec5739218b7fafa62736389813f199edffb9996f0 /source/blender
parentcfd93426002d20a29827503e195d8773d45bef23 (diff)
2.5
Simple toolbox-style menu system. Brecht will review it though, and/or check on way to use it for menus. I tried to avoid uiBlock and rna stuff all over. :) Quick image test: http://www.blender.org/bf/rt.jpg Examples you can read in: - editors/screen/screen_ops.c:testing123() (press F5) - editors/object/object_edit.c:object_add_primitive_invoke() (press SHIFT+A) Concept is simple: uiMenuBegin(): returns a handle. uiMenuEnd(): puts it all to work. In between you can add items like: uiMenuItemVal(): a name, icon, retval (use uiMenuFunc()) uiMenuItemO(): an operator + icon uiMenuItemEnumO(): an operator, property name, value Sublevels go easy too: uiMenuLevel(): creates item for sublevel, with function pointer. Inside that function you can use all menu calls again. Levels can go as deep you want. uiMenuLevelEnumO(): creates operator sublevel for an enum
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenkernel/intern/screen.c5
-rw-r--r--source/blender/editors/include/UI_interface.h17
-rw-r--r--source/blender/editors/interface/interface.c3
-rw-r--r--source/blender/editors/interface/interface_handlers.c8
-rw-r--r--source/blender/editors/interface/interface_regions.c431
-rw-r--r--source/blender/editors/mesh/mesh_ops.c13
-rw-r--r--source/blender/editors/object/object_edit.c169
-rw-r--r--source/blender/editors/object/object_intern.h5
-rw-r--r--source/blender/editors/object/object_ops.c8
-rw-r--r--source/blender/editors/screen/screen_ops.c41
10 files changed, 677 insertions, 23 deletions
diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c
index ce5225d50b9..063c617e6bb 100644
--- a/source/blender/blenkernel/intern/screen.c
+++ b/source/blender/blenkernel/intern/screen.c
@@ -222,13 +222,14 @@ void BKE_area_region_free(SpaceType *st, ARegion *ar)
if(art && art->free)
art->free(ar);
+
+ if(ar->regiondata)
+ printf("regiondata free error\n");
}
else if(ar->type && ar->type->free)
ar->type->free(ar);
if(ar) {
- if(ar->regiondata)
- printf("regiondata free error\n");
BLI_freelistN(&ar->panels);
}
}
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 585979194cb..95a5220ecca 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -219,6 +219,23 @@ void uiPupmenuNotice(struct bContext *C, char *str, ...);
void uiPupmenuError(struct bContext *C, char *str, ...);
void uiPupmenuReports(struct bContext *C, struct ReportList *reports);
+/* Custom popup menus and toolbox */
+typedef struct uiMenuItem uiMenuItem;
+
+uiMenuItem *uiMenuBegin(const char *title);
+
+void uiMenuFunc(uiMenuItem *head, void (*eventfunc)(struct bContext *, void *, int), void *argv);
+void uiMenuContext(uiMenuItem *head, int opcontext);
+
+void uiMenuItemVal(uiMenuItem *head, const char *name, int icon, int argval);
+void uiMenuItemEnumO(uiMenuItem *head, char *opname, char *propname, int value);
+void uiMenuItemsEnumO(uiMenuItem *head, char *opname, char *propname);
+void uiMenuItemO(uiMenuItem *head, char *name, int icon);
+void uiMenuLevel(uiMenuItem *head, const char *name, void (*newlevel)(uiMenuItem *));
+void uiMenuLevelEnumO(uiMenuItem *head, char *opname, char *propname);
+
+void uiMenuEnd(struct bContext *C, struct uiMenuItem *head);
+
/* Block */
uiBlock *uiBeginBlock(const struct bContext *C, struct ARegion *region, char *name, short dt, short font);
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index b29d8b56912..f4696cab08c 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -486,7 +486,8 @@ static void ui_menu_block_set_keymaps(const bContext *C, uiBlock *block)
/* XXX bounds? */
for(but=block->buttons.first; but; but=but->next) {
- if(but->opname) {
+ /* only hotkey for menus without properties */
+ if(but->opname && but->opptr==NULL) {
if(WM_key_event_operator_string(C, but->opname, but->opcontext, buf, sizeof(buf))) {
butstr= MEM_mallocN(strlen(but->str)+strlen(buf)+2, "menu_block_set_keymaps");
strcpy(butstr, but->str);
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index ef4398608d1..bfe6057cfce 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -3340,12 +3340,12 @@ int ui_handle_menu_event(bContext *C, wmEvent *event, uiMenuBlockHandle *menu, i
but= ui_but_find_activated(ar);
if(but) {
if(ELEM(event->type, DOWNARROWKEY, WHEELDOWNMOUSE)) {
- if(block->direction & UI_DOWN) but= ui_but_next(but);
- else but= ui_but_prev(but);
+ if(block->direction & UI_TOP) but= ui_but_prev(but);
+ else but= ui_but_next(but);
}
else {
- if(block->direction & UI_DOWN) but= ui_but_prev(but);
- else but= ui_but_next(but);
+ if(block->direction & UI_TOP) but= ui_but_next(but);
+ else but= ui_but_prev(but);
}
if(but)
diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c
index f100a0f8965..d0343f55db3 100644
--- a/source/blender/editors/interface/interface_regions.c
+++ b/source/blender/editors/interface/interface_regions.c
@@ -49,6 +49,8 @@
#include "wm_subwindow.h"
#include "wm_window.h"
+#include "RNA_access.h"
+
#include "BIF_gl.h"
#include "UI_interface.h"
@@ -1796,3 +1798,432 @@ void uiPupmenuReports(bContext *C, ReportList *reports)
BLI_dynstr_free(ds);
}
+/* ******************* customize own menus, toolbox *************** */
+
+/* prototype */
+static uiBlock *ui_block_func_MENU_ITEM(bContext *C, uiMenuBlockHandle *handle, void *arg_info);
+
+#define MAX_MENU_STR 64
+
+/* type, internal */
+#define MENU_ITEM_TITLE 0
+#define MENU_ITEM_ITEM 1
+#define MENU_ITEM_OPNAME 2
+#define MENU_ITEM_OPNAME_ENUM 3
+#define MENU_ITEM_LEVEL 4
+#define MENU_ITEM_LEVEL_ENUM 5
+
+struct uiMenuItem {
+ struct uiMenuItem *next, *prev;
+
+ int type;
+ int icon;
+ char name[MAX_MENU_STR];
+
+ char *opname; /* static string */
+ char *propname; /* static string */
+
+ int retval;
+ int opcontext;
+ void (*eventfunc)(bContext *, void *, int);
+ void *argv;
+ void (*newlevel)(uiMenuItem *);
+
+ ListBase items;
+};
+
+typedef struct uiMenuInfo {
+ uiMenuItem *head;
+ int mx, my;
+ int startx, starty;
+} uiMenuInfo;
+
+/* 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= WM_OP_EXEC_REGION_WIN;
+
+ BLI_addtail(&head->items, item);
+
+ return item;
+}
+
+
+/* only return handler, and set optional title */
+uiMenuItem *uiMenuBegin(const char *title)
+{
+ uiMenuItem *item= MEM_callocN(sizeof(uiMenuItem), "menu start");
+
+ item->type = MENU_ITEM_TITLE;
+ item->opcontext= WM_OP_EXEC_REGION_WIN;
+
+ /* NULL is no title */
+ if(title)
+ BLI_strncpy(item->name, title, MAX_MENU_STR);
+
+ 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, char *name, int icon)
+{
+ uiMenuItem *item= ui_menu_add_item(head, name, icon, 0);
+
+ item->opname= name; // static!
+ item->type = MENU_ITEM_OPNAME;
+}
+
+/* Single operator item with property */
+void uiMenuItemEnumO(uiMenuItem *head, char *opname, char *propname, int value)
+{
+ uiMenuItem *item= ui_menu_add_item(head, "", 0, 0);
+
+ item->opname= opname; // static!
+ item->propname= propname; // static!
+ item->retval= value;
+ item->type = MENU_ITEM_OPNAME_ENUM;
+}
+
+/* Add all operator items with property */
+void uiMenuItemsEnumO(uiMenuItem *head, char *opname, char *propname)
+{
+ wmOperatorType *ot;
+
+ ot= WM_operatortype_find(opname);
+ if(ot) {
+ PointerRNA *opptr= MEM_callocN(sizeof(PointerRNA), "uiButOpPtr");
+ PropertyRNA *prop;
+
+ WM_operator_properties_create(opptr, opname);
+ prop= RNA_struct_find_property(opptr, propname);
+
+ if(prop) {
+ const EnumPropertyItem *item;
+ int totitem, i;
+
+ RNA_property_enum_items(opptr, prop, &item, &totitem);
+
+ for (i=0; i<totitem; i++) {
+ uiMenuItemEnumO(head, opname, propname, item[i].value);
+ }
+ }
+ WM_operator_properties_free(opptr);
+ MEM_freeN(opptr);
+ }
+}
+
+
+/* generic new menu level */
+void uiMenuLevel(uiMenuItem *head, const char *name, void (*newlevel)(uiMenuItem *))
+{
+ 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_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!
+
+ BLI_addtail(&head->items, item);
+}
+
+/* set the whole structure to work */
+void uiMenuEnd(bContext *C, uiMenuItem *head)
+{
+ wmWindow *window= CTX_wm_window(C);
+ uiMenuInfo info;
+ uiMenuBlockHandle *menu;
+
+ memset(&info, 0, sizeof(info));
+ info.mx= window->eventstate->x;
+ info.my= window->eventstate->y;
+ info.head= head;
+
+ menu= ui_menu_block_create(C, NULL, NULL, ui_block_func_MENU_ITEM, &info);
+ menu->popup= 1;
+
+ UI_add_popup_handlers(&window->handlers, menu);
+ WM_event_add_mousemove(C);
+
+ BLI_freelistN(&head->items);
+ MEM_freeN(head);
+}
+
+/* *********** internal code for menu/toolbox system */
+
+const char *ui_menu_enumpropname(PointerRNA *opptr, const char *propname, int retval)
+{
+ PropertyRNA *prop;
+
+ prop= RNA_struct_find_property(opptr, propname);
+
+ if(prop) {
+ const EnumPropertyItem *item;
+ int totitem, i;
+
+ RNA_property_enum_items(opptr, prop, &item, &totitem);
+
+ for (i=0; i<totitem; i++) {
+ if(item[i].value==retval)
+ return item[i].name;
+ }
+ }
+ return "";
+}
+
+/* make a menu level from uiMenuItems */
+static uiBlock *menu_item_makemenu(bContext *C, uiMenuBlockHandle *handle, void *arg)
+{
+ uiBlock *block;
+ uiMenuInfo info;
+ uiMenuItem *head;
+ void (*newlevel)(uiMenuItem *)= arg;
+
+ if(arg==NULL) return NULL;
+
+ head= MEM_callocN(sizeof(uiMenuItem), "sub level item");
+ head->opcontext= WM_OP_EXEC_REGION_WIN;
+
+ newlevel(head);
+
+ memset(&info, 0, sizeof(info));
+ info.head= head;
+
+ block= ui_block_func_MENU_ITEM(C, handle, &info);
+ block->direction= UI_RIGHT;
+
+ BLI_freelistN(&head->items);
+ MEM_freeN(head);
+
+ return block;
+}
+
+/* make a menu level from enum properties */
+static uiBlock *menu_item_enum_menu(bContext *C, uiMenuBlockHandle *handle, void *arg)
+{
+ uiBlock *block;
+ uiBut *but= arg; /* parent caller */
+ wmOperatorType *ot;
+ uiMenuInfo info;
+ uiMenuItem *head;
+
+ head= MEM_callocN(sizeof(uiMenuItem), "sub level item");
+ head->opcontext= WM_OP_EXEC_REGION_WIN;
+
+ ot= WM_operatortype_find(but->func_arg1);
+ if(ot) {
+ PointerRNA *opptr= MEM_callocN(sizeof(PointerRNA), "uiButOpPtr");
+ PropertyRNA *prop;
+
+ WM_operator_properties_create(opptr, but->func_arg1);
+ prop= RNA_struct_find_property(opptr, but->func_arg2);
+
+ if(prop) {
+ const EnumPropertyItem *item;
+ int totitem, i;
+
+ RNA_property_enum_items(opptr, prop, &item, &totitem);
+
+ for (i=0; i<totitem; i++) {
+ uiMenuItemEnumO(head, but->func_arg1, but->func_arg2, item[i].value);
+ }
+ }
+ WM_operator_properties_free(opptr);
+ MEM_freeN(opptr);
+ }
+
+ memset(&info, 0, sizeof(info));
+ info.head= head;
+
+ block= ui_block_func_MENU_ITEM(C, handle, &info);
+ block->direction= UI_RIGHT;
+
+ BLI_freelistN(&head->items);
+ MEM_freeN(head);
+
+ return block;
+}
+
+static uiBlock *ui_block_func_MENU_ITEM(bContext *C, uiMenuBlockHandle *handle, void *arg_info)
+{
+ uiBlock *block;
+ uiBut *but;
+ uiMenuInfo *info= arg_info;
+ uiMenuItem *head, *item;
+ static int counter= 0;
+ int width, height, xmax, ymax;
+ int startx, starty, endx, endy, x1, y1;
+ char str[16];
+
+ head= info->head;
+ height= 0;
+
+ /* block stuff first, need to know the font */
+ sprintf(str, "tb %d", counter++);
+ block= uiBeginBlock(C, handle->region, str, UI_EMBOSSP, UI_HELV);
+ uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_RET_1|UI_BLOCK_NUMSELECT);
+ uiBlockSetButmFunc(block, head->eventfunc, head->argv);
+ block->themecol= TH_MENU_ITEM;
+ block->direction= UI_DOWN;
+
+ /* size and location, title slightly bigger for bold */
+ if(head->name[0]) {
+ width= 2*strlen(head->name)+UI_GetStringWidth(uiBlockGetCurFont(block), head->name, ui_translate_buttons());
+ }
+ else width= UI_GetStringWidth(uiBlockGetCurFont(block), "Standardtext", ui_translate_buttons());
+
+ for(item= head->items.first; item; item= item->next) {
+ xmax= UI_GetStringWidth(uiBlockGetCurFont(block), item->name, ui_translate_buttons());
+ if(xmax>width) width= xmax;
+
+ if(0) height+= PUP_LABELH; // XXX sepr line
+ else height+= MENU_BUTTON_HEIGHT;
+ }
+
+ width+= 10;
+ if (width<50) width=50;
+
+ wm_window_get_size(CTX_wm_window(C), &xmax, &ymax);
+
+ /* boundbox */
+
+ startx= info->mx-(0.8*(width));
+ starty= info->my-height+MENU_BUTTON_HEIGHT/2;
+
+ if(startx<10) {
+ startx= 10;
+ }
+ if(starty<10) {
+ starty= 10;
+ }
+
+ endx= startx+width;
+ endy= starty+height;
+
+ if(endx>xmax) {
+ endx= xmax-10;
+ startx= endx-width;
+ }
+ if(endy>ymax-20) {
+ endy= ymax-20;
+ starty= endy-height;
+ }
+
+ /* here we go! */
+ if(head->name[0]) {
+ char titlestr[256];
+ uiSetCurFont(block, UI_HELVB);
+
+ 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, "");
+ }
+ else {
+ but= uiDefBut(block, LABEL, 0, head->name, startx, (short)(starty+height), width, MENU_BUTTON_HEIGHT, NULL, 0.0, 0.0, 0, 0, "");
+ but->flag= UI_TEXT_LEFT;
+ }
+ uiSetCurFont(block, UI_HELV);
+
+ //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(0) { // SEPR
+ uiDefBut(block, SEPR, B_NOP, "", x1, y1, width, PUP_LABELH, NULL, 0, 0.0, 0, 0, "");
+ y1 -= PUP_LABELH;
+ }
+ else if(item->type==MENU_ITEM_LEVEL) {
+ uiDefIconTextBlockBut(block, menu_item_makemenu, item->newlevel, 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_ENUM) {
+ but= uiDefIconTextBlockBut(block, menu_item_enum_menu, NULL, ICON_RIGHTARROW_THIN, item->name, x1, y1, width+16, MENU_BUTTON_HEIGHT-1, NULL);
+ /* XXX warning, abuse of func_arg! */
+ but->poin= (char *)but;
+ but->func_arg1= item->opname;
+ but->func_arg2= item->propname;
+
+ y1 -= MENU_BUTTON_HEIGHT;
+ }
+ else if(item->type==MENU_ITEM_OPNAME_ENUM) {
+ PointerRNA *opptr= MEM_callocN(sizeof(PointerRNA), "uiButOpPtr");
+ char bname[64];
+ const char *name;
+
+ WM_operator_properties_create(opptr, item->opname);
+ RNA_enum_set(opptr, item->propname, item->retval);
+ name= ui_menu_enumpropname(opptr, item->propname, item->retval);
+ BLI_strncpy(bname, name, 64);
+
+ but= uiDefIconTextBut(block, BUTM, item->retval, ICON_BLANK1, bname, x1, y1, width+16, MENU_BUTTON_HEIGHT-1, NULL, 0.0, 0.0, 0, 0, "");
+
+ but->opptr= opptr;
+ but->opname= item->opname;
+ but->opcontext= head->opcontext;
+
+ y1 -= MENU_BUTTON_HEIGHT;
+ }
+ else if(item->type==MENU_ITEM_OPNAME) {
+ uiDefIconTextButO(block, BUTM, item->opname, head->opcontext, ICON_BLANK1, NULL, x1, y1, width+16, MENU_BUTTON_HEIGHT-1, NULL);
+ y1 -= MENU_BUTTON_HEIGHT;
+ }
+ else {
+ 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;
+ }
+ }
+
+ uiBoundsBlock(block, 1);
+ uiEndBlock(C, block);
+
+ return block;
+}
+
+
diff --git a/source/blender/editors/mesh/mesh_ops.c b/source/blender/editors/mesh/mesh_ops.c
index 7d47e491db5..34e87a29d63 100644
--- a/source/blender/editors/mesh/mesh_ops.c
+++ b/source/blender/editors/mesh/mesh_ops.c
@@ -173,19 +173,8 @@ void ED_keymap_mesh(wmWindowManager *wm)
WM_keymap_add_item(keymap, "MESH_OT_extrude_mesh", EKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "MESH_OT_edit_faces", PKEY, KM_PRESS, KM_CTRL, 0);
-
-
/* add */
WM_keymap_add_item(keymap, "MESH_OT_add_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0);
- WM_keymap_add_item(keymap, "MESH_OT_add_primitive_plane", ZEROKEY, KM_PRESS, KM_CTRL, 0);
- WM_keymap_add_item(keymap, "MESH_OT_add_primitive_cube", ONEKEY, KM_PRESS, KM_CTRL, 0);
- WM_keymap_add_item(keymap, "MESH_OT_add_primitive_circle", TWOKEY, KM_PRESS, KM_CTRL, 0);
- WM_keymap_add_item(keymap, "MESH_OT_add_primitive_cylinder", THREEKEY, KM_PRESS, KM_CTRL, 0);
- WM_keymap_add_item(keymap, "MESH_OT_add_primitive_tube", FOURKEY, KM_PRESS, KM_CTRL, 0);
- WM_keymap_add_item(keymap, "MESH_OT_add_primitive_cone", FIVEKEY, KM_PRESS, KM_CTRL, 0);
- WM_keymap_add_item(keymap, "MESH_OT_add_primitive_grid", SIXKEY, KM_PRESS, KM_CTRL, 0);
- WM_keymap_add_item(keymap, "MESH_OT_add_primitive_uv_sphere", SEVENKEY, KM_PRESS, KM_CTRL, 0);
- WM_keymap_add_item(keymap, "MESH_OT_add_primitive_ico_sphere", EIGHTKEY, KM_PRESS, KM_CTRL, 0);
- WM_keymap_add_item(keymap, "MESH_OT_add_primitive_monkey", NINEKEY, KM_PRESS, KM_CTRL, 0);
+ WM_keymap_add_item(keymap, "OBJECT_OT_mesh_add", AKEY, KM_PRESS, KM_SHIFT, 0);
}
diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c
index 38add807580..dc94d61b940 100644
--- a/source/blender/editors/object/object_edit.c
+++ b/source/blender/editors/object/object_edit.c
@@ -258,6 +258,7 @@ void ED_object_base_init_from_view(bContext *C, Base *base)
}
}
}
+ where_is_object(scene, ob);
}
/* ******************* add object operator ****************** */
@@ -324,6 +325,174 @@ void OBJECT_OT_object_add(wmOperatorType *ot)
RNA_def_enum(ot->srna, "type", prop_object_types, 0, "Type", "");
}
+/* ***************** add primitives *************** */
+/* ****** work both in and outside editmode ****** */
+
+static EnumPropertyItem prop_mesh_types[] = {
+ {0, "PLANE", "Plane", ""},
+ {1, "CUBE", "Cube", ""},
+ {2, "CIRCLE", "Circle", ""},
+ {3, "UVSPHERE", "UVsphere", ""},
+ {4, "ICOSPHERE", "Icosphere", ""},
+ {5, "CYLINDER", "Cylinder", ""},
+ {6, "CONE", "Cone", ""},
+ {7, "GRID", "Grid", ""},
+ {8, "MONKEY", "Monkey", ""},
+ {0, NULL, NULL, NULL}
+};
+
+static int object_add_mesh_exec(bContext *C, wmOperator *op)
+{
+ Object *obedit= CTX_data_edit_object(C);
+ int newob= 0;
+
+ if(obedit==NULL) {
+ RNA_enum_set(op->ptr, "type", OB_MESH);
+ object_add_exec(C, op);
+ ED_object_enter_editmode(C, 0);
+ newob = 1;
+ }
+ switch(RNA_enum_get(op->ptr, "primtype")) {
+ case 0:
+ WM_operator_name_call(C, "MESH_OT_add_primitive_plane", WM_OP_INVOKE_REGION_WIN, NULL);
+ break;
+ case 1:
+ WM_operator_name_call(C, "MESH_OT_add_primitive_cube", WM_OP_INVOKE_REGION_WIN, NULL);
+ break;
+ case 2:
+ WM_operator_name_call(C, "MESH_OT_add_primitive_circle", WM_OP_INVOKE_REGION_WIN, NULL);
+ break;
+ case 3:
+ WM_operator_name_call(C, "MESH_OT_add_primitive_uv_sphere", WM_OP_INVOKE_REGION_WIN, NULL);
+ break;
+ case 4:
+ WM_operator_name_call(C, "MESH_OT_add_primitive_ico_sphere", WM_OP_INVOKE_REGION_WIN, NULL);
+ break;
+ case 5:
+ WM_operator_name_call(C, "MESH_OT_add_primitive_cylinder", WM_OP_INVOKE_REGION_WIN, NULL);
+ break;
+ case 6:
+ WM_operator_name_call(C, "MESH_OT_add_primitive_cone", WM_OP_INVOKE_REGION_WIN, NULL);
+ break;
+ case 7:
+ WM_operator_name_call(C, "MESH_OT_add_primitive_grid", WM_OP_INVOKE_REGION_WIN, NULL);
+ break;
+ case 8:
+ WM_operator_name_call(C, "MESH_OT_add_primitive_monkey", WM_OP_INVOKE_REGION_WIN, NULL);
+ break;
+ }
+ /* userdef */
+ if (newob && (U.flag & USER_ADD_EDITMODE)==0) {
+ ED_object_exit_editmode(C, EM_FREEDATA);
+ }
+
+ return OPERATOR_FINISHED;
+}
+
+static int object_add_mesh_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+ uiMenuItem *head= uiMenuBegin("Add Mesh");
+
+ uiMenuItemsEnumO(head, "OBJECT_OT_mesh_add", "primtype");
+ uiMenuEnd(C, head);
+
+ /* this operator is only for a menu, not used further */
+ return OPERATOR_CANCELLED;
+}
+
+void OBJECT_OT_mesh_add(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Add Mesh";
+ ot->idname= "OBJECT_OT_mesh_add";
+
+ /* api callbacks */
+ ot->invoke= object_add_mesh_invoke;
+ ot->exec= object_add_mesh_exec;
+
+ ot->poll= ED_operator_scene_editable;
+ ot->flag= OPTYPE_REGISTER;
+
+ RNA_def_enum(ot->srna, "type", prop_object_types, 0, "Type", "");
+ RNA_def_enum(ot->srna, "primtype", prop_mesh_types, 0, "Primitive", "");
+}
+
+static EnumPropertyItem prop_curve_types[] = {
+ {0, "BEZCUVE", "Bezier Curve", ""},
+ {1, "BEZCIRCLE", "Bezier Circle", ""},
+ {2, "NURBSCUVE", "Nurbs Curve", ""},
+ {3, "NURBSCIRCLE", "Nurbs Circle", ""},
+ {0, NULL, NULL, NULL}
+};
+
+static int object_add_curve_exec(bContext *C, wmOperator *op)
+{
+ Object *obedit= CTX_data_edit_object(C);
+
+ if(obedit==NULL) {
+ RNA_enum_set(op->ptr, "type", OB_MESH);
+ object_add_exec(C, op);
+ ED_object_enter_editmode(C, 0);
+ }
+ switch(RNA_enum_get(op->ptr, "primtype")) {
+
+
+ }
+ /* userdef */
+
+ return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_curve_add(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Add Curve";
+ ot->idname= "OBJECT_OT_curve_add";
+
+ /* api callbacks */
+ ot->exec= object_add_curve_exec;
+
+ ot->poll= ED_operator_scene_editable;
+ ot->flag= OPTYPE_REGISTER;
+
+ RNA_def_enum(ot->srna, "primtype", prop_curve_types, 0, "Type", "");
+}
+
+
+static int object_add_primitive_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+ uiMenuItem *head= uiMenuBegin("Add Object");
+
+ uiMenuLevelEnumO(head, "OBJECT_OT_mesh_add", "primtype");
+ uiMenuLevelEnumO(head, "OBJECT_OT_curve_add", "primtype");
+ uiMenuItemEnumO(head, "OBJECT_OT_object_add", "type", OB_SURF);
+ uiMenuItemEnumO(head, "OBJECT_OT_object_add", "type", OB_MBALL);
+ uiMenuItemEnumO(head, "OBJECT_OT_object_add", "type", OB_CAMERA);
+ uiMenuItemEnumO(head, "OBJECT_OT_object_add", "type", OB_LAMP);
+ uiMenuItemEnumO(head, "OBJECT_OT_object_add", "type", OB_EMPTY);
+ uiMenuItemEnumO(head, "OBJECT_OT_object_add", "type", OB_ARMATURE);
+ uiMenuItemEnumO(head, "OBJECT_OT_object_add", "type", OB_LATTICE);
+
+ uiMenuEnd(C, head);
+
+ /* this operator is only for a menu, not used further */
+ return OPERATOR_CANCELLED;
+}
+
+/* only used as menu */
+void OBJECT_OT_primitive_add(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Add Primitive";
+ ot->idname= "OBJECT_OT_primitive_add";
+
+ /* api callbacks */
+ ot->invoke= object_add_primitive_invoke;
+
+ ot->poll= ED_operator_scene_editable;
+ ot->flag= OPTYPE_REGISTER;
+}
+
/* ******************************* */
diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h
index 27455fd8a50..9abc896198b 100644
--- a/source/blender/editors/object/object_intern.h
+++ b/source/blender/editors/object/object_intern.h
@@ -66,6 +66,11 @@ void OBJECT_OT_make_dupli_real(struct wmOperatorType *ot);
void OBJECT_OT_object_add(struct wmOperatorType *ot);
void OBJECT_OT_add_duplicate(struct wmOperatorType *ot);
+void OBJECT_OT_mesh_add(struct wmOperatorType *ot);
+void OBJECT_OT_curve_add(struct wmOperatorType *ot);
+ /* only used as menu */
+void OBJECT_OT_primitive_add(struct wmOperatorType *ot);
+
/* editlattice.c */
void free_editLatt(Object *ob);
void make_editLatt(Object *obedit);
diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c
index 7ceb7b8f541..7001295bea0 100644
--- a/source/blender/editors/object/object_ops.c
+++ b/source/blender/editors/object/object_ops.c
@@ -84,12 +84,16 @@ void ED_operatortypes_object(void)
WM_operatortype_append(OBJECT_OT_clear_slowparent);
WM_operatortype_append(OBJECT_OT_set_center);
WM_operatortype_append(OBJECT_OT_make_dupli_real);
- WM_operatortype_append(OBJECT_OT_object_add);
WM_operatortype_append(OBJECT_OT_add_duplicate);
WM_operatortype_append(GROUP_OT_group_create);
WM_operatortype_append(GROUP_OT_group_remove);
WM_operatortype_append(GROUP_OT_objects_add_active);
WM_operatortype_append(GROUP_OT_objects_remove_active);
+
+ WM_operatortype_append(OBJECT_OT_mesh_add);
+ WM_operatortype_append(OBJECT_OT_curve_add);
+ WM_operatortype_append(OBJECT_OT_object_add);
+ WM_operatortype_append(OBJECT_OT_primitive_add);
}
void ED_keymap_object(wmWindowManager *wm)
@@ -123,7 +127,7 @@ void ED_keymap_object(wmWindowManager *wm)
WM_keymap_verify_item(keymap, "OBJECT_OT_clear_restrictview", HKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_verify_item(keymap, "OBJECT_OT_set_restrictview", HKEY, KM_PRESS, 0, 0);
- WM_keymap_verify_item(keymap, "OBJECT_OT_object_add", AKEY, KM_PRESS, KM_SHIFT, 0);
+ WM_keymap_verify_item(keymap, "OBJECT_OT_primitive_add", AKEY, KM_PRESS, KM_SHIFT, 0);
WM_keymap_verify_item(keymap, "OBJECT_OT_add_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0);
// XXX this should probably be in screen instead... here for testing purposes in the meantime... - Aligorith
diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c
index 60768d10e9d..0dff9c1b92f 100644
--- a/source/blender/editors/screen/screen_ops.c
+++ b/source/blender/editors/screen/screen_ops.c
@@ -55,6 +55,7 @@
#include "RNA_define.h"
#include "UI_interface.h"
+#include "UI_resources.h"
#include "screen_intern.h" /* own module include */
@@ -1028,7 +1029,7 @@ static int screen_full_area_exec(bContext *C, wmOperator *op)
void SCREEN_OT_screen_full_area(wmOperatorType *ot)
{
- ot->name = "Toggle Full Area in Screen";
+ ot->name = "Toggle Make Area Fullscreen";
ot->idname = "SCREEN_OT_screen_full_area";
ot->exec= screen_full_area_exec;
@@ -1548,10 +1549,43 @@ static int region_flip_exec(bContext *C, wmOperator *op)
ar->alignment= RGN_ALIGN_LEFT;
WM_event_add_notifier(C, NC_SCREEN|NA_EDITED, NULL);
+ printf("executed region flip\n");
return OPERATOR_FINISHED;
}
+static void testfunc(bContext *C, void *argv, int arg)
+{
+ printf("arg %d\n", arg);
+}
+
+static void newlevel1(uiMenuItem *head)
+{
+ uiMenuFunc(head, 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);
+}
+
+static int testing123(bContext *C, wmOperator *op, wmEvent *event)
+{
+ uiMenuItem *head= uiMenuBegin("Hello world");
+
+ uiMenuContext(head, WM_OP_EXEC_DEFAULT);
+ uiMenuItemO(head, "SCREEN_OT_region_flip", ICON_PROP_ON);
+ uiMenuItemO(head, "SCREEN_OT_screen_full_area", ICON_PROP_CON);
+ uiMenuItemO(head, "SCREEN_OT_region_foursplit", ICON_SMOOTHCURVE);
+ uiMenuLevel(head, "Submenu", newlevel1);
+ uiMenuItemO(head, "SCREEN_OT_area_rip", ICON_PROP_ON);
+
+ uiMenuEnd(C, head);
+
+ /* this operator is only for a menu, not used further */
+ return OPERATOR_CANCELLED;
+}
+
void SCREEN_OT_region_flip(wmOperatorType *ot)
{
/* identifiers */
@@ -1559,10 +1593,13 @@ void SCREEN_OT_region_flip(wmOperatorType *ot)
ot->idname= "SCREEN_OT_region_flip";
/* api callbacks */
- ot->invoke= WM_operator_confirm;
+ ot->invoke= testing123; // XXX WM_operator_confirm;
ot->exec= region_flip_exec;
ot->poll= ED_operator_areaactive;
+
+ RNA_def_int(ot->srna, "test", 0, INT_MIN, INT_MAX, "test", "", INT_MIN, INT_MAX);
+
}
/* ****************** anim player, typically with timer ***************** */