diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-05-19 21:13:33 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-05-19 21:13:33 +0400 |
commit | 40ae17d2f6e2d5dbbe89321491572035c304872c (patch) | |
tree | 7f39fe42977a45878352e34d7bfdc1820ed980ff /source/blender/editors/interface | |
parent | 861398542f8ba71dd4783886adda21544d939763 (diff) |
UI
* Fix buttons jumping around when resizing and zoom. Part of this was
adding a tiny a 0.001f offset in UI_view2d_view_ortho, otherwise the
rounding is unpredictable (used to be 0.375f, but that was disabled).
* Fix various issues with zooming, panning panels. V2D_LOCKOFS_X/Y is
now taken into account in more places in the view2d code, to avoid
zooming into the center or panning out of the view.
* Remove "Free" align mode in buttons window (it's not really useful).
* View3D/Graph/Image editors now use the same PanelType system as the
buttons window, means some deprecated panel code could be removed.
* Some small visual tweaks for panels.
* View 2D Reset operator (Home key), to reset zoom and panning for panels.
* Added argument to set number buttons as sliders (slider=True for itemR).
* Ignore labels for button alignment (doesn't look right).
* Fix some use of context.main in py scripts, should get data from active
object instead.
* Fix autotexspace -> auto_texspace in py script.
Diffstat (limited to 'source/blender/editors/interface')
-rw-r--r-- | source/blender/editors/interface/interface.c | 9 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_api.c | 1 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 5 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_intern.h | 4 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_layout.c | 282 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_panel.c | 349 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_templates.c | 14 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_utils.c | 30 | ||||
-rw-r--r-- | source/blender/editors/interface/view2d.c | 79 | ||||
-rw-r--r-- | source/blender/editors/interface/view2d_ops.c | 126 |
10 files changed, 358 insertions, 541 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 57f45059865..e937ab0c50a 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -559,7 +559,7 @@ void uiEndBlock(const bContext *C, uiBlock *block) } /* handle pending stuff */ - if(block->layout) uiBlockLayoutResolve(C, block, NULL, NULL); + if(block->layouts.first) uiBlockLayoutResolve(C, block, NULL, NULL); ui_block_do_align(block); if(block->flag & UI_BLOCK_LOOP) ui_menu_block_set_keymaps(C, block); @@ -1984,6 +1984,11 @@ void uiBlockEndAlign(uiBlock *block) block->flag &= ~UI_BUT_ALIGN; // all 4 flags } +int ui_but_can_align(uiBut *but) +{ + return !ELEM(but->type, LABEL, ROUNDBOX); +} + static void ui_block_do_align_but(uiBlock *block, uiBut *first, int nr) { uiBut *prev, *but=NULL, *next; @@ -2176,7 +2181,7 @@ static uiBut *ui_def_but(uiBlock *block, int type, int retval, char *str, short but->aspect= 1.0f; //XXX block->aspect; but->block= block; // pointer back, used for frontbuffer status, and picker - if(block->flag & UI_BUT_ALIGN) + if((block->flag & UI_BUT_ALIGN) && ui_but_can_align(but)) but->alignnr= block->alignnr; but->func= block->func; diff --git a/source/blender/editors/interface/interface_api.c b/source/blender/editors/interface/interface_api.c index 873406de7aa..b593aef2208 100644 --- a/source/blender/editors/interface/interface_api.c +++ b/source/blender/editors/interface/interface_api.c @@ -89,6 +89,7 @@ void RNA_api_ui_layout(StructRNA *srna) parm= RNA_def_string(func, "property", "", 0, "", "Identifier of property in data."); RNA_def_property_flag(parm, PROP_REQUIRED); RNA_def_boolean(func, "expand", 0, "", "Expand button to show more detail."); + RNA_def_boolean(func, "slider", 0, "", "Use slider for numeric values."); func= RNA_def_function(srna, "items_enumR", "uiItemsEnumR"); parm= RNA_def_pointer(func, "data", "AnyType", "", "Data from which to take property."); diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index c38f147a480..ed126ed870d 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -2767,6 +2767,11 @@ static uiBut *ui_but_find_activated(ARegion *ar) return NULL; } +int ui_button_is_active(ARegion *ar) +{ + return (ui_but_find_activated(ar) != NULL); +} + static void ui_blocks_set_tooltips(ARegion *ar, int enable) { uiBlock *block; diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index b96726a5ead..13c9d09aff1 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -222,7 +222,7 @@ struct uiBlock { Panel *panel; uiBlock *oldblock; - struct uiLayout *layout; + ListBase layouts; struct uiLayout *curlayout; char name[UI_MAX_NAME_STR]; @@ -378,6 +378,7 @@ void ui_draw_but_CURVE(ARegion *ar, uiBut *but, struct uiWidgetColors *wcol, rct /* interface_handlers.c */ extern void ui_button_active_cancel(const struct bContext *C, uiBut *but); +extern int ui_button_is_active(struct ARegion *ar); /* interface_widgets.c */ void ui_draw_anti_tria(float x1, float y1, float x2, float y2, float x3, float y3); @@ -398,6 +399,7 @@ void ui_resources_free(void); /* interface_layout.c */ void ui_layout_add_but(struct uiLayout *layout, uiBut *but); +int ui_but_can_align(uiBut *but); /* interface_anim.c */ void ui_but_anim_flag(uiBut *but, float cfra); diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index ab2bb57a25f..c1877ac8861 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -70,9 +70,11 @@ #define EM_SEPR_X 6 #define EM_SEPR_Y 6 -/* uiLayoutCommon */ +/* uiLayoutRoot */ + +typedef struct uiLayoutRoot { + struct uiLayoutRoot *next, *prev; -typedef struct uiLayoutCommon { int type; int opcontext; @@ -83,7 +85,8 @@ typedef struct uiLayoutCommon { uiStyle *style; uiBlock *block; -} uiLayoutCommon; + uiLayout *layout; +} uiLayoutRoot; /* Item */ @@ -122,7 +125,7 @@ typedef struct uiButtonItem { struct uiLayout { uiItem item; - uiLayoutCommon *common; + uiLayoutRoot *root; ListBase items; int x, y, w, h; @@ -198,7 +201,7 @@ static int ui_item_fit(int item, int pos, int all, int available, int spacing, i static int ui_layout_vary_direction(uiLayout *layout) { - return (layout->common->type == UI_LAYOUT_HEADER)? UI_ITEM_VARY_X: UI_ITEM_VARY_Y; + return (layout->root->type == UI_LAYOUT_HEADER)? UI_ITEM_VARY_X: UI_ITEM_VARY_Y; } /* estimated size of text + icon */ @@ -253,6 +256,8 @@ static void ui_item_position(uiItem *item, int x, int y, int w, int h) bitem->but->y1= y; bitem->but->x2= x+w; bitem->but->y2= y+h; + + ui_check_but(bitem->but); /* for strlen */ } else { uiLayout *litem= (uiLayout*)item; @@ -296,9 +301,10 @@ static uiLayout *ui_item_local_sublayout(uiLayout *test, uiLayout *layout, int a } /* create buttons for an item with an RNA array */ -static void ui_item_array(uiLayout *layout, uiBlock *block, char *name, int icon, PointerRNA *ptr, PropertyRNA *prop, int len, int x, int y, int w, int h, int expand) +static void ui_item_array(uiLayout *layout, uiBlock *block, char *name, int icon, PointerRNA *ptr, PropertyRNA *prop, int len, int x, int y, int w, int h, int expand, int slider) { - uiStyle *style= layout->common->style; + uiStyle *style= layout->root->style; + uiBut *but; PropertyType type; PropertySubType subtype; uiLayout *sub; @@ -308,7 +314,7 @@ static void ui_item_array(uiLayout *layout, uiBlock *block, char *name, int icon type= RNA_property_type(prop); subtype= RNA_property_subtype(prop); - sub= ui_item_local_sublayout(layout, layout, 0); + sub= ui_item_local_sublayout(layout, layout, 1); uiBlockSetCurLayout(block, sub); /* create label */ @@ -358,12 +364,12 @@ static void ui_item_array(uiLayout *layout, uiBlock *block, char *name, int icon col= a%len; row= a/len; - uiDefAutoButR(block, ptr, prop, a, "", 0, x + w*col, y+(row-a-1)*UI_UNIT_Y, w, UI_UNIT_Y); + but= uiDefAutoButR(block, ptr, prop, a, "", 0, x + w*col, y+(row-a-1)*UI_UNIT_Y, w, UI_UNIT_Y); + if(slider && but->type==NUM) + but->type= NUMSLI; } } else if(len <= 4 && ELEM3(subtype, PROP_ROTATION, PROP_VECTOR, PROP_COLOR)) { - uiBlockSetCurLayout(block, ui_item_local_sublayout(layout, sub, 1)); - if(subtype == PROP_COLOR) uiDefAutoButR(block, ptr, prop, -1, "", 0, 0, 0, w, UI_UNIT_Y); @@ -390,18 +396,23 @@ static void ui_item_array(uiLayout *layout, uiBlock *block, char *name, int icon str[2]= '\0'; } - uiDefAutoButR(block, ptr, prop, a, str, 0, 0, 0, w, UI_UNIT_Y); + but= uiDefAutoButR(block, ptr, prop, a, str, 0, 0, 0, w, UI_UNIT_Y); + if(slider && but->type==NUM) + but->type= NUMSLI; } } - else if(subtype == PROP_COLOR && len == 4) - uiDefAutoButR(block, ptr, prop, 3, "A:", 0, 0, 0, w, UI_UNIT_Y); + else if(subtype == PROP_COLOR && len == 4) { + but= uiDefAutoButR(block, ptr, prop, 3, "A:", 0, 0, 0, w, UI_UNIT_Y); + if(slider && but->type==NUM) + but->type= NUMSLI; + } } else { - /* default array layout */ - uiBlockSetCurLayout(block, ui_item_local_sublayout(layout, sub, 1)); - - for(a=0; a<len; a++) - uiDefAutoButR(block, ptr, prop, a, "", 0, 0, 0, w, UI_UNIT_Y); + for(a=0; a<len; a++) { + but= uiDefAutoButR(block, ptr, prop, a, "", 0, 0, 0, w, UI_UNIT_Y); + if(slider && but->type==NUM) + but->type= NUMSLI; + } } uiBlockSetCurLayout(block, layout); @@ -456,7 +467,7 @@ static void ui_item_with_label(uiLayout *layout, uiBlock *block, char *name, int /* disabled item */ static void ui_item_disabled(uiLayout *layout, char *name) { - uiBlock *block= layout->common->block; + uiBlock *block= layout->root->block; uiBut *but; int w; @@ -476,7 +487,7 @@ static void ui_item_disabled(uiLayout *layout, char *name) /* operator items */ void uiItemFullO(uiLayout *layout, char *name, int icon, char *idname, IDProperty *properties, int context) { - uiBlock *block= layout->common->block; + uiBlock *block= layout->root->block; wmOperatorType *ot= WM_operatortype_find(idname); uiBut *but; int w; @@ -488,7 +499,7 @@ void uiItemFullO(uiLayout *layout, char *name, int icon, char *idname, IDPropert if(!name) name= ot->name; - if(layout->common->type == UI_LAYOUT_MENU && !icon) + if(layout->root->type == UI_LAYOUT_MENU && !icon) icon= ICON_BLANK1; /* create button */ @@ -547,7 +558,7 @@ void uiItemEnumO(uiLayout *layout, char *name, int icon, char *opname, char *pro if(!name) name= ui_menu_enumpropname(opname, propname, value); - uiItemFullO(layout, name, icon, opname, ptr.data, layout->common->opcontext); + uiItemFullO(layout, name, icon, opname, ptr.data, layout->root->opcontext); } void uiItemsEnumO(uiLayout *layout, char *opname, char *propname) @@ -582,7 +593,7 @@ void uiItemBooleanO(uiLayout *layout, char *name, int icon, char *opname, char * WM_operator_properties_create(&ptr, opname); RNA_boolean_set(&ptr, propname, value); - uiItemFullO(layout, name, icon, opname, ptr.data, layout->common->opcontext); + uiItemFullO(layout, name, icon, opname, ptr.data, layout->root->opcontext); } void uiItemIntO(uiLayout *layout, char *name, int icon, char *opname, char *propname, int value) @@ -592,7 +603,7 @@ void uiItemIntO(uiLayout *layout, char *name, int icon, char *opname, char *prop WM_operator_properties_create(&ptr, opname); RNA_int_set(&ptr, propname, value); - uiItemFullO(layout, name, icon, opname, ptr.data, layout->common->opcontext); + uiItemFullO(layout, name, icon, opname, ptr.data, layout->root->opcontext); } void uiItemFloatO(uiLayout *layout, char *name, int icon, char *opname, char *propname, float value) @@ -602,7 +613,7 @@ void uiItemFloatO(uiLayout *layout, char *name, int icon, char *opname, char *pr WM_operator_properties_create(&ptr, opname); RNA_float_set(&ptr, propname, value); - uiItemFullO(layout, name, icon, opname, ptr.data, layout->common->opcontext); + uiItemFullO(layout, name, icon, opname, ptr.data, layout->root->opcontext); } void uiItemStringO(uiLayout *layout, char *name, int icon, char *opname, char *propname, char *value) @@ -612,12 +623,12 @@ void uiItemStringO(uiLayout *layout, char *name, int icon, char *opname, char *p WM_operator_properties_create(&ptr, opname); RNA_string_set(&ptr, propname, value); - uiItemFullO(layout, name, icon, opname, ptr.data, layout->common->opcontext); + uiItemFullO(layout, name, icon, opname, ptr.data, layout->root->opcontext); } void uiItemO(uiLayout *layout, char *name, int icon, char *opname) { - uiItemFullO(layout, name, icon, opname, NULL, layout->common->opcontext); + uiItemFullO(layout, name, icon, opname, NULL, layout->root->opcontext); } /* RNA property items */ @@ -660,9 +671,10 @@ static void ui_item_rna_size(uiLayout *layout, char *name, int icon, PropertyRNA *r_h= h; } -void uiItemFullR(uiLayout *layout, char *name, int icon, PointerRNA *ptr, PropertyRNA *prop, int index, int value, int expand) +void uiItemFullR(uiLayout *layout, char *name, int icon, PointerRNA *ptr, PropertyRNA *prop, int index, int value, int expand, int slider) { - uiBlock *block= layout->common->block; + uiBlock *block= layout->root->block; + uiBut *but; PropertyType type; char namestr[UI_MAX_NAME_STR]; int len, w, h; @@ -685,7 +697,7 @@ void uiItemFullR(uiLayout *layout, char *name, int icon, PointerRNA *ptr, Proper if(type == PROP_BOOLEAN && len) name= ui_item_name_add_colon(name, namestr); - if(layout->common->type == UI_LAYOUT_MENU) { + if(layout->root->type == UI_LAYOUT_MENU) { if(type == PROP_BOOLEAN) icon= (RNA_property_boolean_get(ptr, prop))? ICON_CHECKBOX_HLT: ICON_CHECKBOX_DEHLT; else if(type == PROP_ENUM && index == RNA_ENUM_VALUE) @@ -697,7 +709,7 @@ void uiItemFullR(uiLayout *layout, char *name, int icon, PointerRNA *ptr, Proper /* array property */ if(index == RNA_NO_INDEX && len > 0) - ui_item_array(layout, block, name, icon, ptr, prop, len, 0, 0, w, h, expand); + ui_item_array(layout, block, name, icon, ptr, prop, len, 0, 0, w, h, expand, slider); /* enum item */ else if(type == PROP_ENUM && index == RNA_ENUM_VALUE) { char *identifier= (char*)RNA_property_identifier(prop); @@ -716,11 +728,15 @@ void uiItemFullR(uiLayout *layout, char *name, int icon, PointerRNA *ptr, Proper else if(type == PROP_ENUM || type == PROP_STRING || type == PROP_POINTER) ui_item_with_label(layout, block, name, icon, ptr, prop, index, 0, 0, w, h); /* single button */ - else - uiDefAutoButR(block, ptr, prop, index, (char*)name, icon, 0, 0, w, h); + else { + but= uiDefAutoButR(block, ptr, prop, index, (char*)name, icon, 0, 0, w, h); + + if(slider && but->type==NUM) + but->type= NUMSLI; + } } -void uiItemR(uiLayout *layout, char *name, int icon, PointerRNA *ptr, char *propname, int expand) +void uiItemR(uiLayout *layout, char *name, int icon, PointerRNA *ptr, char *propname, int expand, int slider) { PropertyRNA *prop; @@ -735,7 +751,7 @@ void uiItemR(uiLayout *layout, char *name, int icon, PointerRNA *ptr, char *prop return; } - uiItemFullR(layout, name, icon, ptr, prop, RNA_NO_INDEX, 0, expand); + uiItemFullR(layout, name, icon, ptr, prop, RNA_NO_INDEX, 0, expand, slider); } void uiItemEnumR(uiLayout *layout, char *name, int icon, struct PointerRNA *ptr, char *propname, int value) @@ -753,7 +769,7 @@ void uiItemEnumR(uiLayout *layout, char *name, int icon, struct PointerRNA *ptr, return; } - uiItemFullR(layout, name, icon, ptr, prop, RNA_ENUM_VALUE, value, 0); + uiItemFullR(layout, name, icon, ptr, prop, RNA_ENUM_VALUE, value, 0, 0); } void uiItemsEnumR(uiLayout *layout, struct PointerRNA *ptr, char *propname) @@ -791,24 +807,24 @@ static void ui_item_menutype_func(bContext *C, uiLayout *layout, void *arg_mt) static void ui_item_menu(uiLayout *layout, char *name, int icon, uiMenuCreateFunc func, void *arg, void *argN) { - uiBlock *block= layout->common->block; + uiBlock *block= layout->root->block; uiBut *but; int w, h; uiBlockSetCurLayout(block, layout); - if(layout->common->type == UI_LAYOUT_HEADER) + if(layout->root->type == UI_LAYOUT_HEADER) uiBlockSetEmboss(block, UI_EMBOSSP); if(!name) name= ""; - if(layout->common->type == UI_LAYOUT_MENU && !icon) + if(layout->root->type == UI_LAYOUT_MENU && !icon) icon= ICON_BLANK1; w= ui_text_icon_width(layout, name, icon); h= UI_UNIT_Y; - if(layout->common->type == UI_LAYOUT_HEADER) /* ugly .. */ + if(layout->root->type == UI_LAYOUT_HEADER) /* ugly .. */ w -= 3; if(icon) @@ -821,7 +837,7 @@ static void ui_item_menu(uiLayout *layout, char *name, int icon, uiMenuCreateFun but->func_argN= argN; } - if(layout->common->type == UI_LAYOUT_HEADER) + if(layout->root->type == UI_LAYOUT_HEADER) uiBlockSetEmboss(block, UI_EMBOSS); } @@ -837,7 +853,7 @@ void uiItemM(uiLayout *layout, bContext *C, char *name, int icon, char *menuname if(strcmp(menuname, mt->idname) == 0) { if(!name) name= mt->label; - if(layout->common->type == UI_LAYOUT_MENU && !icon) + if(layout->root->type == UI_LAYOUT_MENU && !icon) icon= ICON_BLANK1; ui_item_menu(layout, name, icon, ui_item_menutype_func, mt, NULL); break; @@ -848,7 +864,7 @@ void uiItemM(uiLayout *layout, bContext *C, char *name, int icon, char *menuname /* label item */ void uiItemL(uiLayout *layout, char *name, int icon) { - uiBlock *block= layout->common->block; + uiBlock *block= layout->root->block; uiBut *but; int w; @@ -856,7 +872,7 @@ void uiItemL(uiLayout *layout, char *name, int icon) if(!name) name= ""; - if(layout->common->type == UI_LAYOUT_MENU && !icon) + if(layout->root->type == UI_LAYOUT_MENU && !icon) icon= ICON_BLANK1; w= ui_text_icon_width(layout, name, icon); @@ -873,7 +889,7 @@ void uiItemL(uiLayout *layout, char *name, int icon) void uiItemV(uiLayout *layout, char *name, int icon, int argval) { /* label */ - uiBlock *block= layout->common->block; + uiBlock *block= layout->root->block; float *retvalue= (block->handle)? &block->handle->retvalue: NULL; int w; @@ -881,7 +897,7 @@ void uiItemV(uiLayout *layout, char *name, int icon, int argval) if(!name) name= ""; - if(layout->common->type == UI_LAYOUT_MENU && !icon) + if(layout->root->type == UI_LAYOUT_MENU && !icon) icon= ICON_BLANK1; w= ui_text_icon_width(layout, name, icon); @@ -897,7 +913,7 @@ void uiItemV(uiLayout *layout, char *name, int icon, int argval) /* separator item */ void uiItemS(uiLayout *layout) { - uiBlock *block= layout->common->block; + uiBlock *block= layout->root->block; uiBlockSetCurLayout(block, layout); uiDefBut(block, SEPR, 0, "", 0, 0, EM_SEPR_X, EM_SEPR_Y, NULL, 0.0, 0.0, 0, 0, ""); @@ -939,13 +955,13 @@ void uiItemMenuEnumO(uiLayout *layout, char *name, int icon, char *opname, char if(!name) name= ot->name; - if(layout->common->type == UI_LAYOUT_MENU && !icon) + if(layout->root->type == UI_LAYOUT_MENU && !icon) icon= ICON_BLANK1; lvl= MEM_callocN(sizeof(MenuItemLevel), "MenuItemLevel"); lvl->opname= opname; lvl->propname= propname; - lvl->opcontext= layout->common->opcontext; + lvl->opcontext= layout->root->opcontext; ui_item_menu(layout, name, icon, menu_item_enum_opname_menu, NULL, lvl); } @@ -971,13 +987,13 @@ void uiItemMenuEnumR(uiLayout *layout, char *name, int icon, struct PointerRNA * if(!name) name= (char*)RNA_property_ui_name(prop); - if(layout->common->type == UI_LAYOUT_MENU && !icon) + if(layout->root->type == UI_LAYOUT_MENU && !icon) icon= ICON_BLANK1; lvl= MEM_callocN(sizeof(MenuItemLevel), "MenuItemLevel"); lvl->rnapoin= *ptr; lvl->propname= propname; - lvl->opcontext= layout->common->opcontext; + lvl->opcontext= layout->root->opcontext; ui_item_menu(layout, name, icon, menu_item_enum_rna_menu, NULL, lvl); } @@ -1117,7 +1133,7 @@ static void ui_litem_estimate_root(uiLayout *litem) static void ui_litem_layout_root(uiLayout *litem) { - if(litem->common->type == UI_LAYOUT_HEADER) + if(litem->root->type == UI_LAYOUT_HEADER) ui_litem_layout_row(litem); else ui_litem_layout_column(litem); @@ -1126,7 +1142,7 @@ static void ui_litem_layout_root(uiLayout *litem) /* box layout */ static void ui_litem_estimate_box(uiLayout *litem) { - uiStyle *style= litem->common->style; + uiStyle *style= litem->root->style; ui_litem_estimate_column(litem); litem->w += 2*style->boxspace; @@ -1135,7 +1151,7 @@ static void ui_litem_estimate_box(uiLayout *litem) static void ui_litem_layout_box(uiLayout *litem) { - uiStyle *style= litem->common->style; + uiStyle *style= litem->root->style; int w, h; w= litem->w; @@ -1156,13 +1172,13 @@ static void ui_litem_layout_box(uiLayout *litem) if(h != 0) litem->h += 2*style->boxspace; /* roundbox around the sublayout */ - uiDefBut(litem->common->block, ROUNDBOX, 0, "", litem->x, litem->y, litem->w, litem->h, NULL, 7.0, 0.0, 3, 20, ""); + uiDefBut(litem->root->block, ROUNDBOX, 0, "", litem->x, litem->y, litem->w, litem->h, NULL, 7.0, 0.0, 3, 20, ""); } /* multi-column layout, automatically flowing to the next */ static void ui_litem_estimate_column_flow(uiLayout *litem) { - uiStyle *style= litem->common->style; + uiStyle *style= litem->root->style; uiLayoutItemFlow *flow= (uiLayoutItemFlow*)litem; uiItem *item; int col, x, y, emh, emy, miny, itemw, itemh, maxw=0; @@ -1185,7 +1201,7 @@ static void ui_litem_estimate_column_flow(uiLayout *litem) return; } - flow->totcol= MAX2(litem->common->emw/maxw, 1); + flow->totcol= MAX2(litem->root->emw/maxw, 1); flow->totcol= MIN2(flow->totcol, totitem); } else @@ -1224,7 +1240,7 @@ static void ui_litem_estimate_column_flow(uiLayout *litem) static void ui_litem_layout_column_flow(uiLayout *litem) { - uiStyle *style= litem->common->style; + uiStyle *style= litem->root->style; uiLayoutItemFlow *flow= (uiLayoutItemFlow*)litem; uiItem *item; int col, x, y, w, emh, emy, miny, itemw, itemh; @@ -1404,11 +1420,13 @@ uiLayout *uiLayoutRow(uiLayout *layout, int align) litem= MEM_callocN(sizeof(uiLayout), "uiLayoutRow"); litem->item.type= ITEM_LAYOUT_ROW; - litem->common= layout->common; + litem->root= layout->root; litem->align= align; - litem->space= (align)? 0: layout->common->style->buttonspacex; + litem->space= (align)? 0: layout->root->style->buttonspacex; BLI_addtail(&layout->items, litem); + uiBlockSetCurLayout(layout->root->block, litem); + return litem; } @@ -1418,11 +1436,13 @@ uiLayout *uiLayoutColumn(uiLayout *layout, int align) litem= MEM_callocN(sizeof(uiLayout), "uiLayoutColumn"); litem->item.type= ITEM_LAYOUT_COLUMN; - litem->common= layout->common; + litem->root= layout->root; litem->align= align; - litem->space= (litem->align)? 0: layout->common->style->buttonspacey; + litem->space= (litem->align)? 0: layout->root->style->buttonspacey; BLI_addtail(&layout->items, litem); + uiBlockSetCurLayout(layout->root->block, litem); + return litem; } @@ -1432,12 +1452,14 @@ uiLayout *uiLayoutColumnFlow(uiLayout *layout, int number, int align) flow= MEM_callocN(sizeof(uiLayoutItemFlow), "uiLayoutItemFlow"); flow->litem.item.type= ITEM_LAYOUT_COLUMN_FLOW; - flow->litem.common= layout->common; + flow->litem.root= layout->root; flow->litem.align= align; - flow->litem.space= (flow->litem.align)? 0: layout->common->style->columnspace; + flow->litem.space= (flow->litem.align)? 0: layout->root->style->columnspace; flow->number= number; BLI_addtail(&layout->items, flow); + uiBlockSetCurLayout(layout->root->block, &flow->litem); + return &flow->litem; } @@ -1447,10 +1469,12 @@ uiLayout *uiLayoutBox(uiLayout *layout) box= MEM_callocN(sizeof(uiLayoutItemBx), "uiLayoutItemBx"); box->litem.item.type= ITEM_LAYOUT_BOX; - box->litem.common= layout->common; - box->litem.space= layout->common->style->columnspace; + box->litem.root= layout->root; + box->litem.space= layout->root->style->columnspace; BLI_addtail(&layout->items, box); + uiBlockSetCurLayout(layout->root->block, &box->litem); + return &box->litem; } @@ -1460,21 +1484,35 @@ uiLayout *uiLayoutFree(uiLayout *layout, int align) litem= MEM_callocN(sizeof(uiLayout), "uiLayoutFree"); litem->item.type= ITEM_LAYOUT_FREE; - litem->common= layout->common; + litem->root= layout->root; litem->align= align; BLI_addtail(&layout->items, litem); + uiBlockSetCurLayout(layout->root->block, litem); + return litem; } +uiBlock *uiLayoutFreeBlock(uiLayout *layout) +{ + uiBlock *block; + + block= uiLayoutBlock(layout); + uiLayoutFree(layout, 0); + + return block; +} + uiLayout *uiLayoutSplit(uiLayout *layout) { uiLayout *litem; litem= uiLayoutRow(layout, 0); litem->item.type = ITEM_LAYOUT_SPLIT; - litem->common= layout->common; - litem->space= layout->common->style->columnspace; + litem->root= layout->root; + litem->space= layout->root->style->columnspace; + + uiBlockSetCurLayout(layout->root->block, litem); return litem; } @@ -1491,6 +1529,9 @@ static void ui_item_estimate(uiItem *item) for(subitem=litem->items.first; subitem; subitem=subitem->next) ui_item_estimate(subitem); + if(litem->items.first == NULL) + return; + switch(litem->item.type) { case ITEM_LAYOUT_COLUMN: ui_litem_estimate_column(litem); @@ -1522,10 +1563,14 @@ static void ui_item_estimate(uiItem *item) static void ui_item_align(uiLayout *litem, int nr) { uiItem *item; + uiButtonItem *bitem; for(item=litem->items.first; item; item=item->next) { - if(item->type == ITEM_BUTTON) - ((uiButtonItem*)item)->but->alignnr= nr; + if(item->type == ITEM_BUTTON) { + bitem= (uiButtonItem*)item; + if(ui_but_can_align(bitem->but)) + bitem->but->alignnr= nr; + } else ui_item_align((uiLayout*)item, nr); } @@ -1538,8 +1583,11 @@ static void ui_item_layout(uiItem *item, int align) if(item->type != ITEM_BUTTON) { uiLayout *litem= (uiLayout*)item; + if(litem->items.first == NULL) + return; + if(litem->align && !align) - ui_item_align(litem, ++litem->common->block->alignnr); + ui_item_align(litem, ++litem->root->block->alignnr); switch(litem->item.type) { case ITEM_LAYOUT_COLUMN: @@ -1580,8 +1628,8 @@ static void ui_layout_items(const bContext *C, uiBlock *block, uiLayout *layout) static void ui_layout_end(const bContext *C, uiBlock *block, uiLayout *layout, int *x, int *y) { - if(layout->common->handlefunc) - uiBlockSetButmFunc(block, layout->common->handlefunc, layout->common->argv); + if(layout->root->handlefunc) + uiBlockSetButmFunc(block, layout->root->handlefunc, layout->root->argv); ui_layout_items(C, block, layout); @@ -1608,45 +1656,44 @@ static void ui_layout_free(uiLayout *layout) uiLayout *uiBlockLayout(uiBlock *block, int dir, int type, int x, int y, int size, int em, uiStyle *style) { uiLayout *layout; - uiLayoutCommon *common; + uiLayoutRoot *root; - if(!block->layout) { - common= MEM_callocN(sizeof(uiLayoutCommon), "uiLayoutCommon"); - common->type= type; - common->style= style; - common->block= block; - common->opcontext= WM_OP_INVOKE_REGION_WIN; + root= MEM_callocN(sizeof(uiLayoutRoot), "uiLayoutRoot"); + root->type= type; + root->style= style; + root->block= block; + root->opcontext= WM_OP_INVOKE_REGION_WIN; - layout= MEM_callocN(sizeof(uiLayout), "uiLayout"); - layout->item.type= ITEM_LAYOUT_ROOT; + layout= MEM_callocN(sizeof(uiLayout), "uiLayout"); + layout->item.type= ITEM_LAYOUT_ROOT; - layout->x= x; - layout->y= y; - layout->common= common; - layout->space= style->templatespace; + layout->x= x; + layout->y= y; + layout->root= root; + layout->space= style->templatespace; - if(type == UI_LAYOUT_MENU) - layout->space= 0; - - if(dir == UI_LAYOUT_HORIZONTAL) { - layout->h= size; - layout->common->emh= em*UI_UNIT_Y; - } - else { - layout->w= size; - layout->common->emw= em*UI_UNIT_X; - } + if(type == UI_LAYOUT_MENU) + layout->space= 0; - block->curlayout= layout; - block->layout= layout; + if(dir == UI_LAYOUT_HORIZONTAL) { + layout->h= size; + layout->root->emh= em*UI_UNIT_Y; + } + else { + layout->w= size; + layout->root->emw= em*UI_UNIT_X; } + + block->curlayout= layout; + root->layout= layout; + BLI_addtail(&block->layouts, root); - return block->layout; + return layout; } uiBlock *uiLayoutBlock(uiLayout *layout) { - return layout->common->block; + return layout->root->block; } void uiBlockSetCurLayout(uiBlock *block, uiLayout *layout) @@ -1666,33 +1713,32 @@ void ui_layout_add_but(uiLayout *layout, uiBut *but) void uiLayoutContext(uiLayout *layout, int opcontext) { - layout->common->opcontext= opcontext; + layout->root->opcontext= opcontext; } void uiLayoutFunc(uiLayout *layout, uiMenuHandleFunc handlefunc, void *argv) { - layout->common->handlefunc= handlefunc; - layout->common->argv= argv; + layout->root->handlefunc= handlefunc; + layout->root->argv= argv; } void uiBlockLayoutResolve(const bContext *C, uiBlock *block, int *x, int *y) { - uiLayout *layout= block->layout; + uiLayoutRoot *root; - if(layout) { - /* NULL in advance so we don't interfere when adding button */ - block->layout= NULL; - block->curlayout= NULL; + if(x) *x= 0; + if(y) *y= 0; - ui_layout_end(C, block, layout, x, y); - MEM_freeN(layout->common); - ui_layout_free(layout); - } - else { - if(x) *x= 0; - if(y) *y= 0; + block->curlayout= NULL; + + for(root=block->layouts.first; root; root=root->next) { + /* NULL in advance so we don't interfere when adding button */ + ui_layout_end(C, block, root->layout, x, y); + ui_layout_free(root->layout); } + BLI_freelistN(&block->layouts); + /* XXX silly trick, interface_templates.c doesn't get linked * because it's not used by other files in this module? */ { diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c index 36c794ab098..96683750062 100644 --- a/source/blender/editors/interface/interface_panel.c +++ b/source/blender/editors/interface/interface_panel.c @@ -125,6 +125,7 @@ static int panels_re_align(ScrArea *sa, ARegion *ar, Panel **r_pa) else if(ar->regiontype==RGN_TYPE_UI) return 1; + /* in case panel is added or disappears */ for(pa=ar->panels.first; pa; pa=pa->next) { if((pa->runtime_flag & PNL_WAS_ACTIVE) && !(pa->runtime_flag & PNL_ACTIVE)) return 1; @@ -134,6 +135,7 @@ static int panels_re_align(ScrArea *sa, ARegion *ar, Panel **r_pa) active= 1; } + /* in case we need to do an animation (size changes) */ for(pa=ar->panels.first; pa; pa=pa->next) { if(pa->runtime_flag & PNL_ANIM_ALIGN) { if(!active) @@ -155,7 +157,7 @@ static void ui_panel_copy_offset(Panel *pa, Panel *papar) pa->ofsy= papar->ofsy + papar->sizey-pa->sizey; } -Panel *uiBeginPanel(ARegion *ar, uiBlock *block, PanelType *pt) +Panel *uiBeginPanel(ARegion *ar, uiBlock *block, PanelType *pt, int *open) { uiStyle *style= U.uistyles.first; Panel *pa, *patab, *palast, *panext; @@ -182,7 +184,7 @@ Panel *uiBeginPanel(ARegion *ar, uiBlock *block, PanelType *pt) BLI_strncpy(pa->panelname, panelname, UI_MAX_NAME_STR); BLI_strncpy(pa->tabname, tabname, UI_MAX_NAME_STR); - pa->ofsx= style->panelouter; + pa->ofsx= 0; pa->ofsy= style->panelouter; pa->sizex= 0; pa->sizey= 0; @@ -227,11 +229,13 @@ Panel *uiBeginPanel(ARegion *ar, uiBlock *block, PanelType *pt) block->panel= pa; pa->runtime_flag |= PNL_ACTIVE|PNL_LAST_ADDED; - if(pa->paneltab) return NULL; - if(pa->flag & PNL_CLOSED) return NULL; + *open= 0; - /* the 'return 0' above makes this to be in end. otherwise closes panels show wrong title */ - pa->drawname[0]= 0; + if(pa->paneltab) return pa; + if(pa->flag & PNL_CLOSED) return pa; + + *open= 1; + pa->drawname[0]= 0; /* otherwise closes panels show wrong title */ return pa; } @@ -274,93 +278,6 @@ void uiPanelToMouse(const bContext *C, Panel *pa) } #endif -/* ofsx/ofsy only used for new panel definitions */ -/* return 1 if visible (create buttons!) */ -int uiNewPanel(const bContext *C, ARegion *ar, uiBlock *block, char *panelname, char *tabname, int ofsx, int ofsy, int sizex, int sizey) -{ - Panel *pa; - - /* check if Panel exists, then use that one */ - for(pa=ar->panels.first; pa; pa=pa->next) - if(strncmp(pa->panelname, panelname, UI_MAX_NAME_STR)==0) - if(strncmp(pa->tabname, tabname, UI_MAX_NAME_STR)==0) - break; - - if(pa) { - /* scale correction */ - if(pa->control & UI_PNL_SCALE); - else { - pa->sizex= sizex; - if(pa->sizey != sizey) { - pa->ofsy+= (pa->sizey - sizey); // check uiNewPanelHeight() - pa->sizey= sizey; - } - } - } - else { - /* new panel */ - pa= MEM_callocN(sizeof(Panel), "new panel"); - BLI_addtail(&ar->panels, pa); - strncpy(pa->panelname, panelname, UI_MAX_NAME_STR); - strncpy(pa->tabname, tabname, UI_MAX_NAME_STR); - - pa->ofsx= ofsx & ~(PNL_GRID-1); - pa->ofsy= ofsy & ~(PNL_GRID-1); - pa->sizex= sizex; - pa->sizey= sizey; - -#if 0 - /* make new Panel tabbed? */ - if(panel_tabbed && group_tabbed) { - Panel *papar; - for(papar= ar->panels.first; papar; papar= papar->next) { - if(papar->active && papar->paneltab==NULL) { - if( strncmp(panel_tabbed, papar->panelname, UI_MAX_NAME_STR)==0) { - if( strncmp(group_tabbed, papar->tabname, UI_MAX_NAME_STR)==0) { - pa->paneltab= papar; - copy_panel_offset(pa, papar); - break; - } - } - } - } - } -#endif - } - - block->panel= pa; - pa->runtime_flag |= PNL_ACTIVE; - - /* clear ugly globals */ - // XXX pa->control= pnl_control; - // XXX panel_tabbed= group_tabbed= NULL; - // XXX pa->control= UI_PNL_TRANSP; // back to default - - if(pa->paneltab) return 0; - if(pa->flag & PNL_CLOSED) return 0; - - /* the 'return 0' above makes this to be in end. otherwise closes panels show wrong title */ - pa->drawname[0]= 0; - - return 1; -} - -void uiNewPanelHeight(uiBlock *block, int sizey) -{ - if(sizey<0) sizey= 0; - - if(block->panel) { - block->panel->ofsy+= (block->panel->sizey - sizey); - block->panel->sizey= sizey; - } -} - -void uiNewPanelTitle(uiBlock *block, char *str) -{ - if(block->panel) - BLI_strncpy(block->panel->drawname, str, UI_MAX_NAME_STR); -} - static int panel_has_tabs(ARegion *ar, Panel *panel) { Panel *pa= ar->panels.first; @@ -376,35 +293,20 @@ static int panel_has_tabs(ARegion *ar, Panel *panel) return 0; } -static void ui_scale_panel_block(uiBlock *block) +static void ui_offset_panel_block(uiBlock *block) { uiStyle *style= U.uistyles.first; uiBut *but; - float facx= 1.0, facy= 1.0; - int centerx= 0, topy=0, tabsy=0, space= style->panelspace; - - if(block->panel==NULL) return; + int space= style->panelspace; /* buttons min/max centered, offset calculated */ ui_bounds_block(block); - if((!block->panel->type) && block->maxx-block->minx > block->panel->sizex - 2*space) - facx= (block->panel->sizex - (2*space))/(block->maxx-block->minx); - else - centerx= (block->panel->sizex-(block->maxx-block->minx) - 2*space)/2; - - // tabsy= PNL_HEADER*panel_has_tabs(block->panel); - if((!block->panel->type) && (block->maxy-block->miny) > block->panel->sizey - 2*space - tabsy) - facy= (block->panel->sizey - (2*space) - tabsy)/(block->maxy-block->miny); - else - topy= (block->panel->sizey- 2*space - tabsy) - (block->maxy-block->miny) ; - for(but= block->buttons.first; but; but=but->next) { - but->x1= space+centerx+ facx*(but->x1-block->minx); - but->y1= space+topy + facy*(but->y1-block->miny); - but->x2= space+centerx+ facx*(but->x2-block->minx); - but->y2= space+topy + facy*(but->y2-block->miny); - if(facx!=1.0) ui_check_but(but); /* for strlen */ + but->x1= space + (but->x1-block->minx); + but->y1= space + (but->y1-block->miny); + but->x2= space + (but->x2-block->minx); + but->y2= space + (but->y2-block->miny); } block->maxx= block->panel->sizex; @@ -412,110 +314,6 @@ static void ui_scale_panel_block(uiBlock *block) block->minx= block->miny= 0.0; } -// for 'home' key -void uiPanelsHome(ARegion *ar) -{ - uiStyle *style= U.uistyles.first; - Panel *pa; - uiBlock *block; - View2D *v2d; - float minx=10000, maxx= -10000, miny=10000, maxy= -10000; - int done=0; - - v2d= &ar->v2d; - - for(pa= ar->panels.first; pa; pa=pa->next) { - if((pa->runtime_flag & PNL_ACTIVE) && pa->paneltab==NULL) { - done= 1; - if(pa->ofsx < minx) minx= pa->ofsx; - if(pa->ofsx+pa->sizex > maxx) maxx= pa->ofsx+pa->sizex; - if(pa->ofsy < miny) miny= pa->ofsy; - if(pa->ofsy+pa->sizey+PNL_HEADER > maxy) maxy= pa->ofsy+pa->sizey+PNL_HEADER; - } - } - - if(done) { - v2d->tot.xmin= minx-style->panelouter; - v2d->tot.xmax= maxx+style->panelouter; - v2d->tot.ymin= miny-style->panelouter; - v2d->tot.ymax= maxy+style->panelouter; - } - else { - v2d->tot.xmin= 0; - v2d->tot.xmax= 1280; - v2d->tot.ymin= 0; - v2d->tot.ymax= 228; - - /* no panels, but old 'loose' buttons, as in old logic editor */ - for(block= ar->uiblocks.first; block; block= block->next) { - if(block->minx < v2d->tot.xmin) v2d->tot.xmin= block->minx; - if(block->maxx > v2d->tot.xmax) v2d->tot.xmax= block->maxx; - if(block->miny < v2d->tot.ymin) v2d->tot.ymin= block->miny; - if(block->maxy > v2d->tot.ymax) v2d->tot.ymax= block->maxy; - } - } -} - -// make sure the panels are not outside 'tot' area -static void ui_panels_update_totrct(ARegion *ar) -{ - Panel *pa; - uiBlock *block; - View2D *v2d; - int done=0; - - v2d= &ar->v2d; - - v2d->tot.xmin= 0.0f; - v2d->tot.xmax= ar->winx; - v2d->tot.ymax= 0.0f; - v2d->tot.ymin= -ar->winy; - - for(pa= ar->panels.first; pa; pa=pa->next) { - if((pa->runtime_flag & PNL_ACTIVE) && pa->paneltab==NULL) { - done= 1; - - if(pa->ofsx < v2d->tot.xmin) - v2d->tot.xmin= pa->ofsx; - if(pa->ofsx+pa->sizex > v2d->tot.xmax) - v2d->tot.xmax= pa->ofsx+pa->sizex; - if(pa->ofsy < v2d->tot.ymin) - v2d->tot.ymin= pa->ofsy; - if(pa->ofsy+pa->sizey+PNL_HEADER > v2d->tot.ymax) - v2d->tot.ymax= pa->ofsy+pa->sizey+PNL_HEADER; - } - } - - if(done==0) { - /* no panels, but old 'loose' buttons, as in old logic editor */ - for(block= ar->uiblocks.first; block; block= block->next) { - if(block->minx < v2d->tot.xmin) v2d->tot.xmin= block->minx; - if(block->maxx > v2d->tot.xmax) v2d->tot.xmax= block->maxx; - if(block->miny < v2d->tot.ymin) v2d->tot.ymin= block->miny; - if(block->maxy > v2d->tot.ymax) v2d->tot.ymax= block->maxy; - } - } - - UI_view2d_totRect_set(v2d, v2d->tot.xmax, v2d->tot.ymin); -} - -uiBlock *uiFindOpenPanelBlockName(ListBase *lb, char *name) -{ - uiBlock *block; - Panel *pa; - - for(block= lb->first; block; block= block->next) { - pa= block->panel; - - if(pa && (pa->runtime_flag & PNL_ACTIVE) && pa->paneltab==NULL) { - if(pa->flag & PNL_CLOSED); - else if(strncmp(name, pa->panelname, UI_MAX_NAME_STR)==0) break; - } - } - - return block; -} - /**************************** drawing *******************************/ /* extern used by previewrender */ @@ -652,8 +450,9 @@ static void ui_draw_aligned_panel_header(ARegion *ar, uiStyle *style, uiBlock *b if(pa->paneltab==panel) nr++; - if(panel->control & UI_PNL_CLOSE) pnl_icons=(2*PNL_ICON+10)/block->aspect; - else pnl_icons= (PNL_ICON+10)/block->aspect; + /* + 0.001f to avoid flirting with float inaccuracy */ + if(panel->control & UI_PNL_CLOSE) pnl_icons=(2*PNL_ICON+5)/block->aspect + 0.001f; + else pnl_icons= (PNL_ICON+5)/block->aspect + 0.001f; if(nr==1) { @@ -718,9 +517,10 @@ void ui_draw_aligned_panel(ARegion *ar, uiStyle *style, uiBlock *block, rcti *re if(panel->paneltab) return; /* calculate header rect */ + /* + 0.001f to prevent flicker due to float inaccuracy */ headrect= *rect; headrect.ymin= headrect.ymax; - headrect.ymax= headrect.ymin + floor(PNL_HEADER/block->aspect); + headrect.ymax= headrect.ymin + floor(PNL_HEADER/block->aspect + 0.001f); /* divider only when there's a previous panel */ prev= panel->prev; @@ -729,8 +529,8 @@ void ui_draw_aligned_panel(ARegion *ar, uiStyle *style, uiBlock *block, rcti *re prev= prev->prev; } - if(prev) { - float minx= rect->xmin+10.0f/block->aspect; + if(panel->sortorder != 0) { + float minx= rect->xmin+5.0f/block->aspect; float maxx= rect->xmax-5.0f/block->aspect; float y= headrect.ymax; @@ -747,7 +547,7 @@ void ui_draw_aligned_panel(ARegion *ar, uiStyle *style, uiBlock *block, rcti *re ui_draw_aligned_panel_header(ar, style, block, &headrect); /* itemrect smaller */ - itemrect.xmax= headrect.xmax - 10.0f/block->aspect; + itemrect.xmax= headrect.xmax - 5.0f/block->aspect; itemrect.xmin= itemrect.xmax - (headrect.ymax-headrect.ymin); itemrect.ymin= headrect.ymin; itemrect.ymax= headrect.ymax; @@ -808,12 +608,12 @@ void ui_draw_aligned_panel(ARegion *ar, uiStyle *style, uiBlock *block, rcti *re UI_ThemeColor(TH_TEXT); /* itemrect smaller */ - itemrect.xmin= headrect.xmin + 10.0f/block->aspect; + itemrect.xmin= headrect.xmin + 5.0f/block->aspect; itemrect.xmax= itemrect.xmin + (headrect.ymax-headrect.ymin); itemrect.ymin= headrect.ymin; itemrect.ymax= headrect.ymax; - rectf_scale(&itemrect, 0.7f); + rectf_scale(&itemrect, 0.5f); if(panel->flag & PNL_CLOSEDY) ui_draw_tria_rect(&itemrect, 'h'); @@ -944,7 +744,7 @@ int uiAlignPanelStep(ScrArea *sa, ARegion *ar, float fac, int drag) /* no smart other default start loc! this keeps switching f5/f6/etc compatible */ ps= panelsort; - ps->pa->ofsx= style->panelouter; + ps->pa->ofsx= 0; ps->pa->ofsy= -ps->pa->sizey-PNL_HEADER-style->panelouter; for(a=0; a<tot-1; a++, ps++) { @@ -955,7 +755,7 @@ int uiAlignPanelStep(ScrArea *sa, ARegion *ar, float fac, int drag) psnext->pa->ofsy= get_panel_real_ofsy(ps->pa) - psnext->pa->sizey-PNL_HEADER-style->panelouter; } else { - psnext->pa->ofsx= get_panel_real_ofsx(ps->pa)+style->panelouter; + psnext->pa->ofsx= get_panel_real_ofsx(ps->pa); psnext->pa->ofsy= ps->pa->ofsy + ps->pa->sizey - psnext->pa->sizey; } } @@ -1034,7 +834,7 @@ void uiEndPanels(const bContext *C, ARegion *ar) /* scaling contents */ for(block= ar->uiblocks.first; block; block= block->next) if(block->active && block->panel) - ui_scale_panel_block(block); + ui_offset_panel_block(block); /* consistancy; are panels not made, whilst they have tabs */ for(panot= ar->panels.first; panot; panot= panot->next) { @@ -1068,93 +868,6 @@ void uiEndPanels(const bContext *C, ARegion *ar) else uiAlignPanelStep(sa, ar, 1.0, 0); } - - if(sa->spacetype!=SPACE_BUTS) { -#if 0 // XXX make float panel exception - SpaceLink *sl= sa->spacedata.first; - for(block= ar->uiblocks.first; block; block= block->next) { - if(block->active && block->panel && block->panel->active && block->panel->paneltab == NULL) { - float dx=0.0, dy=0.0, minx, miny, maxx, maxy, miny_panel; - - minx= sl->blockscale*block->panel->ofsx; - maxx= sl->blockscale*(block->panel->ofsx+block->panel->sizex); - miny= sl->blockscale*(block->panel->ofsy+block->panel->sizey); - maxy= sl->blockscale*(block->panel->ofsy+block->panel->sizey+PNL_HEADER); - miny_panel= sl->blockscale*(block->panel->ofsy); - - /* check to see if snapped panels have been left out in the open by resizing a window - * and if so, offset them back to where they belong */ - if (block->panel->snap) { - if (((block->panel->snap) & PNL_SNAP_RIGHT) && - (maxx < (float)sa->winx)) { - - dx = sa->winx-maxx; - block->panel->ofsx+= dx/sl->blockscale; - } - if (((block->panel->snap) & PNL_SNAP_TOP) && - (maxy < (float)sa->winy)) { - - dy = sa->winy-maxy; - block->panel->ofsy+= dy/sl->blockscale; - } - - /* reset these vars with updated panel offset distances */ - minx= sl->blockscale*block->panel->ofsx; - maxx= sl->blockscale*(block->panel->ofsx+block->panel->sizex); - miny= sl->blockscale*(block->panel->ofsy+block->panel->sizey); - maxy= sl->blockscale*(block->panel->ofsy+block->panel->sizey+PNL_HEADER); - miny_panel= sl->blockscale*(block->panel->ofsy); - } else - /* reset to no snapping */ - block->panel->snap = PNL_SNAP_NONE; - - - /* clip panels (headers) for non-butspace situations (maybe make optimized event later) */ - - /* check left and right edges */ - if (minx < PNL_SNAP_DIST) { - dx = -minx; - block->panel->snap |= PNL_SNAP_LEFT; - } - else if (maxx > ((float)sa->winx - PNL_SNAP_DIST)) { - dx= sa->winx-maxx; - block->panel->snap |= PNL_SNAP_RIGHT; - } - if(minx + dx < 0.0) dx= -minx; // when panel cant fit, put it fixed here - - /* check top and bottom edges */ - if ((miny_panel < PNL_SNAP_DIST) && (miny_panel > -PNL_SNAP_DIST)) { - dy= -miny_panel; - block->panel->snap |= PNL_SNAP_BOTTOM; - } - if(miny < PNL_SNAP_DIST) { - dy= -miny; - block->panel->snap |= PNL_SNAP_BOTTOM; - } - else if(maxy > ((float)sa->winy - PNL_SNAP_DIST)) { - dy= sa->winy-maxy; - block->panel->snap |= PNL_SNAP_TOP; - } - if(miny + dy < 0.0) dy= -miny; // when panel cant fit, put it fixed here - - - block->panel->ofsx+= dx/sl->blockscale; - block->panel->ofsy+= dy/sl->blockscale; - - /* copy locations */ - for(patest= ar->panels.first; patest; patest= patest->next) { - if(patest->paneltab==block->panel) ui_panel_copy_offset(patest, block->panel); - } - - } - } -#endif - } - - /* update v2d->totrct and update view */ - ui_panels_update_totrct(ar); - UI_view2d_view_restore(C); - UI_view2d_view_ortho(C, &ar->v2d); /* draw panels, selected on top */ for(block= ar->uiblocks.first; block; block=block->next) { @@ -1464,6 +1177,10 @@ int ui_handler_panel_region(bContext *C, wmEvent *event) retval= WM_UI_HANDLER_CONTINUE; + /* buttons get priority */ + if(ui_button_is_active(ar)) + return retval; + for(block=ar->uiblocks.last; block; block=block->prev) { mx= event->x; my= event->y; diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 5244c9983cf..8969e2b69ae 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -42,16 +42,6 @@ #include "UI_interface.h" #include "UI_resources.h" -static uiBlock *block_free_layout(uiLayout *layout) -{ - uiBlock *block; - - block= uiLayoutBlock(layout); - uiBlockSetCurLayout(block, uiLayoutFree(layout, 0)); - - return block; -} - void ui_template_fix_linking() { } @@ -62,7 +52,7 @@ void uiTemplateHeader(uiLayout *layout, bContext *C) { uiBlock *block; - block= block_free_layout(layout); + block= uiLayoutFreeBlock(layout); ED_area_header_standardbuttons(C, block, 0); } @@ -240,7 +230,7 @@ void uiTemplateHeaderID(uiLayout *layout, bContext *C, PointerRNA *ptr, char *pr BLI_strncpy(template->unlinkop, unlinkop, sizeof(template->unlinkop)); } - block= block_free_layout(layout); + block= uiLayoutFreeBlock(layout); template_header_ID(C, block, template); MEM_freeN(template); diff --git a/source/blender/editors/interface/interface_utils.c b/source/blender/editors/interface/interface_utils.c index e3f986efde9..e9d96446c11 100644 --- a/source/blender/editors/interface/interface_utils.c +++ b/source/blender/editors/interface/interface_utils.c @@ -315,16 +315,12 @@ uiBut *uiDefAutoButR(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int ind return but; } -int uiDefAutoButsRNA(const bContext *C, uiBlock *block, PointerRNA *ptr) +void uiDefAutoButsRNA(const bContext *C, uiLayout *layout, PointerRNA *ptr) { - uiStyle *style= U.uistyles.first; CollectionPropertyIterator iter; PropertyRNA *iterprop, *prop; - uiLayout *layout, *split; + uiLayout *split; char *name; - int x= 0, y= 0; - - layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, x, y, DEF_BUT_WIDTH*2, 20, style); uiItemL(layout, (char*)RNA_struct_ui_name(ptr->type), 0); @@ -342,26 +338,19 @@ int uiDefAutoButsRNA(const bContext *C, uiBlock *block, PointerRNA *ptr) name= (char*)RNA_property_ui_name(prop); uiItemL(uiLayoutColumn(split, 0), name, 0); - uiItemFullR(uiLayoutColumn(split, 0), "", 0, ptr, prop, -1, 0, 0); + uiItemFullR(uiLayoutColumn(split, 0), "", 0, ptr, prop, -1, 0, 0, 0); } RNA_property_collection_end(&iter); - uiBlockLayoutResolve(C, block, &x, &y); - - return -y; } /* temp call, single collumn, test for toolbar only */ -int uiDefAutoButsRNA_single(const bContext *C, uiBlock *block, PointerRNA *ptr) +void uiDefAutoButsRNA_single(const bContext *C, uiLayout *layout, PointerRNA *ptr) { - uiStyle *style= U.uistyles.first; CollectionPropertyIterator iter; PropertyRNA *iterprop, *prop; - uiLayout *layout; + uiLayout *col; char *name; - int x= 0, y= 0; - - layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, x, y, block->panel->sizex, 20, style); uiItemL(layout, (char*)RNA_struct_ui_name(ptr->type), 0); @@ -375,17 +364,14 @@ int uiDefAutoButsRNA_single(const bContext *C, uiBlock *block, PointerRNA *ptr) continue; name= (char*)RNA_property_ui_name(prop); - uiItemL(layout, name, 0); - uiItemFullR(layout, "", 0, ptr, prop, -1, 0, 0); + col= uiLayoutColumn(layout, 1); + uiItemL(col, name, 0); + uiItemFullR(col, "", 0, ptr, prop, -1, 0, 0, 0); } RNA_property_collection_end(&iter); - uiBlockLayoutResolve(C, block, &x, &y); - - return -y; } - /***************************** ID Utilities *******************************/ typedef struct uiIDPoinParams { diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c index 191f38ad7d0..f2fc2deefbb 100644 --- a/source/blender/editors/interface/view2d.c +++ b/source/blender/editors/interface/view2d.c @@ -155,23 +155,6 @@ void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy) { short tot_changed= 0; - /* XXX always set state vars for buttonsview, this is hardcoded */ - switch (type) { - /* panels view, with free/horizontal/vertical align */ - case V2D_COMMONVIEW_PANELS_UI: - { - /* for now, aspect ratio should be maintained, and zoom is clamped within sane default limits */ - v2d->keepzoom= (V2D_KEEPASPECT|V2D_KEEPZOOM); - v2d->minzoom= 0.5f; - v2d->maxzoom= 2.0f; - - v2d->align= (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_POS_Y); - v2d->keeptot= V2D_KEEPTOT_BOUNDS; - } - break; - } - - /* initialise data if there is a need for such */ if ((v2d->flag & V2D_IS_INITIALISED) == 0) { /* set initialised flag so that View2D doesn't get reinitialised next time again */ @@ -249,28 +232,7 @@ void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy) } break; - /* ui listviews, tries to wrap 'tot' inside region width */ - case V2D_COMMONVIEW_LIST_UI: - { - /* for now, aspect ratio should be maintained, and zoom is clamped within sane default limits */ - v2d->keepzoom= (V2D_KEEPASPECT|V2D_KEEPZOOM); - v2d->minzoom= 0.5f; - v2d->maxzoom= 2.0f; - - v2d->align= (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_POS_Y); - v2d->keeptot= V2D_KEEPTOT_BOUNDS; - - v2d->tot.xmin= 0.0f; - v2d->tot.xmax= 336.f; // XXX 320 width + 2 x PNL_DIST - - v2d->tot.ymax= 0.0f; - v2d->tot.ymin= -336.0f*((float)winy)/(float)winx; - - v2d->cur= v2d->tot; - } - break; - - /* panels view, with free/horizontal/vertical align */ + /* panels view, with horizontal/vertical align */ case V2D_COMMONVIEW_PANELS_UI: { /* for now, aspect ratio should be maintained, and zoom is clamped within sane default limits */ @@ -465,18 +427,28 @@ void UI_view2d_curRect_validate(View2D *v2d) /* resize from centerpoint */ if (width != curwidth) { - temp= (cur->xmax + cur->xmin) * 0.5f; - dh= width * 0.5f; - - cur->xmin = temp - dh; - cur->xmax = temp + dh; + if (v2d->keepofs & V2D_LOCKOFS_X) { + cur->xmax += width - (cur->xmax - cur->xmin); + } + else { + temp= (cur->xmax + cur->xmin) * 0.5f; + dh= width * 0.5f; + + cur->xmin = temp - dh; + cur->xmax = temp + dh; + } } if (height != curheight) { - temp= (cur->ymax + cur->ymin) * 0.5f; - dh= height * 0.5f; - - cur->ymin = temp - dh; - cur->ymax = temp + dh; + if (v2d->keepofs & V2D_LOCKOFS_Y) { + cur->ymax += height - (cur->ymax - cur->ymin); + } + else { + temp= (cur->ymax + cur->ymin) * 0.5f; + dh= height * 0.5f; + + cur->ymin = temp - dh; + cur->ymax = temp + dh; + } } } @@ -872,8 +844,13 @@ void UI_view2d_view_ortho(const bContext *C, View2D *v2d) * but only applied where requsted */ /* XXX ton: fix this! */ - xofs= 0.0f; // (v2d->flag & V2D_PIXELOFS_X) ? 0.375f : 0.0f; - yofs= 0.0f; // (v2d->flag & V2D_PIXELOFS_Y) ? 0.375f : 0.0f; + xofs= 0.0; // (v2d->flag & V2D_PIXELOFS_X) ? 0.375f : 0.0f; + yofs= 0.0; // (v2d->flag & V2D_PIXELOFS_Y) ? 0.375f : 0.0f; + + /* XXX brecht: instead of zero at least use a tiny offset, otherwise + * pixel rounding is effectively random due to float inaccuracy */ + xofs= 0.001f; + yofs= 0.001f; /* apply mask-based adjustments to cur rect (due to scrollers), to eliminate scaling artifacts */ view2d_map_cur_using_mask(v2d, &curmasked); diff --git a/source/blender/editors/interface/view2d_ops.c b/source/blender/editors/interface/view2d_ops.c index 6da9512f9e0..bd1c734b870 100644 --- a/source/blender/editors/interface/view2d_ops.c +++ b/source/blender/editors/interface/view2d_ops.c @@ -54,6 +54,12 @@ #include "UI_resources.h" #include "UI_view2d.h" +static int view2d_poll(bContext *C) +{ + ARegion *ar= CTX_wm_region(C); + + return (ar != NULL) && (ar->v2d.flag & V2D_IS_INITIALISED); +} /* ********************************************************* */ /* VIEW PANNING OPERATOR */ @@ -110,8 +116,8 @@ static int view_pan_init(bContext *C, wmOperator *op) vpd->v2d= v2d; /* calculate translation factor - based on size of view */ - winx= (float)(ar->winrct.xmax - ar->winrct.xmin); - winy= (float)(ar->winrct.ymax - ar->winrct.ymin); + winx= (float)(ar->winrct.xmax - ar->winrct.xmin + 1); + winy= (float)(ar->winrct.ymax - ar->winrct.ymin + 1); vpd->facx= (v2d->cur.xmax - v2d->cur.xmin) / winx; vpd->facy= (v2d->cur.ymax - v2d->cur.ymin) / winy; @@ -489,12 +495,22 @@ static void view_zoomstep_apply(bContext *C, wmOperator *op) /* only resize view on an axis if change is allowed */ if ((v2d->keepzoom & V2D_LOCKZOOM_X)==0) { - v2d->cur.xmin += dx; - v2d->cur.xmax -= dx; + if (v2d->keepofs & V2D_LOCKOFS_X) { + v2d->cur.xmax -= 2*dx; + } + else { + v2d->cur.xmin += dx; + v2d->cur.xmax -= dx; + } } if ((v2d->keepzoom & V2D_LOCKZOOM_Y)==0) { - v2d->cur.ymin += dy; - v2d->cur.ymax -= dy; + if (v2d->keepofs & V2D_LOCKOFS_Y) { + v2d->cur.ymax -= 2*dy; + } + else { + v2d->cur.ymin += dy; + v2d->cur.ymax -= dy; + } } /* validate that view is in valid configuration after this operation */ @@ -635,12 +651,22 @@ static void view_zoomdrag_apply(bContext *C, wmOperator *op) /* only move view on an axis if change is allowed */ if ((v2d->keepzoom & V2D_LOCKZOOM_X)==0) { - v2d->cur.xmin += dx; - v2d->cur.xmax -= dx; + if (v2d->keepofs & V2D_LOCKOFS_X) { + v2d->cur.xmax -= 2*dx; + } + else { + v2d->cur.xmin += dx; + v2d->cur.xmax -= dx; + } } if ((v2d->keepzoom & V2D_LOCKZOOM_Y)==0) { - v2d->cur.ymin += dy; - v2d->cur.ymax -= dy; + if (v2d->keepofs & V2D_LOCKOFS_Y) { + v2d->cur.ymax -= 2*dy; + } + else { + v2d->cur.ymin += dy; + v2d->cur.ymax -= dy; + } } /* validate that view is in valid configuration after this operation */ @@ -1187,15 +1213,8 @@ static int scroller_activate_modal(bContext *C, wmOperator *op, wmEvent *event) static int scroller_activate_invoke(bContext *C, wmOperator *op, wmEvent *event) { ARegion *ar= CTX_wm_region(C); - View2D *v2d= NULL; + View2D *v2d= &ar->v2d; short in_scroller= 0; - - /* firstly, check context to see if mouse is actually in region */ - // XXX isn't this the job of poll() callbacks which can't check events, but only context? - if (ar == NULL) - return OPERATOR_PASS_THROUGH;//OPERATOR_CANCELLED; - else - v2d= &ar->v2d; /* check if mouse in scrollbars, if they're enabled */ in_scroller= UI_view2d_mouse_in_scrollers(C, v2d, event->x, event->y); @@ -1241,6 +1260,70 @@ void VIEW2D_OT_scroller_activate(wmOperatorType *ot) /* api callbacks */ ot->invoke= scroller_activate_invoke; ot->modal= scroller_activate_modal; + ot->poll= view2d_poll; +} + +/* ********************************************************* */ +/* RESET */ + +static int reset_exec(bContext *C, wmOperator *op) +{ + ARegion *ar= CTX_wm_region(C); + View2D *v2d= &ar->v2d; + int winx, winy; + + /* zoom 1.0 */ + winx= (float)(v2d->mask.xmax - v2d->mask.xmin + 1); + winy= (float)(v2d->mask.ymax - v2d->mask.ymin + 1); + + v2d->cur.xmax= v2d->cur.xmin + winx; + v2d->cur.ymax= v2d->cur.ymin + winy; + + /* align */ + if(v2d->align) { + /* posx and negx flags are mutually exclusive, so watch out */ + if ((v2d->align & V2D_ALIGN_NO_POS_X) && !(v2d->align & V2D_ALIGN_NO_NEG_X)) { + v2d->cur.xmax= 0.0f; + v2d->cur.xmin= v2d->winx; + } + else if ((v2d->align & V2D_ALIGN_NO_NEG_X) && !(v2d->align & V2D_ALIGN_NO_POS_X)) { + v2d->cur.xmax= v2d->cur.xmax - v2d->cur.xmin; + v2d->cur.xmin= 0.0f; + } + + /* - posx and negx flags are mutually exclusive, so watch out */ + if ((v2d->align & V2D_ALIGN_NO_POS_Y) && !(v2d->align & V2D_ALIGN_NO_NEG_Y)) { + v2d->cur.ymax= 0.0f; + v2d->cur.ymin= -v2d->winy; + } + else if ((v2d->align & V2D_ALIGN_NO_NEG_Y) && !(v2d->align & V2D_ALIGN_NO_POS_Y)) { + v2d->cur.ymax= v2d->cur.ymax - v2d->cur.ymin; + v2d->cur.ymin= 0.0f; + } + } + + /* validate that view is in valid configuration after this operation */ + UI_view2d_curRect_validate(v2d); + + /* request updates to be done... */ + ED_area_tag_redraw(CTX_wm_area(C)); + UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY); + + return OPERATOR_FINISHED; +} + +void VIEW2D_OT_reset(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Reset View"; + ot->idname= "VIEW2D_OT_reset"; + + /* api callbacks */ + ot->exec= reset_exec; + ot->poll= view2d_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } /* ********************************************************* */ @@ -1262,6 +1345,8 @@ void ui_view2d_operatortypes(void) WM_operatortype_append(VIEW2D_OT_zoom_border); WM_operatortype_append(VIEW2D_OT_scroller_activate); + + WM_operatortype_append(VIEW2D_OT_reset); } void UI_view2d_keymap(wmWindowManager *wm) @@ -1300,12 +1385,15 @@ void UI_view2d_keymap(wmWindowManager *wm) /* scrollers */ WM_keymap_add_item(keymap, "VIEW2D_OT_scroller_activate", LEFTMOUSE, KM_PRESS, 0, 0); - + /* Alternative keymap for buttons listview */ keymap= WM_keymap_listbase(wm, "View2D Buttons List", 0, 0); WM_keymap_add_item(keymap, "VIEW2D_OT_pan", MIDDLEMOUSE, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_down", WHEELDOWNMOUSE, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_up", WHEELUPMOUSE, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "VIEW2D_OT_zoom", MIDDLEMOUSE, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_out", PADMINUS, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_in", PADPLUSKEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "VIEW2D_OT_reset", HOMEKEY, KM_PRESS, 0, 0); } |