Revision: 48913
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48913
Author: mont29
Date: 2012-07-14 14:03:36 +0000 (Sat, 14 Jul 2012)
Log Message:
-----------
Fix [#32086] Missing bevel "hold shift" for better accuracy.
This commit adds "shift" and numtype to both Bevel and Inset mesh operators.
It also gets rid of the magicnumber used in NumInput to str operation
(currently, 20 chars per element, now defined as NUM_STR_REP_LEN in
ED_numinput.h).
Modified Paths:
--------------
trunk/blender/source/blender/editors/animation/anim_markers.c
trunk/blender/source/blender/editors/include/ED_numinput.h
trunk/blender/source/blender/editors/mesh/editmesh_tools.c
trunk/blender/source/blender/editors/transform/transform.c
trunk/blender/source/blender/editors/util/numinput.c
Modified: trunk/blender/source/blender/editors/animation/anim_markers.c
===================================================================
--- trunk/blender/source/blender/editors/animation/anim_markers.c
2012-07-14 13:04:01 UTC (rev 48912)
+++ trunk/blender/source/blender/editors/animation/anim_markers.c
2012-07-14 14:03:36 UTC (rev 48913)
@@ -848,14 +848,14 @@
}
if (evt->val == KM_PRESS) {
- float vec[3];
- char str_tx[256];
+ float vec;
+ char str_tx[NUM_STR_REP_LEN];
if (handleNumInput(&mm->num, evt)) {
- applyNumInput(&mm->num, vec);
+ applyNumInput(&mm->num, &vec);
outputNumInput(&mm->num, str_tx);
- RNA_int_set(op->ptr, "frames", vec[0]);
+ RNA_int_set(op->ptr, "frames", vec);
ed_marker_move_apply(op);
// ed_marker_header_update(C, op, str, (int)vec[0]);
// strcat(str, str_tx);
Modified: trunk/blender/source/blender/editors/include/ED_numinput.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_numinput.h 2012-07-14
13:04:01 UTC (rev 48912)
+++ trunk/blender/source/blender/editors/include/ED_numinput.h 2012-07-14
14:03:36 UTC (rev 48913)
@@ -57,6 +57,7 @@
/*********************** NumInput ********************************/
void initNumInput(NumInput *n);
+#define NUM_STR_REP_LEN 20 /* str must be NUM_STR_LEN * (idx_max + 1) length.
*/
void outputNumInput(NumInput *n, char *str);
short hasNumInput(NumInput *n);
void applyNumInput(NumInput *n, float *vec);
Modified: trunk/blender/source/blender/editors/mesh/editmesh_tools.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/editmesh_tools.c 2012-07-14
13:04:01 UTC (rev 48912)
+++ trunk/blender/source/blender/editors/mesh/editmesh_tools.c 2012-07-14
14:03:36 UTC (rev 48913)
@@ -58,6 +58,7 @@
#include "WM_types.h"
#include "ED_mesh.h"
+#include "ED_numinput.h"
#include "ED_object.h"
#include "ED_screen.h"
#include "ED_transform.h"
@@ -4305,23 +4306,31 @@
int mcenter[2];
float initial_length;
int is_modal;
+ NumInput num_input;
+ float shift_factor; /* The current factor when shift is pressed.
Negative when shift not active. */
} BevelData;
#define HEADER_LENGTH 180
static void edbm_bevel_update_header(wmOperator *op, bContext *C)
{
- static char str[] = "Confirm: Enter/LClick, Cancel: (Esc/RMB), factor:
%f, Use Dist (D): %s: Use Even (E): %s";
+ static char str[] = "Confirm: Enter/LClick, Cancel: (Esc/RMB), factor:
%s, Use Dist (D): %s: Use Even (E): %s";
char msg[HEADER_LENGTH];
ScrArea *sa = CTX_wm_area(C);
+ BevelData *opdata = op->customdata;
if (sa) {
+ char factor_str[NUM_STR_REP_LEN];
+ if (hasNumInput(&opdata->num_input))
+ outputNumInput(&opdata->num_input, factor_str);
+ else
+ BLI_snprintf(factor_str, NUM_STR_REP_LEN, "%f",
RNA_float_get(op->ptr, "percent"));
BLI_snprintf(msg, HEADER_LENGTH, str,
- RNA_float_get(op->ptr, "percent"),
+ factor_str,
RNA_boolean_get(op->ptr, "use_dist") ? "On" :
"Off",
RNA_boolean_get(op->ptr, "use_even") ? "On" : "Off"
- );
+ );
ED_area_headerprint(sa, msg);
}
@@ -4384,7 +4393,11 @@
opdata->li = li;
opdata->weights = NULL;
opdata->is_modal = is_modal;
-
+ opdata->shift_factor = -1.0f;
+
+ initNumInput(&opdata->num_input);
+ opdata->num_input.flag = NUM_NO_NEGATIVE;
+
/* avoid the cost of allocating a bm copy */
if (is_modal)
opdata->mesh_backup = EDBM_redo_state_store(em);
@@ -4523,8 +4536,21 @@
static int edbm_bevel_modal(bContext *C, wmOperator *op, wmEvent *event)
{
BevelData *opdata = op->customdata;
-// Scene *scene = CTX_data_scene(C);
+ if (event->val == KM_PRESS) {
+ /* Try to handle numeric inputs... */
+ float factor;
+
+ if (handleNumInput(&opdata->num_input, event)) {
+ applyNumInput(&opdata->num_input, &factor);
+ CLAMP(factor, 0.0f, 1.0f);
+ RNA_float_set(op->ptr, "percent", factor);
+
+ edbm_bevel_calc(C, op);
+ edbm_bevel_update_header(op, C);
+ return OPERATOR_RUNNING_MODAL;
+ }
+ }
switch (event->type) {
case ESCKEY:
case RIGHTMOUSE:
@@ -4532,22 +4558,32 @@
return OPERATOR_CANCELLED;
case MOUSEMOVE:
- {
- float factor;
- float mdiff[2];
+ if (!hasNumInput(&opdata->num_input)) {
+ float factor;
+ float mdiff[2];
- mdiff[0] = opdata->mcenter[0] - event->mval[0];
- mdiff[1] = opdata->mcenter[1] - event->mval[1];
+ mdiff[0] = opdata->mcenter[0] - event->mval[0];
+ mdiff[1] = opdata->mcenter[1] - event->mval[1];
- factor = len_v2(mdiff) / opdata->initial_length;
- factor = MAX2(1.0f - factor, 0.0f);
+ factor = -len_v2(mdiff) /
opdata->initial_length + 1.0f;
- RNA_float_set(op->ptr, "percent", factor);
+ /* Fake shift-transform... */
+ if (event->shift) {
+ if (opdata->shift_factor < 0.0f)
+ opdata->shift_factor =
RNA_float_get(op->ptr, "percent");
+ factor = (factor -
opdata->shift_factor) * 0.1f + opdata->shift_factor;
+ }
+ else if (opdata->shift_factor >= 0.0f)
+ opdata->shift_factor = -1.0f;
- edbm_bevel_calc(C, op);
- edbm_bevel_update_header(op, C);
+ CLAMP(factor, 0.0f, 1.0f);
+
+ RNA_float_set(op->ptr, "percent", factor);
+
+ edbm_bevel_calc(C, op);
+ edbm_bevel_update_header(op, C);
+ }
return OPERATOR_RUNNING_MODAL;
- }
case LEFTMOUSE:
case PADENTER:
@@ -4598,8 +4634,8 @@
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
RNA_def_float(ot->srna, "percent", 0.0f, -FLT_MAX, FLT_MAX,
"Percentage", "", 0.0f, 1.0f);
-// XXX, disabled for 2.63 release, needs to work much better without overlap
before we can give to users.
-// RNA_def_int(ot->srna, "recursion", 1, 1, 50, "Recursion Level",
"Recursion Level", 1, 8);
+ /* XXX, disabled for 2.63 release, needs to work much better without
overlap before we can give to users. */
+/* RNA_def_int(ot->srna, "recursion", 1, 1, 50, "Recursion Level",
"Recursion Level", 1, 8); */
RNA_def_boolean(ot->srna, "use_even", FALSE, "Even", "Calculate
evenly spaced bevel");
RNA_def_boolean(ot->srna, "use_dist", FALSE, "Distance", "Interpret the
percent in blender units");
@@ -4643,26 +4679,36 @@
int modify_depth;
int is_modal;
float initial_length;
+ int shift;
+ float shift_amount;
BMBackup backup;
BMEditMesh *em;
+ NumInput num_input;
} InsetData;
static void edbm_inset_update_header(wmOperator *op, bContext *C)
{
InsetData *opdata = op->customdata;
- static char str[] = "Confirm: Enter/LClick, Cancel: (Esc/RClick),
thickness: %f, depth (Ctrl to tweak): %f (%s), Outset (O): (%s)";
+ static char str[] = "Confirm: Enter/LClick, Cancel: (Esc/RClick),
thickness: %s, depth (Ctrl to tweak): %s (%s), Outset (O): (%s)";
char msg[HEADER_LENGTH];
ScrArea *sa = CTX_wm_area(C);
if (sa) {
+ char flts_str[NUM_STR_REP_LEN * 2];
+ if (hasNumInput(&opdata->num_input))
+ outputNumInput(&opdata->num_input, flts_str);
+ else {
+ BLI_snprintf(flts_str, NUM_STR_REP_LEN, "%f",
RNA_float_get(op->ptr, "thickness"));
+ BLI_snprintf(flts_str + NUM_STR_REP_LEN,
NUM_STR_REP_LEN, "%f", RNA_float_get(op->ptr, "depth"));
+ }
BLI_snprintf(msg, HEADER_LENGTH, str,
- RNA_float_get(op->ptr, "thickness"),
- RNA_float_get(op->ptr, "depth"),
+ flts_str,
+ flts_str + NUM_STR_REP_LEN,
opdata->modify_depth ? "On" : "Off",
RNA_boolean_get(op->ptr, "use_outset") ? "On" :
"Off"
- );
+ );
ED_area_headerprint(sa, msg);
}
@@ -4680,9 +4726,14 @@
opdata->old_thickness = 0.01;
opdata->old_depth = 0.0;
opdata->modify_depth = FALSE;
+ opdata->shift = FALSE;
+ opdata->shift_amount = 0.0f;
opdata->is_modal = is_modal;
opdata->em = em;
+ initNumInput(&opdata->num_input);
+ opdata->num_input.idx_max = 1; /* Two elements. */
+
if (is_modal)
opdata->backup = EDBM_redo_state_store(em);
@@ -4814,10 +4865,28 @@
static int edbm_inset_modal(bContext *C, wmOperator *op, wmEvent *event)
{
- InsetData *opdata;
+ InsetData *opdata = op->customdata;
- opdata = op->customdata;
+ if (event->val == KM_PRESS) {
+ /* Try to handle numeric inputs... */
+ float amounts[2];
+ if (handleNumInput(&opdata->num_input, event)) {
+ applyNumInput(&opdata->num_input, amounts);
+ amounts[0] = MAX2(amounts[0], 0.0f);
+ RNA_float_set(op->ptr, "thickness", amounts[0]);
+ RNA_float_set(op->ptr, "depth", amounts[1]);
+
+ if (edbm_inset_calc(C, op)) {
+ edbm_inset_update_header(op, C);
+ return OPERATOR_RUNNING_MODAL;
+ }
+ else {
+ edbm_inset_cancel(C, op);
+ return OPERATOR_CANCELLED;
+ }
+ }
+ }
switch (event->type) {
case ESCKEY:
case RIGHTMOUSE:
@@ -4825,33 +4894,37 @@
return OPERATOR_CANCELLED;
case MOUSEMOVE:
- {
- float mdiff[2];
- float amount;
+ if (!hasNumInput(&opdata->num_input)) {
+ float mdiff[2];
+ float amount;
- mdiff[0] = opdata->mcenter[0] - event->mval[0];
- mdiff[1] = opdata->mcenter[1] - event->mval[1];
+ mdiff[0] = opdata->mcenter[0] - event->mval[0];
+ mdiff[1] = opdata->mcenter[1] - event->mval[1];
- if (opdata->modify_depth) {
- amount = opdata->old_depth + (len_v2(mdiff) -
opdata->initial_length) / opdata->initial_length;
- RNA_float_set(op->ptr, "depth", amount);
- }
- else {
- amount = opdata->old_thickness - (len_v2(mdiff)
- opdata->initial_length) / opdata->initial_length;
- amount = MAX2(amount, 0.0f);
+ if (opdata->modify_depth)
+ amount = opdata->old_depth +
len_v2(mdiff) / opdata->initial_length - 1.0f;
+ else
+ amount = opdata->old_thickness -
len_v2(mdiff) / opdata->initial_length + 1.0f;
- RNA_float_set(op->ptr, "thickness", amount);
- }
+ /* Fake shift-transform... */
+ if (opdata->shift)
+ amount = (amount -
opdata->shift_amount) * 0.1f + opdata->shift_amount;
- if (edbm_inset_calc(C, op)) {
- edbm_inset_update_header(op, C);
- return OPERATOR_RUNNING_MODAL;
+ if (opdata->modify_depth)
+ RNA_float_set(op->ptr, "depth", amount);
+ else {
+ amount = MAX2(amount, 0.0f);
+ RNA_float_set(op->ptr, "thickness",
amount);
+ }
+
+ if (edbm_inset_calc(C, op))
+ edbm_inset_update_header(op, C);
+ else {
+ edbm_inset_cancel(C, op);
+ return OPERATOR_CANCELLED;
+ }
}
- else {
- edbm_inset_cancel(C, op);
- return OPERATOR_CANCELLED;
- }
- }
+ return OPERATOR_RUNNING_MODAL;
case LEFTMOUSE:
case PADENTER:
@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs