Revision: 37574
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37574
Author:   psy-fi
Date:     2011-06-17 00:39:59 +0000 (Fri, 17 Jun 2011)
Log Message:
-----------
Modal operator for stitching. Old options fully functional again

Modified Paths:
--------------
    branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_ops.c

Modified: branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_ops.c
===================================================================
--- branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_ops.c  
2011-06-17 00:30:04 UTC (rev 37573)
+++ branches/soc-2011-onion/source/blender/editors/uvedit/uvedit_ops.c  
2011-06-17 00:39:59 UTC (rev 37574)
@@ -1123,22 +1123,54 @@
        int count;
 } UVVertAverage;
 
-static int stitch_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
+typedef struct StitchState {
+       short preview;
+       int use_limit;
+       float limitDist;
+       short selectMode;
+} StitchState;
+
+#define VERT_STITCH 1
+#define EDGE_STITCH 2
+
+static void stitch_update_header(StitchState *stitch_state, bContext *C)
 {
+       static char str[] = "V(ertices): %c  E(dges): %c  P(review): %c  
L(imit): %c  S(nap): %c  Wheel(limit adjust): %f";
+       char msg[256];
        ScrArea *sa= CTX_wm_area(C);
-
        if(sa) {
-               char str[] = "V(ertices):  E(dges):  P(review):  L(imit):  
S(nap):  Wheel(limit adjust):";
-               ED_area_headerprint(sa, str);
+               sprintf(msg, str, ' ', ' ', ' ', stitch_state->use_limit?'*':' 
', ' ', stitch_state->limitDist);
+               ED_area_headerprint(sa, msg);
        }
+}
+
+static int stitch_init(bContext *C, wmOperator *op)
+{
+       StitchState *stitch_state = MEM_mallocN(sizeof(StitchState), 
"stitch_state");
+
+       op->customdata = stitch_state;
+
+       if(!stitch_state)
+               return 0;
+
+       stitch_state->use_limit = RNA_boolean_get(op->ptr, "use_limit");
+       stitch_state->limitDist = RNA_float_get(op->ptr, "limit");
+
+       stitch_update_header(stitch_state, C);
+       return 1;
+}
+
+static int stitch_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
+{
+       if(!stitch_init(C, op))
+               return OPERATOR_CANCELLED;
+
        WM_event_add_modal_handler(C, op);
        return OPERATOR_RUNNING_MODAL;
 }
 
-
-static int stitch_exec(bContext *C, wmOperator *op)
+static int stitch_uvs(bContext *C, wmOperator *op)
 {
-       SpaceImage *sima;
        Scene *scene;
        Object *obedit;
        EditMesh *em;
@@ -1146,20 +1178,21 @@
        EditVert *eve;
        Image *ima;
        MTFace *tf;
+       StitchState *stitch_state;
 
+       stitch_state = (StitchState *)op->customdata;
        scene= CTX_data_scene(C);
        obedit= CTX_data_edit_object(C);
        em= BKE_mesh_get_editmesh((Mesh*)obedit->data);
        ima= CTX_data_edit_image(C);
-       sima= CTX_wm_space_image(C);
        
-       if(RNA_boolean_get(op->ptr, "use_limit")) {
+       if(stitch_state->use_limit) {
                UvVertMap *vmap;
                UvMapVert *vlist, *iterv;
                float newuv[2], limit[2];
                int a, vtot;
 
-               limit[0]= RNA_float_get(op->ptr, "limit");
+               limit[0]= stitch_state->limitDist;
                limit[1]= limit[0];
 
                EM_init_index_arrays(em, 0, 0, 1);
@@ -1293,27 +1326,64 @@
 
                MEM_freeN(uv_average);
        }
+       BKE_mesh_end_editmesh(obedit->data, em);
 
+       return OPERATOR_FINISHED;
+}
+
+
+static void stitch_exit(bContext *C, wmOperator *op)
+{
+       StitchState *stitch_state;
+       Scene *scene;
+       SpaceImage *sima;
+       ScrArea *sa= CTX_wm_area(C);
+       Object *obedit;
+
+       stitch_state = (StitchState *)op->customdata;
+       scene= CTX_data_scene(C);
+       obedit= CTX_data_edit_object(C);
+       sima= CTX_wm_space_image(C);
+
+       stitch_state = (StitchState *)op->customdata;
+
+       RNA_float_set(op->ptr, "limit", stitch_state->limitDist);
+       RNA_boolean_set(op->ptr, "use_limit", stitch_state->use_limit);
+
+       if(sa)
+               ED_area_headerprint(sa, NULL);
+
        uvedit_live_unwrap_update(sima, scene, obedit);
        DAG_id_tag_update(obedit->data, 0);
        WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
+       if(stitch_state){
+               MEM_freeN(stitch_state);
+               op->customdata = NULL;
+       }
 
-       BKE_mesh_end_editmesh(obedit->data, em);
-       return OPERATOR_FINISHED;
 }
 
 
-static int stitch_modal(bContext *C, wmOperator *op, wmEvent *event)
+static int stitch_exec(bContext *C, wmOperator *op)
 {
-       float limit;
        int returnValue;
-       ScrArea *sa= CTX_wm_area(C);;
+       if(!stitch_init(C, op))
+               return OPERATOR_CANCELLED;
+       returnValue = stitch_uvs(C, op);
+       stitch_exit(C, op);
+       return returnValue;
+}
 
+static int stitch_modal(bContext *C, wmOperator *op, wmEvent *event)
+{
+       StitchState *stitch_state;
+
+       stitch_state = (StitchState *)op->customdata;
+
        switch(event->type){
                /* Cancel */
                case ESCKEY:
-                       if(sa)
-                               ED_area_headerprint(sa, NULL);
+                       stitch_exit(C, op);
                        return OPERATOR_CANCELLED;
 
                /* Select verts/edges*/
@@ -1321,33 +1391,32 @@
                        return OPERATOR_RUNNING_MODAL;
 
                case LEFTMOUSE:
-               case PADENTER:
-                       returnValue = stitch_exec(C, op);
-                       if(sa)
-                               ED_area_headerprint(sa, NULL);
+               case PADENTER:{
+                       int returnValue;
+                       returnValue = stitch_uvs(C, op);
+                       stitch_exit(C, op);
                        return returnValue;
-
+               }
                /* Increase limit */
                case PADPLUSKEY:
                case WHEELUPMOUSE:
-                       limit = RNA_float_get(op->ptr, "limit");
-                       limit += 0.01;
-                       RNA_float_set(op->ptr, "limit", limit);
-                       return OPERATOR_RUNNING_MODAL;
+                       stitch_state->limitDist += 0.01;
+                       break;
 
                /* Decrease limit */
                case PADMINUS:
                case WHEELDOWNMOUSE:
-                       limit = RNA_float_get(op->ptr, "limit");
-                       limit -= 0.01;
-                       RNA_float_set(op->ptr, "limit", limit);
-                       return OPERATOR_RUNNING_MODAL;
+                       stitch_state->limitDist -= 0.01;
+                       stitch_state->limitDist = MAX2(0.01, 
stitch_state->limitDist);
+                       break;
 
                /* Use Limit (Default off)*/
                case LKEY:
-                       returnValue = RNA_boolean_get(op->ptr, "use_limit");
-                       RNA_boolean_set(op->ptr, "use_limit", !returnValue);
-                       return OPERATOR_RUNNING_MODAL;
+                       if(event->val == KM_PRESS){
+                               stitch_state->use_limit = 
!stitch_state->use_limit;
+                               break;
+                       } else
+                               return OPERATOR_RUNNING_MODAL;
 
                /* Use Edge selection */
                case EKEY:
@@ -1368,8 +1437,17 @@
                default:
                        return OPERATOR_RUNNING_MODAL;
        }
+
+       /* if updated settings, renew feedback message */
+       stitch_update_header(stitch_state, C);
+       return OPERATOR_RUNNING_MODAL;
 }
 
+static int stitch_cancel(bContext *C, wmOperator *op)
+{
+       stitch_exit(C, op);
+       return OPERATOR_CANCELLED;
+}
 
 static void UV_OT_stitch(wmOperatorType *ot)
 {
@@ -1383,6 +1461,7 @@
        ot->invoke = stitch_invoke;
        ot->modal = stitch_modal;
        ot->exec= stitch_exec;
+       ot->cancel = stitch_cancel;
        ot->poll= ED_operator_uvedit;
 
        /* properties */

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to