Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2013-04-02 14:48:11 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-04-02 14:48:11 +0400
commit37bf7dd98a494c1dd80459aa017bb796f699261b (patch)
tree81e5ff2c24c074b0d64e88b37e186496a81e6a8d /source/blender/editors
parent932820499a2a012cc0bb7df7ae4f7a8275d2944f (diff)
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.
Diffstat (limited to 'source/blender/editors')
-rw-r--r--source/blender/editors/include/ED_space_api.h4
-rw-r--r--source/blender/editors/mesh/editmesh_bevel.c29
-rw-r--r--source/blender/editors/mesh/editmesh_inset.c44
-rw-r--r--source/blender/editors/util/ed_util.c26
4 files changed, 85 insertions, 18 deletions
diff --git a/source/blender/editors/include/ED_space_api.h b/source/blender/editors/include/ED_space_api.h
index a40cf90f7ad..4fbe01a5fc7 100644
--- a/source/blender/editors/include/ED_space_api.h
+++ b/source/blender/editors/include/ED_space_api.h
@@ -74,6 +74,8 @@ void *ED_region_draw_cb_activate(struct ARegionType *,
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__ */
-
diff --git a/source/blender/editors/mesh/editmesh_bevel.c b/source/blender/editors/mesh/editmesh_bevel.c
index d79f12551dd..a34ca4dcb9e 100644
--- a/source/blender/editors/mesh/editmesh_bevel.c
+++ b/source/blender/editors/mesh/editmesh_bevel.c
@@ -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 void edbm_bevel_update_header(wmOperator *op, bContext *C)
}
}
-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 @@ static int edbm_bevel_init(bContext *C, wmOperator *op, int is_modal)
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 @@ static void edbm_bevel_exit(bContext *C, wmOperator *op)
}
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;
diff --git a/source/blender/editors/mesh/editmesh_inset.c b/source/blender/editors/mesh/editmesh_inset.c
index 10f384f5b7c..f7cf32a074f 100644
--- a/source/blender/editors/mesh/editmesh_inset.c
+++ b/source/blender/editors/mesh/editmesh_inset.c
@@ -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 void edbm_inset_update_header(wmOperator *op, bContext *C)
}
-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,8 +125,16 @@ static int edbm_inset_init(bContext *C, wmOperator *op, int is_modal)
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 @@ static void edbm_inset_exit(bContext *C, wmOperator *op)
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 @@ static int edbm_inset_cancel(bContext *C, wmOperator *op)
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 @@ static int edbm_inset_calc(wmOperator *op)
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,
diff --git a/source/blender/editors/util/ed_util.c b/source/blender/editors/util/ed_util.c
index 73062c57526..7e14e8cf2a3 100644
--- a/source/blender/editors/util/ed_util.c
+++ b/source/blender/editors/util/ed_util.c
@@ -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 @@ void unpack_menu(bContext *C, const char *opname, const char *id_name, const cha
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);
+}