diff options
42 files changed, 928 insertions, 1099 deletions
diff --git a/release/ui/buttons_data_camera.py b/release/ui/buttons_data_camera.py index 24006b5e7cc..3bca07c319d 100644 --- a/release/ui/buttons_data_camera.py +++ b/release/ui/buttons_data_camera.py @@ -15,7 +15,7 @@ class DATA_PT_cameralens(DataButtonsPanel): __label__ = "Lens" def draw(self, context): - cam = context.main.cameras[0] + cam = context.active_object.data layout = self.layout if not cam: @@ -55,7 +55,7 @@ class DATA_PT_cameradisplay(DataButtonsPanel): __label__ = "Display" def draw(self, context): - cam = context.main.cameras[0] + cam = context.active_object.data layout = self.layout if not cam: diff --git a/release/ui/buttons_data_curve.py b/release/ui/buttons_data_curve.py index 4d6817d0fe8..a51ce50b047 100644 --- a/release/ui/buttons_data_curve.py +++ b/release/ui/buttons_data_curve.py @@ -33,7 +33,7 @@ class DATA_PT_shape_curve(DataButtonsPanel): sub.itemL(text="Textures:") sub.itemR(curve, "uv_orco") - sub.itemR(curve, "autotexspace") + sub.itemR(curve, "auto_texspace") sub = split.column() sub.itemL(text="Resolution:") diff --git a/release/ui/buttons_data_lamp.py b/release/ui/buttons_data_lamp.py index 9b64748032d..2005481d38b 100644 --- a/release/ui/buttons_data_lamp.py +++ b/release/ui/buttons_data_lamp.py @@ -15,7 +15,7 @@ class DATA_PT_lamp(DataButtonsPanel): __label__ = "Lamp" def draw(self, context): - lamp = context.main.lamps[0] + lamp = context.active_object.data layout = self.layout if not lamp: @@ -61,11 +61,10 @@ class DATA_PT_sunsky(DataButtonsPanel): def poll(self, context): ob = context.active_object - lamp = context.main.lamps[0] - return (ob.type == 'LAMP' and lamp.type == 'SUN') + return (ob.type == 'LAMP' and ob.data.type == 'SUN') def draw(self, context): - lamp = context.main.lamps[0].sky + lamp = context.active_object.data layout = self.layout if not lamp: @@ -107,11 +106,10 @@ class DATA_PT_shadow(DataButtonsPanel): def poll(self, context): ob = context.active_object - lamp = context.main.lamps[0] - return (ob.type == 'LAMP' and lamp.type in ('POINT','SUN', 'SPOT', 'AREA')) + return (ob.type == 'LAMP' and ob.data.type in ('POINT','SUN', 'SPOT', 'AREA')) def draw(self, context): - lamp = context.main.lamps[0] + lamp = context.active_object.data layout = self.layout if not lamp: @@ -190,11 +188,10 @@ class DATA_PT_spot(DataButtonsPanel): def poll(self, context): ob = context.active_object - lamp = context.main.lamps[0] - return (ob.type == 'LAMP' and lamp.type == 'SPOT') + return (ob.type == 'LAMP' and ob.data.type == 'SPOT') def draw(self, context): - lamp = context.main.lamps[0] + lamp = context.active_object.data layout = self.layout if not lamp: diff --git a/release/ui/buttons_data_lattice.py b/release/ui/buttons_data_lattice.py index 0446f3916a1..c7d5b9cfe4a 100644 --- a/release/ui/buttons_data_lattice.py +++ b/release/ui/buttons_data_lattice.py @@ -15,7 +15,7 @@ class DATA_PT_lattice(DataButtonsPanel): __label__ = "Lattice" def draw(self, context): - lat = context.main.lattices[0] + lat = context.active_object.data layout = self.layout if not lat: diff --git a/release/ui/buttons_data_text.py b/release/ui/buttons_data_text.py index 8fbcf083c98..8db1d0316a9 100644 --- a/release/ui/buttons_data_text.py +++ b/release/ui/buttons_data_text.py @@ -32,7 +32,7 @@ class DATA_PT_shape_text(DataButtonsPanel): sub.itemL(text="Textures:") sub.itemR(curve, "uv_orco") - sub.itemR(curve, "autotexspace") + sub.itemR(curve, "auto_texspace") sub = split.column() sub.itemL(text="Resolution:") diff --git a/release/ui/buttons_material.py b/release/ui/buttons_material.py index a80ae8d4624..551a62cfc84 100644 --- a/release/ui/buttons_material.py +++ b/release/ui/buttons_material.py @@ -64,18 +64,20 @@ class MATERIAL_PT_raymir(MaterialButtonsPanel): __idname__= "MATERIAL_PT_raymir" __label__ = "Ray Mirror" + def poll(self, context): + ob = context.active_object + return (ob and ob.active_material) + + def draw_header(self, context): + raym = context.active_object.active_material.raytrace_mirror + + layout = self.layout + layout.itemR(raym, "enabled", text=self.__label__) + def draw(self, context): layout = self.layout - try: - raym = context.active_object.active_material.raytrace_mirror - except: - raym = None - - if not raym: - return - - layout.itemR(raym, "enabled", text="Enable") - + raym = context.active_object.active_material.raytrace_mirror + split = layout.split() sub = split.column() diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h index 4797616a471..9b5d99f6ae6 100644 --- a/source/blender/blenkernel/BKE_screen.h +++ b/source/blender/blenkernel/BKE_screen.h @@ -159,6 +159,8 @@ typedef struct PanelType { /* verify if the panel should draw or not */ int (*poll)(const struct bContext *, struct PanelType *); + /* draw header (optional) */ + void (*draw_header)(const struct bContext *, struct Panel *); /* draw entirely, view changes should be handled here */ void (*draw)(const struct bContext *, struct Panel *); diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 67887769d38..c680c6b3b54 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -5650,7 +5650,6 @@ static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb) { SpaceButs *sbuts= (SpaceButs *)sl; memcpy(&ar->v2d, &sbuts->v2d, sizeof(View2D)); - ar->v2d.keepzoom |= V2D_KEEPASPECT; break; } case SPACE_FILE: diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h index bfa0c680bd6..2484b558b04 100644 --- a/source/blender/editors/include/ED_screen.h +++ b/source/blender/editors/include/ED_screen.h @@ -53,7 +53,9 @@ void ED_region_pixelspace(struct ARegion *ar); void ED_region_init(struct bContext *C, struct ARegion *ar); void ED_region_tag_redraw(struct ARegion *ar); void ED_region_tag_redraw_partial(struct ARegion *ar, struct rcti *rct); +void ED_region_panels_init(struct wmWindowManager *wm, struct ARegion *ar); void ED_region_panels(const struct bContext *C, struct ARegion *ar, int vertical, char *context); +void ED_region_header_init(struct ARegion *ar); void ED_region_header(const struct bContext *C, struct ARegion *ar); /* spaces */ diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 475d77d90f3..dba944ad9b7 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -400,7 +400,7 @@ void uiDefKeyevtButS(uiBlock *block, int retval, char *str, short x1, short y1, void uiBlockPickerButtons(struct uiBlock *block, float *col, float *hsv, float *old, char *hexcol, char mode, short retval); uiBut *uiDefAutoButR(uiBlock *block, struct PointerRNA *ptr, struct PropertyRNA *prop, int index, char *name, int icon, int x1, int y1, int x2, int y2); -int uiDefAutoButsRNA(const struct bContext *C, uiBlock *block, struct PointerRNA *ptr); +void uiDefAutoButsRNA(const struct bContext *C, uiLayout *layout, struct PointerRNA *ptr); /* Links * @@ -462,16 +462,9 @@ void autocomplete_end(AutoComplete *autocpl, char *autoname); void uiBeginPanels(const struct bContext *C, struct ARegion *ar); void uiEndPanels(const struct bContext *C, struct ARegion *ar); -struct Panel *uiBeginPanel(struct ARegion *ar, uiBlock *block, struct PanelType *pt); +struct Panel *uiBeginPanel(struct ARegion *ar, uiBlock *block, struct PanelType *pt, int *open); void uiEndPanel(uiBlock *block, int width, int height); -void uiPanelsHome(struct ARegion *ar); - -/* deprecated */ -extern int uiNewPanel(const struct bContext *C, struct ARegion *ar, uiBlock *block, char *panelname, char *tabname, int ofsx, int ofsy, int sizex, int sizey); -extern void uiNewPanelHeight(struct uiBlock *block, int sizey); -extern void uiNewPanelTitle(struct uiBlock *block, char *str); - /* Handlers * * Handlers that can be registered in regions, areas and windows for @@ -558,6 +551,8 @@ uiLayout *uiLayoutBox(uiLayout *layout); uiLayout *uiLayoutFree(uiLayout *layout, int align); uiLayout *uiLayoutSplit(uiLayout *layout); +uiBlock *uiLayoutFreeBlock(uiLayout *layout); + /* templates */ void uiTemplateHeader(uiLayout *layout, struct bContext *C); void uiTemplateHeaderID(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, char *propname, @@ -573,8 +568,8 @@ void uiItemFloatO(uiLayout *layout, char *name, int icon, char *opname, char *pr void uiItemStringO(uiLayout *layout, char *name, int icon, char *opname, char *propname, char *value); void uiItemFullO(uiLayout *layout, char *name, int icon, char *idname, struct IDProperty *properties, int context); -void uiItemR(uiLayout *layout, char *name, int icon, struct PointerRNA *ptr, char *propname, int expand); -void uiItemFullR(uiLayout *layout, char *name, int icon, struct PointerRNA *ptr, struct PropertyRNA *prop, int index, int value, int expand); +void uiItemR(uiLayout *layout, char *name, int icon, struct PointerRNA *ptr, char *propname, int expand, int slider); +void uiItemFullR(uiLayout *layout, char *name, int icon, struct PointerRNA *ptr, struct PropertyRNA *prop, int index, int value, int expand, int slider); void uiItemEnumR(uiLayout *layout, char *name, int icon, struct PointerRNA *ptr, char *propname, int value); void uiItemsEnumR(uiLayout *layout, struct PointerRNA *ptr, char *propname); diff --git a/source/blender/editors/include/UI_view2d.h b/source/blender/editors/include/UI_view2d.h index 0650a5611dc..7ff312151c5 100644 --- a/source/blender/editors/include/UI_view2d.h +++ b/source/blender/editors/include/UI_view2d.h @@ -54,8 +54,6 @@ enum { V2D_COMMONVIEW_LIST, /* headers (this is basically the same as listview, but no y-panning) */ V2D_COMMONVIEW_HEADER, - /* ui listviews, tries to wrap tot inside region width */ - V2D_COMMONVIEW_LIST_UI, /* ui region containing panels */ V2D_COMMONVIEW_PANELS_UI, } eView2D_CommonViewTypes; 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); } diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c index e344a177517..4920182c16b 100644 --- a/source/blender/editors/screen/area.c +++ b/source/blender/editors/screen/area.c @@ -966,24 +966,29 @@ void ED_region_panels(const bContext *C, ARegion *ar, int vertical, char *contex uiBlock *block; PanelType *pt; Panel *panel; + View2D *v2d= &ar->v2d; float col[3]; - int xco, yco, x, y, w, em, header; + int xco, yco, x, y, miny=0, w, em, header, open; + + if(vertical) { + w= v2d->cur.xmax - v2d->cur.xmin; + em= (ar->type->minsizex)? 10: 20; + } + else { + w= UI_PANEL_WIDTH; + em= (ar->type->minsizex)? 10: 20; + } header= 20; // XXX - x= style->panelouter; - y= -(header + style->panelouter); + x= 0; + y= -style->panelouter; - /* clear */ - UI_GetThemeColor3fv(TH_BACK, col); - glClearColor(col[0], col[1], col[2], 0.0); - glClear(GL_COLOR_BUFFER_BIT); - - /* set view2d view matrix for scrolling (without scrollers) */ - UI_view2d_view_ortho(C, &ar->v2d); - /* create panels */ uiBeginPanels(C, ar); + /* set view2d view matrix for scrolling (without scrollers) */ + UI_view2d_view_ortho(C, v2d); + for(pt= ar->type->paneltypes.first; pt; pt= pt->next) { /* verify context */ if(context) @@ -993,18 +998,25 @@ void ED_region_panels(const bContext *C, ARegion *ar, int vertical, char *contex /* draw panel */ if(pt->draw && (!pt->poll || pt->poll(C, pt))) { block= uiBeginBlock(C, ar, pt->idname, UI_EMBOSS); - panel= uiBeginPanel(ar, block, pt); + panel= uiBeginPanel(ar, block, pt, &open); - if(panel) { - if(vertical) { - w= (ar->type->minsizex)? ar->type->minsizex-12: uiBlockAspect(block)*ar->winx-12; - em= (ar->type->minsizex)? 10: 20; - } - else { - w= (ar->type->minsizex)? ar->type->minsizex-12: UI_PANEL_WIDTH-12; - em= (ar->type->minsizex)? 10: 20; - } + if(vertical) + y -= header; + + /* XXX enable buttons test */ +#if 0 + panel->layout= uiBlockLayout(block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER, + header+style->panelspace, header+style->panelspace, header, 1, style); + + if(pt->draw_header) + pt->draw_header(C, panel); + else + uiItemL(panel->layout, pt->label, 0); + + panel->layout= NULL; +#endif + if(open) { panel->type= pt; panel->layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, style->panelspace, 0, w-2*style->panelspace, em, style); @@ -1012,29 +1024,74 @@ void ED_region_panels(const bContext *C, ARegion *ar, int vertical, char *contex pt->draw(C, panel); uiBlockLayoutResolve(C, block, &xco, &yco); - uiEndPanel(block, w, -yco + 12); panel->layout= NULL; + + yco -= 2*style->panelspace; + uiEndPanel(block, w, -yco); } - else { - w= header; - yco= header; - } + else + yco= 0; uiEndBlock(C, block); - if(vertical) - y += yco+style->panelouter; - else - x += w+style->panelouter; + if(vertical) { + y += yco-style->panelouter; + } + else { + x += w; + miny= MIN2(y, yco-style->panelouter-header); + } } } + if(vertical) + x += w; + else + y= miny; + + /* in case there are no panels */ + if(x == 0 || y == 0) { + x= UI_PANEL_WIDTH; + y= UI_PANEL_WIDTH; + } + + /* clear */ + UI_GetThemeColor3fv(TH_BACK, col); + glClearColor(col[0], col[1], col[2], 0.0); + glClear(GL_COLOR_BUFFER_BIT); + + /* before setting the view */ + if(vertical) { + v2d->keepofs |= V2D_LOCKOFS_X; + v2d->keepofs &= ~V2D_LOCKOFS_Y; + } + else { + v2d->keepofs &= ~V2D_LOCKOFS_X; + v2d->keepofs |= V2D_LOCKOFS_Y; + } + + UI_view2d_totRect_set(v2d, x, -y); + + /* set the view */ + UI_view2d_view_ortho(C, v2d); + + /* this does the actual drawing! */ uiEndPanels(C, ar); - /* restore view matrix? */ + /* restore view matrix */ UI_view2d_view_restore(C); } +void ED_region_panels_init(wmWindowManager *wm, ARegion *ar) +{ + ListBase *keymap; + + UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_PANELS_UI, ar->winx, ar->winy); + + keymap= WM_keymap_listbase(wm, "View2D Buttons List", 0, 0); + WM_event_add_keymap_handler(&ar->handlers, keymap); +} + void ED_region_header(const bContext *C, ARegion *ar) { uiStyle *style= U.uistyles.first; @@ -1083,3 +1140,9 @@ void ED_region_header(const bContext *C, ARegion *ar) UI_view2d_view_restore(C); } +void ED_region_header_init(ARegion *ar) +{ + UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy); + ar->v2d.flag &= ~(V2D_PIXELOFS_X|V2D_PIXELOFS_Y); // XXX temporary +} + diff --git a/source/blender/editors/space_buttons/buttons_header.c b/source/blender/editors/space_buttons/buttons_header.c index 91b88ad5b1b..83586986e23 100644 --- a/source/blender/editors/space_buttons/buttons_header.c +++ b/source/blender/editors/space_buttons/buttons_header.c @@ -68,12 +68,10 @@ static void do_viewmenu(bContext *C, void *arg, int event) ScrArea *sa= CTX_wm_area(C); switch(event) { - case 0: /* panel alignment */ case 1: case 2: sbuts->align= event; - if(sbuts->align) - sbuts->re_align= 1; + sbuts->re_align= 1; break; } @@ -96,9 +94,6 @@ static uiBlock *dummy_viewmenu(bContext *C, ARegion *ar, void *arg_unused) if (sbuts->align == 2) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Vertical", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, ""); else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Vertical", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, ""); - if (sbuts->align == 0) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Free", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, ""); - else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Free", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, ""); - if(sa->headertype==HEADERTOP) { uiBlockSetDirection(block, UI_DOWN); } @@ -151,7 +146,7 @@ void buttons_header_buttons(const bContext *C, ARegion *ar) uiDefPulldownBut(block, dummy_viewmenu, CTX_wm_area(C), "View", xco, yco, xmax-3, 20, ""); - xco+=XIC+xmax; + xco+=xmax; } // DATA Icons if(ob) { diff --git a/source/blender/editors/space_buttons/space_buttons.c b/source/blender/editors/space_buttons/space_buttons.c index 785f0d0b89b..9f5e0f5974a 100644 --- a/source/blender/editors/space_buttons/space_buttons.c +++ b/source/blender/editors/space_buttons/space_buttons.c @@ -132,7 +132,7 @@ static void buttons_init(struct wmWindowManager *wm, ScrArea *sa) SpaceButs *sbuts= sa->spacedata.first; /* auto-align based on size */ - if(sbuts->align == BUT_AUTO) { + if(sbuts->align == BUT_AUTO || !sbuts->align) { if(sa->winx > sa->winy) sbuts->align= BUT_HORIZONTAL; else @@ -155,8 +155,7 @@ static void buttons_main_area_init(wmWindowManager *wm, ARegion *ar) { ListBase *keymap; -// ar->v2d.minzoom= ar->v2d.maxzoom= 1.0f; - UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_PANELS_UI, ar->winx, ar->winy); + ED_region_panels_init(wm, ar); /* own keymap */ keymap= WM_keymap_listbase(wm, "Buttons", SPACE_BUTS, 0); /* XXX weak? */ @@ -280,7 +279,7 @@ void ED_spacetype_buttons(void) art->init= buttons_main_area_init; art->draw= buttons_main_area_draw; art->listener= buttons_area_listener; - art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_FRAMES; + art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_FRAMES; BLI_addhead(&st->regiontypes, art); /* regions: header */ diff --git a/source/blender/editors/space_graph/graph_buttons.c b/source/blender/editors/space_graph/graph_buttons.c index 16628f31b63..a4babaad74c 100644 --- a/source/blender/editors/space_graph/graph_buttons.c +++ b/source/blender/editors/space_graph/graph_buttons.c @@ -104,18 +104,49 @@ static void do_graph_region_buttons(bContext *C, void *arg, int event) //WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, ob); } -static void graph_panel_properties(const bContext *C, ARegion *ar, short cntrl, bAnimListElem *ale) +static int graph_panel_context(const bContext *C, bAnimListElem **ale, FCurve **fcu) { - FCurve *fcu= (FCurve *)ale->data; + bAnimContext ac; + bAnimListElem *elem= NULL; + + /* for now, only draw if we could init the anim-context info (necessary for all animation-related tools) + * to work correctly is able to be correctly retrieved. There's no point showing empty panels? + */ + if (ANIM_animdata_get_context(C, &ac) == 0) + return 0; + + /* try to find 'active' F-Curve */ + elem= get_active_fcurve_channel(&ac); + if(elem == NULL) + return 0; + + if(fcu) + *fcu= (FCurve*)elem->data; + if(ale) + *ale= elem; + else + MEM_freeN(elem); + + return 1; +} + +static int graph_panel_poll(const bContext *C, PanelType *pt) +{ + return graph_panel_context(C, NULL, NULL); +} + +static void graph_panel_properties(const bContext *C, Panel *pa) +{ + bAnimListElem *ale; + FCurve *fcu; uiBlock *block; char name[128]; - block= uiBeginBlock(C, ar, "graph_panel_properties", UI_EMBOSS); - if (uiNewPanel(C, ar, block, "Properties", "Graph", 340, 30, 318, 254)==0) return; - uiBlockSetHandleFunc(block, do_graph_region_buttons, NULL); + if(!graph_panel_context(C, &ale, &fcu)) + return; - /* to force height */ - uiNewPanelHeight(block, 204); + block= uiLayoutFreeBlock(pa->layout); + uiBlockSetHandleFunc(block, do_graph_region_buttons, NULL); /* Info - Active F-Curve */ uiDefBut(block, LABEL, 1, "Active F-Curve:", 10, 200, 150, 19, NULL, 0.0, 0.0, 0, 0, ""); @@ -136,6 +167,8 @@ static void graph_panel_properties(const bContext *C, ARegion *ar, short cntrl, * - Access details (ID-block + RNA-Path + Array Index) * - ... */ + + MEM_freeN(ale); } /* ******************* drivers ******************************** */ @@ -206,11 +239,23 @@ static void driver_update_flags_cb (bContext *C, void *fcu_v, void *dummy_v) driver->flag &= ~DRIVER_FLAG_INVALID; } +/* drivers panel poll */ +static int graph_panel_drivers_poll(const bContext *C, PanelType *pt) +{ + SpaceIpo *sipo= (SpaceIpo *)CTX_wm_space_data(C); + + if(sipo->mode != SIPO_MODE_DRIVERS) + return 0; + + return graph_panel_context(C, NULL, NULL); +} -static void graph_panel_drivers(const bContext *C, ARegion *ar, short cntrl, bAnimListElem *ale) +/* driver settings for active F-Curve (only for 'Drivers' mode) */ +static void graph_panel_drivers(const bContext *C, Panel *pa) { - FCurve *fcu= (FCurve *)ale->data; - ChannelDriver *driver= fcu->driver; + bAnimListElem *ale; + FCurve *fcu; + ChannelDriver *driver; DriverTarget *dtar; PointerRNA rna_ptr; @@ -218,12 +263,13 @@ static void graph_panel_drivers(const bContext *C, ARegion *ar, short cntrl, bAn uiBut *but; int yco=85, i=0; - block= uiBeginBlock(C, ar, "graph_panel_drivers", UI_EMBOSS); - if (uiNewPanel(C, ar, block, "Drivers", "Graph", 340, 30, 318, 254)==0) return; - uiBlockSetHandleFunc(block, do_graph_region_driver_buttons, NULL); + if(!graph_panel_context(C, &ale, &fcu)) + return; - /* to force height */ - uiNewPanelHeight(block, 204); + driver= fcu->driver; + + block= uiLayoutFreeBlock(pa->layout); + uiBlockSetHandleFunc(block, do_graph_region_driver_buttons, NULL); /* general actions */ but= uiDefBut(block, BUT, B_IPO_DEPCHANGE, "Update Dependencies", 10, 200, 180, 22, NULL, 0.0, 0.0, 0, 0, "Force updates of dependencies"); @@ -296,12 +342,8 @@ static void graph_panel_drivers(const bContext *C, ARegion *ar, short cntrl, bAn yco -= height; i++; } - - /* since these buttons can have variable height */ - if (yco < 0) - uiNewPanelHeight(block, (204 - yco)); - else - uiNewPanelHeight(block, 204); + + MEM_freeN(ale); } /* ******************* f-modifiers ******************************** */ @@ -928,18 +970,19 @@ static void graph_panel_modifier_draw(uiBlock *block, FCurve *fcu, FModifier *fc (*yco) -= (height + 27); } -static void graph_panel_modifiers(const bContext *C, ARegion *ar, short cntrl, bAnimListElem *ale) +static void graph_panel_modifiers(const bContext *C, Panel *pa) { - FCurve *fcu= (FCurve *)ale->data; + bAnimListElem *ale; + FCurve *fcu; FModifier *fcm; uiBlock *block; int yco= 190; - block= uiBeginBlock(C, ar, "graph_panel_modifiers", UI_EMBOSS); - if (uiNewPanel(C, ar, block, "Modifiers", "Graph", 340, 30, 318, 254)==0) return; - uiBlockSetHandleFunc(block, do_graph_region_modifier_buttons, NULL); + if(!graph_panel_context(C, &ale, &fcu)) + return; - uiNewPanelHeight(block, 204); + block= uiLayoutFreeBlock(pa->layout); + uiBlockSetHandleFunc(block, do_graph_region_modifier_buttons, NULL); /* 'add modifier' button at top of panel */ // XXX for now, this will be a operator button which calls a temporary 'add modifier' operator @@ -948,12 +991,8 @@ static void graph_panel_modifiers(const bContext *C, ARegion *ar, short cntrl, b /* draw each modifier */ for (fcm= fcu->modifiers.first; fcm; fcm= fcm->next) graph_panel_modifier_draw(block, fcu, fcm, &yco); - - /* since these buttons can have variable height */ - if (yco < 0) - uiNewPanelHeight(block, (204 - yco)); - else - uiNewPanelHeight(block, 204); + + MEM_freeN(ale); } /* ******************* general ******************************** */ @@ -986,44 +1025,32 @@ bAnimListElem *get_active_fcurve_channel (bAnimContext *ac) return NULL; } -void graph_region_buttons(const bContext *C, ARegion *ar) +void graph_buttons_register(ARegionType *art) { - SpaceIpo *sipo= (SpaceIpo *)CTX_wm_space_data(C); - bAnimContext ac; - bAnimListElem *ale= NULL; - - /* for now, only draw if we could init the anim-context info (necessary for all animation-related tools) - * to work correctly is able to be correctly retrieved. There's no point showing empty panels? - */ - if (ANIM_animdata_get_context(C, &ac) == 0) - return; - - - /* try to find 'active' F-Curve */ - ale= get_active_fcurve_channel(&ac); - if (ale == NULL) - return; - - uiBeginPanels(C, ar); - - /* for now, the properties panel displays info about the selected channels */ - graph_panel_properties(C, ar, 0, ale); - - /* driver settings for active F-Curve (only for 'Drivers' mode) */ - if (sipo->mode == SIPO_MODE_DRIVERS) - graph_panel_drivers(C, ar, 0, ale); - - /* modifiers */ - graph_panel_modifiers(C, ar, 0, ale); - - - uiEndPanels(C, ar); - - /* free temp data */ - MEM_freeN(ale); + PanelType *pt; + + pt= MEM_callocN(sizeof(PanelType), "spacetype graph panel properties"); + strcpy(pt->idname, "GRAPH_PT_properties"); + strcpy(pt->label, "Properties"); + pt->draw= graph_panel_properties; + pt->poll= graph_panel_poll; + BLI_addtail(&art->paneltypes, pt); + + pt= MEM_callocN(sizeof(PanelType), "spacetype graph panel drivers"); + strcpy(pt->idname, "GRAPH_PT_drivers"); + strcpy(pt->label, "Drivers"); + pt->draw= graph_panel_drivers; + pt->poll= graph_panel_drivers_poll; + BLI_addtail(&art->paneltypes, pt); + + pt= MEM_callocN(sizeof(PanelType), "spacetype graph panel modifiers"); + strcpy(pt->idname, "GRAPH_PT_modifiers"); + strcpy(pt->label, "Modifiers"); + pt->draw= graph_panel_modifiers; + pt->poll= graph_panel_poll; + BLI_addtail(&art->paneltypes, pt); } - static int graph_properties(bContext *C, wmOperator *op) { ScrArea *sa= CTX_wm_area(C); diff --git a/source/blender/editors/space_graph/graph_intern.h b/source/blender/editors/space_graph/graph_intern.h index a06cdddbec8..7ba636302a5 100644 --- a/source/blender/editors/space_graph/graph_intern.h +++ b/source/blender/editors/space_graph/graph_intern.h @@ -35,6 +35,7 @@ struct bAnimListElem; struct SpaceIpo; struct ScrArea; struct ARegion; +struct ARegionType; struct View2DGrid; /* internal exports only */ @@ -137,7 +138,7 @@ void GRAPHEDIT_OT_ghost_curves_clear(struct wmOperatorType *ot); /* ***************************************** */ /* graph_buttons.c */ void GRAPHEDIT_OT_properties(struct wmOperatorType *ot); -void graph_region_buttons(const struct bContext *C, struct ARegion *ar); +void graph_buttons_register(struct ARegionType *art); struct bAnimListElem *get_active_fcurve_channel(struct bAnimContext *ac); diff --git a/source/blender/editors/space_graph/space_graph.c b/source/blender/editors/space_graph/space_graph.c index 66ebc145621..74002f64187 100644 --- a/source/blender/editors/space_graph/space_graph.c +++ b/source/blender/editors/space_graph/space_graph.c @@ -346,34 +346,17 @@ static void graph_buttons_area_init(wmWindowManager *wm, ARegion *ar) { ListBase *keymap; - UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_LIST_UI, ar->winx, ar->winy); + ED_region_panels_init(wm, ar); - keymap= WM_keymap_listbase(wm, "View2D Buttons List", 0, 0); - WM_event_add_keymap_handler(&ar->handlers, keymap); keymap= WM_keymap_listbase(wm, "GraphEdit Generic", SPACE_IPO, 0); WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); } static void graph_buttons_area_draw(const bContext *C, ARegion *ar) { - float col[3]; - - /* clear */ - UI_GetThemeColor3fv(TH_BACK, col); - - glClearColor(col[0], col[1], col[2], 0.0); - glClear(GL_COLOR_BUFFER_BIT); - - /* set view2d view matrix for scrolling (without scrollers) */ - UI_view2d_view_ortho(C, &ar->v2d); - - graph_region_buttons(C, ar); - - /* restore view matrix? */ - UI_view2d_view_restore(C); + ED_region_panels(C, ar, 1, NULL); } - static void graph_region_listener(ARegion *ar, wmNotifier *wmn) { /* context changes */ @@ -586,6 +569,8 @@ void ED_spacetype_ipo(void) art->draw= graph_buttons_area_draw; BLI_addhead(&st->regiontypes, art); + + graph_buttons_register(art); BKE_spacetype_register(st); } diff --git a/source/blender/editors/space_image/image_panels.c b/source/blender/editors/space_image/image_buttons.c index 971f3a70a8a..35004a4bdef 100644 --- a/source/blender/editors/space_image/image_panels.c +++ b/source/blender/editors/space_image/image_buttons.c @@ -383,15 +383,13 @@ static void image_editcursor_buts(const bContext *C, View2D *v2d, uiBlock *block } } -static void image_panel_game_properties(const bContext *C, ARegion *ar) +static void image_panel_game_properties(const bContext *C, Panel *pa) { SpaceImage *sima= (SpaceImage*)CTX_wm_space_data(C); ImBuf *ibuf= BKE_image_get_ibuf(sima->image, &sima->iuser); uiBlock *block; - block= uiBeginBlock(C, ar, "image_panel_game_properties", UI_EMBOSS); - if(uiNewPanel(C, ar, block, "Real-time Properties", "Image", 10, 10, 318, 204)==0) - return; + block= uiLayoutFreeBlock(pa->layout); uiBlockSetHandleFunc(block, do_image_panel_events, NULL); if (ibuf) { @@ -420,15 +418,14 @@ static void image_panel_game_properties(const bContext *C, ARegion *ar) } } -static void image_panel_view_properties(const bContext *C, ARegion *ar) +static void image_panel_view_properties(const bContext *C, Panel *pa) { SpaceImage *sima= (SpaceImage*)CTX_wm_space_data(C); + ARegion *ar= CTX_wm_region(C); Object *obedit= CTX_data_edit_object(C); uiBlock *block; - block= uiBeginBlock(C, ar, "image_view_properties", UI_EMBOSS); - if(uiNewPanel(C, ar, block, "View Properties", "Image", 10, 30, 318, 204)==0) - return; + block= uiLayoutFreeBlock(pa->layout); uiBlockSetHandleFunc(block, do_image_panel_events, NULL); uiDefButBitI(block, TOG, SI_DRAW_TILE, B_REDR, "Repeat Image", 10,160,140,19, &sima->flag, 0, 0, 0, 0, "Repeat/Tile the image display"); @@ -599,7 +596,14 @@ void brush_buttons(const bContext *C, uiBlock *block, short fromsima, #endif } -static void image_panel_paintcolor(const bContext *C, ARegion *ar) +static int image_panel_paint_poll(const bContext *C, PanelType *pt) +{ + SpaceImage *sima= (SpaceImage*)CTX_wm_space_data(C); + + return (sima->image && (sima->flag & SI_DRAWTOOL)); +} + +static void image_panel_paintcolor(const bContext *C, Panel *pa) { SpaceImage *sima= (SpaceImage*)CTX_wm_space_data(C); ToolSettings *settings= CTX_data_tool_settings(C); @@ -608,37 +612,26 @@ static void image_panel_paintcolor(const bContext *C, ARegion *ar) static float hsv[3], old[3]; // used as temp mem for picker static char hexcol[128]; - block= uiBeginBlock(C, ar, "image_panel_paintcolor", UI_EMBOSS); - uiBlockSetHandleFunc(block, do_image_panel_events, NULL); - if(uiNewPanel(C, ar, block, "Paint Color", "Image", 10, 22, 318, 204)==0) + if(!sima->image || (sima->flag & SI_DRAWTOOL)==0) return; - if ( (brush && sima->image && (sima->flag & SI_DRAWTOOL))==0) { - uiNewPanelHeight(block, 0); - return; - } - uiNewPanelHeight(block, 204); - - uiBlockPickerButtons(block, brush->rgb, hsv, old, hexcol, 'f', B_REDR); -} - + block= uiLayoutFreeBlock(pa->layout); + uiBlockSetHandleFunc(block, do_image_panel_events, NULL); + if(brush) + uiBlockPickerButtons(block, brush->rgb, hsv, old, hexcol, 'f', B_REDR); +} -static void image_panel_paint(const bContext *C, ARegion *ar) +static void image_panel_paint(const bContext *C, Panel *pa) { SpaceImage *sima= (SpaceImage*)CTX_wm_space_data(C); uiBlock *block; - block= uiBeginBlock(C, ar, "image_panel_paint", UI_EMBOSS); - uiBlockSetHandleFunc(block, do_image_panel_events, NULL); - if(uiNewPanel(C, ar, block, "Image Paint", "Image", 10, 20, 318, 204)==0) + if(!sima->image || (sima->flag & SI_DRAWTOOL)==0) return; - if ((sima->image && (sima->flag & SI_DRAWTOOL))==0) { - uiNewPanelHeight(block, 0); - return; - } - uiNewPanelHeight(block, 204); + block= uiLayoutFreeBlock(pa->layout); + uiBlockSetHandleFunc(block, do_image_panel_events, NULL); brush_buttons(C, block, 1, B_SIMANOTHING, B_SIMABRUSHCHANGE, B_SIMABRUSHBROWSE, B_SIMABRUSHLOCAL, B_SIMABRUSHDELETE, B_KEEPDATA, B_SIMABTEXBROWSE, B_SIMABTEXDELETE); } @@ -663,7 +656,7 @@ static void image_panel_curves_reset(bContext *C, void *cumap_v, void *ibuf_v) } -static void image_panel_curves(const bContext *C, ARegion *ar) +static void image_panel_curves(const bContext *C, Panel *pa) { SpaceImage *sima= (SpaceImage*)CTX_wm_space_data(C); ImBuf *ibuf; @@ -673,9 +666,7 @@ static void image_panel_curves(const bContext *C, ARegion *ar) /* and we check for spare */ ibuf= ED_space_image_buffer(sima); - block= uiBeginBlock(C, ar, "image_panel_curves", UI_EMBOSS); - if(uiNewPanel(C, ar, block, "Curves", "Image", 10, 40, 318, 204)==0) - return; + block= uiLayoutFreeBlock(pa->layout); uiBlockSetHandleFunc(block, do_image_panel_events, NULL); if (ibuf) { @@ -1398,40 +1389,62 @@ void ED_image_uiblock_panel(const bContext *C, uiBlock *block, Image **ima_pp, I } -static void image_panel_properties(const bContext *C, ARegion *ar) +static void image_panel_properties(const bContext *C, Panel *pa) { SpaceImage *sima= (SpaceImage*)CTX_wm_space_data(C); uiBlock *block; - block= uiBeginBlock(C, ar, "image_panel_properties", UI_EMBOSS); - if(uiNewPanel(C, ar, block, "Image Properties", "Image", 10, 50, 318, 204)==0) - return; + block= uiLayoutFreeBlock(pa->layout); uiBlockSetHandleFunc(block, do_image_panel_events, NULL); /* note, it draws no bottom half in facemode, for vertex buttons */ ED_image_uiblock_panel(C, block, &sima->image, &sima->iuser, B_REDR, B_REDR); image_editvertex_buts(C, block); - - uiEndBlock(C, block); } - - -void image_buttons_area_defbuts(const bContext *C, ARegion *ar) +void image_buttons_register(ARegionType *art) { - uiBeginPanels(C, ar); - - image_panel_properties(C, ar); - image_panel_game_properties(C, ar); - image_panel_view_properties(C, ar); - image_panel_paint(C, ar); - image_panel_paintcolor(C, ar); - image_panel_curves(C, ar); - - uiEndPanels(C, ar); + PanelType *pt; + + pt= MEM_callocN(sizeof(PanelType), "spacetype image panel properties"); + strcpy(pt->idname, "IMAGE_PT_properties"); + strcpy(pt->label, "Image Properties"); + pt->draw= image_panel_properties; + BLI_addtail(&art->paneltypes, pt); + + pt= MEM_callocN(sizeof(PanelType), "spacetype image panel game properties"); + strcpy(pt->idname, "IMAGE_PT_game_properties"); + strcpy(pt->label, "Game Properties"); + pt->draw= image_panel_game_properties; + BLI_addtail(&art->paneltypes, pt); + + pt= MEM_callocN(sizeof(PanelType), "spacetype image view properties"); + strcpy(pt->idname, "IMAGE_PT_view_properties"); + strcpy(pt->label, "View Properties"); + pt->draw= image_panel_view_properties; + BLI_addtail(&art->paneltypes, pt); + + pt= MEM_callocN(sizeof(PanelType), "spacetype image panel paint"); + strcpy(pt->idname, "IMAGE_PT_paint"); + strcpy(pt->label, "Paint"); + pt->draw= image_panel_paint; + pt->poll= image_panel_paint_poll; + BLI_addtail(&art->paneltypes, pt); + + pt= MEM_callocN(sizeof(PanelType), "spacetype image panel paint color"); + strcpy(pt->idname, "IMAGE_PT_paint_color"); + strcpy(pt->label, "Paint Color"); + pt->draw= image_panel_paintcolor; + pt->poll= image_panel_paint_poll; + BLI_addtail(&art->paneltypes, pt); + + pt= MEM_callocN(sizeof(PanelType), "spacetype image panel curves"); + strcpy(pt->idname, "IMAGE_PT_curves"); + strcpy(pt->label, "Curves"); + pt->draw= image_panel_curves; + BLI_addtail(&art->paneltypes, pt); } - static int image_properties(bContext *C, wmOperator *op) { ScrArea *sa= CTX_wm_area(C); diff --git a/source/blender/editors/space_image/image_header.c b/source/blender/editors/space_image/image_header.c index 7a28499009b..2accef990d3 100644 --- a/source/blender/editors/space_image/image_header.c +++ b/source/blender/editors/space_image/image_header.c @@ -150,8 +150,8 @@ static void image_viewmenu(bContext *C, uiLayout *layout, void *arg_unused) uiItemS(layout); - uiItemR(layout, NULL, 0, &spaceptr, "update_automatically", 0); - // XXX if(show_uvedit) uiItemR(layout, NULL, 0, &uvptr, "local_view", 0); // "UV Local View", Numpad / + uiItemR(layout, NULL, 0, &spaceptr, "update_automatically", 0, 0); + // XXX if(show_uvedit) uiItemR(layout, NULL, 0, &uvptr, "local_view", 0, 0); // "UV Local View", Numpad / uiItemS(layout); @@ -234,7 +234,7 @@ static void image_imagemenu(bContext *C, uiLayout *layout, void *arg_unused) uiItemS(layout); - uiItemR(layout, NULL, 0, &spaceptr, "image_painting", 0); + uiItemR(layout, NULL, 0, &spaceptr, "image_painting", 0, 0); /* move to realtime properties panel */ RNA_id_pointer_create(&ima->id, &imaptr); @@ -338,12 +338,12 @@ static void image_uvsmenu(bContext *C, uiLayout *layout, void *arg_unused) RNA_id_pointer_create(&scene->id, &sceneptr); /* create menu */ - uiItemR(layout, NULL, 0, &uvptr, "snap_to_pixels", 0); - uiItemR(layout, NULL, 0, &uvptr, "constrain_to_image_bounds", 0); + uiItemR(layout, NULL, 0, &uvptr, "snap_to_pixels", 0, 0); + uiItemR(layout, NULL, 0, &uvptr, "constrain_to_image_bounds", 0, 0); uiItemS(layout); - uiItemR(layout, NULL, 0, &uvptr, "live_unwrap", 0); + uiItemR(layout, NULL, 0, &uvptr, "live_unwrap", 0, 0); uiItemO(layout, NULL, 0, "UV_OT_unwrap"); uiItemBooleanO(layout, "Unpin", 0, "UV_OT_pin", "clear", 1); uiItemO(layout, NULL, 0, "UV_OT_pin"); @@ -363,7 +363,7 @@ static void image_uvsmenu(bContext *C, uiLayout *layout, void *arg_unused) uiItemS(layout); - uiItemR(layout, NULL, 0, &sceneptr, "proportional_editing", 0); + uiItemR(layout, NULL, 0, &sceneptr, "proportional_editing", 0, 0); uiItemMenuEnumR(layout, NULL, 0, &sceneptr, "proportional_editing_falloff"); uiItemS(layout); diff --git a/source/blender/editors/space_image/image_intern.h b/source/blender/editors/space_image/image_intern.h index c592e2cb004..aa97e339c68 100644 --- a/source/blender/editors/space_image/image_intern.h +++ b/source/blender/editors/space_image/image_intern.h @@ -32,6 +32,7 @@ /* internal exports only */ struct bContext; struct ARegion; +struct ARegionType; struct ScrArea; struct SpaceImage; struct Object; @@ -84,7 +85,7 @@ void draw_uvedit_main(struct SpaceImage *sima, struct ARegion *ar, struct Scene /* image_panels.c */ struct ImageUser *ntree_get_active_iuser(struct bNodeTree *ntree); -void image_buttons_area_defbuts(const struct bContext *C, struct ARegion *ar); +void image_buttons_register(struct ARegionType *art); void IMAGE_OT_properties(struct wmOperatorType *ot); #endif /* ED_IMAGE_INTERN_H */ diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c index 5f743afd65d..c82018a3aac 100644 --- a/source/blender/editors/space_image/space_image.c +++ b/source/blender/editors/space_image/space_image.c @@ -483,32 +483,16 @@ static void image_main_area_listener(ARegion *ar, wmNotifier *wmn) static void image_buttons_area_init(wmWindowManager *wm, ARegion *ar) { ListBase *keymap; + + ED_region_panels_init(wm, ar); - keymap= WM_keymap_listbase(wm, "View2D Buttons List", 0, 0); - WM_event_add_keymap_handler(&ar->handlers, keymap); keymap= WM_keymap_listbase(wm, "Image Generic", SPACE_IMAGE, 0); WM_event_add_keymap_handler(&ar->handlers, keymap); - - UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_LIST_UI, ar->winx, ar->winy); } static void image_buttons_area_draw(const bContext *C, ARegion *ar) { - float col[3]; - - /* clear */ - UI_GetThemeColor3fv(TH_PANEL, col); - - glClearColor(col[0], col[1], col[2], 0.0); - glClear(GL_COLOR_BUFFER_BIT); - - /* set view2d view matrix for scrolling (without scrollers) */ - UI_view2d_view_ortho(C, &ar->v2d); - - image_buttons_area_defbuts(C, ar); - - /* restore view matrix? */ - UI_view2d_view_restore(C); + ED_region_panels(C, ar, 1, NULL); } static void image_buttons_area_listener(ARegion *ar, wmNotifier *wmn) @@ -590,6 +574,8 @@ void ED_spacetype_image(void) art->draw= image_buttons_area_draw; BLI_addhead(&st->regiontypes, art); + image_buttons_register(art); + /* regions: header */ art= MEM_callocN(sizeof(ARegionType), "spacetype image region"); art->regionid = RGN_TYPE_HEADER; diff --git a/source/blender/editors/space_text/space_text.c b/source/blender/editors/space_text/space_text.c index 33fa85dbb5d..384ad3e919c 100644 --- a/source/blender/editors/space_text/space_text.c +++ b/source/blender/editors/space_text/space_text.c @@ -348,8 +348,7 @@ static void text_cursor(wmWindow *win, ScrArea *sa, ARegion *ar) /* add handlers, stuff you only do once or on area/region changes */ static void text_header_area_init(wmWindowManager *wm, ARegion *ar) { - UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy); - ar->v2d.flag &= ~(V2D_PIXELOFS_X|V2D_PIXELOFS_Y); // XXX temporary + ED_region_header_init(ar); } static void text_header_area_draw(const bContext *C, ARegion *ar) @@ -362,7 +361,7 @@ static void text_header_area_draw(const bContext *C, ARegion *ar) /* add handlers, stuff you only do once or on area/region changes */ static void text_properties_area_init(wmWindowManager *wm, ARegion *ar) { - UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_PANELS_UI, ar->winx, ar->winy); + ED_region_panels_init(wm, ar); } static void text_properties_area_draw(const bContext *C, ARegion *ar) diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c index 9ed7dd50d2e..3b3fd5109cf 100644 --- a/source/blender/editors/space_view3d/space_view3d.c +++ b/source/blender/editors/space_view3d/space_view3d.c @@ -487,32 +487,16 @@ static void view3d_header_area_listener(ARegion *ar, wmNotifier *wmn) static void view3d_buttons_area_init(wmWindowManager *wm, ARegion *ar) { ListBase *keymap; + + ED_region_panels_init(wm, ar); - keymap= WM_keymap_listbase(wm, "View2D Buttons List", 0, 0); - WM_event_add_keymap_handler(&ar->handlers, keymap); keymap= WM_keymap_listbase(wm, "View3D Generic", SPACE_VIEW3D, 0); WM_event_add_keymap_handler(&ar->handlers, keymap); - - UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_LIST_UI, ar->winx, ar->winy); } static void view3d_buttons_area_draw(const bContext *C, ARegion *ar) { - float col[3]; - - /* clear */ - UI_GetThemeColor3fv(TH_BACK, col); - - glClearColor(col[0], col[1], col[2], 0.0); - glClear(GL_COLOR_BUFFER_BIT); - - /* set view2d view matrix for scrolling (without scrollers) */ - UI_view2d_view_ortho(C, &ar->v2d); - - view3d_buttons_area_defbuts(C, ar); - - /* restore view matrix? */ - UI_view2d_view_restore(C); + ED_region_panels(C, ar, 1, NULL); } static void view3d_buttons_area_listener(ARegion *ar, wmNotifier *wmn) @@ -549,35 +533,17 @@ static void view3d_tools_area_init(wmWindowManager *wm, ARegion *ar) { ListBase *keymap; - keymap= WM_keymap_listbase(wm, "View2D Buttons List", 0, 0); - WM_event_add_keymap_handler(&ar->handlers, keymap); + ED_region_panels_init(wm, ar); + keymap= WM_keymap_listbase(wm, "View3D Generic", SPACE_VIEW3D, 0); WM_event_add_keymap_handler(&ar->handlers, keymap); - // XXX +20 temp... need init for this - UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_PANELS_UI, ar->winx+20, ar->winy); } - static void view3d_tools_area_draw(const bContext *C, ARegion *ar) { - float col[3]; - - /* clear */ - UI_GetThemeColor3fv(TH_BACK, col); - - glClearColor(col[0], col[1], col[2], 0.0); - glClear(GL_COLOR_BUFFER_BIT); - - /* set view2d view matrix for scrolling (without scrollers) */ - UI_view2d_view_ortho(C, &ar->v2d); - - view3d_tools_area_defbuts(C, ar); - - /* restore view matrix? */ - UI_view2d_view_restore(C); + ED_region_panels(C, ar, 1, NULL); } - /* * Returns true if the Object is a from an external blend file (libdata) */ @@ -850,6 +816,8 @@ void ED_spacetype_view3d(void) art->draw= view3d_buttons_area_draw; BLI_addhead(&st->regiontypes, art); + view3d_buttons_register(art); + /* regions: tool(bar) */ art= MEM_callocN(sizeof(ARegionType), "spacetype view3d region"); art->regionid = RGN_TYPE_TOOLS; @@ -861,6 +829,7 @@ void ED_spacetype_view3d(void) art->draw= view3d_tools_area_draw; BLI_addhead(&st->regiontypes, art); + view3d_toolbar_register(art); /* regions: header */ art= MEM_callocN(sizeof(ARegionType), "spacetype view3d region"); diff --git a/source/blender/editors/space_view3d/view3d_buttons.c b/source/blender/editors/space_view3d/view3d_buttons.c index 5dad3f8cc7d..95abb4d59a5 100644 --- a/source/blender/editors/space_view3d/view3d_buttons.c +++ b/source/blender/editors/space_view3d/view3d_buttons.c @@ -947,7 +947,7 @@ void selectTransformOrientation_func(bContext *C, void *target, void *unused) BIF_selectTransformOrientation(C, (TransformOrientation *) target); } -static void view3d_panel_transform_spaces(const bContext *C, ARegion *ar, short cntrl) +static void view3d_panel_transform_spaces(const bContext *C, Panel *pa) { Scene *scene= CTX_data_scene(C); Object *obedit= CTX_data_edit_object(C); @@ -956,13 +956,10 @@ static void view3d_panel_transform_spaces(const bContext *C, ARegion *ar, short TransformOrientation *ts = transform_spaces->first; uiBlock *block; uiBut *but; - int xco = 20, yco = 70, height = 140; + int xco = 20, yco = 70; int index; - block= uiBeginBlock(C, ar, "view3d_panel_transform", UI_EMBOSS); - if(uiNewPanel(C, ar, block, "Transform Orientations", "View3d", 1000, 0, 318, height)==0) return; - - uiNewPanelHeight(block, height); + block= uiLayoutFreeBlock(pa->layout); uiBlockBeginAlign(block); @@ -999,9 +996,6 @@ static void view3d_panel_transform_spaces(const bContext *C, ARegion *ar, short yco -= 25; } uiBlockEndAlign(block); - - if(yco < 0) uiNewPanelHeight(block, height-yco); - uiEndBlock(C, block); } static void weight_paint_buttons(Scene *scene, uiBlock *block) @@ -1103,19 +1097,23 @@ static void brush_idpoin_handle(bContext *C, ID *id, int event) } } -static void view3d_panel_brush(const bContext *C, ARegion *ar, short cntrl) +static int view3d_panel_brush_poll(const bContext *C, PanelType *pt) +{ + Brush **brp = current_brush_source(CTX_data_scene(C)); + + return ((G.f & (G_SCULPTMODE|G_TEXTUREPAINT|G_VERTEXPAINT|G_WEIGHTPAINT)) && brp); +} + +static void view3d_panel_brush(const bContext *C, Panel *pa) { uiBlock *block; Brush **brp = current_brush_source(CTX_data_scene(C)), *br; short w = 268, h = 400, cx = 10, cy = h; rctf rect; - if(!brp) - return; br = *brp; - block= uiBeginBlock(C, ar, "view3d_panel_brush", UI_EMBOSS); - if(uiNewPanel(C, ar, block, "Brush", "View3d", 340, 10, 318, h)==0) return; + block= uiLayoutFreeBlock(pa->layout); uiBlockSetHandleFunc(block, do_view3d_region_buttons, NULL); uiBlockBeginAlign(block); @@ -1164,8 +1162,6 @@ static void view3d_panel_brush(const bContext *C, ARegion *ar, short cntrl) uiBlockBeginAlign(block); curvemap_buttons(block, br->curve, (char)0, B_NOP, 0, &rect); uiBlockEndAlign(block); - - uiEndBlock(C, block); } static void sculptmode_draw_interface_tools(Scene *scene, uiBlock *block, unsigned short cx, unsigned short cy) @@ -1203,12 +1199,12 @@ static void sculptmode_draw_interface_tools(Scene *scene, uiBlock *block, unsign } -static void view3d_panel_object(const bContext *C, ARegion *ar, short cntrl) // VIEW3D_HANDLER_OBJECT +static void view3d_panel_object(const bContext *C, Panel *pa) { + uiBlock *block; Scene *scene= CTX_data_scene(C); Object *obedit= CTX_data_edit_object(C); View3D *v3d= CTX_wm_view3d(C); - uiBlock *block; uiBut *bt; Object *ob= OBACT; TransformProperties *tfp; @@ -1222,19 +1218,8 @@ static void view3d_panel_object(const bContext *C, ARegion *ar, short cntrl) // v3d->properties_storage= MEM_callocN(sizeof(TransformProperties), "TransformProperties"); tfp= v3d->properties_storage; - block= uiBeginBlock(C, ar, "view3d_panel_object", UI_EMBOSS); + block= uiLayoutFreeBlock(pa->layout); uiBlockSetHandleFunc(block, do_view3d_region_buttons, NULL); - - if((G.f & G_SCULPTMODE) && !obedit) { - if(!uiNewPanel(C, ar, block, "Transform Properties", "View3d", 10, 230, 318, 234)) - return; - } else if(G.f & G_PARTICLEEDIT && !obedit){ - if(!uiNewPanel(C, ar, block, "Transform Properties", "View3d", 10, 230, 318, 234)) - return; - } else { - if(!uiNewPanel(C, ar, block, "Transform Properties", "View3d", 10, 230, 318, 204)) - return; - } // XXX uiSetButLock(object_is_libdata(ob), ERROR_LIBDATA_MESSAGE); @@ -1269,24 +1254,24 @@ static void view3d_panel_object(const bContext *C, ARegion *ar, short cntrl) // v3d_posearmature_buts(block, v3d, ob, lim); } else if(G.f & G_WEIGHTPAINT) { - uiNewPanelTitle(block, "Weight Paint Properties"); + BLI_strncpy(pa->drawname, "Weight Paint Properties", sizeof(pa->drawname)); weight_paint_buttons(scene, block); } else if(G.f & (G_VERTEXPAINT|G_TEXTUREPAINT)) { static float hsv[3], old[3]; // used as temp mem for picker Brush **br = current_brush_source(scene); - uiNewPanelTitle(block, "Paint Properties"); + BLI_strncpy(pa->drawname, "Paint Properties", sizeof(pa->drawname)); if(br && *br) /* 'f' is for floating panel */ uiBlockPickerButtons(block, (*br)->rgb, hsv, old, hexcol, 'f', B_REDR); } else if(G.f & G_SCULPTMODE) { - uiNewPanelTitle(block, "Sculpt Properties"); + BLI_strncpy(pa->drawname, "Sculpt Properties", sizeof(pa->drawname)); sculptmode_draw_interface_tools(scene, block, 10, 150); } else if(G.f & G_PARTICLEEDIT){ - uiNewPanelTitle(block, "Particle Edit Properties"); + BLI_strncpy(pa->drawname, "Particle Edit Properties", sizeof(pa->drawname)); // XXX particle_edit_buttons(block); } else { @@ -1364,17 +1349,14 @@ static void view3d_panel_object(const bContext *C, ARegion *ar, short cntrl) // uiBlockEndAlign(block); } } -// XXX uiClearButLock(); - uiEndBlock(C, block); } -static void view3d_panel_background(const bContext *C, ARegion *ar, short cntrl) // VIEW3D_HANDLER_BACKGROUND +static void view3d_panel_background(const bContext *C, Panel *pa) { View3D *v3d= CTX_wm_view3d(C); uiBlock *block; - block= uiBeginBlock(C, ar, "view3d_panel_background", UI_EMBOSS); - if(uiNewPanel(C, ar, block, "Background Image", "View3d", 340, 10, 318, 204)==0) return; + block= uiLayoutFreeBlock(pa->layout); uiBlockSetHandleFunc(block, do_view3d_region_buttons, NULL); if(v3d->flag & V3D_DISPBGPIC) { @@ -1403,11 +1385,10 @@ static void view3d_panel_background(const bContext *C, ARegion *ar, short cntrl) ED_image_uiblock_panel(C, block, &v3d->bgpic->ima, &v3d->bgpic->iuser, B_REDR, B_REDR); uiBlockEndAlign(block); } - uiEndBlock(C, block); } -static void view3d_panel_properties(const bContext *C, ARegion *ar, short cntrl) // VIEW3D_HANDLER_SETTINGS +static void view3d_panel_properties(const bContext *C, Panel *pa) { ScrArea *sa= CTX_wm_area(C); ARegion *arlast; @@ -1417,13 +1398,9 @@ static void view3d_panel_properties(const bContext *C, ARegion *ar, short cntrl) uiBlock *block; float *curs; - block= uiBeginBlock(C, ar, "view3d_panel_properties", UI_EMBOSS); - if(uiNewPanel(C, ar, block, "View Properties", "View3d", 340, 30, 318, 254)==0) return; + block= uiLayoutFreeBlock(pa->layout); uiBlockSetHandleFunc(block, do_view3d_region_buttons, NULL); - /* to force height */ - uiNewPanelHeight(block, 264); - uiDefBut(block, LABEL, 1, "Grid:", 10, 220, 150, 19, NULL, 0.0, 0.0, 0, 0, ""); uiBlockBeginAlign(block); uiDefButF(block, NUM, B_REDR, "Spacing:", 10, 200, 140, 19, &v3d->grid, 0.001, 100.0, 10, 0, "Set the distance between grid lines"); @@ -1497,8 +1474,6 @@ static void view3d_panel_properties(const bContext *C, ARegion *ar, short cntrl) // uiDefButBitS(block, TOGN, ANIMFILTER_NOSKEY, B_REDR, "ShapeKey",235, -42, 75, 19, &v3d->keyflags, 0, 0, 0, 0, "Show keyframes for any available Shape Keys"); // } uiBlockEndAlign(block); - - uiEndBlock(C, block); } #if 0 @@ -1527,13 +1502,12 @@ static void view3d_panel_preview(bContext *C, ARegion *ar, short cntrl) // VIEW3 } #endif -static void view3d_panel_gpencil(const bContext *C, ARegion *ar, short cntrl) // VIEW3D_HANDLER_GREASEPENCIL +static void view3d_panel_gpencil(const bContext *C, Panel *pa) { View3D *v3d= CTX_wm_view3d(C); uiBlock *block; - block= uiBeginBlock(C, ar, "view3d_panel_gpencil", UI_EMBOSS); - if (uiNewPanel(C, ar, block, "Grease Pencil", "View3d", 100, 30, 318, 204)==0) return; + block= uiLayoutFreeBlock(pa->layout); /* allocate memory for gpd if drawing enabled (this must be done first or else we crash) */ if (v3d->flag2 & V3D_DISPGP) { @@ -1543,24 +1517,14 @@ static void view3d_panel_gpencil(const bContext *C, ARegion *ar, short cntrl) // if (v3d->flag2 & V3D_DISPGP) { // XXX bGPdata *gpd= v3d->gpd; - short newheight; - - /* this is a variable height panel, newpanel doesnt force new size on existing panels */ - /* so first we make it default height */ - uiNewPanelHeight(block, 204); /* draw button for showing gpencil settings and drawings */ uiDefButBitS(block, TOG, V3D_DISPGP, B_REDR, "Use Grease Pencil", 10, 225, 150, 20, &v3d->flag2, 0, 0, 0, 0, "Display freehand annotations overlay over this 3D View (draw using Shift-LMB)"); - - /* extend the panel if the contents won't fit */ -// newheight= draw_gpencil_panel(block, gpd, ar); - uiNewPanelHeight(block, newheight); } else { uiDefButBitS(block, TOG, V3D_DISPGP, B_REDR, "Use Grease Pencil", 10, 225, 150, 20, &v3d->flag2, 0, 0, 0, 0, "Display freehand annotations overlay over this 3D View"); uiDefBut(block, LABEL, 1, " ", 160, 180, 150, 20, NULL, 0.0, 0.0, 0, 0, ""); } - uiEndBlock(C, block); } static void delete_sketch_armature(bContext *C, void *arg1, void *arg2) @@ -1578,126 +1542,123 @@ static void assign_template_sketch_armature(bContext *C, void *arg1, void *arg2) int index = *(int*)arg1; BIF_setTemplate(C, index); } -static void view3d_panel_bonesketch_spaces(const bContext *C, ARegion *ar, short cntrl) + +static int view3d_panel_bonesketch_spaces_poll(const bContext *C, PanelType *pt) { Object *obedit = CTX_data_edit_object(C); + + /* replace with check call to sketching lib */ + return (obedit && obedit->type == OB_ARMATURE); +} +static void view3d_panel_bonesketch_spaces(const bContext *C, Panel *pa) +{ Scene *scene = CTX_data_scene(C); static int template_index; static char joint_label[128]; uiBlock *block; uiBut *but; char *bone_name; - int yco = 130, height = 140; + int yco = 130; int nb_joints; + static char subdiv_tooltip[4][64] = { + "Subdivide arcs based on a fixed number of bones", + "Subdivide arcs in bones of equal length", + "Subdivide arcs based on correlation", + "Retarget template to stroke" + }; - /* replace with check call to sketching lib */ - if (obedit && obedit->type == OB_ARMATURE) - { - static char subdiv_tooltip[4][64] = { - "Subdivide arcs based on a fixed number of bones", - "Subdivide arcs in bones of equal length", - "Subdivide arcs based on correlation", - "Retarget template to stroke" - }; + + block= uiLayoutFreeBlock(pa->layout); + uiBlockSetHandleFunc(block, do_view3d_region_buttons, NULL); - - block= uiBeginBlock(C, ar, "view3d_panel_bonesketch_spaces", UI_EMBOSS); - if(uiNewPanel(C, ar, block, "Bone Sketching", "View3d", 340, 10, 318, height)==0) return; - uiBlockSetHandleFunc(block, do_view3d_region_buttons, NULL); + uiBlockBeginAlign(block); + + /* use real flag instead of 1 */ + uiDefButBitC(block, TOG, BONE_SKETCHING, B_REDR, "Use Bone Sketching", 10, yco, 160, 20, &scene->toolsettings->bone_sketching, 0, 0, 0, 0, "Use sketching to create and edit bones"); + uiDefButBitC(block, TOG, BONE_SKETCHING_ADJUST, B_REDR, "A", 170, yco, 20, 20, &scene->toolsettings->bone_sketching, 0, 0, 0, 0, "Adjust strokes by drawing near them"); + uiDefButBitC(block, TOG, BONE_SKETCHING_QUICK, B_REDR, "Q", 190, yco, 20, 20, &scene->toolsettings->bone_sketching, 0, 0, 0, 0, "Automatically convert and delete on stroke end"); + yco -= 20; + + but = uiDefBut(block, BUT, B_REDR, "Convert", 10,yco,100,20, 0, 0, 0, 0, 0, "Convert sketch to armature"); + uiButSetFunc(but, convert_sketch_armature, NULL, NULL); + + but = uiDefBut(block, BUT, B_REDR, "Delete", 110,yco,100,20, 0, 0, 0, 0, 0, "Delete sketch"); + uiButSetFunc(but, delete_sketch_armature, NULL, NULL); + yco -= 20; - uiNewPanelHeight(block, height); + uiBlockEndAlign(block); + + uiBlockBeginAlign(block); + uiDefButC(block, MENU, B_REDR, "Subdivision Method%t|Length%x1|Adaptative%x2|Fixed%x0|Template%x3", 10,yco,60,19, &scene->toolsettings->bone_sketching_convert, 0, 0, 0, 0, subdiv_tooltip[(unsigned char)scene->toolsettings->bone_sketching_convert]); + + switch(scene->toolsettings->bone_sketching_convert) + { + case SK_CONVERT_CUT_LENGTH: + uiDefButF(block, NUM, B_REDR, "Lim:", 70, yco, 140, 19, &scene->toolsettings->skgen_length_limit,0.1,50.0, 10, 0, "Maximum length of the subdivided bones"); + yco -= 20; + break; + case SK_CONVERT_CUT_ADAPTATIVE: + uiDefButF(block, NUM, B_REDR, "Thres:", 70, yco, 140, 19, &scene->toolsettings->skgen_correlation_limit,0.0, 1.0, 0.01, 0, "Correlation threshold for subdivision"); + yco -= 20; + break; + default: + case SK_CONVERT_CUT_FIXED: + uiDefButC(block, NUM, B_REDR, "Num:", 70, yco, 140, 19, &scene->toolsettings->skgen_subdivision_number,1, 100, 1, 5, "Number of subdivided bones"); + yco -= 20; + break; + case SK_CONVERT_RETARGET: + uiDefButC(block, ROW, B_NOP, "No", 70, yco, 40,19, &scene->toolsettings->skgen_retarget_roll, 0, 0, 0, 0, "No special roll treatment"); + uiDefButC(block, ROW, B_NOP, "View", 110, yco, 50,19, &scene->toolsettings->skgen_retarget_roll, 0, SK_RETARGET_ROLL_VIEW, 0, 0, "Roll bones perpendicular to view"); + uiDefButC(block, ROW, B_NOP, "Joint", 160, yco, 50,19, &scene->toolsettings->skgen_retarget_roll, 0, SK_RETARGET_ROLL_JOINT, 0, 0, "Roll bones relative to joint bend"); + yco -= 30; + + uiBlockEndAlign(block); + uiBlockBeginAlign(block); + /* button here to select what to do (copy or not), template, ...*/ + + BIF_makeListTemplates(C); + template_index = BIF_currentTemplate(C); + + but = uiDefButI(block, MENU, B_REDR, BIF_listTemplates(C), 10,yco,200,19, &template_index, 0, 0, 0, 0, "Template"); + uiButSetFunc(but, assign_template_sketch_armature, &template_index, NULL); - /* use real flag instead of 1 */ - uiDefButBitC(block, TOG, BONE_SKETCHING, B_REDR, "Use Bone Sketching", 10, yco, 160, 20, &scene->toolsettings->bone_sketching, 0, 0, 0, 0, "Use sketching to create and edit bones"); - uiDefButBitC(block, TOG, BONE_SKETCHING_ADJUST, B_REDR, "A", 170, yco, 20, 20, &scene->toolsettings->bone_sketching, 0, 0, 0, 0, "Adjust strokes by drawing near them"); - uiDefButBitC(block, TOG, BONE_SKETCHING_QUICK, B_REDR, "Q", 190, yco, 20, 20, &scene->toolsettings->bone_sketching, 0, 0, 0, 0, "Automatically convert and delete on stroke end"); yco -= 20; - but = uiDefBut(block, BUT, B_REDR, "Convert", 10,yco,100,20, 0, 0, 0, 0, 0, "Convert sketch to armature"); - uiButSetFunc(but, convert_sketch_armature, NULL, NULL); - - but = uiDefBut(block, BUT, B_REDR, "Delete", 110,yco,100,20, 0, 0, 0, 0, 0, "Delete sketch"); - uiButSetFunc(but, delete_sketch_armature, NULL, NULL); + uiDefButF(block, NUM, B_NOP, "A:", 10, yco, 66,19, &scene->toolsettings->skgen_retarget_angle_weight, 0, 10, 1, 0, "Angle Weight"); + uiDefButF(block, NUM, B_NOP, "L:", 76, yco, 67,19, &scene->toolsettings->skgen_retarget_length_weight, 0, 10, 1, 0, "Length Weight"); + uiDefButF(block, NUM, B_NOP, "D:", 143,yco, 67,19, &scene->toolsettings->skgen_retarget_distance_weight, 0, 10, 1, 0, "Distance Weight"); yco -= 20; - uiBlockEndAlign(block); + uiDefBut(block, TEX,B_REDR,"S:", 10, yco, 90, 20, scene->toolsettings->skgen_side_string, 0.0, 8.0, 0, 0, "Text to replace &S with"); + uiDefBut(block, TEX,B_REDR,"N:", 100, yco, 90, 20, scene->toolsettings->skgen_num_string, 0.0, 8.0, 0, 0, "Text to replace &N with"); + uiDefIconButBitC(block, TOG, SK_RETARGET_AUTONAME, B_NOP, ICON_AUTO,190,yco,20,20, &scene->toolsettings->skgen_retarget_options, 0, 0, 0, 0, "Use Auto Naming"); + yco -= 20; - uiBlockBeginAlign(block); + /* auto renaming magic */ + uiBlockEndAlign(block); - uiDefButC(block, MENU, B_REDR, "Subdivision Method%t|Length%x1|Adaptative%x2|Fixed%x0|Template%x3", 10,yco,60,19, &scene->toolsettings->bone_sketching_convert, 0, 0, 0, 0, subdiv_tooltip[(unsigned char)scene->toolsettings->bone_sketching_convert]); + nb_joints = BIF_nbJointsTemplate(C); - switch(scene->toolsettings->bone_sketching_convert) + if (nb_joints == -1) { - case SK_CONVERT_CUT_LENGTH: - uiDefButF(block, NUM, B_REDR, "Lim:", 70, yco, 140, 19, &scene->toolsettings->skgen_length_limit,0.1,50.0, 10, 0, "Maximum length of the subdivided bones"); - yco -= 20; - break; - case SK_CONVERT_CUT_ADAPTATIVE: - uiDefButF(block, NUM, B_REDR, "Thres:", 70, yco, 140, 19, &scene->toolsettings->skgen_correlation_limit,0.0, 1.0, 0.01, 0, "Correlation threshold for subdivision"); - yco -= 20; - break; - default: - case SK_CONVERT_CUT_FIXED: - uiDefButC(block, NUM, B_REDR, "Num:", 70, yco, 140, 19, &scene->toolsettings->skgen_subdivision_number,1, 100, 1, 5, "Number of subdivided bones"); - yco -= 20; - break; - case SK_CONVERT_RETARGET: - uiDefButC(block, ROW, B_NOP, "No", 70, yco, 40,19, &scene->toolsettings->skgen_retarget_roll, 0, 0, 0, 0, "No special roll treatment"); - uiDefButC(block, ROW, B_NOP, "View", 110, yco, 50,19, &scene->toolsettings->skgen_retarget_roll, 0, SK_RETARGET_ROLL_VIEW, 0, 0, "Roll bones perpendicular to view"); - uiDefButC(block, ROW, B_NOP, "Joint", 160, yco, 50,19, &scene->toolsettings->skgen_retarget_roll, 0, SK_RETARGET_ROLL_JOINT, 0, 0, "Roll bones relative to joint bend"); - yco -= 30; - - uiBlockEndAlign(block); - - uiBlockBeginAlign(block); - /* button here to select what to do (copy or not), template, ...*/ - - BIF_makeListTemplates(C); - template_index = BIF_currentTemplate(C); - - but = uiDefButI(block, MENU, B_REDR, BIF_listTemplates(C), 10,yco,200,19, &template_index, 0, 0, 0, 0, "Template"); - uiButSetFunc(but, assign_template_sketch_armature, &template_index, NULL); - - yco -= 20; - - uiDefButF(block, NUM, B_NOP, "A:", 10, yco, 66,19, &scene->toolsettings->skgen_retarget_angle_weight, 0, 10, 1, 0, "Angle Weight"); - uiDefButF(block, NUM, B_NOP, "L:", 76, yco, 67,19, &scene->toolsettings->skgen_retarget_length_weight, 0, 10, 1, 0, "Length Weight"); - uiDefButF(block, NUM, B_NOP, "D:", 143,yco, 67,19, &scene->toolsettings->skgen_retarget_distance_weight, 0, 10, 1, 0, "Distance Weight"); - yco -= 20; - - uiDefBut(block, TEX,B_REDR,"S:", 10, yco, 90, 20, scene->toolsettings->skgen_side_string, 0.0, 8.0, 0, 0, "Text to replace &S with"); - uiDefBut(block, TEX,B_REDR,"N:", 100, yco, 90, 20, scene->toolsettings->skgen_num_string, 0.0, 8.0, 0, 0, "Text to replace &N with"); - uiDefIconButBitC(block, TOG, SK_RETARGET_AUTONAME, B_NOP, ICON_AUTO,190,yco,20,20, &scene->toolsettings->skgen_retarget_options, 0, 0, 0, 0, "Use Auto Naming"); - yco -= 20; - - /* auto renaming magic */ - uiBlockEndAlign(block); - - nb_joints = BIF_nbJointsTemplate(C); - - if (nb_joints == -1) - { - //XXX - //nb_joints = G.totvertsel; - } - - bone_name = BIF_nameBoneTemplate(C); - - BLI_snprintf(joint_label, 32, "%i joints: %s", nb_joints, bone_name); - - uiDefBut(block, LABEL, 1, joint_label, 10, yco, 200, 20, NULL, 0.0, 0.0, 0, 0, ""); - yco -= 20; - break; + //XXX + //nb_joints = G.totvertsel; } - - uiBlockEndAlign(block); - uiDefButBitS(block, TOG, SCE_SNAP_PEEL_OBJECT, B_NOP, "Peel Objects", 10, yco, 200, 20, &scene->snap_flag, 0, 0, 0, 0, "Peel whole objects as one"); - - if(yco < 0) uiNewPanelHeight(block, height-yco); + bone_name = BIF_nameBoneTemplate(C); + + BLI_snprintf(joint_label, 32, "%i joints: %s", nb_joints, bone_name); + + uiDefBut(block, LABEL, 1, joint_label, 10, yco, 200, 20, NULL, 0.0, 0.0, 0, 0, ""); + yco -= 20; + break; } + + uiBlockEndAlign(block); + + uiDefButBitS(block, TOG, SCE_SNAP_PEEL_OBJECT, B_NOP, "Peel Objects", 10, yco, 200, 20, &scene->snap_flag, 0, 0, 0, 0, "Peel whole objects as one"); } @@ -1719,16 +1680,14 @@ static void redo_cb(bContext *C, void *arg_op, void *arg2) } } -static void view3d_panel_operator_redo(const bContext *C, ARegion *ar, short cntrl) +static void view3d_panel_operator_redo(const bContext *C, Panel *pa) { wmWindowManager *wm= CTX_wm_manager(C); wmOperator *op; PointerRNA ptr; uiBlock *block; - int height = 0; - block= uiBeginBlock(C, ar, "view3d_panel_operator_redo", UI_EMBOSS); - if(uiNewPanel(C, ar, block, "Last Operator", "View3d", 340, 10, 318, height)==0) return; + block= uiLayoutBlock(pa->layout); /* only for operators that are registered and did an undo push */ for(op= wm->operators.last; op; op= op->prev) @@ -1746,36 +1705,66 @@ static void view3d_panel_operator_redo(const bContext *C, ARegion *ar, short cnt } RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr); - height= uiDefAutoButsRNA(C, block, &ptr); - - uiNewPanelHeight(block, height); - - uiEndBlock(C, block); + uiDefAutoButsRNA(C, pa->layout, &ptr); } - -void view3d_buttons_area_defbuts(const bContext *C, ARegion *ar) +void view3d_buttons_register(ARegionType *art) { - uiBeginPanels(C, ar); - - view3d_panel_object(C, ar, 0); - view3d_panel_properties(C, ar, 0); - view3d_panel_background(C, ar, 0); - if(G.f & (G_SCULPTMODE|G_TEXTUREPAINT|G_VERTEXPAINT|G_WEIGHTPAINT)) - view3d_panel_brush(C, ar, 0); + PanelType *pt; + + pt= MEM_callocN(sizeof(PanelType), "spacetype view3d panel object"); + strcpy(pt->idname, "VIEW3D_PT_object"); + strcpy(pt->label, "Transform Properties"); + pt->draw= view3d_panel_object; + BLI_addtail(&art->paneltypes, pt); + + pt= MEM_callocN(sizeof(PanelType), "spacetype view3d panel properties"); + strcpy(pt->idname, "VIEW3D_PT_properties"); + strcpy(pt->label, "View Properties"); + pt->draw= view3d_panel_properties; + BLI_addtail(&art->paneltypes, pt); + + pt= MEM_callocN(sizeof(PanelType), "spacetype view3d panel background"); + strcpy(pt->idname, "VIEW3D_PT_background"); + strcpy(pt->label, "Background Image"); + pt->draw= view3d_panel_background; + BLI_addtail(&art->paneltypes, pt); + + pt= MEM_callocN(sizeof(PanelType), "spacetype view3d panel brush"); + strcpy(pt->idname, "VIEW3D_PT_brush"); + strcpy(pt->label, "Brush"); + pt->draw= view3d_panel_brush; + pt->poll= view3d_panel_brush_poll; + BLI_addtail(&art->paneltypes, pt); + + pt= MEM_callocN(sizeof(PanelType), "spacetype view3d panel transform spaces"); + strcpy(pt->idname, "VIEW3D_PT_transform spaces"); + strcpy(pt->label, "Transform Orientations"); + pt->draw= view3d_panel_transform_spaces; + BLI_addtail(&art->paneltypes, pt); + + /*pt= MEM_callocN(sizeof(PanelType), "spacetype view3d panel gpencil"); + strcpy(pt->idname, "VIEW3D_PT_gpencil"); + strcpy(pt->label, "Greas Pencil"); + pt->draw= view3d_panel_gpencil; + BLI_addtail(&art->paneltypes, pt);*/ + + pt= MEM_callocN(sizeof(PanelType), "spacetype view3d panel bonesketch spaces"); + strcpy(pt->idname, "VIEW3D_PT_bonesketch_spaces"); + strcpy(pt->label, "Bone Sketching"); + pt->draw= view3d_panel_bonesketch_spaces; + pt->poll= view3d_panel_bonesketch_spaces_poll; + BLI_addtail(&art->paneltypes, pt); + + pt= MEM_callocN(sizeof(PanelType), "spacetype view3d panel redo"); + strcpy(pt->idname, "VIEW3D_PT_redo"); + strcpy(pt->label, "Last Operator"); + pt->draw= view3d_panel_operator_redo; + BLI_addtail(&art->paneltypes, pt); + // XXX view3d_panel_preview(C, ar, 0); - view3d_panel_transform_spaces(C, ar, 0); - if(0) - view3d_panel_gpencil(C, ar, 0); - - view3d_panel_bonesketch_spaces(C, ar, 0); - - view3d_panel_operator_redo(C, ar, 0); - - uiEndPanels(C, ar); } - static int view3d_properties(bContext *C, wmOperator *op) { ScrArea *sa= CTX_wm_area(C); diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c index 2fd453c9ff7..da201195288 100644 --- a/source/blender/editors/space_view3d/view3d_header.c +++ b/source/blender/editors/space_view3d/view3d_header.c @@ -3359,7 +3359,7 @@ static void view3d_edit_curvemenu(bContext *C, uiLayout *layout, void *arg_unuse uiItemS(layout); - uiItemR(layout, NULL, 0, &sceneptr, "proportional_editing", 0); // |O + uiItemR(layout, NULL, 0, &sceneptr, "proportional_editing", 0, 0); // |O uiItemMenuEnumR(layout, NULL, 0, &sceneptr, "proportional_editing_falloff"); uiItemS(layout); @@ -4533,12 +4533,12 @@ static void view3d_sculpt_menu(bContext *C, uiLayout *layout, void *arg_unused) RNA_pointer_create(&sc->id, &RNA_Sculpt, s, &rna); - uiItemR(layout, NULL, 0, &rna, "symmetry_x", 0); - uiItemR(layout, NULL, 0, &rna, "symmetry_y", 0); - uiItemR(layout, NULL, 0, &rna, "symmetry_z", 0); - uiItemR(layout, NULL, 0, &rna, "lock_x", 0); - uiItemR(layout, NULL, 0, &rna, "lock_y", 0); - uiItemR(layout, NULL, 0, &rna, "lock_z", 0); + uiItemR(layout, NULL, 0, &rna, "symmetry_x", 0, 0); + uiItemR(layout, NULL, 0, &rna, "symmetry_y", 0, 0); + uiItemR(layout, NULL, 0, &rna, "symmetry_z", 0, 0); + uiItemR(layout, NULL, 0, &rna, "lock_x", 0, 0); + uiItemR(layout, NULL, 0, &rna, "lock_y", 0, 0); + uiItemR(layout, NULL, 0, &rna, "lock_z", 0, 0); /* Brush settings */ RNA_pointer_create(&sc->id, &RNA_Brush, s->brush, &rna); @@ -4551,12 +4551,12 @@ static void view3d_sculpt_menu(bContext *C, uiLayout *layout, void *arg_unused) uiItemS(layout); - uiItemR(layout, NULL, 0, &rna, "airbrush", 0); - uiItemR(layout, NULL, 0, &rna, "rake", 0); - uiItemR(layout, NULL, 0, &rna, "anchored", 0); - uiItemR(layout, NULL, 0, &rna, "space", 0); + uiItemR(layout, NULL, 0, &rna, "airbrush", 0, 0); + uiItemR(layout, NULL, 0, &rna, "rake", 0, 0); + uiItemR(layout, NULL, 0, &rna, "anchored", 0, 0); + uiItemR(layout, NULL, 0, &rna, "space", 0, 0); - uiItemR(layout, NULL, 0, &rna, "flip_direction", 0); + uiItemR(layout, NULL, 0, &rna, "flip_direction", 0, 0); } uiBlock *view3d_sculptmenu(bContext *C, ARegion *ar, void *arg_unused) diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h index 9f162c5327b..ab705cb32fb 100644 --- a/source/blender/editors/space_view3d/view3d_intern.h +++ b/source/blender/editors/space_view3d/view3d_intern.h @@ -42,6 +42,7 @@ struct bContext; struct wmWindowManager; struct EditMesh; struct ViewContext; +struct ARegionType; #define BL_NEAR_CLIP 0.001 @@ -131,11 +132,11 @@ void setviewmatrixview3d(Scene *scene, View3D *v3d, RegionView3D *rv3d); /* view3d_buttons.c */ void VIEW3D_OT_properties(struct wmOperatorType *ot); -void view3d_buttons_area_defbuts(const struct bContext *C, ARegion *ar); +void view3d_buttons_register(struct ARegionType *art); /* view3d_buttons.c */ void VIEW3D_OT_toolbar(struct wmOperatorType *ot); -void view3d_tools_area_defbuts(const struct bContext *C, ARegion *ar); +void view3d_toolbar_register(struct ARegionType *art); /* view3d_snap.c */ int minmax_verts(Object *obedit, float *min, float *max); diff --git a/source/blender/editors/space_view3d/view3d_toolbar.c b/source/blender/editors/space_view3d/view3d_toolbar.c index 9f16e124f77..c7cd5a92ebf 100644 --- a/source/blender/editors/space_view3d/view3d_toolbar.c +++ b/source/blender/editors/space_view3d/view3d_toolbar.c @@ -118,18 +118,16 @@ static void redo_cb(bContext *C, void *arg_op, void *arg2) } } -static void view3d_panel_operator_redo(const bContext *C, ARegion *ar, short cntrl) +static void view3d_panel_operator_redo(const bContext *C, Panel *pa) { /* XXX temp */ - extern int uiDefAutoButsRNA_single(const bContext *C, uiBlock *block, PointerRNA *ptr); + extern void uiDefAutoButsRNA_single(const bContext *C, uiLayout *layout, PointerRNA *ptr); wmWindowManager *wm= CTX_wm_manager(C); wmOperator *op; PointerRNA ptr; uiBlock *block; - int height = 0; - block= uiBeginBlock(C, ar, "view3d_panel_operator_redo", UI_EMBOSS); - if(uiNewPanel(C, ar, block, "Operator", "View3d", 0, 10, 120, height)==0) return; + block= uiLayoutBlock(pa->layout); /* only for operators that are registered and did an undo push */ for(op= wm->operators.last; op; op= op->prev) @@ -149,23 +147,19 @@ static void view3d_panel_operator_redo(const bContext *C, ARegion *ar, short cnt } RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr); - height= uiDefAutoButsRNA_single(C, block, &ptr); - - uiNewPanelHeight(block, height); - - uiEndBlock(C, block); + uiDefAutoButsRNA_single(C, pa->layout, &ptr); } - -void view3d_tools_area_defbuts(const bContext *C, ARegion *ar) +void view3d_toolbar_register(ARegionType *art) { - uiBeginPanels(C, ar); - - view3d_panel_operator_redo(C, ar, 0); - - uiEndPanels(C, ar); -} + PanelType *pt; + pt= MEM_callocN(sizeof(PanelType), "spacetype view3d panel last operator"); + strcpy(pt->idname, "VIEW3D_PT_last_operator"); + strcpy(pt->label, "Last Operator"); + pt->draw= view3d_panel_operator_redo; + BLI_addtail(&art->paneltypes, pt); +} static int view3d_toolbar(bContext *C, wmOperator *op) { diff --git a/source/blender/makesdna/DNA_screen_types.h b/source/blender/makesdna/DNA_screen_types.h index 7a6e48f2ca9..4a39744c1dc 100644 --- a/source/blender/makesdna/DNA_screen_types.h +++ b/source/blender/makesdna/DNA_screen_types.h @@ -91,8 +91,8 @@ typedef struct ScrEdge { typedef struct Panel { /* the part from uiBlock that needs saved in file */ struct Panel *next, *prev; - struct PanelType *type; /* runtime */ - struct uiLayout *layout; /* runtime for drawing */ + struct PanelType *type; /* runtime */ + struct uiLayout *layout; /* runtime for drawing */ char panelname[64], tabname[64]; /* defined as UI_MAX_NAME_STR */ char drawname[64]; /* panelname is identifier for restoring location */ diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index cfe1778db41..6698335e1cb 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -63,15 +63,21 @@ void RNA_main_pointer_create(struct Main *main, PointerRNA *r_ptr) void RNA_id_pointer_create(ID *id, PointerRNA *r_ptr) { PointerRNA tmp; - StructRNA *idtype= NULL; + StructRNA *type, *idtype= NULL; if(id) { memset(&tmp, 0, sizeof(tmp)); tmp.data= id; idtype= rna_ID_refine(&tmp); - if(idtype->refine) - idtype= idtype->refine(&tmp); + while(idtype->refine) { + type= idtype->refine(&tmp); + + if(type == idtype) + break; + else + idtype= type; + } } r_ptr->id.data= id; @@ -121,8 +127,14 @@ PointerRNA rna_pointer_inherit_refine(PointerRNA *ptr, StructRNA *type, void *da result.type= type; rna_pointer_inherit_id(type, ptr, &result); - if(type->refine) - result.type= type->refine(&result); + while(result.type->refine) { + type= result.type->refine(&result); + + if(type == result.type) + break; + else + result.type= type; + } } else memset(&result, 0, sizeof(result)); diff --git a/source/blender/makesrna/intern/rna_ui.c b/source/blender/makesrna/intern/rna_ui.c index 405ae9a0f74..a3e48f629cb 100644 --- a/source/blender/makesrna/intern/rna_ui.c +++ b/source/blender/makesrna/intern/rna_ui.c @@ -111,6 +111,22 @@ static void panel_draw(const bContext *C, Panel *pnl) RNA_parameter_list_free(list); } +static void panel_draw_header(const bContext *C, Panel *pnl) +{ + PointerRNA ptr; + ParameterList *list; + FunctionRNA *func; + + RNA_pointer_create(&CTX_wm_screen(C)->id, pnl->type->py_srna, pnl, &ptr); + func= RNA_struct_find_function(&ptr, "draw_header"); + + list= RNA_parameter_list_create(&ptr, func); + RNA_parameter_set_lookup(list, "context", &C); + pnl->type->py_call(&ptr, func, list); + + RNA_parameter_list_free(list); +} + static void rna_Panel_unregister(const bContext *C, StructRNA *type) { ARegionType *art; @@ -169,6 +185,7 @@ static StructRNA *rna_Panel_register(const bContext *C, ReportList *reports, voi pt->poll= (have_function[0])? panel_poll: NULL; pt->draw= (have_function[1])? panel_draw: NULL; + pt->draw_header= (have_function[2])? panel_draw_header: NULL; BLI_addtail(&art->paneltypes, pt); @@ -429,6 +446,11 @@ static void rna_def_panel(BlenderRNA *brna) RNA_def_function_flag(func, FUNC_REGISTER); RNA_def_pointer(func, "context", "Context", "", ""); + func= RNA_def_function(srna, "draw_header", NULL); + RNA_def_function_ui_description(func, "Draw buttons into the panel header UI layout."); + RNA_def_function_flag(func, FUNC_REGISTER); + RNA_def_pointer(func, "context", "Context", "", ""); + prop= RNA_def_property(srna, "layout", PROP_POINTER, PROP_NONE); RNA_def_property_struct_type(prop, "UILayout"); diff --git a/source/blender/python/intern/bpy_ui.c b/source/blender/python/intern/bpy_ui.c index 471263d9d63..0f2142f4b62 100644 --- a/source/blender/python/intern/bpy_ui.c +++ b/source/blender/python/intern/bpy_ui.c @@ -179,32 +179,6 @@ static PyObject *Method_drawBlock( PyObject * self, PyObject * args ) Py_RETURN_NONE; } -static PyObject *Method_beginPanels( PyObject * self, PyObject * args ) -{ - bContext *C; - PyObject *py_context; - - if( !PyArg_ParseTuple( args, "O!i:beginPanels", &PyCObject_Type, &py_context) ) - return NULL; - - C= PyCObject_AsVoidPtr(py_context); - uiBeginPanels(C, CTX_wm_region(C)); - Py_RETURN_NONE; -} - -static PyObject *Method_endPanels( PyObject * self, PyObject * args ) -{ - bContext *C; - PyObject *py_context; - - if( !PyArg_ParseTuple( args, "O!:endPanels", &PyCObject_Type, &py_context) ) - return NULL; - - C= PyCObject_AsVoidPtr(py_context); - uiEndPanels(C, CTX_wm_region(C)); - Py_RETURN_NONE; -} - static PyObject *Method_popupBoundsBlock( PyObject * self, PyObject * args ) { PyObject *py_block; @@ -251,18 +225,6 @@ static PyObject *Method_blockSetFlag( PyObject * self, PyObject * args ) Py_RETURN_NONE; } -static PyObject *Method_newPanel( PyObject * self, PyObject * args ) -{ - PyObject *py_context, *py_area, *py_block; - char *panelname, *tabname; - int ofsx, ofsy, sizex, sizey; - - if( !PyArg_ParseTuple( args, "O!O!O!ssiiii:newPanel", &PyCObject_Type, &py_context, &PyCObject_Type, &py_area, &PyCObject_Type, &py_block, &panelname, &tabname, &ofsx, &ofsy, &sizex, &sizey)) - return NULL; - - return PyLong_FromSsize_t(uiNewPanel(PyCObject_AsVoidPtr(py_context), PyCObject_AsVoidPtr(py_area), PyCObject_AsVoidPtr(py_block), panelname, tabname, ofsx, ofsy, sizex, sizey)); -} - /* similar to Draw.c */ static PyObject *Method_register( PyObject * self, PyObject * args ) { @@ -402,9 +364,6 @@ static struct PyMethodDef ui_methods[] = { {"blockBeginAlign", (PyCFunction)Method_blockBeginAlign, METH_VARARGS, ""}, {"blockEndAlign", (PyCFunction)Method_blockEndAlign, METH_VARARGS, ""}, {"blockSetFlag", (PyCFunction)Method_blockSetFlag, METH_VARARGS, ""}, - {"newPanel", (PyCFunction)Method_newPanel, METH_VARARGS, ""}, - {"beginPanels", (PyCFunction)Method_beginPanels, METH_VARARGS, ""}, - {"endPanels", (PyCFunction)Method_endPanels, METH_VARARGS, ""}, {"register", (PyCFunction)Method_register, METH_VARARGS, ""}, // XXX not sure about this - registers current script with the ScriptSpace, like Draw.Register() {"registerKey", (PyCFunction)Method_registerKey, METH_VARARGS, ""}, // XXX could have this in another place too diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 34baf672d5e..9c0fc4d8e9e 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -276,7 +276,8 @@ static uiBlock *wm_block_create_redo(bContext *C, ARegion *ar, void *arg_op) wmOperator *op= arg_op; PointerRNA ptr; uiBlock *block; - int height; + uiLayout *layout; + uiStyle *style= U.uistyles.first; block= uiBeginBlock(C, ar, "redo_popup", UI_EMBOSS); uiBlockClearFlag(block, UI_BLOCK_LOOP); @@ -289,7 +290,8 @@ static uiBlock *wm_block_create_redo(bContext *C, ARegion *ar, void *arg_op) } RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr); - height= uiDefAutoButsRNA(C, block, &ptr); + layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, 300, 20, style); + uiDefAutoButsRNA(C, layout, &ptr); uiPopupBoundsBlock(block, 4.0f, 0, 0); uiEndBlock(C, block); |