[Bf-blender-cvs] [9b3bd55] master: Replace resize code of image scopes by use of new GRIP button.

Bastien Montagne noreply at git.blender.org
Wed Apr 2 13:10:07 CEST 2014


Commit: 9b3bd5582be99e26b6c3651f66db516982bc8461
Author: Bastien Montagne
Date:   Wed Apr 2 13:09:43 2014 +0200
https://developer.blender.org/rB9b3bd5582be99e26b6c3651f66db516982bc8461

Replace resize code of image scopes by use of new GRIP button.

This deduplicates/simplifies some code. Also cleanup up a bit scopes UI code!

Use new GRIP button for uiList grab-resize.

This allows us to greatly simplifies the code, and get rid of a few hacks in uiList event handling!

Note autosize mode of uiList is now trigered by any value of list_grip below a given threshold, rather than the fixed zero value...

Reviewers: brecht

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D343

===================================================================

M	source/blender/editors/interface/interface_draw.c
M	source/blender/editors/interface/interface_handlers.c
M	source/blender/editors/interface/interface_layout.c
M	source/blender/editors/interface/interface_templates.c
M	source/blender/editors/space_clip/clip_buttons.c
M	source/blender/makesdna/DNA_screen_types.h

===================================================================

diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c
index 13551d9..2d13159 100644
--- a/source/blender/editors/interface/interface_draw.c
+++ b/source/blender/editors/interface/interface_draw.c
@@ -444,24 +444,11 @@ void ui_draw_but_IMAGE(ARegion *UNUSED(ar), uiBut *but, uiWidgetColors *UNUSED(w
 
 static void draw_scope_end(const rctf *rect, GLint *scissor)
 {
-	float scaler_x1, scaler_x2;
-	
 	/* restore scissortest */
 	glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
-	
+
 	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-	
-	/* scale widget */
-	scaler_x1 = rect->xmin + BLI_rctf_size_x(rect) / 2 - SCOPE_RESIZE_PAD;
-	scaler_x2 = rect->xmin + BLI_rctf_size_x(rect) / 2 + SCOPE_RESIZE_PAD;
-	
-	glColor4f(0.f, 0.f, 0.f, 0.25f);
-	fdrawline(scaler_x1, rect->ymin - 4, scaler_x2, rect->ymin - 4);
-	fdrawline(scaler_x1, rect->ymin - 7, scaler_x2, rect->ymin - 7);
-	glColor4f(1.f, 1.f, 1.f, 0.25f);
-	fdrawline(scaler_x1, rect->ymin - 5, scaler_x2, rect->ymin - 5);
-	fdrawline(scaler_x1, rect->ymin - 8, scaler_x2, rect->ymin - 8);
-	
+
 	/* outline */
 	glColor4f(0.f, 0.f, 0.f, 0.5f);
 	uiSetRoundBox(UI_CNR_ALL);
@@ -539,7 +526,7 @@ void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol)
 	
 	rect.xmin = (float)recti->xmin + 1;
 	rect.xmax = (float)recti->xmax - 1;
-	rect.ymin = (float)recti->ymin + SCOPE_RESIZE_PAD + 2;
+	rect.ymin = (float)recti->ymin + 1;
 	rect.ymax = (float)recti->ymax - 1;
 	
 	w = BLI_rctf_size_x(&rect);
@@ -588,7 +575,7 @@ void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol)
 			histogram_draw_one(0.0, 0.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_b, res, is_line);
 	}
 	
-	/* outline, scale gripper */
+	/* outline */
 	draw_scope_end(&rect, scissor);
 }
 
@@ -610,7 +597,7 @@ void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol),
 	
 	rect.xmin = (float)recti->xmin + 1;
 	rect.xmax = (float)recti->xmax - 1;
-	rect.ymin = (float)recti->ymin + SCOPE_RESIZE_PAD + 2;
+	rect.ymin = (float)recti->ymin + 1;
 	rect.ymax = (float)recti->ymax - 1;
 
 	if (scopes->wavefrm_yfac < 0.5f)
@@ -629,14 +616,13 @@ void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol),
 			colorsycc_alpha[c][i] = colorsycc[c][i] * alpha;
 		}
 	}
-			
+
 	glEnable(GL_BLEND);
 	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 	
 	glColor4f(0.f, 0.f, 0.f, 0.3f);
 	uiSetRoundBox(UI_CNR_ALL);
 	uiDrawBox(GL_POLYGON, rect.xmin - 1, rect.ymin - 1, rect.xmax + 1, rect.ymax + 1, 3.0f);
-	
 
 	/* need scissor test, waveform can draw outside of boundary */
 	glGetIntegerv(GL_VIEWPORT, scissor);
@@ -694,7 +680,7 @@ void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol),
 			glScalef(w, h, 0.f);
 			glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_1);
 			glDrawArrays(GL_POINTS, 0, scopes->waveform_tot);
-					
+
 			glDisableClientState(GL_VERTEX_ARRAY);
 			glPopMatrix();
 
@@ -755,10 +741,9 @@ void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol),
 				fdrawline(rect.xmin + w + 2 + c * 2, min, rect.xmin + w + 2 + c * 2, max);
 			}
 		}
-		
 	}
 	
-	/* outline, scale gripper */
+	/* outline */
 	draw_scope_end(&rect, scissor);
 }
 
@@ -840,7 +825,7 @@ void ui_draw_but_VECTORSCOPE(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wco
 	
 	rect.xmin = (float)recti->xmin + 1;
 	rect.xmax = (float)recti->xmax - 1;
-	rect.ymin = (float)recti->ymin + SCOPE_RESIZE_PAD + 2;
+	rect.ymin = (float)recti->ymin + 1;
 	rect.ymax = (float)recti->ymax - 1;
 	
 	w = BLI_rctf_size_x(&rect);
@@ -850,7 +835,7 @@ void ui_draw_but_VECTORSCOPE(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wco
 	diam = (w < h) ? w : h;
 	
 	alpha = scopes->vecscope_alpha * scopes->vecscope_alpha * scopes->vecscope_alpha;
-			
+
 	glEnable(GL_BLEND);
 	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 	
@@ -906,9 +891,9 @@ void ui_draw_but_VECTORSCOPE(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wco
 		glPopMatrix();
 	}
 
-	/* outline, scale gripper */
+	/* outline */
 	draw_scope_end(&rect, scissor);
-		
+
 	glDisable(GL_BLEND);
 }
 
@@ -1505,7 +1490,7 @@ void ui_draw_but_TRACKPREVIEW(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wc
 
 	rect.xmin = (float)recti->xmin + 1;
 	rect.xmax = (float)recti->xmax - 1;
-	rect.ymin = (float)recti->ymin + SCOPE_RESIZE_PAD + 2;
+	rect.ymin = (float)recti->ymin + 1;
 	rect.ymax = (float)recti->ymax - 1;
 
 	width  = BLI_rctf_size_x(&rect) + 1;
@@ -1616,7 +1601,7 @@ void ui_draw_but_TRACKPREVIEW(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wc
 		uiDrawBox(GL_POLYGON, rect.xmin - 1, rect.ymin, rect.xmax + 1, rect.ymax + 1, 3.0f);
 	}
 
-	/* outline, scale gripper */
+	/* outline */
 	draw_scope_end(&rect, scissor);
 
 	glDisable(GL_BLEND);
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index c911e0d..6f06544 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -3942,6 +3942,12 @@ static int ui_do_but_GRIP(bContext *C, uiBlock *block, uiBut *but, uiHandleButto
 	int retval = WM_UI_HANDLER_CONTINUE;
 	const bool horizontal = (BLI_rctf_size_x(&but->rect) < BLI_rctf_size_y(&but->rect));
 
+	/* Note: Having to store org point in window space and recompute it to block "space" each time
+	 *       is not ideal, but this is a way to hack around behavior of ui_window_to_block(), which
+	 *       returns different results when the block is inside a panel or not...
+	 *       See T37739.
+	 */
+
 	mx = event->x;
 	my = event->y;
 	ui_window_to_block(data->region, block, &mx, &my);
@@ -4001,94 +4007,6 @@ static int ui_do_but_LISTROW(bContext *C, uiBut *but, uiHandleButtonData *data,
 	return ui_do_but_EXIT(C, but, data, event);
 }
 
-
-static int ui_do_but_LISTBOX(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const wmEvent *event)
-{
-	uiList *ui_list = but->custom_data;
-	int *size = (int *)but->poin;
-	int mx, my, dragx, dragy;
-	int retval = WM_UI_HANDLER_CONTINUE;
-
-	/* Note: Having to store org point in window space and recompute it to block "space" each time
-	 *       is not ideal, but this is a way to hack around behavior of ui_window_to_block(), which
-	 *       returns different results when the block is inside a panel or not...
-	 *       See T37739.
-	 */
-	dragx = data->dragstartx;
-	dragy = data->dragstarty;
-	ui_window_to_block(data->region, block, &dragx, &dragy);
-
-	mx = event->x;
-	my = event->y;
-	ui_window_to_block(data->region, block, &mx, &my);
-
-	if (data->state == BUTTON_STATE_NUM_EDITING) {
-		if (event->type == ESCKEY) {
-			if (event->val == KM_PRESS) {
-				data->cancel = true;
-				data->escapecancel = true;
-				*size = (int)data->origvalue;
-				button_activate_state(C, but, BUTTON_STATE_EXIT);
-				ui_list->flag &= ~UILST_RESIZING;
-				ED_region_tag_redraw(data->region);
-			}
-		}
-		else if (event->type == LEFTMOUSE && event->val != KM_PRESS) {
-			button_activate_state(C, but, BUTTON_STATE_EXIT);
-			ui_list->flag &= ~UILST_RESIZING;
-			ED_region_tag_redraw(data->region);
-		}
-		else if (event->type == MOUSEMOVE) {
-			/* If we switched from dragged to auto size, suspend shrinking dragging and set dragstarty to a temp
-			 * refpoint.
-			 */
-			if (data->draglastvalue > 0 && *size == 0) {
-				data->draglastvalue = *size;
-				data->dragstartx = data->dragstarty;  /* draglasty already used... */
-				data->dragstarty = event->y;
-			}
-			else {
-				int newsize = *size;
-				int diff = dragy - my;
-
-				diff = iroundf((float)diff / (float)UI_UNIT_Y);
-
-				/* If we are not in autosize mode, default behavior... */
-				if (*size > 0) {
-					/* list template will clamp, but we do not want to reach 0 aka autosize mode! */
-					newsize = data->dragstartvalue + diff;
-				}
-				/* If we are leaving autosize mode (growing dragging), restore to minimal size. */
-				else if (diff > 0) {
-					/* We can't use ui_numedit_apply()... */
-					newsize = ui_list->dyn_data->visual_height_min;
-
-					/* Restore real dragstarty value! */
-					data->dragstarty = data->dragstartx;
-				}
-
-				/* Used to detect switch to/from autosize mode. */
-				data->draglastvalue = newsize;
-
-				if (newsize != *size) {
-					*size = newsize;
-
-					/* We can't use ui_numedit_apply()... */
-					data->dragchange = true;
-					data->applied = data->applied_interactive = true;
-
-					ui_list->flag |= UILST_SCROLL_TO_ACTIVE_ITEM;
-					ED_region_tag_redraw(data->region);
-				}
-			}
-		}
-
-		retval = WM_UI_HANDLER_BREAK;
-	}
-
-	return retval;
-}
-
 static int ui_do_but_BLOCK(bContext *C, uiBut *but, uiHandleButtonData *data, const wmEvent *event)
 {
 	
@@ -5279,40 +5197,22 @@ static int ui_do_but_CURVE(bContext *C, uiBlock *block, uiBut *but, uiHandleButt
 	return WM_UI_HANDLER_CONTINUE;
 }
 
-static bool in_scope_resize_zone(uiBut *but, int UNUSED(x), int y)
-{
-	/* bottom corner return (x > but->rect.xmax - SCOPE_RESIZE_PAD) && (y < but->rect.ymin + SCOPE_RESIZE_PAD); */
-	return (y < but->rect.ymin + SCOPE_RESIZE_PAD);
-}
-
 static bool ui_numedit_but_HISTOGRAM(uiBut *but, uiHandleButtonData *data, int mx, int my)
 {
 	Histogram *hist = (Histogram *)but->poin;
-	/* rcti rect; */
 	bool changed = true;
-	float /* dx, */ dy; /* UNUSED */
-	
-	/* BLI_rcti_rctf_copy(&rect, &but->rect); */
-	
-	/* dx = mx - data->draglastx; */ /* UNUSED */
-	dy = my - data->draglasty;
+	float dy = my - data->draglasty;
+
+	/* scale histogram values (dy / 10 for better control) */
+	const float yfac = min_ff(powf(hist->ymax, 2.0f), 1.0f) * 0.5f;
+	hist->ymax += (dy * 0.1f) * yfac;
+
+	/* 0.1 allows us to see HDR colors up to 10 */
+	CLAMP(hist->ymax, 0.1f, 100.f);
 
-	if (in_scope_resize_zone(but, data->dragstartx, data->dragstarty)) {
-		/* resize histogram widget itself */
-		hist->height = (BLI_rctf_size_y(&but->rect) + (data->dragstarty - my)) / UI_DPI_FAC;
-	}
-	else {
-		/* scale histogram values (dy / 10 for better control) */
-		const float yfac = min_ff(powf(hist->ymax, 2.0f), 1.0f) * 0.5f;
-		hist->ymax += (dy * 0.1f) * yfac;
-	
-		/* 0.1 allows us to 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list