svn merge ^/trunk/blender -r42009:42053
[blender.git] / source / blender / editors / mesh / loopcut.c
index ef99b07..a6f71d9 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id$
- *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
@@ -74,6 +72,7 @@
 #include "ED_space_api.h"
 #include "ED_view3d.h"
 #include "ED_mesh.h"
+#include "ED_numinput.h"
 
 #include "RNA_access.h"
 #include "RNA_define.h"
@@ -100,6 +99,7 @@ typedef struct tringselOpData {
        Object *ob;
        BMEditMesh *em;
        BMEdge *eed;
+       NumInput num;
 
        int extend;
        int do_cut;
@@ -162,9 +162,9 @@ static void edgering_find_order(BMEditMesh *em, BMEdge *lasteed, BMEdge *eed,
        }
        
        l2 = BM_OtherFaceLoop(l->e, l->f, eed->v1);
-       rev = (l2 == (BMLoop*)l->prev);
+       rev = (l2 == l->prev);
        while (l2->v != lasteed->v1 && l2->v != lasteed->v2) {
-               l2 = rev ? (BMLoop*)l2->prev : (BMLoop*)l2->next;
+               l2 = rev ? l2->prev : l2->next;
        }
 
        if (l2->v == lastv1) {
@@ -370,6 +370,11 @@ static int ringsel_init (bContext *C, wmOperator *op, int do_cut)
        lcd->em= ((Mesh *)lcd->ob->data)->edit_btmesh;
        lcd->extend = do_cut ? 0 : RNA_boolean_get(op->ptr, "extend");
        lcd->do_cut = do_cut;
+       
+       initNumInput(&lcd->num);
+       lcd->num.idx_max = 0;
+       lcd->num.flag |= NUM_NO_NEGATIVE | NUM_NO_FRACTION;
+       
        em_setup_viewcontext(C, &lcd->vc);
 
        ED_region_tag_redraw(lcd->ar);
@@ -384,39 +389,6 @@ static int ringcut_cancel (bContext *C, wmOperator *op)
        return OPERATOR_CANCELLED;
 }
 
-static int ringsel_invoke (bContext *C, wmOperator *op, wmEvent *evt)
-{
-       tringselOpData *lcd;
-       BMEdge *edge;
-       int dist = 75;
-       
-       view3d_operator_needs_opengl(C);
-
-       if (!ringsel_init(C, op, 0))
-               return OPERATOR_CANCELLED;
-       
-       lcd = op->customdata;
-       
-       if (lcd->em->selectmode == SCE_SELECT_FACE) {
-               ringsel_exit(C, op);
-               WM_operator_name_call(C, "MESH_OT_loop_select", WM_OP_INVOKE_REGION_WIN, NULL);
-               return OPERATOR_CANCELLED;
-       }
-
-       lcd->vc.mval[0] = evt->mval[0];
-       lcd->vc.mval[1] = evt->mval[1];
-       
-       edge = EDBM_findnearestedge(&lcd->vc, &dist);
-
-       lcd->eed = edge;
-       
-       ringsel_find_edge(lcd, 1);
-       ringsel_finish(C, op);
-       ringsel_exit(C, op);
-
-       return OPERATOR_FINISHED;
-}
-
 static int ringcut_invoke (bContext *C, wmOperator *op, wmEvent *evt)
 {
        Object *obedit= CTX_data_edit_object(C);
@@ -490,6 +462,7 @@ static int loopcut_modal (bContext *C, wmOperator *op, wmEvent *event)
                        
                        ED_region_tag_redraw(lcd->ar);
                        break;
+               case PADPLUSKEY:
                case PAGEUPKEY:
                case WHEELUPMOUSE:  /* change number of cuts */
                        if (event->val == KM_RELEASE)
@@ -501,6 +474,7 @@ static int loopcut_modal (bContext *C, wmOperator *op, wmEvent *event)
                        
                        ED_region_tag_redraw(lcd->ar);
                        break;
+               case PADMINUS:
                case PAGEDOWNKEY:
                case WHEELDOWNMOUSE:  /* change number of cuts */
                        if (event->val == KM_RELEASE)
@@ -530,33 +504,33 @@ static int loopcut_modal (bContext *C, wmOperator *op, wmEvent *event)
                }                       
        }
        
+       /* using the keyboard to input the number of cuts */
+       if (event->val==KM_PRESS) {
+               float value;
+               
+               if (handleNumInput(&lcd->num, event))
+               {
+                       applyNumInput(&lcd->num, &value);
+                       
+                       cuts= CLAMPIS(value, 1, 32);
+                       
+                       RNA_int_set(op->ptr,"number_cuts",cuts);
+                       ringsel_find_edge(lcd, cuts);
+                       
+                       ED_region_tag_redraw(lcd->ar);
+               }
+       }
+       
        /* keep going until the user confirms */
        return OPERATOR_RUNNING_MODAL;
 }
 
-void MESH_OT_edgering_select (wmOperatorType *ot)
-{
-       /* description */
-       ot->name= "Edge Ring Select";
-       ot->idname= "MESH_OT_edgering_select";
-       ot->description= "Select an edge ring";
-       
-       /* callbacks */
-       ot->invoke= ringsel_invoke;
-       ot->poll= ED_operator_editmesh_region_view3d; 
-       
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-
-       RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the selection");
-}
-
 void MESH_OT_loopcut (wmOperatorType *ot)
 {
        /* description */
        ot->name= "Loop Cut";
        ot->idname= "MESH_OT_loopcut";
-       ot->description= "Add a new loop between existing loops.";
+       ot->description= "Add a new loop between existing loops";
        
        /* callbacks */
        ot->invoke= ringcut_invoke;