[Bf-blender-cvs] [8e1208c] wiggly-widgets: Widget API:

Antony Riakiotakis noreply at git.blender.org
Wed Oct 1 14:59:15 CEST 2014


Commit: 8e1208c974b4adb9f4cf0bcd61016904f8d145b4
Author: Antony Riakiotakis
Date:   Wed Oct 1 14:59:09 2014 +0200
Branches: wiggly-widgets
https://developer.blender.org/rB8e1208c974b4adb9f4cf0bcd61016904f8d145b4

Widget API:

Code that handles 3D object intersection via GPU selection. We might
want to use raycasting here, but leaving that for when we have it.

Manipulator code now uses this API to do intersection testing

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

M	source/blender/editors/include/ED_transform.h
M	source/blender/editors/space_view3d/space_view3d.c
M	source/blender/editors/transform/transform_manipulator.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/WM_types.h
M	source/blender/windowmanager/intern/wm_event_system.c
M	source/blender/windowmanager/intern/wm_widgets.c

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

diff --git a/source/blender/editors/include/ED_transform.h b/source/blender/editors/include/ED_transform.h
index 9c0b8cc..4718353 100644
--- a/source/blender/editors/include/ED_transform.h
+++ b/source/blender/editors/include/ED_transform.h
@@ -152,7 +152,7 @@ void Transform_Properties(struct wmOperatorType *ot, int flags);
 
 /* view3d manipulators */
 
-int BIF_do_manipulator(struct bContext *C, const struct wmEvent *event, struct wmWidget *widget);
+int BIF_manipulator_handler(struct bContext *C, const struct wmEvent *event, struct wmWidget *widget, int active);
 void BIF_manipulator_render_3d_intersect(const struct bContext *C, struct wmWidget *widget, int selectionbase);
 void BIF_draw_manipulator(const struct bContext *C, struct wmWidget *customdata);
 bool BIF_manipulator_poll(const struct bContext *C, struct wmWidget *customdata);
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index 5061cca..88e8386 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -430,7 +430,11 @@ static void view3d_init(wmWindowManager *UNUSED(wm), ScrArea *UNUSED(sa))
 	if (!manipulator_widget) {
 		ListBase *widgets = WM_widgetmap_find("View3D", SPACE_VIEW3D, RGN_TYPE_WINDOW);
 		
-		manipulator_widget = WM_widget_new(BIF_manipulator_poll, BIF_draw_manipulator, BIF_manipulator_render_3d_intersect, NULL, BIF_do_manipulator, NULL, 0, 0);
+		manipulator_widget = WM_widget_new(BIF_manipulator_poll, 
+										   BIF_draw_manipulator, 
+										   BIF_manipulator_render_3d_intersect, 
+										   NULL, 
+										   BIF_manipulator_handler, NULL, 0, 0);
 		
 		WM_widget_register(widgets, manipulator_widget);
 	}
diff --git a/source/blender/editors/transform/transform_manipulator.c b/source/blender/editors/transform/transform_manipulator.c
index f638e53..a4b6eba 100644
--- a/source/blender/editors/transform/transform_manipulator.c
+++ b/source/blender/editors/transform/transform_manipulator.c
@@ -114,6 +114,8 @@ enum {
 	/* those two stay at the end so the rest can be inferred with bitshifting */
 	MAN_SEL_SCALE_C,
 	MAN_SEL_TRANS_C,
+	
+	MAN_SEL_MAX
 };
 
 /* color codes */
@@ -1710,119 +1712,6 @@ bool BIF_manipulator_poll(const struct bContext *C, wmWidget *UNUSED(customdata)
 	return ((v3d->twflag & V3D_USE_MANIPULATOR) != 0);
 }
 
-static int manipulator_selectbuf(ScrArea *sa, ARegion *ar, const int mval[2], float hotspot)
-{
-	View3D *v3d = sa->spacedata.first;
-	RegionView3D *rv3d = ar->regiondata;
-	rctf rect, selrect;
-	GLuint buffer[64];      // max 4 items per select, so large enuf
-	short hits;
-	const bool selectionbase = 0;
-	const bool do_passes = GPU_select_query_check_active();
-
-	/* XXX check a bit later on this... (ton) */
-	extern void view3d_winmatrix_set(ARegion *ar, View3D *v3d, rctf *rect);
-
-	/* when looking through a selected camera, the manipulator can be at the
-	 * exact same position as the view, skip so we don't break selection */
-	if (fabsf(mat4_to_scale(rv3d->twmat)) < 1e-7f)
-		return 0;
-
-	rect.xmin = mval[0] - hotspot;
-	rect.xmax = mval[0] + hotspot;
-	rect.ymin = mval[1] - hotspot;
-	rect.ymax = mval[1] + hotspot;
-
-	selrect = rect;
-
-	view3d_winmatrix_set(ar, v3d, &rect);
-	mul_m4_m4m4(rv3d->persmat, rv3d->winmat, rv3d->viewmat);
-
-	if (do_passes)
-		GPU_select_begin(buffer, 64, &selrect, GPU_SELECT_NEAREST_FIRST_PASS, 0);
-	else
-		GPU_select_begin(buffer, 64, &selrect, GPU_SELECT_ALL, 0);
-
-	/* do the drawing */
-	if (v3d->twtype & V3D_MANIP_ROTATE) {
-		if (G.debug_value == 3) draw_manipulator_rotate_cyl(v3d, rv3d, MAN_ROT_C & rv3d->twdrawflag, v3d->twtype, MAN_RGB, false, selectionbase);
-		else draw_manipulator_rotate(v3d, rv3d, MAN_ROT_C & rv3d->twdrawflag, v3d->twtype, false, selectionbase);
-	}
-	if (v3d->twtype & V3D_MANIP_SCALE)
-		draw_manipulator_scale(v3d, rv3d, MAN_SCALE_C & rv3d->twdrawflag, v3d->twtype, MAN_RGB, false, selectionbase);
-	if (v3d->twtype & V3D_MANIP_TRANSLATE)
-		draw_manipulator_translate(v3d, rv3d, MAN_TRANS_C & rv3d->twdrawflag, v3d->twtype, MAN_RGB, false, selectionbase);
-
-	hits = GPU_select_end();
-
-	if (do_passes) {
-		GPU_select_begin(buffer, 64, &selrect, GPU_SELECT_NEAREST_SECOND_PASS, hits);
-
-		/* do the drawing */
-		if (v3d->twtype & V3D_MANIP_ROTATE) {
-			if (G.debug_value == 3) draw_manipulator_rotate_cyl(v3d, rv3d, MAN_ROT_C & rv3d->twdrawflag, v3d->twtype, MAN_RGB, false, selectionbase);
-			else draw_manipulator_rotate(v3d, rv3d, MAN_ROT_C & rv3d->twdrawflag, v3d->twtype, false, selectionbase);
-		}
-		if (v3d->twtype & V3D_MANIP_SCALE)
-			draw_manipulator_scale(v3d, rv3d, MAN_SCALE_C & rv3d->twdrawflag, v3d->twtype, MAN_RGB, false, selectionbase);
-		if (v3d->twtype & V3D_MANIP_TRANSLATE)
-			draw_manipulator_translate(v3d, rv3d, MAN_TRANS_C & rv3d->twdrawflag, v3d->twtype, MAN_RGB, false, selectionbase);
-
-		GPU_select_end();
-	}
-
-	view3d_winmatrix_set(ar, v3d, NULL);
-	mul_m4_m4m4(rv3d->persmat, rv3d->winmat, rv3d->viewmat);
-
-	if (hits == 1) {
-		int val = buffer[3] - selectionbase;
-		
-		if (val == MAN_SEL_TRANS_C) return MAN_TRANS_C;
-		else if (val == MAN_SEL_SCALE_C) return MAN_SCALE_C;
-		else return 1 << val;
-	}
-	else if (hits > 1) {
-		GLuint val, dep, mindep = 0, mindeprot = 0, minval = 0, minvalrot = 0;
-		int a;
-
-		/* we compare the hits in buffer, but value centers highest */
-		/* we also store the rotation hits separate (because of arcs) and return hits on other widgets if there are */
-
-		for (a = 0; a < hits; a++) {
-			dep = buffer[4 * a + 1];
-			val = buffer[4 * a + 3] - selectionbase;
-
-			if (val == MAN_SEL_TRANS_C) {
-				return MAN_TRANS_C;
-			}
-			else if (val == MAN_SEL_SCALE_C) {
-				return MAN_SCALE_C;
-			}
-			else {
-				if (val >= MAN_SEL_ROT_X && val <= MAN_SEL_ROT_T) {
-					if (minvalrot == 0 || dep < mindeprot) {
-						mindeprot = dep;
-						minvalrot = 1 << val;
-					}
-				}
-				else {
-					if (minval == 0 || dep < mindep) {
-						mindep = dep;
-						minval = 1 << val;
-					}
-				}
-			}
-		}
-
-		if (minval)
-			return minval;
-		else
-			return minvalrot;
-	}
-	return 0;
-}
-
-
 void BIF_manipulator_render_3d_intersect(const bContext *C, wmWidget *UNUSED(widget), int selectionbase)
 {
 	ScrArea *sa = CTX_wm_area(C);
@@ -1837,21 +1726,20 @@ void BIF_manipulator_render_3d_intersect(const bContext *C, wmWidget *UNUSED(wid
 	
 	/* do the drawing */
 	if (v3d->twtype & V3D_MANIP_ROTATE) {
-		if (G.debug_value == 3) draw_manipulator_rotate_cyl(v3d, rv3d, MAN_ROT_C & rv3d->twdrawflag, v3d->twtype, MAN_RGB, false, true);
-		else draw_manipulator_rotate(v3d, rv3d, MAN_ROT_C & rv3d->twdrawflag, v3d->twtype, false, true);
+		if (G.debug_value == 3) draw_manipulator_rotate_cyl(v3d, rv3d, MAN_ROT_C & rv3d->twdrawflag, v3d->twtype, MAN_RGB, false, selectionbase);
+		else draw_manipulator_rotate(v3d, rv3d, MAN_ROT_C & rv3d->twdrawflag, v3d->twtype, false, selectionbase);
 	}
 	if (v3d->twtype & V3D_MANIP_SCALE)
-		draw_manipulator_scale(v3d, rv3d, MAN_SCALE_C & rv3d->twdrawflag, v3d->twtype, MAN_RGB, false, true);
+		draw_manipulator_scale(v3d, rv3d, MAN_SCALE_C & rv3d->twdrawflag, v3d->twtype, MAN_RGB, false, selectionbase);
 	if (v3d->twtype & V3D_MANIP_TRANSLATE)
 		draw_manipulator_translate(v3d, rv3d, MAN_TRANS_C & rv3d->twdrawflag, v3d->twtype, MAN_RGB, false, selectionbase);
 }
 
 /* return 0; nothing happened */
-int BIF_do_manipulator(bContext *C, const struct wmEvent *event, wmWidget *UNUSED(widget))
+int BIF_manipulator_handler(bContext *C, const struct wmEvent *event, wmWidget *UNUSED(widget), int active)
 {
 	ScrArea *sa = CTX_wm_area(C);
 	View3D *v3d = sa->spacedata.first;
-	ARegion *ar = CTX_wm_region(C);
 	int constraint_axis[3] = {0, 0, 0};
 	int val;
 	int shift = event->shift;
@@ -1866,14 +1754,23 @@ int BIF_do_manipulator(bContext *C, const struct wmEvent *event, wmWidget *UNUSE
 		return OPERATOR_PASS_THROUGH;
 	}
 	
-	view3d_operator_needs_opengl(C);
+	if (active != -1) {
+		if (active == MAN_SEL_TRANS_C) {
+			val = MAN_TRANS_C;
+		}
+		else if (active == MAN_SEL_SCALE_C) {
+			val = MAN_SCALE_C;
+		}
+		else {
+			val = 1 << active;
+		}
+	}
+	else 
+		val = 0;
 	
-	// find the hotspots first test narrow hotspot
-	val = manipulator_selectbuf(sa, ar, event->mval, 0.5f * (float)U.tw_hotspot);
 	if (val) {
 		// drawflags still global, for drawing call above
-		drawflags = manipulator_selectbuf(sa, ar, event->mval, 0.2f * (float)U.tw_hotspot);
-		if (drawflags == 0) drawflags = val;
+		drawflags = val;//manipulator_selectbuf(sa, ar, event->mval, 0.2f * (float)U.tw_hotspot);
 
 		if (drawflags & MAN_TRANS_C) {
 			switch (drawflags) {
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 8d312f6..f75ac2f 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -463,9 +463,9 @@ bool        WM_event_is_tablet(const struct wmEvent *event);
 /* widget API */
 struct wmWidget *WM_widget_new(bool (*poll)(const struct bContext *, struct wmWidget *),
                                void (*draw)(const struct bContext *, struct wmWidget *),
-							   void (*render_3d_intersection)(const struct bContext *C, struct wmWidget *customdata, int selectionbase),
+							   void (*render_3d_intersection)(const struct bContext *, struct wmWidget *, int),
 							   int  (*intersect)(struct bContext *C, const struct wmEvent *event, struct wmWidget *customdata),
-                               int  (*handler)(struct bContext *, const struct wmEvent *, struct wmWidget *),
+                               int  (*handler)(struct bContext *, const struct wmEvent *, struct wmWidget *, int active),
                                void *customdata, bool free_data, bool requires_ogl);
 
 void WM_widgets_delete(ListBase *widgetlist, struct wmWidget *widget);
@@ -475,6 +475,7 @@ void WM_event_add_widget_handler(struct ARegion *ar);
 bool WM_widget_register(ListBase *widgetlist, struct wmWidget *widget);
 void WM_widget_unregister(ListBase *widgetlist, struct wmWidget *widget);
 struct ListBase *WM_widgetmap_find(const char *idname, int spaceid, int regionid);
+int WM_widget_find_active_3D (ListBase *widg

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list