~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/editors/animation/fmodifier_ui.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
69
69
 
70
70
// XXX! --------------------------------
71
71
/* temporary definition for limits of float number buttons (FLT_MAX tends to infinity with old system) */
72
 
#define UI_FLT_MAX      10000.0f
73
 
 
74
 
#define B_REDR                                  1
75
 
#define B_FMODIFIER_REDRAW              20
76
 
 
77
 
/* macro for use here to draw background box and set height */
78
 
// XXX for now, roundbox has it's callback func set to NULL to not intercept events
79
 
#define DRAW_BACKDROP(height) \
80
 
        { \
81
 
                uiDefBut(block, ROUNDBOX, B_REDR, "", -3, yco-height, width+3, height-1, NULL, 5.0, 0.0, 12.0, (float)rb_col, ""); \
82
 
        }
 
72
#define UI_FLT_MAX  10000.0f
 
73
 
 
74
#define B_REDR                  1
 
75
#define B_FMODIFIER_REDRAW      20
83
76
 
84
77
/* callback to verify modifier data */
85
 
static void validate_fmodifier_cb (bContext *UNUSED(C), void *fcm_v, void *UNUSED(arg))
 
78
static void validate_fmodifier_cb(bContext *UNUSED(C), void *fcm_v, void *UNUSED(arg))
86
79
{
87
 
        FModifier *fcm= (FModifier *)fcm_v;
88
 
        FModifierTypeInfo *fmi= fmodifier_get_typeinfo(fcm);
 
80
        FModifier *fcm = (FModifier *)fcm_v;
 
81
        FModifierTypeInfo *fmi = fmodifier_get_typeinfo(fcm);
89
82
        
90
83
        /* call the verify callback on the modifier if applicable */
91
84
        if (fmi && fmi->verify_data)
93
86
}
94
87
 
95
88
/* callback to remove the given modifier  */
96
 
static void delete_fmodifier_cb (bContext *C, void *fmods_v, void *fcm_v)
 
89
static void delete_fmodifier_cb(bContext *C, void *fmods_v, void *fcm_v)
97
90
{
98
91
        ListBase *modifiers = (ListBase *)fmods_v;
99
 
        FModifier *fcm= (FModifier *)fcm_v;
 
92
        FModifier *fcm = (FModifier *)fcm_v;
100
93
        
101
94
        /* remove the given F-Modifier from the active modifier-stack */
102
95
        remove_fmodifier(modifiers, fcm);
105
98
        
106
99
        /* send notifiers */
107
100
        // XXX for now, this is the only way to get updates in all the right places... but would be nice to have a special one in this case 
108
 
        WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
 
101
        WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
109
102
}
110
103
 
111
104
/* --------------- */
113
106
/* draw settings for generator modifier */
114
107
static void draw_modifier__generator(uiLayout *layout, ID *id, FModifier *fcm, short width)
115
108
{
116
 
        FMod_Generator *data= (FMod_Generator *)fcm->data;
 
109
        FMod_Generator *data = (FMod_Generator *)fcm->data;
117
110
        uiLayout /* *col, */ /* UNUSED */ *row;
118
111
        uiBlock *block;
119
112
        uiBut *but;
120
113
        PointerRNA ptr;
 
114
        short bwidth = width - 30; /* max button width */
121
115
        
122
116
        /* init the RNA-pointer */
123
117
        RNA_pointer_create(id, &RNA_FModifierFunctionGenerator, fcm, &ptr);
124
118
        
125
119
        /* basic settings (backdrop + mode selector + some padding) */
126
 
        /* col= uiLayoutColumn(layout, 1); */ /* UNUSED */
127
 
        block= uiLayoutGetBlock(layout);
 
120
        /* col = uiLayoutColumn(layout, TRUE); */ /* UNUSED */
 
121
        block = uiLayoutGetBlock(layout);
128
122
        uiBlockBeginAlign(block);
129
 
                but = uiDefButR(block, MENU, B_FMODIFIER_REDRAW, NULL, 0, 0, width-30, UI_UNIT_Y, &ptr, "mode", -1, 0, 0, -1, -1, NULL);
130
 
                uiButSetFunc(but, validate_fmodifier_cb, fcm, NULL);
131
 
                
132
 
                uiDefButR(block, TOG, B_FMODIFIER_REDRAW, NULL, 0, 0, width-30, UI_UNIT_Y, &ptr, "use_additive", -1, 0, 0, -1, -1, NULL);
 
123
        but = uiDefButR(block, MENU, B_FMODIFIER_REDRAW, NULL, 0, 0, bwidth, UI_UNIT_Y, &ptr, "mode", -1, 0, 0, -1, -1, NULL);
 
124
        uiButSetFunc(but, validate_fmodifier_cb, fcm, NULL);
 
125
        
 
126
        uiDefButR(block, TOG, B_FMODIFIER_REDRAW, NULL, 0, 0, bwidth, UI_UNIT_Y, &ptr, "use_additive", -1, 0, 0, -1, -1, NULL);
133
127
        uiBlockEndAlign(block);
134
128
        
135
129
        /* now add settings for individual modes */
139
133
                        float *cp = NULL;
140
134
                        char xval[32];
141
135
                        unsigned int i;
 
136
                        int maxXWidth;
142
137
                        
143
138
                        /* draw polynomial order selector */
144
 
                        row= uiLayoutRow(layout, 0);
145
 
                        block= uiLayoutGetBlock(row);
146
 
                                but = uiDefButI(block, NUM, B_FMODIFIER_REDRAW, IFACE_("Poly Order:"), 10, 0, width-30, 19,
147
 
                                               &data->poly_order, 1, 100, 0, 0,
148
 
                                               TIP_("'Order' of the Polynomial (for a polynomial with n terms, 'order' is n-1)"));
149
 
                                uiButSetFunc(but, validate_fmodifier_cb, fcm, NULL);
150
 
                        
 
139
                        row = uiLayoutRow(layout, FALSE);
 
140
                        block = uiLayoutGetBlock(row);
 
141
                        but = uiDefButI(block, NUM, B_FMODIFIER_REDRAW, IFACE_("Poly Order:"), 10, 0, bwidth, 20,
 
142
                                        &data->poly_order, 1, 100, 0, 0,
 
143
                                        TIP_("'Order' of the Polynomial (for a polynomial with n terms, 'order' is n-1)"));
 
144
                        uiButSetFunc(but, validate_fmodifier_cb, fcm, NULL);
 
145
                        
 
146
                        
 
147
                        /* calculate maximum width of label for "x^n" labels */
 
148
                        if (data->arraysize > 2) {
 
149
                                BLI_snprintf(xval, sizeof(xval), "x^%u", data->arraysize);
 
150
                                maxXWidth = UI_GetStringWidth(xval) + 10; /* XXX: UI_GetStringWidth is not accurate */
 
151
                        }
 
152
                        else {
 
153
                                /* basic size (just "x") */
 
154
                                maxXWidth = UI_GetStringWidth("x") + 10; 
 
155
                        }
151
156
                        
152
157
                        /* draw controls for each coefficient and a + sign at end of row */
153
 
                        row= uiLayoutRow(layout, 1);
154
 
                        block= uiLayoutGetBlock(row);
 
158
                        row = uiLayoutRow(layout, TRUE);
 
159
                        block = uiLayoutGetBlock(row);
155
160
                        
156
 
                        cp= data->coefficients;
157
 
                        for (i=0; (i < data->arraysize) && (cp); i++, cp++) {
158
 
                                /* To align with first line */
 
161
                        cp = data->coefficients;
 
162
                        for (i = 0; (i < data->arraysize) && (cp); i++, cp++) {
 
163
                                /* To align with first line... */
159
164
                                if (i)
160
 
                                        uiDefBut(block, LABEL, 1, "   ", 0, 0, 50, 20, NULL, 0.0, 0.0, 0, 0, "");
 
165
                                        uiDefBut(block, LABEL, 1, "   ", 0, 0, 40, 20, NULL, 0.0, 0.0, 0, 0, "");
161
166
                                else
162
 
                                        uiDefBut(block, LABEL, 1, "y =", 0, 0, 50, 20, NULL, 0.0, 0.0, 0, 0, "");
 
167
                                        uiDefBut(block, LABEL, 1, "y =", 0, 0, 40, 20, NULL, 0.0, 0.0, 0, 0, "");
 
168
                                
163
169
                                /* coefficient */
164
 
                                uiDefButF(block, NUM, B_FMODIFIER_REDRAW, "", 0, 0, 150, 20, cp, -UI_FLT_MAX, UI_FLT_MAX,
 
170
                                uiDefButF(block, NUM, B_FMODIFIER_REDRAW, "", 0, 0, bwidth / 2, 20, cp, -UI_FLT_MAX, UI_FLT_MAX,
165
171
                                          10, 3, TIP_("Coefficient for polynomial"));
166
172
                                
167
173
                                /* 'x' param (and '+' if necessary) */
168
174
                                if (i == 0)
169
 
                                        strcpy(xval, "");
 
175
                                        BLI_strncpy(xval, "", sizeof(xval));
170
176
                                else if (i == 1)
171
 
                                        strcpy(xval, "x");
 
177
                                        BLI_strncpy(xval, "x", sizeof(xval));
172
178
                                else
173
 
                                        sprintf(xval, "x^%u", i);
174
 
                                uiDefBut(block, LABEL, 1, xval, 0, 0, 50, 20, NULL, 0.0, 0.0, 0, 0, TIP_("Power of x"));
 
179
                                        BLI_snprintf(xval, sizeof(xval), "x^%u", i);
 
180
                                uiDefBut(block, LABEL, 1, xval, 0, 0, maxXWidth, 20, NULL, 0.0, 0.0, 0, 0, TIP_("Power of x"));
175
181
                                
176
 
                                if ( (i != (data->arraysize - 1)) || ((i==0) && data->arraysize==2) ) {
177
 
                                        uiDefBut(block, LABEL, 1, "+", 0, 0, 30, 20, NULL, 0.0, 0.0, 0, 0, "");
 
182
                                if ( (i != (data->arraysize - 1)) || ((i == 0) && data->arraysize == 2) ) {
 
183
                                        uiDefBut(block, LABEL, 1, "+", 0, 0, 20, 20, NULL, 0.0, 0.0, 0, 0, "");
178
184
                                        
179
185
                                        /* next coefficient on a new row */
180
 
                                        row= uiLayoutRow(layout, 1);
181
 
                                        block= uiLayoutGetBlock(row);
 
186
                                        row = uiLayoutRow(layout, TRUE);
 
187
                                        block = uiLayoutGetBlock(row);
182
188
                                }
183
189
                                else {
184
 
                                        /* For alignement in UI! */
185
 
                                        uiDefBut(block, LABEL, 1, " ", 0, 0, 30, 20, NULL, 0.0, 0.0, 0, 0, "");
 
190
                                        /* For alignment in UI! */
 
191
                                        uiDefBut(block, LABEL, 1, " ", 0, 0, 20, 20, NULL, 0.0, 0.0, 0, 0, "");
186
192
                                }
187
193
                        }
188
194
                        break;
194
200
                        unsigned int i;
195
201
                        
196
202
                        /* draw polynomial order selector */
197
 
                        row= uiLayoutRow(layout, 0);
198
 
                        block= uiLayoutGetBlock(row);
199
 
                                but = uiDefButI(block, NUM, B_FMODIFIER_REDRAW, IFACE_("Poly Order:"), 0, 0, width-30, 19,
200
 
                                               &data->poly_order, 1, 100, 0, 0,
201
 
                                               TIP_("'Order' of the Polynomial (for a polynomial with n terms, 'order' is n-1)"));
202
 
                                uiButSetFunc(but, validate_fmodifier_cb, fcm, NULL);
 
203
                        row = uiLayoutRow(layout, FALSE);
 
204
                        block = uiLayoutGetBlock(row);
 
205
                        but = uiDefButI(block, NUM, B_FMODIFIER_REDRAW, IFACE_("Poly Order:"), 0, 0, width - 30, 19,
 
206
                                        &data->poly_order, 1, 100, 0, 0,
 
207
                                        TIP_("'Order' of the Polynomial (for a polynomial with n terms, 'order' is n-1)"));
 
208
                        uiButSetFunc(but, validate_fmodifier_cb, fcm, NULL);
203
209
                        
204
210
                        
205
211
                        /* draw controls for each pair of coefficients */
206
 
                        row= uiLayoutRow(layout, 1);
207
 
                        block= uiLayoutGetBlock(row);
 
212
                        row = uiLayoutRow(layout, TRUE);
 
213
                        block = uiLayoutGetBlock(row);
208
214
                        
209
 
                        cp= data->coefficients;
210
 
                        for (i=0; (i < data->poly_order) && (cp); i++, cp+=2) {
 
215
                        cp = data->coefficients;
 
216
                        for (i = 0; (i < data->poly_order) && (cp); i++, cp += 2) {
211
217
                                /* To align with first line */
212
218
                                if (i)
213
219
                                        uiDefBut(block, LABEL, 1, "   ", 0, 0, 50, 20, NULL, 0.0, 0.0, 0, 0, "");
222
228
                                
223
229
                                uiDefBut(block, LABEL, 1, "x +", 0, 0, 40, 20, NULL, 0.0, 0.0, 0, 0, "");
224
230
                                
225
 
                                uiDefButF(block, NUM, B_FMODIFIER_REDRAW, "", 0, 0, 100, 20, cp+1, -UI_FLT_MAX, UI_FLT_MAX,
 
231
                                uiDefButF(block, NUM, B_FMODIFIER_REDRAW, "", 0, 0, 100, 20, cp + 1, -UI_FLT_MAX, UI_FLT_MAX,
226
232
                                          10, 3, TIP_("Second coefficient"));
227
233
                                
228
 
                                /* closing bracket and '+' sign */
229
 
                                if ( (i != (data->poly_order - 1)) || ((i==0) && data->poly_order==2) ) {
230
 
                                        uiDefBut(block, LABEL, 1, ") +", 0, 0, 30, 20, NULL, 0.0, 0.0, 0, 0, "");
 
234
                                /* closing bracket and multiplication sign */
 
235
                                if ( (i != (data->poly_order - 1)) || ((i == 0) && data->poly_order == 2) ) {
 
236
                                        uiDefBut(block, LABEL, 1, ") ×", 0, 0, 40, 20, NULL, 0.0, 0.0, 0, 0, "");
231
237
                                        
232
 
                                        /* set up new row for the next pair of coefficients*/
233
 
                                        row= uiLayoutRow(layout, 1);
234
 
                                        block= uiLayoutGetBlock(row);
 
238
                                        /* set up new row for the next pair of coefficients */
 
239
                                        row = uiLayoutRow(layout, TRUE);
 
240
                                        block = uiLayoutGetBlock(row);
235
241
                                }
236
242
                                else 
237
 
                                        uiDefBut(block, LABEL, 1, ")", 0, 0, 20, 20, NULL, 0.0, 0.0, 0, 0, "");
 
243
                                        uiDefBut(block, LABEL, 1, ")  ", 0, 0, 40, 20, NULL, 0.0, 0.0, 0, 0, "");
238
244
                        }
239
245
                }
240
 
                        break;
 
246
                break;
241
247
        }
242
248
}
243
249
 
253
259
        RNA_pointer_create(id, &RNA_FModifierFunctionGenerator, fcm, &ptr);
254
260
        
255
261
        /* add the settings */
256
 
        col= uiLayoutColumn(layout, 1);
257
 
                uiItemR(col, &ptr, "function_type", 0, "", ICON_NONE);
258
 
                uiItemR(col, &ptr, "use_additive", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
259
 
        
260
 
        col= uiLayoutColumn(layout, 0); // no grouping for now
261
 
                uiItemR(col, &ptr, "amplitude", 0, NULL, ICON_NONE);
262
 
                uiItemR(col, &ptr, "phase_multiplier", 0, NULL, ICON_NONE);
263
 
                uiItemR(col, &ptr, "phase_offset", 0, NULL, ICON_NONE);
264
 
                uiItemR(col, &ptr, "value_offset", 0, NULL, ICON_NONE);
 
262
        col = uiLayoutColumn(layout, TRUE);
 
263
        uiItemR(col, &ptr, "function_type", 0, "", ICON_NONE);
 
264
        uiItemR(col, &ptr, "use_additive", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
 
265
 
 
266
        col = uiLayoutColumn(layout, FALSE); // no grouping for now
 
267
        uiItemR(col, &ptr, "amplitude", 0, NULL, ICON_NONE);
 
268
        uiItemR(col, &ptr, "phase_multiplier", 0, NULL, ICON_NONE);
 
269
        uiItemR(col, &ptr, "phase_offset", 0, NULL, ICON_NONE);
 
270
        uiItemR(col, &ptr, "value_offset", 0, NULL, ICON_NONE);
265
271
}
266
272
 
267
273
/* --------------- */
278
284
        /* split into 2 columns 
279
285
         * NOTE: the mode comboboxes shouldn't get labels, otherwise there isn't enough room
280
286
         */
281
 
        split= uiLayoutSplit(layout, 0.5f, 0);
 
287
        split = uiLayoutSplit(layout, 0.5f, FALSE);
282
288
        
283
289
        /* before range */
284
 
        col= uiLayoutColumn(split, 1);
285
 
                uiItemL(col, IFACE_("Before:"), ICON_NONE);
286
 
                uiItemR(col, &ptr, "mode_before", 0, "", ICON_NONE);
287
 
                uiItemR(col, &ptr, "cycles_before", 0, NULL, ICON_NONE);
 
290
        col = uiLayoutColumn(split, TRUE);
 
291
        uiItemL(col, IFACE_("Before:"), ICON_NONE);
 
292
        uiItemR(col, &ptr, "mode_before", 0, "", ICON_NONE);
 
293
        uiItemR(col, &ptr, "cycles_before", 0, NULL, ICON_NONE);
288
294
                
289
295
        /* after range */
290
 
        col= uiLayoutColumn(split, 1);
291
 
                uiItemL(col, IFACE_("After:"), ICON_NONE);
292
 
                uiItemR(col, &ptr, "mode_after", 0, "", ICON_NONE);
293
 
                uiItemR(col, &ptr, "cycles_after", 0, NULL, ICON_NONE);
 
296
        col = uiLayoutColumn(split, TRUE);
 
297
        uiItemL(col, IFACE_("After:"), ICON_NONE);
 
298
        uiItemR(col, &ptr, "mode_after", 0, "", ICON_NONE);
 
299
        uiItemR(col, &ptr, "cycles_after", 0, NULL, ICON_NONE);
294
300
}
295
301
 
296
302
/* --------------- */
308
314
        uiItemR(layout, &ptr, "blend_type", 0, NULL, ICON_NONE);
309
315
        
310
316
        /* split into 2 columns */
311
 
        split= uiLayoutSplit(layout, 0.5f, 0);
 
317
        split = uiLayoutSplit(layout, 0.5f, FALSE);
312
318
        
313
319
        /* col 1 */
314
 
        col= uiLayoutColumn(split, 0);
315
 
                uiItemR(col, &ptr, "scale", 0, NULL, ICON_NONE);
316
 
                uiItemR(col, &ptr, "strength", 0, NULL, ICON_NONE);
 
320
        col = uiLayoutColumn(split, FALSE);
 
321
        uiItemR(col, &ptr, "scale", 0, NULL, ICON_NONE);
 
322
        uiItemR(col, &ptr, "strength", 0, NULL, ICON_NONE);
317
323
        
318
324
        /* col 2 */
319
 
        col= uiLayoutColumn(split, 0);
320
 
                uiItemR(col, &ptr, "phase", 0, NULL, ICON_NONE);
321
 
                uiItemR(col, &ptr, "depth", 0, NULL, ICON_NONE);
322
 
}
323
 
 
324
 
/* --------------- */
325
 
 
326
 
#define BINARYSEARCH_FRAMEEQ_THRESH     0.0001f
327
 
 
328
 
/* Binary search algorithm for finding where to insert Envelope Data Point.
329
 
 * Returns the index to insert at (data already at that index will be offset if replace is 0)
330
 
 */
331
 
static int binarysearch_fcm_envelopedata_index (FCM_EnvelopeData array[], float frame, int arraylen, short *exists)
332
 
{
333
 
        int start=0, end=arraylen;
334
 
        int loopbreaker= 0, maxloop= arraylen * 2;
335
 
        
336
 
        /* initialize exists-flag first */
337
 
        *exists= 0;
338
 
        
339
 
        /* sneaky optimisations (don't go through searching process if...):
340
 
         *      - keyframe to be added is to be added out of current bounds
341
 
         *      - keyframe to be added would replace one of the existing ones on bounds
342
 
         */
343
 
        if ((arraylen <= 0) || (array == NULL)) {
344
 
                printf("Warning: binarysearch_fcm_envelopedata_index() encountered invalid array\n");
345
 
                return 0;
346
 
        }
347
 
        else {
348
 
                /* check whether to add before/after/on */
349
 
                float framenum;
350
 
                
351
 
                /* 'First' Point (when only one point, this case is used) */
352
 
                framenum= array[0].time;
353
 
                if (IS_EQT(frame, framenum, BINARYSEARCH_FRAMEEQ_THRESH)) {
354
 
                        *exists = 1;
355
 
                        return 0;
356
 
                }
357
 
                else if (frame < framenum)
358
 
                        return 0;
359
 
                        
360
 
                /* 'Last' Point */
361
 
                framenum= array[(arraylen-1)].time;
362
 
                if (IS_EQT(frame, framenum, BINARYSEARCH_FRAMEEQ_THRESH)) {
363
 
                        *exists= 1;
364
 
                        return (arraylen - 1);
365
 
                }
366
 
                else if (frame > framenum)
367
 
                        return arraylen;
368
 
        }
369
 
        
370
 
        
371
 
        /* most of the time, this loop is just to find where to put it
372
 
         *      - 'loopbreaker' is just here to prevent infinite loops 
373
 
         */
374
 
        for (loopbreaker=0; (start <= end) && (loopbreaker < maxloop); loopbreaker++) {
375
 
                /* compute and get midpoint */
376
 
                int mid = start + ((end - start) / 2);  /* we calculate the midpoint this way to avoid int overflows... */
377
 
                float midfra= array[mid].time;
378
 
                
379
 
                /* check if exactly equal to midpoint */
380
 
                if (IS_EQT(frame, midfra, BINARYSEARCH_FRAMEEQ_THRESH)) {
381
 
                        *exists = 1;
382
 
                        return mid;
383
 
                }
384
 
                
385
 
                /* repeat in upper/lower half */
386
 
                if (frame > midfra)
387
 
                        start= mid + 1;
388
 
                else if (frame < midfra)
389
 
                        end= mid - 1;
390
 
        }
391
 
        
392
 
        /* print error if loop-limit exceeded */
393
 
        if (loopbreaker == (maxloop-1)) {
394
 
                printf("Error: binarysearch_fcm_envelopedata_index() was taking too long\n");
395
 
                
396
 
                // include debug info 
397
 
                printf("\tround = %d: start = %d, end = %d, arraylen = %d\n", loopbreaker, start, end, arraylen);
398
 
        }
399
 
        
400
 
        /* not found, so return where to place it */
401
 
        return start;
 
325
        col = uiLayoutColumn(split, FALSE);
 
326
        uiItemR(col, &ptr, "phase", 0, NULL, ICON_NONE);
 
327
        uiItemR(col, &ptr, "depth", 0, NULL, ICON_NONE);
402
328
}
403
329
 
404
330
/* callback to add new envelope data point */
405
 
// TODO: should we have a separate file for things like this?
406
 
static void fmod_envelope_addpoint_cb (bContext *C, void *fcm_dv, void *UNUSED(arg))
 
331
static void fmod_envelope_addpoint_cb(bContext *C, void *fcm_dv, void *UNUSED(arg))
407
332
{
408
 
        Scene *scene= CTX_data_scene(C);
409
 
        FMod_Envelope *env= (FMod_Envelope *)fcm_dv;
 
333
        Scene *scene = CTX_data_scene(C);
 
334
        FMod_Envelope *env = (FMod_Envelope *)fcm_dv;
410
335
        FCM_EnvelopeData *fedn;
411
336
        FCM_EnvelopeData fed;
412
337
        
413
338
        /* init template data */
414
 
        fed.min= -1.0f;
415
 
        fed.max= 1.0f;
416
 
        fed.time= (float)scene->r.cfra; // XXX make this int for ease of use?
417
 
        fed.f1= fed.f2= 0;
 
339
        fed.min = -1.0f;
 
340
        fed.max = 1.0f;
 
341
        fed.time = (float)scene->r.cfra; // XXX make this int for ease of use?
 
342
        fed.f1 = fed.f2 = 0;
418
343
        
419
344
        /* check that no data exists for the current frame... */
420
345
        if (env->data) {
421
346
                short exists = -1;
422
 
                int i= binarysearch_fcm_envelopedata_index(env->data, (float)(scene->r.cfra), env->totvert, &exists);
 
347
                int i = BKE_fcm_envelope_find_index(env->data, (float)(scene->r.cfra), env->totvert, &exists);
423
348
                
424
349
                /* binarysearch_...() will set exists by default to 0, so if it is non-zero, that means that the point exists already */
425
350
                if (exists)
426
351
                        return;
427
352
                        
428
353
                /* add new */
429
 
                fedn= MEM_callocN((env->totvert+1)*sizeof(FCM_EnvelopeData), "FCM_EnvelopeData");
 
354
                fedn = MEM_callocN((env->totvert + 1) * sizeof(FCM_EnvelopeData), "FCM_EnvelopeData");
430
355
                
431
356
                /* add the points that should occur before the point to be pasted */
432
357
                if (i > 0)
433
 
                        memcpy(fedn, env->data, i*sizeof(FCM_EnvelopeData));
 
358
                        memcpy(fedn, env->data, i * sizeof(FCM_EnvelopeData));
434
359
                
435
360
                /* add point to paste at index i */
436
 
                *(fedn + i)= fed;
 
361
                *(fedn + i) = fed;
437
362
                
438
363
                /* add the points that occur after the point to be pasted */
439
364
                if (i < env->totvert) 
440
 
                        memcpy(fedn+i+1, env->data+i, (env->totvert-i)*sizeof(FCM_EnvelopeData));
 
365
                        memcpy(fedn + i + 1, env->data + i, (env->totvert - i) * sizeof(FCM_EnvelopeData));
441
366
                
442
367
                /* replace (+ free) old with new */
443
368
                MEM_freeN(env->data);
444
 
                env->data= fedn;
 
369
                env->data = fedn;
445
370
                
446
371
                env->totvert++;
447
372
        }
448
373
        else {
449
 
                env->data= MEM_callocN(sizeof(FCM_EnvelopeData), "FCM_EnvelopeData");
450
 
                *(env->data)= fed;
 
374
                env->data = MEM_callocN(sizeof(FCM_EnvelopeData), "FCM_EnvelopeData");
 
375
                *(env->data) = fed;
451
376
                
452
 
                env->totvert= 1;
 
377
                env->totvert = 1;
453
378
        }
454
379
}
455
380
 
456
381
/* callback to remove envelope data point */
457
382
// TODO: should we have a separate file for things like this?
458
 
static void fmod_envelope_deletepoint_cb (bContext *UNUSED(C), void *fcm_dv, void *ind_v)
 
383
static void fmod_envelope_deletepoint_cb(bContext *UNUSED(C), void *fcm_dv, void *ind_v)
459
384
{
460
 
        FMod_Envelope *env= (FMod_Envelope *)fcm_dv;
 
385
        FMod_Envelope *env = (FMod_Envelope *)fcm_dv;
461
386
        FCM_EnvelopeData *fedn;
462
 
        int index= GET_INT_FROM_POINTER(ind_v);
 
387
        int index = GET_INT_FROM_POINTER(ind_v);
463
388
        
464
389
        /* check that no data exists for the current frame... */
465
390
        if (env->totvert > 1) {
466
391
                /* allocate a new smaller array */
467
 
                fedn= MEM_callocN(sizeof(FCM_EnvelopeData)*(env->totvert-1), "FCM_EnvelopeData");
 
392
                fedn = MEM_callocN(sizeof(FCM_EnvelopeData) * (env->totvert - 1), "FCM_EnvelopeData");
468
393
 
469
 
                memcpy(fedn, env->data, sizeof(FCM_EnvelopeData)*(index));
470
 
                memcpy(fedn + index, env->data + (index + 1), sizeof(FCM_EnvelopeData)*((env->totvert - index)-1));
 
394
                memcpy(fedn, env->data, sizeof(FCM_EnvelopeData) * (index));
 
395
                memcpy(fedn + index, env->data + (index + 1), sizeof(FCM_EnvelopeData) * ((env->totvert - index) - 1));
471
396
                
472
397
                /* free old array, and set the new */
473
398
                MEM_freeN(env->data);
474
 
                env->data= fedn;
 
399
                env->data = fedn;
475
400
                env->totvert--;
476
401
        }
477
402
        else {
478
403
                /* just free array, since the only vert was deleted */
479
404
                if (env->data) {
480
405
                        MEM_freeN(env->data);
481
 
                        env->data= NULL;
 
406
                        env->data = NULL;
482
407
                }
483
 
                env->totvert= 0;
 
408
                env->totvert = 0;
484
409
        }
485
410
}
486
411
 
487
412
/* draw settings for envelope modifier */
488
413
static void draw_modifier__envelope(uiLayout *layout, ID *id, FModifier *fcm, short UNUSED(width))
489
414
{
490
 
        FMod_Envelope *env= (FMod_Envelope *)fcm->data;
 
415
        FMod_Envelope *env = (FMod_Envelope *)fcm->data;
491
416
        FCM_EnvelopeData *fed;
492
417
        uiLayout *col, *row;
493
418
        uiBlock *block;
499
424
        RNA_pointer_create(id, &RNA_FModifierEnvelope, fcm, &ptr);
500
425
        
501
426
        /* general settings */
502
 
        col= uiLayoutColumn(layout, 1);
503
 
                uiItemL(col, IFACE_("Envelope:"), ICON_NONE);
504
 
                uiItemR(col, &ptr, "reference_value", 0, NULL, ICON_NONE);
505
 
                
506
 
                row= uiLayoutRow(col, 1);
507
 
                        uiItemR(row, &ptr, "default_min", 0, IFACE_("Min"), ICON_NONE);
508
 
                        uiItemR(row, &ptr, "default_max", 0, IFACE_("Max"), ICON_NONE);
509
 
                        
 
427
        col = uiLayoutColumn(layout, TRUE);
 
428
        uiItemL(col, IFACE_("Envelope:"), ICON_NONE);
 
429
        uiItemR(col, &ptr, "reference_value", 0, NULL, ICON_NONE);
 
430
 
 
431
        row = uiLayoutRow(col, TRUE);
 
432
        uiItemR(row, &ptr, "default_min", 0, IFACE_("Min"), ICON_NONE);
 
433
        uiItemR(row, &ptr, "default_max", 0, IFACE_("Max"), ICON_NONE);
 
434
 
510
435
        /* control points header */
511
 
        // TODO: move this control-point control stuff to using the new special widgets for lists
512
 
        // the current way is far too cramped
513
 
        row= uiLayoutRow(layout, 0);
514
 
        block= uiLayoutGetBlock(row);
515
 
                
516
 
                uiDefBut(block, LABEL, 1, IFACE_("Control Points:"), 0, 0, 150, 20, NULL, 0.0, 0.0, 0, 0, "");
517
 
                
518
 
                but = uiDefBut(block, BUT, B_FMODIFIER_REDRAW, IFACE_("Add Point"), 0, 0, 150, 19,
519
 
                              NULL, 0, 0, 0, 0, TIP_("Add a new control-point to the envelope on the current frame"));
520
 
                uiButSetFunc(but, fmod_envelope_addpoint_cb, env, NULL);
 
436
        /* TODO: move this control-point control stuff to using the new special widgets for lists
 
437
         * the current way is far too cramped */
 
438
        row = uiLayoutRow(layout, FALSE);
 
439
        block = uiLayoutGetBlock(row);
 
440
                
 
441
        uiDefBut(block, LABEL, 1, IFACE_("Control Points:"), 0, 0, 150, 20, NULL, 0.0, 0.0, 0, 0, "");
 
442
                
 
443
        but = uiDefBut(block, BUT, B_FMODIFIER_REDRAW, IFACE_("Add Point"), 0, 0, 150, 19,
 
444
                       NULL, 0, 0, 0, 0, TIP_("Add a new control-point to the envelope on the current frame"));
 
445
        uiButSetFunc(but, fmod_envelope_addpoint_cb, env, NULL);
521
446
                
522
447
        /* control points list */
523
 
        for (i=0, fed=env->data; i < env->totvert; i++, fed++) {
 
448
        for (i = 0, fed = env->data; i < env->totvert; i++, fed++) {
524
449
                /* get a new row to operate on */
525
 
                row= uiLayoutRow(layout, 1);
526
 
                block= uiLayoutGetBlock(row);
 
450
                row = uiLayoutRow(layout, TRUE);
 
451
                block = uiLayoutGetBlock(row);
527
452
                
528
453
                uiBlockBeginAlign(block);
529
 
                        but=uiDefButF(block, NUM, B_FMODIFIER_REDRAW, IFACE_("Fra:"), 0, 0, 90, 20,
530
 
                                      &fed->time, -MAXFRAMEF, MAXFRAMEF, 10, 1, TIP_("Frame that envelope point occurs"));
531
 
                        uiButSetFunc(but, validate_fmodifier_cb, fcm, NULL);
532
 
                        
533
 
                        uiDefButF(block, NUM, B_FMODIFIER_REDRAW, IFACE_("Min:"), 0, 0, 100, 20,
534
 
                                  &fed->min, -UI_FLT_MAX, UI_FLT_MAX, 10, 2, TIP_("Minimum bound of envelope at this point"));
535
 
                        uiDefButF(block, NUM, B_FMODIFIER_REDRAW, IFACE_("Max:"), 0, 0, 100, 20,
536
 
                                  &fed->max, -UI_FLT_MAX, UI_FLT_MAX, 10, 2, TIP_("Maximum bound of envelope at this point"));
537
 
                        
538
 
                        but = uiDefIconBut(block, BUT, B_FMODIFIER_REDRAW, ICON_X, 0, 0, 18, 20,
539
 
                                          NULL, 0.0, 0.0, 0.0, 0.0, TIP_("Delete envelope control point"));
540
 
                        uiButSetFunc(but, fmod_envelope_deletepoint_cb, env, SET_INT_IN_POINTER(i));
 
454
                but = uiDefButF(block, NUM, B_FMODIFIER_REDRAW, IFACE_("Fra:"), 0, 0, 90, 20,
 
455
                                &fed->time, -MAXFRAMEF, MAXFRAMEF, 10, 1, TIP_("Frame that envelope point occurs"));
 
456
                uiButSetFunc(but, validate_fmodifier_cb, fcm, NULL);
 
457
                        
 
458
                uiDefButF(block, NUM, B_FMODIFIER_REDRAW, IFACE_("Min:"), 0, 0, 100, 20,
 
459
                          &fed->min, -UI_FLT_MAX, UI_FLT_MAX, 10, 2, TIP_("Minimum bound of envelope at this point"));
 
460
                uiDefButF(block, NUM, B_FMODIFIER_REDRAW, IFACE_("Max:"), 0, 0, 100, 20,
 
461
                          &fed->max, -UI_FLT_MAX, UI_FLT_MAX, 10, 2, TIP_("Maximum bound of envelope at this point"));
 
462
 
 
463
                but = uiDefIconBut(block, BUT, B_FMODIFIER_REDRAW, ICON_X, 0, 0, 18, 20,
 
464
                                   NULL, 0.0, 0.0, 0.0, 0.0, TIP_("Delete envelope control point"));
 
465
                uiButSetFunc(but, fmod_envelope_deletepoint_cb, env, SET_INT_IN_POINTER(i));
541
466
                uiBlockBeginAlign(block);
542
467
        }
543
468
}
555
480
        
556
481
        /* row 1: minimum */
557
482
        {
558
 
                /* row= uiLayoutRow(layout, 0); */ /* UNUSED */
 
483
                /* row = uiLayoutRow(layout, FALSE); */ /* UNUSED */
559
484
                
560
485
                /* split into 2 columns */
561
 
                split= uiLayoutSplit(layout, 0.5f, 0);
 
486
                split = uiLayoutSplit(layout, 0.5f, FALSE);
562
487
                
563
488
                /* x-minimum */
564
 
                col= uiLayoutColumn(split, 1);
565
 
                        uiItemR(col, &ptr, "use_min_x", 0, NULL, ICON_NONE);
566
 
                        uiItemR(col, &ptr, "min_x", 0, NULL, ICON_NONE);
 
489
                col = uiLayoutColumn(split, TRUE);
 
490
                uiItemR(col, &ptr, "use_min_x", 0, NULL, ICON_NONE);
 
491
                uiItemR(col, &ptr, "min_x", 0, NULL, ICON_NONE);
567
492
                        
568
493
                /* y-minimum*/
569
 
                col= uiLayoutColumn(split, 1);
570
 
                        uiItemR(col, &ptr, "use_min_y", 0, NULL, ICON_NONE);
571
 
                        uiItemR(col, &ptr, "min_y", 0, NULL, ICON_NONE);
 
494
                col = uiLayoutColumn(split, TRUE);
 
495
                uiItemR(col, &ptr, "use_min_y", 0, NULL, ICON_NONE);
 
496
                uiItemR(col, &ptr, "min_y", 0, NULL, ICON_NONE);
572
497
        }
573
498
        
574
499
        /* row 2: maximum */
575
500
        {
576
 
                /* row= uiLayoutRow(layout, 0); */ /* UNUSED */
 
501
                /* row = uiLayoutRow(layout, FALSE); */ /* UNUSED */
577
502
                
578
503
                /* split into 2 columns */
579
 
                split= uiLayoutSplit(layout, 0.5f, 0);
 
504
                split = uiLayoutSplit(layout, 0.5f, FALSE);
580
505
                
581
506
                /* x-minimum */
582
 
                col= uiLayoutColumn(split, 1);
583
 
                        uiItemR(col, &ptr, "use_max_x", 0, NULL, ICON_NONE);
584
 
                        uiItemR(col, &ptr, "max_x", 0, NULL, ICON_NONE);
 
507
                col = uiLayoutColumn(split, TRUE);
 
508
                uiItemR(col, &ptr, "use_max_x", 0, NULL, ICON_NONE);
 
509
                uiItemR(col, &ptr, "max_x", 0, NULL, ICON_NONE);
585
510
                        
586
511
                /* y-minimum*/
587
 
                col= uiLayoutColumn(split, 1);
588
 
                        uiItemR(col, &ptr, "use_max_y", 0, NULL, ICON_NONE);
589
 
                        uiItemR(col, &ptr, "max_y", 0, NULL, ICON_NONE);
 
512
                col = uiLayoutColumn(split, TRUE);
 
513
                uiItemR(col, &ptr, "use_max_y", 0, NULL, ICON_NONE);
 
514
                uiItemR(col, &ptr, "max_y", 0, NULL, ICON_NONE);
590
515
        }
591
516
}
592
517
 
602
527
        RNA_pointer_create(id, &RNA_FModifierStepped, fcm, &ptr);
603
528
        
604
529
        /* block 1: "stepping" settings */
605
 
        col= uiLayoutColumn(layout, 0);
606
 
                uiItemR(col, &ptr, "frame_step", 0, NULL, ICON_NONE);
607
 
                uiItemR(col, &ptr, "frame_offset", 0, NULL, ICON_NONE);
 
530
        col = uiLayoutColumn(layout, FALSE);
 
531
        uiItemR(col, &ptr, "frame_step", 0, NULL, ICON_NONE);
 
532
        uiItemR(col, &ptr, "frame_offset", 0, NULL, ICON_NONE);
608
533
                
609
534
        /* block 2: start range settings */
610
 
        col= uiLayoutColumn(layout, 1);
611
 
                uiItemR(col, &ptr, "use_frame_start", 0, NULL, ICON_NONE);
 
535
        col = uiLayoutColumn(layout, TRUE);
 
536
        uiItemR(col, &ptr, "use_frame_start", 0, NULL, ICON_NONE);
612
537
                
613
 
                sub = uiLayoutColumn(col, 1);
614
 
                uiLayoutSetActive(sub, RNA_boolean_get(&ptr, "use_frame_start"));
615
 
                        uiItemR(sub, &ptr, "frame_start", 0, NULL, ICON_NONE);
 
538
        sub = uiLayoutColumn(col, TRUE);
 
539
        uiLayoutSetActive(sub, RNA_boolean_get(&ptr, "use_frame_start"));
 
540
        uiItemR(sub, &ptr, "frame_start", 0, NULL, ICON_NONE);
616
541
                        
617
542
        /* block 3: end range settings */
618
 
        col= uiLayoutColumn(layout, 1);
619
 
                uiItemR(col, &ptr, "use_frame_end", 0, NULL, ICON_NONE);
 
543
        col = uiLayoutColumn(layout, TRUE);
 
544
        uiItemR(col, &ptr, "use_frame_end", 0, NULL, ICON_NONE);
620
545
                
621
 
                sub = uiLayoutColumn(col, 1);
622
 
                uiLayoutSetActive(sub, RNA_boolean_get(&ptr, "use_frame_end"));
623
 
                        uiItemR(sub, &ptr, "frame_end", 0, NULL, ICON_NONE);
 
546
        sub = uiLayoutColumn(col, TRUE);
 
547
        uiLayoutSetActive(sub, RNA_boolean_get(&ptr, "use_frame_end"));
 
548
        uiItemR(sub, &ptr, "frame_end", 0, NULL, ICON_NONE);
624
549
}
625
550
 
626
551
/* --------------- */
627
552
 
628
 
void ANIM_uiTemplate_fmodifier_draw (uiLayout *layout, ID *id, ListBase *modifiers, FModifier *fcm)
 
553
void ANIM_uiTemplate_fmodifier_draw(uiLayout *layout, ID *id, ListBase *modifiers, FModifier *fcm)
629
554
{
630
 
        FModifierTypeInfo *fmi= fmodifier_get_typeinfo(fcm);
 
555
        FModifierTypeInfo *fmi = fmodifier_get_typeinfo(fcm);
631
556
        uiLayout *box, *row, *sub, *col;
632
557
        uiBlock *block;
633
558
        uiBut *but;
634
 
        short width= 314;
 
559
        short width = 314;
635
560
        PointerRNA ptr;
636
561
        
637
562
        /* init the RNA-pointer */
640
565
        /* draw header */
641
566
        {
642
567
                /* get layout-row + UI-block for this */
643
 
                box= uiLayoutBox(layout);
 
568
                box = uiLayoutBox(layout);
644
569
                
645
 
                row= uiLayoutRow(box, 0);
646
 
                block= uiLayoutGetBlock(row); // err...
 
570
                row = uiLayoutRow(box, FALSE);
 
571
                block = uiLayoutGetBlock(row); // err...
647
572
                
648
573
                /* left-align -------------------------------------------- */
649
 
                sub= uiLayoutRow(row, 1);
 
574
                sub = uiLayoutRow(row, TRUE);
650
575
                uiLayoutSetAlignment(sub, UI_LAYOUT_ALIGN_LEFT);
651
576
                
652
577
                uiBlockSetEmboss(block, UI_EMBOSSN);
664
589
                        uiItemL(sub, "<Unknown Modifier>", ICON_NONE);
665
590
                
666
591
                /* right-align ------------------------------------------- */
667
 
                sub= uiLayoutRow(row, 1);
 
592
                sub = uiLayoutRow(row, TRUE);
668
593
                uiLayoutSetAlignment(sub, UI_LAYOUT_ALIGN_RIGHT);
669
594
                
670
595
                
675
600
                
676
601
                /* delete button */
677
602
                but = uiDefIconBut(block, BUT, B_REDR, ICON_X, 0, 0, UI_UNIT_X, UI_UNIT_Y,
678
 
                                  NULL, 0.0, 0.0, 0.0, 0.0, TIP_("Delete F-Curve Modifier"));
 
603
                                   NULL, 0.0, 0.0, 0.0, 0.0, TIP_("Delete F-Curve Modifier"));
679
604
                uiButSetFunc(but, delete_fmodifier_cb, modifiers, fcm);
680
605
                
681
606
                uiBlockSetEmboss(block, UI_EMBOSS);
684
609
        /* when modifier is expanded, draw settings */
685
610
        if (fcm->flag & FMODIFIER_FLAG_EXPANDED) {
686
611
                /* set up the flexible-box layout which acts as the backdrop for the modifier settings */
687
 
                box= uiLayoutBox(layout); 
 
612
                box = uiLayoutBox(layout);
688
613
                
689
614
                /* draw settings for individual modifiers */
690
615
                switch (fcm->type) {
726
651
                        box = uiLayoutBox(layout);
727
652
                        
728
653
                        /* restricted range ----------------------------------------------------- */
729
 
                        col = uiLayoutColumn(box, 1);
 
654
                        col = uiLayoutColumn(box, TRUE);
730
655
                        
731
656
                        /* top row: use restricted range */
732
 
                        row= uiLayoutRow(col, 1);
 
657
                        row = uiLayoutRow(col, TRUE);
733
658
                        uiItemR(row, &ptr, "use_restricted_range", 0, NULL, ICON_NONE);
734
659
                        
735
660
                        if (fcm->flag & FMODIFIER_FLAG_RANGERESTRICT) {
736
661
                                /* second row: settings */
737
 
                                row = uiLayoutRow(col, 1);
 
662
                                row = uiLayoutRow(col, TRUE);
738
663
                                
739
664
                                uiItemR(row, &ptr, "frame_start", 0, IFACE_("Start"), ICON_NONE);
740
665
                                uiItemR(row, &ptr, "frame_end", 0, IFACE_("End"), ICON_NONE);
741
666
                                
742
667
                                /* third row: blending influence */
743
 
                                row = uiLayoutRow(col, 1);
 
668
                                row = uiLayoutRow(col, TRUE);
744
669
                                
745
670
                                uiItemR(row, &ptr, "blend_in", 0, IFACE_("In"), ICON_NONE);
746
671
                                uiItemR(row, &ptr, "blend_out", 0, IFACE_("Out"), ICON_NONE);
747
672
                        }
748
673
                        
749
674
                        /* influence -------------------------------------------------------------- */
750
 
                        col = uiLayoutColumn(box, 1);
 
675
                        col = uiLayoutColumn(box, TRUE);
751
676
                        
752
677
                        /* top row: use influence */
753
678
                        uiItemR(col, &ptr, "use_influence", 0, NULL, ICON_NONE);
769
694
/* ---------- */
770
695
 
771
696
/* free the copy/paste buffer */
772
 
void free_fmodifiers_copybuf (void)
 
697
void free_fmodifiers_copybuf(void)
773
698
{
774
699
        /* just free the whole buffer */
775
700
        free_fmodifiers(&fmodifier_copypaste_buf);
779
704
 * assuming that the buffer has been cleared already with free_fmodifiers_copybuf()
780
705
 *      - active: only copy the active modifier
781
706
 */
782
 
short ANIM_fmodifiers_copy_to_buf (ListBase *modifiers, short active)
 
707
short ANIM_fmodifiers_copy_to_buf(ListBase *modifiers, short active)
783
708
{
784
709
        short ok = 1;
785
710
        
808
733
/* 'Paste' the F-Modifier(s) from the buffer to the specified list 
809
734
 *      - replace: free all the existing modifiers to leave only the pasted ones 
810
735
 */
811
 
short ANIM_fmodifiers_paste_from_buf (ListBase *modifiers, short replace)
 
736
short ANIM_fmodifiers_paste_from_buf(ListBase *modifiers, short replace)
812
737
{
813
738
        FModifier *fcm;
814
739
        short ok = 0;
822
747
                free_fmodifiers(modifiers);
823
748
                
824
749
        /* now copy over all the modifiers in the buffer to the end of the list */
825
 
        for (fcm= fmodifier_copypaste_buf.first; fcm; fcm= fcm->next) {
 
750
        for (fcm = fmodifier_copypaste_buf.first; fcm; fcm = fcm->next) {
826
751
                /* make a copy of it */
827
752
                FModifier *fcmN = copy_fmodifier(fcm);
828
753