2.5
More toolbar functionality for workflow review. - Split the region in two parts, bottom has the Tool Properties, the top part shows 2 panels, one for python defined tools, other for a "tool shelf" which (later) will get saved in files. - Added a full context driven framework for this toolbar, showing the tools depending on 3D window 'mode'. Both python defined tools as the shelf respect this. So - for example - you will see different tools in editmode mesh, as in vertex paint mode, etc. - First template for the python tools will be committed after this commit; it has placeholder tools to just show/test functioning. NOTE: if you had saved a layout that shows tools region, open/close it once to get the new region created for properties. TODO: - Moving paint properties to tool settings - Test a layout with horizontal toolbar (without properties) - Bring back floating panels, and put tool-properties here. (as option)
This commit is contained in:
@@ -91,6 +91,9 @@ typedef struct SpaceType {
|
||||
/* region type definitions */
|
||||
ListBase regiontypes;
|
||||
|
||||
/* tool shelf definitions */
|
||||
ListBase toolshelf;
|
||||
|
||||
/* read and write... */
|
||||
|
||||
/* default keymaps to add */
|
||||
@@ -139,7 +142,7 @@ typedef struct ARegionType {
|
||||
|
||||
/* menu type definitions */
|
||||
ListBase menutypes;
|
||||
|
||||
|
||||
/* hardcoded constraints, smaller than these values region is not visible */
|
||||
int minsizex, minsizey;
|
||||
/* default keymaps to add */
|
||||
|
||||
@@ -78,6 +78,8 @@ static void spacetype_free(SpaceType *st)
|
||||
}
|
||||
|
||||
BLI_freelistN(&st->regiontypes);
|
||||
BLI_freelistN(&st->toolshelf);
|
||||
|
||||
}
|
||||
|
||||
void BKE_spacetypes_free(void)
|
||||
|
||||
@@ -293,13 +293,15 @@ static void round_box__edges(uiWidgetBase *wt, int roundboxalign, rcti *rect, fl
|
||||
float maxyi= maxy - 1.0f;
|
||||
float facxi= 1.0f/(maxxi-minxi); /* for uv */
|
||||
float facyi= 1.0f/(maxyi-minyi);
|
||||
int a, tot= 0;
|
||||
int a, tot= 0, minsize;
|
||||
|
||||
if(2.0f*rad > rect->ymax-rect->ymin)
|
||||
rad= 0.5f*(rect->ymax-rect->ymin);
|
||||
minsize= MIN2(rect->xmax-rect->xmin, rect->ymax-rect->ymin);
|
||||
|
||||
if(2.0f*rad > minsize)
|
||||
rad= 0.5f*minsize;
|
||||
|
||||
if(2.0f*(radi+1.0f) > rect->ymax-rect->ymin)
|
||||
radi= 0.5f*(rect->ymax-rect->ymin) - 1.0f;
|
||||
if(2.0f*(radi+1.0f) > minsize)
|
||||
radi= 0.5f*minsize - 1.0f;
|
||||
|
||||
/* mult */
|
||||
for(a=0; a<9; a++) {
|
||||
|
||||
@@ -261,6 +261,7 @@ static void region_scissor_winrct(ARegion *ar, rcti *winrct)
|
||||
|
||||
if(BLI_isect_rcti(winrct, &ar->winrct, NULL)) {
|
||||
if(ar->flag & RGN_FLAG_HIDDEN);
|
||||
else if(ar->alignment & RGN_SPLIT_PREV);
|
||||
else if(ar->alignment==RGN_OVERLAP_LEFT) {
|
||||
winrct->xmin= ar->winrct.xmax + 1;
|
||||
}
|
||||
|
||||
@@ -97,29 +97,45 @@ ARegion *view3d_has_buttons_region(ScrArea *sa)
|
||||
|
||||
ARegion *view3d_has_tools_region(ScrArea *sa)
|
||||
{
|
||||
ARegion *ar, *arnew;
|
||||
ARegion *ar, *artool=NULL, *arprops=NULL, *arhead;
|
||||
|
||||
for(ar= sa->regionbase.first; ar; ar= ar->next)
|
||||
for(ar= sa->regionbase.first; ar; ar= ar->next) {
|
||||
if(ar->regiontype==RGN_TYPE_TOOLS)
|
||||
return ar;
|
||||
artool= ar;
|
||||
if(ar->regiontype==RGN_TYPE_TOOL_PROPS)
|
||||
arprops= ar;
|
||||
}
|
||||
|
||||
/* add subdiv level; after header */
|
||||
for(ar= sa->regionbase.first; ar; ar= ar->next)
|
||||
if(ar->regiontype==RGN_TYPE_HEADER)
|
||||
break;
|
||||
/* tool region hide/unhide also hides props */
|
||||
if(arprops && artool) return artool;
|
||||
|
||||
/* is error! */
|
||||
if(ar==NULL) return NULL;
|
||||
if(artool==NULL) {
|
||||
/* add subdiv level; after header */
|
||||
for(arhead= sa->regionbase.first; arhead; arhead= arhead->next)
|
||||
if(arhead->regiontype==RGN_TYPE_HEADER)
|
||||
break;
|
||||
|
||||
/* is error! */
|
||||
if(arhead==NULL) return NULL;
|
||||
|
||||
artool= MEM_callocN(sizeof(ARegion), "tools for view3d");
|
||||
|
||||
BLI_insertlinkafter(&sa->regionbase, arhead, artool);
|
||||
artool->regiontype= RGN_TYPE_TOOLS;
|
||||
artool->alignment= RGN_OVERLAP_LEFT;
|
||||
artool->flag = RGN_FLAG_HIDDEN;
|
||||
}
|
||||
|
||||
if(arprops==NULL) {
|
||||
/* add extra subdivided region for tool properties */
|
||||
arprops= MEM_callocN(sizeof(ARegion), "tool props for view3d");
|
||||
|
||||
BLI_insertlinkafter(&sa->regionbase, artool, arprops);
|
||||
arprops->regiontype= RGN_TYPE_TOOL_PROPS;
|
||||
arprops->alignment= RGN_ALIGN_BOTTOM|RGN_SPLIT_PREV;
|
||||
}
|
||||
|
||||
arnew= MEM_callocN(sizeof(ARegion), "tools for view3d");
|
||||
|
||||
BLI_insertlinkafter(&sa->regionbase, ar, arnew);
|
||||
arnew->regiontype= RGN_TYPE_TOOLS;
|
||||
arnew->alignment= RGN_OVERLAP_LEFT;
|
||||
|
||||
arnew->flag = RGN_FLAG_HIDDEN;
|
||||
|
||||
return arnew;
|
||||
return artool;
|
||||
}
|
||||
|
||||
/* ****************************************************** */
|
||||
@@ -559,9 +575,11 @@ static void view3d_tools_area_init(wmWindowManager *wm, ARegion *ar)
|
||||
WM_event_add_keymap_handler(&ar->handlers, keymap);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void view3d_tools_area_draw(const bContext *C, ARegion *ar)
|
||||
{
|
||||
ED_region_panels(C, ar, 1, NULL);
|
||||
ED_region_panels(C, ar, 1, view3d_context_string(C));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -860,6 +878,20 @@ void ED_spacetype_view3d(void)
|
||||
BLI_addhead(&st->regiontypes, art);
|
||||
|
||||
view3d_toolbar_register(art);
|
||||
|
||||
/* regions: tool properties */
|
||||
art= MEM_callocN(sizeof(ARegionType), "spacetype view3d region");
|
||||
art->regionid = RGN_TYPE_TOOL_PROPS;
|
||||
art->minsizex= 0;
|
||||
art->minsizey= 120;
|
||||
art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_FRAMES;
|
||||
art->listener= view3d_buttons_area_listener;
|
||||
art->init= view3d_tools_area_init;
|
||||
art->draw= view3d_tools_area_draw;
|
||||
BLI_addhead(&st->regiontypes, art);
|
||||
|
||||
view3d_tool_props_register(art);
|
||||
|
||||
|
||||
/* regions: header */
|
||||
art= MEM_callocN(sizeof(ARegionType), "spacetype view3d region");
|
||||
|
||||
@@ -136,9 +136,11 @@ void setviewmatrixview3d(Scene *scene, View3D *v3d, RegionView3D *rv3d);
|
||||
void VIEW3D_OT_properties(struct wmOperatorType *ot);
|
||||
void view3d_buttons_register(struct ARegionType *art);
|
||||
|
||||
/* view3d_buttons.c */
|
||||
/* view3d_toolbar.c */
|
||||
void VIEW3D_OT_toolbar(struct wmOperatorType *ot);
|
||||
void view3d_toolbar_register(struct ARegionType *art);
|
||||
void view3d_tool_props_register(struct ARegionType *art);
|
||||
char *view3d_context_string(const struct bContext *C);
|
||||
|
||||
/* view3d_snap.c */
|
||||
int minmax_verts(Object *obedit, float *min, float *max);
|
||||
|
||||
@@ -150,9 +150,46 @@ static void view3d_panel_operator_redo(const bContext *C, Panel *pa)
|
||||
|
||||
/* ******************* */
|
||||
|
||||
char *view3d_context_string(const bContext *C)
|
||||
{
|
||||
Object *obedit= CTX_data_edit_object(C);
|
||||
|
||||
if(obedit) {
|
||||
switch(obedit->type) {
|
||||
case OB_MESH:
|
||||
return "editmode_mesh";
|
||||
case OB_CURVE:
|
||||
return "editmode_curve";
|
||||
case OB_SURF:
|
||||
return "editmode_surface";
|
||||
case OB_FONT:
|
||||
return "editmode_text";
|
||||
case OB_ARMATURE:
|
||||
return "editmode_armature";
|
||||
case OB_MBALL:
|
||||
return "editmode_mball";
|
||||
case OB_LATTICE:
|
||||
return "editmode_lattice";
|
||||
}
|
||||
}
|
||||
else {
|
||||
Object *ob = CTX_data_active_object(C);
|
||||
|
||||
if(ob && (ob->flag & OB_POSEMODE)) return "posemode";
|
||||
else if (G.f & G_SCULPTMODE) return "sculptmode";
|
||||
else if (G.f & G_WEIGHTPAINT) return "weightpaint";
|
||||
else if (G.f & G_VERTEXPAINT) return "vertexpaint";
|
||||
else if (G.f & G_TEXTUREPAINT) return "texturepaint";
|
||||
else if(G.f & G_PARTICLEEDIT) return "particlemode";
|
||||
}
|
||||
|
||||
return "objectmode";
|
||||
}
|
||||
|
||||
typedef struct CustomTool {
|
||||
struct CustomTool *next, *prev;
|
||||
char opname[OP_MAX_TYPENAME];
|
||||
char context[OP_MAX_TYPENAME];
|
||||
} CustomTool;
|
||||
|
||||
static void operator_call_cb(struct bContext *C, void *arg_listbase, void *arg2)
|
||||
@@ -164,6 +201,7 @@ static void operator_call_cb(struct bContext *C, void *arg_listbase, void *arg2)
|
||||
|
||||
BLI_addtail(arg_listbase, ct);
|
||||
BLI_strncpy(ct->opname, ot->idname, OP_MAX_TYPENAME);
|
||||
BLI_strncpy(ct->context, view3d_context_string(C), OP_MAX_TYPENAME);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -221,43 +259,28 @@ static uiBlock *tool_search_menu(bContext *C, ARegion *ar, void *arg_listbase)
|
||||
}
|
||||
|
||||
|
||||
static void view3d_panel_tools(const bContext *C, Panel *pa)
|
||||
static void view3d_panel_tool_shelf(const bContext *C, Panel *pa)
|
||||
{
|
||||
static ListBase tools= {NULL, NULL};
|
||||
Object *obedit= CTX_data_edit_object(C);
|
||||
// Object *obact = CTX_data_active_object(C);
|
||||
SpaceLink *sl= CTX_wm_space_data(C);
|
||||
SpaceType *st= NULL;
|
||||
uiLayout *col;
|
||||
const char *context= view3d_context_string(C);
|
||||
|
||||
if(obedit) {
|
||||
if(obedit->type==OB_MESH) {
|
||||
|
||||
col= uiLayoutColumn(pa->layout, 1);
|
||||
uiItemFullO(col, NULL, 0, "MESH_OT_spin", NULL, WM_OP_INVOKE_REGION_WIN);
|
||||
uiItemFullO(col, NULL, 0, "MESH_OT_screw", NULL, WM_OP_INVOKE_REGION_WIN);
|
||||
|
||||
if(tools.first) {
|
||||
CustomTool *ct;
|
||||
|
||||
for(ct= tools.first; ct; ct= ct->next) {
|
||||
col= uiLayoutColumn(pa->layout, 1);
|
||||
uiItemFullO(col, NULL, 0, ct->opname, NULL, WM_OP_INVOKE_REGION_WIN);
|
||||
}
|
||||
if(sl)
|
||||
st= BKE_spacetype_from_id(sl->spacetype);
|
||||
|
||||
if(st && st->toolshelf.first) {
|
||||
CustomTool *ct;
|
||||
|
||||
for(ct= st->toolshelf.first; ct; ct= ct->next) {
|
||||
if(0==strncmp(context, ct->context, OP_MAX_TYPENAME)) {
|
||||
col= uiLayoutColumn(pa->layout, 1);
|
||||
uiItemFullO(col, NULL, 0, ct->opname, NULL, WM_OP_INVOKE_REGION_WIN);
|
||||
}
|
||||
col= uiLayoutColumn(pa->layout, 1);
|
||||
uiDefBlockBut(uiLayoutGetBlock(pa->layout), tool_search_menu, &tools, "Add Operator", 0, 0, UI_UNIT_X, UI_UNIT_Y, "Add tool");
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
col= uiLayoutColumn(pa->layout, 1);
|
||||
uiItemFullO(col, NULL, 0, "OBJECT_OT_delete", NULL, WM_OP_INVOKE_REGION_WIN);
|
||||
uiItemFullO(col, NULL, 0, "OBJECT_OT_primitive_add", NULL, WM_OP_INVOKE_REGION_WIN);
|
||||
|
||||
col= uiLayoutColumn(pa->layout, 1);
|
||||
uiItemFullO(col, NULL, 0, "OBJECT_OT_parent_set", NULL, WM_OP_INVOKE_REGION_WIN);
|
||||
uiItemFullO(col, NULL, 0, "OBJECT_OT_parent_clear", NULL, WM_OP_INVOKE_REGION_WIN);
|
||||
|
||||
}
|
||||
col= uiLayoutColumn(pa->layout, 1);
|
||||
uiDefBlockBut(uiLayoutGetBlock(pa->layout), tool_search_menu, &st->toolshelf, "Add Tool", 0, 0, UI_UNIT_X, UI_UNIT_Y, "Add Tool in shelf, gets saved in files");
|
||||
}
|
||||
|
||||
|
||||
@@ -266,10 +289,15 @@ void view3d_toolbar_register(ARegionType *art)
|
||||
PanelType *pt;
|
||||
|
||||
pt= MEM_callocN(sizeof(PanelType), "spacetype view3d panel tools");
|
||||
strcpy(pt->idname, "VIEW3D_PT_tools");
|
||||
strcpy(pt->label, "Tools");
|
||||
pt->draw= view3d_panel_tools;
|
||||
strcpy(pt->idname, "VIEW3D_PT_tool_shelf");
|
||||
strcpy(pt->label, "Tool Shelf");
|
||||
pt->draw= view3d_panel_tool_shelf;
|
||||
BLI_addtail(&art->paneltypes, pt);
|
||||
}
|
||||
|
||||
void view3d_tool_props_register(ARegionType *art)
|
||||
{
|
||||
PanelType *pt;
|
||||
|
||||
pt= MEM_callocN(sizeof(PanelType), "spacetype view3d panel last operator");
|
||||
strcpy(pt->idname, "VIEW3D_PT_last_operator");
|
||||
@@ -278,6 +306,8 @@ void view3d_toolbar_register(ARegionType *art)
|
||||
BLI_addtail(&art->paneltypes, pt);
|
||||
}
|
||||
|
||||
/* ********** operator to open/close toolbar region */
|
||||
|
||||
static int view3d_toolbar(bContext *C, wmOperator *op)
|
||||
{
|
||||
ScrArea *sa= CTX_wm_area(C);
|
||||
|
||||
@@ -226,6 +226,7 @@ typedef struct ARegion {
|
||||
#define RGN_TYPE_TEMPORARY 3
|
||||
#define RGN_TYPE_UI 4
|
||||
#define RGN_TYPE_TOOLS 5
|
||||
#define RGN_TYPE_TOOL_PROPS 6
|
||||
|
||||
/* region alignment */
|
||||
#define RGN_ALIGN_NONE 0
|
||||
|
||||
@@ -36,6 +36,7 @@ EnumPropertyItem region_type_items[] = {
|
||||
{RGN_TYPE_WINDOW, "WINDOW", 0, "Window", ""},
|
||||
{RGN_TYPE_HEADER, "HEADER", 0, "Header", ""},
|
||||
{RGN_TYPE_CHANNELS, "CHANNELS", 0, "Channels", ""},
|
||||
{RGN_TYPE_TOOLS, "TOOLS", 0, "Tools", ""},
|
||||
{RGN_TYPE_TEMPORARY, "TEMPORARY", 0, "Temporary", ""},
|
||||
{RGN_TYPE_UI, "UI", 0, "UI", ""},
|
||||
{0, NULL, 0, NULL, NULL}};
|
||||
|
||||
Reference in New Issue
Block a user