4 * ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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.
20 * Contributor(s): Blender Foundation 2009.
22 * ***** END GPL LICENSE BLOCK *****
28 #include "MEM_guardedalloc.h"
30 #include "DNA_scene_types.h"
31 #include "DNA_screen_types.h"
33 #include "BLI_string.h"
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"
41 #include "ED_screen.h"
42 #include "ED_previewrender.h"
44 #include "RNA_access.h"
49 #include "UI_interface.h"
50 #include "UI_resources.h"
51 #include "interface_intern.h"
53 void ui_template_fix_linking()
57 /********************** Header Template *************************/
59 void uiTemplateHeader(uiLayout *layout, bContext *C)
63 block= uiLayoutFreeBlock(layout);
64 ED_area_header_standardbuttons(C, block, 0);
67 /********************** Search Callbacks *************************/
69 typedef struct TemplateID {
76 /* Search browse menu, assign */
77 static void id_search_call_cb(struct bContext *C, void *arg_template, void *item)
79 TemplateID *template= (TemplateID*)arg_template;
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);
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)
94 TemplateID *template= (TemplateID*)arg_template;
95 Scene *scene= CTX_data_scene(C);
96 ListBase *lb= template->idlb;
101 for(id= lb->first; id; id= id->next) {
102 iconid= ui_id_icon_get(scene, id);
104 if(BLI_strcasestr(id->name+2, str))
105 if(!uiSearchItemAdd(items, id->name+2, id, iconid))
110 /* ID Search browse menu, open */
111 static uiBlock *search_menu(bContext *C, ARegion *ar, void *arg_litem)
113 static char search[256];
114 static TemplateID template;
117 wmWindow *win= CTX_wm_window(C);
121 /* clear initial search string, then all items show */
123 /* arg_litem is malloced, can be freed by parent button */
124 template= *((TemplateID*)arg_litem);
126 /* get active id for showing first item */
127 idptr= RNA_property_pointer_get(&template.ptr, template.prop);
129 block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
130 uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_RET_1);
132 /* fake button, it holds space for search items */
133 uiDefBut(block, LABEL, 0, "", 10, 15, 150, uiSearchBoxhHeight(), NULL, 0, 0, 0, 0, NULL);
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);
138 uiBoundsBlock(block, 6);
139 uiBlockSetDirection(block, UI_DOWN);
140 uiEndBlock(C, block);
142 event= *(win->eventstate); /* XXX huh huh? make api call */
143 event.type= EVT_BUT_OPEN;
145 event.customdata= but;
146 event.customdatafree= FALSE;
147 wm_event_add(win, &event);
152 /************************ ID Template ***************************/
154 static void template_id_cb(bContext *C, void *arg_litem, void *arg_event)
156 TemplateID *template= (TemplateID*)arg_litem;
157 PointerRNA idptr= RNA_property_pointer_get(&template->ptr, template->prop);
159 int event= GET_INT_FROM_POINTER(arg_event);
164 printf("warning, id event %d shouldnt come here\n", event);
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);
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);
179 case UI_ID_FAKE_USER:
181 if(id->flag & LIB_FAKEUSER) id->us++;
188 if(!id || id->us < 1)
192 if(!id || id->us < 1)
195 case UI_ID_AUTO_NAME:
201 static void template_ID(bContext *C, uiBlock *block, TemplateID *template, StructRNA *type, int flag, char *newop, char *unlinkop)
207 idptr= RNA_property_pointer_get(&template->ptr, template->prop);
210 uiBlockBeginAlign(block);
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");
218 but->icon= RNA_struct_ui_icon(type);
219 but->flag|= UI_HAS_ICON;
220 but->flag|= UI_ICON_LEFT;
224 /* text button with name */
228 //text_idbutton(idptr.data, name);
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));
234 if(flag & UI_ID_ADD_NEW) {
235 int w= idptr.data?UI_UNIT_X:UI_UNIT_X*6;
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));
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));
248 if(idptr.data && (flag & UI_ID_DELETE)) {
250 but= uiDefIconButO(block, BUT, unlinkop, WM_OP_EXEC_REGION_WIN, ICON_X, 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL);
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));
258 uiBlockEndAlign(block);
261 void uiTemplateID(uiLayout *layout, bContext *C, PointerRNA *ptr, char *propname, char *newop, char *unlinkop)
263 TemplateID *template;
272 prop= RNA_struct_find_property(ptr, propname);
274 if(!prop || RNA_property_type(prop) != PROP_POINTER) {
275 printf("uiTemplateID: pointer property not found: %s\n", propname);
279 template= MEM_callocN(sizeof(TemplateID), "TemplateID");
281 template->prop= prop;
283 flag= UI_ID_BROWSE|UI_ID_RENAME|UI_ID_DELETE;
286 flag |= UI_ID_ADD_NEW;
288 type= RNA_property_pointer_type(ptr, prop);
289 template->idlb= wich_libbase(CTX_data_main(C), RNA_type_to_ID_code(type));
292 uiLayoutRow(layout, 1);
293 block= uiLayoutGetBlock(layout);
294 template_ID(C, block, template, type, flag, newop, unlinkop);
300 /************************ Modifier Template *************************/
302 #define ERROR_LIBDATA_MESSAGE "Can't edit external libdata"
306 #include "DNA_object_force.h"
307 #include "DNA_object_types.h"
308 #include "DNA_modifier_types.h"
309 #include "DNA_scene_types.h"
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"
319 #include "UI_resources.h"
322 #include "BLI_arithb.h"
323 #include "BLI_listbase.h"
325 #include "ED_object.h"
327 static void modifiers_setOnCage(bContext *C, void *ob_v, void *md_v)
329 Scene *scene= CTX_data_scene(C);
333 int i, cageIndex = modifiers_getCageIndex(ob, NULL );
335 for(i = 0, md=ob->modifiers.first; md; ++i, md=md->next) {
338 md->mode ^= eModifierMode_OnCage;
343 WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob);
344 DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
347 static void modifiers_convertToReal(bContext *C, void *ob_v, void *md_v)
349 Scene *scene= CTX_data_scene(C);
351 ModifierData *md = md_v;
352 ModifierData *nmd = modifier_new(md->type);
354 modifier_copyData(md, nmd);
355 nmd->mode &= ~eModifierMode_Virtual;
357 BLI_addhead(&ob->modifiers, nmd);
359 ob->partype = PAROBJECT;
361 WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob);
362 DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
364 ED_undo_push(C, "Modifier convert to real");
367 static int modifier_can_delete(ModifierData *md)
369 // fluid particle modifier can't be deleted here
370 if(md->type == eModifierType_ParticleSystem)
371 if(((ParticleSystemModifierData *)md)->psys->part->type == PART_FLUID)
377 static uiLayout *draw_modifier(uiLayout *layout, Object *ob, ModifierData *md, int index, int cageIndex, int lastCageIndex)
379 ModifierTypeInfo *mti = modifierType_getInfo(md->type);
383 uiLayout *column, *row, *result= NULL;
384 int isVirtual = md->mode & eModifierMode_Virtual;
385 // XXX short color = md->error?TH_REDALERT:TH_BUT_NEUTRAL;
388 /* create RNA pointer */
389 RNA_pointer_create(&ob->id, &RNA_Modifier, md, &ptr);
391 column= uiLayoutColumn(layout, 1);
392 uiLayoutSetContextPointer(column, "modifier", &ptr);
395 /* XXX uiBlockSetCol(block, color); */
396 /* roundbox 4 free variables: corner-rounding, nop, roundbox type, shade */
398 row= uiLayoutRow(uiLayoutBox(column), 0);
399 uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_EXPAND);
401 block= uiLayoutGetBlock(row);
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); */
407 /* open/close icon */
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");
413 /* modifier-type icon */
414 uiItemL(row, "", RNA_struct_ui_icon(ptr.type));
416 uiBlockSetEmboss(block, UI_EMBOSS);
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");
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);
428 uiBlockBeginAlign(block);
429 uiItemR(row, "", 0, &ptr, "name", 0, 0, 0);
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);
436 if(mti->flags & eModifierTypeFlag_SupportsEditmode)
437 uiItemR(row, "", ICON_VIEW3D, &ptr, "editmode", 0, 0, 0);
439 uiBlockEndAlign(block);
441 /* XXX uiBlockSetEmboss(block, UI_EMBOSSR); */
443 if(ob->type==OB_MESH && modifier_couldBeCage(md) && index<=lastCageIndex) {
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;
453 // XXX color = TH_BUT_NEUTRAL;
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); */
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");
469 uiBlockSetEmboss(block, UI_EMBOSSN);
471 if(modifier_can_delete(md))
472 uiItemO(row, "", VICON_X, "OBJECT_OT_modifier_remove");
474 /* XXX uiBlockSetCol(block, TH_AUTO); */
477 uiBlockSetEmboss(block, UI_EMBOSS);
479 if(!isVirtual && (md->mode & eModifierMode_Expanded)) {
480 /* apply/convert/copy */
483 box= uiLayoutBox(column);
484 row= uiLayoutRow(box, 1);
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);
490 if(md->type==eModifierType_ParticleSystem) {
491 ParticleSystem *psys= ((ParticleSystemModifierData *)md)->psys;
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");
498 uiItemO(row, "Apply", 0, "OBJECT_OT_modifier_apply");
500 uiBlockClearButLock(block);
501 uiBlockSetButLock(block, ob && ob->id.lib, ERROR_LIBDATA_MESSAGE);
503 if(!ELEM4(md->type, eModifierType_Fluidsim, eModifierType_Softbody, eModifierType_ParticleSystem, eModifierType_Cloth))
504 uiItemO(row, "Copy", 0, "OBJECT_OT_modifier_copy");
507 result= uiLayoutColumn(box, 0);
508 block= uiLayoutFreeBlock(box);
512 row = uiLayoutRow(uiLayoutBox(column), 0);
514 /* XXX uiBlockSetCol(block, color); */
515 uiItemL(row, md->error, ICON_ERROR);
516 /* XXX uiBlockSetCol(block, TH_AUTO); */
522 uiLayout *uiTemplateModifier(uiLayout *layout, PointerRNA *ptr)
525 ModifierData *md, *vmd;
526 int i, lastCageIndex, cageIndex;
528 /* verify we have valid data */
529 if(!RNA_struct_is_a(ptr->type, &RNA_Modifier)) {
530 printf("uiTemplateModifier: expected modifier on object.\n");
537 if(!ob || !(GS(ob->id.name) == ID_OB)) {
538 printf("uiTemplateModifier: expected modifier on object.\n");
542 uiBlockSetButLock(uiLayoutGetBlock(layout), (ob && ob->id.lib), ERROR_LIBDATA_MESSAGE);
544 /* find modifier and draw it */
545 cageIndex = modifiers_getCageIndex(ob, &lastCageIndex);
547 // XXX virtual modifiers are not accesible for python
548 vmd = modifiers_getVirtualModifierList(ob);
550 for(i=0; vmd; i++, vmd=vmd->next) {
552 return draw_modifier(layout, ob, md, i, cageIndex, lastCageIndex);
553 else if(vmd->mode & eModifierMode_Virtual)
560 /************************ Constraint Template *************************/
562 #include "DNA_action_types.h"
563 #include "DNA_constraint_types.h"
565 #include "BKE_action.h"
566 #include "BKE_constraint.h"
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
578 void do_constraint_panels(bContext *C, void *arg, int event)
580 Scene *scene= CTX_data_scene(C);
581 Object *ob= CTX_data_active_object(C);
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 */
592 ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK);
594 case B_CONSTRAINT_CHANGETARGET:
595 if (ob->pose) ob->pose->flag |= POSE_RECALC; // checks & sorts pose channels
596 DAG_scene_sort(scene);
602 object_test_constraints(ob);
604 if(ob->pose) update_pose_constraint_flags(ob->pose);
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);
609 // XXX allqueue(REDRAWVIEW3D, 0);
610 // XXX allqueue(REDRAWBUTSOBJECT, 0);
611 // XXX allqueue(REDRAWBUTSEDIT, 0);
614 static void constraint_active_func(bContext *C, void *ob_v, void *con_v)
616 ED_object_constraint_set_active(ob_v, con_v);
619 static void verify_constraint_name_func (bContext *C, void *con_v, void *name_v)
621 Object *ob= CTX_data_active_object(C);
622 bConstraint *con= con_v;
628 /* put on the stack */
629 BLI_strncpy(oldname, (char *)name_v, 32);
631 ED_object_constraint_rename(ob, con, oldname);
632 ED_object_constraint_set_active(ob, con);
633 // XXX allqueue(REDRAWACTION, 0);
636 /* some commonly used macros in the constraints drawing code */
637 #define is_armature_target(target) (target && target->type==OB_ARMATURE)
638 #define is_armature_owner(ob) ((ob->type == OB_ARMATURE) && (ob->flag & OB_POSEMODE))
639 #define is_geom_target(target) (target && (ELEM(target->type, OB_MESH, OB_LATTICE)) )
641 /* Helper function for draw constraint - draws constraint space stuff
642 * This function should not be called if no menus are required
643 * owner/target: -1 = don't draw menu; 0= not posemode, 1 = posemode
645 static void draw_constraint_spaceselect (uiBlock *block, bConstraint *con, short xco, short yco, short owner, short target)
647 short tarx, ownx, iconx;
649 short iconwidth = 20;
651 /* calculate sizes and placement of menus */
657 else if (target == -1) {
665 iconx = tarx + bwidth + 5;
666 ownx = tarx + bwidth + iconwidth + 10;
670 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Convert:", xco, yco, 80,18, NULL, 0.0, 0.0, 0.0, 0.0, "");
674 uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Target Space %t|World Space %x0|Pose Space %x2|Local with Parent %x3|Local Space %x1",
675 tarx, yco, bwidth, 18, &con->tarspace, 0, 0, 0, 0, "Choose space that target is evaluated in");
677 else if (target == 0) {
678 uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Target Space %t|World Space %x0|Local (Without Parent) Space %x1",
679 tarx, yco, bwidth, 18, &con->tarspace, 0, 0, 0, 0, "Choose space that target is evaluated in");
682 if ((target != -1) && (owner != -1))
683 uiDefIconBut(block, LABEL, 0, ICON_ARROW_LEFTRIGHT,
684 iconx, yco, 20, 20, NULL, 0.0, 0.0, 0.0, 0.0, "");
688 uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Owner Space %t|World Space %x0|Pose Space %x2|Local with Parent %x3|Local Space %x1",
689 ownx, yco, bwidth, 18, &con->ownspace, 0, 0, 0, 0, "Choose space that owner is evaluated in");
691 else if (owner == 0) {
692 uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Owner Space %t|World Space %x0|Local (Without Parent) Space %x1",
693 ownx, yco, bwidth, 18, &con->ownspace, 0, 0, 0, 0, "Choose space that owner is evaluated in");
697 /* draw panel showing settings for a constraint */
698 static uiLayout *draw_constraint(uiLayout *layout, Object *ob, bConstraint *con)
700 bPoseChannel *pchan= get_active_posechannel(ob);
701 bConstraintTypeInfo *cti;
703 uiLayout *result= NULL, *col, *box, *row, *subrow;
708 short proxy_protected, xco=0, yco=0;
711 /* get constraint typeinfo */
712 cti= constraint_get_typeinfo(con);
714 /* exception for 'Null' constraint - it doesn't have constraint typeinfo! */
715 if (con->type == CONSTRAINT_TYPE_NULL)
716 strcpy(typestr, "Null");
718 strcpy(typestr, "Unknown");
721 strcpy(typestr, cti->name);
723 /* determine whether constraint is proxy protected or not */
724 if (proxylocked_constraints_owner(ob, pchan))
725 proxy_protected= (con->flag & CONSTRAINT_PROXY_LOCAL)==0;
729 /* unless button has own callback, it adds this callback to button */
730 block= uiLayoutGetBlock(layout);
731 uiBlockSetHandleFunc(block, do_constraint_panels, NULL);
732 uiBlockSetFunc(block, constraint_active_func, ob, con);
734 RNA_pointer_create(&ob->id, &RNA_Constraint, con, &ptr);
736 col= uiLayoutColumn(layout, 1);
737 uiLayoutSetContextPointer(col, "constraint", &ptr);
739 box= uiLayoutBox(col);
740 row= uiLayoutRow(box, 0);
742 block= uiLayoutGetBlock(box);
744 subrow= uiLayoutRow(row, 0);
745 uiLayoutSetAlignment(subrow, UI_LAYOUT_ALIGN_LEFT);
747 /* Draw constraint header */
748 uiBlockSetEmboss(block, UI_EMBOSSN);
751 rb_col= (con->flag & CONSTRAINT_ACTIVE)?50:20;
754 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");
757 uiBlockSetEmboss(block, UI_EMBOSS);
759 /* XXX if (con->flag & CONSTRAINT_DISABLE)
760 uiBlockSetCol(block, TH_REDALERT);*/
762 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, typestr, xco+10, yco, 100, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
764 if(proxy_protected == 0) {
765 but = uiDefBut(block, TEX, B_CONSTRAINT_TEST, "", xco+120, yco, 85, 18, con->name, 0.0, 29.0, 0.0, 0.0, "Constraint name");
766 uiButSetFunc(but, verify_constraint_name_func, con, NULL);
769 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, con->name, xco+120, yco-1, 135, 19, NULL, 0.0, 0.0, 0.0, 0.0, "");
771 // XXX uiBlockSetCol(block, TH_AUTO);
773 subrow= uiLayoutRow(row, 0);
774 uiLayoutSetAlignment(subrow, UI_LAYOUT_ALIGN_RIGHT);
776 /* proxy-protected constraints cannot be edited, so hide up/down + close buttons */
777 if (proxy_protected) {
778 uiBlockSetEmboss(block, UI_EMBOSSN);
780 /* draw a ghost icon (for proxy) and also a lock beside it, to show that constraint is "proxy locked" */
781 uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, ICON_GHOST, xco+244, yco, 19, 19, NULL, 0.0, 0.0, 0.0, 0.0, "Proxy Protected");
782 uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, ICON_LOCKED, xco+262, yco, 19, 19, NULL, 0.0, 0.0, 0.0, 0.0, "Proxy Protected");
784 uiBlockSetEmboss(block, UI_EMBOSS);
787 short prev_proxylock, show_upbut, show_downbut;
790 * Proxy-constraints are not allowed to occur after local (non-proxy) constraints
791 * as that poses problems when restoring them, so disable the "up" button where
792 * it may cause this situation.
794 * Up/Down buttons should only be shown (or not greyed - todo) if they serve some purpose.
796 if (proxylocked_constraints_owner(ob, pchan)) {
798 prev_proxylock= (con->prev->flag & CONSTRAINT_PROXY_LOCAL) ? 0 : 1;
806 show_upbut= ((prev_proxylock == 0) && (con->prev));
807 show_downbut= (con->next) ? 1 : 0;
809 if (show_upbut || show_downbut) {
810 uiBlockBeginAlign(block);
811 uiBlockSetEmboss(block, UI_EMBOSS);
814 uiDefIconButO(block, BUT, "CONSTRAINT_OT_move_up", WM_OP_INVOKE_DEFAULT, VICON_MOVE_UP, xco+width-50, yco, 16, 18, "Move constraint up in constraint stack");
817 uiDefIconButO(block, BUT, "CONSTRAINT_OT_move_down", WM_OP_INVOKE_DEFAULT, VICON_MOVE_DOWN, xco+width-50+18, yco, 16, 18, "Move constraint down in constraint stack");
818 uiBlockEndAlign(block);
822 /* Close 'button' - emboss calls here disable drawing of 'button' behind X */
823 uiBlockSetEmboss(block, UI_EMBOSSN);
824 uiDefIconButO(block, BUT, "CONSTRAINT_OT_delete", WM_OP_INVOKE_DEFAULT, ICON_X, xco+262, yco, 19, 19, "Delete constraint");
825 uiBlockSetEmboss(block, UI_EMBOSS);
828 /* Set but-locks for protected settings (magic numbers are used here!) */
830 uiBlockSetButLock(block, 1, "Cannot edit Proxy-Protected Constraint");
832 /* Draw constraint data */
833 if ((con->flag & CONSTRAINT_EXPAND) == 0) {
837 box= uiLayoutBox(col);
838 block= uiLayoutFreeBlock(box);
841 #ifndef DISABLE_PYTHON
842 case CONSTRAINT_TYPE_PYTHON:
844 bPythonConstraint *data = con->data;
845 bConstraintTarget *ct;
848 // static int pyconindex=0;
851 theight = (data->tarnum)? (data->tarnum * 38) : (38);
853 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Script:", xco+60, yco-24, 55, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
855 /* do the scripts menu */
856 /* XXX menustr = buildmenu_pyconstraints(data->text, &pyconindex);
857 but2 = uiDefButI(block, MENU, B_CONSTRAINT_TEST, menustr,
858 xco+120, yco-24, 150, 20, &pyconindex,
859 0, 0, 0, 0, "Set the Script Constraint to use");
860 uiButSetFunc(but2, validate_pyconstraint_cb, data, &pyconindex);
861 MEM_freeN(menustr); */
864 if (data->flag & PYCON_USETARGETS) {
865 /* Draw target parameters */
866 for (ct=data->targets.first, tarnum=1; ct; ct=ct->next, tarnum++) {
868 short yoffset= ((tarnum-1) * 38);
871 sprintf(tarstr, "Target %d:", tarnum);
872 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, tarstr, xco+45, yco-(48+yoffset), 100, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
874 /* target space-selector - per target */
875 if (is_armature_target(ct->tar)) {
876 uiDefButS(block, MENU, B_CONSTRAINT_TEST, "Target Space %t|World Space %x0|Pose Space %x3|Local with Parent %x4|Local Space %x1",
877 xco+10, yco-(66+yoffset), 100, 18, &ct->space, 0, 0, 0, 0, "Choose space that target is evaluated in");
880 uiDefButS(block, MENU, B_CONSTRAINT_TEST, "Target Space %t|World Space %x0|Local (Without Parent) Space %x1",
881 xco+10, yco-(66+yoffset), 100, 18, &ct->space, 0, 0, 0, 0, "Choose space that target is evaluated in");
884 uiBlockBeginAlign(block);
886 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", xco+120, yco-(48+yoffset), 150, 18, &ct->tar, "Target Object");
889 if (is_armature_target(ct->tar)) {
890 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", xco+120, yco-(66+yoffset),150,18, &ct->subtarget, 0, 24, 0, 0, "Subtarget Bone");
891 uiButSetCompleteFunc(but, autocomplete_bone, (void *)ct->tar);
893 else if (is_geom_target(ct->tar)) {
894 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");
895 uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)ct->tar);
898 strcpy(ct->subtarget, "");
900 uiBlockEndAlign(block);
904 /* Draw indication that no target needed */
905 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", xco+60, yco-48, 55, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
906 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Not Applicable", xco+120, yco-48, 150, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
910 uiBlockBeginAlign(block);
911 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.");
912 // XXX uiButSetFunc(but, BPY_pyconstraint_settings, data, NULL);
914 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");
915 uiBlockEndAlign(block);
917 /* constraint space settings */
918 draw_constraint_spaceselect(block, con, xco, yco-(73+theight), is_armature_owner(ob), -1);
921 #endif /* DISABLE_PYTHON */
923 /*case CONSTRAINT_TYPE_RIGIDBODYJOINT:
925 if (data->type==CONSTRAINT_RB_GENERIC6DOF) {
926 // Draw Pairs of LimitToggle+LimitValue
927 uiBlockBeginAlign(block);
928 uiDefButBitS(block, TOG, 1, B_CONSTRAINT_TEST, "LinMinX", xco, yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum x limit");
929 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");
930 uiBlockEndAlign(block);
932 uiBlockBeginAlign(block);
933 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");
934 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");
935 uiBlockEndAlign(block);
938 uiBlockBeginAlign(block);
939 uiDefButBitS(block, TOG, 2, B_CONSTRAINT_TEST, "LinMinY", xco, yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum y limit");
940 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");
941 uiBlockEndAlign(block);
943 uiBlockBeginAlign(block);
944 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");
945 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");
946 uiBlockEndAlign(block);
949 uiBlockBeginAlign(block);
950 uiDefButBitS(block, TOG, 4, B_CONSTRAINT_TEST, "LinMinZ", xco, yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum z limit");
951 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");
952 uiBlockEndAlign(block);
954 uiBlockBeginAlign(block);
955 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");
956 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");
957 uiBlockEndAlign(block);
960 if ((data->type==CONSTRAINT_RB_GENERIC6DOF) || (data->type==CONSTRAINT_RB_CONETWIST)) {
961 // Draw Pairs of LimitToggle+LimitValue /
962 uiBlockBeginAlign(block);
963 uiDefButBitS(block, TOG, 8, B_CONSTRAINT_TEST, "AngMinX", xco, yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum x limit");
964 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");
965 uiBlockEndAlign(block);
966 uiBlockBeginAlign(block);
967 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");
968 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");
969 uiBlockEndAlign(block);
972 uiBlockBeginAlign(block);
973 uiDefButBitS(block, TOG, 16, B_CONSTRAINT_TEST, "AngMinY", xco, yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum y limit");
974 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");
975 uiBlockEndAlign(block);
977 uiBlockBeginAlign(block);
978 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");
979 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");
980 uiBlockEndAlign(block);
983 uiBlockBeginAlign(block);
984 uiDefButBitS(block, TOG, 32, B_CONSTRAINT_TEST, "AngMinZ", xco, yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum z limit");
985 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");
986 uiBlockEndAlign(block);
988 uiBlockBeginAlign(block);
989 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");
990 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");
991 uiBlockEndAlign(block);
998 case CONSTRAINT_TYPE_NULL:
1000 uiItemL(box, "", 0);
1009 /* clear any locks set up for proxies/lib-linking */
1010 uiBlockClearButLock(block);
1015 uiLayout *uiTemplateConstraint(uiLayout *layout, PointerRNA *ptr)
1020 /* verify we have valid data */
1021 if(!RNA_struct_is_a(ptr->type, &RNA_Constraint)) {
1022 printf("uiTemplateConstraint: expected constraint on object.\n");
1029 if(!ob || !(GS(ob->id.name) == ID_OB)) {
1030 printf("uiTemplateConstraint: expected constraint on object.\n");
1034 uiBlockSetButLock(uiLayoutGetBlock(layout), (ob && ob->id.lib), ERROR_LIBDATA_MESSAGE);
1036 /* hrms, the temporal constraint should not draw! */
1037 if(con->type==CONSTRAINT_TYPE_KINEMATIC) {
1038 bKinematicConstraint *data= con->data;
1039 if(data->flag & CONSTRAINT_IK_TEMP)
1043 return draw_constraint(layout, ob, con);
1046 /************************* Group Template ***************************/
1049 static void do_add_groupmenu(void *arg, int event)
1056 Group *group= add_group( "Group" );
1057 add_to_group(group, ob);
1060 add_to_group(BLI_findlink(&G.main->group, event), ob);
1062 ob->flag |= OB_FROMGROUP;
1063 BASACT->flag |= OB_FROMGROUP;
1064 allqueue(REDRAWBUTSOBJECT, 0);
1065 allqueue(REDRAWVIEW3D, 0);
1069 static uiBlock *add_groupmenu(void *arg_unused)
1073 short xco=0, yco= 0, index=0;
1076 block= uiNewBlock(&curarea->uiblocks, "add_constraintmenu", UI_EMBOSSP, UI_HELV, curarea->win);
1077 uiBlockSetButmFunc(block, do_add_groupmenu, NULL);
1079 uiDefBut(block, BUTM, B_NOP, "ADD NEW", 0, 20, 160, 19, NULL, 0.0, 0.0, 1, -1, "");
1080 for(group= G.main->group.first; group; group= group->id.next, index++) {
1082 /*if(group->id.lib) strcpy(str, "L ");*/ /* we cant allow adding objects inside linked groups, it wont be saved anyway */
1083 if(group->id.lib==0) {
1085 strcat(str, group->id.name+2);
1086 uiDefBut(block, BUTM, B_NOP, str, xco*160, -20*yco, 160, 19, NULL, 0.0, 0.0, 1, index, "");
1096 uiTextBoundsBlock(block, 50);
1097 uiBlockSetDirection(block, UI_DOWN);
1102 static void group_ob_rem(void *gr_v, void *ob_v)
1106 if(rem_from_group(gr_v, ob) && find_group(ob, NULL)==NULL) {
1107 ob->flag &= ~OB_FROMGROUP;
1108 BASACT->flag &= ~OB_FROMGROUP;
1110 allqueue(REDRAWBUTSOBJECT, 0);
1111 allqueue(REDRAWVIEW3D, 0);
1115 static void group_local(void *gr_v, void *unused)
1119 group->id.lib= NULL;
1121 allqueue(REDRAWBUTSOBJECT, 0);
1122 allqueue(REDRAWVIEW3D, 0);
1126 uiLayout *uiTemplateGroup(uiLayout *layout, Object *ob, Group *group)
1128 uiSetButLock(1, NULL);
1129 uiDefBlockBut(block, add_groupmenu, NULL, "Add to Group", 10,150,150,20, "Add Object to a new Group");
1134 uiBlockBeginAlign(block);
1135 uiSetButLock(GET_INT_FROM_POINTER(group->id.lib), ERROR_LIBDATA_MESSAGE); /* We cant actually use this button */
1136 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.");
1139 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");
1140 uiButSetFunc(but, group_local, group, NULL);
1141 uiBlockEndAlign(block);
1143 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.");
1144 uiButSetFunc(but, test_idbutton_cb, group->id.name, NULL);
1148 if(group->id.lib==0) { /* cant remove objects from linked groups */
1149 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");
1150 uiButSetFunc(but, group_ob_rem, group, ob);
1155 /************************* Preview Template ***************************/
1157 #include "DNA_material_types.h"
1162 static void do_preview_buttons(bContext *C, void *arg, int event)
1166 WM_event_add_notifier(C, NC_MATERIAL|ND_SHADING, arg);
1171 void uiTemplatePreview(uiLayout *layout, ID *id)
1173 uiLayout *row, *col;
1177 if(id && !ELEM4(GS(id->name), ID_MA, ID_TE, ID_WO, ID_LA)) {
1178 printf("uiTemplatePreview: expected ID of type material, texture, lamp or world.\n");
1182 block= uiLayoutGetBlock(layout);
1184 row= uiLayoutRow(layout, 0);
1186 col= uiLayoutColumn(row, 0);
1187 uiLayoutSetKeepAspect(col, 1);
1189 uiDefBut(block, BUT_EXTRA, 0, "", 0, 0, UI_UNIT_X*6, UI_UNIT_Y*6, id, 0.0, 0.0, 0, 0, "");
1190 uiBlockSetDrawExtraFunc(block, ED_preview_draw);
1192 uiBlockSetHandleFunc(block, do_preview_buttons, NULL);
1195 if(GS(id->name) == ID_MA) {
1198 uiLayoutColumn(row, 1);
1200 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");
1201 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");
1202 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");
1203 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");
1204 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");
1205 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");
1210 /********************** ColorRamp Template **************************/
1212 void uiTemplateColorRamp(uiLayout *layout, ColorBand *coba, int expand)
1218 rect.xmin= 0; rect.xmax= 200;
1219 rect.ymin= 0; rect.ymax= 190;
1221 block= uiLayoutFreeBlock(layout);
1222 colorband_buttons(block, coba, &rect, !expand);
1226 /********************* CurveMapping Template ************************/
1228 #include "DNA_color_types.h"
1230 void uiTemplateCurveMapping(uiLayout *layout, CurveMapping *cumap, int type)
1236 rect.xmin= 0; rect.xmax= 200;
1237 rect.ymin= 0; rect.ymax= 190;
1239 block= uiLayoutFreeBlock(layout);
1240 curvemap_buttons(block, cumap, type, 0, 0, &rect);
1244 /********************* Layer Buttons Template ************************/
1247 // - option for showing extra info like whether layer has contents?
1248 // - for now, grouping of layers is determined by dividing up the length of
1249 // the array of layer bitflags
1251 void uiTemplateLayers(uiLayout *layout, PointerRNA *ptr, char *propname)
1253 uiLayout *uRow, *uSplit, *uCol;
1255 int groups, cols, layers;
1256 int group, col, layer, row;
1261 prop= RNA_struct_find_property(ptr, propname);
1263 printf("uiTemplateLayer: layers property not found: %s\n", propname);
1267 /* the number of layers determines the way we group them
1268 * - we want 2 rows only (for now)
1269 * - the number of columns (cols) is the total number of buttons per row
1270 * the 'remainder' is added to this, as it will be ok to have first row slightly wider if need be
1271 * - for now, only split into groups if if group will have at least 5 items
1273 layers= RNA_property_array_length(prop);
1274 cols= (layers / 2) + (layers % 2);
1275 groups= ((cols / 2) < 5) ? (1) : (cols / 2);
1277 /* layers are laid out going across rows, with the columns being divided into groups */
1278 uSplit= uiLayoutSplit(layout, (1.0f/(float)groups));
1280 for (group= 0; group < groups; group++) {
1281 uCol= uiLayoutColumn(uSplit, 1);
1283 for (row= 0; row < 2; row++) {
1284 uRow= uiLayoutRow(uCol, 1);
1285 layer= groups*cols*row + cols*group;
1287 /* add layers as toggle buts */
1288 for (col= 0; (col < cols) && (layer < layers); col++, layer++) {
1289 int icon=0; // XXX - add some way of setting this...
1290 uiItemFullR(uRow, "", icon, ptr, prop, layer, 0, 0, 0, 1);
1297 /************************* List Template **************************/
1299 ListBase uiTemplateList(uiLayout *layout, PointerRNA *ptr, char *propname, PointerRNA *activeptr, char *activepropname, int rows, int columns, int compact)
1301 CollectionPointerLink *link;
1302 PropertyRNA *prop= NULL, *activeprop;
1303 PropertyType type, activetype;
1305 uiLayout *box, *row, *col;
1310 char *name, str[32];
1311 int icon=0, i= 0, activei= 0, len, items, found, min, max;
1313 lb.first= lb.last= NULL;
1315 /* validate arguments */
1316 block= uiLayoutGetBlock(layout);
1320 printf("uiTemplateList: only works inside a panel.\n");
1324 if(!activeptr->data)
1328 prop= RNA_struct_find_property(ptr, propname);
1330 printf("uiTemplateList: property not found: %s\n", propname);
1335 activeprop= RNA_struct_find_property(activeptr, activepropname);
1337 printf("uiTemplateList: property not found: %s\n", activepropname);
1342 type= RNA_property_type(prop);
1343 if(type != PROP_COLLECTION) {
1344 printf("uiTemplateList: expected collection property.\n");
1349 activetype= RNA_property_type(activeprop);
1350 if(activetype != PROP_INT) {
1351 printf("uiTemplateList: expected integer property.\n");
1356 if(ptr->data && prop) {
1357 ptype= RNA_property_pointer_type(ptr, prop);
1358 icon= RNA_struct_ui_icon(ptype);
1361 /* get active data */
1362 activei= RNA_property_int_get(activeptr, activeprop);
1365 /* compact layout */
1368 row= uiLayoutRow(layout, 1);
1370 if(ptr->data && prop) {
1371 /* create list items */
1372 RNA_PROP_BEGIN(ptr, itemptr, prop) {
1373 found= (activei == i);
1377 name= RNA_struct_name_get_alloc(&itemptr, NULL, 0);
1378 uiItemL(row, (name)? name: "", icon);
1383 /* add to list to return */
1384 link= MEM_callocN(sizeof(CollectionPointerLink), "uiTemplateList return");
1386 BLI_addtail(&lb, link);
1394 /* if not found, add in dummy button */
1396 uiItemL(row, "", 0);
1398 /* next/prev button */
1399 sprintf(str, "%d :", i);
1400 but= uiDefIconTextButR(block, NUM, 0, 0, str, 0,0,UI_UNIT_X*5,UI_UNIT_Y, activeptr, activepropname, 0, 0, 0, 0, 0, "");
1402 uiButSetFlag(but, UI_BUT_DISABLED);
1405 /* default rows/columns */
1412 box= uiLayoutBox(layout);
1413 row= uiLayoutRow(box, 0);
1414 col = uiLayoutColumn(row, 1);
1416 uiBlockSetEmboss(block, UI_EMBOSSN);
1419 RNA_property_int_range(activeptr, activeprop, &min, &max);
1422 items= rows*columns;
1424 pa->list_scroll= MIN2(pa->list_scroll, len-items);
1425 pa->list_scroll= MAX2(pa->list_scroll, 0);
1427 if(ptr->data && prop) {
1428 /* create list items */
1429 RNA_PROP_BEGIN(ptr, itemptr, prop) {
1430 if(i >= pa->list_scroll && i<pa->list_scroll+items) {
1431 name= RNA_struct_name_get_alloc(&itemptr, NULL, 0);
1434 but= uiDefIconTextButR(block, ROW, 0, icon, (name)? name: "", 0,0,UI_UNIT_X*10,UI_UNIT_Y, activeptr, activepropname, 0, 0, i, 0, 0, "");
1435 uiButSetFlag(but, UI_ICON_LEFT|UI_TEXT_LEFT);
1440 /* add to list to return */
1441 link= MEM_callocN(sizeof(CollectionPointerLink), "uiTemplateList return");
1443 BLI_addtail(&lb, link);
1451 /* add dummy buttons to fill space */
1452 while(i < pa->list_scroll+items) {
1453 if(i >= pa->list_scroll)
1454 uiItemL(col, "", 0);
1458 uiBlockSetEmboss(block, UI_EMBOSS);
1462 col= uiLayoutColumn(row, 0);
1463 uiDefButI(block, SCROLL, 0, "", 0,0,UI_UNIT_X*0.75,UI_UNIT_Y*items, &pa->list_scroll, 0, len-items, items, 0, "");
1467 /* return items in list */
1471 /************************* Operator Search Template **************************/
1473 static void operator_call_cb(struct bContext *C, void *arg1, void *arg2)
1475 wmOperatorType *ot= arg2;
1478 WM_operator_name_call(C, ot->idname, WM_OP_INVOKE_DEFAULT, NULL);
1481 static void operator_search_cb(const struct bContext *C, void *arg, char *str, uiSearchItems *items)
1483 wmOperatorType *ot = WM_operatortype_first();
1485 for(; ot; ot= ot->next) {
1487 if(BLI_strcasestr(ot->name, str)) {
1488 if(ot->poll==NULL || ot->poll((bContext *)C)) {
1490 int len= strlen(ot->name);
1492 /* display name for menu, can hold hotkey */
1493 BLI_strncpy(name, ot->name, 256);
1495 /* check for hotkey */
1497 if(WM_key_event_operator_string(C, ot->idname, WM_OP_EXEC_DEFAULT, NULL, &name[len+1], 256-len-1))
1501 if(0==uiSearchItemAdd(items, name, ot, 0))
1508 void uiTemplateOperatorSearch(uiLayout *layout)
1512 static char search[256]= "";
1514 block= uiLayoutGetBlock(layout);
1515 uiBlockSetCurLayout(block, layout);
1517 but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, sizeof(search), 0, 0, UI_UNIT_X*6, UI_UNIT_Y, "");
1518 uiButSetSearchFunc(but, operator_search_cb, NULL, operator_call_cb, NULL);
1521 /************************* Running Jobs Template **************************/
1523 #define B_STOPRENDER 1
1524 #define B_STOPCAST 2
1525 #define B_STOPANIM 3
1527 static void do_running_jobs(bContext *C, void *arg, int event)
1534 WM_jobs_stop(CTX_wm_manager(C), CTX_wm_screen(C));
1537 ED_screen_animation_timer(C, 0, 0);
1542 void uiTemplateRunningJobs(uiLayout *layout, bContext *C)
1544 bScreen *screen= CTX_wm_screen(C);
1545 Scene *scene= CTX_data_scene(C);
1546 wmWindowManager *wm= CTX_wm_manager(C);
1549 block= uiLayoutGetBlock(layout);
1550 uiBlockSetCurLayout(block, layout);
1552 uiBlockSetHandleFunc(block, do_running_jobs, NULL);
1554 if(WM_jobs_test(wm, scene))
1555 uiDefIconTextBut(block, BUT, B_STOPRENDER, ICON_REC, "Render", 0,0,75,UI_UNIT_Y, NULL, 0.0f, 0.0f, 0, 0, "Stop rendering");
1556 if(WM_jobs_test(wm, screen))
1557 uiDefIconTextBut(block, BUT, B_STOPCAST, ICON_REC, "Capture", 0,0,85,UI_UNIT_Y, NULL, 0.0f, 0.0f, 0, 0, "Stop screencast");
1558 if(screen->animtimer)
1559 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");