[Bf-blender-cvs] [1709562] pie-menus: Some cleanup, refresh pie direction and drawing on the same events that fired the pie menu, also some debug prints. Note, this is not ideal, normally we want to just ignore those events, will look into that later.

Antony Riakiotakis noreply at git.blender.org
Tue Jun 3 16:06:05 CEST 2014


Commit: 1709562a04a831ff91fe53fe4bebda61a7715ea0
Author: Antony Riakiotakis
Date:   Tue Jun 3 17:05:46 2014 +0300
https://developer.blender.org/rB1709562a04a831ff91fe53fe4bebda61a7715ea0

Some cleanup, refresh pie direction and drawing on the same events that
fired the pie menu, also some debug prints. Note, this is not ideal,
normally we want to just ignore those events, will look into that later.

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

M	source/blender/editors/interface/interface.c
M	source/blender/editors/interface/interface_handlers.c
M	source/blender/editors/interface/interface_regions.c
M	source/blender/editors/interface/interface_widgets.c

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

diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 951eecd..6ca42f1 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -3056,7 +3056,7 @@ static uiBut *ui_def_but(uiBlock *block, int type, int retval, const char *str,
 		}
 	}
 
-	if ((block->flag & UI_BLOCK_RADIAL)) {
+	if (block->flag & UI_BLOCK_RADIAL) {
 		but->drawflag |= UI_BUT_ICON_LEFT;
 	}
 	else if ((block->flag & UI_BLOCK_LOOP) ||
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 8dd96d9..df81168 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -6228,7 +6228,7 @@ static bool ui_but_contains_pt(uiBut *but, float mx, float my)
 	return BLI_rctf_isect_pt(&but->rect, mx, my);
 }
 
-static bool ui_but_isect_pie_seg(uiBlock *block, uiBut *but, const float seg[2])
+static bool ui_but_isect_pie_seg(uiBlock *block, uiBut *but)
 {
 	float angle_range = (block->num_pie_items < 5) ? M_PI_4 : M_PI_4 / 2.0f;
 	float angle_pie;
@@ -6271,7 +6271,7 @@ static bool ui_but_isect_pie_seg(uiBlock *block, uiBut *but, const float seg[2])
 	vec[0] = cosf(angle_pie);
 	vec[1] = sinf(angle_pie);
 
-	if (saacos(dot_v2v2(vec, seg)) < angle_range)
+	if (saacos(dot_v2v2(vec, block->pie_dir)) < angle_range)
 		return true;
 
 	return false;
@@ -6379,20 +6379,6 @@ static bool ui_mouse_inside_region(ARegion *ar, int x, int y)
 	return true;
 }
 
-static void ui_block_calculate_pie_segment(const float mx, const float my, float seg2[2], uiBlock *block)
-{
-	float seg1[2];
-
-	seg1[0] = BLI_rctf_cent_x(&block->rect);
-	seg1[1] = BLI_rctf_cent_y(&block->rect);
-
-	seg2[0] = mx - seg1[0];
-	seg2[1] = my - seg1[1];
-	normalize_v2(seg2);
-
-	copy_v2_v2(block->pie_dir, seg2);
-}
-
 
 static bool ui_mouse_inside_button(ARegion *ar, uiBut *but, int x, int y)
 {
@@ -6408,11 +6394,7 @@ static bool ui_mouse_inside_button(ARegion *ar, uiBut *but, int x, int y)
 	ui_window_to_block_fl(ar, block, &mx, &my);
 
 	if (but->dt == UI_EMBOSSR) {
-		float seg[2];
-
-		ui_block_calculate_pie_segment(mx, my, seg, block);
-
-		if (!ui_but_isect_pie_seg(block, but, seg)) {
+		if (!ui_but_isect_pie_seg(block, but)) {
 			return false;
 		}
 	}
@@ -6459,7 +6441,6 @@ static uiBut *ui_but_find_mouse_over_ex(ARegion *ar, const int x, const int y, c
 	uiBut *but, *butover = NULL;
 
 	float mx, my;
-	float seg[2];
 
 //	if (!win->active)
 //		return NULL;
@@ -6471,14 +6452,10 @@ static uiBut *ui_but_find_mouse_over_ex(ARegion *ar, const int x, const int y, c
 		my = y;
 		ui_window_to_block_fl(ar, block, &mx, &my);
 
-		if (block->flag & UI_BLOCK_RADIAL) {
-			ui_block_calculate_pie_segment(mx, my, seg, block);
-		}
-
 		for (but = block->buttons.last; but; but = but->prev) {
 			if (ui_is_but_interactive(but, labeledit)) {
 				if (but->dt == UI_EMBOSSR) {
-					if (ui_but_isect_pie_seg(block, but, seg)) {
+					if (ui_but_isect_pie_seg(block, but)) {
 						butover = but;
 						break;
 					}
@@ -7798,6 +7775,25 @@ static int ui_handle_menu_button(bContext *C, const wmEvent *event, uiPopupBlock
 	return retval;
 }
 
+static void ui_block_calculate_pie_segment(uiBlock *block, const float mx, const float my)
+{
+	float seg1[2];
+	float seg2[2];
+
+	seg1[0] = BLI_rctf_cent_x(&block->rect);
+	seg1[1] = BLI_rctf_cent_y(&block->rect);
+
+	print_v2("center of block", seg1);
+	printf("event: %f %f\n", mx, my);
+
+	seg2[0] = mx - seg1[0];
+	seg2[1] = my - seg1[1];
+
+	normalize_v2_v2(block->pie_dir, seg2);
+
+	print_v2("calculation", seg2);
+}
+
 static int ui_handle_menu_event(
         bContext *C, const wmEvent *event, uiPopupBlockHandle *menu,
         int level, const bool is_parent_inside, const bool is_parent_menu, const bool is_floating)
@@ -7816,8 +7812,20 @@ static int ui_handle_menu_event(
 
 	mx = event->x;
 	my = event->y;
+	printf("event: %d %d\n", mx, my);
 	ui_window_to_block(ar, block, &mx, &my);
 
+	if (block->flag & UI_BLOCK_RADIAL) {
+		ui_block_calculate_pie_segment(block, mx, my);
+
+		if ((event->type == block->event) && !(event->val == KM_RELEASE)){
+			printf("initial key press\n");
+
+			ED_region_tag_redraw(ar);
+			return WM_UI_HANDLER_BREAK;
+		}
+	}
+
 	/* check if mouse is inside block */
 	inside = BLI_rctf_isect_pt(&block->rect, mx, my);
 	inside_title = inside && ((my + (UI_UNIT_Y * 1.5f)) > block->rect.ymax);
@@ -7857,15 +7865,20 @@ static int ui_handle_menu_event(
 		if (event->customdata == menu->scrolltimer)
 			ui_menu_scroll(ar, block, my, NULL);
 	}
-	else if ((block->flag & UI_BLOCK_RADIAL) && (event->type == block->event) && event->val == KM_RELEASE) {
+	else if ((block->flag & UI_BLOCK_RADIAL) &&
+		     (((event->type == block->event) && event->val == KM_RELEASE) ||
+		     ((event->type == LEFTMOUSE) && event->val == KM_PRESS)))
+	{
 		if (but) {
 			wmEvent local_event = *event;
+
 			local_event.type = RETKEY;
 			local_event.val = KM_PRESS;
-			ui_handle_menu_button(C, &local_event, menu);
+			ui_handle_button_event(C, &local_event, but);
 			local_event.type = RETKEY;
 			local_event.val = KM_RELEASE;
-			return ui_handle_menu_button(C, &local_event, menu);
+			ui_handle_button_event(C, &local_event, but);
+			return WM_UI_HANDLER_CONTINUE;
 		}
 		else {
 			menu->menuretval = UI_RETURN_CANCEL;
@@ -7881,9 +7894,10 @@ static int ui_handle_menu_event(
 
 			/* mouse move should always refresh the area for pie menus */
 			if (block->flag & UI_BLOCK_RADIAL) {
+				printf("refresh\n");
 				ED_region_tag_redraw(ar);
 			}
-			
+
 			/* add menu scroll timer, if needed */
 			if (ui_menu_scroll_test(block, my))
 				if (menu->scrolltimer == NULL)
diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c
index 421e95e..9d58e8a 100644
--- a/source/blender/editors/interface/interface_regions.c
+++ b/source/blender/editors/interface/interface_regions.c
@@ -2434,7 +2434,7 @@ static uiBlock *ui_block_func_PIE(bContext *C, uiPopupBlockHandle *handle, void
 	if (BLI_findindex(&handle->region->uiblocks, block) == -1)
 		uiBlockSetRegion(block, handle->region);
 
-	block->direction = UI_DOWN;
+	block->direction = direction;
 
 	uiBlockLayoutResolve(block, &width, &height);
 
@@ -2468,10 +2468,6 @@ static uiBlock *ui_block_func_PIE(bContext *C, uiPopupBlockHandle *handle, void
 	block->my = offset[1];
 	block->bounds_type = UI_BLOCK_BOUNDS_PIE_CENTER;
 
-	/* pies: useful for later, but keep it basic for now
-	if (pup->slideout)
-		uiBlockSetDirection(block, UI_RIGHT);
-	*/
 	uiEndBlock(C, block);
 
 	return pie->block_radial;
@@ -2490,7 +2486,7 @@ struct uiPieMenu *uiPieMenuBegin(struct bContext *C, const char *title, int icon
 	uiBut *but;
 
 	pie->block_radial = uiBeginBlock(C, NULL, __func__, UI_EMBOSSR);
-	pie->block_radial->flag |= UI_BLOCK_POPUP_MEMORY;
+	//pie->block_radial->flag |= UI_BLOCK_POPUP_MEMORY;
 	pie->block_radial->puphash = ui_popup_menu_hash(title);
 	pie->block_radial->flag |= UI_BLOCK_RADIAL;
 	pie->block_radial->event = event;
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 07d0492..1409f93 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -3691,6 +3691,7 @@ void ui_draw_pie_center(uiBlock *block)
 	glVertex2f(block->pie_dir[0] * (pie_radius_internal + 10.0f), block->pie_dir[1] * (pie_radius_internal + 10.0f));
 	glEnd();
 
+	print_v2("direction", block->pie_dir);
 	glDisable(GL_BLEND);
 	glPopMatrix();
 }




More information about the Bf-blender-cvs mailing list