~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to source/blender/src/editmball.c

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2005-11-06 12:40:03 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051106124003-3pgs7tcg5rox96xg
Tags: 2.37a-1.1
* Non-maintainer upload.
* Split out parts of 01_SConstruct_debian.dpatch again: root_build_dir
  really needs to get adjusted before the clean target runs - closes: #333958,
  see #288882 for reference

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
 * $Id: editmball.c,v 1.9 2003/11/19 22:00:13 ton Exp $
 
2
 * $Id: editmball.c,v 1.19 2005/05/10 04:21:11 theeth Exp $
3
3
 *
4
4
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5
5
 *
30
30
 * ***** END GPL/BL DUAL LICENSE BLOCK *****
31
31
 */
32
32
 
 
33
#include <string.h>
 
34
 
33
35
#ifdef HAVE_CONFIG_H
34
36
#include <config.h>
35
37
#endif
36
38
 
37
 
#ifdef WIN32
38
 
#include "BLI_winstuff.h"
39
 
#endif
40
39
#include "MEM_guardedalloc.h"
41
40
 
42
41
#include "BLI_blenlib.h"
45
44
#include "DNA_screen_types.h"
46
45
#include "DNA_meta_types.h"
47
46
#include "DNA_object_types.h"
 
47
#include "DNA_scene_types.h"
48
48
#include "DNA_view3d_types.h"
49
49
 
50
50
#include "BKE_utildefines.h"
57
57
#include "BIF_screen.h"
58
58
#include "BIF_toolbox.h"
59
59
#include "BIF_space.h"
 
60
#include "BIF_editmode_undo.h"
 
61
#include "BIF_transform.h"
60
62
 
61
63
#include "BDR_editobject.h"
62
64
#include "BDR_editmball.h"
64
66
#include "BSE_edit.h"
65
67
#include "BSE_view.h"
66
68
 
67
 
#include "render.h"
68
69
#include "blendef.h"
69
70
#include "mydevice.h"
70
71
 
171
172
        ml->x= cent[0];
172
173
        ml->y= cent[1];
173
174
        ml->z= cent[2];
 
175
        ml->quat[0]= 1.0;
 
176
        ml->quat[1]= 0.0;
 
177
        ml->quat[2]= 0.0;
 
178
        ml->quat[3]= 0.0;
174
179
        ml->rad= 2.0;
175
 
        ml->lay= 1;
176
180
        ml->s= 2.0;
177
 
        ml->flag= SELECT;
 
181
        ml->flag= SELECT | MB_SCALE_RAD;
178
182
 
179
183
        switch(dummy_argument) {
180
184
                case 1:
207
211
        
208
212
        allqueue(REDRAWALL, 0);
209
213
        makeDispList(G.obedit);
 
214
        BIF_undo_push("Add MetaElem");
210
215
}
211
216
 
212
217
void deselectall_mball()
229
234
                ml= ml->next;
230
235
        }
231
236
        allqueue(REDRAWVIEW3D, 0);
 
237
//      BIF_undo_push("Deselect MetaElem");
232
238
}
233
239
 
234
240
void mouse_mball()
251
257
        if(hits>0) {
252
258
                ml= startelem;
253
259
                while(ml) {
254
 
                        /* if(base->lay & G.vd->lay) { */
255
260
                        
256
 
                                for(a=0; a<hits; a++) {
257
 
                                        /* index converted for gl stuff */
258
 
                                        if(ml->selcol==buffer[ 4 * a + 3 ]) act= ml;
259
 
                                }
260
 
                        /* } */
 
261
                        for(a=0; a<hits; a++) {
 
262
                                /* index converted for gl stuff */
 
263
                                if(ml->selcol1==buffer[ 4 * a + 3 ]){
 
264
                                        ml->flag |= MB_SCALE_RAD;
 
265
                                        act= ml;
 
266
                                }
 
267
                                if(ml->selcol2==buffer[ 4 * a + 3 ]){
 
268
                                        ml->flag &= ~MB_SCALE_RAD;
 
269
                                        act= ml;
 
270
                                }
 
271
 
 
272
                        }
261
273
                        
262
274
                        if(act) break;
263
275
                        
300
312
                ml= ml->prev;
301
313
        }
302
314
        
303
 
        transform('g');
 
315
        BIF_TransformSetUndo("Add Duplicate");
 
316
        initTransform(TFM_TRANSLATION, CTX_NO_PET);
 
317
        Transform();
304
318
        allqueue(REDRAWBUTSEDIT, 0);
305
319
}
306
320
 
 
321
/* Delete all selected MetaElems (not MetaBall) */
307
322
void delete_mball()
308
323
{
309
324
        MetaElem *ml, *next;
324
339
        makeDispList(G.obedit);
325
340
        allqueue(REDRAWVIEW3D, 0);
326
341
        allqueue(REDRAWBUTSEDIT, 0);
 
342
 
 
343
        BIF_undo_push("Delete MetaElem");
 
344
}
 
345
 
 
346
/* free all MetaElems from ListBase */
 
347
void freeMetaElemlist(ListBase *lb)
 
348
{
 
349
        MetaElem *ml, *next;
 
350
 
 
351
        if(lb==NULL) return;
 
352
 
 
353
        ml= lb->first;
 
354
        while(ml){
 
355
                next= ml->next;
 
356
                BLI_remlink(lb, ml);
 
357
                MEM_freeN(ml);
 
358
                ml= next;
 
359
        }
 
360
 
 
361
        lb->first= lb->last= NULL;
 
362
        
 
363
}
 
364
 
 
365
/*  ************* undo for MetaBalls ************* */
 
366
 
 
367
static void undoMball_to_editMball(void *lbv)
 
368
{
 
369
        ListBase *lb= lbv;
 
370
        MetaElem *ml, *newml;
 
371
        unsigned int nr, lastmlnr= 0;
 
372
 
 
373
        /* we try to restore lastelem, which used in for example in button window */
 
374
        for(ml= editelems.first; ml; ml= ml->next, lastmlnr++)
 
375
                if(lastelem==ml) break;
 
376
 
 
377
        freeMetaElemlist(&editelems);
 
378
 
 
379
        /* copy 'undo' MetaElems to 'edit' MetaElems */
 
380
        ml= lb->first;
 
381
        while(ml){
 
382
                newml= MEM_dupallocN(ml);
 
383
                BLI_addtail(&editelems, newml);
 
384
                ml= ml->next;
 
385
        }
 
386
        
 
387
        for(nr=0, lastelem= editelems.first; lastelem; lastelem= lastelem->next, nr++)
 
388
                if(nr==lastmlnr) break;
 
389
        
 
390
}
 
391
 
 
392
static void *editMball_to_undoMball(void)
 
393
{
 
394
        ListBase *lb;
 
395
        MetaElem *ml, *newml;
 
396
 
 
397
        /* allocate memory for undo ListBase */
 
398
        lb= MEM_callocN(sizeof(ListBase), "listbase undo");
 
399
        lb->first= lb->last= NULL;
 
400
        
 
401
        /* copy contents of current ListBase to the undo ListBase */
 
402
        ml= editelems.first;
 
403
        while(ml){
 
404
                newml= MEM_dupallocN(ml);
 
405
                BLI_addtail(lb, newml);
 
406
                ml= ml->next;
 
407
        }
 
408
        
 
409
        return lb;
 
410
}
 
411
 
 
412
/* free undo ListBase of MetaElems */
 
413
static void free_undoMball(void *lbv)
 
414
{
 
415
        ListBase *lb= lbv;
 
416
        
 
417
        freeMetaElemlist(lb);
 
418
        MEM_freeN(lb);
 
419
}
 
420
 
 
421
/* this is undo system for MetaBalls */
 
422
void undo_push_mball(char *name)
 
423
{
 
424
        undo_editmode_push(name, free_undoMball, undoMball_to_editMball, editMball_to_undoMball);
 
425
}
 
426
 
 
427
/* Hide selected/unselected MetaElems */
 
428
void hide_mball(char hide)
 
429
{
 
430
        MetaElem *ml;
 
431
 
 
432
        ml= editelems.first;
 
433
 
 
434
        while(ml){
 
435
                if(hide){
 
436
                        if(!(ml->flag & SELECT))
 
437
                                ml->flag |= MB_HIDE;
 
438
                }
 
439
                else{
 
440
                        if(ml->flag & SELECT)
 
441
                                ml->flag |= MB_HIDE;
 
442
                }
 
443
                ml= ml->next;
 
444
        }
 
445
 
 
446
        makeDispList(G.obedit);
 
447
        allqueue(REDRAWVIEW3D, 0);
 
448
        allqueue(REDRAWBUTSEDIT, 0);
 
449
 
 
450
        BIF_undo_push("Hide MetaElems");
 
451
}
 
452
 
 
453
/* Unhide all edited MetaElems */
 
454
void reveal_mball(void)
 
455
{
 
456
        MetaElem *ml;
 
457
 
 
458
        ml= editelems.first;
 
459
 
 
460
        while(ml){
 
461
                ml->flag &= ~MB_HIDE;
 
462
                ml= ml->next;
 
463
        }
 
464
 
 
465
        makeDispList(G.obedit);
 
466
        allqueue(REDRAWVIEW3D, 0);
 
467
        allqueue(REDRAWBUTSEDIT, 0);
 
468
 
 
469
        BIF_undo_push("Unhide MetaElems");
327
470
}