Undo revision 23130 which was a merge with 2.5, a messy one because I did something...
[blender.git] / source / blender / editors / physics / editparticle.c
index b656aa8..b92632b 100644 (file)
@@ -104,21 +104,13 @@ static int PE_poll(bContext *C)
        
        psys= PE_get_current(scene, ob);
 
-       return (psys && psys->edit && (G.f & G_PARTICLEEDIT));
+       return (psys && psys->edit && (ob && ob->mode & OB_MODE_PARTICLE_EDIT));
 }
 
 static int PE_poll_3dview(bContext *C)
 {
-       Scene *scene= CTX_data_scene(C);
-       Object *ob= CTX_data_active_object(C);
-       ParticleSystem *psys;
-
-       if(!scene || !ob || !CTX_wm_region_view3d(C))
-               return 0;
-       
-       psys= PE_get_current(scene, ob);
-
-       return (psys && psys->edit && (G.f & G_PARTICLEEDIT));
+       return PE_poll(C) && CTX_wm_area(C)->spacetype == SPACE_VIEW3D &&
+               CTX_wm_region(C)->regiontype == RGN_TYPE_WINDOW;
 }
 
 static void PE_free_particle_edit(ParticleSystem *psys)
@@ -164,7 +156,7 @@ static void PE_free_particle_edit(ParticleSystem *psys)
 
 int PE_can_edit(ParticleSystem *psys)
 {
-       return (psys && psys->edit && (G.f & G_PARTICLEEDIT));
+       return (psys && psys->edit);
 }
 
 ParticleEditSettings *PE_settings(Scene *scene)
@@ -194,7 +186,7 @@ ParticleSystem *PE_get_current(Scene *scene, Object *ob)
 
        /* this happens when Blender is started with particle
         * edit mode enabled XXX there's a draw error then? */
-       if(psys && psys_check_enabled(ob, psys) && (ob == OBACT) && (G.f & G_PARTICLEEDIT))
+       if(psys && psys_check_enabled(ob, psys) && (ob == OBACT) && (ob->mode & OB_MODE_PARTICLE_EDIT))
                if(psys->part->type == PART_HAIR && psys->flag & PSYS_EDITED)
                        if(psys->edit == NULL)
                                PE_create_particle_edit(scene, ob, psys);
@@ -271,6 +263,7 @@ typedef struct PEData {
        float smoothfac;
        float weightfac;
        float growfac;
+       int totrekey;
 
        int invert;
        int tot;
@@ -1748,7 +1741,6 @@ static void rekey_particle(PEData *data, int pa_index)
        ParticleSystem *psys= data->psys;
        ParticleData *pa= &psys->particles[pa_index];
        ParticleEdit *edit= psys->edit;
-       ParticleEditSettings *pset= PE_settings(data->scene);
        ParticleKey state;
        HairKey *key, *new_keys;
        ParticleEditKey *ekey;
@@ -1757,19 +1749,19 @@ static void rekey_particle(PEData *data, int pa_index)
 
        pa->flag |= PARS_REKEY;
 
-       key= new_keys= MEM_callocN(pset->totrekey * sizeof(HairKey),"Hair re-key keys");
+       key= new_keys= MEM_callocN(data->totrekey * sizeof(HairKey),"Hair re-key keys");
 
        /* root and tip stay the same */
        VECCOPY(key->co, pa->hair->co);
-       VECCOPY((key + pset->totrekey - 1)->co, (pa->hair + pa->totkey - 1)->co);
+       VECCOPY((key + data->totrekey - 1)->co, (pa->hair + pa->totkey - 1)->co);
 
        sta= key->time= pa->hair->time;
-       end= (key + pset->totrekey - 1)->time= (pa->hair + pa->totkey - 1)->time;
-       dval= (end - sta) / (float)(pset->totrekey - 1);
+       end= (key + data->totrekey - 1)->time= (pa->hair + pa->totkey - 1)->time;
+       dval= (end - sta) / (float)(data->totrekey - 1);
 
        /* interpolate new keys from old ones */
-       for(k=1,key++; k<pset->totrekey-1; k++,key++) {
-               state.time= (float)k / (float)(pset->totrekey-1);
+       for(k=1,key++; k<data->totrekey-1; k++,key++) {
+               state.time= (float)k / (float)(data->totrekey-1);
                psys_get_particle_on_path(data->scene, data->ob, psys, pa_index, &state, 0);
                VECCOPY(key->co, state.co);
                key->time= sta + k * dval;
@@ -1780,7 +1772,7 @@ static void rekey_particle(PEData *data, int pa_index)
                MEM_freeN(pa->hair);
        pa->hair= new_keys;
 
-       pa->totkey=pset->totrekey;
+       pa->totkey=data->totrekey;
 
        if(edit->keys[pa_index])
                MEM_freeN(edit->keys[pa_index]);
@@ -1798,14 +1790,11 @@ static void rekey_particle(PEData *data, int pa_index)
 static int rekey_exec(bContext *C, wmOperator *op)
 {
        PEData data;
-       ParticleEditSettings *pset;
 
        PE_set_data(C, &data);
 
-       pset= PE_settings(data.scene);
-       pset->totrekey= RNA_int_get(op->ptr, "keys");
-
-       data.dval= 1.0f / (float)(pset->totrekey-1);
+       data.dval= 1.0f / (float)(data.totrekey-1);
+       data.totrekey= RNA_int_get(op->ptr, "keys");
 
        foreach_selected_particle(&data, rekey_particle);
        
@@ -2272,7 +2261,7 @@ static void toggle_particle_cursor(bContext *C, int enable)
                pset->paintcursor = NULL;
        }
        else if(enable)
-               pset->paintcursor= WM_paint_cursor_activate(CTX_wm_manager(C), PE_poll, brush_drawcursor, NULL);
+               pset->paintcursor= WM_paint_cursor_activate(CTX_wm_manager(C), PE_poll_3dview, brush_drawcursor, NULL);
 }
 
 /********************* radial control operator *********************/
@@ -2282,7 +2271,7 @@ static int brush_radial_control_invoke(bContext *C, wmOperator *op, wmEvent *eve
        ParticleEditSettings *pset= PE_settings(CTX_data_scene(C));
        ParticleBrushData *brush;
        int mode = RNA_enum_get(op->ptr, "mode");
-       float original_value;
+       float original_value=1.0f;
 
        if(pset->brushtype < 0)
                return OPERATOR_CANCELLED;
@@ -2344,7 +2333,7 @@ void PARTICLE_OT_brush_radial_control(wmOperatorType *ot)
        ot->poll= PE_poll;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
 }
 
 /*************************** delete operator **************************/
@@ -3079,11 +3068,13 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr)
        ParticleSystemModifierData *psmd= psys_get_modifier(ob, psys);
        ParticleBrushData *brush= &pset->brush[pset->brushtype];
        ARegion *ar= CTX_wm_region(C);
-       float vec1[3], vec2[3];
+       float vec1[3], vec2[3], mousef[2];
        short mval[2], mvalo[2];
        int flip, mouse[2], dx, dy, removed= 0, selected= 0;
 
-       RNA_int_get_array(itemptr, "mouse", mouse);
+       RNA_float_get_array(itemptr, "mouse", mousef);
+       mouse[0] = mousef[0];
+       mouse[1] = mousef[1];
        flip= RNA_boolean_get(itemptr, "flip");
 
        if(bedit->first) {
@@ -3294,7 +3285,7 @@ static void brush_edit_apply_event(bContext *C, wmOperator *op, wmEvent *event)
 {
        ARegion *ar= CTX_wm_region(C);
        PointerRNA itemptr;
-       int mouse[2];
+       float mouse[2];
 
        mouse[0]= event->x - ar->winrct.xmin;
        mouse[1]= event->y - ar->winrct.ymin;
@@ -3302,7 +3293,7 @@ static void brush_edit_apply_event(bContext *C, wmOperator *op, wmEvent *event)
        /* fill in stroke */
        RNA_collection_add(op->ptr, "stroke", &itemptr);
 
-       RNA_int_set_array(&itemptr, "mouse", mouse);
+       RNA_float_set_array(&itemptr, "mouse", mouse);
        RNA_boolean_set(&itemptr, "flip", event->shift != 0); // XXX hardcoded
 
        /* apply */
@@ -3358,7 +3349,7 @@ void PARTICLE_OT_brush_edit(wmOperatorType *ot)
        ot->poll= PE_poll_3dview;
 
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
 
        /* properties */
        RNA_def_collection_runtime(ot->srna, "stroke", &RNA_OperatorStrokeElement, "Stroke", "");
@@ -3570,7 +3561,7 @@ void PE_undo_menu(Scene *scene, Object *ob)
        ParticleEdit *edit= 0;
        ParticleUndo *undo;
        DynStr *ds;
-       short event;
+       short event=0;
        char *menu;
 
        if(!PE_can_edit(psys)) return;
@@ -3713,7 +3704,7 @@ static int particle_edit_toggle_exec(bContext *C, wmOperator *op)
                psys->flag |= PSYS_CURRENT;
        }
 
-       if(!(G.f & G_PARTICLEEDIT)) {
+       if(!(ob->mode & OB_MODE_PARTICLE_EDIT)) {
                if(psys && psys->part->type == PART_HAIR && psys->flag & PSYS_EDITED) {
                        if(psys_check_enabled(ob, psys)) {
                                if(psys->edit==NULL)
@@ -3723,12 +3714,12 @@ static int particle_edit_toggle_exec(bContext *C, wmOperator *op)
                        }
                }
 
-               G.f |= G_PARTICLEEDIT;
+               ob->mode |= OB_MODE_PARTICLE_EDIT;
                toggle_particle_cursor(C, 1);
                WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_PARTICLE, NULL);
        }
        else {
-               G.f &= ~G_PARTICLEEDIT;
+               ob->mode &= ~OB_MODE_PARTICLE_EDIT;
                toggle_particle_cursor(C, 0);
                WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_OBJECT, NULL);
        }
@@ -3776,7 +3767,7 @@ static int set_editable_exec(bContext *C, wmOperator *op)
                if(psys_check_enabled(ob, psys)) {
                        psys->flag |= PSYS_EDITED;
 
-                       if(G.f & G_PARTICLEEDIT)
+                       if(ob->mode & OB_MODE_PARTICLE_EDIT)
                                PE_create_particle_edit(scene, ob, psys);
                }
                else
@@ -3817,7 +3808,7 @@ void PE_change_act(void *ob_v, void *act_v)
                        psys->flag |= PSYS_CURRENT;
 
                        if(psys_check_enabled(ob, psys)) {
-                               if(G.f & G_PARTICLEEDIT && !psys->edit)
+                               if(ob->mode & OB_MODE_PARTICLE_EDIT && !psys->edit)
                                        PE_create_particle_edit(scene, ob, psys);
                                psys_update_world_cos(ob, psys);
                        }
@@ -3835,7 +3826,7 @@ void PE_change_act_psys(Scene *scene, Object *ob, ParticleSystem *psys)
        psys->flag |= PSYS_CURRENT;
        
        if(psys_check_enabled(ob, psys)) {
-               if(G.f & G_PARTICLEEDIT && !psys->edit)
+               if(ob->mode & OB_MODE_PARTICLE_EDIT && !psys->edit)
                        PE_create_particle_edit(scene, ob, psys);
 
                psys_update_world_cos(ob, psys);