NLA SoC: Merge from 2.5
[blender-staging.git] / source / blender / editors / interface / interface_templates.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * Contributor(s): Blender Foundation 2009.
21  *
22  * ***** END GPL LICENSE BLOCK *****
23  */
24
25 #include <stdlib.h>
26 #include <string.h>
27
28 #include "MEM_guardedalloc.h"
29
30 #include "DNA_scene_types.h"
31 #include "DNA_screen_types.h"
32
33 #include "BLI_string.h"
34
35 #include "BKE_context.h"
36 #include "BKE_icons.h"
37 #include "BKE_global.h"
38 #include "BKE_library.h"
39 #include "BKE_utildefines.h"
40
41 #include "ED_screen.h"
42 #include "ED_previewrender.h"
43
44 #include "RNA_access.h"
45
46 #include "WM_api.h"
47 #include "WM_types.h"
48
49 #include "UI_interface.h"
50 #include "UI_resources.h"
51 #include "interface_intern.h"
52
53 void ui_template_fix_linking()
54 {
55 }
56
57 /********************** Header Template *************************/
58
59 void uiTemplateHeader(uiLayout *layout, bContext *C)
60 {
61         uiBlock *block;
62         
63         block= uiLayoutFreeBlock(layout);
64         ED_area_header_standardbuttons(C, block, 0);
65 }
66
67 /********************** Search Callbacks *************************/
68
69 typedef struct TemplateID {
70         PointerRNA ptr;
71         PropertyRNA *prop;
72
73         ListBase *idlb;
74 } TemplateID;
75
76 /* Search browse menu, assign  */
77 static void id_search_call_cb(struct bContext *C, void *arg_template, void *item)
78 {
79         TemplateID *template= (TemplateID*)arg_template;
80
81         /* ID */
82         if(item) {
83                 PointerRNA idptr;
84
85                 RNA_id_pointer_create(item, &idptr);
86                 RNA_property_pointer_set(&template->ptr, template->prop, idptr);
87                 RNA_property_update(C, &template->ptr, template->prop);
88         }
89 }
90
91 /* ID Search browse menu, do the search */
92 static void id_search_cb(const struct bContext *C, void *arg_template, char *str, uiSearchItems *items)
93 {
94         TemplateID *template= (TemplateID*)arg_template;
95         Scene *scene= CTX_data_scene(C);
96         ListBase *lb= template->idlb;
97         ID *id;
98         int iconid;
99
100         /* ID listbase */
101         for(id= lb->first; id; id= id->next) {
102                 iconid= ui_id_icon_get(scene, id);
103
104                 if(BLI_strcasestr(id->name+2, str))
105                         if(!uiSearchItemAdd(items, id->name+2, id, iconid))
106                                 break;
107         }
108 }
109
110 /* ID Search browse menu, open */
111 static uiBlock *search_menu(bContext *C, ARegion *ar, void *arg_litem)
112 {
113         static char search[256];
114         static TemplateID template;
115         PointerRNA idptr;
116         wmEvent event;
117         wmWindow *win= CTX_wm_window(C);
118         uiBlock *block;
119         uiBut *but;
120         
121         /* clear initial search string, then all items show */
122         search[0]= 0;
123         /* arg_litem is malloced, can be freed by parent button */
124         template= *((TemplateID*)arg_litem);
125         
126         /* get active id for showing first item */
127         idptr= RNA_property_pointer_get(&template.ptr, template.prop);
128
129         block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
130         uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_RET_1);
131         
132         /* fake button, it holds space for search items */
133         uiDefBut(block, LABEL, 0, "", 10, 15, 150, uiSearchBoxhHeight(), NULL, 0, 0, 0, 0, NULL);
134         
135         but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, 256, 10, 0, 150, 19, "");
136         uiButSetSearchFunc(but, id_search_cb, &template, id_search_call_cb, idptr.data);
137         
138         uiBoundsBlock(block, 6);
139         uiBlockSetDirection(block, UI_DOWN);    
140         uiEndBlock(C, block);
141         
142         event= *(win->eventstate);      /* XXX huh huh? make api call */
143         event.type= EVT_BUT_OPEN;
144         event.val= KM_PRESS;
145         event.customdata= but;
146         event.customdatafree= FALSE;
147         wm_event_add(win, &event);
148         
149         return block;
150 }
151
152 /************************ ID Template ***************************/
153
154 static void template_id_cb(bContext *C, void *arg_litem, void *arg_event)
155 {
156         TemplateID *template= (TemplateID*)arg_litem;
157         PointerRNA idptr= RNA_property_pointer_get(&template->ptr, template->prop);
158         ID *id= idptr.data;
159         int event= GET_INT_FROM_POINTER(arg_event);
160         
161         switch(event) {
162                 case UI_ID_BROWSE:
163                 case UI_ID_PIN:
164                         printf("warning, id event %d shouldnt come here\n", event);
165                         break;
166                 case UI_ID_OPEN:
167                 case UI_ID_ADD_NEW:
168                         if(template->idlb->last) {
169                                 RNA_id_pointer_create(template->idlb->last, &idptr);
170                                 RNA_property_pointer_set(&template->ptr, template->prop, idptr);
171                                 RNA_property_update(C, &template->ptr, template->prop);
172                         }
173                         break;
174                 case UI_ID_DELETE:
175                         memset(&idptr, 0, sizeof(idptr));
176                         RNA_property_pointer_set(&template->ptr, template->prop, idptr);
177                         RNA_property_update(C, &template->ptr, template->prop);
178                         break;
179                 case UI_ID_FAKE_USER:
180                         if(id) {
181                                 if(id->flag & LIB_FAKEUSER) id->us++;
182                                 else id->us--;
183                         }
184                         else return;
185                         break;
186 #if 0
187                 case UI_ID_ALONE:
188                         if(!id || id->us < 1)
189                                 return;
190                         break;
191                 case UI_ID_LOCAL:
192                         if(!id || id->us < 1)
193                                 return;
194                         break;
195                 case UI_ID_AUTO_NAME:
196                         break;
197 #endif
198         }
199 }
200
201 static void template_ID(bContext *C, uiBlock *block, TemplateID *template, StructRNA *type, int flag, char *newop, char *unlinkop)
202 {
203         uiBut *but;
204         PointerRNA idptr;
205         ListBase *lb;
206
207         idptr= RNA_property_pointer_get(&template->ptr, template->prop);
208         lb= template->idlb;
209
210         uiBlockBeginAlign(block);
211
212         if(idptr.type)
213                 type= idptr.type;
214
215         if(flag & UI_ID_BROWSE) {
216                 but= uiDefBlockButN(block, search_menu, MEM_dupallocN(template), "", 0, 0, UI_UNIT_X*1.6, UI_UNIT_Y, "Browse ID data");
217                 if(type) {
218                         but->icon= RNA_struct_ui_icon(type);
219                         but->flag|= UI_HAS_ICON;
220                         but->flag|= UI_ICON_LEFT;
221                 }
222         }
223
224         /* text button with name */
225         if(idptr.data) {
226                 char name[64];
227
228                 //text_idbutton(idptr.data, name);
229                 name[0]= '\0';
230                 but= uiDefButR(block, TEX, 0, name, 0, 0, UI_UNIT_X*6, UI_UNIT_Y, &idptr, "name", -1, 0, 0, -1, -1, NULL);
231                 uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_RENAME));
232         }
233         
234         if(flag & UI_ID_ADD_NEW) {
235                 int w= idptr.data?UI_UNIT_X:UI_UNIT_X*6;
236                 
237                 if(newop) {
238                         but= uiDefIconTextButO(block, BUT, newop, WM_OP_EXEC_REGION_WIN, ICON_ZOOMIN, "Add New", 0, 0, w, UI_UNIT_Y, NULL);
239                         uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_ADD_NEW));
240                 }
241                 else {
242                         but= uiDefIconTextBut(block, BUT, 0, ICON_ZOOMIN, "Add New", 0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, NULL);
243                         uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_ADD_NEW));
244                 }
245         }
246         
247         /* delete button */
248         if(idptr.data && (flag & UI_ID_DELETE)) {
249                 if(unlinkop) {
250                         but= uiDefIconButO(block, BUT, unlinkop, WM_OP_EXEC_REGION_WIN, ICON_X, 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL);
251                 }
252                 else {
253                         but= uiDefIconBut(block, BUT, 0, ICON_X, 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL, 0, 0, 0, 0, NULL);
254                         uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_DELETE));
255                 }
256         }
257         
258         uiBlockEndAlign(block);
259 }
260
261 void uiTemplateID(uiLayout *layout, bContext *C, PointerRNA *ptr, char *propname, char *newop, char *unlinkop)
262 {
263         TemplateID *template;
264         uiBlock *block;
265         PropertyRNA *prop;
266         StructRNA *type;
267         int flag;
268
269         if(!ptr->data)
270                 return;
271
272         prop= RNA_struct_find_property(ptr, propname);
273
274         if(!prop || RNA_property_type(prop) != PROP_POINTER) {
275                 printf("uiTemplateID: pointer property not found: %s\n", propname);
276                 return;
277         }
278
279         template= MEM_callocN(sizeof(TemplateID), "TemplateID");
280         template->ptr= *ptr;
281         template->prop= prop;
282
283         flag= UI_ID_BROWSE|UI_ID_RENAME|UI_ID_DELETE;
284
285         if(newop)
286                 flag |= UI_ID_ADD_NEW;
287
288         type= RNA_property_pointer_type(ptr, prop);
289         template->idlb= wich_libbase(CTX_data_main(C), RNA_type_to_ID_code(type));
290
291         if(template->idlb) {
292                 uiLayoutRow(layout, 1);
293                 block= uiLayoutGetBlock(layout);
294                 template_ID(C, block, template, type, flag, newop, unlinkop);
295         }
296
297         MEM_freeN(template);
298 }
299
300 /************************ Modifier Template *************************/
301
302 #define ERROR_LIBDATA_MESSAGE "Can't edit external libdata"
303
304 #include <string.h>
305
306 #include "DNA_object_force.h"
307 #include "DNA_object_types.h"
308 #include "DNA_modifier_types.h"
309 #include "DNA_scene_types.h"
310
311 #include "BKE_depsgraph.h"
312 #include "BKE_DerivedMesh.h"
313 #include "BKE_global.h"
314 #include "BKE_modifier.h"
315 #include "BKE_object.h"
316 #include "BKE_particle.h"
317 #include "BKE_report.h"
318
319 #include "UI_resources.h"
320 #include "ED_util.h"
321
322 #include "BLI_arithb.h"
323 #include "BLI_listbase.h"
324
325 #include "ED_object.h"
326
327 static void modifiers_setOnCage(bContext *C, void *ob_v, void *md_v)
328 {
329         Scene *scene= CTX_data_scene(C);
330         Object *ob = ob_v;
331         ModifierData *md;
332         
333         int i, cageIndex = modifiers_getCageIndex(ob, NULL );
334
335         for(i = 0, md=ob->modifiers.first; md; ++i, md=md->next) {
336                 if(md == md_v) {
337                         if(i >= cageIndex)
338                                 md->mode ^= eModifierMode_OnCage;
339                         break;
340                 }
341         }
342
343         WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob);
344         DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
345 }
346
347 static void modifiers_convertToReal(bContext *C, void *ob_v, void *md_v)
348 {
349         Scene *scene= CTX_data_scene(C);
350         Object *ob = ob_v;
351         ModifierData *md = md_v;
352         ModifierData *nmd = modifier_new(md->type);
353
354         modifier_copyData(md, nmd);
355         nmd->mode &= ~eModifierMode_Virtual;
356
357         BLI_addhead(&ob->modifiers, nmd);
358
359         ob->partype = PAROBJECT;
360
361         WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob);
362         DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
363
364         ED_undo_push(C, "Modifier convert to real");
365 }
366
367 static int modifier_can_delete(ModifierData *md)
368 {
369         // fluid particle modifier can't be deleted here
370         if(md->type == eModifierType_ParticleSystem)
371                 if(((ParticleSystemModifierData *)md)->psys->part->type == PART_FLUID)
372                         return 0;
373
374         return 1;
375 }
376
377 static uiLayout *draw_modifier(uiLayout *layout, Object *ob, ModifierData *md, int index, int cageIndex, int lastCageIndex)
378 {
379         ModifierTypeInfo *mti = modifierType_getInfo(md->type);
380         PointerRNA ptr;
381         uiBut *but;
382         uiBlock *block;
383         uiLayout *column, *row, *result= NULL;
384         int isVirtual = md->mode & eModifierMode_Virtual;
385         // XXX short color = md->error?TH_REDALERT:TH_BUT_NEUTRAL;
386         char str[128];
387
388         /* create RNA pointer */
389         RNA_pointer_create(&ob->id, &RNA_Modifier, md, &ptr);
390
391         column= uiLayoutColumn(layout, 1);
392         uiLayoutSetContextPointer(column, "modifier", &ptr);
393
394         /* rounded header */
395         /* XXX uiBlockSetCol(block, color); */
396                 /* roundbox 4 free variables: corner-rounding, nop, roundbox type, shade */
397
398         row= uiLayoutRow(uiLayoutBox(column), 0);
399         uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_EXPAND);
400
401         block= uiLayoutGetBlock(row);
402
403         //uiDefBut(block, ROUNDBOX, 0, "", x-10, y-4, width, 25, NULL, 7.0, 0.0, 
404         //               (!isVirtual && (md->mode & eModifierMode_Expanded))?3:15, 20, ""); 
405         /* XXX uiBlockSetCol(block, TH_AUTO); */
406         
407         /* open/close icon */
408         if(!isVirtual) {
409                 uiBlockSetEmboss(block, UI_EMBOSSN);
410                 uiDefIconButBitI(block, ICONTOG, eModifierMode_Expanded, 0, ICON_TRIA_RIGHT, 0, 0, UI_UNIT_X, UI_UNIT_Y, &md->mode, 0.0, 0.0, 0.0, 0.0, "Collapse/Expand Modifier");
411         }
412         
413         /* modifier-type icon */
414         uiItemL(row, "", RNA_struct_ui_icon(ptr.type));
415         
416         uiBlockSetEmboss(block, UI_EMBOSS);
417         
418         if(isVirtual) {
419                 /* virtual modifier */
420                 sprintf(str, "%s parent deform", md->name);
421                 uiDefBut(block, LABEL, 0, str, 0, 0, 185, UI_UNIT_Y, NULL, 0.0, 0.0, 0.0, 0.0, "Modifier name"); 
422
423                 but = uiDefBut(block, BUT, 0, "Make Real", 0, 0, 80, 16, NULL, 0.0, 0.0, 0.0, 0.0, "Convert virtual modifier to a real modifier");
424                 uiButSetFunc(but, modifiers_convertToReal, ob, md);
425         }
426         else {
427                 /* real modifier */
428                 uiBlockBeginAlign(block);
429                 uiItemR(row, "", 0, &ptr, "name", 0, 0, 0);
430
431                 /* Softbody not allowed in this situation, enforce! */
432                 if(((md->type!=eModifierType_Softbody && md->type!=eModifierType_Collision) || !(ob->pd && ob->pd->deflect)) && (md->type!=eModifierType_Surface)) {
433                         uiItemR(row, "", ICON_SCENE, &ptr, "render", 0, 0, 0);
434                         uiItemR(row, "", ICON_VIEW3D, &ptr, "realtime", 0, 0, 0);
435
436                         if(mti->flags & eModifierTypeFlag_SupportsEditmode)
437                                 uiItemR(row, "", ICON_VIEW3D, &ptr, "editmode", 0, 0, 0);
438                 }
439                 uiBlockEndAlign(block);
440
441                 /* XXX uiBlockSetEmboss(block, UI_EMBOSSR); */
442
443                 if(ob->type==OB_MESH && modifier_couldBeCage(md) && index<=lastCageIndex) {
444                         int icon; //, color;
445
446                         if(index==cageIndex) {
447                                 // XXX color = TH_BUT_SETTING;
448                                 icon = VICON_EDITMODE_HLT;
449                         } else if(index<cageIndex) {
450                                 // XXX color = TH_BUT_NEUTRAL;
451                                 icon = VICON_EDITMODE_DEHLT;
452                         } else {
453                                 // XXX color = TH_BUT_NEUTRAL;
454                                 icon = ICON_BLANK1;
455                         }
456                         /* XXX uiBlockSetCol(block, color); */
457                         but = uiDefIconBut(block, BUT, 0, icon, 0, 0, 16, 16, NULL, 0.0, 0.0, 0.0, 0.0, "Apply modifier to editing cage during Editmode");
458                         uiButSetFunc(but, modifiers_setOnCage, ob, md);
459                         /* XXX uiBlockSetCol(block, TH_AUTO); */
460                 }
461         }
462
463         /* up/down/delete */
464         if(!isVirtual) {
465                 /* XXX uiBlockSetCol(block, TH_BUT_ACTION); */
466                 uiItemO(row, "", VICON_MOVE_UP, "OBJECT_OT_modifier_move_up");
467                 uiItemO(row, "", VICON_MOVE_DOWN, "OBJECT_OT_modifier_move_down");
468                 
469                 uiBlockSetEmboss(block, UI_EMBOSSN);
470
471                 if(modifier_can_delete(md))
472                         uiItemO(row, "", VICON_X, "OBJECT_OT_modifier_remove");
473
474                 /* XXX uiBlockSetCol(block, TH_AUTO); */
475         }
476
477         uiBlockSetEmboss(block, UI_EMBOSS);
478
479         if(!isVirtual && (md->mode & eModifierMode_Expanded)) {
480                 /* apply/convert/copy */
481                 uiLayout *box;
482
483                 box= uiLayoutBox(column);
484                 row= uiLayoutRow(box, 1);
485
486                 if(!isVirtual && (md->type!=eModifierType_Collision) && (md->type!=eModifierType_Surface)) {
487                         /* only here obdata, the rest of modifiers is ob level */
488                         uiBlockSetButLock(block, object_data_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
489
490                         if(md->type==eModifierType_ParticleSystem) {
491                         ParticleSystem *psys= ((ParticleSystemModifierData *)md)->psys;
492
493                         if(!(G.f & G_PARTICLEEDIT))
494                                         if(ELEM3(psys->part->ren_as, PART_DRAW_PATH, PART_DRAW_GR, PART_DRAW_OB) && psys->pathcache)
495                                                 uiItemO(row, "Convert", 0, "OBJECT_OT_modifier_convert");
496                         }
497                         else
498                                 uiItemO(row, "Apply", 0, "OBJECT_OT_modifier_apply");
499                         
500                         uiBlockClearButLock(block);
501                         uiBlockSetButLock(block, ob && ob->id.lib, ERROR_LIBDATA_MESSAGE);
502
503                         if(!ELEM4(md->type, eModifierType_Fluidsim, eModifierType_Softbody, eModifierType_ParticleSystem, eModifierType_Cloth))
504                                 uiItemO(row, "Copy", 0, "OBJECT_OT_modifier_copy");
505                 }
506
507                 result= uiLayoutColumn(box, 0);
508                 block= uiLayoutFreeBlock(box);
509         }
510
511         if(md->error) {
512                 row = uiLayoutRow(uiLayoutBox(column), 0);
513
514                 /* XXX uiBlockSetCol(block, color); */
515                 uiItemL(row, md->error, ICON_ERROR);
516                 /* XXX uiBlockSetCol(block, TH_AUTO); */
517         }
518
519         return result;
520 }
521
522 uiLayout *uiTemplateModifier(uiLayout *layout, PointerRNA *ptr)
523 {
524         Object *ob;
525         ModifierData *md, *vmd;
526         int i, lastCageIndex, cageIndex;
527
528         /* verify we have valid data */
529         if(!RNA_struct_is_a(ptr->type, &RNA_Modifier)) {
530                 printf("uiTemplateModifier: expected modifier on object.\n");
531                 return NULL;
532         }
533
534         ob= ptr->id.data;
535         md= ptr->data;
536
537         if(!ob || !(GS(ob->id.name) == ID_OB)) {
538                 printf("uiTemplateModifier: expected modifier on object.\n");
539                 return NULL;
540         }
541         
542         uiBlockSetButLock(uiLayoutGetBlock(layout), (ob && ob->id.lib), ERROR_LIBDATA_MESSAGE);
543         
544         /* find modifier and draw it */
545         cageIndex = modifiers_getCageIndex(ob, &lastCageIndex);
546
547         // XXX virtual modifiers are not accesible for python
548         vmd = modifiers_getVirtualModifierList(ob);
549
550         for(i=0; vmd; i++, vmd=vmd->next) {
551                 if(md == vmd)
552                         return draw_modifier(layout, ob, md, i, cageIndex, lastCageIndex);
553                 else if(vmd->mode & eModifierMode_Virtual)
554                         i--;
555         }
556
557         return NULL;
558 }
559
560 /************************ Constraint Template *************************/
561
562 #include "DNA_action_types.h"
563 #include "DNA_constraint_types.h"
564
565 #include "BKE_action.h"
566 #include "BKE_constraint.h"
567
568 #define REDRAWIPO                                       1
569 #define REDRAWNLA                                       2
570 #define REDRAWBUTSOBJECT                        3               
571 #define REDRAWACTION                            4
572 #define B_CONSTRAINT_TEST                       5
573 #define B_CONSTRAINT_CHANGETARGET       6
574 #define B_CONSTRAINT_INF                        7
575 #define REMAKEIPO                                       8
576 #define B_DIFF                                          9
577
578 void do_constraint_panels(bContext *C, void *arg, int event)
579 {
580         Scene *scene= CTX_data_scene(C);
581         Object *ob= CTX_data_active_object(C);
582         
583         switch(event) {
584         case B_CONSTRAINT_TEST:
585                 // XXX allqueue(REDRAWVIEW3D, 0);
586                 // XXX allqueue(REDRAWBUTSOBJECT, 0);
587                 // XXX allqueue(REDRAWBUTSEDIT, 0);
588                 break;  // no handling
589         case B_CONSTRAINT_INF:
590                 /* influence; do not execute actions for 1 dag_flush */
591                 if (ob->pose)
592                         ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK);
593                 break;
594         case B_CONSTRAINT_CHANGETARGET:
595                 if (ob->pose) ob->pose->flag |= POSE_RECALC;    // checks & sorts pose channels
596                 DAG_scene_sort(scene);
597                 break;
598         default:
599                 break;
600         }
601
602         object_test_constraints(ob);
603         
604         if(ob->pose) update_pose_constraint_flags(ob->pose);
605         
606         if(ob->type==OB_ARMATURE) DAG_object_flush_update(scene, ob, OB_RECALC_DATA|OB_RECALC_OB);
607         else DAG_object_flush_update(scene, ob, OB_RECALC_OB);
608         
609         // XXX allqueue(REDRAWVIEW3D, 0);
610         // XXX allqueue(REDRAWBUTSOBJECT, 0);
611         // XXX allqueue(REDRAWBUTSEDIT, 0);
612 }
613
614 static void constraint_active_func(bContext *C, void *ob_v, void *con_v)
615 {
616         ED_object_constraint_set_active(ob_v, con_v);
617 }
618
619 static void del_constraint_func (bContext *C, void *ob_v, void *con_v)
620 {
621         if(ED_object_constraint_delete(NULL, ob_v, con_v))
622                 ED_undo_push(C, "Delete Constraint");
623 }
624
625 static void verify_constraint_name_func (bContext *C, void *con_v, void *name_v)
626 {
627         Object *ob= CTX_data_active_object(C);
628         bConstraint *con= con_v;
629         char oldname[32];       
630         
631         if (!con)
632                 return;
633         
634         /* put on the stack */
635         BLI_strncpy(oldname, (char *)name_v, 32);
636         
637         ED_object_constraint_rename(ob, con, oldname);
638         ED_object_constraint_set_active(ob, con);
639         // XXX allqueue(REDRAWACTION, 0); 
640 }
641
642 static void constraint_moveUp(bContext *C, void *ob_v, void *con_v)
643 {
644         if(ED_object_constraint_move_up(NULL, ob_v, con_v))
645                 ED_undo_push(C, "Move Constraint");
646 }
647
648 static void constraint_moveDown(bContext *C, void *ob_v, void *con_v)
649 {
650         if(ED_object_constraint_move_down(NULL, ob_v, con_v))
651                 ED_undo_push(C, "Move Constraint");
652 }
653
654 /* some commonly used macros in the constraints drawing code */
655 #define is_armature_target(target) (target && target->type==OB_ARMATURE)
656 #define is_armature_owner(ob) ((ob->type == OB_ARMATURE) && (ob->flag & OB_POSEMODE))
657 #define is_geom_target(target) (target && (ELEM(target->type, OB_MESH, OB_LATTICE)) )
658
659 /* Helper function for draw constraint - draws constraint space stuff 
660  * This function should not be called if no menus are required 
661  * owner/target: -1 = don't draw menu; 0= not posemode, 1 = posemode 
662  */
663 static void draw_constraint_spaceselect (uiBlock *block, bConstraint *con, short xco, short yco, short owner, short target)
664 {
665         short tarx, ownx, iconx;
666         short bwidth;
667         short iconwidth = 20;
668         
669         /* calculate sizes and placement of menus */
670         if (owner == -1) {
671                 bwidth = 125;
672                 tarx = 120;
673                 ownx = 0;
674         }
675         else if (target == -1) {
676                 bwidth = 125;
677                 tarx = 0;
678                 ownx = 120;
679         }
680         else {
681                 bwidth = 100;
682                 tarx = 85;
683                 iconx = tarx + bwidth + 5;
684                 ownx = tarx + bwidth + iconwidth + 10;
685         }
686         
687         
688         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Convert:", xco, yco, 80,18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
689
690         /* Target-Space */
691         if (target == 1) {
692                 uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Target Space %t|World Space %x0|Pose Space %x2|Local with Parent %x3|Local Space %x1", 
693                                                                                                 tarx, yco, bwidth, 18, &con->tarspace, 0, 0, 0, 0, "Choose space that target is evaluated in"); 
694         }
695         else if (target == 0) {
696                 uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Target Space %t|World Space %x0|Local (Without Parent) Space %x1", 
697                                                                                 tarx, yco, bwidth, 18, &con->tarspace, 0, 0, 0, 0, "Choose space that target is evaluated in"); 
698         }
699         
700         if ((target != -1) && (owner != -1))
701                 uiDefIconBut(block, LABEL, 0, ICON_ARROW_LEFTRIGHT,
702                         iconx, yco, 20, 20, NULL, 0.0, 0.0, 0.0, 0.0, "");
703         
704         /* Owner-Space */
705         if (owner == 1) {
706                 uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Owner Space %t|World Space %x0|Pose Space %x2|Local with Parent %x3|Local Space %x1", 
707                                                                                                 ownx, yco, bwidth, 18, &con->ownspace, 0, 0, 0, 0, "Choose space that owner is evaluated in");  
708         }
709         else if (owner == 0) {
710                 uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Owner Space %t|World Space %x0|Local (Without Parent) Space %x1", 
711                                                                                 ownx, yco, bwidth, 18, &con->ownspace, 0, 0, 0, 0, "Choose space that owner is evaluated in");  
712         }
713 }
714
715 /* draw panel showing settings for a constraint */
716 static uiLayout *draw_constraint(uiLayout *layout, Object *ob, bConstraint *con)
717 {
718         bPoseChannel *pchan= get_active_posechannel(ob);
719         bConstraintTypeInfo *cti;
720         uiBlock *block;
721         uiLayout *result= NULL, *col, *box, *row, *subrow;
722         uiBut *but;
723         PointerRNA ptr;
724         char typestr[32];
725         short width = 265;
726         short proxy_protected, xco=0, yco=0;
727         int rb_col;
728
729         /* get constraint typeinfo */
730         cti= constraint_get_typeinfo(con);
731         if (cti == NULL) {
732                 /* exception for 'Null' constraint - it doesn't have constraint typeinfo! */
733                 if (con->type == CONSTRAINT_TYPE_NULL)
734                         strcpy(typestr, "Null");
735                 else
736                         strcpy(typestr, "Unknown");
737         }
738         else
739                 strcpy(typestr, cti->name);
740                 
741         /* determine whether constraint is proxy protected or not */
742         if (proxylocked_constraints_owner(ob, pchan))
743                 proxy_protected= (con->flag & CONSTRAINT_PROXY_LOCAL)==0;
744         else
745                 proxy_protected= 0;
746
747         /* unless button has own callback, it adds this callback to button */
748         block= uiLayoutGetBlock(layout);
749         uiBlockSetHandleFunc(block, do_constraint_panels, NULL);
750         uiBlockSetFunc(block, constraint_active_func, ob, con);
751
752         RNA_pointer_create(&ob->id, &RNA_Constraint, con, &ptr);
753
754         col= uiLayoutColumn(layout, 1);
755         uiLayoutSetContextPointer(col, "constraint", &ptr);
756
757         box= uiLayoutBox(col);
758         row= uiLayoutRow(box, 0);
759
760         block= uiLayoutGetBlock(box);
761
762         subrow= uiLayoutRow(row, 0);
763         uiLayoutSetAlignment(subrow, UI_LAYOUT_ALIGN_LEFT);
764
765         /* Draw constraint header */
766         uiBlockSetEmboss(block, UI_EMBOSSN);
767         
768         /* rounded header */
769         rb_col= (con->flag & CONSTRAINT_ACTIVE)?50:20;
770         
771         /* open/close */
772         uiDefIconButBitS(block, ICONTOG, CONSTRAINT_EXPAND, B_CONSTRAINT_TEST, ICON_TRIA_RIGHT, xco-10, yco, 20, 20, &con->flag, 0.0, 0.0, 0.0, 0.0, "Collapse/Expand Constraint");
773         
774         /* name */      
775         uiBlockSetEmboss(block, UI_EMBOSS);
776         
777         /* XXX if (con->flag & CONSTRAINT_DISABLE)
778                 uiBlockSetCol(block, TH_REDALERT);*/
779         
780         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, typestr, xco+10, yco, 100, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
781         
782         if(proxy_protected == 0) {
783                 but = uiDefBut(block, TEX, B_CONSTRAINT_TEST, "", xco+120, yco, 85, 18, con->name, 0.0, 29.0, 0.0, 0.0, "Constraint name"); 
784                 uiButSetFunc(but, verify_constraint_name_func, con, NULL);
785         }
786         else
787                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, con->name, xco+120, yco-1, 135, 19, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
788
789         // XXX uiBlockSetCol(block, TH_AUTO);   
790
791         subrow= uiLayoutRow(row, 0);
792         uiLayoutSetAlignment(subrow, UI_LAYOUT_ALIGN_RIGHT);
793         
794         /* proxy-protected constraints cannot be edited, so hide up/down + close buttons */
795         if (proxy_protected) {
796                 uiBlockSetEmboss(block, UI_EMBOSSN);
797                 
798                 /* draw a ghost icon (for proxy) and also a lock beside it, to show that constraint is "proxy locked" */
799                 uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, ICON_GHOST, xco+244, yco, 19, 19, NULL, 0.0, 0.0, 0.0, 0.0, "Proxy Protected");
800                 uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, ICON_LOCKED, xco+262, yco, 19, 19, NULL, 0.0, 0.0, 0.0, 0.0, "Proxy Protected");
801                 
802                 uiBlockSetEmboss(block, UI_EMBOSS);
803         }
804         else {
805                 short prev_proxylock, show_upbut, show_downbut;
806                 
807                 /* Up/Down buttons: 
808                  *      Proxy-constraints are not allowed to occur after local (non-proxy) constraints
809                  *      as that poses problems when restoring them, so disable the "up" button where
810                  *      it may cause this situation. 
811                  *
812                  *      Up/Down buttons should only be shown (or not greyed - todo) if they serve some purpose. 
813                  */
814                 if (proxylocked_constraints_owner(ob, pchan)) {
815                         if (con->prev) {
816                                 prev_proxylock= (con->prev->flag & CONSTRAINT_PROXY_LOCAL) ? 0 : 1;
817                         }
818                         else
819                                 prev_proxylock= 0;
820                 }
821                 else
822                         prev_proxylock= 0;
823                         
824                 show_upbut= ((prev_proxylock == 0) && (con->prev));
825                 show_downbut= (con->next) ? 1 : 0;
826                 
827                 if (show_upbut || show_downbut) {
828                         uiBlockBeginAlign(block);
829                                 uiBlockSetEmboss(block, UI_EMBOSS);
830                                 
831                                 if (show_upbut) {
832                                         but = uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, VICON_MOVE_UP, xco+width-50, yco, 16, 18, NULL, 0.0, 0.0, 0.0, 0.0, "Move constraint up in constraint stack");
833                                         uiButSetFunc(but, constraint_moveUp, ob, con);
834                                 }
835                                 
836                                 if (show_downbut) {
837                                         but = uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, VICON_MOVE_DOWN, xco+width-50+18, yco, 16, 18, NULL, 0.0, 0.0, 0.0, 0.0, "Move constraint down in constraint stack");
838                                         uiButSetFunc(but, constraint_moveDown, ob, con);
839                                 }
840                         uiBlockEndAlign(block);
841                 }
842                 
843                 
844                 /* Close 'button' - emboss calls here disable drawing of 'button' behind X */
845                 uiBlockSetEmboss(block, UI_EMBOSSN);
846                 
847                 but = uiDefIconBut(block, BUT, B_CONSTRAINT_CHANGETARGET, ICON_X, xco+262, yco, 19, 19, NULL, 0.0, 0.0, 0.0, 0.0, "Delete constraint");
848                 uiButSetFunc(but, del_constraint_func, ob, con);
849                 
850                 uiBlockSetEmboss(block, UI_EMBOSS);
851         }
852         
853         /* Set but-locks for protected settings (magic numbers are used here!) */
854         if (proxy_protected)
855                 uiBlockSetButLock(block, 1, "Cannot edit Proxy-Protected Constraint");
856         
857         /* Draw constraint data */
858         if ((con->flag & CONSTRAINT_EXPAND) == 0) {
859                 (yco) -= 21;
860         }
861         else {
862                 box= uiLayoutBox(col);
863                 block= uiLayoutFreeBlock(box);
864
865                 switch (con->type) {
866 #ifndef DISABLE_PYTHON
867                 case CONSTRAINT_TYPE_PYTHON:
868                         {
869                                 bPythonConstraint *data = con->data;
870                                 bConstraintTarget *ct;
871                                 // uiBut *but2;
872                                 int tarnum, theight;
873                                 // static int pyconindex=0;
874                                 // char *menustr;
875                                 
876                                 theight = (data->tarnum)? (data->tarnum * 38) : (38);
877                                 
878                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Script:", xco+60, yco-24, 55, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
879                                 
880                                 /* do the scripts menu */
881                                 /* XXX menustr = buildmenu_pyconstraints(data->text, &pyconindex);
882                                 but2 = uiDefButI(block, MENU, B_CONSTRAINT_TEST, menustr,
883                                       xco+120, yco-24, 150, 20, &pyconindex,
884                                       0, 0, 0, 0, "Set the Script Constraint to use");
885                                 uiButSetFunc(but2, validate_pyconstraint_cb, data, &pyconindex);
886                                 MEM_freeN(menustr);      */
887                                 
888                                 /* draw target(s) */
889                                 if (data->flag & PYCON_USETARGETS) {
890                                         /* Draw target parameters */ 
891                                         for (ct=data->targets.first, tarnum=1; ct; ct=ct->next, tarnum++) {
892                                                 char tarstr[32];
893                                                 short yoffset= ((tarnum-1) * 38);
894         
895                                                 /* target label */
896                                                 sprintf(tarstr, "Target %d:", tarnum);
897                                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, tarstr, xco+45, yco-(48+yoffset), 100, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
898                                                 
899                                                 /* target space-selector - per target */
900                                                 if (is_armature_target(ct->tar)) {
901                                                         uiDefButS(block, MENU, B_CONSTRAINT_TEST, "Target Space %t|World Space %x0|Pose Space %x3|Local with Parent %x4|Local Space %x1", 
902                                                                                                                         xco+10, yco-(66+yoffset), 100, 18, &ct->space, 0, 0, 0, 0, "Choose space that target is evaluated in"); 
903                                                 }
904                                                 else {
905                                                         uiDefButS(block, MENU, B_CONSTRAINT_TEST, "Target Space %t|World Space %x0|Local (Without Parent) Space %x1", 
906                                                                                                                         xco+10, yco-(66+yoffset), 100, 18, &ct->space, 0, 0, 0, 0, "Choose space that target is evaluated in"); 
907                                                 }
908                                                 
909                                                 uiBlockBeginAlign(block);
910                                                         /* target object */
911                                                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", xco+120, yco-(48+yoffset), 150, 18, &ct->tar, "Target Object"); 
912                                                         
913                                                         /* subtarget */
914                                                         if (is_armature_target(ct->tar)) {
915                                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", xco+120, yco-(66+yoffset),150,18, &ct->subtarget, 0, 24, 0, 0, "Subtarget Bone");
916                                                                 uiButSetCompleteFunc(but, autocomplete_bone, (void *)ct->tar);
917                                                         }
918                                                         else if (is_geom_target(ct->tar)) {
919                                                                 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "VG:", xco+120, yco-(66+yoffset),150,18, &ct->subtarget, 0, 24, 0, 0, "Name of Vertex Group defining 'target' points");
920                                                                 uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)ct->tar);
921                                                         }
922                                                         else {
923                                                                 strcpy(ct->subtarget, "");
924                                                         }
925                                                 uiBlockEndAlign(block);
926                                         }
927                                 }
928                                 else {
929                                         /* Draw indication that no target needed */
930                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", xco+60, yco-48, 55, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
931                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Not Applicable", xco+120, yco-48, 150, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
932                                 }
933                                 
934                                 /* settings */
935                                 uiBlockBeginAlign(block);
936                                         but=uiDefBut(block, BUT, B_CONSTRAINT_TEST, "Options", xco, yco-(52+theight), (width/2),18, NULL, 0, 24, 0, 0, "Change some of the constraint's settings.");
937                                         // XXX uiButSetFunc(but, BPY_pyconstraint_settings, data, NULL);
938                                         
939                                         but=uiDefBut(block, BUT, B_CONSTRAINT_TEST, "Refresh", xco+((width/2)+10), yco-(52+theight), (width/2),18, NULL, 0, 24, 0, 0, "Force constraint to refresh it's settings");
940                                 uiBlockEndAlign(block);
941                                 
942                                 /* constraint space settings */
943                                 draw_constraint_spaceselect(block, con, xco, yco-(73+theight), is_armature_owner(ob), -1);
944                         }
945                         break;
946 #endif /* DISABLE_PYTHON */
947                 /*case CONSTRAINT_TYPE_CHILDOF:
948                         {
949                                 // Inverse options 
950                                 uiBlockBeginAlign(block);
951                                         but=uiDefBut(block, BUT, B_CONSTRAINT_TEST, "Set Offset", xco, yco-151, (width/2),18, NULL, 0, 24, 0, 0, "Calculate current Parent-Inverse Matrix (i.e. restore offset from parent)");
952                                         // XXX uiButSetFunc(but, childof_const_setinv, con, NULL);
953                                         
954                                         but=uiDefBut(block, BUT, B_CONSTRAINT_TEST, "Clear Offset", xco+((width/2)+10), yco-151, (width/2),18, NULL, 0, 24, 0, 0, "Clear Parent-Inverse Matrix (i.e. clear offset from parent)");
955                                         // XXX uiButSetFunc(but, childof_const_clearinv, con, NULL);
956                                 uiBlockEndAlign(block);
957                         }
958                         break; 
959                 */
960                 
961                 /*case CONSTRAINT_TYPE_RIGIDBODYJOINT:
962                         {
963                                 if (data->type==CONSTRAINT_RB_GENERIC6DOF) {
964                                         // Draw Pairs of LimitToggle+LimitValue 
965                                         uiBlockBeginAlign(block); 
966                                                 uiDefButBitS(block, TOG, 1, B_CONSTRAINT_TEST, "LinMinX", xco, yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum x limit"); 
967                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", xco+togButWidth, yco-offsetY, (textButWidth-5), 18, &(data->minLimit[0]), -extremeLin, extremeLin, 0.1,0.5,"min x limit"); 
968                                         uiBlockEndAlign(block);
969                                         
970                                         uiBlockBeginAlign(block); 
971                                                 uiDefButBitS(block, TOG, 1, B_CONSTRAINT_TEST, "LinMaxX", xco+(width-(textButWidth-5)-togButWidth), yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum x limit"); 
972                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", xco+(width-textButWidth-5), yco-offsetY, (textButWidth), 18, &(data->maxLimit[0]), -extremeLin, extremeLin, 0.1,0.5,"max x limit"); 
973                                         uiBlockEndAlign(block);
974                                         
975                                         offsetY += 20;
976                                         uiBlockBeginAlign(block); 
977                                                 uiDefButBitS(block, TOG, 2, B_CONSTRAINT_TEST, "LinMinY", xco, yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum y limit"); 
978                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", xco+togButWidth, yco-offsetY, (textButWidth-5), 18, &(data->minLimit[1]), -extremeLin, extremeLin, 0.1,0.5,"min y limit"); 
979                                         uiBlockEndAlign(block);
980                                         
981                                         uiBlockBeginAlign(block); 
982                                                 uiDefButBitS(block, TOG, 2, B_CONSTRAINT_TEST, "LinMaxY", xco+(width-(textButWidth-5)-togButWidth), yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum y limit"); 
983                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", xco+(width-textButWidth-5), yco-offsetY, (textButWidth), 18, &(data->maxLimit[1]), -extremeLin, extremeLin, 0.1,0.5,"max y limit"); 
984                                         uiBlockEndAlign(block);
985                                         
986                                         offsetY += 20;
987                                         uiBlockBeginAlign(block); 
988                                                 uiDefButBitS(block, TOG, 4, B_CONSTRAINT_TEST, "LinMinZ", xco, yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum z limit"); 
989                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", xco+togButWidth, yco-offsetY, (textButWidth-5), 18, &(data->minLimit[2]), -extremeLin, extremeLin, 0.1,0.5,"min z limit"); 
990                                         uiBlockEndAlign(block);
991                                         
992                                         uiBlockBeginAlign(block); 
993                                                 uiDefButBitS(block, TOG, 4, B_CONSTRAINT_TEST, "LinMaxZ", xco+(width-(textButWidth-5)-togButWidth), yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum z limit"); 
994                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", xco+(width-textButWidth-5), yco-offsetY, (textButWidth), 18, &(data->maxLimit[2]), -extremeLin, extremeLin, 0.1,0.5,"max z limit"); 
995                                         uiBlockEndAlign(block);
996                                         offsetY += 20;
997                                 }
998                                 if ((data->type==CONSTRAINT_RB_GENERIC6DOF) || (data->type==CONSTRAINT_RB_CONETWIST)) {
999                                         // Draw Pairs of LimitToggle+LimitValue /
1000                                         uiBlockBeginAlign(block); 
1001                                                 uiDefButBitS(block, TOG, 8, B_CONSTRAINT_TEST, "AngMinX", xco, yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum x limit"); 
1002                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", xco+togButWidth, yco-offsetY, (textButWidth-5), 18, &(data->minLimit[3]), -extremeAngX, extremeAngX, 0.1,0.5,"min x limit"); 
1003                                         uiBlockEndAlign(block);
1004                                         uiBlockBeginAlign(block); 
1005                                                 uiDefButBitS(block, TOG, 8, B_CONSTRAINT_TEST, "AngMaxX", xco+(width-(textButWidth-5)-togButWidth), yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum x limit"); 
1006                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", xco+(width-textButWidth-5), yco-offsetY, (textButWidth), 18, &(data->maxLimit[3]), -extremeAngX, extremeAngX, 0.1,0.5,"max x limit"); 
1007                                         uiBlockEndAlign(block);
1008                                         
1009                                         offsetY += 20;
1010                                         uiBlockBeginAlign(block); 
1011                                                 uiDefButBitS(block, TOG, 16, B_CONSTRAINT_TEST, "AngMinY", xco, yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum y limit"); 
1012                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", xco+togButWidth, yco-offsetY, (textButWidth-5), 18, &(data->minLimit[4]), -extremeAngY, extremeAngY, 0.1,0.5,"min y limit"); 
1013                                         uiBlockEndAlign(block);
1014                                         
1015                                         uiBlockBeginAlign(block); 
1016                                                 uiDefButBitS(block, TOG, 16, B_CONSTRAINT_TEST, "AngMaxY", xco+(width-(textButWidth-5)-togButWidth), yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum y limit"); 
1017                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", xco+(width-textButWidth-5), yco-offsetY, (textButWidth), 18, &(data->maxLimit[4]), -extremeAngY, extremeAngY, 0.1,0.5,"max y limit"); 
1018                                         uiBlockEndAlign(block);
1019                                         
1020                                         offsetY += 20;
1021                                         uiBlockBeginAlign(block); 
1022                                                 uiDefButBitS(block, TOG, 32, B_CONSTRAINT_TEST, "AngMinZ", xco, yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum z limit"); 
1023                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", xco+togButWidth, yco-offsetY, (textButWidth-5), 18, &(data->minLimit[5]), -extremeAngZ, extremeAngZ, 0.1,0.5,"min z limit"); 
1024                                         uiBlockEndAlign(block);
1025                                         
1026                                         uiBlockBeginAlign(block); 
1027                                                 uiDefButBitS(block, TOG, 32, B_CONSTRAINT_TEST, "AngMaxZ", xco+(width-(textButWidth-5)-togButWidth), yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum z limit"); 
1028                                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", xco+(width-textButWidth-5), yco-offsetY, (textButWidth), 18, &(data->maxLimit[5]), -extremeAngZ, extremeAngZ, 0.1,0.5,"max z limit"); 
1029                                         uiBlockEndAlign(block);
1030                                 }
1031                                 
1032                         }
1033                         break;
1034                         */
1035
1036                 case CONSTRAINT_TYPE_NULL:
1037                         {
1038                                 uiItemL(box, "", 0);
1039                         }
1040                         break;
1041                 default:
1042                         result= box;
1043                         break;
1044                 }
1045         }
1046         
1047         /* clear any locks set up for proxies/lib-linking */
1048         uiBlockClearButLock(block);
1049
1050         return result;
1051 }
1052
1053 uiLayout *uiTemplateConstraint(uiLayout *layout, PointerRNA *ptr)
1054 {
1055         Object *ob;
1056         bConstraint *con;
1057
1058         /* verify we have valid data */
1059         if(!RNA_struct_is_a(ptr->type, &RNA_Constraint)) {
1060                 printf("uiTemplateConstraint: expected constraint on object.\n");
1061                 return NULL;
1062         }
1063
1064         ob= ptr->id.data;
1065         con= ptr->data;
1066
1067         if(!ob || !(GS(ob->id.name) == ID_OB)) {
1068                 printf("uiTemplateConstraint: expected constraint on object.\n");
1069                 return NULL;
1070         }
1071         
1072         uiBlockSetButLock(uiLayoutGetBlock(layout), (ob && ob->id.lib), ERROR_LIBDATA_MESSAGE);
1073
1074         /* hrms, the temporal constraint should not draw! */
1075         if(con->type==CONSTRAINT_TYPE_KINEMATIC) {
1076                 bKinematicConstraint *data= con->data;
1077                 if(data->flag & CONSTRAINT_IK_TEMP)
1078                         return NULL;
1079         }
1080
1081         return draw_constraint(layout, ob, con);
1082 }
1083
1084 /************************* Group Template ***************************/
1085
1086 #if 0
1087 static void do_add_groupmenu(void *arg, int event)
1088 {
1089         Object *ob= OBACT;
1090         
1091         if(ob) {
1092                 
1093                 if(event== -1) {
1094                         Group *group= add_group( "Group" );
1095                         add_to_group(group, ob);
1096                 }
1097                 else
1098                         add_to_group(BLI_findlink(&G.main->group, event), ob);
1099                         
1100                 ob->flag |= OB_FROMGROUP;
1101                 BASACT->flag |= OB_FROMGROUP;
1102                 allqueue(REDRAWBUTSOBJECT, 0);
1103                 allqueue(REDRAWVIEW3D, 0);
1104         }               
1105 }
1106
1107 static uiBlock *add_groupmenu(void *arg_unused)
1108 {
1109         uiBlock *block;
1110         Group *group;
1111         short xco=0, yco= 0, index=0;
1112         char str[32];
1113         
1114         block= uiNewBlock(&curarea->uiblocks, "add_constraintmenu", UI_EMBOSSP, UI_HELV, curarea->win);
1115         uiBlockSetButmFunc(block, do_add_groupmenu, NULL);
1116
1117         uiDefBut(block, BUTM, B_NOP, "ADD NEW",         0, 20, 160, 19, NULL, 0.0, 0.0, 1, -1, "");
1118         for(group= G.main->group.first; group; group= group->id.next, index++) {
1119                 
1120                 /*if(group->id.lib) strcpy(str, "L  ");*/ /* we cant allow adding objects inside linked groups, it wont be saved anyway */
1121                 if(group->id.lib==0) {
1122                         strcpy(str, "   ");
1123                         strcat(str, group->id.name+2);
1124                         uiDefBut(block, BUTM, B_NOP, str,       xco*160, -20*yco, 160, 19, NULL, 0.0, 0.0, 1, index, "");
1125                         
1126                         yco++;
1127                         if(yco>24) {
1128                                 yco= 0;
1129                                 xco++;
1130                         }
1131                 }
1132         }
1133         
1134         uiTextBoundsBlock(block, 50);
1135         uiBlockSetDirection(block, UI_DOWN);    
1136         
1137         return block;
1138 }
1139
1140 static void group_ob_rem(void *gr_v, void *ob_v)
1141 {
1142         Object *ob= OBACT;
1143         
1144         if(rem_from_group(gr_v, ob) && find_group(ob, NULL)==NULL) {
1145                 ob->flag &= ~OB_FROMGROUP;
1146                 BASACT->flag &= ~OB_FROMGROUP;
1147         }
1148         allqueue(REDRAWBUTSOBJECT, 0);
1149         allqueue(REDRAWVIEW3D, 0);
1150
1151 }
1152
1153 static void group_local(void *gr_v, void *unused)
1154 {
1155         Group *group= gr_v;
1156         
1157         group->id.lib= NULL;
1158         
1159         allqueue(REDRAWBUTSOBJECT, 0);
1160         allqueue(REDRAWVIEW3D, 0);
1161         
1162 }
1163
1164 uiLayout *uiTemplateGroup(uiLayout *layout, Object *ob, Group *group)
1165 {
1166         uiSetButLock(1, NULL);
1167         uiDefBlockBut(block, add_groupmenu, NULL, "Add to Group", 10,150,150,20, "Add Object to a new Group");
1168
1169         /* all groups */
1170         if(group->id.lib) {
1171                 uiLayoutRow()
1172                 uiBlockBeginAlign(block);
1173                 uiSetButLock(GET_INT_FROM_POINTER(group->id.lib), ERROR_LIBDATA_MESSAGE); /* We cant actually use this button */
1174                 uiDefBut(block, TEX, B_IDNAME, "GR:",   10, 120-yco, 100, 20, group->id.name+2, 0.0, 21.0, 0, 0, "Displays Group name. Click to change.");
1175                 uiClearButLock();
1176                 
1177                 but= uiDefIconBut(block, BUT, B_NOP, ICON_PARLIB, 110, 120-yco, 20, 20, NULL, 0.0, 0.0, 0.0, 0.0, "Make Group local");
1178                 uiButSetFunc(but, group_local, group, NULL);
1179                 uiBlockEndAlign(block);
1180         } else {
1181                 but = uiDefBut(block, TEX, B_IDNAME, "GR:",     10, 120-yco, 120, 20, group->id.name+2, 0.0, 21.0, 0, 0, "Displays Group name. Click to change.");
1182                 uiButSetFunc(but, test_idbutton_cb, group->id.name, NULL);
1183         }
1184         
1185         xco = 290;
1186         if(group->id.lib==0) { /* cant remove objects from linked groups */
1187                 but = uiDefIconBut(block, BUT, B_NOP, VICON_X, xco, 120-yco, 20, 20, NULL, 0.0, 0.0, 0.0, 0.0, "Remove Group membership");
1188                 uiButSetFunc(but, group_ob_rem, group, ob);
1189         }
1190 }
1191 #endif
1192
1193 /************************* Preview Template ***************************/
1194
1195 #include "DNA_material_types.h"
1196
1197 #define B_MATPRV 1
1198
1199
1200 static void do_preview_buttons(bContext *C, void *arg, int event)
1201 {
1202         switch(event) {
1203                 case B_MATPRV:
1204                         WM_event_add_notifier(C, NC_MATERIAL|ND_SHADING, arg);
1205                         break;
1206         }
1207 }
1208
1209 void uiTemplatePreview(uiLayout *layout, ID *id)
1210 {
1211         uiLayout *row, *col;
1212         uiBlock *block;
1213         Material *ma;
1214
1215         if(id && !ELEM4(GS(id->name), ID_MA, ID_TE, ID_WO, ID_LA)) {
1216                 printf("uiTemplatePreview: expected ID of type material, texture, lamp or world.\n");
1217                 return;
1218         }
1219
1220         block= uiLayoutGetBlock(layout);
1221
1222         row= uiLayoutRow(layout, 0);
1223
1224         col= uiLayoutColumn(row, 0);
1225         uiLayoutSetKeepAspect(col, 1);
1226         
1227         uiDefBut(block, BUT_EXTRA, 0, "", 0, 0, UI_UNIT_X*6, UI_UNIT_Y*6, id, 0.0, 0.0, 0, 0, "");
1228         uiBlockSetDrawExtraFunc(block, ED_preview_draw);
1229         
1230         uiBlockSetHandleFunc(block, do_preview_buttons, NULL);
1231         
1232         if(id) {
1233                 if(GS(id->name) == ID_MA) {
1234                         ma= (Material*)id;
1235
1236                         uiLayoutColumn(row, 1);
1237
1238                         uiDefIconButC(block, ROW, B_MATPRV, ICON_MATPLANE,  0, 0,UI_UNIT_X*1.5,UI_UNIT_Y, &(ma->pr_type), 10, MA_FLAT, 0, 0, "Preview type: Flat XY plane");
1239                         uiDefIconButC(block, ROW, B_MATPRV, ICON_MATSPHERE, 0, 0,UI_UNIT_X*1.5,UI_UNIT_Y, &(ma->pr_type), 10, MA_SPHERE, 0, 0, "Preview type: Sphere");
1240                         uiDefIconButC(block, ROW, B_MATPRV, ICON_MATCUBE,   0, 0,UI_UNIT_X*1.5,UI_UNIT_Y, &(ma->pr_type), 10, MA_CUBE, 0, 0, "Preview type: Cube");
1241                         uiDefIconButC(block, ROW, B_MATPRV, ICON_MONKEY,    0, 0,UI_UNIT_X*1.5,UI_UNIT_Y, &(ma->pr_type), 10, MA_MONKEY, 0, 0, "Preview type: Monkey");
1242                         uiDefIconButC(block, ROW, B_MATPRV, ICON_HAIR,      0, 0,UI_UNIT_X*1.5,UI_UNIT_Y, &(ma->pr_type), 10, MA_HAIR, 0, 0, "Preview type: Hair strands");
1243                         uiDefIconButC(block, ROW, B_MATPRV, ICON_MATSPHERE, 0, 0,UI_UNIT_X*1.5,UI_UNIT_Y, &(ma->pr_type), 10, MA_SPHERE_A, 0, 0, "Preview type: Large sphere with sky");
1244                 }
1245         }
1246 }
1247
1248 /********************** ColorRamp Template **************************/
1249
1250 void uiTemplateColorRamp(uiLayout *layout, ColorBand *coba, int expand)
1251 {
1252         uiBlock *block;
1253         rctf rect;
1254
1255         if(coba) {
1256                 rect.xmin= 0; rect.xmax= 200;
1257                 rect.ymin= 0; rect.ymax= 190;
1258                 
1259                 block= uiLayoutFreeBlock(layout);
1260                 colorband_buttons(block, coba, &rect, !expand);
1261         }
1262 }
1263
1264 /********************* CurveMapping Template ************************/
1265
1266 #include "DNA_color_types.h"
1267
1268 void uiTemplateCurveMapping(uiLayout *layout, CurveMapping *cumap, int type)
1269 {
1270         uiBlock *block;
1271         rctf rect;
1272
1273         if(cumap) {
1274                 rect.xmin= 0; rect.xmax= 200;
1275                 rect.ymin= 0; rect.ymax= 190;
1276                 
1277                 block= uiLayoutFreeBlock(layout);
1278                 curvemap_buttons(block, cumap, type, 0, 0, &rect);
1279         }
1280 }
1281
1282 /********************* Layer Buttons Template ************************/
1283
1284 // TODO:
1285 //      - option for showing extra info like whether layer has contents?
1286 //      - for now, grouping of layers is determined by dividing up the length of 
1287 //        the array of layer bitflags
1288
1289 void uiTemplateLayers(uiLayout *layout, PointerRNA *ptr, char *propname)
1290 {
1291         uiLayout *uRow, *uSplit, *uCol;
1292         PropertyRNA *prop;
1293         int groups, cols, layers;
1294         int group, col, layer, row;
1295         
1296         if (!ptr->data)
1297                 return;
1298         
1299         prop= RNA_struct_find_property(ptr, propname);
1300         if (!prop) {
1301                 printf("uiTemplateLayer: layers property not found: %s\n", propname);
1302                 return;
1303         }
1304         
1305         /* the number of layers determines the way we group them 
1306          *      - we want 2 rows only (for now)
1307          *      - the number of columns (cols) is the total number of buttons per row
1308          *        the 'remainder' is added to this, as it will be ok to have first row slightly wider if need be
1309          *      - for now, only split into groups if if group will have at least 5 items
1310          */
1311         layers= RNA_property_array_length(prop);
1312         cols= (layers / 2) + (layers % 2);
1313         groups= ((cols / 2) < 5) ? (1) : (cols / 2);
1314         
1315         /* layers are laid out going across rows, with the columns being divided into groups */
1316         uSplit= uiLayoutSplit(layout, (1.0f/(float)groups));
1317         
1318         for (group= 0; group < groups; group++) {
1319                 uCol= uiLayoutColumn(uSplit, 1);
1320                 
1321                 for (row= 0; row < 2; row++) {
1322                         uRow= uiLayoutRow(uCol, 1);
1323                         layer= groups*cols*row + cols*group;
1324                         
1325                         /* add layers as toggle buts */
1326                         for (col= 0; (col < cols) && (layer < layers); col++, layer++) {
1327                                 int icon=0; // XXX - add some way of setting this...
1328                                 uiItemFullR(uRow, "", icon, ptr, prop, layer, 0, 0, 0, 1);
1329                         }
1330                 }
1331         }
1332 }
1333
1334
1335 /************************* List Template **************************/
1336
1337 ListBase uiTemplateList(uiLayout *layout, PointerRNA *ptr, char *propname, PointerRNA *activeptr, char *activepropname, int rows, int columns, int compact)
1338 {
1339         CollectionPointerLink *link;
1340         PropertyRNA *prop= NULL, *activeprop;
1341         PropertyType type, activetype;
1342         uiLayout *box, *row, *col;
1343         uiBlock *block;
1344         uiBut *but;
1345         Panel *pa;
1346         ListBase lb;
1347         char *name, str[32];
1348         int i= 0, activei= 0, len, items, found, min, max;
1349
1350         lb.first= lb.last= NULL;
1351         
1352         /* validate arguments */
1353         block= uiLayoutGetBlock(layout);
1354         pa= block->panel;
1355
1356         if(!pa) {
1357                 printf("uiTemplateList: only works inside a panel.\n");
1358                 return lb;
1359         }
1360
1361         if(!activeptr->data)
1362                 return lb;
1363         
1364         if(ptr->data) {
1365                 prop= RNA_struct_find_property(ptr, propname);
1366                 if(!prop) {
1367                         printf("uiTemplateList: property not found: %s\n", propname);
1368                         return lb;
1369                 }
1370         }
1371
1372         activeprop= RNA_struct_find_property(activeptr, activepropname);
1373         if(!activeprop) {
1374                 printf("uiTemplateList: property not found: %s\n", activepropname);
1375                 return lb;
1376         }
1377
1378         if(prop) {
1379                 type= RNA_property_type(prop);
1380                 if(type != PROP_COLLECTION) {
1381                         printf("uiTemplateList: expected collection property.\n");
1382                         return lb;
1383                 }
1384         }
1385
1386         activetype= RNA_property_type(activeprop);
1387         if(activetype != PROP_INT) {
1388                 printf("uiTemplateList: expected integer property.\n");
1389                 return lb;
1390         }
1391
1392         /* get active data */
1393         activei= RNA_property_int_get(activeptr, activeprop);
1394
1395         if(compact) {
1396                 /* compact layout */
1397                 found= 0;
1398
1399                 row= uiLayoutRow(layout, 1);
1400
1401                 if(ptr->data && prop) {
1402                         /* create list items */
1403                         RNA_PROP_BEGIN(ptr, itemptr, prop) {
1404                                 found= (activei == i);
1405
1406                                 if(found) {
1407                                         /* create button */
1408                                         name= RNA_struct_name_get_alloc(&itemptr, NULL, 0);
1409                                         if(name) {
1410                                                 uiItemL(row, name, RNA_struct_ui_icon(itemptr.type));
1411                                                 MEM_freeN(name);
1412                                         }
1413
1414                                         /* add to list to return */
1415                                         link= MEM_callocN(sizeof(CollectionPointerLink), "uiTemplateList return");
1416                                         link->ptr= itemptr;
1417                                         BLI_addtail(&lb, link);
1418                                 }
1419
1420                                 i++;
1421                         }
1422                         RNA_PROP_END;
1423                 }
1424
1425                 /* if not found, add in dummy button */
1426                 if(i == 0)
1427                         uiItemL(row, "", 0);
1428
1429                 /* next/prev button */
1430                 sprintf(str, "%d :", i);
1431                 but= uiDefIconTextButR(block, NUM, 0, 0, str, 0,0,UI_UNIT_X*5,UI_UNIT_Y, activeptr, activepropname, 0, 0, 0, 0, 0, "");
1432                 if(i == 0)
1433                         uiButSetFlag(but, UI_BUT_DISABLED);
1434         }
1435         else {
1436                 /* default rows/columns */
1437                 if(rows == 0)
1438                         rows= 5;
1439                 if(columns == 0)
1440                         columns= 1;
1441
1442                 /* layout */
1443                 box= uiLayoutBox(layout);
1444                 row= uiLayoutRow(box, 0);
1445                 col = uiLayoutColumn(row, 1);
1446
1447                 uiBlockSetEmboss(block, UI_EMBOSSN);
1448
1449                 /* init numbers */
1450                 RNA_property_int_range(activeptr, activeprop, &min, &max);
1451
1452                 len= max - min + 1;
1453                 items= rows*columns;
1454
1455                 pa->list_scroll= MIN2(pa->list_scroll, len-items);
1456                 pa->list_scroll= MAX2(pa->list_scroll, 0);
1457
1458                 if(ptr->data && prop) {
1459                         /* create list items */
1460                         RNA_PROP_BEGIN(ptr, itemptr, prop) {
1461                                 if(i >= pa->list_scroll && i<pa->list_scroll+items) {
1462                                         name= RNA_struct_name_get_alloc(&itemptr, NULL, 0);
1463
1464                                         if(name) {
1465                                                 /* create button */
1466                                                 but= uiDefIconTextButR(block, ROW, 0, RNA_struct_ui_icon(itemptr.type), name, 0,0,UI_UNIT_X*10,UI_UNIT_Y, activeptr, activepropname, 0, 0, i, 0, 0, "");
1467                                                 uiButSetFlag(but, UI_ICON_LEFT|UI_TEXT_LEFT);
1468
1469                                                 MEM_freeN(name);
1470                                         }
1471
1472                                         /* add to list to return */
1473                                         link= MEM_callocN(sizeof(CollectionPointerLink), "uiTemplateList return");
1474                                         link->ptr= itemptr;
1475                                         BLI_addtail(&lb, link);
1476                                 }
1477
1478                                 i++;
1479                         }
1480                         RNA_PROP_END;
1481                 }
1482
1483                 /* add dummy buttons to fill space */
1484                 while(i < pa->list_scroll+items) {
1485                         if(i >= pa->list_scroll)
1486                                 uiItemL(col, "", 0);
1487                         i++;
1488                 }
1489
1490                 uiBlockSetEmboss(block, UI_EMBOSS);
1491
1492                 /* add scrollbar */
1493                 if(len > items) {
1494                         col= uiLayoutColumn(row, 0);
1495                         uiDefButI(block, SCROLL, 0, "", 0,0,UI_UNIT_X*0.75,UI_UNIT_Y*items, &pa->list_scroll, 0, len-items, items, 0, "");
1496                 }
1497         }
1498
1499         /* return items in list */
1500         return lb;
1501 }
1502
1503 /************************* Operator Search Template **************************/
1504
1505 static void operator_call_cb(struct bContext *C, void *arg1, void *arg2)
1506 {
1507         wmOperatorType *ot= arg2;
1508         
1509         if(ot)
1510                 WM_operator_name_call(C, ot->idname, WM_OP_INVOKE_DEFAULT, NULL);
1511 }
1512
1513 static void operator_search_cb(const struct bContext *C, void *arg, char *str, uiSearchItems *items)
1514 {
1515         wmOperatorType *ot = WM_operatortype_first();
1516         
1517         for(; ot; ot= ot->next) {
1518                 
1519                 if(BLI_strcasestr(ot->name, str)) {
1520                         if(ot->poll==NULL || ot->poll((bContext *)C)) {
1521                                 char name[256];
1522                                 int len= strlen(ot->name);
1523                                 
1524                                 /* display name for menu, can hold hotkey */
1525                                 BLI_strncpy(name, ot->name, 256);
1526                                 
1527                                 /* check for hotkey */
1528                                 if(len < 256-6) {
1529                                         if(WM_key_event_operator_string(C, ot->idname, WM_OP_EXEC_DEFAULT, NULL, &name[len+1], 256-len-1))
1530                                                 name[len]= '|';
1531                                 }
1532                                 
1533                                 if(0==uiSearchItemAdd(items, name, ot, 0))
1534                                         break;
1535                         }
1536                 }
1537         }
1538 }
1539
1540 void uiTemplateOperatorSearch(uiLayout *layout)
1541 {
1542         uiBlock *block;
1543         uiBut *but;
1544         static char search[256]= "";
1545                 
1546         block= uiLayoutGetBlock(layout);
1547         uiBlockSetCurLayout(block, layout);
1548
1549         but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, sizeof(search), 0, 0, UI_UNIT_X*6, UI_UNIT_Y, "");
1550         uiButSetSearchFunc(but, operator_search_cb, NULL, operator_call_cb, NULL);
1551 }
1552
1553 /************************* Running Jobs Template **************************/
1554
1555 #define B_STOPRENDER    1
1556 #define B_STOPCAST              2
1557 #define B_STOPANIM              3
1558
1559 static void do_running_jobs(bContext *C, void *arg, int event)
1560 {
1561         switch(event) {
1562                 case B_STOPRENDER:
1563                         G.afbreek= 1;
1564                         break;
1565                 case B_STOPCAST:
1566                         WM_jobs_stop(CTX_wm_manager(C), CTX_wm_screen(C));
1567                         break;
1568                 case B_STOPANIM:
1569                         ED_screen_animation_timer(C, 0, 0);
1570                         break;
1571         }
1572 }
1573
1574 void uiTemplateRunningJobs(uiLayout *layout, bContext *C)
1575 {
1576         bScreen *screen= CTX_wm_screen(C);
1577         Scene *scene= CTX_data_scene(C);
1578         wmWindowManager *wm= CTX_wm_manager(C);
1579         uiBlock *block;
1580
1581         block= uiLayoutGetBlock(layout);
1582         uiBlockSetCurLayout(block, layout);
1583
1584         uiBlockSetHandleFunc(block, do_running_jobs, NULL);
1585
1586         if(WM_jobs_test(wm, scene))
1587                 uiDefIconTextBut(block, BUT, B_STOPRENDER, ICON_REC, "Render", 0,0,75,UI_UNIT_Y, NULL, 0.0f, 0.0f, 0, 0, "Stop rendering");
1588         if(WM_jobs_test(wm, screen))
1589                 uiDefIconTextBut(block, BUT, B_STOPCAST, ICON_REC, "Capture", 0,0,85,UI_UNIT_Y, NULL, 0.0f, 0.0f, 0, 0, "Stop screencast");
1590         if(screen->animtimer)
1591                 uiDefIconTextBut(block, BUT, B_STOPANIM, ICON_REC, "Anim Player", 0,0,85,UI_UNIT_Y, NULL, 0.0f, 0.0f, 0, 0, "Stop animation playback");
1592 }
1593