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:
authorBastien Montagne <montagne29@wanadoo.fr>2013-12-21 20:11:43 +0400
committerBastien Montagne <montagne29@wanadoo.fr>2013-12-21 20:44:48 +0400
commit87cc890aef53c4660448b1125dc0c40a187ae1f2 (patch)
tree5742d07986fa362b4f17590129dd8c5692cd51b7 /source/blender/editors/mesh/editmesh_loopcut.c
parentf72b86da8cab4bff482fc58095d14c97823fa39f (diff)
Support units in modal numinput
Summary: This completly changes the way modal numinput is handled. Now, edited expression is a string, which then gets unit- and py-evaluated to get a float value. We gain many power and flexibility, but lose a few "shortcuts" like '-' to negate, or '/' to inverse (if they are really needed, we still can add them with modifiers, like e.g. ctrl-/ or so). Features: - units (cm, ", deg, etc.). - basic operations from python/BKE_unit (+, *, **, etc.), and math constants and functions (pi, sin, etc.). - you can navigate in edited value (left/right key, ctrl to move by block) and insert/delete chars, e.g. to fix a typo without having to rewrite everything. - you can go to next/previous value with (ctrl-)TAB key. - As before, hitting backspace after having deleted all leading chars will first reset the edited value to init state, and on second press, the whole "modal numinput" editing will be cancelled, going back to usual transform with mouse. Notes: - Did not touch to how values are shown in header when modal numinput is not enabled (would do that in another commit), so this is still quite inconsistent. - Added back radian support in BKE_unit. - Added arcminute/arcsecond to BKE_unit. (those unit changes affect all angle UI controls, btw, so you can now enter radians or longitude/latitude values when in degrees units). Related to T37600. Reviewers: brecht, campbellbarton, carter2422 Reviewed By: brecht, campbellbarton, carter2422 Thanks everybody! Differential Revision: http://developer.blender.org/D61
Diffstat (limited to 'source/blender/editors/mesh/editmesh_loopcut.c')
-rw-r--r--source/blender/editors/mesh/editmesh_loopcut.c249
1 files changed, 146 insertions, 103 deletions
diff --git a/source/blender/editors/mesh/editmesh_loopcut.c b/source/blender/editors/mesh/editmesh_loopcut.c
index 9223f6d9450..fd24981bde0 100644
--- a/source/blender/editors/mesh/editmesh_loopcut.c
+++ b/source/blender/editors/mesh/editmesh_loopcut.c
@@ -43,6 +43,7 @@
#include "BKE_report.h"
#include "BKE_editmesh.h"
#include "BKE_DerivedMesh.h"
+#include "BKE_unit.h"
#include "BIF_gl.h"
@@ -392,6 +393,7 @@ static void ringsel_exit(bContext *UNUSED(C), wmOperator *op)
static int ringsel_init(bContext *C, wmOperator *op, bool do_cut)
{
RingSelOpData *lcd;
+ Scene *scene = CTX_data_scene(C);
/* alloc new customdata */
lcd = op->customdata = MEM_callocN(sizeof(RingSelOpData), "ringsel Modal Op Data");
@@ -405,8 +407,12 @@ static int ringsel_init(bContext *C, wmOperator *op, bool do_cut)
lcd->do_cut = do_cut;
initNumInput(&lcd->num);
- lcd->num.idx_max = 0;
- lcd->num.flag |= NUM_NO_NEGATIVE | NUM_NO_FRACTION;
+ lcd->num.idx_max = 1;
+ lcd->num.val_flag[0] |= NUM_NO_NEGATIVE | NUM_NO_FRACTION;
+ /* No specific flags for smoothness. */
+ lcd->num.unit_sys = scene->unit.system;
+ lcd->num.unit_type[0] = B_UNIT_NONE;
+ lcd->num.unit_type[1] = B_UNIT_NONE;
/* XXX, temp, workaround for [# ] */
EDBM_mesh_ensure_valid_dm_hack(CTX_data_scene(C), lcd->em);
@@ -529,126 +535,163 @@ static int loopcut_modal(bContext *C, wmOperator *op, const wmEvent *event)
view3d_operator_needs_opengl(C);
- switch (event->type) {
- case RETKEY:
- case PADENTER:
- case LEFTMOUSE: /* confirm */ // XXX hardcoded
- if (event->val == KM_PRESS) {
- /* finish */
+ /* using the keyboard to input the number of cuts */
+ if (event->val == KM_PRESS && hasNumInput(&lcd->num)) {
+ /* Modal numinput active, try to handle numeric inputs first... */
+ if (handleNumInput(C, &lcd->num, event)) {
+ float values[2] = {(float)cuts, smoothness};
+ applyNumInput(&lcd->num, values);
+
+ /* allow zero so you can backspace and type in a value
+ * otherwise 1 as minimum would make more sense */
+ cuts = CLAMPIS(values[0], 0, SUBD_CUTS_MAX);
+ smoothness = CLAMPIS(values[1], -SUBD_SMOOTH_MAX, SUBD_SMOOTH_MAX);
+
+ RNA_int_set(op->ptr, "number_cuts", cuts);
+ ringsel_find_edge(lcd, cuts);
+ show_cuts = true;
+ RNA_float_set(op->ptr, "smoothness", smoothness);
+
+ ED_region_tag_redraw(lcd->ar);
+ }
+ }
+ else {
+ bool handled = false;
+ switch (event->type) {
+ case RETKEY:
+ case PADENTER:
+ case LEFTMOUSE: /* confirm */ // XXX hardcoded
+ if (event->val == KM_PRESS) {
+ /* finish */
+ ED_region_tag_redraw(lcd->ar);
+ ED_area_headerprint(CTX_wm_area(C), NULL);
+
+ if (lcd->eed) {
+ /* set for redo */
+ BM_mesh_elem_index_ensure(lcd->em->bm, BM_EDGE);
+ RNA_int_set(op->ptr, "edge_index", BM_elem_index_get(lcd->eed));
+
+ /* execute */
+ ringsel_finish(C, op);
+ ringsel_exit(C, op);
+ }
+ else {
+ ringcut_cancel(C, op);
+ return OPERATOR_CANCELLED;
+ }
+
+ return OPERATOR_FINISHED;
+ }
+
+ ED_region_tag_redraw(lcd->ar);
+ handled = true;
+ break;
+ case RIGHTMOUSE: /* abort */ // XXX hardcoded
ED_region_tag_redraw(lcd->ar);
+ ringsel_exit(C, op);
ED_area_headerprint(CTX_wm_area(C), NULL);
- if (lcd->eed) {
- /* set for redo */
- BM_mesh_elem_index_ensure(lcd->em->bm, BM_EDGE);
- RNA_int_set(op->ptr, "edge_index", BM_elem_index_get(lcd->eed));
-
- /* execute */
- ringsel_finish(C, op);
- ringsel_exit(C, op);
- }
- else {
+ return OPERATOR_FINISHED;
+ case ESCKEY:
+ if (event->val == KM_RELEASE) {
+ /* cancel */
+ ED_region_tag_redraw(lcd->ar);
+ ED_area_headerprint(CTX_wm_area(C), NULL);
+
ringcut_cancel(C, op);
return OPERATOR_CANCELLED;
}
-
- return OPERATOR_FINISHED;
- }
-
- ED_region_tag_redraw(lcd->ar);
- break;
- case RIGHTMOUSE: /* abort */ // XXX hardcoded
- ED_region_tag_redraw(lcd->ar);
- ringsel_exit(C, op);
- ED_area_headerprint(CTX_wm_area(C), NULL);
-
- return OPERATOR_FINISHED;
- case ESCKEY:
- if (event->val == KM_RELEASE) {
- /* cancel */
+
ED_region_tag_redraw(lcd->ar);
- ED_area_headerprint(CTX_wm_area(C), NULL);
+ handled = true;
+ break;
+ case PADPLUSKEY:
+ case PAGEUPKEY:
+ case WHEELUPMOUSE: /* change number of cuts */
+ if (event->val == KM_RELEASE)
+ break;
+ if (event->alt == 0) {
+ cuts++;
+ cuts = CLAMPIS(cuts, 0, SUBD_CUTS_MAX);
+ RNA_int_set(op->ptr, "number_cuts", cuts);
+ ringsel_find_edge(lcd, cuts);
+ show_cuts = true;
+ }
+ else {
+ smoothness = min_ff(smoothness + 0.05f, SUBD_SMOOTH_MAX);
+ RNA_float_set(op->ptr, "smoothness", smoothness);
+ show_cuts = true;
+ }
- ringcut_cancel(C, op);
- return OPERATOR_CANCELLED;
- }
-
- ED_region_tag_redraw(lcd->ar);
- break;
- case PADPLUSKEY:
- case PAGEUPKEY:
- case WHEELUPMOUSE: /* change number of cuts */
- if (event->val == KM_RELEASE)
+ ED_region_tag_redraw(lcd->ar);
+ handled = true;
break;
- if (event->alt == 0) {
- cuts++;
- cuts = CLAMPIS(cuts, 0, SUBD_CUTS_MAX);
- RNA_int_set(op->ptr, "number_cuts", cuts);
- ringsel_find_edge(lcd, cuts);
- show_cuts = true;
- }
- else {
- smoothness = min_ff(smoothness + 0.05f, SUBD_SMOOTH_MAX);
- RNA_float_set(op->ptr, "smoothness", smoothness);
- show_cuts = true;
- }
-
- ED_region_tag_redraw(lcd->ar);
- break;
- case PADMINUS:
- case PAGEDOWNKEY:
- case WHEELDOWNMOUSE: /* change number of cuts */
- if (event->val == KM_RELEASE)
+ case PADMINUS:
+ case PAGEDOWNKEY:
+ case WHEELDOWNMOUSE: /* change number of cuts */
+ if (event->val == KM_RELEASE)
+ break;
+
+ if (event->alt == 0) {
+ cuts = max_ii(cuts - 1, 1);
+ RNA_int_set(op->ptr, "number_cuts", cuts);
+ ringsel_find_edge(lcd, cuts);
+ show_cuts = true;
+ }
+ else {
+ smoothness = max_ff(smoothness - 0.05f, -SUBD_SMOOTH_MAX);
+ RNA_float_set(op->ptr, "smoothness", smoothness);
+ show_cuts = true;
+ }
+
+ ED_region_tag_redraw(lcd->ar);
+ handled = true;
+ break;
+ case MOUSEMOVE: /* mouse moved somewhere to select another loop */
+ {
+ lcd->vc.mval[0] = event->mval[0];
+ lcd->vc.mval[1] = event->mval[1];
+ loopcut_mouse_move(lcd, cuts);
+
+ ED_region_tag_redraw(lcd->ar);
+ handled = true;
break;
+ }
+ }
- if (event->alt == 0) {
- cuts = max_ii(cuts - 1, 1);
+ if (!handled && event->val == KM_PRESS) {
+ /* Modal numinput inactive, try to handle numeric inputs last... */
+ if (handleNumInput(C, &lcd->num, event)) {
+ float values[2] = {(float)cuts, smoothness};
+ applyNumInput(&lcd->num, values);
+
+ /* allow zero so you can backspace and type in a value
+ * otherwise 1 as minimum would make more sense */
+ cuts = CLAMPIS(values[0], 0, SUBD_CUTS_MAX);
+ smoothness = CLAMPIS(values[1], -SUBD_SMOOTH_MAX, SUBD_SMOOTH_MAX);
+
RNA_int_set(op->ptr, "number_cuts", cuts);
ringsel_find_edge(lcd, cuts);
show_cuts = true;
- }
- else {
- smoothness = max_ff(smoothness - 0.05f, -SUBD_SMOOTH_MAX);
RNA_float_set(op->ptr, "smoothness", smoothness);
- show_cuts = true;
+
+ ED_region_tag_redraw(lcd->ar);
}
-
- ED_region_tag_redraw(lcd->ar);
- break;
- case MOUSEMOVE: /* mouse moved somewhere to select another loop */
- {
- lcd->vc.mval[0] = event->mval[0];
- lcd->vc.mval[1] = event->mval[1];
- loopcut_mouse_move(lcd, cuts);
-
- ED_region_tag_redraw(lcd->ar);
- break;
- }
- }
-
- /* using the keyboard to input the number of cuts */
- if (event->val == KM_PRESS) {
- /* init as zero so backspace clears */
-
- if (handleNumInput(&lcd->num, event)) {
- float value = RNA_int_get(op->ptr, "number_cuts");
- applyNumInput(&lcd->num, &value);
-
- /* allow zero so you can backspace and type in a value
- * otherwise 1 as minimum would make more sense */
- cuts = CLAMPIS(value, 0, SUBD_CUTS_MAX);
-
- RNA_int_set(op->ptr, "number_cuts", cuts);
- ringsel_find_edge(lcd, cuts);
- show_cuts = true;
-
- ED_region_tag_redraw(lcd->ar);
}
}
-
+
if (show_cuts) {
- char buf[64];
- BLI_snprintf(buf, sizeof(buf), IFACE_("Number of Cuts: %d, Smooth: %.2f (Alt)"), cuts, smoothness);
+ char buf[64 + NUM_STR_REP_LEN * 2];
+ char str_rep[NUM_STR_REP_LEN * 2];
+ if (hasNumInput(&lcd->num)) {
+ outputNumInput(&lcd->num, str_rep);
+ }
+ else {
+ BLI_snprintf(str_rep, NUM_STR_REP_LEN, "%d", cuts);
+ BLI_snprintf(str_rep + NUM_STR_REP_LEN, NUM_STR_REP_LEN, "%.2f", smoothness);
+ }
+ BLI_snprintf(buf, sizeof(buf), IFACE_("Number of Cuts: %s, Smooth: %s (Alt)"),
+ str_rep, str_rep + NUM_STR_REP_LEN);
ED_area_headerprint(CTX_wm_area(C), buf);
}