[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [24042] trunk/blender/source/blender: UI: List Template tweaks to get it a bit more usable

Brecht Van Lommel brecht at blender.org
Wed Oct 21 22:58:10 CEST 2009


Revision: 24042
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24042
Author:   blendix
Date:     2009-10-21 22:58:10 +0200 (Wed, 21 Oct 2009)

Log Message:
-----------
UI: List Template tweaks to get it a bit more usable

* Mouse wheel now scrolls the list.
* Up/down key and alt mouse wheel change the active item.
* Adding/removing items from the list now automatically scrolls so the
  active item is in the view.
* Shift mouse wheel changes the size of the list widget to display more
  items. Lazy replacement for a proper grip.

* Shape key list now displays the influence value next to the name,
* Also fix the range of the value slider to match the defined min/max
  range.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/include/UI_interface.h
    trunk/blender/source/blender/editors/interface/interface_handlers.c
    trunk/blender/source/blender/editors/interface/interface_layout.c
    trunk/blender/source/blender/editors/interface/interface_regions.c
    trunk/blender/source/blender/editors/interface/interface_templates.c
    trunk/blender/source/blender/makesdna/DNA_screen_types.h
    trunk/blender/source/blender/makesrna/intern/rna_key.c
    trunk/blender/source/blender/makesrna/intern/rna_ui.c
    trunk/blender/source/blender/makesrna/intern/rna_ui_api.c

Modified: trunk/blender/source/blender/editors/include/UI_interface.h
===================================================================
--- trunk/blender/source/blender/editors/include/UI_interface.h	2009-10-21 17:56:26 UTC (rev 24041)
+++ trunk/blender/source/blender/editors/include/UI_interface.h	2009-10-21 20:58:10 UTC (rev 24042)
@@ -148,6 +148,7 @@
 #define UI_BUT_LAST_ACTIVE	(1<<24)
 #define UI_BUT_UNDO			(1<<25)
 #define UI_BUT_IMMEDIATE	(1<<26)
+#define UI_BUT_NO_TOOLTIP	(1<<27)
 
 #define UI_PANEL_WIDTH			340
 #define UI_COMPACT_PANEL_WIDTH	160
@@ -603,16 +604,17 @@
 int uiLayoutGetWidth(uiLayout *layout);
 float uiLayoutGetScaleX(uiLayout *layout);
 float uiLayoutGetScaleY(uiLayout *layout);
-ListBase *uiLayoutBoxGetList(uiLayout *layout);
 
 /* layout specifiers */
 uiLayout *uiLayoutRow(uiLayout *layout, int align);
 uiLayout *uiLayoutColumn(uiLayout *layout, int align);
 uiLayout *uiLayoutColumnFlow(uiLayout *layout, int number, int align);
 uiLayout *uiLayoutBox(uiLayout *layout);
-uiLayout *uiLayoutListBox(uiLayout *layout);
-uiLayout *uiLayoutFree(uiLayout *layout, int align);
+uiLayout *uiLayoutListBox(uiLayout *layout, struct PointerRNA *ptr, struct PropertyRNA *prop,
+	struct PointerRNA *actptr, struct PropertyRNA *actprop);
+uiLayout *uiLayoutAbsolute(uiLayout *layout, int align);
 uiLayout *uiLayoutSplit(uiLayout *layout, float percentage);
+uiLayout *uiLayoutOverlap(uiLayout *layout);
 
 uiBlock *uiLayoutAbsoluteBlock(uiLayout *layout);
 
@@ -639,15 +641,8 @@
 void uiTemplate_view3d_select_faceselmenu(uiLayout *layout, struct bContext *C);
 void uiTemplateTextureImage(uiLayout *layout, struct bContext *C, struct Tex *tex);
 
-typedef struct uiListItem {
-	struct uiListItem *next, *prev;
+void uiTemplateList(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, char *propname, struct PointerRNA *activeptr, char *activeprop, int rows, int type);
 
-	struct PointerRNA data;
-	uiLayout *layout;
-} uiListItem;
-
-ListBase uiTemplateList(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, char *propname, struct PointerRNA *activeptr, char *activeprop, int rows, int type);
-
 /* items */
 void uiItemO(uiLayout *layout, char *name, int icon, char *opname);
 void uiItemEnumO(uiLayout *layout, char *name, int icon, char *opname, char *propname, int value);

Modified: trunk/blender/source/blender/editors/interface/interface_handlers.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_handlers.c	2009-10-21 17:56:26 UTC (rev 24041)
+++ trunk/blender/source/blender/editors/interface/interface_handlers.c	2009-10-21 20:58:10 UTC (rev 24042)
@@ -1944,8 +1944,11 @@
 {
 	if(data->state == BUTTON_STATE_HIGHLIGHT) {
 		if(ELEM4(event->type, LEFTMOUSE, PADENTER, RETKEY, EVT_BUT_OPEN) && event->val==KM_PRESS) {
-			button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING);
-			return WM_UI_HANDLER_BREAK;
+			if(but->dt == UI_EMBOSSN && !event->ctrl);
+			else {
+				button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING);
+				return WM_UI_HANDLER_BREAK;
+			}
 		}
 	}
 	else if(data->state == BUTTON_STATE_TEXT_EDITING) {
@@ -3653,15 +3656,35 @@
 			if(but->flag & UI_HIDDEN)
 				continue;
 			if(ui_but_contains_pt(but, mx, my))
-				/* give precedence to already activated buttons */
-				if(!butover || (!butover->active && but->active))
-					butover= but;
+				butover= but;
 		}
 	}
 
 	return butover;
 }
 
+static uiBut *ui_list_find_mouse_over(ARegion *ar, int x, int y)
+{
+	uiBlock *block;
+	uiBut *but;
+	int mx, my;
+
+	if(!ui_mouse_inside_region(ar, x, y))
+		return NULL;
+
+	for(block=ar->uiblocks.first; block; block=block->next) {
+		mx= x;
+		my= y;
+		ui_window_to_block(ar, block, &mx, &my);
+
+		for(but=block->buttons.last; but; but= but->prev)
+			if(but->type == LISTBOX && ui_but_contains_pt(but, mx, my))
+				return but;
+	}
+
+	return NULL;
+}
+
 /* ****************** button state handling **************************/
 
 static int button_modal_state(uiHandleButtonState state)
@@ -4028,6 +4051,10 @@
 					data->cancel= 1;
 					button_activate_state(C, but, BUTTON_STATE_EXIT);
 				}
+				else if(ui_but_find_mouse_over(ar, event->x, event->y) != but) {
+					data->cancel= 1;
+					button_activate_state(C, but, BUTTON_STATE_EXIT);
+				}
 				else if(event->x!=event->prevx || event->y!=event->prevy) {
 					/* re-enable tooltip on mouse move */
 					ui_blocks_set_tooltips(ar, 1);
@@ -4151,6 +4178,71 @@
 	return retval;
 }
 
+static int ui_handle_list_event(bContext *C, wmEvent *event, ARegion *ar)
+{
+	uiBut *but= ui_list_find_mouse_over(ar, event->x, event->y);
+	int retval= WM_UI_HANDLER_CONTINUE;
+	int value, min, max;
+
+	if(but && (event->val == KM_PRESS)) {
+		Panel *pa= but->block->panel;
+
+		if(ELEM(event->type, UPARROWKEY, DOWNARROWKEY) ||
+		   ((ELEM(event->type, WHEELUPMOUSE, WHEELDOWNMOUSE) && event->alt))) {
+			/* activate up/down the list */
+			value= RNA_property_int_get(&but->rnapoin, but->rnaprop);
+
+			if(ELEM(event->type, UPARROWKEY, WHEELUPMOUSE))
+				value--;
+			else
+				value++;
+
+			if(value < pa->list_scroll)
+				pa->list_scroll= value;
+			else if(value >= pa->list_scroll+pa->list_size)
+				pa->list_scroll= value - pa->list_size + 1;
+
+			RNA_property_int_range(&but->rnapoin, but->rnaprop, &min, &max);
+			value= CLAMPIS(value, min, max);
+
+			RNA_property_int_set(&but->rnapoin, but->rnaprop, value);
+			RNA_property_update(C, &but->rnapoin, but->rnaprop);
+			ED_region_tag_redraw(ar);
+
+			retval= WM_UI_HANDLER_BREAK;
+		}
+		else if(ELEM(event->type, WHEELUPMOUSE, WHEELDOWNMOUSE) && event->shift) {
+			/* silly replacement for proper grip */
+			if(pa->list_grip_size == 0)
+				pa->list_grip_size= pa->list_size;
+
+			if(event->type == WHEELUPMOUSE)
+				pa->list_grip_size--;
+			else
+				pa->list_grip_size++;
+
+			pa->list_grip_size= MAX2(pa->list_grip_size, 1);
+
+			ED_region_tag_redraw(ar);
+
+			retval= WM_UI_HANDLER_BREAK;
+		}
+		else if(ELEM(event->type, WHEELUPMOUSE, WHEELDOWNMOUSE)) {
+			/* list template will clamp */
+			if(event->type == WHEELUPMOUSE)
+				pa->list_scroll--;
+			else
+				pa->list_scroll++;
+
+			ED_region_tag_redraw(ar);
+
+			retval= WM_UI_HANDLER_BREAK;
+		}
+	}
+
+	return retval;
+}
+
 static void ui_handle_button_return_submenu(bContext *C, wmEvent *event, uiBut *but)
 {
 	uiHandleButtonData *data;
@@ -4615,6 +4707,9 @@
 	if(!but || !button_modal_state(but->active->state))
 		retval= ui_handler_panel_region(C, event);
 
+	if(retval == WM_UI_HANDLER_CONTINUE)
+		retval= ui_handle_list_event(C, event, ar);
+
 	if(retval == WM_UI_HANDLER_CONTINUE) {
 		if(but)
 			retval= ui_handle_button_event(C, event, but);

Modified: trunk/blender/source/blender/editors/interface/interface_layout.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_layout.c	2009-10-21 17:56:26 UTC (rev 24041)
+++ trunk/blender/source/blender/editors/interface/interface_layout.c	2009-10-21 20:58:10 UTC (rev 24042)
@@ -98,6 +98,7 @@
 	ITEM_LAYOUT_BOX,
 	ITEM_LAYOUT_ABSOLUTE,
 	ITEM_LAYOUT_SPLIT,
+	ITEM_LAYOUT_OVERLAP,
 
 	ITEM_LAYOUT_ROOT
 #if 0
@@ -148,7 +149,6 @@
 typedef struct uiLayoutItemBx {
 	uiLayout litem;
 	uiBut *roundbox;
-	ListBase items;
 } uiLayoutItemBx;
 
 typedef struct uiLayoutItemSplt {
@@ -286,6 +286,7 @@
 	switch(layout->item.type) {
 		case ITEM_LAYOUT_ROW:
 		case ITEM_LAYOUT_ROOT:
+		case ITEM_LAYOUT_OVERLAP:
 			return UI_LAYOUT_HORIZONTAL;
 		case ITEM_LAYOUT_COLUMN:
 		case ITEM_LAYOUT_COLUMN_FLOW:
@@ -362,7 +363,7 @@
 		int cols= (len >= 20)? 2: 1;
 		int colbuts= len/(2*cols);
 
-		uiBlockSetCurLayout(block, uiLayoutFree(layout, 0));
+		uiBlockSetCurLayout(block, uiLayoutAbsolute(layout, 0));
 
 		unit= UI_UNIT_X*0.75;
 		butw= unit;
@@ -390,7 +391,7 @@
 		/* matrix layout */
 		int row, col;
 
-		uiBlockSetCurLayout(block, uiLayoutFree(layout, 1));
+		uiBlockSetCurLayout(block, uiLayoutAbsolute(layout, 1));
 
 		len= ceil(sqrt(len));
 
@@ -1869,6 +1870,42 @@
 	litem->y= y;
 }
 
+/* overlap layout */
+static void ui_litem_estimate_overlap(uiLayout *litem)
+{
+	uiItem *item;
+	int itemw, itemh;
+
+	litem->w= 0;
+	litem->h= 0;
+
+	for(item=litem->items.first; item; item=item->next) {
+		ui_item_size(item, &itemw, &itemh);
+
+		litem->w= MAX2(itemw, litem->w);
+		litem->h= MAX2(itemh, litem->h);
+	}
+}
+
+static void ui_litem_layout_overlap(uiLayout *litem)
+{
+	uiItem *item;
+	int itemw, itemh, x, y;
+
+	x= litem->x;
+	y= litem->y;
+
+	for(item=litem->items.first; item; item=item->next) {
+		ui_item_size(item, &itemw, &itemh);
+		ui_item_position(item, x, y-itemh, litem->w, itemh);
+
+		litem->h= MAX2(litem->h, itemh);
+	}
+
+	litem->x= x;
+	litem->y= y - litem->h;
+}
+
 /* layout create functions */
 uiLayout *uiLayoutRow(uiLayout *layout, int align)
 {
@@ -1928,7 +1965,7 @@
 	return &flow->litem;
 }
 
-static uiLayout *ui_layout_box(uiLayout *layout, int type)
+static uiLayoutItemBx *ui_layout_box(uiLayout *layout, int type)
 {
 	uiLayoutItemBx *box;
 
@@ -1945,30 +1982,32 @@
 
 	box->roundbox= uiDefBut(layout->root->block, type, 0, "", 0, 0, 0, 0, NULL, 0.0, 0.0, 0, 0, "");
 
-	return &box->litem;
+	return box;
 }
 
 uiLayout *uiLayoutBox(uiLayout *layout)
 {
-	return ui_layout_box(layout, ROUNDBOX);
+	return (uiLayout*)ui_layout_box(layout, ROUNDBOX);
 }
 
-uiLayout *uiLayoutListBox(uiLayout *layout)
+uiLayout *uiLayoutListBox(uiLayout *layout, PointerRNA *ptr, PropertyRNA *prop, PointerRNA *actptr, PropertyRNA *actprop)
 {
-	return ui_layout_box(layout, LISTBOX);
-}
+    uiLayoutItemBx *box= ui_layout_box(layout, LISTBOX);
+	uiBut *but= box->roundbox;
 
-ListBase *uiLayoutBoxGetList(uiLayout *layout)
-{
-	uiLayoutItemBx *box= (uiLayoutItemBx*)layout;
-	return &box->items;
+	but->rnasearchpoin= *ptr;
+	but->rnasearchprop= prop;
+	but->rnapoin= *actptr;
+	but->rnaprop= actprop;
+
+	return (uiLayout*)box;
 }
 
-uiLayout *uiLayoutFree(uiLayout *layout, int align)
+uiLayout *uiLayoutAbsolute(uiLayout *layout, int align)
 {
 	uiLayout *litem;
 
-	litem= MEM_callocN(sizeof(uiLayout), "uiLayoutFree");
+	litem= MEM_callocN(sizeof(uiLayout), "uiLayoutAbsolute");
 	litem->item.type= ITEM_LAYOUT_ABSOLUTE;
 	litem->root= layout->root;
 	litem->align= align;
@@ -1987,11 +2026,28 @@
 	uiBlock *block;
 
 	block= uiLayoutGetBlock(layout);
-	uiLayoutFree(layout, 0);
+	uiLayoutAbsolute(layout, 0);
 
 	return block;
 }
 
+uiLayout *uiLayoutOverlap(uiLayout *layout)
+{
+	uiLayout *litem;
+
+	litem= MEM_callocN(sizeof(uiLayout), "uiLayoutOverlap");

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list