[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55716] trunk/blender/source/blender/ editors: draw helper lines for inset and bevel operators, the mouse distance from the selection center was used, but often it was hard to tell where this was and you'd have to guess.

Campbell Barton ideasman42 at gmail.com
Tue Apr 2 12:48:12 CEST 2013


Revision: 55716
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55716
Author:   campbellbarton
Date:     2013-04-02 10:48:11 +0000 (Tue, 02 Apr 2013)
Log Message:
-----------
draw helper lines for inset and bevel operators, the mouse distance from the selection center was used, but often it was hard to tell where this was and you'd have to guess.
adds ED_region_draw_mouse_line_cb() generic draw callback for mouse helper lines.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/include/ED_space_api.h
    trunk/blender/source/blender/editors/mesh/editmesh_bevel.c
    trunk/blender/source/blender/editors/mesh/editmesh_inset.c
    trunk/blender/source/blender/editors/util/ed_util.c

Modified: trunk/blender/source/blender/editors/include/ED_space_api.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_space_api.h	2013-04-02 07:27:39 UTC (rev 55715)
+++ trunk/blender/source/blender/editors/include/ED_space_api.h	2013-04-02 10:48:11 UTC (rev 55716)
@@ -74,6 +74,8 @@
 void ED_region_draw_cb_draw(const struct bContext *, struct ARegion *, int);
 void ED_region_draw_cb_exit(struct ARegionType *, void *);
 void *ED_region_draw_cb_customdata(void *handle);
+/* generic callbacks */
+/* ed_util.c */
+void ED_region_draw_mouse_line_cb(const struct bContext *C, struct ARegion *ar, void *arg_info);
 
 #endif /* __ED_SPACE_API_H__ */
-

Modified: trunk/blender/source/blender/editors/mesh/editmesh_bevel.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/editmesh_bevel.c	2013-04-02 07:27:39 UTC (rev 55715)
+++ trunk/blender/source/blender/editors/mesh/editmesh_bevel.c	2013-04-02 10:48:11 UTC (rev 55716)
@@ -34,6 +34,7 @@
 #include "BLF_translation.h"
 
 #include "BKE_context.h"
+#include "BKE_global.h"
 #include "BKE_tessmesh.h"
 
 #include "RNA_define.h"
@@ -45,6 +46,7 @@
 #include "ED_mesh.h"
 #include "ED_numinput.h"
 #include "ED_screen.h"
+#include "ED_space_api.h"
 #include "ED_transform.h"
 #include "ED_view3d.h"
 
@@ -55,13 +57,17 @@
 
 typedef struct {
 	BMEditMesh *em;
-	BMBackup mesh_backup;
-	int mcenter[2];
 	float initial_length;
 	float pixel_size;  /* use when mouse input is interpreted as spatial distance */
-	int is_modal;
+	bool is_modal;
 	NumInput num_input;
 	float shift_factor; /* The current factor when shift is pressed. Negative when shift not active. */
+
+	/* modal only */
+	int mcenter[2];
+	BMBackup mesh_backup;
+	void *draw_handle_pixel;
+	short twtype;
 } BevelData;
 
 #define HEADER_LENGTH 180
@@ -85,7 +91,7 @@
 	}
 }
 
-static int edbm_bevel_init(bContext *C, wmOperator *op, int is_modal)
+static int edbm_bevel_init(bContext *C, wmOperator *op, const bool is_modal)
 {
 	Object *obedit = CTX_data_edit_object(C);
 	BMEditMesh *em = BMEdit_FromObject(obedit);
@@ -105,8 +111,16 @@
 	opdata->num_input.flag = NUM_NO_NEGATIVE;
 
 	/* avoid the cost of allocating a bm copy */
-	if (is_modal)
+	if (is_modal) {
+		View3D *v3d = CTX_wm_view3d(C);
+		ARegion *ar = CTX_wm_region(C);
+
 		opdata->mesh_backup = EDBM_redo_state_store(em);
+		opdata->draw_handle_pixel = ED_region_draw_cb_activate(ar->type, ED_region_draw_mouse_line_cb, opdata->mcenter, REGION_DRAW_POST_PIXEL);
+		G.moving = true;
+		opdata->twtype = v3d->twtype;
+		v3d->twtype = 0;
+	}
 
 	return 1;
 }
@@ -163,7 +177,12 @@
 	}
 
 	if (opdata->is_modal) {
+		View3D *v3d = CTX_wm_view3d(C);
+		ARegion *ar = CTX_wm_region(C);
 		EDBM_redo_state_free(&opdata->mesh_backup, NULL, false);
+		ED_region_draw_cb_exit(ar->type, opdata->draw_handle_pixel);
+		v3d->twtype = opdata->twtype;
+		G.moving = false;
 	}
 	MEM_freeN(opdata);
 	op->customdata = NULL;

Modified: trunk/blender/source/blender/editors/mesh/editmesh_inset.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/editmesh_inset.c	2013-04-02 07:27:39 UTC (rev 55715)
+++ trunk/blender/source/blender/editors/mesh/editmesh_inset.c	2013-04-02 10:48:11 UTC (rev 55716)
@@ -34,6 +34,7 @@
 #include "BLF_translation.h"
 
 #include "BKE_context.h"
+#include "BKE_global.h"
 #include "BKE_tessmesh.h"
 
 #include "RNA_define.h"
@@ -45,6 +46,7 @@
 #include "ED_mesh.h"
 #include "ED_numinput.h"
 #include "ED_screen.h"
+#include "ED_space_api.h"
 #include "ED_transform.h"
 #include "ED_view3d.h"
 
@@ -56,16 +58,20 @@
 typedef struct {
 	float old_thickness;
 	float old_depth;
-	int mcenter[2];
-	int modify_depth;
+	bool modify_depth;
 	float initial_length;
 	float pixel_size;  /* use when mouse input is interpreted as spatial distance */
-	int is_modal;
-	int shift;
+	bool is_modal;
+	bool shift;
 	float shift_amount;
-	BMBackup backup;
 	BMEditMesh *em;
 	NumInput num_input;
+
+	/* modal only */
+	int mcenter[2];
+	BMBackup mesh_backup;
+	void *draw_handle_pixel;
+	short twtype;
 } InsetData;
 
 
@@ -100,7 +106,7 @@
 }
 
 
-static int edbm_inset_init(bContext *C, wmOperator *op, int is_modal)
+static int edbm_inset_init(bContext *C, wmOperator *op, const bool is_modal)
 {
 	InsetData *opdata;
 	Object *obedit = CTX_data_edit_object(C);
@@ -119,9 +125,17 @@
 	initNumInput(&opdata->num_input);
 	opdata->num_input.idx_max = 1; /* Two elements. */
 
-	if (is_modal)
-		opdata->backup = EDBM_redo_state_store(em);
+	if (is_modal) {
+		View3D *v3d = CTX_wm_view3d(C);
+		ARegion *ar = CTX_wm_region(C);
 
+		opdata->mesh_backup = EDBM_redo_state_store(em);
+		opdata->draw_handle_pixel = ED_region_draw_cb_activate(ar->type, ED_region_draw_mouse_line_cb, opdata->mcenter, REGION_DRAW_POST_PIXEL);
+		G.moving = true;
+		opdata->twtype = v3d->twtype;
+		v3d->twtype = 0;
+	}
+
 	return 1;
 }
 
@@ -132,8 +146,14 @@
 
 	opdata = op->customdata;
 
-	if (opdata->is_modal)
-		EDBM_redo_state_free(&opdata->backup, NULL, false);
+	if (opdata->is_modal) {
+		View3D *v3d = CTX_wm_view3d(C);
+		ARegion *ar = CTX_wm_region(C);
+		EDBM_redo_state_free(&opdata->mesh_backup, NULL, false);
+		ED_region_draw_cb_exit(ar->type, opdata->draw_handle_pixel);
+		v3d->twtype = opdata->twtype;
+		G.moving = false;
+	}
 
 	if (sa) {
 		ED_area_headerprint(sa, NULL);
@@ -147,7 +167,7 @@
 
 	opdata = op->customdata;
 	if (opdata->is_modal) {
-		EDBM_redo_state_free(&opdata->backup, opdata->em, true);
+		EDBM_redo_state_free(&opdata->mesh_backup, opdata->em, true);
 		EDBM_update_generic(opdata->em, false, true);
 	}
 
@@ -176,7 +196,7 @@
 	em = opdata->em;
 
 	if (opdata->is_modal) {
-		EDBM_redo_state_restore(opdata->backup, em, false);
+		EDBM_redo_state_restore(opdata->mesh_backup, em, false);
 	}
 
 	EDBM_op_init(em, &bmop, op,

Modified: trunk/blender/source/blender/editors/util/ed_util.c
===================================================================
--- trunk/blender/source/blender/editors/util/ed_util.c	2013-04-02 07:27:39 UTC (rev 55715)
+++ trunk/blender/source/blender/editors/util/ed_util.c	2013-04-02 10:48:11 UTC (rev 55716)
@@ -37,11 +37,15 @@
 
 #include "DNA_mesh_types.h"
 #include "DNA_object_types.h"
+#include "DNA_screen_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_packedFile_types.h"
 
 #include "BLI_blenlib.h"
 
+#include "BIF_gl.h"
+#include "BIF_glutil.h"
+
 #include "BLF_translation.h"
 
 #include "BKE_context.h"
@@ -54,6 +58,7 @@
 #include "ED_mesh.h"
 #include "ED_object.h"
 #include "ED_sculpt.h"
+#include "ED_space_api.h"
 #include "ED_util.h"
 
 #include "UI_interface.h"
@@ -255,3 +260,24 @@
 
 	uiPupMenuEnd(C, pup);
 }
+
+/* ********************* generic callbacks for drawcall api *********************** */
+
+/**
+ * Callback that draws a line between the mouse and a position given as the initial argument.
+ */
+void ED_region_draw_mouse_line_cb(const bContext *C, ARegion *ar, void *arg_info)
+{
+	wmWindow *win = CTX_wm_window(C);
+	const int *mval_src = (int *)arg_info;
+	const int mval_dst[2] = {win->eventstate->x - ar->winrct.xmin,
+	                         win->eventstate->y - ar->winrct.ymin};
+
+	UI_ThemeColor(TH_WIRE);
+	setlinestyle(3);
+	glBegin(GL_LINE_STRIP);
+	glVertex2iv(mval_dst);
+	glVertex2iv(mval_src);
+	glEnd();
+	setlinestyle(0);
+}




More information about the Bf-blender-cvs mailing list