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

« back to all changes in this revision

Viewing changes to source/blender/src/buttons_script.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:
39
39
#include <config.h>
40
40
#endif
41
41
 
42
 
#ifdef WIN32
43
 
#include "BLI_winstuff.h"
44
 
#endif
45
 
 
46
42
#include "MEM_guardedalloc.h"
47
43
#include "DNA_action_types.h"
48
44
#include "DNA_armature_types.h"
51
47
#include "DNA_curve_types.h"
52
48
#include "DNA_effect_types.h"
53
49
#include "DNA_group_types.h"
 
50
#include "DNA_ID.h"
54
51
#include "DNA_ika_types.h"
55
52
#include "DNA_image_types.h"
56
53
#include "DNA_key_types.h"
63
60
#include "DNA_screen_types.h"
64
61
#include "DNA_scene_types.h"
65
62
#include "DNA_sound_types.h"
 
63
#include "DNA_text_types.h"
66
64
#include "DNA_texture_types.h"
67
65
#include "DNA_userdef_types.h"
68
66
#include "DNA_vfont_types.h"
81
79
#include "BKE_image.h"
82
80
#include "BKE_ipo.h"
83
81
#include "BKE_lattice.h"
 
82
#include "BKE_main.h"
84
83
#include "BKE_material.h"
85
84
#include "BKE_mball.h"
86
85
#include "BKE_mesh.h"
91
90
#include "BKE_utildefines.h"
92
91
 
93
92
#include "BLI_blenlib.h"
 
93
#include "BLI_dynstr.h"
94
94
 
95
95
#include "BSE_filesel.h"
96
96
 
112
112
#include "blendef.h"
113
113
#include "butspace.h"
114
114
 
115
 
 
116
 
 
117
 
 
118
 
 
 
115
/* ************************ function prototypes ********************** */
 
116
void draw_scriptlink(uiBlock *, ScriptLink *, int , int , int ) ;
119
117
 
120
118
/* *************************** SCRIPT ******************************** */
121
119
 
143
141
        slink->flag[slink->totscript]= SCRIPT_FRAMECHANGED;
144
142
 
145
143
        slink->totscript++;
146
 
                                
147
 
        if(slink->actscript<1) slink->actscript=1;
 
144
        slink->actscript = slink->totscript;
148
145
}
149
146
 
150
147
static void delete_scriptlink(ScriptLink *slink)
174
171
        }
175
172
}
176
173
 
 
174
static char *scriptlinks_menu_string(void)
 
175
{
 
176
        char *menu = NULL;
 
177
        DynStr *ds = BLI_dynstr_new();
 
178
        Text *text = G.main->text.first;
 
179
        int txtcounter = 0;
 
180
 
 
181
        if (text) {
 
182
                BLI_dynstr_append(ds, "Select Script Link%t");
 
183
                while (text) {
 
184
                        BLI_dynstr_append(ds, "|");
 
185
                        BLI_dynstr_append(ds, text->id.name+2);
 
186
                        txtcounter += 1;
 
187
                        text = text->id.next;
 
188
                }
 
189
                if (txtcounter) menu = BLI_dynstr_get_cstring(ds);
 
190
        }
 
191
        BLI_dynstr_free(ds);
 
192
        return menu;
 
193
}
 
194
 
 
195
static void scriptlinks_pupmenu(ScriptLink *slink)
 
196
{
 
197
        short menuitem;
 
198
        char *menustr = scriptlinks_menu_string();
 
199
 
 
200
        if (menustr) {
 
201
                menuitem = pupmenu_col(menustr, 20);
 
202
                MEM_freeN(menustr);
 
203
                if (menuitem > 0) {
 
204
                        Text *text = G.main->text.first;
 
205
                        while (--menuitem) text = text->id.next;
 
206
                        if (text) slink->scripts[slink->totscript - 1]= (ID *)text;
 
207
                }
 
208
        }
 
209
}
 
210
 
177
211
void do_scriptbuts(unsigned short event)
178
212
{
179
213
        Object *ob=NULL;
180
 
        ScriptLink *script=NULL;
 
214
        ScriptLink *slink=NULL;
181
215
        Material *ma;
182
216
        
183
217
        switch (event) {
184
218
        case B_SSCRIPT_ADD:
185
 
                extend_scriptlink(&G.scene->scriptlink);
 
219
                slink = &G.scene->scriptlink;
 
220
                extend_scriptlink(slink);
 
221
                BIF_undo_push("Add scriptlink");
 
222
                scriptlinks_pupmenu(slink);
186
223
                break;
187
224
        case B_SSCRIPT_DEL:
 
225
                BIF_undo_push("Delete scriptlink");
188
226
                delete_scriptlink(&G.scene->scriptlink);
189
227
                break;
190
228
                
193
231
                ob= OBACT;
194
232
 
195
233
                if (ob && G.buts->scriptblock==ID_OB) {
196
 
                                script= &ob->scriptlink;
 
234
                                slink= &ob->scriptlink;
197
235
 
198
236
                } else if (ob && G.buts->scriptblock==ID_MA) {
199
237
                        ma= give_current_material(ob, ob->actcol);
200
 
                        if (ma) script= &ma->scriptlink;
 
238
                        if (ma) slink= &ma->scriptlink;
201
239
 
202
240
                } else if (ob && G.buts->scriptblock==ID_CA) {
203
241
                        if (ob->type==OB_CAMERA)
204
 
                                script= &((Camera *)ob->data)->scriptlink;
 
242
                                slink= &((Camera *)ob->data)->scriptlink;
205
243
 
206
244
                } else if (ob && G.buts->scriptblock==ID_LA) {
207
245
                        if (ob->type==OB_LAMP)
208
 
                                script= &((Lamp *)ob->data)->scriptlink;
 
246
                                slink= &((Lamp *)ob->data)->scriptlink;
209
247
 
210
248
                } else if (G.buts->scriptblock==ID_WO) {
211
249
                        if (G.scene->world) 
212
 
                                script= &(G.scene->world->scriptlink);
213
 
                }
214
 
                
215
 
                if (event==B_SCRIPT_ADD) extend_scriptlink(script);
216
 
                else delete_scriptlink(script);
217
 
                
 
250
                                slink= &(G.scene->world->scriptlink);
 
251
                }
 
252
                
 
253
                if (event==B_SCRIPT_ADD) {
 
254
                        extend_scriptlink(slink);
 
255
                        BIF_undo_push("Add scriptlink");
 
256
                        scriptlinks_pupmenu(slink);
 
257
                }
 
258
                else {
 
259
                        delete_scriptlink(slink);
 
260
                        BIF_undo_push("Delete scriptlink");
 
261
                }
218
262
                break;
219
263
        default:
220
264
                break;
230
274
        if (script->totscript) {
231
275
                strcpy(str, "FrameChanged%x 1|");
232
276
                strcat(str, "Redraw%x 4|");
 
277
                strcat(str, "Render%x 16|");
233
278
                if (scene) {
234
 
                        strcat(str, "OnLoad%x 2");
 
279
                        strcat(str, "OnLoad%x 2|");
 
280
                        strcat(str, "OnSave%x 8");
235
281
                }
236
282
 
237
 
                uiDefButS(block, MENU, 1, str, (short)sx, (short)sy, 140, 19, &script->flag[script->actscript-1], 0, 0, 0, 0, "Script links for the Frame changed event");
 
283
                uiDefButS(block, MENU, 1, str, (short)sx, (short)sy, 140, 19, &script->flag[script->actscript-1], 0, 0, 0, 0, "Script links for this event");
238
284
 
239
285
                uiDefIDPoinBut(block, test_scriptpoin_but, 1, "", (short)(sx+140),(short)sy, 140, 19, &script->scripts[script->actscript-1], "Name of Script to link");
240
286
        }
248
294
                if (script->totscript) 
249
295
                        uiDefBut(block, BUT, B_SSCRIPT_DEL, "Del", (short)(sx+200), (short)sy-20, 40, 19, 0, 0, 0, 0, 0, "Delete the current Script link");
250
296
 
251
 
                uiDefBut(block, LABEL, 0, "Scene scriptlink",   sx,sy-20,140,20, 0, 0, 0, 0, 0, "");
 
297
                uiDefBut(block, LABEL, 0, "Scene Script link",  sx,sy-20,140,20, 0, 0, 0, 0, 0, "");
252
298
 
253
299
        } 
254
300
        else {
257
303
                if (script->totscript) 
258
304
                        uiDefBut(block, BUT, B_SCRIPT_DEL, "Del", (short)(sx+200), (short)sy-20, 40, 19, 0, 0, 0, 0, 0, "Delete the current Script link");
259
305
 
260
 
                uiDefBut(block, LABEL, 0, "Selected scriptlink",        sx,sy-20,140,20, 0, 0, 0, 0, 0, "");
 
306
                uiDefBut(block, LABEL, 0, "Selected Script link",       sx,sy-20,140,20, 0, 0, 0, 0, 0, "");
261
307
        }               
262
308
}
263
309
 
270
316
        ScriptLink *script=NULL;
271
317
        Material *ma;
272
318
        int xco = 10;
273
 
        
 
319
 
274
320
        block= uiNewBlock(&curarea->uiblocks, "script_panel_scriptlink", UI_EMBOSS, UI_HELV, curarea->win);
275
321
        if(uiNewPanel(curarea, block, "Scriptlinks", "Script", 0, 0, 318, 204)==0) return;
276
 
        
277
 
        
278
 
        ob= OBACT;
279
 
        if(ob) 
280
 
                uiDefIconButS(block, ROW, B_REDR, ICON_OBJECT, xco,180,25,20, &G.buts->scriptblock,  2.0, (float)ID_OB, 0, 0, "Displays Object script links");
281
 
 
282
 
        if(ob && give_current_material(ob, ob->actcol))
283
 
                uiDefIconButS(block, ROW, B_REDR, ICON_MATERIAL,        xco+=25,180,25,20, &G.buts->scriptblock, 2.0, (float)ID_MA, 0, 0, "Displays Material script links ");
284
 
 
285
 
        if(G.scene->world) 
286
 
                uiDefIconButS(block, ROW, B_REDR, ICON_WORLD,   xco+=25,180,25,20, &G.buts->scriptblock, 2.0, (float)ID_WO, 0, 0, "Displays World script links");
287
 
 
288
 
        if(ob && ob->type==OB_CAMERA)
289
 
                uiDefIconButS(block, ROW, B_REDR, ICON_CAMERA,  xco+=25,180,25,20, &G.buts->scriptblock, 2.0, (float)ID_CA, 0, 0, "Displays Camera script links");
290
 
 
291
 
        if(ob && ob->type==OB_LAMP)
292
 
                uiDefIconButS(block, ROW, B_REDR, ICON_LAMP,    xco+=25,180,25,20, &G.buts->scriptblock, 2.0, (float)ID_LA, 0, 0, "Displays Lamp script links");
293
 
 
294
 
 
295
 
        if (ob && G.buts->scriptblock==ID_OB) {
296
 
                script= &ob->scriptlink;
297
 
                
298
 
        } else if (ob && G.buts->scriptblock==ID_MA) {
299
 
                ma= give_current_material(ob, ob->actcol);
300
 
                if (ma) script= &ma->scriptlink;
301
 
                
302
 
        } else if (ob && G.buts->scriptblock==ID_CA) {
303
 
                if (ob->type==OB_CAMERA)
304
 
                        script= &((Camera *)ob->data)->scriptlink;
 
322
 
 
323
        uiDefButI(block, TOG|BIT|13, REDRAWBUTSSCRIPT,
 
324
                        "Enable Script Links", xco, 200, 150, 20, &G.f, 0, 0, 0, 0,
 
325
                        "Enable execution of all assigned Script links");
 
326
        /* for proper alignment: */
 
327
        uiDefBut(block, LABEL, 0, "",   160, 200,150,20, NULL, 0.0, 0.0, 0, 0, "");
 
328
 
 
329
        if (G.f & G_DOSCRIPTLINKS) {
 
330
                ob= OBACT;
 
331
                if(ob) 
 
332
                        uiDefIconButS(block, ROW, B_REDR, ICON_OBJECT, xco,175,25,20, &G.buts->scriptblock,  2.0, (float)ID_OB, 0, 0, "Displays Object script links");
 
333
 
 
334
                if(ob && give_current_material(ob, ob->actcol))
 
335
                        uiDefIconButS(block, ROW, B_REDR, ICON_MATERIAL,        xco+=25,175,25,20, &G.buts->scriptblock, 2.0, (float)ID_MA, 0, 0, "Displays Material script links ");
 
336
 
 
337
                if(G.scene->world) 
 
338
                        uiDefIconButS(block, ROW, B_REDR, ICON_WORLD,   xco+=25,175,25,20, &G.buts->scriptblock, 2.0, (float)ID_WO, 0, 0, "Displays World script links");
 
339
 
 
340
                if(ob && ob->type==OB_CAMERA)
 
341
                        uiDefIconButS(block, ROW, B_REDR, ICON_CAMERA,  xco+=25,175,25,20, &G.buts->scriptblock, 2.0, (float)ID_CA, 0, 0, "Displays Camera script links");
 
342
 
 
343
                if(ob && ob->type==OB_LAMP)
 
344
                        uiDefIconButS(block, ROW, B_REDR, ICON_LAMP,    xco+=25,175,25,20, &G.buts->scriptblock, 2.0, (float)ID_LA, 0, 0, "Displays Lamp script links");
 
345
 
 
346
 
 
347
                if (ob && G.buts->scriptblock==ID_OB) {
 
348
                        script= &ob->scriptlink;
 
349
                
 
350
                } else if (ob && G.buts->scriptblock==ID_MA) {
 
351
                        ma= give_current_material(ob, ob->actcol);
 
352
                        if (ma) script= &ma->scriptlink;
 
353
                
 
354
                } else if (ob && G.buts->scriptblock==ID_CA) {
 
355
                        if (ob->type==OB_CAMERA)
 
356
                                script= &((Camera *)ob->data)->scriptlink;
305
357
                        
306
 
        } else if (ob && G.buts->scriptblock==ID_LA) {
307
 
                if (ob->type==OB_LAMP)
308
 
                        script= &((Lamp *)ob->data)->scriptlink;
309
 
 
310
 
        } else if (G.buts->scriptblock==ID_WO) {
311
 
                if (G.scene->world)
312
 
                        script= &(G.scene->world->scriptlink);
 
358
                } else if (ob && G.buts->scriptblock==ID_LA) {
 
359
                        if (ob->type==OB_LAMP)
 
360
                                script= &((Lamp *)ob->data)->scriptlink;
 
361
 
 
362
                } else if (G.buts->scriptblock==ID_WO) {
 
363
                        if (G.scene->world)
 
364
                                script= &(G.scene->world->scriptlink);
 
365
                }
 
366
 
 
367
                if (script) draw_scriptlink(block, script, 10, 140, 0);                 
 
368
 
 
369
                draw_scriptlink(block, &G.scene->scriptlink, 10, 80, 1);
313
370
        }
314
 
 
315
 
        if (script) draw_scriptlink(block, script, 10, 140, 0);                 
316
 
 
317
 
        draw_scriptlink(block, &G.scene->scriptlink, 10, 80, 1);
318
 
 
319
 
 
320
371
}
321
372
 
322
373